fix randomVal to be actually random. Fixes habitrpg/habitrpg#2176

This commit is contained in:
Cole Gleason 2014-01-11 02:43:07 -06:00
parent 3e290b4734
commit 2f51041bf4
2 changed files with 133 additions and 58 deletions

View file

@ -27,7 +27,8 @@ process.nextTick = (function () {
if (canPost) {
var queue = [];
window.addEventListener('message', function (ev) {
if (ev.source === window && ev.data === 'process-tick') {
var source = ev.source;
if ((source === window || source === null) && ev.data === 'process-tick') {
ev.stopPropagation();
if (queue.length > 0) {
var fn = queue.shift();
@ -63,7 +64,7 @@ process.chdir = function (dir) {
};
},{}],3:[function(require,module,exports){
var global=self;/**
var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {};/**
* @license
* Lo-Dash 2.4.1 (Custom Build) <http://lodash.com/>
* Build: `lodash modern -o ./dist/lodash.js`
@ -9397,6 +9398,7 @@ var global=self;/**
value: 150,
canOwn: (function(u) {
var _ref;
return +((_ref = u.backer) != null ? _ref.tier : void 0) >= 70;
})
},
@ -9410,6 +9412,7 @@ var global=self;/**
value: 170,
canOwn: (function(u) {
var _ref;
return +((_ref = u.contributor) != null ? _ref.level : void 0) >= 4;
})
},
@ -9421,6 +9424,7 @@ var global=self;/**
value: 200,
canOwn: (function(u) {
var _ref;
return +((_ref = u.backer) != null ? _ref.tier : void 0) >= 300;
})
},
@ -9433,6 +9437,7 @@ var global=self;/**
value: 200,
canOwn: (function(u) {
var _ref;
return +((_ref = u.backer) != null ? _ref.tier : void 0) >= 300;
})
},
@ -9628,6 +9633,7 @@ var global=self;/**
value: 150,
canOwn: (function(u) {
var _ref;
return +((_ref = u.backer) != null ? _ref.tier : void 0) >= 45;
})
},
@ -9641,6 +9647,7 @@ var global=self;/**
value: 170,
canOwn: (function(u) {
var _ref;
return +((_ref = u.contributor) != null ? _ref.level : void 0) >= 2;
})
},
@ -9652,6 +9659,7 @@ var global=self;/**
value: 200,
canOwn: (function(u) {
var _ref;
return +((_ref = u.backer) != null ? _ref.tier : void 0) >= 300;
})
},
@ -9845,6 +9853,7 @@ var global=self;/**
value: 150,
canOwn: (function(u) {
var _ref;
return +((_ref = u.backer) != null ? _ref.tier : void 0) >= 45;
})
},
@ -9858,6 +9867,7 @@ var global=self;/**
value: 170,
canOwn: (function(u) {
var _ref;
return +((_ref = u.contributor) != null ? _ref.level : void 0) >= 3;
})
},
@ -9869,6 +9879,7 @@ var global=self;/**
value: 200,
canOwn: (function(u) {
var _ref;
return +((_ref = u.backer) != null ? _ref.tier : void 0) >= 300;
})
},
@ -10048,6 +10059,7 @@ var global=self;/**
value: 150,
canOwn: (function(u) {
var _ref;
return +((_ref = u.backer) != null ? _ref.tier : void 0) >= 45;
})
},
@ -10061,6 +10073,7 @@ var global=self;/**
value: 170,
canOwn: (function(u) {
var _ref;
return +((_ref = u.contributor) != null ? _ref.level : void 0) >= 5;
})
},
@ -10113,6 +10126,7 @@ var global=self;/**
return _.each(['base', 'warrior', 'rogue', 'healer', 'wizard', 'special'], function(klass) {
return _.each(gear[type][klass], function(item, i) {
var key, _canOwn;
key = "" + type + "_" + klass + "_" + i;
_.defaults(item, {
type: type,
@ -10191,6 +10205,7 @@ var global=self;/**
notes: 'With a crack, flames burst from your staff, scorching a task. You deal high damage to the task, and gain additional experience (more experience for greens).',
cast: function(user, target) {
var bonus;
bonus = user._statsComputed.int * user.fns.crit('per');
target.value += diminishingReturns(bonus * .02, 4);
bonus *= Math.ceil((target.value < 0 ? 1 : target.value + 1) * .075);
@ -10209,6 +10224,7 @@ var global=self;/**
cast: function(user, target) {
return _.each(target, function(member) {
var bonus;
bonus = Math.ceil(user._statsComputed.int * .1);
if (bonus > 25) {
bonus = 25;
@ -10225,8 +10241,9 @@ var global=self;/**
notes: "The ground below your party's tasks cracks and shakes with extreme intensity, slowing them down and opening them up to more attacks. Your party gains a buff to experience.",
cast: function(user, target) {
return _.each(target, function(member) {
var _base;
if ((_base = member.stats.buffs).int == null) {
var _base, _ref;
if ((_ref = (_base = member.stats.buffs).int) == null) {
_base.int = 0;
}
return member.stats.buffs.int += Math.ceil(user._statsComputed.int * .05);
@ -10265,8 +10282,9 @@ var global=self;/**
target: 'self',
notes: "You take a moment to relax your body and enter a defensive stance to ready yourself for the tasks' next onslaught. Reduces damage from dailies at the end of the day.",
cast: function(user, target) {
var _base;
if ((_base = user.stats.buffs).con == null) {
var _base, _ref;
if ((_ref = (_base = user.stats.buffs).con) == null) {
_base.con = 0;
}
return user.stats.buffs.con += Math.ceil(user._statsComputed.con * .05);
@ -10280,8 +10298,9 @@ var global=self;/**
notes: "Your presence emboldens the party. Their newfound courage gives them a boost of strength. Party members gain a buff to their STR.",
cast: function(user, target) {
return _.each(target, function(member) {
var _base;
if ((_base = member.stats.buffs).str == null) {
var _base, _ref;
if ((_ref = (_base = member.stats.buffs).str) == null) {
_base.str = 0;
}
return member.stats.buffs.str += Math.ceil(user._statsComputed.str * .05);
@ -10296,8 +10315,9 @@ var global=self;/**
notes: "Your gaze strikes fear into the hearts of your party's enemies. The party gains a moderate boost to defense.",
cast: function(user, target) {
return _.each(target, function(member) {
var _base;
if ((_base = member.stats.buffs).con == null) {
var _base, _ref;
if ((_ref = (_base = member.stats.buffs).con) == null) {
_base.con = 0;
}
return member.stats.buffs.con += Math.ceil(user._statsComputed.con * .03);
@ -10324,6 +10344,7 @@ var global=self;/**
notes: "Without a sound, you sweep behind a task and stab it in the back. You deal higher damage to the task, with a higher chance of a critical hit.",
cast: function(user, target) {
var bonus, _crit;
_crit = user.fns.crit('per', .3);
target.value += _crit * .03;
bonus = (target.value < 0 ? 1 : target.value + 1) * _crit;
@ -10339,8 +10360,9 @@ var global=self;/**
notes: "You share your thievery tools with the party to aid them in 'acquiring' more gold. The party's gold bonus for tasks and chance of drops is buffed for a day.",
cast: function(user, target) {
return _.each(target, function(member) {
var _base;
if ((_base = member.stats.buffs).per == null) {
var _base, _ref;
if ((_ref = (_base = member.stats.buffs).per) == null) {
_base.per = 0;
}
return member.stats.buffs.per += Math.ceil(user._statsComputed.per * .03);
@ -10354,8 +10376,9 @@ var global=self;/**
target: 'self',
notes: "You duck into the shadows, pulling up your hood. Many dailies won't find you this night; fewer yet the higher your Perception.",
cast: function(user, target) {
var _base;
if ((_base = user.stats.buffs).stealth == null) {
var _base, _ref;
if ((_ref = (_base = user.stats.buffs).stealth) == null) {
_base.stealth = 0;
}
return user.stats.buffs.stealth += Math.ceil(user._statsComputed.per * .03);
@ -10399,8 +10422,9 @@ var global=self;/**
notes: "A magical aura surrounds your party members, protecting them from damage. Your party members gain a buff to their defense.",
cast: function(user, target) {
return _.each(target, function(member) {
var _base;
if ((_base = member.stats.buffs).con == null) {
var _base, _ref;
if ((_ref = (_base = member.stats.buffs).con) == null) {
_base.con = 0;
}
return member.stats.buffs.con += Math.ceil(user._statsComputed.con * .15);
@ -10431,9 +10455,10 @@ var global=self;/**
target: 'user',
notes: "Throw a snowball at a party member, what could possibly go wrong? Lasts until member's new day.",
cast: function(user, target) {
var _base;
var _base, _ref;
target.stats.buffs.snowball = true;
if ((_base = target.achievements).snowball == null) {
if ((_ref = (_base = target.achievements).snowball) == null) {
_base.snowball = 0;
}
target.achievements.snowball++;
@ -10457,6 +10482,7 @@ var global=self;/**
_.each(api.spells, function(spellClass) {
return _.each(spellClass, function(spell, key) {
var _cast;
spell.key = key;
_cast = spell.cast;
return spell.cast = function(user, target) {
@ -10837,6 +10863,7 @@ var process=require("__browserify_process");(function() {
sanitizeOptions = function(o) {
var dayStart, now, timezoneOffset, _ref;
dayStart = !_.isNaN(+o.dayStart) && (0 <= (_ref = +o.dayStart) && _ref <= 24) ? +o.dayStart : 0;
timezoneOffset = o.timezoneOffset ? +o.timezoneOffset : +moment().zone();
now = o.now ? moment(o.now).zone(timezoneOffset) : moment(+(new Date)).zone(timezoneOffset);
@ -10849,6 +10876,7 @@ var process=require("__browserify_process");(function() {
api.startOfWeek = api.startOfWeek = function(options) {
var o;
if (options == null) {
options = {};
}
@ -10858,6 +10886,7 @@ var process=require("__browserify_process");(function() {
api.startOfDay = function(options) {
var o;
if (options == null) {
options = {};
}
@ -10882,6 +10911,7 @@ var process=require("__browserify_process");(function() {
api.daysSince = function(yesterday, options) {
var o;
if (options == null) {
options = {};
}
@ -10898,6 +10928,7 @@ var process=require("__browserify_process");(function() {
api.shouldDo = function(day, repeat, options) {
var o, selected, yesterday;
if (options == null) {
options = {};
}
@ -10963,12 +10994,14 @@ var process=require("__browserify_process");(function() {
preenHistory = function(history) {
var newHistory, preen, thisMonth;
history = _.filter(history, function(h) {
return !!h;
});
newHistory = [];
preen = function(amount, groupBy) {
var groups;
groups = _.chain(history).groupBy(function(h) {
return moment(h.date).format(groupBy);
}).sortBy(function(h, k) {
@ -11002,12 +11035,14 @@ var process=require("__browserify_process");(function() {
api.updateStore = function(user) {
var changes;
if (!user) {
return;
}
changes = [];
_.each(['weapon', 'armor', 'shield', 'head'], function(type) {
var found;
found = _.find(content.gear.tree[type][user.stats["class"]], function(item) {
return !user.items.gear.owned[item.key];
});
@ -11057,6 +11092,7 @@ var process=require("__browserify_process");(function() {
api.uuid = function() {
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) {
var r, v;
r = Math.random() * 16 | 0;
v = (c === "x" ? r : r & 0x3 | 0x8);
return v.toString(16);
@ -11076,7 +11112,8 @@ var process=require("__browserify_process");(function() {
api.taskDefaults = function(task) {
var defaults, _ref, _ref1, _ref2;
var defaults, _ref, _ref1, _ref2, _ref3;
if (task == null) {
task = {};
}
@ -11124,7 +11161,7 @@ var process=require("__browserify_process");(function() {
});
}
task._id = task.id;
if (task.value == null) {
if ((_ref3 = task.value) == null) {
task.value = task.type === 'reward' ? 10 : 0;
}
if (!_.isNumber(task.priority)) {
@ -11159,6 +11196,7 @@ var process=require("__browserify_process");(function() {
api.encodeiCalLink = function(uid, apiToken) {
var loc, _ref;
loc = (typeof window !== "undefined" && window !== null ? window.location.host : void 0) || (typeof process !== "undefined" && process !== null ? (_ref = process.env) != null ? _ref.BASE_URL : void 0 : void 0) || '';
return encodeURIComponent("http://" + loc + "/v1/users/" + uid + "/calendar.ics?apiToken=" + apiToken);
};
@ -11196,6 +11234,7 @@ var process=require("__browserify_process");(function() {
api.taskClasses = function(task, filters, dayStart, lastCron, showCompleted, main) {
var classes, completed, enabled, filter, repeat, type, value, _ref;
if (filters == null) {
filters = [];
}
@ -11297,6 +11336,7 @@ var process=require("__browserify_process");(function() {
api.appliedTags = function(userTags, taskTags) {
var arr;
arr = [];
_.each(userTags, function(t) {
if (t == null) {
@ -11311,6 +11351,7 @@ var process=require("__browserify_process");(function() {
api.countPets = function(originalCount, pets) {
var count, pet;
count = originalCount != null ? originalCount : _.size(pets);
for (pet in content.specialPets) {
if (pets[pet]) {
@ -11381,6 +11422,7 @@ var process=require("__browserify_process");(function() {
},
revive: function(req, cb) {
var item, lostItem, lostStat;
_.merge(user.stats, {
hp: 50,
exp: 0,
@ -11423,6 +11465,7 @@ var process=require("__browserify_process");(function() {
},
reset: function(req, cb) {
var gear;
user.habits = [];
user.dailys = [];
user.todos = [];
@ -11465,6 +11508,7 @@ var process=require("__browserify_process");(function() {
},
rebirth: function(req, cb) {
var flags, gear, lvl, stats;
if (user.balance < 2) {
return typeof cb === "function" ? cb({
code: 401,
@ -11542,6 +11586,7 @@ var process=require("__browserify_process");(function() {
clearCompleted: function(req, cb) {
_.remove(user.todos, function(t) {
var _ref;
return t.completed && !((_ref = t.challenge) != null ? _ref.id : void 0);
});
if (typeof user.markModified === "function") {
@ -11551,6 +11596,7 @@ var process=require("__browserify_process");(function() {
},
sortTask: function(req, cb) {
var from, id, task, tasks, to, _ref;
id = req.params.id;
_ref = req.query, to = _ref.to, from = _ref.from;
task = user.tasks[id];
@ -11569,6 +11615,7 @@ var process=require("__browserify_process");(function() {
},
updateTask: function(req, cb) {
var task, _ref;
if (!(task = user.tasks[(_ref = req.params) != null ? _ref.id : void 0])) {
return typeof cb === "function" ? cb("Task not found") : void 0;
}
@ -11583,6 +11630,7 @@ var process=require("__browserify_process");(function() {
},
deleteTask: function(req, cb) {
var i, task, _ref;
task = user.tasks[(_ref = req.params) != null ? _ref.id : void 0];
if (!task) {
return typeof cb === "function" ? cb({
@ -11598,6 +11646,7 @@ var process=require("__browserify_process");(function() {
},
addTask: function(req, cb) {
var task;
task = api.taskDefaults(req.body);
user["" + task.type + "s"].unshift(task);
if (user.preferences.newTaskEdit) {
@ -11609,7 +11658,9 @@ var process=require("__browserify_process");(function() {
return task;
},
addTag: function(req, cb) {
if (user.tags == null) {
var _ref;
if ((_ref = user.tags) == null) {
user.tags = [];
}
user.tags.push({
@ -11620,6 +11671,7 @@ var process=require("__browserify_process");(function() {
},
updateTag: function(req, cb) {
var i, tid;
tid = req.params.id;
i = _.findIndex(user.tags, {
id: tid
@ -11632,6 +11684,7 @@ var process=require("__browserify_process");(function() {
},
deleteTag: function(req, cb) {
var i, tag, tid;
tid = req.params.id;
i = _.findIndex(user.tags, {
id: tid
@ -11652,6 +11705,7 @@ var process=require("__browserify_process");(function() {
},
feed: function(req, cb) {
var egg, evolve, food, message, pet, potion, userPets, _ref, _ref1, _ref2;
_ref = req.params, pet = _ref.pet, food = _ref.food;
food = content.food[food];
_ref1 = pet.split('-'), egg = _ref1[0], potion = _ref1[1];
@ -11711,6 +11765,7 @@ var process=require("__browserify_process");(function() {
},
purchase: function(req, cb) {
var item, key, type, _ref;
_ref = req.params, type = _ref.type, key = _ref.key;
if (type !== 'eggs' && type !== 'hatchingPotions' && type !== 'food' && type !== 'quests' && type !== 'special') {
return typeof cb === "function" ? cb({
@ -11734,6 +11789,7 @@ var process=require("__browserify_process");(function() {
},
buy: function(req, cb) {
var item, key, message, _ref;
key = req.params.key;
item = key === 'potion' ? content.potion : content.gear.flat[key];
if (!item) {
@ -11772,6 +11828,7 @@ var process=require("__browserify_process");(function() {
},
sell: function(req, cb) {
var key, type, _ref;
_ref = req.params, key = _ref.key, type = _ref.type;
if (type !== 'eggs' && type !== 'hatchingPotions' && type !== 'food') {
return typeof cb === "function" ? cb({
@ -11791,6 +11848,7 @@ var process=require("__browserify_process");(function() {
},
equip: function(req, cb) {
var item, key, message, type, _ref;
_ref = [req.params.type || 'equipped', req.params.key], type = _ref[0], key = _ref[1];
switch (type) {
case 'mount':
@ -11812,6 +11870,7 @@ var process=require("__browserify_process");(function() {
},
hatch: function(req, cb) {
var egg, hatchingPotion, pet, _ref;
_ref = req.params, egg = _ref.egg, hatchingPotion = _ref.hatchingPotion;
if (!(egg && hatchingPotion)) {
return typeof cb === "function" ? cb({
@ -11839,6 +11898,7 @@ var process=require("__browserify_process");(function() {
},
unlock: function(req, cb) {
var alreadyOwns, cost, fullSet, k, path, split, v;
path = req.query.path;
fullSet = ~path.indexOf(",");
cost = fullSet ? 1.25 : 0.5;
@ -11872,12 +11932,14 @@ var process=require("__browserify_process");(function() {
},
changeClass: function(req, cb) {
var klass, _ref;
klass = (_ref = req.query) != null ? _ref["class"] : void 0;
if (klass === 'warrior' || klass === 'rogue' || klass === 'wizard' || klass === 'healer') {
user.stats["class"] = klass;
user.flags.classSelected = true;
_.each(["weapon", "armor", "shield", "head"], function(type) {
var foundKey;
foundKey = false;
_.findLast(user.items.gear.owned, function(v, k) {
if (~k.indexOf(type + "_" + klass) && v === true) {
@ -11925,6 +11987,7 @@ var process=require("__browserify_process");(function() {
},
allocate: function(req, cb) {
var stat;
stat = req.query.stat || 'str';
if (user.stats.points > 0) {
user.stats[stat]++;
@ -11936,7 +11999,8 @@ var process=require("__browserify_process");(function() {
return typeof cb === "function" ? cb(null, _.pick(user, $w('stats'))) : void 0;
},
score: function(req, cb) {
var addPoints, calculateDelta, delta, direction, id, mpDelta, num, options, stats, subtractPoints, task, th, _ref, _ref1, _ref2;
var addPoints, calculateDelta, delta, direction, id, mpDelta, num, options, stats, subtractPoints, task, th, _ref, _ref1, _ref2, _ref3, _ref4;
_ref = req.params, id = _ref.id, direction = _ref.direction;
task = user.tasks[id];
options = req.query || {};
@ -11952,7 +12016,7 @@ var process=require("__browserify_process");(function() {
};
task.value = +task.value;
task.streak = ~~task.streak;
if (task.priority == null) {
if ((_ref1 = task.priority) == null) {
task.priority = 1;
}
if (task.value > stats.gp && task.type === 'reward') {
@ -11961,10 +12025,11 @@ var process=require("__browserify_process");(function() {
delta = 0;
calculateDelta = function() {
return _.times(options.times, function() {
var adjustAmt, currVal, nextDelta, _ref1, _ref2;
var adjustAmt, currVal, nextDelta, _ref2, _ref3;
currVal = task.value < -47.27 ? -47.27 : task.value > 21.27 ? 21.27 : task.value;
nextDelta = Math.pow(0.9747, currVal) * (direction === 'down' ? -1 : 1);
if (((_ref1 = task.checklist) != null ? _ref1.length : void 0) > 0) {
if (((_ref2 = task.checklist) != null ? _ref2.length : void 0) > 0) {
if (direction === 'down' && task.type === 'daily' && options.cron) {
nextDelta *= 1 - _.reduce(task.checklist, (function(m, i) {
return m + (i.completed ? 1 : 0);
@ -11982,7 +12047,7 @@ var process=require("__browserify_process");(function() {
if (direction === 'up' && task.type !== 'reward' && !(task.type === 'habit' && !task.down)) {
adjustAmt = nextDelta * (1 + user._statsComputed.str * .004);
user.party.quest.progress.up = user.party.quest.progress.up || 0;
if ((_ref2 = task.type) === 'daily' || _ref2 === 'todo') {
if ((_ref3 = task.type) === 'daily' || _ref3 === 'todo') {
user.party.quest.progress.up += adjustAmt;
}
}
@ -11993,6 +12058,7 @@ var process=require("__browserify_process");(function() {
};
addPoints = function() {
var afterStreak, gpMod, intBonus, perBonus, streakBonus, _crit;
_crit = user.fns.crit();
if (_crit > 1) {
user._tmp.crit = _crit;
@ -12005,6 +12071,7 @@ var process=require("__browserify_process");(function() {
};
subtractPoints = function() {
var conBonus, hpMod;
conBonus = 1 - (user._statsComputed.con / 250);
if (conBonus < .1) {
conBonus = 0.1;
@ -12020,7 +12087,7 @@ var process=require("__browserify_process");(function() {
} else {
subtractPoints();
}
th = (task.history != null ? task.history : task.history = []);
th = ((_ref2 = task.history) != null ? _ref2 : task.history = []);
if (th[th.length - 1] && moment(th[th.length - 1].date).isSame(new Date, 'day')) {
th[th.length - 1].value = task.value;
} else {
@ -12064,7 +12131,7 @@ var process=require("__browserify_process");(function() {
} else {
calculateDelta();
addPoints();
mpDelta = _.max([1 + (((_ref1 = task.checklist) != null ? _ref1.length : void 0) || 0), .01 * user._statsComputed.maxMP * (1 + (((_ref2 = task.checklist) != null ? _ref2.length : void 0) || 0))]);
mpDelta = _.max([1 + (((_ref3 = task.checklist) != null ? _ref3.length : void 0) || 0), .01 * user._statsComputed.maxMP * (1 + (((_ref4 = task.checklist) != null ? _ref4.length : void 0) || 0))]);
if (direction === 'down') {
mpDelta *= -1;
}
@ -12105,6 +12172,7 @@ var process=require("__browserify_process");(function() {
user.fns = {
getItem: function(type) {
var item;
item = content.gear.flat[user.items.gear.equipped[type]];
if (!item) {
return content.gear.flat["" + type + "_base_0"];
@ -12113,6 +12181,7 @@ var process=require("__browserify_process");(function() {
},
handleTwoHanded: function(item, type) {
var message, weapon, _ref;
if (type == null) {
type = 'equipped';
}
@ -12133,6 +12202,7 @@ var process=require("__browserify_process");(function() {
predictableRandom: function(seed) {
var x;
if (!seed || seed === Math.PI) {
seed = _.reduce(user.stats, (function(m, v) {
if (_.isNumber(v)) {
@ -12160,21 +12230,15 @@ var process=require("__browserify_process");(function() {
},
/*
Get a random property from an object
http://stackoverflow.com/questions/2532218/pick-random-property-from-a-javascript-object
returns random property (the value)
*/
randomVal: function(obj, options) {
var count, key, result, val;
result = void 0;
count = 0;
for (key in obj) {
val = obj[key];
if (user.fns.predictableRandom(options != null ? options.seed : void 0) < (1 / ++count)) {
result = ((options != null ? options.key : void 0) ? key : val);
}
}
return result;
var array, rand;
array = (options != null ? options.key : void 0) ? _.keys(obj) : _.values(obj);
rand = user.fns.predictableRandom(typeof option !== "undefined" && option !== null ? option.seed : void 0);
return array[Math.floor(rand * array.length)];
},
/*
This allows you to set object properties by dot-path. Eg, you can run pathSet('stats.hp',50,user) which is the same as
@ -12186,22 +12250,27 @@ var process=require("__browserify_process");(function() {
dotSet: function(path, val) {
var arr,
_this = this;
arr = path.split('.');
return _.reduce(arr, function(curr, next, index) {
var _ref;
if ((arr.length - 1) === index) {
curr[next] = val;
}
return curr[next] != null ? curr[next] : curr[next] = {};
return (_ref = curr[next]) != null ? _ref : curr[next] = {};
}, user);
},
dotGet: function(path) {
var _this = this;
return _.reduce(path.split('.'), (function(curr, next) {
return curr != null ? curr[next] : void 0;
}), user);
},
randomDrop: function(modifiers) {
var acceptableDrops, bonus, chance, drop, dropK, quest, rarity, task, _base, _base1, _base2, _name, _name1, _name2, _ref, _ref1;
var acceptableDrops, bonus, chance, drop, dropK, quest, rarity, task, _base, _base1, _base2, _name, _name1, _name2, _ref, _ref1, _ref2, _ref3, _ref4;
task = modifiers.task;
bonus = Math.abs(task.value) * task.priority + (task.streak || 0) + (user._statsComputed.per * .5);
bonus /= 100;
@ -12227,7 +12296,7 @@ var process=require("__browserify_process");(function() {
rarity = user.fns.predictableRandom(user.stats.gp);
if (rarity > .6) {
drop = user.fns.randomVal(_.omit(content.food, 'Saddle'));
if ((_base = user.items.food)[_name = drop.key] == null) {
if ((_ref2 = (_base = user.items.food)[_name = drop.key]) == null) {
_base[_name] = 0;
}
user.items.food[drop.key] += 1;
@ -12235,7 +12304,7 @@ var process=require("__browserify_process");(function() {
drop.dialog = "You've found " + drop.article + drop.text + "! " + drop.notes;
} else if (rarity > .3) {
drop = user.fns.randomVal(content.eggs);
if ((_base1 = user.items.eggs)[_name1 = drop.key] == null) {
if ((_ref3 = (_base1 = user.items.eggs)[_name1 = drop.key]) == null) {
_base1[_name1] = 0;
}
user.items.eggs[drop.key]++;
@ -12246,7 +12315,7 @@ var process=require("__browserify_process");(function() {
drop = user.fns.randomVal(_.pick(content.hatchingPotions, (function(v, k) {
return __indexOf.call(acceptableDrops, k) >= 0;
})));
if ((_base2 = user.items.hatchingPotions)[_name2 = drop.key] == null) {
if ((_ref4 = (_base2 = user.items.hatchingPotions)[_name2 = drop.key]) == null) {
_base2[_name2] = 0;
}
user.items.hatchingPotions[drop.key]++;
@ -12267,6 +12336,7 @@ var process=require("__browserify_process");(function() {
autoAllocate: function() {
return user.stats[(function() {
var diff, ideal, preference, stats, suggested;
switch (user.preferences.allocationMode) {
case "flat":
stats = _.pick(user.stats, $w('con str per int'));
@ -12311,7 +12381,8 @@ var process=require("__browserify_process");(function() {
})()]++;
},
updateStats: function(stats) {
var tnl;
var tnl, _ref;
if (stats.hp <= 0) {
return user.stats.hp = 0;
}
@ -12342,7 +12413,7 @@ var process=require("__browserify_process");(function() {
}
}
user.stats.exp = stats.exp;
if (user.flags == null) {
if ((_ref = user.flags) == null) {
user.flags = {};
}
if (!user.flags.customizationsNotification && (user.stats.exp > 10 || user.stats.lvl > 1)) {
@ -12384,7 +12455,8 @@ var process=require("__browserify_process");(function() {
*/
cron: function(options) {
var daysMissed, expTally, lvl, now, progress, todoTally, _base, _base1, _base2, _progress;
var daysMissed, expTally, lvl, now, progress, todoTally, _base, _base1, _base2, _progress, _ref, _ref1, _ref2, _ref3;
if (options == null) {
options = {};
}
@ -12416,11 +12488,12 @@ var process=require("__browserify_process");(function() {
return;
}
todoTally = 0;
if ((_base = user.party.quest.progress).down == null) {
if ((_ref = (_base = user.party.quest.progress).down) == null) {
_base.down = 0;
}
user.todos.concat(user.dailys).forEach(function(task) {
var absVal, completed, delta, id, repeat, scheduleMisses, type;
var absVal, completed, delta, id, repeat, scheduleMisses, type, _ref1;
if (!task) {
return;
}
@ -12434,6 +12507,7 @@ var process=require("__browserify_process");(function() {
scheduleMisses = 0;
_.times(daysMissed, function(n) {
var thatDay;
thatDay = moment(now).subtract('days', n + 1);
if (api.shouldDo(thatDay, repeat, user.preferences)) {
return scheduleMisses++;
@ -12458,7 +12532,7 @@ var process=require("__browserify_process");(function() {
}
switch (type) {
case 'daily':
(task.history != null ? task.history : task.history = []).push({
((_ref1 = task.history) != null ? _ref1 : task.history = []).push({
date: +(new Date),
value: task.value
});
@ -12481,7 +12555,7 @@ var process=require("__browserify_process");(function() {
}
}
});
((_base1 = (user.history != null ? user.history : user.history = {})).todos != null ? (_base1 = (user.history != null ? user.history : user.history = {})).todos : _base1.todos = []).push({
((_ref1 = (_base1 = ((_ref2 = user.history) != null ? _ref2 : user.history = {})).todos) != null ? _ref1 : _base1.todos = []).push({
date: now,
value: todoTally
});
@ -12491,7 +12565,7 @@ var process=require("__browserify_process");(function() {
lvl++;
expTally += api.tnl(lvl);
}
((_base2 = user.history).exp != null ? (_base2 = user.history).exp : _base2.exp = []).push({
((_ref3 = (_base2 = user.history).exp) != null ? _ref3 : _base2.exp = []).push({
date: now,
value: expTally
});
@ -12527,6 +12601,7 @@ var process=require("__browserify_process");(function() {
}
_.each(user.habits.concat(user.dailys), function(task) {
var _ref;
if (((_ref = task.history) != null ? _ref.length : void 0) > minHistLen) {
task.history = preenHistory(task.history);
}
@ -12548,9 +12623,11 @@ var process=require("__browserify_process");(function() {
get: function() {
var computed,
_this = this;
computed = _.reduce(['per', 'con', 'str', 'int'], function(m, stat) {
m[stat] = _.reduce($w('stats stats.buffs items.gear.equipped.weapon items.gear.equipped.armor items.gear.equipped.head items.gear.equipped.shield'), function(m2, path) {
var item, val;
val = user.fns.dotGet(path);
return m2 + (~path.indexOf('items.gear') ? (item = content.gear.flat[val], (+(item != null ? item[stat] : void 0) || 0) * ((item != null ? item.klass : void 0) === user.stats["class"] ? 1.5 : 1)) : +val[stat] || 0);
}, 0);
@ -12564,6 +12641,7 @@ var process=require("__browserify_process");(function() {
return Object.defineProperty(user, 'tasks', {
get: function() {
var tasks;
tasks = user.habits.concat(user.dailys).concat(user.todos).concat(user.rewards);
return _.object(_.pluck(tasks, "id"), tasks);
}

View file

@ -910,15 +910,12 @@ api.wrap = (user, main=true) ->
###
Get a random property from an object
http://stackoverflow.com/questions/2532218/pick-random-property-from-a-javascript-object
returns random property (the value)
###
randomVal: (obj, options) ->
result = undefined
count = 0
for key, val of obj
result = (if options?.key then key else val) if user.fns.predictableRandom(options?.seed) < (1 / ++count)
result
array = if options?.key then _.keys(obj) else _.values(obj)
rand = user.fns.predictableRandom(option?.seed)
array[Math.floor(rand * array.length)]
###
This allows you to set object properties by dot-path. Eg, you can run pathSet('stats.hp',50,user) which is the same as