public void AddRewardUnits() { LogicCharacterData characterData = this.m_data.GetRewardCharacterData(); if (characterData != null) { int characterCount = this.m_data.GetRewardCharacterCount(); if (characterCount > 0) { LogicClientAvatar playerAvatar = this.m_level.GetPlayerAvatar(); LogicComponentFilter filter = new LogicComponentFilter(); for (int i = 0; i < characterCount; i++) { filter.RemoveAllIgnoreObjects(); while (true) { LogicUnitStorageComponent component = (LogicUnitStorageComponent)this.m_level.GetComponentManagerAt(this.m_level.GetVillageType()).GetClosestComponent(0, 0, filter); if (component != null) { if (component.CanAddUnit(characterData)) { playerAvatar.CommodityCountChangeHelper(0, characterData, 1); component.AddUnit(characterData); if (this.m_level.GetState() == 1 || this.m_level.GetState() == 3) { if (component.GetParentListener() != null) { component.GetParentListener().ExtraCharacterAdded(characterData, null); } } break; } filter.AddIgnoreObject(component.GetParent()); } else { break; } } } } } }
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) { LogicClientAvatar playerAvatar = level.GetPlayerAvatar(); if (playerAvatar != null) { if (this.m_unitData != null) { if (this.m_unitData.GetVillageType() == 0) { if (!this.m_unitData.IsDonationDisabled()) { bool containsUnit = false; int upgLevel = playerAvatar.GetUnitUpgradeLevel(this.m_unitData); LogicUnitProductionComponent unitProductionComponent = null; if (this.m_quickDonate) { int cost = this.m_unitData.GetDonateCost(); if (!playerAvatar.HasEnoughDiamonds(cost, true, level) || !LogicDataTables.GetGlobals().EnableQuickDonateWar()) { playerAvatar.GetChangeListener().WarDonateFailed(this.m_unitData, upgLevel, this.m_streamId, this.m_quickDonate); return(0); } } else { LogicGameObjectManager gameObjectManager = level.GetGameObjectManagerAt(0); if (LogicDataTables.GetGlobals().UseNewTraining()) { LogicUnitProduction unitProduction = gameObjectManager.GetUnitProduction(); LogicUnitProduction spellProduction = gameObjectManager.GetSpellProduction(); if (unitProduction.GetWaitingForSpaceUnitCount(this.m_unitData) > 0) { if (unitProduction.GetUnitProductionType() == this.m_unitData.GetDataType()) { containsUnit = true; } } if (spellProduction.GetWaitingForSpaceUnitCount(this.m_unitData) > 0) { if (spellProduction.GetUnitProductionType() == this.m_unitData.GetDataType()) { containsUnit = true; } } } else { for (int i = 0, c = gameObjectManager.GetNumGameObjects(); i < c; i++) { LogicGameObject gameObject = gameObjectManager.GetGameObjectByIndex(i); if (gameObject.GetGameObjectType() == LogicGameObjectType.BUILDING) { LogicBuilding building = (LogicBuilding)gameObject; LogicUnitProductionComponent component = building.GetUnitProductionComponent(); if (component != null) { unitProductionComponent = component; if (component.ContainsUnit(this.m_unitData)) { if (component.GetRemainingSeconds() == 0 && component.GetCurrentlyTrainedUnit() == this.m_unitData) { containsUnit = true; } } else { unitProductionComponent = null; } } } } } if (!containsUnit) { if (playerAvatar.GetUnitCount(this.m_unitData) <= 0) { playerAvatar.GetChangeListener().WarDonateFailed(this.m_unitData, upgLevel, this.m_streamId, this.m_quickDonate); return(0); } } } if (this.m_unitData.GetCombatItemType() != LogicCombatItemData.COMBAT_ITEM_TYPE_CHARACTER) { playerAvatar.XpGainHelper(this.m_unitData.GetHousingSpace() * LogicDataTables.GetGlobals().GetDarkSpellDonationXP()); level.GetAchievementManager().AlianceSpellDonated((LogicSpellData)this.m_unitData); } else { playerAvatar.XpGainHelper(((LogicCharacterData)this.m_unitData).GetDonateXP()); level.GetAchievementManager().AlianceUnitDonated((LogicCharacterData)this.m_unitData); } playerAvatar.GetChangeListener().WarDonateOk(this.m_unitData, upgLevel, this.m_streamId, this.m_quickDonate); if (this.m_quickDonate) { int cost = this.m_unitData.GetDonateCost(); playerAvatar.UseDiamonds(cost); playerAvatar.GetChangeListener().DiamondPurchaseMade(12, this.m_unitData.GetGlobalID(), 0, cost, level.GetVillageType()); if (level.GetState() == 1 || level.GetState() == 3 && this.m_unitData.GetCombatItemType() == LogicCombatItemData.COMBAT_ITEM_TYPE_CHARACTER) { // TODO: Finish this. } } else { if (!containsUnit) { playerAvatar.CommodityCountChangeHelper(0, this.m_unitData, -1); } LogicResourceData trainingResource = this.m_unitData.GetTrainingResource(); int trainingCost = level.GetGameMode().GetCalendar().GetTrainingCost(this.m_unitData, upgLevel); int refund = playerAvatar.GetTroopDonationRefund() * trainingCost / 100; playerAvatar.CommodityCountChangeHelper(0, trainingResource, LogicMath.Max(refund, 0)); if (level.GetState() == 1 || level.GetState() == 3) { if (containsUnit) { if (LogicDataTables.GetGlobals().UseNewTraining()) { LogicGameObjectManager gameObjectManager = level.GetGameObjectManagerAt(0); LogicUnitProduction unitProduction = this.m_unitData.GetCombatItemType() != LogicCombatItemData.COMBAT_ITEM_TYPE_CHARACTER ? gameObjectManager.GetSpellProduction() : gameObjectManager.GetUnitProduction(); unitProduction.RemoveTrainedUnit(this.m_unitData); } if (this.m_unitData.GetCombatItemType() == LogicCombatItemData.COMBAT_ITEM_TYPE_CHARACTER) { LogicBuilding productionHouse = null; if (unitProductionComponent != null) { productionHouse = (LogicBuilding)unitProductionComponent.GetParent(); } else { if (LogicDataTables.GetGlobals().UseTroopWalksOutFromTraining()) { LogicGameObjectManager gameObjectManager = level.GetGameObjectManagerAt(0); int gameObjectCount = gameObjectManager.GetNumGameObjects(); for (int i = 0; i < gameObjectCount; i++) { LogicGameObject gameObject = gameObjectManager.GetGameObjectByIndex(i); if (gameObject != null && gameObject.GetGameObjectType() == LogicGameObjectType.BUILDING) { LogicBuilding tmpBuilding = (LogicBuilding)gameObject; LogicUnitProductionComponent tmpComponent = tmpBuilding.GetUnitProductionComponent(); if (tmpComponent != null) { if (tmpComponent.GetProductionType() == this.m_unitData.GetCombatItemType()) { if (tmpBuilding.GetBuildingData().GetProducesUnitsOfType() == this.m_unitData.GetUnitOfType() && !tmpBuilding.IsUpgrading() && !tmpBuilding.IsConstructing()) { if (this.m_unitData.IsUnlockedForProductionHouseLevel(tmpBuilding.GetUpgradeLevel())) { if (productionHouse != null) { int seed = playerAvatar.GetExpPoints(); if (tmpBuilding.Rand(seed) % 1000 > 750) { productionHouse = tmpBuilding; } } else { productionHouse = tmpBuilding; } } } } } } } } } if (productionHouse != null) { // TODO: Implement listener. } } } else { LogicArrayList <LogicComponent> components = level.GetComponentManagerAt(0).GetComponents(LogicComponentType.UNIT_STORAGE); for (int i = 0; i < components.Size(); i++) { LogicUnitStorageComponent unitStorageComponent = (LogicUnitStorageComponent)components[i]; int idx = unitStorageComponent.GetUnitTypeIndex(this.m_unitData); if (idx != -1) { if (unitStorageComponent.GetUnitCount(idx) > 0) { unitStorageComponent.RemoveUnits(this.m_unitData, 1); if (LogicDataTables.GetGlobals().UseNewTraining()) { LogicGameObjectManager gameObjectManager = level.GetGameObjectManagerAt(0); LogicUnitProduction unitProduction = this.m_unitData.GetCombatItemType() != LogicCombatItemData.COMBAT_ITEM_TYPE_CHARACTER ? gameObjectManager.GetSpellProduction() : gameObjectManager.GetUnitProduction(); unitProduction.MergeSlots(); unitProduction.UnitRemoved(); } break; } } } } // TODO: Finish this. } } return(0); } return(-91); } return(-45); } } return(0); }
/// <summary> /// Executes this instance. /// </summary> public override int Execute(LogicLevel level) { for (int i = 0; i < this._unitsCount.Count; i++) { if (this._unitsCount[i] < 0) { return(-1); } } if (LogicDataTables.GetGlobals().EnableTroopDeletion() && level.GetState() == 1 && this._unitsData.Count > 0) { LogicClientAvatar playerAvatar = level.GetPlayerAvatar(); Int32 removedUnits = 0; for (int i = 0; i < this._unitsData.Count; i++) { LogicCombatItemData data = this._unitsData[i]; Int32 unitCount = this._unitsCount[i]; if (this._removeType[i] != 0) { Int32 upgLevel = this._unitsUpgLevel[i]; if (data.GetCombatItemType() != 0) { if (data.GetCombatItemType() == 1) { playerAvatar.SetAllianceUnitCount(data, upgLevel, LogicMath.Max(0, playerAvatar.GetAllianceUnitCount(data, upgLevel) - unitCount)); if (unitCount > 0) { do { playerAvatar.GetChangeListener().AllianceUnitRemoved(data, upgLevel); } while (--unitCount != 0); } removedUnits |= 2; } } else { LogicBuilding allianceCastle = level.GetGameObjectManagerAt(0).GetAllianceCastle(); if (allianceCastle != null) { LogicBunkerComponent bunkerComponent = allianceCastle.GetBunkerComponent(); Int32 unitTypeIndex = bunkerComponent.GetUnitTypeIndex(data); if (unitTypeIndex != -1) { Int32 cnt = bunkerComponent.GetUnitCount(unitTypeIndex); if (cnt > 0) { bunkerComponent.RemoveUnits(data, upgLevel, cnt); playerAvatar.SetAllianceUnitCount(data, upgLevel, LogicMath.Max(0, playerAvatar.GetAllianceUnitCount(data, upgLevel) - unitCount)); removedUnits |= 1; if (unitCount > 0) { do { playerAvatar.GetChangeListener().AllianceUnitRemoved(data, upgLevel); } while (--unitCount != 0); } } } } } } else { if (playerAvatar != null && data != null) { playerAvatar.CommodityCountChangeHelper(0, data, -unitCount); } LogicArrayList <LogicComponent> components = level.GetComponentManager().GetComponents(0); for (int j = 0; j < components.Count; j++) { if (unitCount > 0) { LogicUnitStorageComponent storageComponent = (LogicUnitStorageComponent)components[j]; Int32 unitTypeIndex = storageComponent.GetUnitTypeIndex(data); if (unitTypeIndex != -1) { Int32 cnt = storageComponent.GetUnitCount(unitTypeIndex); if (cnt > 0) { cnt = LogicMath.Min(cnt, unitCount); storageComponent.RemoveUnits(data, cnt); int type = 2; if (data.GetCombatItemType() == 0) { if (storageComponent.GetParentListener() != null) { LogicGameObjectListener listener = storageComponent.GetParentListener(); for (int k = 0; k < cnt; k++) { listener.UnitRemoved(data); } } type = 1; } unitCount -= cnt; removedUnits |= type; } } } } } } switch (removedUnits) { case 3: if (LogicDataTables.GetGlobals().UseNewTraining()) { level.GetGameObjectManager().GetUnitProduction().MergeSlots(); level.GetGameObjectManager().GetSpellProduction().MergeSlots(); } break; case 2: if (LogicDataTables.GetGlobals().UseNewTraining()) { level.GetGameObjectManager().GetSpellProduction().MergeSlots(); } break; case 1: if (LogicDataTables.GetGlobals().UseNewTraining()) { level.GetGameObjectManager().GetUnitProduction().MergeSlots(); } break; default: Debugger.Print("WTF: " + removedUnits); break; } } return(0); }