/// <summary> /// 单位进阶 /// </summary> public int Call_UnitGradeUp(ClazupUnitRequest request) { ClazupUnitResponse response = new ClazupUnitResponse(); response.id = request.id; var player = CurrentSession.GetBindPlayer(); Unit unit = player.Units.First(x => x.Id == request.id); DUnit du = DUnits[unit.Tid]; int maxClaz = du.grade_max; int itemId = du.grade_item_id; if (unit.Grade >= du.grade_max) { return((int)GameErrorCode.兵种已经最高阶); } DUnitGradeUp dug = DUnitGrades[du.star][unit.Grade + 1]; if (unit.Level < dug.min_level) { return((int)GameErrorCode.兵种不满足升阶等级);; } int itemCount = dug.item_cnt; var pkgController = Server.GetController <PkgController>(); var playerController = Server.GetController <PlayerController>(); string reason = $"兵种进阶{du.tid}"; if (playerController.IsCurrencyEnough(player, CurrencyType.GOLD, dug.gold)) { if (pkgController.TrySubItem(player, itemId, itemCount, reason, out var item)) { playerController.AddCurrency(player, CurrencyType.GOLD, -dug.gold, reason); unit.Grade += 1; response.unitInfo = this.ToUnitInfo(unit, du, true); response.gold = playerController.GetCurrencyValue(player, CurrencyType.GOLD); response.itemId = itemId; response.count = item.Count; response.success = true; _db.SaveChanges(); CurrentSession.SendAsync(response); //任务 OnUnitGradeUp(new UnitGradeUpEventArgs() { UnitInfo = response.unitInfo, OldGrade = unit.Grade - 1 }); } } return(0); }
public UnitInfo ToUnitInfo(Unit u, DUnit du = null, bool calcPower = false) { UnitInfo info = new UnitInfo(); if (du == null) { du = DUnits[u.Tid]; } info.id = u.Id; info.number = u.Number; info.tid = u.Tid; info.exp = u.Exp; info.level = u.Level; info.claz = u.Grade; info.pid = u.PlayerId; if (u.IsResting && u.RestEndTime <= DateTime.Now) { u.IsResting = false; u.Number = du.max_energy; //推送 TimesUpNotify notify = new TimesUpNotify(); notify.id = u.Tid; notify.lv = u.Number; notify.unitid = u.Id; notify.success = true; notify.type = GameConfig.TYPE_UNITREST; this.Server.SendByUserNameAsync(u.PlayerId, notify); } info.prepareEndTime = u.RestEndTime.ToUnixTime(); info.preparing = u.IsResting; info.equips = new List <EquipInfo>(); info.prepareEndTime = u.RestEndTime.ToUnixTime(); if (du != null) { info.name = du.name; info.type = du.type; info.nation = du.nation; info.desc = du.desc; info.star = du.star; info.crit = du.crit; info.crit_hurt = du.crit_hurt; info.hurt_add = du.hurt_add; info.hurt_sub = du.hurt_sub; info.crit_v = du.crit_v; info.hurt_add_v = du.hurt_add_v; info.hurt_sub_v = du.hurt_sub_v; info.armor = du.armor; info.hurt_multiple = du.hurt_multiple; info.cd = du.cd; info.distance = du.distance; info.r = du.r; info.off = du.off; info.rev = du.rev; info.rev_body = du.rev_body; info.speed = du.speed; info.mob = du.mob; info.hp_add = du.hp_add; info.att_add = du.att_add; info.def_add = du.def_add; info.type_detail = du.type_detail; info.levelLimit = 0; info.gain = null; info.count = du.count; info.last_time = du.last_time; info.bullet_count = du.bullet_count; info.rank = 0; info.exist = du.exist; info.energy = du.energy; for (int i = 0; i < du.res_type.Object.Length; i++) { switch (du.res_type.Object[i]) { case CurrencyType.GOLD: info.gold = du.res_cnt.Object[i]; break; case CurrencyType.SUPPLY: info.supply = du.res_cnt.Object[i]; break; case CurrencyType.IRON: info.iron = du.res_cnt.Object[i]; break; } } info.pvp_point = du.pvp_point; info.pvp_dec_score = du.pvp_dec_score; info.max_energy = du.max_energy; info.unitSkills = du.skills.Object; //info.hp_ex = du.hp_add; //info.att_ex = ; //info.def_ex = ; //todo: 计算兵种属性和战力 info.hp = du.prop_val.Object[2]; info.att = du.prop_val.Object[0]; info.defence = du.prop_val.Object[1]; info.hp_growth = du.prop_grow_val.Object[2]; info.att_growth = du.prop_grow_val.Object[0]; info.defence_growth = du.prop_grow_val.Object[1]; //等级加成 info.hp = (int)(info.hp + info.hp_growth * u.Level); info.defence = (int)(info.defence + info.defence_growth * u.Level); info.att = (int)(info.att + info.att_growth * u.Level); //进阶加成 if (u.Grade > 0) { DUnitGradeUp dug = DUnitGrades[du.star][u.Grade]; info.att += (int)((du.prop_val.Object[0] + (100 - 1) * du.prop_grow_val.Object[0]) * dug.atk / 10000d); info.defence += (int)((du.prop_val.Object[1] + (100 - 1) * du.prop_grow_val.Object[1]) * dug.defence / 10000d); info.hp += (int)((du.prop_val.Object[2] + (100 - 1) * du.prop_grow_val.Object[2]) * dug.hp / 10000d); } //装备加成 foreach (var eq in u.Equips) { DEquip de = DEquips[eq.Tid]; DEquipGrade deg = DEquipGrades[eq.GradeId]; var ei = new EquipInfo(); ei.grade = eq.GradeId; ei.equipId = eq.Tid; ei.level = eq.Level; info.equips.Add(ei); int v = de.base_attr_value + de.level_grow * (eq.Level - 1); //升阶增加的属性 =(基础属性 +(100 - 1)*成长属性)*(升阶增加属性万分比) v += (int)((de.base_attr_value + (100 - 1) * de.level_grow) * deg.grade_grow / 10000d); switch (de.base_attr_type) { case 1: { info.att += v; } break; case 2: { info.defence += v; } break; case 3: { info.hp += v; } break; } } //战力计算 if (calcPower) { info.power = CalcPower(info); u.Power = info.power; } else { info.power = u.Power; } } return(info); }
public UnitInfo AddUnitExp(Player player, Unit unit, int exp, bool usecurrency, bool once, string reason) { DUnit du; if (!DUnits.TryGetValue(unit.Tid, out du)) { return(null); } int grade = unit.Grade == 0 ? 1 : unit.Grade; DUnitGradeUp dug = DUnitGrades[du.star][grade]; int oldlevel = unit.Level; int restype = du.type == 2 ? CurrencyType.IRON : CurrencyType.SUPPLY; var playerController = this.Server.GetController <PlayerController>(); while (unit.Level < player.Level && dug.max_level >= unit.Level) { DUnitLevelUp dul = DUnitLevels[unit.Level]; int costExp = 0; switch (du.star) { case 1: costExp = dul.star1; break; case 2: costExp = dul.star2; break; case 3: costExp = dul.star3; break; case 4: costExp = dul.star4; break; case 5: costExp = dul.star5; break; } unit.Exp += exp; if (unit.Exp < costExp) { if (usecurrency) { int left = costExp - unit.Exp; //判断资源是否足够 if (!playerController.IsCurrencyEnough(player, restype, left)) { break;//用钱,但钱不足 } playerController.AddCurrency(player, restype, -left, reason); unit.Exp = costExp; } else { break;//不用钱,经验不足 } } if (unit.Level < DUnitLevels.Count) { unit.Level += 1; } else { unit.Exp = costExp; } //Spring.bean(QuestService.class).onUnitLvUp(u.getPid(), u.getUid(), u.getLevel()); if (usecurrency && !once) { break; } } if (oldlevel != unit.Level) { UnitInfo ui = this.ToUnitInfo(unit, du, true); OnUnitLevelUp(new UnitLevelUpEventArgs() { UnitInfo = ui, OldLevel = oldlevel }); return(ui); } else { return(this.ToUnitInfo(unit, du));; } }