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 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 bool IsUnlocked(LogicCombatItemData data) { return(data.IsUnlockedForProductionHouseLevel(this.m_level.GetGameObjectManager().GetHighestBuildingLevel(data.GetProductionHouseData()))); }