Пример #1
0
        /// <summary>
        ///     Speed up the unit production.
        /// </summary>
        public void SpeedUp()
        {
            LogicAvatar           homeOwnerAvatar  = this._level.GetHomeOwnerAvatar();
            LogicComponentManager componentManager = this._level.GetComponentManagerAt(this._villageType);
            Int32 totalMaxHousing   = componentManager.GetTotalMaxHousing(this._unitProductionType != 3 ? 1 : 0);
            Int32 totalUsedCapacity = this._unitProductionType == 3 ? homeOwnerAvatar.GetUnitsTotalCapacity() : homeOwnerAvatar.GetSpellsTotalCapacity();
            Int32 freeCapacity      = totalMaxHousing - totalUsedCapacity;

            while (this._slots.Count > 0)
            {
                LogicUnitProductionSlot slot = this._slots[0];
                LogicCombatItemData     data = (LogicCombatItemData)slot.GetData();
                Int32 count = slot.GetCount();

                if (count > 0)
                {
                    do
                    {
                        freeCapacity -= data.GetHousingSpace();

                        if (freeCapacity < 0)
                        {
                            return;
                        }

                        this.ProductionCompleted(true);
                    } while (--count > 0);
                }
                else
                {
                    break;
                }
            }
        }
Пример #2
0
        /// <summary>
        ///     Tries to merge slots.
        /// </summary>
        public void MergeSlots()
        {
            LogicAvatar homeOwnerAvatar = this._level.GetHomeOwnerAvatar();

            if (this._slots.Count > 0)
            {
                if (this._slots.Count > 1)
                {
                    for (int i = 1; i < this._slots.Count; i++)
                    {
                        LogicUnitProductionSlot slot1 = this._slots[i];
                        LogicUnitProductionSlot slot2 = this._slots[i - 1];

                        if (slot1.GetData() == slot2.GetData())
                        {
                            if (slot1.IsTerminate() == slot2.IsTerminate())
                            {
                                this._slots.Remove(i--);
                                slot2.SetCount(slot2.GetCount() + slot1.GetCount());
                                slot1.Destruct();
                                slot1 = null;
                            }
                        }
                    }
                }
            }

            LogicComponentManager componentManager = this._level.GetComponentManagerAt(this._villageType);
            Int32 totalCapcity = componentManager.GetTotalMaxHousing(this._unitProductionType != 3 ? 1 : 0);
            Int32 usedCapacity = this._unitProductionType == 25 ? homeOwnerAvatar.GetSpellsTotalCapacity() : homeOwnerAvatar.GetUnitsTotalCapacity();
            Int32 freeCapacity = totalCapcity - usedCapacity;

            for (int i = 0; i < this._slots.Count; i++)
            {
                LogicUnitProductionSlot slot = this._slots[i];
                LogicCombatItemData     data = (LogicCombatItemData)slot.GetData();

                int housingSpace = data.GetHousingSpace() * slot.GetCount();

                if (freeCapacity < housingSpace)
                {
                    if (slot.GetCount() > 0 && housingSpace / data.GetHousingSpace() > 0)
                    {
                        if (slot.GetCount() > housingSpace / data.GetHousingSpace())
                        {
                            this._slots.Add(i + 1, new LogicUnitProductionSlot(data, slot.GetCount() - housingSpace / data.GetHousingSpace(), slot.IsTerminate()));
                        }
                    }

                    break;
                }

                freeCapacity -= housingSpace;
            }
        }
Пример #3
0
        public bool CanAddUnitToQueue(LogicCombatItemData data, bool ignoreCapacity)
        {
            if (data != null)
            {
                if (data.GetDataType() == this.m_unitProductionType)
                {
                    LogicGameObjectManager gameObjectManager = this.m_level.GetGameObjectManagerAt(0);
                    LogicBuilding          productionHouse   = gameObjectManager.GetHighestBuilding(data.GetProductionHouseData());

                    if (productionHouse != null)
                    {
                        if (!data.IsUnlockedForProductionHouseLevel(productionHouse.GetUpgradeLevel()))
                        {
                            return(false);
                        }

                        if (data.GetUnitOfType() != productionHouse.GetBuildingData().GetProducesUnitsOfType())
                        {
                            return(false);
                        }
                    }

                    if (this.m_level.GetMissionManager().IsTutorialFinished() ||
                        this.m_level.GetHomeOwnerAvatar().GetUnitsTotalCapacity() + this.GetTotalCount() < LogicUnitProduction.TUTORIAL_MAX_CAPACITY)
                    {
                        if (ignoreCapacity)
                        {
                            return(true);
                        }

                        LogicAvatar           avatar           = this.m_level.GetHomeOwnerAvatar();
                        LogicComponentManager componentManager = this.m_level.GetComponentManagerAt(this.m_villageType);
                        int totalMaxHousing   = componentManager.GetTotalMaxHousing(this.m_unitProductionType != LogicDataType.CHARACTER ? 1 : 0) * 2;
                        int totalUsedCapacity = this.GetTotalCount() + data.GetHousingSpace() + (this.m_unitProductionType == LogicDataType.CHARACTER
                                                    ? avatar.GetUnitsTotalCapacity()
                                                    : avatar.GetSpellsTotalCapacity());

                        return(totalMaxHousing >= totalUsedCapacity);
                    }
                }
                else
                {
                    Debugger.Error("Trying to add wrong unit type to UnitProduction");
                }
            }
            else
            {
                Debugger.Error("Trying to add NULL troop to UnitProduction");
            }

            return(false);
        }
Пример #4
0
        public int GetTotalRemainingSeconds()
        {
            LogicAvatar           homeOwnerAvatar  = this.m_level.GetHomeOwnerAvatar();
            LogicComponentManager componentManager = this.m_level.GetComponentManagerAt(this.m_villageType);

            int totalMaxHousing   = componentManager.GetTotalMaxHousing(this.m_unitProductionType != LogicDataType.CHARACTER ? 1 : 0);
            int totalUsedCapacity = this.m_unitProductionType == LogicDataType.CHARACTER ? homeOwnerAvatar.GetUnitsTotalCapacity() : homeOwnerAvatar.GetSpellsTotalCapacity();
            int freeCapacity      = totalMaxHousing - totalUsedCapacity;
            int remainingSecs     = 0;

            for (int i = 0; i < this.m_slots.Size(); i++)
            {
                LogicUnitProductionSlot slot = this.m_slots[i];
                LogicCombatItemData     data = (LogicCombatItemData)slot.GetData();
                int housingSpace             = data.GetHousingSpace();
                int count = slot.GetCount();

                if (count > 0)
                {
                    if (i == 0)
                    {
                        if (!slot.IsTerminate() && freeCapacity - housingSpace >= 0)
                        {
                            if (this.m_timer != null)
                            {
                                remainingSecs += this.m_timer.GetRemainingSeconds(this.m_level.GetLogicTime());
                            }
                        }

                        freeCapacity -= housingSpace;
                        count        -= 1;
                    }

                    for (int j = 0; j < count; j++)
                    {
                        if (!slot.IsTerminate() && freeCapacity - housingSpace >= 0)
                        {
                            remainingSecs += data.GetTrainingTime(homeOwnerAvatar.GetUnitUpgradeLevel(data), this.m_level, 0);
                        }

                        freeCapacity -= housingSpace;
                    }
                }
            }

            return(remainingSecs);
        }
Пример #5
0
        public void SpeedUp()
        {
            LogicAvatar           homeOwnerAvatar  = this.m_level.GetHomeOwnerAvatar();
            LogicComponentManager componentManager = this.m_level.GetComponentManagerAt(this.m_villageType);

            int totalMaxHousing   = componentManager.GetTotalMaxHousing(this.m_unitProductionType != LogicDataType.CHARACTER ? 1 : 0);
            int totalUsedCapacity = this.m_unitProductionType == LogicDataType.CHARACTER ? homeOwnerAvatar.GetUnitsTotalCapacity() : homeOwnerAvatar.GetSpellsTotalCapacity();
            int freeCapacity      = totalMaxHousing - totalUsedCapacity;

            bool armyCampFull = false;

            while (!armyCampFull && this.m_slots.Size() > 0)
            {
                LogicUnitProductionSlot slot = this.m_slots[0];
                LogicCombatItemData     data = (LogicCombatItemData)slot.GetData();

                int count = slot.GetCount();

                if (count <= 0)
                {
                    break;
                }

                armyCampFull = true;

                do
                {
                    freeCapacity -= data.GetHousingSpace();

                    if (freeCapacity >= 0)
                    {
                        this.ProductionCompleted(true);
                        armyCampFull = false;
                    }
                } while (--count > 0);
            }
        }
Пример #6
0
        public void CalculateAvailableResources(LogicLevel level, int matchType)
        {
            for (int i = this.m_availableLootCount.Size() - 1; i >= 0; i--)
            {
                this.m_availableLootCount[i].Destruct();
                this.m_availableLootCount.Remove(i);
            }

            LogicDataTable resourceTable = LogicDataTables.GetTable(LogicDataType.RESOURCE);

            for (int i = 0; i < resourceTable.GetItemCount(); i++)
            {
                LogicResourceData data = (LogicResourceData)resourceTable.GetItemAt(i);
                LogicResourceData warResourceReferenceData = data.GetWarResourceReferenceData();
                LogicDataSlot     dataSlot = null;

                if (warResourceReferenceData != null)
                {
                    for (int j = 0; j < this.m_availableLootCount.Size(); j++)
                    {
                        if (this.m_availableLootCount[j].GetData() == warResourceReferenceData)
                        {
                            dataSlot = this.m_availableLootCount[j];
                            break;
                        }
                    }

                    Debugger.DoAssert(dataSlot != null, "Didn't find the resource slot");
                }
                else
                {
                    this.m_availableLootCount.Add(dataSlot = new LogicDataSlot(data, 0));
                }

                if (matchType == 8 || matchType == 9)
                {
                    LogicAvatar homeOwnerAvatar = level.GetHomeOwnerAvatar();

                    if (homeOwnerAvatar != null)
                    {
                        LogicArrayList <LogicDataSlot> resourceCount = homeOwnerAvatar.GetResources();

                        for (int j = 0; j < resourceCount.Size(); j++)
                        {
                            if (resourceCount[j].GetData() == data)
                            {
                                dataSlot.SetCount(resourceCount[j].GetCount());
                            }
                        }
                    }
                }
                else
                {
                    LogicComponentManager componentManager = level.GetComponentManagerAt(level.GetVillageType());

                    if (warResourceReferenceData == null)
                    {
                        LogicArrayList <LogicComponent> resourceProductionComponents = componentManager.GetComponents(LogicComponentType.RESOURCE_PRODUCTION);
                        LogicArrayList <LogicComponent> resourceStorageComponents    = componentManager.GetComponents(LogicComponentType.RESOURCE_STORAGE);

                        for (int j = 0; j < resourceProductionComponents.Size(); j++)
                        {
                            LogicResourceProductionComponent resourceProductionComponent = (LogicResourceProductionComponent)resourceProductionComponents[j];
                            LogicGameObject gameObject = resourceProductionComponent.GetParent();

                            if (gameObject.IsAlive() &&
                                resourceProductionComponent.IsEnabled())
                            {
                                if (resourceProductionComponent.GetResourceData() == data)
                                {
                                    dataSlot.SetCount(dataSlot.GetCount() + resourceProductionComponent.GetStealableResourceCount());
                                }
                            }
                        }

                        for (int j = 0; j < resourceStorageComponents.Size(); j++)
                        {
                            LogicResourceStorageComponent resourceStorageComponent = (LogicResourceStorageComponent)resourceStorageComponents[j];
                            LogicGameObject gameObject = resourceStorageComponent.GetParent();

                            if (gameObject.IsAlive() &&
                                resourceStorageComponent.IsEnabled())
                            {
                                dataSlot.SetCount(dataSlot.GetCount() + resourceStorageComponent.GetStealableResourceCount(i));
                            }
                        }
                    }
                    else
                    {
                        LogicArrayList <LogicComponent> warResourceStorageComponents = componentManager.GetComponents(LogicComponentType.WAR_RESOURCE_STORAGE);

                        for (int j = 0; j < warResourceStorageComponents.Size(); j++)
                        {
                            LogicWarResourceStorageComponent resourceWarStorageComponent = (LogicWarResourceStorageComponent)warResourceStorageComponents[j];
                            LogicGameObject gameObject = resourceWarStorageComponent.GetParent();

                            if (gameObject.IsAlive() &&
                                resourceWarStorageComponent.IsEnabled())
                            {
                                dataSlot.SetCount(dataSlot.GetCount() + resourceWarStorageComponent.GetStealableResourceCount(i));
                            }
                        }
                    }
                }
            }
        }
Пример #7
0
        public void MergeSlots()
        {
            LogicAvatar homeOwnerAvatar = this.m_level.GetHomeOwnerAvatar();

            if (this.m_slots.Size() > 0)
            {
                if (this.m_slots.Size() > 1)
                {
                    for (int i = 1; i < this.m_slots.Size(); i++)
                    {
                        LogicUnitProductionSlot slot1 = this.m_slots[i];
                        LogicUnitProductionSlot slot2 = this.m_slots[i - 1];

                        if (slot1.GetData() == slot2.GetData())
                        {
                            if (slot1.IsTerminate() == slot2.IsTerminate())
                            {
                                this.m_slots.Remove(i--);

                                slot2.SetCount(slot2.GetCount() + slot1.GetCount());
                                slot1.Destruct();
                                slot1 = null;
                            }
                        }
                    }
                }
            }

            LogicComponentManager componentManager = this.m_level.GetComponentManagerAt(this.m_villageType);

            int usedCapacity  = this.m_unitProductionType == LogicDataType.SPELL ? homeOwnerAvatar.GetSpellsTotalCapacity() : homeOwnerAvatar.GetUnitsTotalCapacity();
            int totalCapacity = componentManager.GetTotalMaxHousing(this.m_unitProductionType != LogicDataType.CHARACTER ? 1 : 0);
            int freeCapacity  = totalCapacity - usedCapacity;

            for (int i = 0, j = freeCapacity; i < this.m_slots.Size(); i++)
            {
                LogicUnitProductionSlot slot = this.m_slots[i];
                LogicCombatItemData     data = (LogicCombatItemData)slot.GetData();

                int count        = slot.GetCount();
                int housingSpace = data.GetHousingSpace() * count;

                if (j < housingSpace)
                {
                    if (count > 1)
                    {
                        int maxInProduction = j / data.GetHousingSpace();

                        if (maxInProduction > 0)
                        {
                            int inQueue = count - maxInProduction;

                            if (inQueue > 0)
                            {
                                slot.SetCount(maxInProduction);
                                this.m_slots.Add(i + 1, new LogicUnitProductionSlot(data, inQueue, slot.IsTerminate()));
                            }
                        }
                    }

                    break;
                }

                j -= housingSpace;
            }
        }
Пример #8
0
        public bool ProductionCompleted(bool speedUp)
        {
            bool success = false;

            if (!this.m_locked)
            {
                LogicComponentFilter filter = new LogicComponentFilter();

                filter.SetComponentType(0);

                while (true)
                {
                    LogicAvatar           homeOwnerAvatar  = this.m_level.GetHomeOwnerAvatar();
                    LogicComponentManager componentManager = this.m_level.GetComponentManagerAt(this.m_villageType);
                    LogicCombatItemData   productionData   = this.GetWaitingForSpaceUnit();

                    if (speedUp)
                    {
                        if (this.m_slots.Size() <= 0)
                        {
                            return(false);
                        }

                        productionData = (LogicCombatItemData)this.m_slots[0].GetData();
                    }

                    if (productionData == null)
                    {
                        filter.Destruct();
                        return(false);
                    }

                    bool productionTerminate = this.m_slots[0].IsTerminate();
                    LogicBuildingData      buildingProductionData = productionData.GetProductionHouseData();
                    LogicGameObjectManager gameObjectManager      = this.m_level.GetGameObjectManagerAt(this.m_villageType);
                    LogicBuilding          productionHouse        = gameObjectManager.GetHighestBuilding(buildingProductionData);

                    if (LogicDataTables.GetGlobals().UseTroopWalksOutFromTraining())
                    {
                        int gameObjectCount = gameObjectManager.GetNumGameObjects();

                        for (int i = 0; i < gameObjectCount; i++)
                        {
                            LogicGameObject gameObject = gameObjectManager.GetGameObjectByIndex(i);

                            if (gameObject.GetGameObjectType() == LogicGameObjectType.BUILDING)
                            {
                                LogicBuilding building = (LogicBuilding)gameObject;
                                LogicUnitProductionComponent unitProductionComponent = building.GetUnitProductionComponent();

                                if (unitProductionComponent != null)
                                {
                                    if (unitProductionComponent.GetProductionType() == productionData.GetCombatItemType())
                                    {
                                        if (building.GetBuildingData().GetProducesUnitsOfType() == productionData.GetUnitOfType() &&
                                            !building.IsUpgrading() &&
                                            !building.IsConstructing())
                                        {
                                            if (productionData.IsUnlockedForProductionHouseLevel(building.GetUpgradeLevel()))
                                            {
                                                if (productionHouse != null)
                                                {
                                                    int seed = this.m_level.GetPlayerAvatar().GetExpPoints();

                                                    if (building.Rand(seed) % 1000 > 750)
                                                    {
                                                        productionHouse = building;
                                                    }
                                                }
                                                else
                                                {
                                                    productionHouse = building;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }

                    if (productionHouse != null)
                    {
                        LogicUnitStorageComponent unitStorageComponent =
                            (LogicUnitStorageComponent)componentManager.GetClosestComponent(productionHouse.GetX(), productionHouse.GetY(), filter);

                        if (unitStorageComponent != null)
                        {
                            if (unitStorageComponent.CanAddUnit(productionData))
                            {
                                homeOwnerAvatar.CommodityCountChangeHelper(0, productionData, 1);
                                unitStorageComponent.AddUnit(productionData);

                                if (productionTerminate)
                                {
                                    this.RemoveUnit(productionData, -1);
                                }
                                else
                                {
                                    this.StartProducingNextUnit();
                                }

                                success = true;

                                if (this.m_slots.Size() > 0 && this.m_slots[0].IsTerminate() && this.m_slots[0].GetCount() > 0)
                                {
                                    continue;
                                }

                                break;
                            }

                            filter.AddIgnoreObject(unitStorageComponent.GetParent());
                        }
                        else
                        {
                            if (this.m_timer != null && this.m_timer.GetRemainingSeconds(this.m_level.GetLogicTime()) == 0)
                            {
                                success = this.TrainingFinished();
                            }

                            break;
                        }
                    }
                    else
                    {
                        break;
                    }
                }

                filter.Destruct();

                if (success)
                {
                    this.m_nextProduction = 0;
                }
                else
                {
                    this.m_nextProduction = 2000;
                }
            }

            return(success);
        }
        public override int Execute(LogicLevel level)
        {
            this.m_level = level;

            if (LogicDataTables.GetGlobals().EnablePresets())
            {
                LogicAvatar homeOwnerAvatar = level.GetHomeOwnerAvatar();

                if (homeOwnerAvatar.GetTownHallLevel() >= LogicDataTables.GetGlobals().GetEnablePresetsTownHallLevel())
                {
                    if (this.m_presetId <= 3)
                    {
                        LogicDataTable        table            = LogicDataTables.GetTable(LogicDataType.CHARACTER);
                        LogicComponentManager componentManager = level.GetComponentManager();

                        int totalMaxHousing = componentManager.GetTotalMaxHousing(0);

                        for (int i = 0, housingSpace = 0; i < table.GetItemCount(); i++)
                        {
                            LogicCharacterData data = (LogicCharacterData)table.GetItemAt(i);

                            if (level.GetGameMode().GetCalendar().IsProductionEnabled(data) && !data.IsSecondaryTroop())
                            {
                                int count = 0;

                                if (this.m_slots.Size() > 0)
                                {
                                    for (int j = 0; j < this.m_slots.Size(); j++)
                                    {
                                        if (this.m_slots[j].GetData() == data)
                                        {
                                            count = this.m_slots[j].GetCount();
                                            break;
                                        }
                                    }
                                }

                                housingSpace += count * data.GetHousingSpace();

                                if (housingSpace > totalMaxHousing || !this.IsUnlocked(data))
                                {
                                    this.SetUnitPresetCount(data, 0);
                                }
                                else
                                {
                                    this.SetUnitPresetCount(data, count);
                                }
                            }
                        }

                        table           = LogicDataTables.GetTable(LogicDataType.SPELL);
                        totalMaxHousing = componentManager.GetTotalMaxHousing(0);

                        for (int i = 0, housingSpace = 0; i < table.GetItemCount(); i++)
                        {
                            LogicSpellData data = (LogicSpellData)table.GetItemAt(i);

                            if (level.GetGameMode().GetCalendar().IsProductionEnabled(data))
                            {
                                int count = 0;

                                if (this.m_slots.Size() > 0)
                                {
                                    for (int j = 0; j < this.m_slots.Size(); j++)
                                    {
                                        if (this.m_slots[j].GetData() == data)
                                        {
                                            count = this.m_slots[j].GetCount();
                                            break;
                                        }
                                    }
                                }

                                housingSpace += count * data.GetHousingSpace();

                                if (housingSpace > totalMaxHousing || !this.IsUnlocked(data))
                                {
                                    this.SetUnitPresetCount(data, 0);
                                }
                                else
                                {
                                    this.SetUnitPresetCount(data, count);
                                }
                            }
                        }

                        return(0);
                    }

                    return(-2);
                }
            }

            return(-1);
        }