fix 玩家升满级后经验计算bug
This commit is contained in:
@@ -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};
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user