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 {lv = 1, exp = 0} = role;
let newExp = exp + kingExp; let newExp = exp + kingExp;
let newLv = getLvByExp(newExp); 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); await RoleModel.levelup(roleId, newLv, newExp);
if(newLv > lv) { // 升级 if(newLv > lv) { // 升级
await redisUserInfoUpdate(roleId, [{field: 'lv', value: newLv}]) await redisUserInfoUpdate(roleId, [{field: 'lv', value: newLv}])
} }
let actordata = []; let actordata = [];
for(let i = lv; i <= newLv; i++) { 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; let lastSum = sum - cur;
// console.log(sum, cur, lastSum, exp, newExp); // console.log(sum, cur, lastSum, exp, newExp);
@@ -28,7 +37,7 @@ export async function roleLevelup(roleId: string, kingExp: number) {
mostExp : cur mostExp : cur
}); });
} }
return {actordata, lv, exp, kingExp}; return {actordata, lv: newLv, exp: newExp, kingExp: newExp - exp};
} }
+1 -1
View File
@@ -165,7 +165,7 @@ export class WarReward {
private async randomBlueprt() { private async randomBlueprt() {
const { lv } = await RoleModel.findByRoleId(this.roleId); const { lv } = await RoleModel.findByRoleId(this.roleId);
const result = BLUEPRT_CHANCE.find(cur => {return cur.min <= lv && cur.max >= lv}); const result = BLUEPRT_CHANCE.find(cur => {return cur.min <= lv && cur.max >= lv});
console.log('****', lv, result)
if(result) { if(result) {
const dicOdds = decodeStr('possibility', result.chance); const dicOdds = decodeStr('possibility', result.chance);
const {dic: {id}} = getRandomWithWeight(dicOdds); const {dic: {id}} = getRandomWithWeight(dicOdds);
+2 -3
View File
@@ -303,9 +303,8 @@ export function getLvByExp(exp: number) {
let curLv = 0; let curLv = 0;
let entries = levelInfos.entries(); let entries = levelInfos.entries();
for (let [lv, {sum}] of entries) { for (let [lv, {sum}] of entries) {
if(exp < sum) { curLv = lv;
curLv = lv; break; if(exp < sum) break;
}
} }
return curLv; return curLv;