shared-code-update-stats
This commit is contained in:
@@ -1,22 +1,19 @@
|
||||
import _ from 'lodash';
|
||||
import {
|
||||
MAX_HEALTH,
|
||||
MAX_STAT_POINTS
|
||||
MAX_STAT_POINTS,
|
||||
} from '../constants';
|
||||
import { toNextLevel } from '../statHelpers';
|
||||
import autoAllocate from './autoAllocate';
|
||||
|
||||
module.exports = function updateStats (user, stats, req, analytics) {
|
||||
module.exports = function updateStats (user, stats, req = {}, analytics) {
|
||||
let allocatedStatPoints;
|
||||
let totalStatPoints;
|
||||
let experienceToNextLevel;
|
||||
|
||||
if (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;
|
||||
user.stats.hp = stats.hp > 0 ? stats.hp : 0;
|
||||
user.stats.gp = stats.gp > 0 ? stats.gp : 0;
|
||||
if (!user._tmp) user._tmp = {};
|
||||
|
||||
experienceToNextLevel = toNextLevel(user.stats.lvl);
|
||||
|
||||
@@ -36,7 +33,7 @@ module.exports = function updateStats (user, stats, req, analytics) {
|
||||
continue; // eslint-disable-line no-continue
|
||||
}
|
||||
if (user.preferences.automaticAllocation) {
|
||||
user.fns.autoAllocate();
|
||||
autoAllocate(user);
|
||||
} else {
|
||||
user.stats.points = user.stats.lvl - allocatedStatPoints;
|
||||
totalStatPoints = user.stats.points + allocatedStatPoints;
|
||||
@@ -53,7 +50,6 @@ module.exports = function updateStats (user, stats, req, analytics) {
|
||||
}
|
||||
|
||||
user.stats.exp = stats.exp;
|
||||
user.flags = user.flags || {};
|
||||
|
||||
if (!user.flags.customizationsNotification && (user.stats.exp > 5 || user.stats.lvl > 1)) {
|
||||
user.flags.customizationsNotification = true;
|
||||
@@ -63,48 +59,39 @@ module.exports = function updateStats (user, stats, req, analytics) {
|
||||
}
|
||||
if (!user.flags.dropsEnabled && user.stats.lvl >= 3) {
|
||||
user.flags.dropsEnabled = true;
|
||||
if (user.items.eggs["Wolf"] > 0) {
|
||||
user.items.eggs["Wolf"]++;
|
||||
if (user.items.eggs.Wolf > 0) {
|
||||
user.items.eggs.Wolf++;
|
||||
} else {
|
||||
user.items.eggs["Wolf"] = 1;
|
||||
user.items.eggs.Wolf = 1;
|
||||
}
|
||||
}
|
||||
if (!user.flags.classSelected && user.stats.lvl >= 10) {
|
||||
user.flags.classSelected;
|
||||
}
|
||||
_.each({
|
||||
vice1: 30,
|
||||
atom1: 15,
|
||||
moonstone1: 60,
|
||||
goldenknight1: 40
|
||||
}, function(lvl, k) {
|
||||
var analyticsData, base, base1, ref;
|
||||
if (!((ref = user.flags.levelDrops) != null ? ref[k] : void 0) && user.stats.lvl >= lvl) {
|
||||
if ((base = user.items.quests)[k] == null) {
|
||||
base[k] = 0;
|
||||
}
|
||||
goldenknight1: 40,
|
||||
}, (lvl, k) => {
|
||||
if (user.stats.lvl >= lvl && !user.flags.levelDrops[k]) {
|
||||
user.flags.levelDrops[k] = true;
|
||||
if (!user.items.quests[k])
|
||||
user.items.quests[k] = 0;
|
||||
user.items.quests[k]++;
|
||||
((base1 = user.flags).levelDrops != null ? base1.levelDrops : base1.levelDrops = {})[k] = true;
|
||||
if (typeof user.markModified === "function") {
|
||||
user.markModified('flags.levelDrops');
|
||||
user.markModified('flags.levelDrops');
|
||||
if (analytics) {
|
||||
analytics.track('acquire item', {
|
||||
uuid: user._id,
|
||||
itemKey: k,
|
||||
acquireMethod: 'Level Drop',
|
||||
category: 'behavior',
|
||||
});
|
||||
}
|
||||
analyticsData = {
|
||||
uuid: user._id,
|
||||
itemKey: k,
|
||||
acquireMethod: 'Level Drop',
|
||||
category: 'behavior'
|
||||
};
|
||||
if (analytics != null) {
|
||||
analytics.track('acquire item', analyticsData);
|
||||
}
|
||||
if (!user._tmp) user._tmp = {}
|
||||
return user._tmp.drop = {
|
||||
user._tmp.drop = {
|
||||
type: 'Quest',
|
||||
key: k
|
||||
key: k,
|
||||
};
|
||||
}
|
||||
});
|
||||
if (!user.flags.rebirthEnabled && (user.stats.lvl >= 50 || user.achievements.beastMaster)) {
|
||||
return user.flags.rebirthEnabled = true;
|
||||
user.flags.rebirthEnabled = true;
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user