fix 玩家升满级后经验计算bug

This commit is contained in:
luying
2020-11-25 16:18:20 +08:00
parent dd9c51f335
commit 71c2d99cf4
3 changed files with 14 additions and 6 deletions
@@ -9,13 +9,22 @@ export async function roleLevelup(roleId: string, kingExp: number) {
let {lv = 1, exp = 0} = role;
let newExp = exp + kingExp;
let newLv = getLvByExp(newExp);
let nextExpObj = getExpByLv(newLv + 1);
let curExpObj = getExpByLv(newLv);
if(curExpObj && !nextExpObj && newExp > curExpObj.sum) {
newExp = curExpObj.sum;
}
await RoleModel.levelup(roleId, newLv, newExp);
if(newLv > lv) { // 升级
await redisUserInfoUpdate(roleId, [{field: 'lv', value: newLv}])
}
let actordata = [];
for(let i = lv; i <= newLv; i++) {
let {sum, cur} = getExpByLv(i);
let lvObj = getExpByLv(i);
if(!lvObj) break;
let {sum, cur} = lvObj;
let lastSum = sum - cur;
// console.log(sum, cur, lastSum, exp, newExp);
@@ -28,7 +37,7 @@ export async function roleLevelup(roleId: string, kingExp: number) {
mostExp : cur
});
}
return {actordata, lv, exp, kingExp};
return {actordata, lv: newLv, exp: newExp, kingExp: newExp - exp};
}