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

View File

@@ -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};
}

View File

@@ -165,7 +165,7 @@ export class WarReward {
private async randomBlueprt() {
const { lv } = await RoleModel.findByRoleId(this.roleId);
const result = BLUEPRT_CHANCE.find(cur => {return cur.min <= lv && cur.max >= lv});
console.log('****', lv, result)
if(result) {
const dicOdds = decodeStr('possibility', result.chance);
const {dic: {id}} = getRandomWithWeight(dicOdds);

View File

@@ -303,9 +303,8 @@ export function getLvByExp(exp: number) {
let curLv = 0;
let entries = levelInfos.entries();
for (let [lv, {sum}] of entries) {
if(exp < sum) {
curLv = lv; break;
}
curLv = lv;
if(exp < sum) break;
}
return curLv;