mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-15 21:57:22 +01:00
start upgrading eslint
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import uuid from '../libs/uuid';
|
||||
import get from 'lodash/get';
|
||||
import uuid from '../libs/uuid';
|
||||
|
||||
// TODO used only in client, move there?
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import taskDefaults from '../libs/taskDefaults';
|
||||
import clone from 'lodash/clone';
|
||||
import taskDefaults from '../libs/taskDefaults';
|
||||
|
||||
// TODO move to client since it's only used there?
|
||||
|
||||
export default function addTask (user, req = {body: {}}) {
|
||||
let task = taskDefaults(req.body, user);
|
||||
export default function addTask (user, req = { body: {} }) {
|
||||
const task = taskDefaults(req.body, user);
|
||||
user.tasksOrder[`${task.type}s`].unshift(task._id);
|
||||
user[`${task.type}s`].unshift(task);
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ export default function blockUser (user, req = {}) {
|
||||
if (!validator.isUUID(req.params.uuid)) throw new BadRequest(i18n.t('invalidUUID', req.language));
|
||||
if (req.params.uuid === user._id) throw new BadRequest(i18n.t('blockYourself', req.language));
|
||||
|
||||
let i = user.inbox.blocks.indexOf(req.params.uuid);
|
||||
const i = user.inbox.blocks.indexOf(req.params.uuid);
|
||||
if (i === -1) {
|
||||
user.inbox.blocks.push(req.params.uuid);
|
||||
} else {
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import _merge from 'lodash/merge';
|
||||
import _get from 'lodash/get';
|
||||
import i18n from '../../i18n';
|
||||
import {
|
||||
NotAuthorized,
|
||||
NotImplementedError,
|
||||
BadRequest,
|
||||
} from '../../libs/errors';
|
||||
import _merge from 'lodash/merge';
|
||||
import _get from 'lodash/get';
|
||||
|
||||
export class AbstractBuyOperation {
|
||||
/**
|
||||
@@ -18,7 +18,7 @@ export class AbstractBuyOperation {
|
||||
this.req = req || {};
|
||||
this.analytics = analytics;
|
||||
|
||||
let quantity = _get(req, 'quantity');
|
||||
const quantity = _get(req, 'quantity');
|
||||
|
||||
this.quantity = quantity ? Number(quantity) : 1;
|
||||
if (this.quantity < 1 || !Number.isInteger(this.quantity)) throw new BadRequest(this.i18n('invalidQuantity'));
|
||||
@@ -48,8 +48,7 @@ export class AbstractBuyOperation {
|
||||
* @returns {String}
|
||||
*/
|
||||
getItemType (item) {
|
||||
if (!item.type)
|
||||
throw new NotImplementedError('item doesn\'t have a type property');
|
||||
if (!item.type) throw new NotImplementedError('item doesn\'t have a type property');
|
||||
|
||||
return item.type;
|
||||
}
|
||||
@@ -95,7 +94,7 @@ export class AbstractBuyOperation {
|
||||
|
||||
this.extractAndValidateParams(this.user, this.req);
|
||||
|
||||
let resultObj = this.executeChanges(this.user, this.item, this.req);
|
||||
const resultObj = this.executeChanges(this.user, this.item, this.req);
|
||||
|
||||
if (this.analytics) {
|
||||
this.sendToAnalytics(this.analyticsData());
|
||||
@@ -110,7 +109,7 @@ export class AbstractBuyOperation {
|
||||
|
||||
sendToAnalytics (additionalData = {}) {
|
||||
// spread-operator produces an "unexpected token" error
|
||||
let analyticsData = _merge(additionalData, {
|
||||
const analyticsData = _merge(additionalData, {
|
||||
// ...additionalData,
|
||||
uuid: this.user._id,
|
||||
category: 'behavior',
|
||||
@@ -132,9 +131,9 @@ export class AbstractGoldItemOperation extends AbstractBuyOperation {
|
||||
|
||||
canUserPurchase (user, item) {
|
||||
this.item = item;
|
||||
let itemValue = this.getItemValue(item);
|
||||
const itemValue = this.getItemValue(item);
|
||||
|
||||
let userGold = user.stats.gp;
|
||||
const userGold = user.stats.gp;
|
||||
|
||||
if (userGold < itemValue * this.quantity) {
|
||||
throw new NotAuthorized(this.i18n('messageNotEnoughGold'));
|
||||
@@ -146,7 +145,7 @@ export class AbstractGoldItemOperation extends AbstractBuyOperation {
|
||||
}
|
||||
|
||||
subtractCurrency (user, item) {
|
||||
let itemValue = this.getItemValue(item);
|
||||
const itemValue = this.getItemValue(item);
|
||||
|
||||
user.stats.gp -= itemValue * this.quantity;
|
||||
}
|
||||
@@ -168,7 +167,7 @@ export class AbstractGemItemOperation extends AbstractBuyOperation {
|
||||
|
||||
canUserPurchase (user, item) {
|
||||
this.item = item;
|
||||
let itemValue = this.getItemValue(item);
|
||||
const itemValue = this.getItemValue(item);
|
||||
|
||||
if (!item.canBuy(user)) {
|
||||
throw new NotAuthorized(this.i18n('messageNotAvailable'));
|
||||
@@ -180,7 +179,7 @@ export class AbstractGemItemOperation extends AbstractBuyOperation {
|
||||
}
|
||||
|
||||
subtractCurrency (user, item) {
|
||||
let itemValue = this.getItemValue(item);
|
||||
const itemValue = this.getItemValue(item);
|
||||
|
||||
user.balance -= itemValue * this.quantity;
|
||||
}
|
||||
|
||||
@@ -2,28 +2,28 @@ import get from 'lodash/get';
|
||||
import {
|
||||
BadRequest,
|
||||
} from '../../libs/errors';
|
||||
import {BuyArmoireOperation} from './buyArmoire';
|
||||
import {BuyHealthPotionOperation} from './buyHealthPotion';
|
||||
import {BuyMarketGearOperation} from './buyMarketGear';
|
||||
import { BuyArmoireOperation } from './buyArmoire';
|
||||
import { BuyHealthPotionOperation } from './buyHealthPotion';
|
||||
import { BuyMarketGearOperation } from './buyMarketGear';
|
||||
import buyMysterySet from './buyMysterySet';
|
||||
import {BuyQuestWithGoldOperation} from './buyQuestGold';
|
||||
import {BuySpellOperation} from './buySpell';
|
||||
import { BuyQuestWithGoldOperation } from './buyQuestGold';
|
||||
import { BuySpellOperation } from './buySpell';
|
||||
import purchaseOp from './purchase';
|
||||
import hourglassPurchase from './hourglassPurchase';
|
||||
import errorMessage from '../../libs/errorMessage';
|
||||
import {BuyGemOperation} from './buyGem';
|
||||
import {BuyQuestWithGemOperation} from './buyQuestGem';
|
||||
import {BuyHourglassMountOperation} from './buyMount';
|
||||
import { BuyGemOperation } from './buyGem';
|
||||
import { BuyQuestWithGemOperation } from './buyQuestGem';
|
||||
import { BuyHourglassMountOperation } from './buyMount';
|
||||
|
||||
// @TODO: remove the req option style. Dependency on express structure is an anti-pattern
|
||||
// We should either have more params or a set structure validated by a Type checker
|
||||
|
||||
// @TODO: when we are sure buy is the only function used, let's move the buy files to a folder
|
||||
|
||||
export default function buy (user, req = {}, analytics, options = {quantity: 1, hourglass: false}) {
|
||||
let key = get(req, 'params.key');
|
||||
const hourglass = options.hourglass;
|
||||
const quantity = options.quantity;
|
||||
export default function buy (user, req = {}, analytics, options = { quantity: 1, hourglass: false }) {
|
||||
const key = get(req, 'params.key');
|
||||
const { hourglass } = options;
|
||||
const { quantity } = options;
|
||||
if (!key) throw new BadRequest(errorMessage('missingKeyParam'));
|
||||
|
||||
// @TODO: Slowly remove the need for key and use type instead
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
import content from '../../content/index';
|
||||
import filter from 'lodash/filter';
|
||||
import isEmpty from 'lodash/isEmpty';
|
||||
import pick from 'lodash/pick';
|
||||
import content from '../../content/index';
|
||||
import * as count from '../../count';
|
||||
import splitWhitespace from '../../libs/splitWhitespace';
|
||||
import {
|
||||
NotAuthorized,
|
||||
} from '../../libs/errors';
|
||||
import randomVal, * as randomValFns from '../../libs/randomVal';
|
||||
import {removeItemByPath} from '../pinnedGearUtils';
|
||||
import {AbstractGoldItemOperation} from './abstractBuyOperation';
|
||||
import { removeItemByPath } from '../pinnedGearUtils';
|
||||
import { AbstractGoldItemOperation } from './abstractBuyOperation';
|
||||
|
||||
// TODO this is only used on the server
|
||||
// move out of common?
|
||||
@@ -27,7 +27,7 @@ export class BuyArmoireOperation extends AbstractGoldItemOperation {
|
||||
}
|
||||
|
||||
extractAndValidateParams (user) {
|
||||
let item = content.armoire;
|
||||
const item = content.armoire;
|
||||
|
||||
this.canUserPurchase(user, item);
|
||||
}
|
||||
@@ -35,11 +35,9 @@ export class BuyArmoireOperation extends AbstractGoldItemOperation {
|
||||
executeChanges (user, item) {
|
||||
let result = {};
|
||||
|
||||
let armoireResult = randomValFns.trueRandom();
|
||||
let eligibleEquipment = filter(content.gear.flat, (eligible) => {
|
||||
return eligible.klass === 'armoire' && !user.items.gear.owned[eligible.key];
|
||||
});
|
||||
let armoireHasEquipment = !isEmpty(eligibleEquipment);
|
||||
const armoireResult = randomValFns.trueRandom();
|
||||
const eligibleEquipment = filter(content.gear.flat, eligible => eligible.klass === 'armoire' && !user.items.gear.owned[eligible.key]);
|
||||
const armoireHasEquipment = !isEmpty(eligibleEquipment);
|
||||
|
||||
if (armoireHasEquipment && (armoireResult < YIELD_EQUIPMENT_THRESHOLD || !user.flags.armoireOpened)) {
|
||||
result = this._gearResult(user, eligibleEquipment);
|
||||
@@ -51,7 +49,7 @@ export class BuyArmoireOperation extends AbstractGoldItemOperation {
|
||||
|
||||
this.subtractCurrency(user, item);
|
||||
|
||||
let {message, armoireResp} = result;
|
||||
let { message, armoireResp } = result;
|
||||
|
||||
if (!message) {
|
||||
message = this.i18n('messageBought', {
|
||||
@@ -59,7 +57,7 @@ export class BuyArmoireOperation extends AbstractGoldItemOperation {
|
||||
});
|
||||
}
|
||||
|
||||
let resData = pick(user, splitWhitespace('items flags'));
|
||||
const resData = pick(user, splitWhitespace('items flags'));
|
||||
if (armoireResp) resData.armoire = armoireResp;
|
||||
|
||||
return [
|
||||
@@ -83,7 +81,7 @@ export class BuyArmoireOperation extends AbstractGoldItemOperation {
|
||||
|
||||
_gearResult (user, eligibleEquipment) {
|
||||
eligibleEquipment.sort();
|
||||
let drop = randomVal(eligibleEquipment);
|
||||
const drop = randomVal(eligibleEquipment);
|
||||
|
||||
if (user.items.gear.owned[drop.key]) {
|
||||
throw new NotAuthorized(this.i18n('equipmentAlreadyOwned'));
|
||||
@@ -93,7 +91,7 @@ export class BuyArmoireOperation extends AbstractGoldItemOperation {
|
||||
if (user.markModified) user.markModified('items.gear.owned');
|
||||
|
||||
user.flags.armoireOpened = true;
|
||||
let message = this.i18n('armoireEquipment', {
|
||||
const message = this.i18n('armoireEquipment', {
|
||||
image: `<span class="shop_${drop.key} pull-left"></span>`,
|
||||
dropText: drop.text(this.req.language),
|
||||
});
|
||||
@@ -108,7 +106,7 @@ export class BuyArmoireOperation extends AbstractGoldItemOperation {
|
||||
this._trackDropAnalytics(user._id, drop.key);
|
||||
}
|
||||
|
||||
let armoireResp = {
|
||||
const armoireResp = {
|
||||
type: 'gear',
|
||||
dropKey: drop.key,
|
||||
dropText: drop.text(this.req.language),
|
||||
@@ -121,7 +119,7 @@ export class BuyArmoireOperation extends AbstractGoldItemOperation {
|
||||
}
|
||||
|
||||
_foodResult (user) {
|
||||
let drop = randomVal(filter(content.food, {
|
||||
const drop = randomVal(filter(content.food, {
|
||||
canDrop: true,
|
||||
}));
|
||||
|
||||
@@ -147,7 +145,7 @@ export class BuyArmoireOperation extends AbstractGoldItemOperation {
|
||||
}
|
||||
|
||||
_experienceResult (user) {
|
||||
let armoireExp = Math.floor(randomValFns.trueRandom() * 40 + 10);
|
||||
const armoireExp = Math.floor(randomValFns.trueRandom() * 40 + 10);
|
||||
user.stats.exp += armoireExp;
|
||||
|
||||
return {
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import pick from 'lodash/pick';
|
||||
import get from 'lodash/get';
|
||||
import splitWhitespace from '../../libs/splitWhitespace';
|
||||
import {
|
||||
BadRequest,
|
||||
NotAuthorized,
|
||||
} from '../../libs/errors';
|
||||
import {AbstractGoldItemOperation} from './abstractBuyOperation';
|
||||
import get from 'lodash/get';
|
||||
import { AbstractGoldItemOperation } from './abstractBuyOperation';
|
||||
import planGemLimits from '../../libs/planGemLimits';
|
||||
|
||||
export class BuyGemOperation extends AbstractGoldItemOperation {
|
||||
@@ -30,10 +30,10 @@ export class BuyGemOperation extends AbstractGoldItemOperation {
|
||||
}
|
||||
|
||||
extractAndValidateParams (user, req) {
|
||||
let key = this.key = get(req, 'params.key');
|
||||
const key = this.key = get(req, 'params.key');
|
||||
if (!key) throw new BadRequest(this.i18n('missingKeyParam'));
|
||||
|
||||
let convCap = planGemLimits.convCap;
|
||||
let { convCap } = planGemLimits;
|
||||
convCap += user.purchased.plan.consecutive.gemCapExtra;
|
||||
|
||||
// todo better name?
|
||||
@@ -50,7 +50,7 @@ export class BuyGemOperation extends AbstractGoldItemOperation {
|
||||
super.canUserPurchase(user, item);
|
||||
|
||||
if (user.purchased.plan.gemsBought >= this.convCap) {
|
||||
throw new NotAuthorized(this.i18n('reachedGoldToGemCap', {convCap: this.convCap}));
|
||||
throw new NotAuthorized(this.i18n('reachedGoldToGemCap', { convCap: this.convCap }));
|
||||
}
|
||||
|
||||
if (user.purchased.plan.gemsBought + this.quantity > this.convCap) {
|
||||
@@ -69,7 +69,7 @@ export class BuyGemOperation extends AbstractGoldItemOperation {
|
||||
|
||||
return [
|
||||
pick(user, splitWhitespace('stats balance')),
|
||||
this.i18n('plusGem', {count: this.quantity}),
|
||||
this.i18n('plusGem', { count: this.quantity }),
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ import {
|
||||
NotAuthorized,
|
||||
} from '../../libs/errors';
|
||||
|
||||
import { AbstractGoldItemOperation} from './abstractBuyOperation';
|
||||
import { AbstractGoldItemOperation } from './abstractBuyOperation';
|
||||
|
||||
export class BuyHealthPotionOperation extends AbstractGoldItemOperation {
|
||||
constructor (user, req, analytics) {
|
||||
@@ -15,8 +15,8 @@ export class BuyHealthPotionOperation extends AbstractGoldItemOperation {
|
||||
}
|
||||
|
||||
extractAndValidateParams (user) {
|
||||
let item = content.potion;
|
||||
let userHp = user.stats.hp;
|
||||
const item = content.potion;
|
||||
const userHp = user.stats.hp;
|
||||
|
||||
super.canUserPurchase(user, item);
|
||||
|
||||
@@ -37,7 +37,7 @@ export class BuyHealthPotionOperation extends AbstractGoldItemOperation {
|
||||
|
||||
this.subtractCurrency(user, item, this.quantity);
|
||||
|
||||
let message = this.i18n('messageBought', {
|
||||
const message = this.i18n('messageBought', {
|
||||
itemText: this.item.text(this.req.language),
|
||||
});
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import content from '../../content/index';
|
||||
import get from 'lodash/get';
|
||||
import pick from 'lodash/pick';
|
||||
import content from '../../content/index';
|
||||
import splitWhitespace from '../../libs/splitWhitespace';
|
||||
import {
|
||||
BadRequest,
|
||||
@@ -10,7 +10,7 @@ import {
|
||||
import handleTwoHanded from '../../fns/handleTwoHanded';
|
||||
import ultimateGear from '../../fns/ultimateGear';
|
||||
|
||||
import {removePinnedGearAddPossibleNewOnes} from '../pinnedGearUtils';
|
||||
import { removePinnedGearAddPossibleNewOnes } from '../pinnedGearUtils';
|
||||
|
||||
import { AbstractGoldItemOperation } from './abstractBuyOperation';
|
||||
import errorMessage from '../../libs/errorMessage';
|
||||
@@ -24,7 +24,7 @@ export class BuyMarketGearOperation extends AbstractGoldItemOperation {
|
||||
return false;
|
||||
}
|
||||
|
||||
canUserPurchase (user, item) {
|
||||
canUserPurchase (user, item) {
|
||||
super.canUserPurchase(user, item);
|
||||
|
||||
const checkKlass = item.klass && !['special', 'armoire', user.stats.class].includes(item.klass);
|
||||
@@ -37,11 +37,11 @@ export class BuyMarketGearOperation extends AbstractGoldItemOperation {
|
||||
}
|
||||
|
||||
extractAndValidateParams (user, req) {
|
||||
let key = this.key = get(req, 'params.key');
|
||||
const key = this.key = get(req, 'params.key');
|
||||
if (!key) throw new BadRequest(errorMessage('missingKeyParam'));
|
||||
|
||||
let item = content.gear.flat[key];
|
||||
if (!item) throw new NotFound(errorMessage('itemNotFound', {key}));
|
||||
const item = content.gear.flat[key];
|
||||
if (!item) throw new NotFound(errorMessage('itemNotFound', { key }));
|
||||
|
||||
this.canUserPurchase(user, item);
|
||||
|
||||
@@ -49,12 +49,12 @@ export class BuyMarketGearOperation extends AbstractGoldItemOperation {
|
||||
throw new NotAuthorized(this.i18n('equipmentAlreadyOwned'));
|
||||
}
|
||||
|
||||
let itemIndex = Number(item.index);
|
||||
const itemIndex = Number(item.index);
|
||||
|
||||
if (Number.isInteger(itemIndex) && content.classes.includes(item.klass)) {
|
||||
let previousLevelGear = key.replace(/[0-9]/, itemIndex - 1);
|
||||
let hasPreviousLevelGear = user.items.gear.owned[previousLevelGear];
|
||||
let checkIndexToType = itemIndex > (item.type === 'weapon' || item.type === 'shield' && item.klass === 'rogue' ? 0 : 1);
|
||||
const previousLevelGear = key.replace(/[0-9]/, itemIndex - 1);
|
||||
const hasPreviousLevelGear = user.items.gear.owned[previousLevelGear];
|
||||
const checkIndexToType = itemIndex > (item.type === 'weapon' || item.type === 'shield' && item.klass === 'rogue' ? 0 : 1);
|
||||
|
||||
if (checkIndexToType && !hasPreviousLevelGear) {
|
||||
throw new NotAuthorized(this.i18n('previousGearNotOwned'));
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import get from 'lodash/get';
|
||||
import includes from 'lodash/includes';
|
||||
import keys from 'lodash/keys';
|
||||
import content from '../../content/index';
|
||||
import {
|
||||
BadRequest,
|
||||
NotAuthorized,
|
||||
} from '../../libs/errors';
|
||||
|
||||
import {AbstractHourglassItemOperation} from './abstractBuyOperation';
|
||||
import get from 'lodash/get';
|
||||
import includes from 'lodash/includes';
|
||||
import keys from 'lodash/keys';
|
||||
import { AbstractHourglassItemOperation } from './abstractBuyOperation';
|
||||
|
||||
export class BuyHourglassMountOperation extends AbstractHourglassItemOperation {
|
||||
constructor (user, req, analytics) {
|
||||
@@ -19,7 +19,7 @@ export class BuyHourglassMountOperation extends AbstractHourglassItemOperation {
|
||||
}
|
||||
|
||||
extractAndValidateParams (user, req) {
|
||||
let key = this.key = get(req, 'params.key');
|
||||
const key = this.key = get(req, 'params.key');
|
||||
if (!key) throw new BadRequest(this.i18n('missingKeyParam'));
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ export class BuyHourglassMountOperation extends AbstractHourglassItemOperation {
|
||||
|
||||
this.subtractCurrency(user);
|
||||
|
||||
let message = this.i18n('hourglassPurchase');
|
||||
const message = this.i18n('hourglassPurchase');
|
||||
|
||||
return [
|
||||
{ items: user.items, purchasedPlanConsecutive: user.purchased.plan.consecutive },
|
||||
@@ -52,7 +52,7 @@ export class BuyHourglassMountOperation extends AbstractHourglassItemOperation {
|
||||
}
|
||||
|
||||
analyticsData () {
|
||||
let data = super.analyticsData();
|
||||
const data = super.analyticsData();
|
||||
data.itemType = 'mounts';
|
||||
return data;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import i18n from '../../i18n';
|
||||
import content from '../../content/index';
|
||||
import get from 'lodash/get';
|
||||
import each from 'lodash/each';
|
||||
import i18n from '../../i18n';
|
||||
import content from '../../content/index';
|
||||
import {
|
||||
BadRequest,
|
||||
NotAuthorized,
|
||||
@@ -10,15 +10,15 @@ import {
|
||||
import errorMessage from '../../libs/errorMessage';
|
||||
|
||||
export default function buyMysterySet (user, req = {}, analytics) {
|
||||
let key = get(req, 'params.key');
|
||||
const key = get(req, 'params.key');
|
||||
if (!key) throw new BadRequest(errorMessage('missingKeyParam'));
|
||||
|
||||
if (!(user.purchased.plan.consecutive.trinkets > 0)) {
|
||||
throw new NotAuthorized(i18n.t('notEnoughHourglasses', req.language));
|
||||
}
|
||||
|
||||
let ref = content.timeTravelerStore(user);
|
||||
let mysterySet = ref ? ref[key] : undefined;
|
||||
const ref = content.timeTravelerStore(user);
|
||||
const mysterySet = ref ? ref[key] : undefined;
|
||||
|
||||
if (!mysterySet) {
|
||||
throw new NotFound(i18n.t('mysterySetNotFound', req.language));
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import get from 'lodash/get';
|
||||
import {
|
||||
BadRequest,
|
||||
NotAuthorized,
|
||||
NotFound,
|
||||
} from '../../libs/errors';
|
||||
import content from '../../content/index';
|
||||
import get from 'lodash/get';
|
||||
|
||||
import errorMessage from '../../libs/errorMessage';
|
||||
import {AbstractGemItemOperation} from './abstractBuyOperation';
|
||||
import { AbstractGemItemOperation } from './abstractBuyOperation';
|
||||
|
||||
export class BuyQuestWithGemOperation extends AbstractGemItemOperation {
|
||||
constructor (user, req, analytics) {
|
||||
@@ -31,15 +31,15 @@ export class BuyQuestWithGemOperation extends AbstractGemItemOperation {
|
||||
}
|
||||
|
||||
extractAndValidateParams (user, req) {
|
||||
let key = this.key = get(req, 'params.key');
|
||||
const key = this.key = get(req, 'params.key');
|
||||
if (!key) throw new BadRequest(errorMessage('missingKeyParam'));
|
||||
|
||||
let item = content.quests[key];
|
||||
const item = content.quests[key];
|
||||
|
||||
if (!item) throw new NotFound(errorMessage('questNotFound', {key}));
|
||||
if (!item) throw new NotFound(errorMessage('questNotFound', { key }));
|
||||
|
||||
if (item.category === 'gold') {
|
||||
throw new NotAuthorized(this.i18n('questNotGemPurchasable', {key}));
|
||||
throw new NotAuthorized(this.i18n('questNotGemPurchasable', { key }));
|
||||
}
|
||||
|
||||
this.canUserPurchase(user, item);
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import get from 'lodash/get';
|
||||
import {
|
||||
BadRequest,
|
||||
NotAuthorized,
|
||||
NotFound,
|
||||
} from '../../libs/errors';
|
||||
import content from '../../content/index';
|
||||
import get from 'lodash/get';
|
||||
|
||||
import {AbstractGoldItemOperation} from './abstractBuyOperation';
|
||||
import { AbstractGoldItemOperation } from './abstractBuyOperation';
|
||||
import errorMessage from '../../libs/errorMessage';
|
||||
|
||||
export class BuyQuestWithGoldOperation extends AbstractGoldItemOperation {
|
||||
@@ -19,10 +19,10 @@ export class BuyQuestWithGoldOperation extends AbstractGoldItemOperation {
|
||||
}
|
||||
|
||||
userAbleToStartMasterClasser (user) {
|
||||
return user.achievements.quests.dilatoryDistress3 &&
|
||||
user.achievements.quests.mayhemMistiflying3 &&
|
||||
user.achievements.quests.stoikalmCalamity3 &&
|
||||
user.achievements.quests.taskwoodsTerror3;
|
||||
return user.achievements.quests.dilatoryDistress3
|
||||
&& user.achievements.quests.mayhemMistiflying3
|
||||
&& user.achievements.quests.stoikalmCalamity3
|
||||
&& user.achievements.quests.taskwoodsTerror3;
|
||||
}
|
||||
|
||||
getItemKey () {
|
||||
@@ -38,15 +38,15 @@ export class BuyQuestWithGoldOperation extends AbstractGoldItemOperation {
|
||||
}
|
||||
|
||||
extractAndValidateParams (user, req) {
|
||||
let key = this.key = get(req, 'params.key');
|
||||
const key = this.key = get(req, 'params.key');
|
||||
if (!key) throw new BadRequest(errorMessage('missingKeyParam'));
|
||||
|
||||
let item = content.quests[key];
|
||||
const item = content.quests[key];
|
||||
|
||||
if (!item) throw new NotFound(errorMessage('questNotFound', {key}));
|
||||
if (!item) throw new NotFound(errorMessage('questNotFound', { key }));
|
||||
|
||||
if (!(item.category === 'gold' && item.goldValue)) {
|
||||
throw new NotAuthorized(this.i18n('questNotGoldPurchasable', {key}));
|
||||
throw new NotAuthorized(this.i18n('questNotGoldPurchasable', { key }));
|
||||
}
|
||||
|
||||
this.checkPrerequisites(user, key);
|
||||
@@ -61,7 +61,7 @@ export class BuyQuestWithGoldOperation extends AbstractGoldItemOperation {
|
||||
}
|
||||
|
||||
if (item && item.previous && !user.achievements.quests[item.previous]) {
|
||||
throw new NotAuthorized(this.i18n('mustComplete', {quest: item.previous}));
|
||||
throw new NotAuthorized(this.i18n('mustComplete', { quest: item.previous }));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import content from '../../content/index';
|
||||
import get from 'lodash/get';
|
||||
import pick from 'lodash/pick';
|
||||
import content from '../../content/index';
|
||||
import splitWhitespace from '../../libs/splitWhitespace';
|
||||
import {
|
||||
BadRequest,
|
||||
NotFound,
|
||||
} from '../../libs/errors';
|
||||
import {AbstractGoldItemOperation} from './abstractBuyOperation';
|
||||
import { AbstractGoldItemOperation } from './abstractBuyOperation';
|
||||
import errorMessage from '../../libs/errorMessage';
|
||||
|
||||
export class BuySpellOperation extends AbstractGoldItemOperation {
|
||||
@@ -27,11 +27,11 @@ export class BuySpellOperation extends AbstractGoldItemOperation {
|
||||
}
|
||||
|
||||
extractAndValidateParams (user, req) {
|
||||
let key = this.key = get(req, 'params.key');
|
||||
const key = this.key = get(req, 'params.key');
|
||||
if (!key) throw new BadRequest(errorMessage('missingKeyParam'));
|
||||
|
||||
let item = content.special[key];
|
||||
if (!item) throw new NotFound(errorMessage('spellNotFound', {spellId: key}));
|
||||
const item = content.special[key];
|
||||
if (!item) throw new NotFound(errorMessage('spellNotFound', { spellId: key }));
|
||||
|
||||
this.canUserPurchase(user, item);
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import content from '../../content/index';
|
||||
import i18n from '../../i18n';
|
||||
import get from 'lodash/get';
|
||||
import includes from 'lodash/includes';
|
||||
import keys from 'lodash/keys';
|
||||
import i18n from '../../i18n';
|
||||
import content from '../../content/index';
|
||||
import {
|
||||
BadRequest,
|
||||
NotAuthorized,
|
||||
@@ -10,10 +10,10 @@ import {
|
||||
import errorMessage from '../../libs/errorMessage';
|
||||
|
||||
export default function purchaseHourglass (user, req = {}, analytics, quantity = 1) {
|
||||
let key = get(req, 'params.key');
|
||||
const key = get(req, 'params.key');
|
||||
if (!key) throw new BadRequest(errorMessage('missingKeyParam'));
|
||||
|
||||
let type = get(req, 'params.type');
|
||||
const type = get(req, 'params.type');
|
||||
if (!type) throw new BadRequest(errorMessage('missingTypeParam'));
|
||||
|
||||
if (type === 'quests') {
|
||||
@@ -29,7 +29,7 @@ export default function purchaseHourglass (user, req = {}, analytics, quantity =
|
||||
if (user.markModified) user.markModified('items.quests');
|
||||
} else {
|
||||
if (!content.timeTravelStable[type]) {
|
||||
throw new NotAuthorized(i18n.t('typeNotAllowedHourglass', {allowedTypes: keys(content.timeTravelStable).toString()}, req.language));
|
||||
throw new NotAuthorized(i18n.t('typeNotAllowedHourglass', { allowedTypes: keys(content.timeTravelStable).toString() }, req.language));
|
||||
}
|
||||
|
||||
if (!includes(keys(content.timeTravelStable[type]), key)) {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import content from '../../content/index';
|
||||
import i18n from '../../i18n';
|
||||
import get from 'lodash/get';
|
||||
import pick from 'lodash/pick';
|
||||
import forEach from 'lodash/forEach';
|
||||
import i18n from '../../i18n';
|
||||
import content from '../../content/index';
|
||||
import splitWhitespace from '../../libs/splitWhitespace';
|
||||
import {
|
||||
NotFound,
|
||||
@@ -21,7 +21,7 @@ function getItemAndPrice (user, type, key, req) {
|
||||
item = content.gear.flat[key];
|
||||
|
||||
if (!item) {
|
||||
throw new NotFound(i18n.t('contentKeyNotFound', {type}, req.language));
|
||||
throw new NotFound(i18n.t('contentKeyNotFound', { type }, req.language));
|
||||
}
|
||||
|
||||
if (user.items.gear.owned[key]) {
|
||||
@@ -33,13 +33,13 @@ function getItemAndPrice (user, type, key, req) {
|
||||
item = content[type][key];
|
||||
|
||||
if (!item) {
|
||||
throw new NotFound(i18n.t('contentKeyNotFound', {type}, req.language));
|
||||
throw new NotFound(i18n.t('contentKeyNotFound', { type }, req.language));
|
||||
}
|
||||
|
||||
price = item.value / 4;
|
||||
}
|
||||
|
||||
return {item, price};
|
||||
return { item, price };
|
||||
}
|
||||
|
||||
function purchaseItem (user, item, price, type, key) {
|
||||
@@ -49,8 +49,8 @@ function purchaseItem (user, item, price, type, key) {
|
||||
user.items.gear.owned[key] = true;
|
||||
if (user.markModified) user.markModified('items.gear.owned');
|
||||
} else if (type === 'bundles') {
|
||||
let subType = item.type;
|
||||
forEach(item.bundleKeys, function addBundledItems (bundledKey) {
|
||||
const subType = item.type;
|
||||
forEach(item.bundleKeys, bundledKey => {
|
||||
if (!user.items[subType][bundledKey] || user.items[subType][key] < 0) {
|
||||
user.items[subType][bundledKey] = 0;
|
||||
}
|
||||
@@ -69,10 +69,10 @@ function purchaseItem (user, item, price, type, key) {
|
||||
const acceptedTypes = ['eggs', 'hatchingPotions', 'food', 'gear', 'bundles'];
|
||||
const singlePurchaseTypes = ['gear'];
|
||||
export default function purchase (user, req = {}, analytics) {
|
||||
let type = get(req.params, 'type');
|
||||
let key = get(req.params, 'key');
|
||||
const type = get(req.params, 'type');
|
||||
const key = get(req.params, 'key');
|
||||
|
||||
let quantity = req.quantity ? Number(req.quantity) : 1;
|
||||
const quantity = req.quantity ? Number(req.quantity) : 1;
|
||||
if (quantity < 1 || !Number.isInteger(quantity)) throw new BadRequest(i18n.t('invalidQuantity', req.language));
|
||||
|
||||
if (!type) {
|
||||
@@ -87,7 +87,7 @@ export default function purchase (user, req = {}, analytics) {
|
||||
throw new NotFound(i18n.t('notAccteptedType', req.language));
|
||||
}
|
||||
|
||||
let {price, item} = getItemAndPrice(user, type, key, req);
|
||||
const { price, item } = getItemAndPrice(user, type, key, req);
|
||||
|
||||
if (!item.canBuy(user)) {
|
||||
throw new NotAuthorized(i18n.t('messageNotAvailable', req.language));
|
||||
@@ -98,7 +98,7 @@ export default function purchase (user, req = {}, analytics) {
|
||||
}
|
||||
|
||||
if (singlePurchaseTypes.includes(type)) {
|
||||
let itemInfo = getItemInfo(user, type, item);
|
||||
const itemInfo = getItemInfo(user, type, item);
|
||||
removeItemByPath(user, itemInfo.path);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import i18n from '../i18n';
|
||||
import get from 'lodash/get';
|
||||
import pick from 'lodash/pick';
|
||||
import i18n from '../i18n';
|
||||
import splitWhitespace from '../libs/splitWhitespace';
|
||||
import { capByLevel } from '../statHelpers';
|
||||
import {
|
||||
@@ -34,7 +34,7 @@ function resetClass (user, req = {}) {
|
||||
}
|
||||
|
||||
export default function changeClass (user, req = {}, analytics) {
|
||||
let klass = get(req, 'query.class');
|
||||
const klass = get(req, 'query.class');
|
||||
let balanceRemoved = 0;
|
||||
// user.flags.classSelected is set to false after the user paid the 3 gems
|
||||
if (user.stats.lvl < 10) {
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
import i18n from '../i18n';
|
||||
import get from 'lodash/get';
|
||||
import findIndex from 'lodash/findIndex';
|
||||
import each from 'lodash/each';
|
||||
import i18n from '../i18n';
|
||||
import { NotFound } from '../libs/errors';
|
||||
|
||||
// TODO used only in client, move there?
|
||||
|
||||
export default function deleteTag (user, req = {}) {
|
||||
let tid = get(req, 'params.id');
|
||||
const tid = get(req, 'params.id');
|
||||
|
||||
let index = findIndex(user.tags, {
|
||||
const index = findIndex(user.tags, {
|
||||
id: tid,
|
||||
});
|
||||
|
||||
@@ -17,16 +17,14 @@ export default function deleteTag (user, req = {}) {
|
||||
throw new NotFound(i18n.t('messageTagNotFound', req.language));
|
||||
}
|
||||
|
||||
let tag = user.tags[index];
|
||||
const tag = user.tags[index];
|
||||
delete user.filters[tag.id];
|
||||
|
||||
user.tags.splice(index, 1);
|
||||
|
||||
each(user.tasks, (task) => {
|
||||
return delete task.tags[tag.id];
|
||||
});
|
||||
each(user.tasks, task => delete task.tags[tag.id]);
|
||||
|
||||
each(['habits', 'dailys', 'todos', 'rewards'], (type) => {
|
||||
each(['habits', 'dailys', 'todos', 'rewards'], type => {
|
||||
if (user.markModified) user.markModified(type);
|
||||
});
|
||||
|
||||
|
||||
@@ -1,17 +1,15 @@
|
||||
import i18n from '../i18n';
|
||||
import { NotFound } from '../libs/errors';
|
||||
import get from 'lodash/get';
|
||||
import findIndex from 'lodash/findIndex';
|
||||
import i18n from '../i18n';
|
||||
import { NotFound } from '../libs/errors';
|
||||
|
||||
// TODO used only in client, move there?
|
||||
|
||||
export default function deleteTask (user, req = {}) {
|
||||
let tid = get(req, 'params.id');
|
||||
let taskType = get(req, 'params.taskType');
|
||||
const tid = get(req, 'params.id');
|
||||
const taskType = get(req, 'params.taskType');
|
||||
|
||||
let index = findIndex(user[`${taskType}s`], function findById (task) {
|
||||
return task._id === tid;
|
||||
});
|
||||
const index = findIndex(user[`${taskType}s`], task => task._id === tid);
|
||||
|
||||
if (index === -1) {
|
||||
throw new NotFound(i18n.t('messageTaskNotFound', req.language));
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import pick from 'lodash/pick';
|
||||
import splitWhitespace from '../libs/splitWhitespace';
|
||||
import { capByLevel } from '../statHelpers';
|
||||
import pick from 'lodash/pick';
|
||||
|
||||
export default function disableClasses (user) {
|
||||
user.stats.class = 'warrior';
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import get from 'lodash/get';
|
||||
import content from '../content/index';
|
||||
import i18n from '../i18n';
|
||||
import handleTwoHanded from '../fns/handleTwoHanded';
|
||||
@@ -5,14 +6,13 @@ import {
|
||||
NotFound,
|
||||
BadRequest,
|
||||
} from '../libs/errors';
|
||||
import get from 'lodash/get';
|
||||
import errorMessage from '../libs/errorMessage';
|
||||
|
||||
export default function equip (user, req = {}) {
|
||||
// Being type a parameter followed by another parameter
|
||||
// when using the API it must be passes specifically in the URL, it's won't default to equipped
|
||||
let type = get(req, 'params.type', 'equipped');
|
||||
let key = get(req, 'params.key');
|
||||
const type = get(req, 'params.type', 'equipped');
|
||||
const key = get(req, 'params.key');
|
||||
|
||||
if (!key || !type) throw new BadRequest(errorMessage('missingTypeKeyEquip'));
|
||||
if (['mount', 'pet', 'costume', 'equipped'].indexOf(type) === -1) {
|
||||
@@ -44,25 +44,25 @@ export default function equip (user, req = {}) {
|
||||
throw new NotFound(i18n.t('gearNotOwned', req.language));
|
||||
}
|
||||
|
||||
let item = content.gear.flat[key];
|
||||
const item = content.gear.flat[key];
|
||||
|
||||
if (user.items.gear[type][item.type] === key) {
|
||||
user.items.gear[type] = Object.assign(
|
||||
{},
|
||||
user.items.gear[type].toObject ? user.items.gear[type].toObject() : user.items.gear[type],
|
||||
{[item.type]: `${item.type}_base_0`}
|
||||
);
|
||||
user.items.gear[type] = {
|
||||
|
||||
...(user.items.gear[type].toObject ? user.items.gear[type].toObject() : user.items.gear[type]),
|
||||
[item.type]: `${item.type}_base_0`,
|
||||
};
|
||||
if (user.markModified && type === 'owned') user.markModified('items.gear.owned');
|
||||
|
||||
message = i18n.t('messageUnEquipped', {
|
||||
itemText: item.text(req.language),
|
||||
}, req.language);
|
||||
} else {
|
||||
user.items.gear[type] = Object.assign(
|
||||
{},
|
||||
user.items.gear[type].toObject ? user.items.gear[type].toObject() : user.items.gear[type],
|
||||
{[item.type]: item.key}
|
||||
);
|
||||
user.items.gear[type] = {
|
||||
|
||||
...(user.items.gear[type].toObject ? user.items.gear[type].toObject() : user.items.gear[type]),
|
||||
[item.type]: item.key,
|
||||
};
|
||||
if (user.markModified && type === 'owned') user.markModified('items.gear.owned');
|
||||
|
||||
message = handleTwoHanded(user, item, type, req);
|
||||
@@ -71,7 +71,7 @@ export default function equip (user, req = {}) {
|
||||
}
|
||||
}
|
||||
|
||||
let res = [user.items];
|
||||
const res = [user.items];
|
||||
if (message) res.push(message);
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import content from '../content/index';
|
||||
import i18n from '../i18n';
|
||||
import forEach from 'lodash/forEach';
|
||||
import findIndex from 'lodash/findIndex';
|
||||
import get from 'lodash/get';
|
||||
import keys from 'lodash/keys';
|
||||
import upperFirst from 'lodash/upperFirst';
|
||||
import i18n from '../i18n';
|
||||
import content from '../content/index';
|
||||
import {
|
||||
BadRequest,
|
||||
NotAuthorized,
|
||||
@@ -32,7 +32,7 @@ function evolve (user, pet, req) {
|
||||
|
||||
export default function feed (user, req = {}) {
|
||||
let pet = get(req, 'params.pet');
|
||||
let foodK = get(req, 'params.food');
|
||||
const foodK = get(req, 'params.food');
|
||||
|
||||
if (!pet || !foodK) throw new BadRequest(errorMessage('missingPetFoodFeed'));
|
||||
|
||||
@@ -42,12 +42,12 @@ export default function feed (user, req = {}) {
|
||||
throw new BadRequest(errorMessage('invalidPetName'));
|
||||
}
|
||||
|
||||
let food = content.food[foodK];
|
||||
const food = content.food[foodK];
|
||||
if (!food) {
|
||||
throw new NotFound(errorMessage('invalidFoodName', req.language));
|
||||
}
|
||||
|
||||
let userPets = user.items.pets;
|
||||
const userPets = user.items.pets;
|
||||
|
||||
if (!userPets[pet.key]) {
|
||||
throw new NotFound(i18n.t('messagePetNotFound', req.language));
|
||||
@@ -70,7 +70,7 @@ export default function feed (user, req = {}) {
|
||||
if (food.key === 'Saddle') {
|
||||
message = evolve(user, pet, req);
|
||||
} else {
|
||||
let messageParams = {
|
||||
const messageParams = {
|
||||
egg: pet.text(req.language),
|
||||
foodText: food.textThe(req.language),
|
||||
};
|
||||
@@ -93,11 +93,9 @@ export default function feed (user, req = {}) {
|
||||
user.items.food[food.key]--;
|
||||
if (user.markModified) user.markModified('items.food');
|
||||
|
||||
forEach(content.animalColorAchievements, (achievement) => {
|
||||
forEach(content.animalColorAchievements, achievement => {
|
||||
if (!user.achievements[achievement.mountAchievement]) {
|
||||
const mountIndex = findIndex(keys(content.dropEggs), (animal) => {
|
||||
return !user.items.mounts[`${animal}-${achievement.color}`];
|
||||
});
|
||||
const mountIndex = findIndex(keys(content.dropEggs), animal => !user.items.mounts[`${animal}-${achievement.color}`]);
|
||||
if (mountIndex === -1) {
|
||||
user.achievements[achievement.mountAchievement] = true;
|
||||
if (user.addNotification) {
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import content from '../content/index';
|
||||
import i18n from '../i18n';
|
||||
import findIndex from 'lodash/findIndex';
|
||||
import forEach from 'lodash/forEach';
|
||||
import get from 'lodash/get';
|
||||
import keys from 'lodash/keys';
|
||||
import upperFirst from 'lodash/upperFirst';
|
||||
import i18n from '../i18n';
|
||||
import content from '../content/index';
|
||||
import {
|
||||
BadRequest,
|
||||
NotAuthorized,
|
||||
@@ -13,8 +13,8 @@ import {
|
||||
import errorMessage from '../libs/errorMessage';
|
||||
|
||||
export default function hatch (user, req = {}) {
|
||||
let egg = get(req, 'params.egg');
|
||||
let hatchingPotion = get(req, 'params.hatchingPotion');
|
||||
const egg = get(req, 'params.egg');
|
||||
const hatchingPotion = get(req, 'params.hatchingPotion');
|
||||
|
||||
if (!(egg && hatchingPotion)) {
|
||||
throw new BadRequest(errorMessage('missingEggHatchingPotion'));
|
||||
@@ -28,7 +28,7 @@ export default function hatch (user, req = {}) {
|
||||
throw new BadRequest(i18n.t('messageInvalidEggPotionCombo', req.language));
|
||||
}
|
||||
|
||||
let pet = `${egg}-${hatchingPotion}`;
|
||||
const pet = `${egg}-${hatchingPotion}`;
|
||||
|
||||
if (user.items.pets[pet] && user.items.pets[pet] > 0) {
|
||||
throw new NotAuthorized(i18n.t('messageAlreadyPet', req.language));
|
||||
@@ -43,11 +43,9 @@ export default function hatch (user, req = {}) {
|
||||
user.markModified('items.hatchingPotions');
|
||||
}
|
||||
|
||||
forEach(content.animalColorAchievements, (achievement) => {
|
||||
forEach(content.animalColorAchievements, achievement => {
|
||||
if (!user.achievements[achievement.petAchievement]) {
|
||||
const petIndex = findIndex(keys(content.dropEggs), (animal) => {
|
||||
return isNaN(user.items.pets[`${animal}-${achievement.color}`]) || user.items.pets[`${animal}-${achievement.color}`] <= 0;
|
||||
});
|
||||
const petIndex = findIndex(keys(content.dropEggs), animal => isNaN(user.items.pets[`${animal}-${achievement.color}`]) || user.items.pets[`${animal}-${achievement.color}`] <= 0);
|
||||
if (petIndex === -1) {
|
||||
user.achievements[achievement.petAchievement] = true;
|
||||
if (user.addNotification) {
|
||||
|
||||
@@ -1,20 +1,18 @@
|
||||
import cloneDeep from 'lodash/cloneDeep';
|
||||
import content from '../content/index';
|
||||
import i18n from '../i18n';
|
||||
import {
|
||||
BadRequest,
|
||||
} from '../libs/errors';
|
||||
import cloneDeep from 'lodash/cloneDeep';
|
||||
|
||||
function markNotificationAsRead (user) {
|
||||
const index = user.notifications.findIndex(notification => {
|
||||
return notification && notification.type === 'NEW_MYSTERY_ITEMS';
|
||||
});
|
||||
const index = user.notifications.findIndex(notification => notification && notification.type === 'NEW_MYSTERY_ITEMS');
|
||||
|
||||
if (index !== -1) user.notifications.splice(index, 1);
|
||||
}
|
||||
|
||||
export default function openMysteryItem (user, req = {}, analytics) {
|
||||
const mysteryItems = user.purchased.plan.mysteryItems;
|
||||
const { mysteryItems } = user.purchased.plan;
|
||||
let item = mysteryItems.shift();
|
||||
|
||||
if (!item) {
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
import each from 'lodash/each';
|
||||
import sortBy from 'lodash/sortBy';
|
||||
import lodashFind from 'lodash/find';
|
||||
import reduce from 'lodash/reduce';
|
||||
import content from '../content/index';
|
||||
import getItemInfo from '../libs/getItemInfo';
|
||||
import { BadRequest } from '../libs/errors';
|
||||
@@ -5,12 +9,8 @@ import i18n from '../i18n';
|
||||
import getItemByPathAndType from '../libs/getItemByPathAndType';
|
||||
import getOfficialPinnedItems from '../libs/getOfficialPinnedItems';
|
||||
|
||||
import each from 'lodash/each';
|
||||
import sortBy from 'lodash/sortBy';
|
||||
import lodashFind from 'lodash/find';
|
||||
import reduce from 'lodash/reduce';
|
||||
|
||||
let sortOrder = reduce(content.gearTypes, (accumulator, val, key) => {
|
||||
const sortOrder = reduce(content.gearTypes, (accumulator, val, key) => {
|
||||
accumulator[val] = key;
|
||||
return accumulator;
|
||||
}, {});
|
||||
@@ -21,9 +21,7 @@ let sortOrder = reduce(content.gearTypes, (accumulator, val, key) => {
|
||||
* @param String path
|
||||
*/
|
||||
function pathExistsInArray (array, path) {
|
||||
return array.findIndex(item => {
|
||||
return item.path === path;
|
||||
});
|
||||
return array.findIndex(item => item.path === path);
|
||||
}
|
||||
|
||||
function checkForNullEntries (array) {
|
||||
@@ -36,17 +34,15 @@ export function checkPinnedAreasForNullEntries (user) {
|
||||
}
|
||||
|
||||
export function selectGearToPin (user) {
|
||||
let changes = [];
|
||||
const changes = [];
|
||||
|
||||
each(content.gearTypes, (type) => {
|
||||
let found = lodashFind(content.gear.tree[type][user.stats.class], (item) => {
|
||||
return !user.items.gear.owned[item.key];
|
||||
});
|
||||
each(content.gearTypes, type => {
|
||||
const found = lodashFind(content.gear.tree[type][user.stats.class], item => !user.items.gear.owned[item.key]);
|
||||
|
||||
if (found) changes.push(found);
|
||||
});
|
||||
|
||||
return sortBy(changes, (change) => sortOrder[change.type]);
|
||||
return sortBy(changes, change => sortOrder[change.type]);
|
||||
}
|
||||
|
||||
export function addPinnedGear (user, type, path) {
|
||||
@@ -61,10 +57,10 @@ export function addPinnedGear (user, type, path) {
|
||||
}
|
||||
|
||||
export function addPinnedGearByClass (user) {
|
||||
let newPinnedItems = selectGearToPin(user);
|
||||
const newPinnedItems = selectGearToPin(user);
|
||||
|
||||
for (let item of newPinnedItems) {
|
||||
let itemInfo = getItemInfo(user, 'marketGear', item);
|
||||
for (const item of newPinnedItems) {
|
||||
const itemInfo = getItemInfo(user, 'marketGear', item);
|
||||
|
||||
addPinnedGear(user, itemInfo.pinType, itemInfo.path);
|
||||
}
|
||||
@@ -82,10 +78,10 @@ export function removeItemByPath (user, path) {
|
||||
}
|
||||
|
||||
export function removePinnedGearByClass (user) {
|
||||
let currentPinnedItems = selectGearToPin(user);
|
||||
const currentPinnedItems = selectGearToPin(user);
|
||||
|
||||
for (let item of currentPinnedItems) {
|
||||
let itemInfo = getItemInfo(user, 'marketGear', item);
|
||||
for (const item of currentPinnedItems) {
|
||||
const itemInfo = getItemInfo(user, 'marketGear', item);
|
||||
|
||||
removeItemByPath(user, itemInfo.path);
|
||||
}
|
||||
@@ -124,9 +120,9 @@ const PATHS_WITHOUT_ITEM = ['special.gems', 'special.rebirth_orb', 'special.fort
|
||||
/**
|
||||
* @returns {boolean} TRUE added the item / FALSE removed it
|
||||
*/
|
||||
export function togglePinnedItem (user, {item, type, path}, req = {}) {
|
||||
export function togglePinnedItem (user, { item, type, path }, req = {}) {
|
||||
let arrayToChange;
|
||||
let officialPinnedItems = getOfficialPinnedItems(user);
|
||||
const officialPinnedItems = getOfficialPinnedItems(user);
|
||||
|
||||
if (!path) {
|
||||
// If path isn't passed it means an item was passed
|
||||
@@ -137,7 +133,7 @@ export function togglePinnedItem (user, {item, type, path}, req = {}) {
|
||||
if (!item && PATHS_WITHOUT_ITEM.indexOf(path) === -1) {
|
||||
// path not exists in our content structure
|
||||
|
||||
throw new BadRequest(i18n.t('wrongItemPath', {path}, req.language));
|
||||
throw new BadRequest(i18n.t('wrongItemPath', { path }, req.language));
|
||||
}
|
||||
|
||||
// check if item exists & valid to be pinned
|
||||
@@ -171,10 +167,9 @@ export function togglePinnedItem (user, {item, type, path}, req = {}) {
|
||||
if (foundIndex >= 0) {
|
||||
arrayToChange.splice(foundIndex, 1);
|
||||
return isOfficialPinned;
|
||||
} else {
|
||||
arrayToChange.push({path, type});
|
||||
return !isOfficialPinned;
|
||||
}
|
||||
arrayToChange.push({ path, type });
|
||||
return !isOfficialPinned;
|
||||
}
|
||||
|
||||
export { default as isPinned } from '../libs/isPinned';
|
||||
|
||||
@@ -11,10 +11,10 @@ import content from '../content/index';
|
||||
function markNotificationAsRead (user, cardType) {
|
||||
const indexToRemove = user.notifications.findIndex(notification => {
|
||||
if (
|
||||
notification &&
|
||||
notification.type === 'CARD_RECEIVED' &&
|
||||
notification.data &&
|
||||
notification.data.card === cardType
|
||||
notification
|
||||
&& notification.type === 'CARD_RECEIVED'
|
||||
&& notification.data
|
||||
&& notification.data.card === cardType
|
||||
) return true;
|
||||
});
|
||||
|
||||
@@ -23,7 +23,7 @@ function markNotificationAsRead (user, cardType) {
|
||||
|
||||
|
||||
export default function readCard (user, req = {}) {
|
||||
let cardType = get(req.params, 'cardType');
|
||||
const cardType = get(req.params, 'cardType');
|
||||
|
||||
if (!cardType) {
|
||||
throw new BadRequest(i18n.t('cardTypeRequired', req.language));
|
||||
@@ -40,6 +40,6 @@ export default function readCard (user, req = {}) {
|
||||
|
||||
return [
|
||||
{ specialItems: user.items.special, cardReceived: user.flags.cardReceived },
|
||||
i18n.t('readCard', {cardType}, req.language),
|
||||
i18n.t('readCard', { cardType }, req.language),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import i18n from '../i18n';
|
||||
import each from 'lodash/each';
|
||||
import i18n from '../i18n';
|
||||
import { capByLevel } from '../statHelpers';
|
||||
import { MAX_LEVEL } from '../constants';
|
||||
import {
|
||||
@@ -18,7 +18,7 @@ export default function rebirth (user, tasks = [], req = {}, analytics) {
|
||||
throw new NotAuthorized(i18n.t('notEnoughGems', req.language));
|
||||
}
|
||||
|
||||
let analyticsData = {
|
||||
const analyticsData = {
|
||||
uuid: user._id,
|
||||
category: 'behavior',
|
||||
};
|
||||
@@ -37,9 +37,9 @@ export default function rebirth (user, tasks = [], req = {}, analytics) {
|
||||
analytics.track('Rebirth', analyticsData);
|
||||
}
|
||||
|
||||
let lvl = capByLevel(user.stats.lvl);
|
||||
const lvl = capByLevel(user.stats.lvl);
|
||||
|
||||
each(tasks, function resetTasks (task) {
|
||||
each(tasks, task => {
|
||||
if (!task.challenge || !task.challenge.id || task.challenge.broken) {
|
||||
if (task.type !== 'reward') {
|
||||
task.value = 0;
|
||||
@@ -56,7 +56,7 @@ export default function rebirth (user, tasks = [], req = {}, analytics) {
|
||||
|
||||
removePinnedGearByClass(user);
|
||||
|
||||
let stats = user.stats;
|
||||
const { stats } = user;
|
||||
stats.buffs = {};
|
||||
stats.hp = 50;
|
||||
stats.lvl = 1;
|
||||
@@ -64,7 +64,7 @@ export default function rebirth (user, tasks = [], req = {}, analytics) {
|
||||
|
||||
user.preferences.automaticAllocation = false;
|
||||
|
||||
each(USERSTATSLIST, function resetStats (value) {
|
||||
each(USERSTATSLIST, value => {
|
||||
stats[value] = 0;
|
||||
});
|
||||
|
||||
@@ -86,7 +86,7 @@ export default function rebirth (user, tasks = [], req = {}, analytics) {
|
||||
});
|
||||
}
|
||||
|
||||
let flags = user.flags;
|
||||
const { flags } = user;
|
||||
flags.itemsEnabled = false;
|
||||
flags.dropsEnabled = false;
|
||||
flags.classSelected = false;
|
||||
@@ -110,7 +110,7 @@ export default function rebirth (user, tasks = [], req = {}, analytics) {
|
||||
user.stats.buffs = {};
|
||||
|
||||
return [
|
||||
{user, tasks},
|
||||
{ user, tasks },
|
||||
i18n.t('rebirthComplete'),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import pick from 'lodash/pick';
|
||||
import content from '../content/index';
|
||||
import {beastMasterProgress, mountMasterProgress} from '../count';
|
||||
import { beastMasterProgress, mountMasterProgress } from '../count';
|
||||
import i18n from '../i18n';
|
||||
import {
|
||||
NotAuthorized,
|
||||
} from '../libs/errors';
|
||||
import splitWhitespace from '../libs/splitWhitespace';
|
||||
import pick from 'lodash/pick';
|
||||
|
||||
export default function releaseBoth (user, req = {}) {
|
||||
let animal;
|
||||
@@ -37,13 +37,13 @@ export default function releaseBoth (user, req = {}) {
|
||||
// user.balance -= 1.5;
|
||||
// }
|
||||
|
||||
let mountInfo = content.mountInfo[user.items.currentMount];
|
||||
const mountInfo = content.mountInfo[user.items.currentMount];
|
||||
|
||||
if (mountInfo && mountInfo.type === 'drop') {
|
||||
user.items.currentMount = '';
|
||||
}
|
||||
|
||||
let petInfo = content.petInfo[user.items.currentPet];
|
||||
const petInfo = content.petInfo[user.items.currentPet];
|
||||
|
||||
if (petInfo && petInfo.type === 'drop') {
|
||||
user.items.currentPet = '';
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import content from '../content/index';
|
||||
import {mountMasterProgress} from '../count';
|
||||
import { mountMasterProgress } from '../count';
|
||||
import i18n from '../i18n';
|
||||
import {
|
||||
NotAuthorized,
|
||||
@@ -18,13 +18,13 @@ export default function releaseMounts (user, req = {}, analytics) {
|
||||
|
||||
let giveMountMasterAchievement = true;
|
||||
|
||||
let mountInfo = content.mountInfo[user.items.currentMount];
|
||||
const mountInfo = content.mountInfo[user.items.currentMount];
|
||||
|
||||
if (mountInfo && mountInfo.type === 'drop') {
|
||||
user.items.currentMount = '';
|
||||
}
|
||||
|
||||
for (let mount in content.pets) {
|
||||
for (const mount in content.pets) {
|
||||
if (user.items.mounts[mount] === null || user.items.mounts[mount] === undefined) {
|
||||
giveMountMasterAchievement = false;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import content from '../content/index';
|
||||
import {beastMasterProgress} from '../count';
|
||||
import { beastMasterProgress } from '../count';
|
||||
import i18n from '../i18n';
|
||||
import {
|
||||
NotAuthorized,
|
||||
@@ -18,13 +18,13 @@ export default function releasePets (user, req = {}, analytics) {
|
||||
|
||||
let giveBeastMasterAchievement = true;
|
||||
|
||||
let petInfo = content.petInfo[user.items.currentPet];
|
||||
const petInfo = content.petInfo[user.items.currentPet];
|
||||
|
||||
if (petInfo && petInfo.type === 'drop') {
|
||||
user.items.currentPet = '';
|
||||
}
|
||||
|
||||
for (let pet in content.pets) {
|
||||
for (const pet in content.pets) {
|
||||
if (!user.items.pets[pet]) {
|
||||
giveBeastMasterAchievement = false;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import i18n from '../i18n';
|
||||
import each from 'lodash/each';
|
||||
import i18n from '../i18n';
|
||||
import {
|
||||
NotAuthorized,
|
||||
} from '../libs/errors';
|
||||
@@ -12,7 +12,7 @@ export default function reroll (user, tasks = [], req = {}, analytics) {
|
||||
user.balance--;
|
||||
user.stats.hp = 50;
|
||||
|
||||
each(tasks, function resetTaskValues (task) {
|
||||
each(tasks, task => {
|
||||
if (!task.challenge || !task.challenge.id || task.challenge.broken) {
|
||||
if (task.type !== 'reward') {
|
||||
task.value = 0;
|
||||
@@ -31,7 +31,7 @@ export default function reroll (user, tasks = [], req = {}, analytics) {
|
||||
}
|
||||
|
||||
return [
|
||||
{user, tasks},
|
||||
{ user, tasks },
|
||||
i18n.t('fortifyComplete'),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -7,14 +7,14 @@ export default function reset (user, tasks = []) {
|
||||
user.stats.gp = 0;
|
||||
user.stats.exp = 0;
|
||||
|
||||
let tasksToRemove = [];
|
||||
const tasksToRemove = [];
|
||||
tasks.forEach(task => {
|
||||
let isNotChallengeTask = !task.challenge || !task.challenge.id || task.challenge.broken;
|
||||
let isNotGroupTask = !task.group || !task.group.id || task.group.broken;
|
||||
const isNotChallengeTask = !task.challenge || !task.challenge.id || task.challenge.broken;
|
||||
const isNotGroupTask = !task.group || !task.group.id || task.group.broken;
|
||||
|
||||
if (isNotChallengeTask && isNotGroupTask) {
|
||||
tasksToRemove.push(task._id);
|
||||
let i = user.tasksOrder[`${task.type}s`].indexOf(task._id);
|
||||
const i = user.tasksOrder[`${task.type}s`].indexOf(task._id);
|
||||
if (i !== -1) user.tasksOrder[`${task.type}s`].splice(i, 1);
|
||||
}
|
||||
});
|
||||
@@ -24,7 +24,7 @@ export default function reset (user, tasks = []) {
|
||||
user.preferences.automaticAllocation = false;
|
||||
|
||||
return [
|
||||
{user, tasksToRemove},
|
||||
{ user, tasksToRemove },
|
||||
i18n.t('resetComplete'),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import content from '../content/index';
|
||||
import i18n from '../i18n';
|
||||
import merge from 'lodash/merge';
|
||||
import reduce from 'lodash/reduce';
|
||||
import each from 'lodash/each';
|
||||
import i18n from '../i18n';
|
||||
import content from '../content/index';
|
||||
import {
|
||||
NotAuthorized,
|
||||
} from '../libs/errors';
|
||||
@@ -27,7 +27,7 @@ export default function revive (user, req = {}, analytics) {
|
||||
user.stats.lvl--;
|
||||
}
|
||||
|
||||
let lostStat = randomVal(reduce(['str', 'con', 'per', 'int'], function findRandomStat (m, k) {
|
||||
const lostStat = randomVal(reduce(['str', 'con', 'per', 'int'], (m, k) => {
|
||||
if (user.stats[k]) {
|
||||
m[k] = k;
|
||||
}
|
||||
@@ -40,7 +40,7 @@ export default function revive (user, req = {}, analytics) {
|
||||
user.stats[lostStat]--;
|
||||
}
|
||||
|
||||
let base = user.items.gear.owned;
|
||||
const base = user.items.gear.owned;
|
||||
let gearOwned;
|
||||
|
||||
if (typeof base.toObject === 'function') {
|
||||
@@ -49,24 +49,24 @@ export default function revive (user, req = {}, analytics) {
|
||||
gearOwned = user.items.gear.owned;
|
||||
}
|
||||
|
||||
let losableItems = {};
|
||||
let userClass = user.stats.class;
|
||||
const losableItems = {};
|
||||
const userClass = user.stats.class;
|
||||
|
||||
each(gearOwned, function findLosableItems (value, key) {
|
||||
each(gearOwned, (value, key) => {
|
||||
let itm;
|
||||
if (value) {
|
||||
itm = content.gear.flat[key];
|
||||
|
||||
if (itm) {
|
||||
let itemHasValueOrWarrior0 = itm.value > 0 || key === 'weapon_warrior_0';
|
||||
const itemHasValueOrWarrior0 = itm.value > 0 || key === 'weapon_warrior_0';
|
||||
|
||||
let itemClassEqualsUserClass = itm.klass === userClass;
|
||||
const itemClassEqualsUserClass = itm.klass === userClass;
|
||||
|
||||
let itemClassSpecial = itm.klass === 'special';
|
||||
let itemNotSpecialOrUserClassIsSpecial = !itm.specialClass || itm.specialClass === userClass;
|
||||
let itemIsSpecial = itemNotSpecialOrUserClassIsSpecial && itemClassSpecial;
|
||||
const itemClassSpecial = itm.klass === 'special';
|
||||
const itemNotSpecialOrUserClassIsSpecial = !itm.specialClass || itm.specialClass === userClass;
|
||||
const itemIsSpecial = itemNotSpecialOrUserClassIsSpecial && itemClassSpecial;
|
||||
|
||||
let itemIsArmoire = itm.klass === 'armoire';
|
||||
const itemIsArmoire = itm.klass === 'armoire';
|
||||
|
||||
if (itemHasValueOrWarrior0 && (itemClassEqualsUserClass || itemIsSpecial || itemIsArmoire)) {
|
||||
losableItems[key] = key;
|
||||
@@ -76,12 +76,12 @@ export default function revive (user, req = {}, analytics) {
|
||||
}
|
||||
});
|
||||
|
||||
let lostItem = randomVal(losableItems, {
|
||||
const lostItem = randomVal(losableItems, {
|
||||
predictableRandom: predictableRandom(user),
|
||||
});
|
||||
|
||||
let message = '';
|
||||
let item = content.gear.flat[lostItem];
|
||||
const item = content.gear.flat[lostItem];
|
||||
|
||||
if (item) {
|
||||
removePinnedGearByClass(user);
|
||||
@@ -91,18 +91,18 @@ export default function revive (user, req = {}, analytics) {
|
||||
|
||||
addPinnedGearByClass(user);
|
||||
|
||||
let itemInfo = getItemInfo(user, 'marketGear', item);
|
||||
const itemInfo = getItemInfo(user, 'marketGear', item);
|
||||
addPinnedGear(user, itemInfo.pinType, itemInfo.path);
|
||||
|
||||
if (user.items.gear.equipped[item.type] === lostItem) {
|
||||
user.items.gear.equipped[item.type] = `${item.type}_base_0`;
|
||||
user.items.gear.equipped[item.type] = `${item.type}_base_0`;
|
||||
}
|
||||
|
||||
if (user.items.gear.costume[item.type] === lostItem) {
|
||||
user.items.gear.costume[item.type] = `${item.type}_base_0`;
|
||||
}
|
||||
|
||||
message = i18n.t('messageLostItem', { itemText: item.text(req.language)}, req.language);
|
||||
message = i18n.t('messageLostItem', { itemText: item.text(req.language) }, req.language);
|
||||
}
|
||||
|
||||
if (analytics) {
|
||||
|
||||
@@ -17,18 +17,17 @@ const CLOSE_ENOUGH = 0.00001;
|
||||
function _getTaskValue (taskValue) {
|
||||
if (taskValue < MIN_TASK_VALUE) {
|
||||
return MIN_TASK_VALUE;
|
||||
} else if (taskValue > MAX_TASK_VALUE) {
|
||||
} if (taskValue > MAX_TASK_VALUE) {
|
||||
return MAX_TASK_VALUE;
|
||||
} else {
|
||||
return taskValue;
|
||||
}
|
||||
return taskValue;
|
||||
}
|
||||
|
||||
// Calculates the next task.value based on direction
|
||||
// Uses a capped inverse log y=.95^x, y>= -5
|
||||
function _calculateDelta (task, direction, cron) {
|
||||
// Min/max on task redness
|
||||
let currVal = _getTaskValue(task.value);
|
||||
const currVal = _getTaskValue(task.value);
|
||||
let nextDelta = Math.pow(0.9747, currVal) * (direction === 'down' ? -1 : 1);
|
||||
|
||||
// Checklists
|
||||
@@ -52,15 +51,15 @@ function _calculateDelta (task, direction, cron) {
|
||||
// First, calculate the value using the normal way for our first guess although
|
||||
// it will be a bit off
|
||||
function _calculateReverseDelta (task, direction) {
|
||||
let currVal = _getTaskValue(task.value);
|
||||
const currVal = _getTaskValue(task.value);
|
||||
let testVal = currVal + Math.pow(0.9747, currVal) * (direction === 'down' ? -1 : 1);
|
||||
|
||||
// Now keep moving closer to the original value until we get "close enough"
|
||||
// Check how close we are to the original value by computing the delta off our guess
|
||||
// and looking at the difference between that and our current value.
|
||||
while (true) { // eslint-disable-line no-constant-condition
|
||||
let calc = testVal + Math.pow(0.9747, testVal);
|
||||
let diff = currVal - calc;
|
||||
const calc = testVal + Math.pow(0.9747, testVal);
|
||||
const diff = currVal - calc;
|
||||
|
||||
if (Math.abs(diff) < CLOSE_ENOUGH) break;
|
||||
|
||||
@@ -101,30 +100,30 @@ function _subtractPoints (user, task, stats, delta) {
|
||||
let conBonus = 1 - statsComputed(user).con / 250;
|
||||
if (conBonus < 0.1) conBonus = 0.1;
|
||||
|
||||
let hpMod = delta * conBonus * task.priority * 2; // constant 2 multiplier for better results
|
||||
const hpMod = delta * conBonus * task.priority * 2; // constant 2 multiplier for better results
|
||||
stats.hp += Math.round(hpMod * 10) / 10; // round to 1dp
|
||||
return stats.hp;
|
||||
}
|
||||
|
||||
function _addPoints (user, task, stats, direction, delta) {
|
||||
let _crit = user._tmp.crit || 1;
|
||||
const _crit = user._tmp.crit || 1;
|
||||
|
||||
// Exp Modifier
|
||||
// ===== Intelligence =====
|
||||
// TODO Increases Experience gain by .2% per point.
|
||||
let intBonus = 1 + statsComputed(user).int * 0.025;
|
||||
const intBonus = 1 + statsComputed(user).int * 0.025;
|
||||
stats.exp += Math.round(delta * intBonus * task.priority * _crit * 6);
|
||||
|
||||
// GP modifier
|
||||
// ===== PERCEPTION =====
|
||||
// TODO Increases Gold gained from tasks by .3% per point.
|
||||
let perBonus = 1 + statsComputed(user).per * 0.02;
|
||||
let gpMod = delta * task.priority * _crit * perBonus;
|
||||
const perBonus = 1 + statsComputed(user).per * 0.02;
|
||||
const gpMod = delta * task.priority * _crit * perBonus;
|
||||
|
||||
if (task.streak) {
|
||||
let currStreak = direction === 'down' ? task.streak - 1 : task.streak;
|
||||
let streakBonus = currStreak / 100 + 1; // eg, 1-day streak is 1.01, 2-day is 1.02, etc
|
||||
let afterStreak = gpMod * streakBonus;
|
||||
const currStreak = direction === 'down' ? task.streak - 1 : task.streak;
|
||||
const streakBonus = currStreak / 100 + 1; // eg, 1-day streak is 1.01, 2-day is 1.02, etc
|
||||
const afterStreak = gpMod * streakBonus;
|
||||
if (currStreak > 0 && gpMod > 0) {
|
||||
user._tmp.streakBonus = afterStreak - gpMod; // keep this on-hand for later, so we can notify streak-bonus
|
||||
}
|
||||
@@ -140,14 +139,14 @@ function _changeTaskValue (user, task, direction, times, cron) {
|
||||
|
||||
// ===== CRITICAL HITS =====
|
||||
// allow critical hit only when checking off a task, not when unchecking it:
|
||||
let _crit = direction === 'up' ? crit.crit(user) : 1;
|
||||
const _crit = direction === 'up' ? crit.crit(user) : 1;
|
||||
// if there was a crit, alert the user via notification
|
||||
if (_crit > 1) user._tmp.crit = _crit;
|
||||
|
||||
// If multiple days have passed, multiply times days missed
|
||||
timesLodash(times, () => {
|
||||
// Each iteration calculate the nextDelta, which is then accumulated in the total delta.
|
||||
let nextDelta = !cron && direction === 'down' ? _calculateReverseDelta(task, direction) : _calculateDelta(task, direction, cron);
|
||||
const nextDelta = !cron && direction === 'down' ? _calculateReverseDelta(task, direction) : _calculateDelta(task, direction, cron);
|
||||
|
||||
if (task.type !== 'reward') {
|
||||
if (user.preferences.automaticAllocation === true && user.preferences.allocationMode === 'taskbased' && !(task.type === 'todo' && direction === 'down')) {
|
||||
@@ -156,7 +155,7 @@ function _changeTaskValue (user, task, direction, times, cron) {
|
||||
|
||||
if (direction === 'up') { // Make progress on quest based on STR
|
||||
user.party.quest.progress.up = user.party.quest.progress.up || 0;
|
||||
let prevProgress = user.party.quest.progress.up;
|
||||
const prevProgress = user.party.quest.progress.up;
|
||||
|
||||
if (task.type === 'todo' || task.type === 'daily') {
|
||||
user.party.quest.progress.up += nextDelta * _crit * (1 + statsComputed(user).str / 200);
|
||||
@@ -185,9 +184,11 @@ function _updateCounter (task, direction, times) {
|
||||
}
|
||||
|
||||
export default function scoreTask (options = {}, req = {}) {
|
||||
let {user, task, direction, times = 1, cron = false} = options;
|
||||
const {
|
||||
user, task, direction, times = 1, cron = false,
|
||||
} = options;
|
||||
let delta = 0;
|
||||
let stats = {
|
||||
const stats = {
|
||||
gp: user.stats.gp,
|
||||
hp: user.stats.hp,
|
||||
exp: user.stats.exp,
|
||||
@@ -215,8 +216,8 @@ export default function scoreTask (options = {}, req = {}) {
|
||||
|
||||
// Save history entry for habit
|
||||
task.history = task.history || [];
|
||||
const timezoneOffset = user.preferences.timezoneOffset;
|
||||
const dayStart = user.preferences.dayStart;
|
||||
const { timezoneOffset } = user.preferences;
|
||||
const { dayStart } = user.preferences;
|
||||
const historyLength = task.history.length;
|
||||
const lastHistoryEntry = task.history[historyLength - 1];
|
||||
|
||||
@@ -229,8 +230,8 @@ export default function scoreTask (options = {}, req = {}) {
|
||||
}
|
||||
|
||||
if (
|
||||
lastHistoryEntryDate &&
|
||||
moment().zone(timezoneOffset).isSame(lastHistoryEntryDate, 'day')
|
||||
lastHistoryEntryDate
|
||||
&& moment().zone(timezoneOffset).isSame(lastHistoryEntryDate, 'day')
|
||||
) {
|
||||
lastHistoryEntry.value = task.value;
|
||||
lastHistoryEntry.date = Number(new Date());
|
||||
@@ -278,7 +279,7 @@ export default function scoreTask (options = {}, req = {}) {
|
||||
|
||||
// Save history entry for daily
|
||||
task.history = task.history || [];
|
||||
let historyEntry = {
|
||||
const historyEntry = {
|
||||
date: Number(new Date()),
|
||||
value: task.value,
|
||||
};
|
||||
@@ -312,7 +313,7 @@ export default function scoreTask (options = {}, req = {}) {
|
||||
_addPoints(user, task, stats, direction, delta);
|
||||
|
||||
// MP++ per checklist item in ToDo, bonus per CLI
|
||||
let multiplier = max([reduce(task.checklist, (m, i) => m + (i.completed ? 1 : 0), 1), 1]);
|
||||
const multiplier = max([reduce(task.checklist, (m, i) => m + (i.completed ? 1 : 0), 1), 1]);
|
||||
_gainMP(user, max([multiplier, 0.01 * statsComputed(user).maxMP * multiplier]) * (direction === 'down' ? -1 : 1));
|
||||
}
|
||||
} else if (task.type === 'reward') {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import content from '../content/index';
|
||||
import i18n from '../i18n';
|
||||
import get from 'lodash/get';
|
||||
import pick from 'lodash/pick';
|
||||
import content from '../content/index';
|
||||
import i18n from '../i18n';
|
||||
import splitWhitespace from '../libs/splitWhitespace';
|
||||
import {
|
||||
NotFound,
|
||||
@@ -13,9 +13,9 @@ import {
|
||||
const ACCEPTEDTYPES = ['eggs', 'hatchingPotions', 'food'];
|
||||
|
||||
export default function sell (user, req = {}) {
|
||||
let key = get(req.params, 'key');
|
||||
let type = get(req.params, 'type');
|
||||
let amount = get(req.query, 'amount', 1);
|
||||
const key = get(req.params, 'key');
|
||||
const type = get(req.params, 'type');
|
||||
const amount = get(req.query, 'amount', 1);
|
||||
|
||||
if (amount < 0) {
|
||||
throw new BadRequest(i18n.t('positiveAmountRequired', req.language));
|
||||
@@ -30,17 +30,17 @@ export default function sell (user, req = {}) {
|
||||
}
|
||||
|
||||
if (ACCEPTEDTYPES.indexOf(type) === -1) {
|
||||
throw new NotAuthorized(i18n.t('typeNotSellable', {acceptedTypes: ACCEPTEDTYPES.join(', ')}, req.language));
|
||||
throw new NotAuthorized(i18n.t('typeNotSellable', { acceptedTypes: ACCEPTEDTYPES.join(', ') }, req.language));
|
||||
}
|
||||
|
||||
if (!user.items[type][key]) {
|
||||
throw new NotFound(i18n.t('userItemsKeyNotFound', {type}, req.language));
|
||||
throw new NotFound(i18n.t('userItemsKeyNotFound', { type }, req.language));
|
||||
}
|
||||
|
||||
let currentAmount = user.items[type][key];
|
||||
const currentAmount = user.items[type][key];
|
||||
|
||||
if (amount > currentAmount) {
|
||||
throw new NotFound(i18n.t('userItemsNotEnough', {type}, req.language));
|
||||
throw new NotFound(i18n.t('userItemsNotEnough', { type }, req.language));
|
||||
}
|
||||
|
||||
if (type === 'food' && key === 'Saddle') {
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
import { BadRequest } from '../libs/errors';
|
||||
import get from 'lodash/get';
|
||||
import { BadRequest } from '../libs/errors';
|
||||
|
||||
// TODO used only in client, move there?
|
||||
|
||||
export default function sortTag (user, req = {}) {
|
||||
let to = get(req, 'query.to');
|
||||
let fromParam = get(req, 'query.from');
|
||||
const to = get(req, 'query.to');
|
||||
const fromParam = get(req, 'query.from');
|
||||
|
||||
let invalidTo = !to && to !== 0;
|
||||
let invalidFrom = !fromParam && fromParam !== 0;
|
||||
const invalidTo = !to && to !== 0;
|
||||
const invalidFrom = !fromParam && fromParam !== 0;
|
||||
|
||||
if (invalidTo || invalidFrom) {
|
||||
throw new BadRequest('?to=__&from=__ are required');
|
||||
|
||||
@@ -1,23 +1,21 @@
|
||||
import get from 'lodash/get';
|
||||
import findIndex from 'lodash/findIndex';
|
||||
import i18n from '../i18n';
|
||||
import preenTodos from '../libs/preenTodos';
|
||||
import {
|
||||
NotFound,
|
||||
BadRequest,
|
||||
} from '../libs/errors';
|
||||
import get from 'lodash/get';
|
||||
import findIndex from 'lodash/findIndex';
|
||||
|
||||
// TODO used only in client, move there?
|
||||
|
||||
export default function sortTask (user, req = {}) {
|
||||
let id = get(req, 'params.id');
|
||||
const id = get(req, 'params.id');
|
||||
let to = get(req, 'query.to');
|
||||
let fromParam = get(req, 'query.from');
|
||||
let taskType = get(req, 'params.taskType');
|
||||
const taskType = get(req, 'params.taskType');
|
||||
|
||||
let index = findIndex(user[`${taskType}s`], function findById (task) {
|
||||
return task._id === id;
|
||||
});
|
||||
const index = findIndex(user[`${taskType}s`], task => task._id === id);
|
||||
|
||||
if (index === -1) {
|
||||
throw new NotFound(i18n.t('messageTaskNotFound', req.language));
|
||||
@@ -26,10 +24,10 @@ export default function sortTask (user, req = {}) {
|
||||
throw new BadRequest('?to=__&from=__ are required');
|
||||
}
|
||||
|
||||
let tasks = user[`${taskType}s`];
|
||||
const tasks = user[`${taskType}s`];
|
||||
|
||||
if (taskType === 'todo') {
|
||||
let preenedTasks = preenTodos(tasks);
|
||||
const preenedTasks = preenTodos(tasks);
|
||||
|
||||
if (to !== -1) {
|
||||
to = tasks.indexOf(preenedTasks[to]);
|
||||
@@ -38,7 +36,7 @@ export default function sortTask (user, req = {}) {
|
||||
fromParam = tasks.indexOf(preenedTasks[fromParam]);
|
||||
}
|
||||
|
||||
let movedTask = tasks.splice(fromParam, 1)[0];
|
||||
const movedTask = tasks.splice(fromParam, 1)[0];
|
||||
|
||||
if (to === -1) {
|
||||
tasks.push(movedTask);
|
||||
|
||||
@@ -11,10 +11,10 @@ import errorMessage from '../../libs/errorMessage';
|
||||
import hasClass from '../../libs/hasClass';
|
||||
|
||||
export default function allocate (user, req = {}) {
|
||||
let stat = get(req, 'query.stat', 'str');
|
||||
const stat = get(req, 'query.stat', 'str');
|
||||
|
||||
if (ATTRIBUTES.indexOf(stat) === -1) {
|
||||
throw new BadRequest(errorMessage('invalidAttribute', {attr: stat}));
|
||||
throw new BadRequest(errorMessage('invalidAttribute', { attr: stat }));
|
||||
}
|
||||
|
||||
if (!hasClass(user)) {
|
||||
|
||||
@@ -15,11 +15,9 @@ export default function allocateBulk (user, req = {}) {
|
||||
if (!stats) throw new BadRequest(errorMessage('statsObjectRequired'));
|
||||
|
||||
const statKeys = Object.keys(stats);
|
||||
const invalidStats = statKeys.filter(statKey => {
|
||||
return ATTRIBUTES.indexOf(statKey) === -1;
|
||||
});
|
||||
const invalidStats = statKeys.filter(statKey => ATTRIBUTES.indexOf(statKey) === -1);
|
||||
if (invalidStats.length > 0) {
|
||||
throw new BadRequest(errorMessage('invalidAttribute', {attr: invalidStats.join(',')}));
|
||||
throw new BadRequest(errorMessage('invalidAttribute', { attr: invalidStats.join(',') }));
|
||||
}
|
||||
|
||||
if (!hasClass(user)) {
|
||||
@@ -31,14 +29,12 @@ export default function allocateBulk (user, req = {}) {
|
||||
}
|
||||
|
||||
const newStatValues = Object.values(stats);
|
||||
const totalPointsToAllocate = newStatValues.reduce((sum, value) => {
|
||||
return sum + value;
|
||||
}, 0);
|
||||
const totalPointsToAllocate = newStatValues.reduce((sum, value) => sum + value, 0);
|
||||
if (user.stats.points < totalPointsToAllocate) {
|
||||
throw new NotAuthorized(i18n.t('notEnoughAttrPoints', req.language));
|
||||
}
|
||||
|
||||
for (let [stat, value] of Object.entries(stats)) {
|
||||
for (const [stat, value] of Object.entries(stats)) {
|
||||
user.stats[stat] += value;
|
||||
user.stats.points -= value;
|
||||
if (stat === 'int') user.stats.mp += value;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import i18n from '../i18n';
|
||||
import get from 'lodash/get';
|
||||
import each from 'lodash/each';
|
||||
import pick from 'lodash/pick';
|
||||
import setWith from 'lodash/setWith';
|
||||
import i18n from '../i18n';
|
||||
import splitWhitespace from '../libs/splitWhitespace';
|
||||
import {
|
||||
NotAuthorized,
|
||||
@@ -16,14 +16,14 @@ import content from '../content/index';
|
||||
// If item is already purchased -> equip it
|
||||
// Otherwise unlock it
|
||||
export default function unlock (user, req = {}, analytics) {
|
||||
let path = get(req.query, 'path');
|
||||
const path = get(req.query, 'path');
|
||||
|
||||
if (!path) {
|
||||
throw new BadRequest(i18n.t('pathRequired', req.language));
|
||||
}
|
||||
|
||||
let isFullSet = path.indexOf(',') !== -1;
|
||||
let isBackground = path.indexOf('background.') !== -1;
|
||||
const isFullSet = path.indexOf(',') !== -1;
|
||||
const isBackground = path.indexOf('background.') !== -1;
|
||||
|
||||
let cost;
|
||||
if (isBackground && isFullSet) {
|
||||
@@ -69,11 +69,11 @@ export default function unlock (user, req = {}, analytics) {
|
||||
}
|
||||
|
||||
if (isFullSet) {
|
||||
each(setPaths, function markItemsAsPurchased (pathPart) {
|
||||
each(setPaths, pathPart => {
|
||||
if (path.indexOf('gear.') !== -1) {
|
||||
// Using Object so path[1] won't create an array but an object {path: {1: value}}
|
||||
setWith(user, pathPart, true, Object);
|
||||
let itemName = pathPart.split('.').pop();
|
||||
const itemName = pathPart.split('.').pop();
|
||||
removeItemByPath(user, `gear.flat.${itemName}`);
|
||||
if (user.markModified && path.indexOf('gear.owned') !== -1) user.markModified('items.gear.owned');
|
||||
}
|
||||
@@ -82,9 +82,9 @@ export default function unlock (user, req = {}, analytics) {
|
||||
setWith(user, `purchased.${pathPart}`, true, Object);
|
||||
});
|
||||
} else {
|
||||
let split = path.split('.');
|
||||
const split = path.split('.');
|
||||
let value = split.pop();
|
||||
let key = split.join('.');
|
||||
const key = split.join('.');
|
||||
|
||||
if (alreadyOwns) { // eslint-disable-line no-lonely-if
|
||||
if (key === 'background' && value === user.preferences.background) {
|
||||
@@ -104,8 +104,8 @@ export default function unlock (user, req = {}, analytics) {
|
||||
|
||||
// @TODO: Test and check test coverage
|
||||
if (isBackground) {
|
||||
let backgroundContent = content.backgroundsFlat[value];
|
||||
let itemInfo = getItemInfo(user, 'background', backgroundContent);
|
||||
const backgroundContent = content.backgroundsFlat[value];
|
||||
const itemInfo = getItemInfo(user, 'background', backgroundContent);
|
||||
removeItemByPath(user, itemInfo.path);
|
||||
}
|
||||
}
|
||||
@@ -131,7 +131,7 @@ export default function unlock (user, req = {}, analytics) {
|
||||
}
|
||||
}
|
||||
|
||||
let response = [
|
||||
const response = [
|
||||
pick(user, splitWhitespace('purchased preferences items')),
|
||||
];
|
||||
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
import i18n from '../i18n';
|
||||
import get from 'lodash/get';
|
||||
import findIndex from 'lodash/findIndex';
|
||||
import i18n from '../i18n';
|
||||
import { NotFound } from '../libs/errors';
|
||||
|
||||
// TODO used only in client, move there?
|
||||
|
||||
export default function updateTag (user, req = {}) {
|
||||
let tid = get(req, 'params.id');
|
||||
const tid = get(req, 'params.id');
|
||||
|
||||
let index = findIndex(user.tags, {
|
||||
const index = findIndex(user.tags, {
|
||||
id: tid,
|
||||
});
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ import omit from 'lodash/omit';
|
||||
|
||||
// From server pass task.toObject() not the task document directly
|
||||
export default function updateTask (task, req = {}) {
|
||||
let body = req.body || {};
|
||||
const body = req.body || {};
|
||||
|
||||
// If reminders are updated -> replace the original ones
|
||||
if (body.reminders) {
|
||||
|
||||
Reference in New Issue
Block a user