public override void Execute(Level level) { foreach (var unit in UnitsToRemove) { List <Component> components = level.GetComponentManager().GetComponents(0); for (int i = 0; i < components.Count; i++) { UnitStorageComponent c = (UnitStorageComponent)components[i]; if (c.GetUnitTypeIndex(unit.Data) != -1) { var storageCount = c.GetUnitCountByData(unit.Data); if (storageCount >= unit.Count) { c.RemoveUnits(unit.Data, unit.Count); break; } else { c.RemoveUnits(unit.Data, storageCount); unit.Count -= storageCount; } } } } }
internal void AddRewardUnits() { // this.Level.Player.Units.Add(this.MissionData.RewardCharacterData, this.MissionData.RewardTroopCount); if (this.MissionData.RewardCharacterData != null) { if (this.MissionData.RewardTroopCount > 0) { int RewardCount = this.MissionData.RewardTroopCount; List <Component> UnitStorages = this.Level.ComponentManager.FindAll(0, Component => Component.Type == 0); for (int i = UnitStorages.Count; i > 0; i--) { UnitStorageComponent Component = (UnitStorageComponent)ComponentManager.GetClosestComponent(0, 0, UnitStorages); while (Component.CanAddUnit(this.MissionData)) { this.Level.Player.Units.Add(this.MissionData.RewardCharacterData, 1); Component.AddUnit(this.MissionData.RewardCharacterData); if (--RewardCount <= 0) { return; } } UnitStorages.Remove(Component); } } } }
/// <summary> /// Executes this command. /// </summary> /// <param name="Level">The levl.</param> internal override void Execute(Level Level) { if (Level.Player.Home.GameObjectManager.GetGameObjectById(this.BoatID) is Building Building) { CharacterData UnitData = (CharacterData)this.UnitData; UnitProductionComponent UnitProductionComponent = (UnitProductionComponent)Building.GetComponent(3); UnitStorageComponent UnitStorageComponent = (UnitStorageComponent)Building.GetComponent(0); if (UnitProductionComponent != null && UnitStorageComponent != null) { CharacterData PreviousUnitData = null; int PreviousUnitCount = 0; ResourceBundle ResourceBundle = UnitData.GetResourceBundle(Level.Player.UnitUpgrades.GetCount(this.UnitData)); if (UnitStorageComponent.HasUnits) { PreviousUnitData = UnitStorageComponent.Unit; PreviousUnitCount += UnitStorageComponent.UnitCount; if (PreviousUnitData != this.UnitData) { ResourceBundle.Removes(1, PreviousUnitData.GetResourceBundle(Level.Player.UnitUpgrades.GetCount(PreviousUnitData)).Resources[1].Count); UnitStorageComponent.Unit = null; UnitStorageComponent.UnitCount = 0; PreviousUnitData = null; PreviousUnitCount = 0; } } int TrainCount = UnitStorageComponent.MaxCapacity / UnitData.HousingSpace - PreviousUnitCount; if (TrainCount > 0) { ResourceBundle.Multiply(TrainCount); if (Level.Player.HasEnoughResources(ResourceBundle)) { Level.Player.Resources.Remove(ResourceBundle.Resources[1].Data, ResourceBundle.Resources[1].Count); } } } } }
public override void Execute(Level level) { List <Component> components = level.GetComponentManager().GetComponents(0); for (int i = 0; i < components.Count; i++) { UnitStorageComponent c = (UnitStorageComponent)components[i]; if (c.GetUnitTypeIndex(Unit) != -1) { var storageCount = c.GetUnitCountByData(Unit); if (storageCount >= 1) { c.RemoveUnits(Unit, 1); break; } } } }