mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 07:07:35 +01:00
fix: Corrects stat allocation bug where it was possible to recieve more points than 100
fixes #6434
This commit is contained in:
@@ -2271,41 +2271,56 @@ api.wrap = function(user, main) {
|
||||
}
|
||||
})()]++;
|
||||
},
|
||||
updateStats: function(stats, req, analytics) {
|
||||
updateStats (stats, req, analytics) {
|
||||
let allocatedStatPoints;
|
||||
let totalStatPoints;
|
||||
let experienceToNextLevel;
|
||||
|
||||
if (stats.hp <= 0) {
|
||||
return user.stats.hp = 0;
|
||||
user.stats.hp = 0;
|
||||
return user.stats.hp;
|
||||
}
|
||||
|
||||
user.stats.hp = stats.hp;
|
||||
user.stats.gp = stats.gp >= 0 ? stats.gp : 0;
|
||||
|
||||
var experienceToNextLevel = api.tnl(user.stats.lvl);
|
||||
experienceToNextLevel = api.tnl(user.stats.lvl);
|
||||
|
||||
if (stats.exp >= experienceToNextLevel) {
|
||||
user.stats.exp = stats.exp;
|
||||
|
||||
while (stats.exp >= experienceToNextLevel) {
|
||||
stats.exp -= experienceToNextLevel;
|
||||
user.stats.lvl++;
|
||||
experienceToNextLevel = api.tnl(user.stats.lvl);
|
||||
user.stats.hp = 50;
|
||||
var userTotalStatPoints = user.stats.str + user.stats.int + user.stats.con + user.stats.per;
|
||||
|
||||
if (userTotalStatPoints >= MAX_STAT_POINTS) {
|
||||
continue;
|
||||
experienceToNextLevel = api.tnl(user.stats.lvl);
|
||||
user.stats.hp = MAX_HEALTH;
|
||||
allocatedStatPoints = user.stats.str + user.stats.int + user.stats.con + user.stats.per;
|
||||
totalStatPoints = allocatedStatPoints + user.stats.points;
|
||||
|
||||
if (totalStatPoints >= MAX_STAT_POINTS) {
|
||||
continue; // eslint-disable-line no-continue
|
||||
}
|
||||
if (user.preferences.automaticAllocation) {
|
||||
user.fns.autoAllocate();
|
||||
} else {
|
||||
user.stats.points = user.stats.lvl - userTotalStatPoints;
|
||||
user.stats.points = user.stats.lvl - allocatedStatPoints;
|
||||
totalStatPoints = user.stats.points + allocatedStatPoints;
|
||||
|
||||
if (totalStatPoints > MAX_STAT_POINTS) {
|
||||
user.stats.points = MAX_STAT_POINTS - allocatedStatPoints;
|
||||
}
|
||||
|
||||
if (user.stats.points < 0) {
|
||||
user.stats.points = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
user.stats.exp = stats.exp;
|
||||
if (user.flags == null) {
|
||||
user.flags = {};
|
||||
}
|
||||
user.flags = user.flags || {};
|
||||
|
||||
if (!user.flags.customizationsNotification && (user.stats.exp > 5 || user.stats.lvl > 1)) {
|
||||
user.flags.customizationsNotification = true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user