public void AddUnitsToQueue(LogicCombatItemData data, int count) { LogicCalendar calendar = this.m_level.GetCalendar(); LogicAvatar homeOwnerAvatar = this.m_level.GetHomeOwnerAvatar(); LogicClientAvatar playerAvatar = this.m_level.GetPlayerAvatar(); LogicGameObjectManager gameObjectManager = this.m_level.GetGameObjectManagerAt(0); LogicUnitProduction production = gameObjectManager.GetUnitProduction(); if (data.GetCombatItemType() != LogicCombatItemData.COMBAT_ITEM_TYPE_CHARACTER) { if (data.GetCombatItemType() != LogicCombatItemData.COMBAT_ITEM_TYPE_SPELL) { return; } production = gameObjectManager.GetSpellProduction(); } if (production != null) { int trainCost = calendar.GetTrainingCost(data, homeOwnerAvatar.GetUnitUpgradeLevel(data)); for (int i = 0; i < count; i++) { if (production.CanAddUnitToQueue(data, true) && playerAvatar.HasEnoughResources(data.GetTrainingResource(), trainCost, false, null, false)) { playerAvatar.CommodityCountChangeHelper(0, data.GetTrainingResource(), -trainCost); production.AddUnitToQueue(data, production.GetSlotCount(), true); } } } }
public override int Execute(LogicLevel level) { if (LogicDataTables.GetGlobals().UseNewTraining()) { if (!LogicDataTables.GetGlobals().UseDragInTraining() && !LogicDataTables.GetGlobals().UseDragInTrainingFix() && !LogicDataTables.GetGlobals().UseDragInTrainingFix2()) { return(-51); } LogicUnitProduction unitProduction = this.m_spellProduction ? level.GetGameObjectManager().GetSpellProduction() : level.GetGameObjectManager().GetUnitProduction(); if (unitProduction.GetSlotCount() > this.m_slotIdx) { if (unitProduction.GetSlotCount() >= this.m_dragIdx) { if (this.m_slotIdx >= 0) { if (this.m_dragIdx >= 0) { return(unitProduction.DragSlot(this.m_slotIdx, this.m_dragIdx) ? 0 : -5); } return(-4); } return(-3); } return(-2); } return(-1); } return(-50); }
public int NewTrainingUnit(LogicLevel level) { if (LogicDataTables.GetGlobals().UseNewTraining()) { if (this.m_trainCount <= 100) { LogicUnitProduction unitProduction = this.m_unitType == 1 ? level.GetGameObjectManagerAt(0).GetSpellProduction() : level.GetGameObjectManagerAt(0).GetUnitProduction(); if (this.m_trainCount > 0) { if (this.m_unitData != null) { LogicClientAvatar playerAvatar = level.GetPlayerAvatar(); bool firstLoopExecuted = false; int trainingCost = level.GetGameMode().GetCalendar().GetTrainingCost(this.m_unitData, playerAvatar.GetUnitUpgradeLevel(this.m_unitData)); for (int i = 0; i < this.m_trainCount; i++) { if (!unitProduction.CanAddUnitToQueue(this.m_unitData, false)) { if (firstLoopExecuted) { break; } return(-40); } if (!playerAvatar.HasEnoughResources(this.m_unitData.GetTrainingResource(), trainingCost, true, this, false)) { if (firstLoopExecuted) { break; } return(-30); } playerAvatar.CommodityCountChangeHelper(0, this.m_unitData.GetTrainingResource(), -trainingCost); if (this.m_slotId == -1) { this.m_slotId = unitProduction.GetSlotCount(); } unitProduction.AddUnitToQueue(this.m_unitData, this.m_slotId, false); firstLoopExecuted = true; } return(0); } } return(-50); } Debugger.Error("LogicTraingUnitCommand - Count is too high"); return(-20); } return(-99); }