public override void Execute(Level level) { ClientAvatar avatar = level.GetPlayerAvatar(); if (UnitType.ToString().StartsWith("400")) { CombatItemData _TroopData = (CombatItemData)CSVManager.DataTables.GetDataById(UnitType); List <DataSlot> units = level.GetPlayerAvatar().GetUnits(); ResourceData trainingResource = _TroopData.GetTrainingResource(); if (_TroopData == null) { return; } DataSlot dataSlot1 = units.Find((Predicate <DataSlot>)(t => t.Data.GetGlobalID() == _TroopData.GetGlobalID())); if (dataSlot1 != null) { dataSlot1.Value = dataSlot1.Value + Count; } else { DataSlot dataSlot2 = new DataSlot((Data)_TroopData, Count); units.Add(dataSlot2); } avatar.SetResourceCount(trainingResource, avatar.GetResourceCount(trainingResource) - _TroopData.GetTrainingCost(avatar.GetUnitUpgradeLevel(_TroopData))); } else { if (!this.UnitType.ToString().StartsWith("260")) { return; } SpellData _SpellData = (SpellData)CSVManager.DataTables.GetDataById(UnitType); List <DataSlot> spells = level.GetPlayerAvatar().GetSpells(); ResourceData trainingResource = _SpellData.GetTrainingResource(); if (_SpellData == null) { return; } DataSlot dataSlot1 = spells.Find((Predicate <DataSlot>)(t => t.Data.GetGlobalID() == _SpellData.GetGlobalID())); if (dataSlot1 != null) { dataSlot1.Value = dataSlot1.Value + Count; } else { DataSlot dataSlot2 = new DataSlot((Data)_SpellData, Count); spells.Add(dataSlot2); } avatar.SetResourceCount(trainingResource, avatar.GetResourceCount(trainingResource) - _SpellData.GetTrainingCost(avatar.GetUnitUpgradeLevel((CombatItemData)_SpellData))); } }
internal override void Process() { ClientAvatar _Player = this.Device.Player.Avatar; if (UnitType.ToString().StartsWith("400")) { CombatItemData _TroopData = (CombatItemData)CSVManager.DataTables.GetDataById(UnitType); List <DataSlot> _PlayerUnits = this.Device.Player.Avatar.GetUnits(); ResourceData _TrainingResource = _TroopData.GetTrainingResource(); if (_TroopData != null) { DataSlot _DataSlot = _PlayerUnits.Find(t => t.Data.GetGlobalID() == _TroopData.GetGlobalID()); if (_DataSlot != null) { _DataSlot.Value = _DataSlot.Value + this.Count; } else { DataSlot ds = new DataSlot(_TroopData, this.Count); _PlayerUnits.Add(ds); } _Player.SetResourceCount(_TrainingResource, _Player.GetResourceCount(_TrainingResource) - _TroopData.GetTrainingCost(_Player.GetUnitUpgradeLevel(_TroopData))); } } else if (UnitType.ToString().StartsWith("260")) { SpellData _SpellData = (SpellData)CSVManager.DataTables.GetDataById(UnitType); List <DataSlot> _PlayerSpells = this.Device.Player.Avatar.GetSpells(); ResourceData _CastResource = _SpellData.GetTrainingResource(); if (_SpellData != null) { DataSlot _DataSlot = _PlayerSpells.Find(t => t.Data.GetGlobalID() == _SpellData.GetGlobalID()); if (_DataSlot != null) { _DataSlot.Value = _DataSlot.Value + this.Count; } else { DataSlot ds = new DataSlot(_SpellData, this.Count); _PlayerSpells.Add(ds); } _Player.SetResourceCount(_CastResource, _Player.GetResourceCount(_CastResource) - _SpellData.GetTrainingCost(_Player.GetUnitUpgradeLevel(_SpellData))); } } }