diff --git a/README.md b/README.md
index b7e93364c3..9798592610 100644
--- a/README.md
+++ b/README.md
@@ -4,11 +4,12 @@ Shared resources useful for the multiple HabitRPG repositories, that way all the
* Algorithms - level up algorithm, scoring functions, etc
* Item definitions - weapons, armor, pets
-Note: We can't load CommonJS format into the browser. There's a way to pull it in with RequireJS (r.js?), but I couldn't get that working. Instead I created a `Makefile` which runs Browserify to compile `index-browser.js`, which you include in a `` tag in your index.html. Let's fix this sometime.
##Installation
- * `npm install`
- * `make`
+ * Node.js - just include files as usual.
+ * Browser - user requre.js with "cs" plugin to include files directly into your index.html
+
+#TODO add and example of require.js config.
##CSS
Shared CSS between the website and the mobile app is a fuzzy area. For now we'll have the website define canonical CSS, and share that down the mobile app.
diff --git a/algos.coffee b/algos.coffee
new file mode 100644
index 0000000000..7d2f311b72
--- /dev/null
+++ b/algos.coffee
@@ -0,0 +1,378 @@
+({ define: (
+ if typeof define == "function"
+ define
+ else
+ (F)->
+ F(require, exports, module)
+)}).define (require, exports, module)->
+ XP = 15
+ HP = 2
+ obj = module.exports =
+ {};
+ obj.priorityValue = (priority = '!') ->
+ switch priority
+ when '!' then 1
+ when '!!' then 1.5
+ when '!!!' then 2
+ else
+ 1
+
+ obj.tnl = (level) ->
+ if level >= 100
+ value = 0
+ else
+ value = Math.round(((Math.pow(level, 2) * 0.25) + (10 * level) + 139.75) / 10) * 10
+ # round to nearest 10
+ return value
+
+ ###
+ Calculates Exp modificaiton based on level and weapon strength
+ {value} task.value for exp gain
+ {weaponStrength) weapon strength
+ {level} current user level
+ {priority} user-defined priority multiplier
+ ###
+ obj.expModifier = (value, weaponStr, level, priority = '!') ->
+ str = (level - 1) / 2
+ # ultimately get this from user
+ totalStr = (str + weaponStr) / 100
+ strMod = 1 + totalStr
+ exp = value * XP * strMod * obj.priorityValue(priority)
+ return Math.round(exp)
+
+ ###
+ Calculates HP modification based on level and armor defence
+ {value} task.value for hp loss
+ {armorDefense} defense from armor
+ {helmDefense} defense from helm
+ {level} current user level
+ {priority} user-defined priority multiplier
+ ###
+ obj.hpModifier = (value, armorDef, helmDef, shieldDef, level, priority = '!') ->
+ def = (level - 1) / 2
+ # ultimately get this from user?
+ totalDef = (def + armorDef + helmDef + shieldDef) / 100
+ #ultimate get this from user
+ defMod = 1 - totalDef
+ hp = value * HP * defMod * obj.priorityValue(priority)
+ return Math.round(hp * 10) / 10
+ # round to 1dp
+
+ ###
+ Future use
+ {priority} user-defined priority multiplier
+ ###
+ obj.gpModifier = (value, modifier, priority = '!', streak, user) ->
+ val = value * modifier * obj.priorityValue(priority)
+ if streak and user
+ streakBonus = streak / 100 + 1
+ # eg, 1-day streak is 1.1, 2-day is 1.2, etc
+ afterStreak = val * streakBonus
+ user.streakBonus = afterStreak - val if (val > 0)
+ # can we do this without model? just global emit?
+ return afterStreak
+ else
+ return val
+
+ ###
+ Calculates the next task.value based on direction
+ Uses a capped inverse log y=.95^x, y>= -5
+ {currentValue} the current value of the task
+ {direction} up or down
+ ###
+ obj.taskDeltaFormula = (currentValue, direction) ->
+ if currentValue < -47.27 then currentValue = -47.27
+ else if currentValue > 21.27 then currentValue = 21.27
+ delta = Math.pow(0.9747, currentValue)
+ return delta if direction is 'up'
+ return -delta
+
+
+ ###
+ Drop System
+ ###
+
+ randomDrop = (user, delta, priority, streak = 0) ->
+ # limit drops to 2 / day
+ if !user.items.lastDrop?
+ user.items =
+ {
+ date: +moment().subtract('d', 1) # trick - set it to yesterday on first run, that way they can get drops today
+ count: 0
+ }
+ reachedDropLimit = (helpers.daysBetween(user.items.lastDrop.date,
+ +new Date) is 0) and user.items.lastDrop.count >= 2
+ return if reachedDropLimit
+
+ # % chance of getting a pet or meat
+ chanceMultiplier = Math.abs(delta)
+ chanceMultiplier *= obj.priorityValue(priority)
+ # multiply chance by reddness
+ chanceMultiplier += streak
+ # streak bonus
+ console.log chanceMultiplier
+
+ if user.flags.dropsEnabled and Math.random() < (.05 * chanceMultiplier)
+ # current breakdown - 3% (adjustable) chance on drop
+ # If they got a drop: 50% chance of egg, 50% Hatching Potion. If hatchingPotion, broken down further even further
+ rarity = Math.random()
+
+ # Egg, 40% chance
+ if rarity > .6
+ drop = randomVal(pets)
+ user.items.eggs.push drop
+ drop.type = 'Egg'
+ drop.dialog = "You've found a #{drop.text} Egg! #{drop.notes}"
+
+ # Hatching Potion, 60% chance - break down by rarity even more. FIXME this may not be the best method, so revisit
+ else
+ acceptableDrops = []
+
+ # Tier 5 (Blue Moon Rare)
+ if rarity < .1
+ acceptableDrops =
+ ['Base', 'White', 'Desert', 'Red', 'Shade', 'Skeleton', 'Zombie', 'CottonCandyPink', 'CottonCandyBlue',
+ 'Golden']
+
+ # Tier 4 (Very Rare)
+ else if rarity < .2
+ acceptableDrops =
+ ['Base', 'White', 'Desert', 'Red', 'Shade', 'Skeleton', 'Zombie', 'CottonCandyPink', 'CottonCandyBlue']
+
+ # Tier 3 (Rare)
+ else if rarity < .3
+ acceptableDrops = ['Base', 'White', 'Desert', 'Red', 'Shade', 'Skeleton']
+
+ # Tier 2 (Scarce)
+ else if rarity < .4
+ acceptableDrops = ['Base', 'White', 'Desert']
+ # Tier 1 (Common)
+ else
+ acceptableDrops = ['Base']
+
+ acceptableDrops = hatchingPotions.filter (hatchingPotion) ->
+ hatchingPotion.name in acceptableDrops
+ drop = randomVal acceptableDrops
+ user.items.hatchingPotions.push drop.name
+ drop.type = 'HatchingPotion'
+ drop.dialog = "You've found a #{drop.text} Hatching Potion! #{drop.notes}"
+
+ user.drop = drop
+
+ user.items.lastDrop.date = +new Date
+ user.items.lastDrop.count++
+
+ # {task} task you want to score
+ # {direction} 'up' or 'down'
+ obj.score = (user, task, direction, items) ->
+ {gp, hp, exp, lvl} = user.stats
+ {type, value, streak} = task
+ priority = task.priority or '!'
+
+ # If they're trying to purhcase a too-expensive reward, confirm they want to take a hit for it
+ if task.value > user.stats.gp and task.type is 'reward'
+ r = confirm "Not enough GP to purchase this reward, buy anyway and lose HP? (Punishment for taking a reward you didn't earn)."
+ unless r
+ #TODO if this rule is working OK.
+ return
+
+ delta = 0
+ calculateDelta = (adjustvalue = true) ->
+ # Each iteration calculate the delta (nextDelta), which is then accumulated in delta
+ # (aka, the total delta). This weirdness won't be necessary when calculating mathematically
+ # rather than iteratively
+ nextDelta = obj.taskDeltaFormula(value, direction)
+ value += nextDelta if adjustvalue
+ delta += nextDelta
+
+ addPoints = ->
+ level = user.stats.lvl
+ weaponStrength = items.items.weapon[user.items.weapon].strength
+ exp += obj.expModifier(delta, weaponStrength, level, priority) / 2
+ # / 2 hack for now bcause people leveling too fast
+ if streak
+ gp += obj.gpModifier(delta, 1, priority, streak, user)
+ else
+ gp += obj.gpModifier(delta, 1, priority)
+
+
+ subtractPoints = ->
+ level = user.stats.lvl
+ armorDefense = items.items.armor[user.items.armor].defense
+ helmDefense = items.items.head[user.items.head].defense
+ shieldDefense = items.items.shield[user.items.shield].defense
+ hp += obj.hpModifier(delta, armorDefense, helmDefense, shieldDefense, level, priority)
+
+ switch type
+ when 'habit'
+ calculateDelta()
+ # Add habit value to habit-history (if different)
+ if (delta > 0) then addPoints() else subtractPoints()
+ task.history ?= []
+ if task.value != value
+ historyEntry = { date: +new Date, value: value }
+ task.history.push historyEntry
+
+ when 'daily'
+ calculateDelta(false)
+ if delta != 0
+ addPoints()
+ # obviously for delta>0, but also a trick to undo accidental checkboxes
+ if direction is 'up'
+ streak = if streak then streak + 1 else 1
+ else
+ streak = if streak then streak - 1 else 0
+ task.streak = streak
+
+ when 'todo'
+ calculateDelta()
+ addPoints() # obviously for delta>0, but also a trick to undo accidental checkboxes
+
+ when 'reward'
+ # Don't adjust values for rewards
+ calculateDelta(false)
+ # purchase item
+ gp -= Math.abs(task.value)
+ num = parseFloat(task.value).toFixed(2)
+ # if too expensive, reduce health & zero gp
+ if gp < 0
+ hp += gp
+ # hp - gp difference
+ gp = 0
+
+ task.value = value
+ updateStats user, { hp, exp, gp }
+
+ # Drop system
+ # randomDrop(user, delta, priority, streak) if direction is 'up'
+
+ return delta
+
+ ###
+ Updates user stats with new stats. Handles death, leveling up, etc
+ {stats} new stats
+ {update} if aggregated changes, pass in userObj as update. otherwise commits will be made immediately
+ ###
+ updateStats = (user, newStats) ->
+ # if user is dead, dont do anything
+ return if user.stats.hp <= 0
+
+ if newStats.hp?
+ # Game Over
+ if newStats.hp <= 0
+ user.stats.hp = 0
+ # signifies dead
+ return
+ else
+ user.stats.hp = newStats.hp
+
+ if newStats.exp?
+ tnl = obj.tnl(user.stats.lvl)
+ #silent = false
+ # if we're at level 100, turn xp to gold
+ if user.stats.lvl >= 100
+ newStats.gp += newStats.exp / 15
+ newStats.exp = 0
+ user.stats.lvl = 100
+ else
+ # level up & carry-over exp
+ if newStats.exp >= tnl
+ #silent = true # push through the negative xp silently
+ user.stats.exp = newStats.exp
+ # push normal + notification
+ while newStats.exp >= tnl and user.stats.lvl < 100 # keep levelling up
+ newStats.exp -= tnl
+ user.stats.lvl++
+ tnl = obj.tnl(user.stats.lvl)
+ if user.stats.lvl == 100
+ newStats.exp = 0
+ user.stats.hp = 50
+
+ user.stats.exp = newStats.exp
+ #if silent
+ #console.log("pushing silent :" + obj.stats.exp)
+
+
+ # Set flags when they unlock features
+ if !user.flags.customizationsNotification and (user.stats.exp > 10 or user.stats.lvl > 1)
+ user.flags.customizationsNotification = true
+ if !user.flags.itemsEnabled and user.stats.lvl >= 2
+ user.flags.itemsEnabled = true
+ if !user.flags.partyEnabled and user.stats.lvl >= 3
+ user.flags.partyEnabled = true
+ if !user.flags.dropsEnabled and user.stats.lvl >= 4
+ user.flags.dropsEnabled = true
+
+ if newStats.gp?
+ #FIXME what was I doing here? I can't remember, gp isn't defined
+ gp = 0.0 if (!gp? or gp < 0)
+ user.stats.gp = newStats.gp
+
+ ###
+ At end of day, add value to all incomplete Daily & Todo tasks (further incentive)
+ For incomplete Dailys, deduct experience
+ Make sure to run this function once in a while as server will not take care of overnight calculations.
+ And you have to run it every time client connects.
+ ###
+ obj.cron = (user) ->
+ today = +new Date
+ daysPassed = helpers.daysBetween(user.lastCron, today, user.preferences.dayStart)
+ if daysPassed > 0
+ user.lastCron = today
+
+ if user.flags.rest is true
+ user.dailys.forEach (daily) ->
+ daily.completed = false
+ return
+
+ # Tally each task
+ todoTally = 0
+ user.todos.concat(user.dailys).forEach (task) ->
+ {id, type, completed, repeat} = task
+ # Deduct experience for missed Daily tasks,
+ # but not for Todos (just increase todo's value)
+ unless completed
+ # for todos & typical dailies, these are equivalent
+ daysFailed = daysPassed
+ # however, for dailys which have repeat dates, need
+ # to calculate how many they've missed according to their own schedule
+ if type == 'daily' && repeat
+ daysFailed = 0
+ for i in [1..daysPassed] by 1
+ thatDay = moment().subtract('days', i + 1)
+ if repeat[helpers.dayMapping[thatDay.day()]] == true
+ daysFailed++
+ score user, task, 'down'
+ if type == 'daily'
+ if completed #set OHV for completed dailies
+ task.value = task.value + taskDeltaFormula(task.value, 'up')
+ task.history ?= []
+ task.history.push { date: +new Date, value: task.value }
+ task.completed = false
+ else
+ #get updated value
+ absVal = if (completed) then Math.abs(task.value) else task.value
+ todoTally += absVal
+ user.habits.forEach (task) -> # slowly reset 'onlies' value to 0
+ if task.up == false or task.down == false
+ if Math.abs(task.value) < 0.1
+ task.value = 0
+ else
+ task.value = task.value / 2
+
+ # Finished tallying
+ user.history ?= {};
+ user.history.todos ?= [];
+ user.history.exp ?= []
+ user.history.todos.push { date: today, value: todoTally }
+ # tally experience
+ expTally = user.stats.exp
+ lvl = 0
+ #iterator
+ while lvl < (user.stats.lvl - 1)
+ lvl++
+ expTally += obj.tnl(lvl)
+ user.history.exp.push { date: today, value: expTally }
+ user
+
+
diff --git a/algos.js b/algos.js
deleted file mode 100644
index 94125c832f..0000000000
--- a/algos.js
+++ /dev/null
@@ -1,256 +0,0 @@
-var HP = 15
- , XP = 2
- , Items = require('./items');
-
-function priorityValue(priority) {
- if (priority == null) {
- priority = '!';
- }
- switch (priority) {
- case '!':
- return 1;
- case '!!':
- return 1.5;
- case '!!!':
- return 2;
- default:
- return 1;
- }
-};
-
-function tnl(level) {
- var value;
- if (level >= 100) {
- value = 0;
- } else {
- value = Math.round(((Math.pow(level, 2) * 0.25) + (10 * level) + 139.75) / 10) * 10;
- }
- return value;
-};
-
-/*
- Calculates Exp modificaiton based on level and weapon strength
- {value} task.value for exp gain
- {weaponStrength) weapon strength
- {level} current user level
- {priority} user-defined priority multiplier
- */
-
-
-function expModifier(value, weaponStr, level, priority) {
- var exp, str, strMod, totalStr;
- if (priority == null) {
- priority = '!';
- }
- str = (level - 1) / 2;
- totalStr = (str + weaponStr) / 100;
- strMod = 1 + totalStr;
- exp = value * XP * strMod * priorityValue(priority);
- return Math.round(exp);
-};
-
-/*
- Calculates HP modification based on level and armor defence
- {value} task.value for hp loss
- {armorDefense} defense from armor
- {helmDefense} defense from helm
- {level} current user level
- {priority} user-defined priority multiplier
- */
-
-
-function hpModifier(value, armorDef, helmDef, shieldDef, level, priority) {
- var def, defMod, hp, totalDef;
- if (priority == null) {
- priority = '!';
- }
- def = (level - 1) / 2;
- totalDef = (def + armorDef + helmDef + shieldDef) / 100;
- defMod = 1 - totalDef;
- hp = value * HP * defMod * priorityValue(priority);
- return Math.round(hp * 10) / 10;
-};
-
-/*
- Future use
- {priority} user-defined priority multiplier
- */
-
-
-function gpModifier(value, modifier, priority) {
- if (priority == null) {
- priority = '!';
- }
- return value * modifier * priorityValue(priority);
-};
-
-/*
- Calculates the next task.value based on direction
- Uses a capped inverse log y=.95^x, y>= -5
- {currentValue} the current value of the task
- {direction} up or down
- */
-
-
-function taskDeltaFormula(currentValue, direction) {
- var delta;
- if (currentValue < -47.27) {
- currentValue = -47.27;
- } else if (currentValue > 21.27) {
- currentValue = 21.27;
- }
- delta = Math.pow(0.9747, currentValue);
- if (direction === 'up') {
- return delta;
- }
- return -delta;
-};
-
-function score(user, taskId, direction, times, cron) {
- var task = _.findWhere(user.tasks, {id: taskId})
- , type = task.type
- , value = task.value
- , priority = task.priority || '!'
- , delta = 0
- , times = times? times: 1;
-
-
- if (task.value > user.stats.gp && task.type === 'reward') {
- r = confirm("Not enough GP to purchase this reward, buy anyway and lose HP? (Punishment for taking a reward you didn't earn).");
- if (!r) return;
- }
-
- function calculateDelta(adjustvalue) {
- adjustvalue = adjustvalue? adjustvalue: true;
- _.times(times, function(n) {
- var nextDelta;
- nextDelta = taskDeltaFormula(value, direction);
- if (adjustvalue) {
- value += nextDelta;
- }
- delta += nextDelta;
- });
- };
-
- function addPoints() {
- var level, weaponStrength;
- level = user.stats.lvl;
- weaponStrength = Items.items.weapon[user.items.weapon].strength;
- user.stats.exp += expModifier(delta, weaponStrength, level, priority);
- user.stats.gp += gpModifier(delta, 1, priority);
- };
-
- function subtractPoints() {
- var armorDefense, helmDefense, level, shieldDefense;
- level = user.stats.lvl;
- armorDefense = Items.items.armor[user.items.armor].defense;
- helmDefense = Items.items.head[user.items.head].defense;
- shieldDefense = Items.items.shield[user.items.shield].defense;
- user.stats.hp += hpModifier(delta, armorDefense, helmDefense, shieldDefense, level, priority);
- };
- switch (type) {
- case 'habit':
- calculateDelta();
- if (delta > 0) {
- addPoints();
- } else {
- subtractPoints();
- }
- task.history = task.history? task.history: [];
- if (task.value !== value) {
- task.history.push({
- date: +(new Date),
- value: value
- });
- }
- break;
- case 'daily':
- if (cron != null) {
- calculateDelta();
- subtractPoints();
- } else {
- calculateDelta(false);
- if (delta !== 0) {
- addPoints();
- }
- }
- break;
- case 'todo':
- if (cron != null) {
- calculateDelta();
- } else {
- calculateDelta();
- addPoints();
- }
- break;
- case 'reward':
- calculateDelta(false);
- user.stats.gp -= Math.abs(task.value);
- var num = parseFloat(task.value).toFixed(2);
- if (user.stats.gp < 0) {
- user.stats.hp += user.stats.gp;
- user.stats.gp = 0;
- }
- }
- task.value = value;
- updateStats(user);
- return delta;
-};
-
-/*
- Updates user stats with new stats. Handles death, leveling up, etc
- {stats} new stats
- {update} if aggregated changes, pass in userObj as update. otherwise commits will be made immediately
- */
-
-
-function updateStats(user) {
- if (user.stats.lvl === 0) return;
- if (user.stats.hp <= 0) {
- user.stats.lvl = 0; // signifies dead
- user.stats.hp = 0;
- return;
- }
- if (user.stats.lvl >= 100) {
- user.stats.gp += user.stats.exp / 15;
- user.stats.exp = 0;
- user.stats.lvl = 100;
- } else {
- var currTnl = user.stats.tnl = tnl(user.stats.lvl);
- if (user.stats.exp >= currTnl) {
- while (user.stats.exp >= currTnl && user.stats.lvl < 100) {
- user.stats.exp -= currTnl;
- user.stats.lvl++;
- user.stats.tnl = tnl(user.stats.lvl);
- }
- if (user.stats.lvl === 100) {
- user.stats.exp = 0;
- }
- user.stats.hp = 50;
- }
- }
- if (!user.flags.customizationsNotification && (user.stats.exp > 10 || user.stats.lvl > 1)) {
- user.flags.customizationsNotification = true;
- user.flags.customizationsNotification = true;
- }
- if (!user.flags.itemsEnabled && user.stats.lvl >= 2) {
- user.flags.itemsEnabled = true;
- user.flags.itemsEnabled = true;
- }
- if (!user.flags.partyEnabled && user.stats.lvl >= 3) {
- user.flags.partyEnabled = true;
- user.flags.partyEnabled = true;
- }
- if (!user.flags.petsEnabled && user.stats.lvl >= 4) {
- user.flags.petsEnabled = true;
- user.flags.petsEnabled = true;
- }
-
- if (user.stats.gp < 0) user.stats.gp = 0.0;
-};
-
-
-module.exports = {
- tnl: tnl,
- score: score
-}
\ No newline at end of file
diff --git a/index-browser.js b/index-browser.js
deleted file mode 100644
index 5b6584bb64..0000000000
--- a/index-browser.js
+++ /dev/null
@@ -1,2037 +0,0 @@
-;(function(e,t,n){function i(n,s){if(!t[n]){if(!e[n]){var o=typeof require=="function"&&require;if(!s&&o)return o(n,!0);if(r)return r(n,!0);throw new Error("Cannot find module '"+n+"'")}var u=t[n]={exports:{}};e[n][0].call(u.exports,function(t){var r=e[n][1][t];return i(r?r:t)},u,u.exports)}return t[n].exports}var r=typeof require=="function"&&require;for(var s=0;s= 100) {
- value = 0;
- } else {
- value = Math.round(((Math.pow(level, 2) * 0.25) + (10 * level) + 139.75) / 10) * 10;
- }
- return value;
-};
-
-/*
- Calculates Exp modificaiton based on level and weapon strength
- {value} task.value for exp gain
- {weaponStrength) weapon strength
- {level} current user level
- {priority} user-defined priority multiplier
- */
-
-
-function expModifier(value, weaponStr, level, priority) {
- var exp, str, strMod, totalStr;
- if (priority == null) {
- priority = '!';
- }
- str = (level - 1) / 2;
- totalStr = (str + weaponStr) / 100;
- strMod = 1 + totalStr;
- exp = value * XP * strMod * priorityValue(priority);
- return Math.round(exp);
-};
-
-/*
- Calculates HP modification based on level and armor defence
- {value} task.value for hp loss
- {armorDefense} defense from armor
- {helmDefense} defense from helm
- {level} current user level
- {priority} user-defined priority multiplier
- */
-
-
-function hpModifier(value, armorDef, helmDef, shieldDef, level, priority) {
- var def, defMod, hp, totalDef;
- if (priority == null) {
- priority = '!';
- }
- def = (level - 1) / 2;
- totalDef = (def + armorDef + helmDef + shieldDef) / 100;
- defMod = 1 - totalDef;
- hp = value * HP * defMod * priorityValue(priority);
- return Math.round(hp * 10) / 10;
-};
-
-/*
- Future use
- {priority} user-defined priority multiplier
- */
-
-
-function gpModifier(value, modifier, priority) {
- if (priority == null) {
- priority = '!';
- }
- return value * modifier * priorityValue(priority);
-};
-
-/*
- Calculates the next task.value based on direction
- Uses a capped inverse log y=.95^x, y>= -5
- {currentValue} the current value of the task
- {direction} up or down
- */
-
-
-function taskDeltaFormula(currentValue, direction) {
- var delta;
- if (currentValue < -47.27) {
- currentValue = -47.27;
- } else if (currentValue > 21.27) {
- currentValue = 21.27;
- }
- delta = Math.pow(0.9747, currentValue);
- if (direction === 'up') {
- return delta;
- }
- return -delta;
-};
-
-function score(user, taskId, direction, times, cron) {
- var task = _.findWhere(user.tasks, {id: taskId})
- , type = task.type
- , value = task.value
- , priority = task.priority || '!'
- , delta = 0
- , times = times? times: 1;
-
-
- if (task.value > user.stats.gp && task.type === 'reward') {
- r = confirm("Not enough GP to purchase this reward, buy anyway and lose HP? (Punishment for taking a reward you didn't earn).");
- if (!r) return;
- }
-
- function calculateDelta(adjustvalue) {
- adjustvalue = adjustvalue? adjustvalue: true;
- _.times(times, function(n) {
- var nextDelta;
- nextDelta = taskDeltaFormula(value, direction);
- if (adjustvalue) {
- value += nextDelta;
- }
- delta += nextDelta;
- });
- };
-
- function addPoints() {
- var level, weaponStrength;
- level = user.stats.lvl;
- weaponStrength = Items.items.weapon[user.items.weapon].strength;
- user.stats.exp += expModifier(delta, weaponStrength, level, priority);
- user.stats.gp += gpModifier(delta, 1, priority);
- };
-
- function subtractPoints() {
- var armorDefense, helmDefense, level, shieldDefense;
- level = user.stats.lvl;
- armorDefense = Items.items.armor[user.items.armor].defense;
- helmDefense = Items.items.head[user.items.head].defense;
- shieldDefense = Items.items.shield[user.items.shield].defense;
- user.stats.hp += hpModifier(delta, armorDefense, helmDefense, shieldDefense, level, priority);
- };
- switch (type) {
- case 'habit':
- calculateDelta();
- if (delta > 0) {
- addPoints();
- } else {
- subtractPoints();
- }
- task.history = task.history? task.history: [];
- if (task.value !== value) {
- task.history.push({
- date: +(new Date),
- value: value
- });
- }
- break;
- case 'daily':
- if (cron != null) {
- calculateDelta();
- subtractPoints();
- } else {
- calculateDelta(false);
- if (delta !== 0) {
- addPoints();
- }
- }
- break;
- case 'todo':
- if (cron != null) {
- calculateDelta();
- } else {
- calculateDelta();
- addPoints();
- }
- break;
- case 'reward':
- calculateDelta(false);
- user.stats.gp -= Math.abs(task.value);
- var num = parseFloat(task.value).toFixed(2);
- if (user.stats.gp < 0) {
- user.stats.hp += user.stats.gp;
- user.stats.gp = 0;
- }
- }
- task.value = value;
- updateStats(user);
- return delta;
-};
-
-/*
- Updates user stats with new stats. Handles death, leveling up, etc
- {stats} new stats
- {update} if aggregated changes, pass in userObj as update. otherwise commits will be made immediately
- */
-
-
-function updateStats(user) {
- if (user.stats.lvl === 0) return;
- if (user.stats.hp <= 0) {
- user.stats.lvl = 0; // signifies dead
- user.stats.hp = 0;
- return;
- }
- if (user.stats.lvl >= 100) {
- user.stats.gp += user.stats.exp / 15;
- user.stats.exp = 0;
- user.stats.lvl = 100;
- } else {
- var currTnl = user.stats.tnl = tnl(user.stats.lvl);
- if (user.stats.exp >= currTnl) {
- while (user.stats.exp >= currTnl && user.stats.lvl < 100) {
- user.stats.exp -= currTnl;
- user.stats.lvl++;
- user.stats.tnl = tnl(user.stats.lvl);
- }
- if (user.stats.lvl === 100) {
- user.stats.exp = 0;
- }
- user.stats.hp = 50;
- }
- }
- if (!user.flags.customizationsNotification && (user.stats.exp > 10 || user.stats.lvl > 1)) {
- user.flags.customizationsNotification = true;
- user.flags.customizationsNotification = true;
- }
- if (!user.flags.itemsEnabled && user.stats.lvl >= 2) {
- user.flags.itemsEnabled = true;
- user.flags.itemsEnabled = true;
- }
- if (!user.flags.partyEnabled && user.stats.lvl >= 3) {
- user.flags.partyEnabled = true;
- user.flags.partyEnabled = true;
- }
- if (!user.flags.petsEnabled && user.stats.lvl >= 4) {
- user.flags.petsEnabled = true;
- user.flags.petsEnabled = true;
- }
-
- if (user.stats.gp < 0) user.stats.gp = 0.0;
-};
-
-
-module.exports = {
- tnl: tnl,
- score: score
-}
-},{"./items":3}],4:[function(require,module,exports){
-var dayMapping, moment;
-
-moment = require('moment');
-
-exports.daysBetween = function(yesterday, now, dayStart) {
- if (!((dayStart != null) && (dayStart = parseInt(dayStart)) && dayStart >= 0 && dayStart <= 24)) {
- dayStart = 0;
- }
- return Math.abs(moment(yesterday).startOf('day').add('h', dayStart).diff(moment(now), 'days'));
-};
-
-exports.dayMapping = dayMapping = {
- 0: 'su',
- 1: 'm',
- 2: 't',
- 3: 'w',
- 4: 'th',
- 5: 'f',
- 6: 's',
- 7: 'su'
-};
-
-
-exports.equipped = function(user, type) {
- var armor, armorSet, gender, head, _ref, _ref1, _ref2;
- _ref = (user != null ? user.preferences : void 0) || {
- 'm': 'm',
- 'v1': 'v1'
- }, gender = _ref.gender, armorSet = _ref.armorSet;
- if (type === 'armor') {
- armor = (user != null ? (_ref1 = user.items) != null ? _ref1.armor : void 0 : void 0) || 0;
- if (gender === 'f') {
- if (parseInt(armor) === 0) {
- return "f_armor_" + armor + "_" + armorSet;
- } else {
- return "f_armor_" + armor;
- }
- } else {
- return "m_armor_" + armor;
- }
- } else if (type === 'head') {
- head = (user != null ? (_ref2 = user.items) != null ? _ref2.head : void 0 : void 0) || 0;
- if (gender === 'f') {
- if (parseInt(head) > 1) {
- return "f_head_" + head + "_" + armorSet;
- } else {
- return "f_head_" + head;
- }
- } else {
- return "m_head_" + head;
- }
- }
-};
-
-},{"moment":5}],5:[function(require,module,exports){
-(function(){// moment.js
-// version : 2.0.0
-// author : Tim Wood
-// license : MIT
-// momentjs.com
-
-(function (undefined) {
-
- /************************************
- Constants
- ************************************/
-
- var moment,
- VERSION = "2.0.0",
- round = Math.round, i,
- // internal storage for language config files
- languages = {},
-
- // check for nodeJS
- hasModule = (typeof module !== 'undefined' && module.exports),
-
- // ASP.NET json date format regex
- aspNetJsonRegex = /^\/?Date\((\-?\d+)/i,
-
- // format tokens
- formattingTokens = /(\[[^\[]*\])|(\\)?(Mo|MM?M?M?|Do|DDDo|DD?D?D?|ddd?d?|do?|w[o|w]?|W[o|W]?|YYYYY|YYYY|YY|a|A|hh?|HH?|mm?|ss?|SS?S?|X|zz?|ZZ?|.)/g,
- localFormattingTokens = /(\[[^\[]*\])|(\\)?(LT|LL?L?L?|l{1,4})/g,
-
- // parsing tokens
- parseMultipleFormatChunker = /([0-9a-zA-Z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+)/gi,
-
- // parsing token regexes
- parseTokenOneOrTwoDigits = /\d\d?/, // 0 - 99
- parseTokenOneToThreeDigits = /\d{1,3}/, // 0 - 999
- parseTokenThreeDigits = /\d{3}/, // 000 - 999
- parseTokenFourDigits = /\d{1,4}/, // 0 - 9999
- parseTokenSixDigits = /[+\-]?\d{1,6}/, // -999,999 - 999,999
- parseTokenWord = /[0-9]*[a-z\u00A0-\u05FF\u0700-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+|[\u0600-\u06FF]+\s*?[\u0600-\u06FF]+/i, // any word (or two) characters or numbers including two word month in arabic.
- parseTokenTimezone = /Z|[\+\-]\d\d:?\d\d/i, // +00:00 -00:00 +0000 -0000 or Z
- parseTokenT = /T/i, // T (ISO seperator)
- parseTokenTimestampMs = /[\+\-]?\d+(\.\d{1,3})?/, // 123456789 123456789.123
-
- // preliminary iso regex
- // 0000-00-00 + T + 00 or 00:00 or 00:00:00 or 00:00:00.000 + +00:00 or +0000
- isoRegex = /^\s*\d{4}-\d\d-\d\d((T| )(\d\d(:\d\d(:\d\d(\.\d\d?\d?)?)?)?)?([\+\-]\d\d:?\d\d)?)?/,
- isoFormat = 'YYYY-MM-DDTHH:mm:ssZ',
-
- // iso time formats and regexes
- isoTimes = [
- ['HH:mm:ss.S', /(T| )\d\d:\d\d:\d\d\.\d{1,3}/],
- ['HH:mm:ss', /(T| )\d\d:\d\d:\d\d/],
- ['HH:mm', /(T| )\d\d:\d\d/],
- ['HH', /(T| )\d\d/]
- ],
-
- // timezone chunker "+10:00" > ["10", "00"] or "-1530" > ["-15", "30"]
- parseTimezoneChunker = /([\+\-]|\d\d)/gi,
-
- // getter and setter names
- proxyGettersAndSetters = 'Month|Date|Hours|Minutes|Seconds|Milliseconds'.split('|'),
- unitMillisecondFactors = {
- 'Milliseconds' : 1,
- 'Seconds' : 1e3,
- 'Minutes' : 6e4,
- 'Hours' : 36e5,
- 'Days' : 864e5,
- 'Months' : 2592e6,
- 'Years' : 31536e6
- },
-
- // format function strings
- formatFunctions = {},
-
- // tokens to ordinalize and pad
- ordinalizeTokens = 'DDD w W M D d'.split(' '),
- paddedTokens = 'M D H h m s w W'.split(' '),
-
- formatTokenFunctions = {
- M : function () {
- return this.month() + 1;
- },
- MMM : function (format) {
- return this.lang().monthsShort(this, format);
- },
- MMMM : function (format) {
- return this.lang().months(this, format);
- },
- D : function () {
- return this.date();
- },
- DDD : function () {
- return this.dayOfYear();
- },
- d : function () {
- return this.day();
- },
- dd : function (format) {
- return this.lang().weekdaysMin(this, format);
- },
- ddd : function (format) {
- return this.lang().weekdaysShort(this, format);
- },
- dddd : function (format) {
- return this.lang().weekdays(this, format);
- },
- w : function () {
- return this.week();
- },
- W : function () {
- return this.isoWeek();
- },
- YY : function () {
- return leftZeroFill(this.year() % 100, 2);
- },
- YYYY : function () {
- return leftZeroFill(this.year(), 4);
- },
- YYYYY : function () {
- return leftZeroFill(this.year(), 5);
- },
- a : function () {
- return this.lang().meridiem(this.hours(), this.minutes(), true);
- },
- A : function () {
- return this.lang().meridiem(this.hours(), this.minutes(), false);
- },
- H : function () {
- return this.hours();
- },
- h : function () {
- return this.hours() % 12 || 12;
- },
- m : function () {
- return this.minutes();
- },
- s : function () {
- return this.seconds();
- },
- S : function () {
- return ~~(this.milliseconds() / 100);
- },
- SS : function () {
- return leftZeroFill(~~(this.milliseconds() / 10), 2);
- },
- SSS : function () {
- return leftZeroFill(this.milliseconds(), 3);
- },
- Z : function () {
- var a = -this.zone(),
- b = "+";
- if (a < 0) {
- a = -a;
- b = "-";
- }
- return b + leftZeroFill(~~(a / 60), 2) + ":" + leftZeroFill(~~a % 60, 2);
- },
- ZZ : function () {
- var a = -this.zone(),
- b = "+";
- if (a < 0) {
- a = -a;
- b = "-";
- }
- return b + leftZeroFill(~~(10 * a / 6), 4);
- },
- X : function () {
- return this.unix();
- }
- };
-
- function padToken(func, count) {
- return function (a) {
- return leftZeroFill(func.call(this, a), count);
- };
- }
- function ordinalizeToken(func) {
- return function (a) {
- return this.lang().ordinal(func.call(this, a));
- };
- }
-
- while (ordinalizeTokens.length) {
- i = ordinalizeTokens.pop();
- formatTokenFunctions[i + 'o'] = ordinalizeToken(formatTokenFunctions[i]);
- }
- while (paddedTokens.length) {
- i = paddedTokens.pop();
- formatTokenFunctions[i + i] = padToken(formatTokenFunctions[i], 2);
- }
- formatTokenFunctions.DDDD = padToken(formatTokenFunctions.DDD, 3);
-
-
- /************************************
- Constructors
- ************************************/
-
- function Language() {
-
- }
-
- // Moment prototype object
- function Moment(config) {
- extend(this, config);
- }
-
- // Duration Constructor
- function Duration(duration) {
- var data = this._data = {},
- years = duration.years || duration.year || duration.y || 0,
- months = duration.months || duration.month || duration.M || 0,
- weeks = duration.weeks || duration.week || duration.w || 0,
- days = duration.days || duration.day || duration.d || 0,
- hours = duration.hours || duration.hour || duration.h || 0,
- minutes = duration.minutes || duration.minute || duration.m || 0,
- seconds = duration.seconds || duration.second || duration.s || 0,
- milliseconds = duration.milliseconds || duration.millisecond || duration.ms || 0;
-
- // representation for dateAddRemove
- this._milliseconds = milliseconds +
- seconds * 1e3 + // 1000
- minutes * 6e4 + // 1000 * 60
- hours * 36e5; // 1000 * 60 * 60
- // Because of dateAddRemove treats 24 hours as different from a
- // day when working around DST, we need to store them separately
- this._days = days +
- weeks * 7;
- // It is impossible translate months into days without knowing
- // which months you are are talking about, so we have to store
- // it separately.
- this._months = months +
- years * 12;
-
- // The following code bubbles up values, see the tests for
- // examples of what that means.
- data.milliseconds = milliseconds % 1000;
- seconds += absRound(milliseconds / 1000);
-
- data.seconds = seconds % 60;
- minutes += absRound(seconds / 60);
-
- data.minutes = minutes % 60;
- hours += absRound(minutes / 60);
-
- data.hours = hours % 24;
- days += absRound(hours / 24);
-
- days += weeks * 7;
- data.days = days % 30;
-
- months += absRound(days / 30);
-
- data.months = months % 12;
- years += absRound(months / 12);
-
- data.years = years;
- }
-
-
- /************************************
- Helpers
- ************************************/
-
-
- function extend(a, b) {
- for (var i in b) {
- if (b.hasOwnProperty(i)) {
- a[i] = b[i];
- }
- }
- return a;
- }
-
- function absRound(number) {
- if (number < 0) {
- return Math.ceil(number);
- } else {
- return Math.floor(number);
- }
- }
-
- // left zero fill a number
- // see http://jsperf.com/left-zero-filling for performance comparison
- function leftZeroFill(number, targetLength) {
- var output = number + '';
- while (output.length < targetLength) {
- output = '0' + output;
- }
- return output;
- }
-
- // helper function for _.addTime and _.subtractTime
- function addOrSubtractDurationFromMoment(mom, duration, isAdding) {
- var ms = duration._milliseconds,
- d = duration._days,
- M = duration._months,
- currentDate;
-
- if (ms) {
- mom._d.setTime(+mom + ms * isAdding);
- }
- if (d) {
- mom.date(mom.date() + d * isAdding);
- }
- if (M) {
- currentDate = mom.date();
- mom.date(1)
- .month(mom.month() + M * isAdding)
- .date(Math.min(currentDate, mom.daysInMonth()));
- }
- }
-
- // check if is an array
- function isArray(input) {
- return Object.prototype.toString.call(input) === '[object Array]';
- }
-
- // compare two arrays, return the number of differences
- function compareArrays(array1, array2) {
- var len = Math.min(array1.length, array2.length),
- lengthDiff = Math.abs(array1.length - array2.length),
- diffs = 0,
- i;
- for (i = 0; i < len; i++) {
- if (~~array1[i] !== ~~array2[i]) {
- diffs++;
- }
- }
- return diffs + lengthDiff;
- }
-
-
- /************************************
- Languages
- ************************************/
-
-
- Language.prototype = {
- set : function (config) {
- var prop, i;
- for (i in config) {
- prop = config[i];
- if (typeof prop === 'function') {
- this[i] = prop;
- } else {
- this['_' + i] = prop;
- }
- }
- },
-
- _months : "January_February_March_April_May_June_July_August_September_October_November_December".split("_"),
- months : function (m) {
- return this._months[m.month()];
- },
-
- _monthsShort : "Jan_Feb_Mar_Apr_May_Jun_Jul_Aug_Sep_Oct_Nov_Dec".split("_"),
- monthsShort : function (m) {
- return this._monthsShort[m.month()];
- },
-
- monthsParse : function (monthName) {
- var i, mom, regex, output;
-
- if (!this._monthsParse) {
- this._monthsParse = [];
- }
-
- for (i = 0; i < 12; i++) {
- // make the regex if we don't have it already
- if (!this._monthsParse[i]) {
- mom = moment([2000, i]);
- regex = '^' + this.months(mom, '') + '|^' + this.monthsShort(mom, '');
- this._monthsParse[i] = new RegExp(regex.replace('.', ''), 'i');
- }
- // test the regex
- if (this._monthsParse[i].test(monthName)) {
- return i;
- }
- }
- },
-
- _weekdays : "Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"),
- weekdays : function (m) {
- return this._weekdays[m.day()];
- },
-
- _weekdaysShort : "Sun_Mon_Tue_Wed_Thu_Fri_Sat".split("_"),
- weekdaysShort : function (m) {
- return this._weekdaysShort[m.day()];
- },
-
- _weekdaysMin : "Su_Mo_Tu_We_Th_Fr_Sa".split("_"),
- weekdaysMin : function (m) {
- return this._weekdaysMin[m.day()];
- },
-
- _longDateFormat : {
- LT : "h:mm A",
- L : "MM/DD/YYYY",
- LL : "MMMM D YYYY",
- LLL : "MMMM D YYYY LT",
- LLLL : "dddd, MMMM D YYYY LT"
- },
- longDateFormat : function (key) {
- var output = this._longDateFormat[key];
- if (!output && this._longDateFormat[key.toUpperCase()]) {
- output = this._longDateFormat[key.toUpperCase()].replace(/MMMM|MM|DD|dddd/g, function (val) {
- return val.slice(1);
- });
- this._longDateFormat[key] = output;
- }
- return output;
- },
-
- meridiem : function (hours, minutes, isLower) {
- if (hours > 11) {
- return isLower ? 'pm' : 'PM';
- } else {
- return isLower ? 'am' : 'AM';
- }
- },
-
- _calendar : {
- sameDay : '[Today at] LT',
- nextDay : '[Tomorrow at] LT',
- nextWeek : 'dddd [at] LT',
- lastDay : '[Yesterday at] LT',
- lastWeek : '[last] dddd [at] LT',
- sameElse : 'L'
- },
- calendar : function (key, mom) {
- var output = this._calendar[key];
- return typeof output === 'function' ? output.apply(mom) : output;
- },
-
- _relativeTime : {
- future : "in %s",
- past : "%s ago",
- s : "a few seconds",
- m : "a minute",
- mm : "%d minutes",
- h : "an hour",
- hh : "%d hours",
- d : "a day",
- dd : "%d days",
- M : "a month",
- MM : "%d months",
- y : "a year",
- yy : "%d years"
- },
- relativeTime : function (number, withoutSuffix, string, isFuture) {
- var output = this._relativeTime[string];
- return (typeof output === 'function') ?
- output(number, withoutSuffix, string, isFuture) :
- output.replace(/%d/i, number);
- },
- pastFuture : function (diff, output) {
- var format = this._relativeTime[diff > 0 ? 'future' : 'past'];
- return typeof format === 'function' ? format(output) : format.replace(/%s/i, output);
- },
-
- ordinal : function (number) {
- return this._ordinal.replace("%d", number);
- },
- _ordinal : "%d",
-
- preparse : function (string) {
- return string;
- },
-
- postformat : function (string) {
- return string;
- },
-
- week : function (mom) {
- return weekOfYear(mom, this._week.dow, this._week.doy);
- },
- _week : {
- dow : 0, // Sunday is the first day of the week.
- doy : 6 // The week that contains Jan 1st is the first week of the year.
- }
- };
-
- // Loads a language definition into the `languages` cache. The function
- // takes a key and optionally values. If not in the browser and no values
- // are provided, it will load the language file module. As a convenience,
- // this function also returns the language values.
- function loadLang(key, values) {
- values.abbr = key;
- if (!languages[key]) {
- languages[key] = new Language();
- }
- languages[key].set(values);
- return languages[key];
- }
-
- // Determines which language definition to use and returns it.
- //
- // With no parameters, it will return the global language. If you
- // pass in a language key, such as 'en', it will return the
- // definition for 'en', so long as 'en' has already been loaded using
- // moment.lang.
- function getLangDefinition(key) {
- if (!key) {
- return moment.fn._lang;
- }
- if (!languages[key] && hasModule) {
- require('./lang/' + key);
- }
- return languages[key];
- }
-
-
- /************************************
- Formatting
- ************************************/
-
-
- function removeFormattingTokens(input) {
- if (input.match(/\[.*\]/)) {
- return input.replace(/^\[|\]$/g, "");
- }
- return input.replace(/\\/g, "");
- }
-
- function makeFormatFunction(format) {
- var array = format.match(formattingTokens), i, length;
-
- for (i = 0, length = array.length; i < length; i++) {
- if (formatTokenFunctions[array[i]]) {
- array[i] = formatTokenFunctions[array[i]];
- } else {
- array[i] = removeFormattingTokens(array[i]);
- }
- }
-
- return function (mom) {
- var output = "";
- for (i = 0; i < length; i++) {
- output += typeof array[i].call === 'function' ? array[i].call(mom, format) : array[i];
- }
- return output;
- };
- }
-
- // format date using native date object
- function formatMoment(m, format) {
- var i = 5;
-
- function replaceLongDateFormatTokens(input) {
- return m.lang().longDateFormat(input) || input;
- }
-
- while (i-- && localFormattingTokens.test(format)) {
- format = format.replace(localFormattingTokens, replaceLongDateFormatTokens);
- }
-
- if (!formatFunctions[format]) {
- formatFunctions[format] = makeFormatFunction(format);
- }
-
- return formatFunctions[format](m);
- }
-
-
- /************************************
- Parsing
- ************************************/
-
-
- // get the regex to find the next token
- function getParseRegexForToken(token) {
- switch (token) {
- case 'DDDD':
- return parseTokenThreeDigits;
- case 'YYYY':
- return parseTokenFourDigits;
- case 'YYYYY':
- return parseTokenSixDigits;
- case 'S':
- case 'SS':
- case 'SSS':
- case 'DDD':
- return parseTokenOneToThreeDigits;
- case 'MMM':
- case 'MMMM':
- case 'dd':
- case 'ddd':
- case 'dddd':
- case 'a':
- case 'A':
- return parseTokenWord;
- case 'X':
- return parseTokenTimestampMs;
- case 'Z':
- case 'ZZ':
- return parseTokenTimezone;
- case 'T':
- return parseTokenT;
- case 'MM':
- case 'DD':
- case 'YY':
- case 'HH':
- case 'hh':
- case 'mm':
- case 'ss':
- case 'M':
- case 'D':
- case 'd':
- case 'H':
- case 'h':
- case 'm':
- case 's':
- return parseTokenOneOrTwoDigits;
- default :
- return new RegExp(token.replace('\\', ''));
- }
- }
-
- // function to convert string input to date
- function addTimeToArrayFromToken(token, input, config) {
- var a, b,
- datePartArray = config._a;
-
- switch (token) {
- // MONTH
- case 'M' : // fall through to MM
- case 'MM' :
- datePartArray[1] = (input == null) ? 0 : ~~input - 1;
- break;
- case 'MMM' : // fall through to MMMM
- case 'MMMM' :
- a = getLangDefinition(config._l).monthsParse(input);
- // if we didn't find a month name, mark the date as invalid.
- if (a != null) {
- datePartArray[1] = a;
- } else {
- config._isValid = false;
- }
- break;
- // DAY OF MONTH
- case 'D' : // fall through to DDDD
- case 'DD' : // fall through to DDDD
- case 'DDD' : // fall through to DDDD
- case 'DDDD' :
- if (input != null) {
- datePartArray[2] = ~~input;
- }
- break;
- // YEAR
- case 'YY' :
- datePartArray[0] = ~~input + (~~input > 68 ? 1900 : 2000);
- break;
- case 'YYYY' :
- case 'YYYYY' :
- datePartArray[0] = ~~input;
- break;
- // AM / PM
- case 'a' : // fall through to A
- case 'A' :
- config._isPm = ((input + '').toLowerCase() === 'pm');
- break;
- // 24 HOUR
- case 'H' : // fall through to hh
- case 'HH' : // fall through to hh
- case 'h' : // fall through to hh
- case 'hh' :
- datePartArray[3] = ~~input;
- break;
- // MINUTE
- case 'm' : // fall through to mm
- case 'mm' :
- datePartArray[4] = ~~input;
- break;
- // SECOND
- case 's' : // fall through to ss
- case 'ss' :
- datePartArray[5] = ~~input;
- break;
- // MILLISECOND
- case 'S' :
- case 'SS' :
- case 'SSS' :
- datePartArray[6] = ~~ (('0.' + input) * 1000);
- break;
- // UNIX TIMESTAMP WITH MS
- case 'X':
- config._d = new Date(parseFloat(input) * 1000);
- break;
- // TIMEZONE
- case 'Z' : // fall through to ZZ
- case 'ZZ' :
- config._useUTC = true;
- a = (input + '').match(parseTimezoneChunker);
- if (a && a[1]) {
- config._tzh = ~~a[1];
- }
- if (a && a[2]) {
- config._tzm = ~~a[2];
- }
- // reverse offsets
- if (a && a[0] === '+') {
- config._tzh = -config._tzh;
- config._tzm = -config._tzm;
- }
- break;
- }
-
- // if the input is null, the date is not valid
- if (input == null) {
- config._isValid = false;
- }
- }
-
- // convert an array to a date.
- // the array should mirror the parameters below
- // note: all values past the year are optional and will default to the lowest possible value.
- // [year, month, day , hour, minute, second, millisecond]
- function dateFromArray(config) {
- var i, date, input = [];
-
- if (config._d) {
- return;
- }
-
- for (i = 0; i < 7; i++) {
- config._a[i] = input[i] = (config._a[i] == null) ? (i === 2 ? 1 : 0) : config._a[i];
- }
-
- // add the offsets to the time to be parsed so that we can have a clean array for checking isValid
- input[3] += config._tzh || 0;
- input[4] += config._tzm || 0;
-
- date = new Date(0);
-
- if (config._useUTC) {
- date.setUTCFullYear(input[0], input[1], input[2]);
- date.setUTCHours(input[3], input[4], input[5], input[6]);
- } else {
- date.setFullYear(input[0], input[1], input[2]);
- date.setHours(input[3], input[4], input[5], input[6]);
- }
-
- config._d = date;
- }
-
- // date from string and format string
- function makeDateFromStringAndFormat(config) {
- // This array is used to make a Date, either with `new Date` or `Date.UTC`
- var tokens = config._f.match(formattingTokens),
- string = config._i,
- i, parsedInput;
-
- config._a = [];
-
- for (i = 0; i < tokens.length; i++) {
- parsedInput = (getParseRegexForToken(tokens[i]).exec(string) || [])[0];
- if (parsedInput) {
- string = string.slice(string.indexOf(parsedInput) + parsedInput.length);
- }
- // don't parse if its not a known token
- if (formatTokenFunctions[tokens[i]]) {
- addTimeToArrayFromToken(tokens[i], parsedInput, config);
- }
- }
- // handle am pm
- if (config._isPm && config._a[3] < 12) {
- config._a[3] += 12;
- }
- // if is 12 am, change hours to 0
- if (config._isPm === false && config._a[3] === 12) {
- config._a[3] = 0;
- }
- // return
- dateFromArray(config);
- }
-
- // date from string and array of format strings
- function makeDateFromStringAndArray(config) {
- var tempConfig,
- tempMoment,
- bestMoment,
-
- scoreToBeat = 99,
- i,
- currentDate,
- currentScore;
-
- while (config._f.length) {
- tempConfig = extend({}, config);
- tempConfig._f = config._f.pop();
- makeDateFromStringAndFormat(tempConfig);
- tempMoment = new Moment(tempConfig);
-
- if (tempMoment.isValid()) {
- bestMoment = tempMoment;
- break;
- }
-
- currentScore = compareArrays(tempConfig._a, tempMoment.toArray());
-
- if (currentScore < scoreToBeat) {
- scoreToBeat = currentScore;
- bestMoment = tempMoment;
- }
- }
-
- extend(config, bestMoment);
- }
-
- // date from iso format
- function makeDateFromString(config) {
- var i,
- string = config._i;
- if (isoRegex.exec(string)) {
- config._f = 'YYYY-MM-DDT';
- for (i = 0; i < 4; i++) {
- if (isoTimes[i][1].exec(string)) {
- config._f += isoTimes[i][0];
- break;
- }
- }
- if (parseTokenTimezone.exec(string)) {
- config._f += " Z";
- }
- makeDateFromStringAndFormat(config);
- } else {
- config._d = new Date(string);
- }
- }
-
- function makeDateFromInput(config) {
- var input = config._i,
- matched = aspNetJsonRegex.exec(input);
-
- if (input === undefined) {
- config._d = new Date();
- } else if (matched) {
- config._d = new Date(+matched[1]);
- } else if (typeof input === 'string') {
- makeDateFromString(config);
- } else if (isArray(input)) {
- config._a = input.slice(0);
- dateFromArray(config);
- } else {
- config._d = input instanceof Date ? new Date(+input) : new Date(input);
- }
- }
-
-
- /************************************
- Relative Time
- ************************************/
-
-
- // helper function for moment.fn.from, moment.fn.fromNow, and moment.duration.fn.humanize
- function substituteTimeAgo(string, number, withoutSuffix, isFuture, lang) {
- return lang.relativeTime(number || 1, !!withoutSuffix, string, isFuture);
- }
-
- function relativeTime(milliseconds, withoutSuffix, lang) {
- var seconds = round(Math.abs(milliseconds) / 1000),
- minutes = round(seconds / 60),
- hours = round(minutes / 60),
- days = round(hours / 24),
- years = round(days / 365),
- args = seconds < 45 && ['s', seconds] ||
- minutes === 1 && ['m'] ||
- minutes < 45 && ['mm', minutes] ||
- hours === 1 && ['h'] ||
- hours < 22 && ['hh', hours] ||
- days === 1 && ['d'] ||
- days <= 25 && ['dd', days] ||
- days <= 45 && ['M'] ||
- days < 345 && ['MM', round(days / 30)] ||
- years === 1 && ['y'] || ['yy', years];
- args[2] = withoutSuffix;
- args[3] = milliseconds > 0;
- args[4] = lang;
- return substituteTimeAgo.apply({}, args);
- }
-
-
- /************************************
- Week of Year
- ************************************/
-
-
- // firstDayOfWeek 0 = sun, 6 = sat
- // the day of the week that starts the week
- // (usually sunday or monday)
- // firstDayOfWeekOfYear 0 = sun, 6 = sat
- // the first week is the week that contains the first
- // of this day of the week
- // (eg. ISO weeks use thursday (4))
- function weekOfYear(mom, firstDayOfWeek, firstDayOfWeekOfYear) {
- var end = firstDayOfWeekOfYear - firstDayOfWeek,
- daysToDayOfWeek = firstDayOfWeekOfYear - mom.day();
-
-
- if (daysToDayOfWeek > end) {
- daysToDayOfWeek -= 7;
- }
-
- if (daysToDayOfWeek < end - 7) {
- daysToDayOfWeek += 7;
- }
-
- return Math.ceil(moment(mom).add('d', daysToDayOfWeek).dayOfYear() / 7);
- }
-
-
- /************************************
- Top Level Functions
- ************************************/
-
- function makeMoment(config) {
- var input = config._i,
- format = config._f;
-
- if (input === null || input === '') {
- return null;
- }
-
- if (typeof input === 'string') {
- config._i = input = getLangDefinition().preparse(input);
- }
-
- if (moment.isMoment(input)) {
- config = extend({}, input);
- config._d = new Date(+input._d);
- } else if (format) {
- if (isArray(format)) {
- makeDateFromStringAndArray(config);
- } else {
- makeDateFromStringAndFormat(config);
- }
- } else {
- makeDateFromInput(config);
- }
-
- return new Moment(config);
- }
-
- moment = function (input, format, lang) {
- return makeMoment({
- _i : input,
- _f : format,
- _l : lang,
- _isUTC : false
- });
- };
-
- // creating with utc
- moment.utc = function (input, format, lang) {
- return makeMoment({
- _useUTC : true,
- _isUTC : true,
- _l : lang,
- _i : input,
- _f : format
- });
- };
-
- // creating with unix timestamp (in seconds)
- moment.unix = function (input) {
- return moment(input * 1000);
- };
-
- // duration
- moment.duration = function (input, key) {
- var isDuration = moment.isDuration(input),
- isNumber = (typeof input === 'number'),
- duration = (isDuration ? input._data : (isNumber ? {} : input)),
- ret;
-
- if (isNumber) {
- if (key) {
- duration[key] = input;
- } else {
- duration.milliseconds = input;
- }
- }
-
- ret = new Duration(duration);
-
- if (isDuration && input.hasOwnProperty('_lang')) {
- ret._lang = input._lang;
- }
-
- return ret;
- };
-
- // version number
- moment.version = VERSION;
-
- // default format
- moment.defaultFormat = isoFormat;
-
- // This function will load languages and then set the global language. If
- // no arguments are passed in, it will simply return the current global
- // language key.
- moment.lang = function (key, values) {
- var i;
-
- if (!key) {
- return moment.fn._lang._abbr;
- }
- if (values) {
- loadLang(key, values);
- } else if (!languages[key]) {
- getLangDefinition(key);
- }
- moment.duration.fn._lang = moment.fn._lang = getLangDefinition(key);
- };
-
- // returns language data
- moment.langData = function (key) {
- if (key && key._lang && key._lang._abbr) {
- key = key._lang._abbr;
- }
- return getLangDefinition(key);
- };
-
- // compare moment object
- moment.isMoment = function (obj) {
- return obj instanceof Moment;
- };
-
- // for typechecking Duration objects
- moment.isDuration = function (obj) {
- return obj instanceof Duration;
- };
-
-
- /************************************
- Moment Prototype
- ************************************/
-
-
- moment.fn = Moment.prototype = {
-
- clone : function () {
- return moment(this);
- },
-
- valueOf : function () {
- return +this._d;
- },
-
- unix : function () {
- return Math.floor(+this._d / 1000);
- },
-
- toString : function () {
- return this.format("ddd MMM DD YYYY HH:mm:ss [GMT]ZZ");
- },
-
- toDate : function () {
- return this._d;
- },
-
- toJSON : function () {
- return moment.utc(this).format('YYYY-MM-DD[T]HH:mm:ss.SSS[Z]');
- },
-
- toArray : function () {
- var m = this;
- return [
- m.year(),
- m.month(),
- m.date(),
- m.hours(),
- m.minutes(),
- m.seconds(),
- m.milliseconds()
- ];
- },
-
- isValid : function () {
- if (this._isValid == null) {
- if (this._a) {
- this._isValid = !compareArrays(this._a, (this._isUTC ? moment.utc(this._a) : moment(this._a)).toArray());
- } else {
- this._isValid = !isNaN(this._d.getTime());
- }
- }
- return !!this._isValid;
- },
-
- utc : function () {
- this._isUTC = true;
- return this;
- },
-
- local : function () {
- this._isUTC = false;
- return this;
- },
-
- format : function (inputString) {
- var output = formatMoment(this, inputString || moment.defaultFormat);
- return this.lang().postformat(output);
- },
-
- add : function (input, val) {
- var dur;
- // switch args to support add('s', 1) and add(1, 's')
- if (typeof input === 'string') {
- dur = moment.duration(+val, input);
- } else {
- dur = moment.duration(input, val);
- }
- addOrSubtractDurationFromMoment(this, dur, 1);
- return this;
- },
-
- subtract : function (input, val) {
- var dur;
- // switch args to support subtract('s', 1) and subtract(1, 's')
- if (typeof input === 'string') {
- dur = moment.duration(+val, input);
- } else {
- dur = moment.duration(input, val);
- }
- addOrSubtractDurationFromMoment(this, dur, -1);
- return this;
- },
-
- diff : function (input, units, asFloat) {
- var that = this._isUTC ? moment(input).utc() : moment(input).local(),
- zoneDiff = (this.zone() - that.zone()) * 6e4,
- diff, output;
-
- if (units) {
- // standardize on singular form
- units = units.replace(/s$/, '');
- }
-
- if (units === 'year' || units === 'month') {
- diff = (this.daysInMonth() + that.daysInMonth()) * 432e5; // 24 * 60 * 60 * 1000 / 2
- output = ((this.year() - that.year()) * 12) + (this.month() - that.month());
- output += ((this - moment(this).startOf('month')) - (that - moment(that).startOf('month'))) / diff;
- if (units === 'year') {
- output = output / 12;
- }
- } else {
- diff = (this - that) - zoneDiff;
- output = units === 'second' ? diff / 1e3 : // 1000
- units === 'minute' ? diff / 6e4 : // 1000 * 60
- units === 'hour' ? diff / 36e5 : // 1000 * 60 * 60
- units === 'day' ? diff / 864e5 : // 1000 * 60 * 60 * 24
- units === 'week' ? diff / 6048e5 : // 1000 * 60 * 60 * 24 * 7
- diff;
- }
- return asFloat ? output : absRound(output);
- },
-
- from : function (time, withoutSuffix) {
- return moment.duration(this.diff(time)).lang(this.lang()._abbr).humanize(!withoutSuffix);
- },
-
- fromNow : function (withoutSuffix) {
- return this.from(moment(), withoutSuffix);
- },
-
- calendar : function () {
- var diff = this.diff(moment().startOf('day'), 'days', true),
- format = diff < -6 ? 'sameElse' :
- diff < -1 ? 'lastWeek' :
- diff < 0 ? 'lastDay' :
- diff < 1 ? 'sameDay' :
- diff < 2 ? 'nextDay' :
- diff < 7 ? 'nextWeek' : 'sameElse';
- return this.format(this.lang().calendar(format, this));
- },
-
- isLeapYear : function () {
- var year = this.year();
- return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0;
- },
-
- isDST : function () {
- return (this.zone() < moment([this.year()]).zone() ||
- this.zone() < moment([this.year(), 5]).zone());
- },
-
- day : function (input) {
- var day = this._isUTC ? this._d.getUTCDay() : this._d.getDay();
- return input == null ? day :
- this.add({ d : input - day });
- },
-
- startOf: function (units) {
- units = units.replace(/s$/, '');
- // the following switch intentionally omits break keywords
- // to utilize falling through the cases.
- switch (units) {
- case 'year':
- this.month(0);
- /* falls through */
- case 'month':
- this.date(1);
- /* falls through */
- case 'week':
- case 'day':
- this.hours(0);
- /* falls through */
- case 'hour':
- this.minutes(0);
- /* falls through */
- case 'minute':
- this.seconds(0);
- /* falls through */
- case 'second':
- this.milliseconds(0);
- /* falls through */
- }
-
- // weeks are a special case
- if (units === 'week') {
- this.day(0);
- }
-
- return this;
- },
-
- endOf: function (units) {
- return this.startOf(units).add(units.replace(/s?$/, 's'), 1).subtract('ms', 1);
- },
-
- isAfter: function (input, units) {
- units = typeof units !== 'undefined' ? units : 'millisecond';
- return +this.clone().startOf(units) > +moment(input).startOf(units);
- },
-
- isBefore: function (input, units) {
- units = typeof units !== 'undefined' ? units : 'millisecond';
- return +this.clone().startOf(units) < +moment(input).startOf(units);
- },
-
- isSame: function (input, units) {
- units = typeof units !== 'undefined' ? units : 'millisecond';
- return +this.clone().startOf(units) === +moment(input).startOf(units);
- },
-
- zone : function () {
- return this._isUTC ? 0 : this._d.getTimezoneOffset();
- },
-
- daysInMonth : function () {
- return moment.utc([this.year(), this.month() + 1, 0]).date();
- },
-
- dayOfYear : function (input) {
- var dayOfYear = round((moment(this).startOf('day') - moment(this).startOf('year')) / 864e5) + 1;
- return input == null ? dayOfYear : this.add("d", (input - dayOfYear));
- },
-
- isoWeek : function (input) {
- var week = weekOfYear(this, 1, 4);
- return input == null ? week : this.add("d", (input - week) * 7);
- },
-
- week : function (input) {
- var week = this.lang().week(this);
- return input == null ? week : this.add("d", (input - week) * 7);
- },
-
- // If passed a language key, it will set the language for this
- // instance. Otherwise, it will return the language configuration
- // variables for this instance.
- lang : function (key) {
- if (key === undefined) {
- return this._lang;
- } else {
- this._lang = getLangDefinition(key);
- return this;
- }
- }
- };
-
- // helper for adding shortcuts
- function makeGetterAndSetter(name, key) {
- moment.fn[name] = moment.fn[name + 's'] = function (input) {
- var utc = this._isUTC ? 'UTC' : '';
- if (input != null) {
- this._d['set' + utc + key](input);
- return this;
- } else {
- return this._d['get' + utc + key]();
- }
- };
- }
-
- // loop through and add shortcuts (Month, Date, Hours, Minutes, Seconds, Milliseconds)
- for (i = 0; i < proxyGettersAndSetters.length; i ++) {
- makeGetterAndSetter(proxyGettersAndSetters[i].toLowerCase().replace(/s$/, ''), proxyGettersAndSetters[i]);
- }
-
- // add shortcut for year (uses different syntax than the getter/setter 'year' == 'FullYear')
- makeGetterAndSetter('year', 'FullYear');
-
- // add plural methods
- moment.fn.days = moment.fn.day;
- moment.fn.weeks = moment.fn.week;
- moment.fn.isoWeeks = moment.fn.isoWeek;
-
- /************************************
- Duration Prototype
- ************************************/
-
-
- moment.duration.fn = Duration.prototype = {
- weeks : function () {
- return absRound(this.days() / 7);
- },
-
- valueOf : function () {
- return this._milliseconds +
- this._days * 864e5 +
- this._months * 2592e6;
- },
-
- humanize : function (withSuffix) {
- var difference = +this,
- output = relativeTime(difference, !withSuffix, this.lang());
-
- if (withSuffix) {
- output = this.lang().pastFuture(difference, output);
- }
-
- return this.lang().postformat(output);
- },
-
- lang : moment.fn.lang
- };
-
- function makeDurationGetter(name) {
- moment.duration.fn[name] = function () {
- return this._data[name];
- };
- }
-
- function makeDurationAsGetter(name, factor) {
- moment.duration.fn['as' + name] = function () {
- return +this / factor;
- };
- }
-
- for (i in unitMillisecondFactors) {
- if (unitMillisecondFactors.hasOwnProperty(i)) {
- makeDurationAsGetter(i, unitMillisecondFactors[i]);
- makeDurationGetter(i.toLowerCase());
- }
- }
-
- makeDurationAsGetter('Weeks', 6048e5);
-
-
- /************************************
- Default Lang
- ************************************/
-
-
- // Set default language, other languages will inherit from English.
- moment.lang('en', {
- ordinal : function (number) {
- var b = number % 10,
- output = (~~ (number % 100 / 10) === 1) ? 'th' :
- (b === 1) ? 'st' :
- (b === 2) ? 'nd' :
- (b === 3) ? 'rd' : 'th';
- return number + output;
- }
- });
-
-
- /************************************
- Exposing Moment
- ************************************/
-
-
- // CommonJS module is defined
- if (hasModule) {
- module.exports = moment;
- }
- /*global ender:false */
- if (typeof ender === 'undefined') {
- // here, `this` means `window` in the browser, or `global` on the server
- // add `moment` as a global object via a string identifier,
- // for Closure Compiler "advanced" mode
- this['moment'] = moment;
- }
- /*global define:false */
- if (typeof define === "function" && define.amd) {
- define("moment", [], function () {
- return moment;
- });
- }
-}).call(this);
-
-})()
-},{}]},{},[1])
-;
\ No newline at end of file
diff --git a/index.js b/index.js
deleted file mode 100644
index 597c208604..0000000000
--- a/index.js
+++ /dev/null
@@ -1,10 +0,0 @@
-exports.algos = require('./algos')
-exports.items = require('./items')
-exports.helpers = require('./helpers')
-
-// This is how we're exporting this module to the browser. A preferable way would be http://requirejs.org/docs/api.html#packages
-// but I couldn't get that working
-try {
- window;
- window.habitrpgShared = exports;
-} catch(e) {}
\ No newline at end of file
diff --git a/items.coffee b/items.coffee
new file mode 100644
index 0000000000..867edc109e
--- /dev/null
+++ b/items.coffee
@@ -0,0 +1,146 @@
+({ define: (
+ if typeof define == "function"
+ define
+ else
+ (F)->
+ F(require, exports, module)
+)}).define (require, exports, module)->
+ obj = module.exports = {};
+ items = obj.items =
+ {
+ weapon: [
+ {index: 0, text: "Training Sword", classes: "weapon_0", notes: 'Training weapon.', strength: 0, value: 0}
+ {index: 1, text: "Sword", classes: 'weapon_1', notes: 'Increases experience gain by 3%.', strength: 3, value: 20}
+ {index: 2, text: "Axe", classes: 'weapon_2', notes: 'Increases experience gain by 6%.', strength: 6, value: 30}
+ {index: 3, text: "Morningstar", classes: 'weapon_3', notes: 'Increases experience gain by 9%.', strength: 9, value: 45}
+ {index: 4, text: "Blue Sword", classes: 'weapon_4', notes: 'Increases experience gain by 12%.', strength: 12, value: 65}
+ {index: 5, text: "Red Sword", classes: 'weapon_5', notes: 'Increases experience gain by 15%.', strength: 15, value: 90}
+ {index: 6, text: "Golden Sword", classes: 'weapon_6', notes: 'Increases experience gain by 18%.', strength: 18, value: 120}
+ {index: 7, text: "Dark Souls Blade", classes: 'weapon_7', notes: 'Increases experience gain by 21%.', strength: 21, value: 150}
+ ]
+ armor: [
+ {index: 0, text: "Cloth Armor", classes: 'armor_0', notes: 'Training armor.', defense: 0, value: 0}
+ {index: 1, text: "Leather Armor", classes: 'armor_1', notes: 'Decreases HP loss by 4%.', defense: 4, value: 30}
+ {index: 2, text: "Chain Mail", classes: 'armor_2', notes: 'Decreases HP loss by 6%.', defense: 6, value: 45}
+ {index: 3, text: "Plate Mail", classes: 'armor_3', notes: 'Decreases HP loss by 7%.', defense: 7, value: 65}
+ {index: 4, text: "Red Armor", classes: 'armor_4', notes: 'Decreases HP loss by 8%.', defense: 8, value: 90}
+ {index: 5, text: "Golden Armor", classes: 'armor_5', notes: 'Decreases HP loss by 10%.', defense: 10, value: 120}
+ {index: 6, text: "Shade Armor", classes: 'armor_6', notes: 'Decreases HP loss by 12%.', defense: 12, value: 150}
+ ]
+ head: [
+ {index: 0, text: "No Helm", classes: 'head_0', notes: 'Training helm.', defense: 0, value: 0}
+ {index: 1, text: "Leather Helm", classes: 'head_1', notes: 'Decreases HP loss by 2%.', defense: 2, value: 15}
+ {index: 2, text: "Chain Coif", classes: 'head_2', notes: 'Decreases HP loss by 3%.', defense: 3, value: 25}
+ {index: 3, text: "Plate Helm", classes: 'head_3', notes: 'Decreases HP loss by 4%.', defense: 4, value: 45}
+ {index: 4, text: "Red Helm", classes: 'head_4', notes: 'Decreases HP loss by 5%.', defense: 5, value: 60}
+ {index: 5, text: "Golden Helm", classes: 'head_5', notes: 'Decreases HP loss by 6%.', defense: 6, value: 80}
+ {index: 6, text: "Shade Helm", classes: 'head_6', notes: 'Decreases HP loss by 7%.', defense: 7, value: 100}
+ ]
+ shield: [
+ {index: 0, text: "No Shield", classes: 'shield_0', notes: 'No Shield.', defense: 0, value: 0}
+ {index: 1, text: "Wooden Shield", classes: 'shield_1', notes: 'Decreases HP loss by 3%', defense: 3, value: 20}
+ {index: 2, text: "Buckler", classes: 'shield_2', notes: 'Decreases HP loss by 4%.', defense: 4, value: 35}
+ {index: 3, text: "Enforced Shield", classes: 'shield_3', notes: 'Decreases HP loss by 5%.', defense: 5, value: 55}
+ {index: 4, text: "Red Shield", classes: 'shield_4', notes: 'Decreases HP loss by 7%.', defense: 7, value: 70}
+ {index: 5, text: "Golden Shield", classes: 'shield_5', notes: 'Decreases HP loss by 8%.', defense: 8, value: 90}
+ {index: 6, text: "Tormented Skull", classes: 'shield_6', notes: 'Decreases HP loss by 9%.', defense: 9, value: 120}
+ ]
+ potion:
+ {type: 'potion', text: "Potion", notes: "Recover 15 HP", value: 25, classes: 'potion'}
+ reroll:
+ {type: 'reroll', text: "Re-Roll", classes: 'reroll', notes: "Resets your task values back to 0 (yellow). Useful when everything's red and it's hard to stay alive.", value: 0 }
+ pets: [
+ {text: 'Wolf', name: 'Wolf', value: 3}
+ {text: 'Tiger Cub', name: 'TigerCub', value: 3}
+ #{text: 'Polar Bear Cub', name: 'PolarBearCub', value: 3} #commented out because there are no polarbear modifiers yet, special drop?
+ {text: 'Panda Cub', name: 'PandaCub', value: 3}
+ {text: 'Lion Cub', name: 'LionCub', value: 3}
+ {text: 'Fox', name: 'Fox', value: 3}
+ {text: 'Flying Pig', name: 'FlyingPig', value: 3}
+ {text: 'Dragon', name: 'Dragon', value: 3}
+ {text: 'Cactus', name: 'Cactus', value: 3}
+ {text: 'Bear Cub', name: 'BearCub', value: 3}
+ ]
+ hatchingPotions: [
+ {text: 'Base', name: 'Base', notes: "Hatches your pet in it's base form.", value: 1}
+ {text: 'White', name: 'White', notes: 'Turns your animal into a White pet.', value: 2}
+ {text: 'Desert', name: 'Desert', notes: 'Turns your animal into a Desert pet.', value: 2}
+ {text: 'Red', name: 'Red', notes: 'Turns your animal into a Red pet.', value: 3}
+ {text: 'Shade', name: 'Shade', notes: 'Turns your animal into a Shade pet.', value: 3}
+ {text: 'Skeleton', name: 'Skeleton', notes: 'Turns your animal into a Skeleton.', value: 3}
+ {text: 'Zombie', name: 'Zombie', notes: 'Turns your animal into a Zombie.', value: 4}
+ {text: 'Cotton Candy Pink', name: 'CottonCandyPink', notes: 'Turns your animal into a Cotton Candy Pink pet.', value: 4}
+ {text: 'Cotton Candy Blue', name: 'CottonCandyBlue', notes: 'Turns your animal into a Cotton Candy Blue pet.', value: 4}
+ {text: 'Golden', name: 'Golden', notes: 'Turns your animal into a Golden pet.', value: 5}
+ ]
+ }
+
+ # add "type" to each item, so we can reference that as "weapon" or "armor" in the html
+ ['weapon', 'armor', 'head', 'shield'].forEach (key)->
+ items[key].forEach (item)->
+ item.type = key
+
+ items.pets.forEach (pet)->
+ pet.notes = 'Find a hatching potion to pour on this egg, and one day it will hatch into a loyal pet.'
+ items.hatchingPotions.forEach (hatchingPotion)->
+ hatchingPotion.notes = "Pour this on an egg, and it will hatch as a #{hatchingPotion.text} pet."
+
+
+ ###
+ app exports
+ ###
+ obj.app = (appExports, user) ->
+ appExports.buyItem = (e, el, next) ->
+ #TODO: this should be working but it's not. so instead, i'm passing all needed values as data-attrs
+ # item = model.at(e.target)
+ gp = user.stats.gp
+ [type, value, index] = [ $(el).attr('data-type'), $(el).attr('data-value'), $(el).attr('data-index') ]
+
+ return if gp < value
+ # make sure deduction doesn't happen unless purchase was successful, see https://github.com/lefnire/habitrpg/issues/233
+ deductGP = ->
+ user.stats.gp = gp - value
+ if type == 'weapon'
+ user.set 'items.weapon', index, deductGP
+ updateStore model
+ else if type == 'armor'
+ user.set 'items.armor', index, deductGP
+ updateStore model
+ else if type == 'head'
+ user.set 'items.head', index, deductGP
+ updateStore model
+ else if type == 'shield'
+ user.set 'items.shield', index, deductGP
+ updateStore model
+ else if type == 'potion'
+ hp = user.get 'stats.hp'
+ hp += 15
+ hp = 50 if hp > 50
+ user.set 'stats.hp', hp, deductGP
+
+
+ ###
+ update store
+ ###
+ obj.updateStore = updateStore = (user) ->
+ if !items.next?
+ items.next =
+ {}
+ equipped = user.items
+
+ ['weapon', 'armor', 'shield', 'head'].forEach (type) ->
+ i = parseInt(equipped? [type] || 0) + 1
+ showNext = true
+ if i is items[type].length - 1
+ if (type in ['armor', 'shield', 'head'])
+ showNext = user.backer.tier >= 45 # backer armor
+ else
+ showNext = user.backer.tier >= 70 # backer weapon
+ else if i is items[type].length
+ showNext = false
+
+ items.next[type] = if showNext then items[type][i] else {hide: true}
+
+
+
+
diff --git a/package.json b/package.json
index a5e3d4c7a9..1ff2bbde60 100644
--- a/package.json
+++ b/package.json
@@ -2,7 +2,5 @@
"name": "habitrpg-shared",
"version": "0.0.0",
"dependencies": {
- "browserify": "*",
- "moment": "*"
}
}