wip(shared): port buy ops and linked fns
This commit is contained in:
@@ -1,24 +1,23 @@
|
||||
import content from '../content/index';
|
||||
import i18n from '../i18n';
|
||||
|
||||
module.exports = function(user, item, type, req) {
|
||||
var message, currentWeapon, currentShield;
|
||||
if (type == null) {
|
||||
type = 'equipped';
|
||||
}
|
||||
currentShield = content.gear.flat[user.items.gear[type].shield];
|
||||
currentWeapon = content.gear.flat[user.items.gear[type].weapon];
|
||||
module.exports = function handleTwoHanded (user, item, type = 'equipped', req) {
|
||||
let currentShield = content.gear.flat[user.items.gear[type].shield];
|
||||
let currentWeapon = content.gear.flat[user.items.gear[type].weapon];
|
||||
|
||||
if (item.type === "shield" && (currentWeapon ? currentWeapon.twoHanded : false)) {
|
||||
let message;
|
||||
|
||||
if (item.type === 'shield' && (currentWeapon ? currentWeapon.twoHanded : false)) {
|
||||
user.items.gear[type].weapon = 'weapon_base_0';
|
||||
message = i18n.t('messageTwoHandedUnequip', {
|
||||
twoHandedText: currentWeapon.text(req.language), offHandedText: item.text(req.language),
|
||||
}, req.language);
|
||||
} else if (item.twoHanded && (currentShield && user.items.gear[type].shield != "shield_base_0")) {
|
||||
user.items.gear[type].shield = "shield_base_0";
|
||||
} else if (item.twoHanded && (currentShield && user.items.gear[type].shield !== 'shield_base_0')) {
|
||||
user.items.gear[type].shield = 'shield_base_0';
|
||||
message = i18n.t('messageTwoHandedEquip', {
|
||||
twoHandedText: item.text(req.language), offHandedText: currentShield.text(req.language),
|
||||
}, req.language);
|
||||
}
|
||||
|
||||
return message;
|
||||
};
|
||||
|
||||
@@ -1,20 +1,19 @@
|
||||
import _ from 'lodash';
|
||||
/*
|
||||
Because the same op needs to be performed on the client and the server (critical hits, item drops, etc),
|
||||
we need things to be "random", but technically predictable so that they don't go out-of-sync
|
||||
*/
|
||||
|
||||
module.exports = function(user, seed) {
|
||||
var x;
|
||||
// Because the same op needs to be performed on the client and the server (critical hits, item drops, etc),
|
||||
// we need things to be "random", but technically predictable so that they don't go out-of-sync
|
||||
|
||||
module.exports = function predictableRandom (user, seed) {
|
||||
if (!seed || seed === Math.PI) {
|
||||
seed = _.reduce(user.stats, (function(m, v) {
|
||||
if (_.isNumber(v)) {
|
||||
return m + v;
|
||||
seed = _.reduce(user.stats, (accumulator, val) => {
|
||||
if (_.isNumber(val)) {
|
||||
return accumulator + val;
|
||||
} else {
|
||||
return m;
|
||||
return accumulator;
|
||||
}
|
||||
}), 0);
|
||||
}, 0);
|
||||
}
|
||||
x = Math.sin(seed++) * 10000;
|
||||
|
||||
let x = Math.sin(seed++) * 10000;
|
||||
return x - Math.floor(x);
|
||||
};
|
||||
|
||||
@@ -1,14 +1,12 @@
|
||||
import _ from 'lodash';
|
||||
import predictableRandom from './predictableRandom';
|
||||
|
||||
/*
|
||||
Get a random property from an object
|
||||
returns random property (the value)
|
||||
*/
|
||||
// Get a random property from an object
|
||||
// returns random property (the value)
|
||||
|
||||
module.exports = function(user, obj, options) {
|
||||
var array, rand;
|
||||
array = (options != null ? options.key : void 0) ? _.keys(obj) : _.values(obj);
|
||||
rand = user.fns.predictableRandom(options != null ? options.seed : void 0);
|
||||
module.exports = function randomVal (user, obj, options = {}) {
|
||||
let array = options.key ? _.keys(obj) : _.values(obj);
|
||||
let rand = predictableRandom(user, options.seed);
|
||||
array.sort();
|
||||
return array[Math.floor(rand * array.length)];
|
||||
};
|
||||
|
||||
@@ -1,33 +1,35 @@
|
||||
import content from '../content/index';
|
||||
import _ from 'lodash';
|
||||
|
||||
module.exports = function(user) {
|
||||
var base, owned;
|
||||
owned = typeof window !== "undefined" && window !== null ? user.items.gear.owned : user.items.gear.owned.toObject();
|
||||
if ((base = user.achievements).ultimateGearSets == null) {
|
||||
base.ultimateGearSets = {
|
||||
module.exports = function ultimateGear (user) {
|
||||
let owned = window ? user.items.gear.owned : user.items.gear.owned.toObject();
|
||||
|
||||
if (!user.achievements.ultimateGearSets) {
|
||||
user.achievements.ultimateGearSets = {
|
||||
healer: false,
|
||||
wizard: false,
|
||||
rogue: false,
|
||||
warrior: false
|
||||
warrior: false,
|
||||
};
|
||||
}
|
||||
content.classes.forEach(function(klass) {
|
||||
|
||||
content.classes.forEach((klass) => {
|
||||
if (user.achievements.ultimateGearSets[klass] !== true) {
|
||||
return user.achievements.ultimateGearSets[klass] = _.reduce(['armor', 'shield', 'head', 'weapon'], function(soFarGood, type) {
|
||||
var found;
|
||||
found = _.find(content.gear.tree[type][klass], {
|
||||
last: true
|
||||
user.achievements.ultimateGearSets[klass] = _.reduce(['armor', 'shield', 'head', 'weapon'], (soFarGood, type) => {
|
||||
let found = _.find(content.gear.tree[type][klass], {
|
||||
last: true,
|
||||
});
|
||||
return soFarGood && (!found || owned[found.key] === true);
|
||||
}, true);
|
||||
}
|
||||
});
|
||||
if (typeof user.markModified === "function") {
|
||||
user.markModified('achievements.ultimateGearSets');
|
||||
}
|
||||
|
||||
// TODO
|
||||
if (user.markModified) user.markModified('achievements.ultimateGearSets');
|
||||
|
||||
if (_.contains(user.achievements.ultimateGearSets, true) && user.flags.armoireEnabled !== true) {
|
||||
user.flags.armoireEnabled = true;
|
||||
return typeof user.markModified === "function" ? user.markModified('flags') : void 0;
|
||||
}
|
||||
|
||||
return;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user