// Generated by CoffeeScript 1.3.3 var MODIFIER, async, content, cron, expModifier, helpers, hpModifier, model, moment, score, setModel, setupNotifications, taskDeltaFormula, updateStats, user, _; async = require('async'); moment = require('moment'); _ = require('lodash'); content = require('./content'); helpers = require('./helpers'); MODIFIER = .03; user = void 0; model = void 0; setModel = function(m) { model = m; user = model.at('_user'); return setupNotifications(); }; setupNotifications = function() { var statsNotification; if (typeof jQuery === "undefined" || jQuery === null) { return; } statsNotification = function(html, type) { if (user.get('stats.lvl') === 0) { return; } return $.bootstrapGrowl(html, { type: type, top_offset: 20, align: 'right', width: 250, delay: 3000, allow_dismiss: true, stackup_spacing: 10 }); }; user.on('set', 'stats.hp', function(captures, args) { var num, rounded; num = captures - args; rounded = Math.abs(num.toFixed(1)); if (num < 0) { return statsNotification("HP -" + rounded, 'error'); } }); user.on('set', 'stats.money', function(captures, args) { var num, rounded; num = captures - args; rounded = Math.abs(num.toFixed(1)); if (num < 0) { return statsNotification("GP -" + rounded, 'success'); } else if (num > 0) { num = Math.abs(num); return statsNotification("Exp,GP +" + rounded, 'success'); } }); return user.on('set', 'stats.lvl', function(captures, args) { if (captures > args) { return statsNotification(' Level Up!', 'info'); } }); }; /* Calculates Exp & GP modification based on weapon & lvl {value} task.value for gain {modifiers} may manually pass in stats as {weapon, exp}. This is used for testing */ expModifier = function(value, modifiers) { var dmg, lvl, modified, weapon, _ref; if (modifiers == null) { modifiers = null; } _ref = [user.get('items.weapon'), user.get('stats.lvl')], weapon = _ref[0], lvl = _ref[1]; if (modifiers) { weapon = modifiers.weapon, lvl = modifiers.lvl; } dmg = weapon * MODIFIER; dmg += (lvl - 1) * MODIFIER; modified = value + (value * dmg); return modified; }; /* Calculates HP-loss modification based on armor & lvl {value} task.value which is hurting us {modifiers} may manually pass in modifier as {armor, lvl}. This is used for testing */ hpModifier = function(value, modifiers) { var ac, armor, lvl, modified, _ref; if (modifiers == null) { modifiers = null; } _ref = [user.get('items.armor'), user.get('stats.lvl')], armor = _ref[0], lvl = _ref[1]; if (modifiers) { armor = modifiers.armor, lvl = modifiers.lvl; } ac = armor * MODIFIER; ac += (lvl - 1) * MODIFIER; modified = value - (value * ac); return modified; }; /* Calculates the next task.value based on direction For negative values, use a line: something like y=-.1x+1 For positibe values, taper off with inverse log: y=.9^x Would love to use inverse log for the whole thing, but after 13 fails it hits infinity. Revisit this formula later {currentValue} the current value of the task, determines it's next value {direction} 'up' or 'down' */ taskDeltaFormula = function(currentValue, direction) { var delta, sign; sign = direction === "up" ? 1 : -1; return delta = currentValue < 0 ? (-0.1 * currentValue + 1) * sign : (Math.pow(0.9, currentValue)) * sign; }; updateStats = function(stats) { var money, tnl; if (user.get('stats.lvl') === 0) { return; } if (stats.hp != null) { if (stats.hp <= 0) { user.set('stats.lvl', 0); user.set('stast.hp', 0); return; } else { user.set('stats.hp', stats.hp); } } if (stats.exp != null) { tnl = user.get('_tnl'); if (stats.exp >= tnl) { stats.exp -= tnl; user.set('stats.lvl', user.get('stats.lvl') + 1); user.set('stats.hp', 50); } if (!user.get('items.itemsEnabled') && stats.exp >= 15) { user.set('items.itemsEnabled', true); $('ul.items').popover({ title: content.items.unlockedMessage.title, placement: 'left', trigger: 'manual', html: true, content: "
" + content.items.unlockedMessage.content + " [Close]