添加主角等级升级逻辑

This commit is contained in:
luying
2020-10-20 20:18:15 +08:00
parent 3332d16cc6
commit 7b65c1856b
6 changed files with 71 additions and 24 deletions
@@ -5,7 +5,7 @@ import { getWarById, } from '../../../pubUtils/gamedata';
import { genCode } from '../../../pubUtils/util';
import { WAR_TYPE, EVENT_START_BATTLE } from '../../../consts/consts';
import { checkDaily, checkDailyAndIncrease } from '../../../services/dailyBattleService';
import { checkTowerWar, towerBattleEnd } from '../../../services/battleService';
import { checkTowerWar, towerBattleEnd, roleLevelup } from '../../../services/battleService';
import { WarReward } from '../../../services/warRewardService';
import { getAp, setAp } from '../../../services/actionPointService';
import { setBattleStatus, startEvent } from '../../../services/eventSercive';
@@ -181,6 +181,8 @@ export class NormalBattleHandler {
}, true);
let { status } = updateResult;
let actordata = await roleLevelup(roleId, warInfo.kingExp)// 主公升级经验
let curHeroes = [];
for(let hid of heroes) {
let hero = await HeroModel.findByHidAndRole(hid, roleId);
@@ -201,28 +203,8 @@ export class NormalBattleHandler {
goods: reward, towerBonus, towerReward,
apJson,
dailyNum,
kingExp: warInfo.kingExp,
heroes: curHeroes,
actordata: [
{
lv : 20,
exp : 700,
getExp : 1300,
mostExp : 2000
},
{
lv : 21,
exp : 0,
getExp : 3000,
mostExp : 3000
},
{
lv : 22,
exp : 0,
getExp : 700,
mostExp : 4000,
}
]
...actordata
});
}
@@ -266,6 +248,8 @@ export class NormalBattleHandler {
let warReward = new WarReward(roleId, roleName, battleId, true);
let result = await warReward.saveReward(count);
let actordata = await roleLevelup(roleId, warInfo.kingExp * count)// 主公升级经验
// 扫荡记录
await BattleSweepRecordModel.saveBattleSweepRecordById(roleId, battleId, {
$set: {
@@ -280,7 +264,8 @@ export class NormalBattleHandler {
battleId, count,
goods: result,
apJson,
dailyNum
dailyNum,
...actordata
});
}
+22 -1
View File
@@ -5,7 +5,7 @@ import { HANG_UP_CONSTS } from './../consts/consts';
import { BattleRecordModel } from './../db/BattleRecord';
import { TowerRecordModel } from './../db/TowerRecord';
import { RoleModel } from './../db/Role';
import { getHeroInfoById, getJobInfoById, getTowerDataByLv } from "../pubUtils/gamedata"
import { getHeroInfoById, getJobInfoById, getTowerDataByLv, getLvByExp, getExpByLv } from "../pubUtils/gamedata"
import { decodeArrayStr, shouldRefresh } from '../pubUtils/util';
import { handleFixedReward } from './rewardService';
import { resResult } from '../pubUtils/util';
@@ -180,4 +180,25 @@ export async function checkTaskConditions(roleId: string, heroes: Array<number>,
}
}
return res;
}
export async function roleLevelup(roleId: string, kingExp: number) {
let role = await RoleModel.findByRoleId(roleId);
let {lv = 1, exp = 0} = role;
exp += kingExp;
let newLv = getLvByExp(exp);
await RoleModel.levelup(roleId, newLv, exp);
let actordata = [];
for(let i = lv; i <= newLv; i++) {
let {sum, cur} = getExpByLv(i);
let getExp = sum > exp? sum - exp: 0;
actordata.push({
lv : i,
exp : cur - getExp,
getExp : getExp,
mostExp : cur
})
}
return {actordata, lv, exp};
}