add revive to algos.coffee, needed by apiv2 & mobile

This commit is contained in:
Tyler Renelle 2013-08-04 23:45:58 -04:00
parent 4df34095aa
commit c88fa701a5
3 changed files with 576 additions and 485 deletions

File diff suppressed because one or more lines are too long

View file

@ -7,7 +7,431 @@ try {
window;
window.habitrpgShared = exports;
} catch(e) {}
},{"./algos.coffee":2,"./items.coffee":3,"./helpers.coffee":4}],2:[function(require,module,exports){
},{"./algos.coffee":2,"./items.coffee":3,"./helpers.coffee":4}],3:[function(require,module,exports){
(function() {
var items, _;
_ = require('lodash');
items = module.exports.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: "Reinforced 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 (Instant Use)",
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: '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
}
]
};
_.each(['weapon', 'armor', 'head', 'shield'], function(key) {
return _.each(items[key], function(item) {
return item.type = key;
});
});
_.each(items.pets, function(pet) {
return pet.notes = 'Find a hatching potion to pour on this egg, and it will hatch into a loyal pet.';
});
_.each(items.hatchingPotions, function(hatchingPotion) {
return hatchingPotion.notes = "Pour this on an egg, and it will hatch as a " + hatchingPotion.text + " pet.";
});
module.exports.buyItem = function(user, type, value, index) {
var changes, hp;
if (user.stats.gp < value) {
return false;
}
changes = {};
switch (type) {
case 'weapon':
changes['items.weapon'] = index;
break;
case 'armor':
changes['items.armor'] = index;
break;
case 'head':
changes['items.head'] = index;
break;
case 'shield':
changes['items.shield'] = index;
break;
case 'potion':
hp = user.stats.hp;
hp += 15;
if (hp > 50) {
hp = 50;
}
changes['stats.hp'] = hp;
}
changes['stats.gp'] = user.stats.gp - value;
return changes;
};
/*
update store
*/
module.exports.updateStore = function(user) {
var changes;
changes = {};
_.each(['weapon', 'armor', 'shield', 'head'], function(type) {
var i, showNext, _ref, _ref1, _ref2;
i = parseInt(((_ref = user.items) != null ? _ref[type] : void 0) || 0) + 1;
showNext = true;
if (i === items[type].length - 1) {
if ((type === 'armor' || type === 'shield' || type === 'head')) {
showNext = ((_ref1 = user.backer) != null ? _ref1.tier : void 0) && user.backer.tier >= 45;
} else {
showNext = ((_ref2 = user.backer) != null ? _ref2.tier : void 0) && user.backer.tier >= 70;
}
} else if (i === items[type].length) {
showNext = false;
}
return changes[type] = showNext ? items[type][i] : {
hide: true
};
});
return changes;
};
/*
Gets an itme, and caps max to the last item in its array
*/
module.exports.getItem = function(type, index) {
var i;
if (index == null) {
index = 0;
}
i = ~~index > items[type].length - 1 ? items[type].length - 1 : ~~index;
return items[type][i];
};
}).call(this);
},{"lodash":5}],2:[function(require,module,exports){
(function() {
var HP, XP, hatchingPotions, helpers, items, moment, obj, pets, randomDrop, updateStats, _, _ref,
__indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
@ -28,6 +452,40 @@ try {
obj = module.exports = {};
obj.revive = function(user, options) {
var candidate, loseThisItem, owned, paths;
if (options == null) {
options = {};
}
paths = options.paths || {};
user.stats.hp = 50;
user.stats.exp = 0;
user.stats.gp = 0;
if (user.stats.lvl > 1) {
user.stats.lvl--;
}
loseThisItem = false;
owned = user.items;
if (~~owned.armor > 0 || ~~owned.head > 0 || ~~owned.shield > 0 || ~~owned.weapon > 0) {
while (!loseThisItem) {
candidate = {
0: 'armor',
1: 'head',
2: 'shield',
3: 'weapon'
}[Math.random() * 4 | 0];
if (owned[candidate] > 0) {
loseThisItem = candidate;
}
}
user.items[loseThisItem] = 0;
}
return ("stats.hp stats.exp stats.gp stats.lvl items." + loseThisItem).split(' ').forEach(function(path) {
return paths[path] = 1;
});
};
obj.priorityValue = function(priority) {
if (priority == null) {
priority = '!';
@ -511,431 +969,7 @@ try {
}).call(this);
},{"./helpers.coffee":4,"./items.coffee":3,"moment":5,"lodash":6}],3:[function(require,module,exports){
(function() {
var items, _;
_ = require('lodash');
items = module.exports.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: "Reinforced 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 (Instant Use)",
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: '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
}
]
};
_.each(['weapon', 'armor', 'head', 'shield'], function(key) {
return _.each(items[key], function(item) {
return item.type = key;
});
});
_.each(items.pets, function(pet) {
return pet.notes = 'Find a hatching potion to pour on this egg, and one day it will hatch into a loyal pet.';
});
_.each(items.hatchingPotions, function(hatchingPotion) {
return hatchingPotion.notes = "Pour this on an egg, and it will hatch as a " + hatchingPotion.text + " pet.";
});
module.exports.buyItem = function(user, type, value, index) {
var changes, hp;
if (user.stats.gp < value) {
return false;
}
changes = {};
switch (type) {
case 'weapon':
changes['items.weapon'] = index;
break;
case 'armor':
changes['items.armor'] = index;
break;
case 'head':
changes['items.head'] = index;
break;
case 'shield':
changes['items.shield'] = index;
break;
case 'potion':
hp = user.stats.hp;
hp += 15;
if (hp > 50) {
hp = 50;
}
changes['stats.hp'] = hp;
}
changes['stats.gp'] = user.stats.gp - value;
return changes;
};
/*
update store
*/
module.exports.updateStore = function(user) {
var changes;
changes = {};
_.each(['weapon', 'armor', 'shield', 'head'], function(type) {
var i, showNext, _ref, _ref1, _ref2;
i = parseInt(((_ref = user.items) != null ? _ref[type] : void 0) || 0) + 1;
showNext = true;
if (i === items[type].length - 1) {
if ((type === 'armor' || type === 'shield' || type === 'head')) {
showNext = ((_ref1 = user.backer) != null ? _ref1.tier : void 0) && user.backer.tier >= 45;
} else {
showNext = ((_ref2 = user.backer) != null ? _ref2.tier : void 0) && user.backer.tier >= 70;
}
} else if (i === items[type].length) {
showNext = false;
}
return changes[type] = showNext ? items[type][i] : {
hide: true
};
});
return changes;
};
/*
Gets an itme, and caps max to the last item in its array
*/
module.exports.getItem = function(type, index) {
var i;
if (index == null) {
index = 0;
}
i = ~~index > items[type].length - 1 ? items[type].length - 1 : ~~index;
return items[type][i];
};
}).call(this);
},{"lodash":6}],7:[function(require,module,exports){
},{"./helpers.coffee":4,"./items.coffee":3,"lodash":5,"moment":6}],7:[function(require,module,exports){
// shim for using process in browser
var process = module.exports = {};
@ -1574,7 +1608,7 @@ process.chdir = function (dir) {
})(require("__browserify_process"))
},{"./items.coffee":3,"moment":5,"lodash":6,"relative-date":8,"__browserify_process":7}],5:[function(require,module,exports){
},{"./items.coffee":3,"lodash":5,"moment":6,"relative-date":8,"__browserify_process":7}],6:[function(require,module,exports){
(function(){// moment.js
// version : 2.0.0
// author : Tim Wood
@ -2977,7 +3011,7 @@ process.chdir = function (dir) {
}).call(this);
})()
},{}],6:[function(require,module,exports){
},{}],5:[function(require,module,exports){
(function(global){/**
* @license
* Lo-Dash 1.2.1 (Custom Build) <http://lodash.com/>

View file

@ -8,6 +8,29 @@ XP = 15
HP = 2
obj = module.exports = {}
obj.revive = (user, options={})->
paths = options.paths || {}
# Reset stats
user.stats.hp = 50
user.stats.exp = 0
user.stats.gp = 0
user.stats.lvl-- if user.stats.lvl > 1
## Lose a random item
loseThisItem = false
owned = user.items
# unless they're already at 0-everything
if ~~owned.armor > 0 or ~~owned.head > 0 or ~~owned.shield > 0 or ~~owned.weapon > 0
# find a random item to lose
until loseThisItem
#candidate = {0:'items.armor', 1:'items.head', 2:'items.shield', 3:'items.weapon', 4:'stats.gp'}[Math.random()*5|0]
candidate = {0:'armor', 1:'head', 2:'shield', 3:'weapon'}[Math.random()*4|0]
loseThisItem = candidate if owned[candidate] > 0
user.items[loseThisItem] = 0
"stats.hp stats.exp stats.gp stats.lvl items.#{loseThisItem}".split(' ').forEach (path) ->
paths[path] = 1
obj.priorityValue = (priority = '!') ->
switch priority