/// <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; } }
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); }
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; } }
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); } }
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); }
public bool HasEnoughFreeHousingSpace() { LogicCalendar calendar = this.m_level.GetCalendar(); LogicAvatar homeOwnerAvatar = this.m_level.GetHomeOwnerAvatar(); LogicUnitProduction unitProduction = this.m_level.GetGameObjectManagerAt(0).GetUnitProduction(); LogicDataTable characterTable = LogicDataTables.GetTable(LogicDataType.CHARACTER); int freeHousingSpace = unitProduction.GetMaxTrainCount() - (homeOwnerAvatar.GetUnitsTotalCapacity() - unitProduction.GetTotalCount()); int requiredHousingSpace = 0; for (int i = 0; i < characterTable.GetItemCount(); i++) { LogicCharacterData data = (LogicCharacterData)characterTable.GetItemAt(i); if (calendar.IsProductionEnabled(data) && !data.IsSecondaryTroop()) { int count = homeOwnerAvatar.GetUnitPresetCount(data, this.m_presetId); if (count > 0) { requiredHousingSpace += data.GetHousingSpace() * count; } } } if (requiredHousingSpace <= freeHousingSpace) { LogicUnitProduction spellProduction = this.m_level.GetGameObjectManagerAt(0).GetSpellProduction(); LogicDataTable spellTable = LogicDataTables.GetTable(LogicDataType.SPELL); int freeSpellHousingSpace = spellProduction.GetMaxTrainCount() - (homeOwnerAvatar.GetSpellsTotalCapacity() - spellProduction.GetTotalCount()); int requiredSpellHousingSpace = 0; for (int i = 0; i < spellTable.GetItemCount(); i++) { LogicSpellData data = (LogicSpellData)spellTable.GetItemAt(i); if (calendar.IsProductionEnabled(data)) { int count = homeOwnerAvatar.GetUnitPresetCount(data, this.m_presetId); if (count > 0) { requiredSpellHousingSpace += data.GetHousingSpace() * count; } } } return(requiredSpellHousingSpace <= freeSpellHousingSpace); } return(false); }
/// <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; } } }