public void AddArmy(ArmyVO army) { foreach (var armyVo in Defender.armies) { if (armyVo.cid == army.cid) { armyVo.amount += army.amount; ChangeArmyExp(army); return; } } Defender.armies.Add(army); ChangeArmyExp(army); }
private void ChangeArmyExp(ArmyVO army) { //判断当前的兵能不能加经验 if (!ItemOperationManager.Instance.IsItemCanLevelUp(army.cid)) { return; } List <ArmyExpVO> list = Defender.player.armyShop; EntityModel nextModel = ModelUtil.GetNextLevelModel(army.cid); //升级到的Id int levelUpId = 0; foreach (ArmyExpVO expVo in list) { if (expVo.cid == army.cid) { expVo.exp += army.amount; //可能跳跃升级 while (null != nextModel && expVo.exp >= nextModel.costResourceCount) { expVo.cid = nextModel.baseId; levelUpId = nextModel.baseId; nextModel = ModelUtil.GetNextLevelModel(nextModel.baseId); } break; } } if (levelUpId != 0) { foreach (var armyVo in Defender.armies) { if (armyVo.cid == army.cid) { armyVo.cid = levelUpId; break; } } EventDispather.DispatherEvent(GameEvents.SOLDIER_UP, army.cid); } else { EventDispather.DispatherEvent(GameEvents.SOLDIER_COUNT_CHANGE, army.cid); } }
public override void OnCompleteProductionImmediately() { DataCenter.Instance.SpaceUsed += CurrentQueueSize; var newViewActors = new List <ArmyVO>(); foreach (var productionItem in ProductionItems) { var army = new ArmyVO() { amount = productionItem.count, cid = productionItem.cid }; DataCenter.Instance.AddArmy(army); newViewActors.Add(army); } ProductionItems.Clear(); int diamond = GameDataAlgorithm.TimeToGem(TotalTimeLeft); EndTime = System.DateTime.MinValue; CoroutineHelper.Run(CreateViewActors(newViewActors)); new ProductionRequestCommand(ProductionReq.ProductionRequestType.CompleteImmediately, Entity.buildingVO, null, diamond).ExecuteAndSend(); }