mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 22:57:21 +01:00
fix(stats): enforce sensible maxima in db
This commit is contained in:
@@ -362,6 +362,8 @@ schema.pre('save', true, function preSaveUser (next, done) {
|
||||
}
|
||||
}
|
||||
|
||||
// Enforce min/max values without displaying schema errors to end user
|
||||
|
||||
if (this.isDirectSelected('preferences')) {
|
||||
if (
|
||||
_.isNaN(this.preferences.dayStart)
|
||||
@@ -372,6 +374,20 @@ schema.pre('save', true, function preSaveUser (next, done) {
|
||||
}
|
||||
}
|
||||
|
||||
if (this.isSelected('stats')) {
|
||||
const statMaximum = common.constants.MAX_FIELD_HARD_CAP;
|
||||
const levelMaximum = common.constants.MAX_LEVEL_HARD_CAP;
|
||||
|
||||
_.each(['hp', 'mp', 'exp', 'gp'], stat => {
|
||||
if (this.stats[stat] > statMaximum) {
|
||||
this.stats[stat] = statMaximum;
|
||||
}
|
||||
});
|
||||
if (this.stats.lvl > levelMaximum) {
|
||||
this.stats.lvl = levelMaximum;
|
||||
}
|
||||
}
|
||||
|
||||
// our own version incrementer
|
||||
if (this.isDirectSelected('_v')) {
|
||||
if (_.isNaN(this._v) || !_.isNumber(this._v)) this._v = 0;
|
||||
|
||||
Reference in New Issue
Block a user