fix(stats): bump level cap to 9999 and related corrections

This commit is contained in:
Sabe Jones
2021-03-11 16:44:34 -06:00
parent d7aa448676
commit d2795f3ac9
7 changed files with 19 additions and 5 deletions

View File

@@ -115,6 +115,7 @@ import { toNextLevel } from '@/../../common/script/statHelpers';
import { shouldDo } from '@/../../common/script/cron';
import { onOnboardingComplete } from '@/../../common/script/libs/onboarding';
import { mapState } from '@/libs/store';
import { MAX_LEVEL_HARD_CAP } from '@/../../common/script/constants';
import notifications from '@/mixins/notifications';
import guide from '@/mixins/guide';
@@ -651,7 +652,7 @@ export default {
const lvlUps = afterLvl - beforeLvl;
let exp = afterExp - beforeExp;
if (lvlUps > 0) {
if (lvlUps > 0 || afterLvl >= MAX_LEVEL_HARD_CAP) {
let level = Math.trunc(beforeLvl);
exp += toNextLevel(level);

View File

@@ -114,6 +114,7 @@
<script>
import clone from 'lodash/clone';
import { MAX_LEVEL_HARD_CAP } from '@/../../common/script/constants';
import { mapState } from '@/libs/store';
export default {
@@ -151,7 +152,9 @@ export default {
return;
}
if (this.restoreValues.stats.lvl > 999) this.restoreValues.stats.lvl = 999;
if (this.restoreValues.stats.lvl > MAX_LEVEL_HARD_CAP) {
this.restoreValues.stats.lvl = MAX_LEVEL_HARD_CAP;
}
const userChangedLevel = this.restoreValues.stats.lvl !== this.user.stats.lvl;
const userDidNotChangeExp = this.restoreValues.stats.exp === this.user.stats.exp;

View File

@@ -1,6 +1,7 @@
export const MAX_HEALTH = 50;
export const MAX_LEVEL = 100;
export const MAX_STAT_POINTS = MAX_LEVEL;
export const MAX_LEVEL_HARD_CAP = 9999;
export const ATTRIBUTES = ['str', 'int', 'con', 'per'];
export const MAX_INCENTIVES = 500;

View File

@@ -1,6 +1,7 @@
import each from 'lodash/each';
import {
MAX_HEALTH,
MAX_LEVEL_HARD_CAP,
MAX_STAT_POINTS,
} from '../constants';
import { toNextLevel } from '../statHelpers';
@@ -24,7 +25,11 @@ export default function updateStats (user, stats, req = {}, analytics) {
while (stats.exp >= experienceToNextLevel) {
stats.exp -= experienceToNextLevel;
user.stats.lvl += 1;
if (user.stats.lvl >= MAX_LEVEL_HARD_CAP) {
user.stats.lvl = MAX_LEVEL_HARD_CAP;
} else {
user.stats.lvl += 1;
}
experienceToNextLevel = toNextLevel(user.stats.lvl);
user.stats.hp = MAX_HEALTH;

View File

@@ -10,6 +10,7 @@ import {
MAX_HEALTH,
MAX_INCENTIVES,
MAX_LEVEL,
MAX_LEVEL_HARD_CAP,
MAX_STAT_POINTS,
MAX_SUMMARY_SIZE_FOR_CHALLENGES,
MAX_SUMMARY_SIZE_FOR_GUILDS,
@@ -114,6 +115,7 @@ api.constants = {
MINIMUM_PASSWORD_LENGTH,
MAX_MESSAGE_LENGTH,
MAX_GIFT_MESSAGE_LENGTH,
MAX_LEVEL_HARD_CAP,
};
// TODO Move these under api.constants
api.maxLevel = MAX_LEVEL;

View File

@@ -167,7 +167,9 @@ export async function update (req, res, { isV3 = false }) {
}
} else if (acceptablePUTPaths[key]) {
let adjustedVal = val;
if (key === 'stats.lvl' && val > 999) adjustedVal = 999;
if (key === 'stats.lvl' && val > common.constants.MAX_LEVEL_HARD_CAP) {
adjustedVal = common.constants.MAX_LEVEL_HARD_CAP;
}
_.set(user, key, adjustedVal);
} else {
throw new NotAuthorized(res.t('messageUserOperationProtected', { operation: key }));

View File

@@ -596,7 +596,7 @@ export default new Schema({
$type: Number,
default: 1,
min: 1,
max: 999,
max: shared.constants.MAX_LEVEL_HARD_CAP,
},
// Class System