diff --git a/common/script/fns/predictableRandom.js b/common/script/fns/predictableRandom.js index 373e015500..e67daf3b62 100644 --- a/common/script/fns/predictableRandom.js +++ b/common/script/fns/predictableRandom.js @@ -5,7 +5,12 @@ import _ from 'lodash'; module.exports = function predictableRandom (user, seed) { if (!seed || seed === Math.PI) { - seed = _.reduce(user.stats, (accumulator, val) => { + let stats = user.stats.toObject ? user.stats.toObject() : user.stats; + // These items are not part of the stat object but exists on the server (see controllers/user#getUser) + // we remove them in order to use the same user.stats both on server and on client + stats = _.omit(stats, 'toNextLevel', 'maxHealth', 'maxMP'); + + seed = _.reduce(stats, (accumulator, val) => { if (_.isNumber(val)) { return accumulator + val; } else { diff --git a/website/server/controllers/api-v3/user.js b/website/server/controllers/api-v3/user.js index a96bd43453..3e6bd8b8da 100644 --- a/website/server/controllers/api-v3/user.js +++ b/website/server/controllers/api-v3/user.js @@ -37,6 +37,8 @@ api.getUser = { delete user.apiToken; // TODO move to model? (maybe virtuals, maybe in toJSON) + // NOTE: if an item is manually added to user.stats common/fns/predictableRandom must be tweaked + // so it's not considered. Otherwise the client will have it while the server won't and the results will be different. user.stats.toNextLevel = common.tnl(user.stats.lvl); user.stats.maxHealth = common.maxHealth; user.stats.maxMP = common.statsComputed(user).maxMP;