wip(shared): port buy ops and linked fns

This commit is contained in:
Matteo Pagliazzi
2016-03-16 16:25:46 +01:00
parent e68ebee980
commit ff72706cae
11 changed files with 227 additions and 215 deletions

View File

@@ -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);
};