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); }
public void TrainUnits() { LogicAvatar homeOwnerAvatar = this.m_level.GetHomeOwnerAvatar(); LogicDataTable characterTable = LogicDataTables.GetTable(LogicDataType.CHARACTER); LogicDataTable spellTable = LogicDataTables.GetTable(LogicDataType.SPELL); LogicArrayList <LogicCombatItemData> productionUnits = new LogicArrayList <LogicCombatItemData>(characterTable.GetItemCount()); LogicArrayList <LogicCombatItemData> productionSpells = new LogicArrayList <LogicCombatItemData>(spellTable.GetItemCount()); for (int i = 0; i < characterTable.GetItemCount(); i++) { LogicCharacterData data = (LogicCharacterData)characterTable.GetItemAt(i); if (this.m_level.GetCalendar().IsProductionEnabled(data) && !data.IsSecondaryTroop()) { productionUnits.Add(data); } } this.SortProduction(productionUnits); for (int i = 0; i < productionUnits.Size(); i++) { int unitCount = homeOwnerAvatar.GetUnitPresetCount(productionUnits[i], this.m_presetId); if (unitCount > 0) { this.AddUnitsToQueue(productionUnits[i], unitCount); } } for (int i = 0; i < spellTable.GetItemCount(); i++) { LogicSpellData data = (LogicSpellData)spellTable.GetItemAt(i); if (this.m_level.GetCalendar().IsProductionEnabled(data)) { productionSpells.Add(data); } } this.SortProduction(productionSpells); for (int i = 0; i < productionSpells.Size(); i++) { int spellCount = homeOwnerAvatar.GetUnitPresetCount(productionSpells[i], this.m_presetId); if (spellCount > 0) { this.AddUnitsToQueue(productionSpells[i], spellCount); } } }
public int GetResourceCost(LogicResourceData resourceData) { int cost = 0; LogicAvatar homeOwnerAvatar = this.m_level.GetHomeOwnerAvatar(); LogicCalendar calendar = this.m_level.GetCalendar(); LogicDataTable table = LogicDataTables.GetTable(LogicDataType.CHARACTER); for (int i = 0; i < table.GetItemCount(); i++) { LogicCharacterData data = (LogicCharacterData)table.GetItemAt(i); if (calendar.IsProductionEnabled(data) && !data.IsSecondaryTroop()) { int count = homeOwnerAvatar.GetUnitPresetCount(data, this.m_presetId); if (count > 0) { if (data.GetTrainingResource() == resourceData) { cost += count * calendar.GetTrainingCost(data, homeOwnerAvatar.GetUnitUpgradeLevel(data)); } } } } table = LogicDataTables.GetTable(LogicDataType.SPELL); for (int i = 0; i < table.GetItemCount(); i++) { LogicSpellData data = (LogicSpellData)table.GetItemAt(i); if (calendar.IsProductionEnabled(data)) { int count = homeOwnerAvatar.GetUnitPresetCount(data, this.m_presetId); if (count > 0) { if (data.GetTrainingResource() == resourceData) { cost += count * calendar.GetTrainingCost(data, homeOwnerAvatar.GetUnitUpgradeLevel(data)); } } } } return(cost); }
public void SetUnitPresetCount(LogicCombatItemData data, int count) { LogicAvatar homeOwnerAvatar = this.m_level.GetHomeOwnerAvatar(); if (homeOwnerAvatar.GetUnitPresetCount(data, this.m_presetId) != count) { homeOwnerAvatar.SetUnitPresetCount(data, this.m_presetId, count); homeOwnerAvatar.GetChangeListener().CommodityCountChanged(3, data, count); } }