classes: support buying special gear (backer, contrib, etc) from item store

This commit is contained in:
Tyler Renelle 2013-12-05 15:48:13 -07:00
parent 69d248f826
commit 617d29b3fb
2 changed files with 48 additions and 56 deletions

View file

@ -9998,7 +9998,7 @@ try {
} catch(e) {} } catch(e) {}
},{"./algos.coffee":4,"./helpers.coffee":5,"./items.coffee":7,"lodash":2,"moment":3}],7:[function(require,module,exports){ },{"./algos.coffee":4,"./helpers.coffee":5,"./items.coffee":7,"lodash":2,"moment":3}],7:[function(require,module,exports){
(function() { (function() {
var crit, gear, getItem, items, _, _class; var crit, gear, getItem, items, _;
_ = require('lodash'); _ = require('lodash');
@ -10733,13 +10733,14 @@ try {
}; };
_.each(['weapon', 'armor', 'head', 'shield'], function(type) { _.each(['weapon', 'armor', 'head', 'shield'], function(type) {
return _.each(['warrior', 'rogue', 'healer', 'wizard', 'special'], function(_class_) { return _.each(['warrior', 'rogue', 'healer', 'wizard', 'special'], function(klass) {
return _.each(gear[type][_class_], function(item, i) { return _.each(gear[type][klass], function(item, i) {
var key; var key;
key = "" + type + "_" + _class_ + "_" + i; key = "" + type + "_" + klass + "_" + i;
_.defaults(item, { _.defaults(item, {
type: type, type: type,
key: key, key: key,
klass: klass,
index: i, index: i,
str: 0, str: 0,
int: 0, int: 0,
@ -11185,39 +11186,26 @@ try {
*/ */
_class = function(user) { module.exports.buyItem = function(user, item) {
var _ref; var _ref;
if (((_ref = user.stats["class"]) === 'warrior' || _ref === 'healer' || _ref === 'wizard' || _ref === 'rogue')) { if (+user.stats.gp < +item.value) {
return user.stats["class"];
} else {
return 'warrior';
}
};
/*
FIXME
*/
module.exports.buyItem = function(user, type) {
var i, nextItem;
nextItem = type === 'potion' ? items.potion : (i = module.exports.getItem(user, type).index, items.gear.flat["" + type + "_" + (_class(user)) + "_" + (+i + 1)]);
if (+user.stats.gp < +nextItem.value) {
return false; return false;
} }
if (nextItem.type === 'potion') { if (item.key === 'potion') {
user.stats.hp += 15; user.stats.hp += 15;
if (user.stats.hp > 50) { if (user.stats.hp > 50) {
user.stats.hp = 50; user.stats.hp = 50;
} }
} else { } else {
user.items.gear.equipped[type] = nextItem.key; user.items.gear.equipped[item.type] = item.key;
user.items.gear.owned[nextItem.key] = true; user.items.gear.owned[item.key] = true;
if ((_ref = item.klass) === 'warrior' || _ref === 'wizard' || _ref === 'healer' || _ref === 'rogue') {
if (getItem(user, 'weapon').last && getItem(user, 'armor').last && getItem(user, 'head').last && getItem(user, 'shield').last) { if (getItem(user, 'weapon').last && getItem(user, 'armor').last && getItem(user, 'head').last && getItem(user, 'shield').last) {
user.achievements.ultimateGear = true; user.achievements.ultimateGear = true;
} }
} }
user.stats.gp -= nextItem.value; }
user.stats.gp -= item.value;
return true; return true;
}; };
@ -11232,10 +11220,18 @@ try {
_.each(['weapon', 'armor', 'shield', 'head'], function(type) { _.each(['weapon', 'armor', 'shield', 'head'], function(type) {
var i; var i;
i = module.exports.getItem(user, type).index; i = module.exports.getItem(user, type).index;
return changes[type] = items.gear.flat["" + type + "_" + (_class(user)) + "_" + (+i + 1)] || { return changes[type] = items.gear.flat["" + type + "_" + user.stats["class"] + "_" + (+i + 1)] || {
hide: true hide: true
}; };
}); });
_.defaults(changes, _.reduce(_.where(items.gear.flat, {
klass: 'special'
}), function(m, v) {
if ((typeof v.canOwn === "function" ? v.canOwn(user) : void 0) && !user.items.gear.owned[v.key]) {
m[v.key] = v;
}
return m;
}, {}));
changes.potion = items.potion; changes.potion = items.potion;
changes.reroll = items.reroll; changes.reroll = items.reroll;
return changes; return changes;
@ -11250,7 +11246,7 @@ try {
var item; var item;
item = items.gear.flat[user.items.gear.equipped[type]]; item = items.gear.flat[user.items.gear.equipped[type]];
if (!item) { if (!item) {
return items.gear.flat["" + type + "_" + (_class(user)) + "_0"]; return items.gear.flat["" + type + "_" + user.stats["class"] + "_0"];
} }
return item; return item;
}; };

View file

@ -151,11 +151,11 @@ items.gear =
flat: {} flat: {}
_.each ['weapon', 'armor', 'head', 'shield'], (type) -> _.each ['weapon', 'armor', 'head', 'shield'], (type) ->
_.each ['warrior', 'rogue', 'healer', 'wizard', 'special'], (_class_) -> _.each ['warrior', 'rogue', 'healer', 'wizard', 'special'], (klass) ->
# add "type" to each item, so we can reference that as "weapon" or "armor" in the html # add "type" to each item, so we can reference that as "weapon" or "armor" in the html
_.each gear[type][_class_], (item, i) -> _.each gear[type][klass], (item, i) ->
key = "#{type}_#{_class_}_#{i}" key = "#{type}_#{klass}_#{i}"
_.defaults item, {type, key, index: i, str:0, int:0, per:0, con:0} _.defaults item, {type, key, klass, index: i, str:0, int:0, per:0, con:0}
items.gear.flat[key] = item items.gear.flat[key] = item
### ###
@ -430,29 +430,18 @@ _.each items.food, (food,k) ->
--------------------------------------------------------------- ---------------------------------------------------------------
### ###
# TODO remove once we have proper migrations and validation in place module.exports.buyItem = (user, item) ->
_class = (user) -> if (user.stats.class in ['warrior','healer','wizard','rogue']) then user.stats.class else 'warrior' return false if +user.stats.gp < +item.value
if item.key is 'potion'
### user.stats.hp += 15
FIXME
###
module.exports.buyItem = (user, type) ->
nextItem =
if type is 'potion' then items.potion
else
i = module.exports.getItem(user, type).index
items.gear.flat["#{type}_#{_class(user)}_#{+i + 1}"]
return false if +user.stats.gp < +nextItem.value
if nextItem.type is 'potion'
user.stats.hp += 15;
user.stats.hp = 50 if user.stats.hp > 50 user.stats.hp = 50 if user.stats.hp > 50
else else
user.items.gear.equipped[type] = nextItem.key user.items.gear.equipped[item.type] = item.key
user.items.gear.owned[nextItem.key] = true; user.items.gear.owned[item.key] = true;
if item.klass in ['warrior','wizard','healer','rogue']
if getItem(user,'weapon').last && getItem(user,'armor').last && getItem(user,'head').last && getItem(user,'shield').last if getItem(user,'weapon').last && getItem(user,'armor').last && getItem(user,'head').last && getItem(user,'shield').last
user.achievements.ultimateGear = true; user.achievements.ultimateGear = true
user.stats.gp -= nextItem.value user.stats.gp -= item.value
true true
### ###
@ -462,7 +451,14 @@ module.exports.updateStore = (user) ->
changes = {} changes = {}
_.each ['weapon', 'armor', 'shield', 'head'], (type) -> _.each ['weapon', 'armor', 'shield', 'head'], (type) ->
i = module.exports.getItem(user, type).index i = module.exports.getItem(user, type).index
changes[type] = items.gear.flat["#{type}_#{_class(user)}_#{+i + 1}"] or {hide:true} changes[type] = items.gear.flat["#{type}_#{user.stats.class}_#{+i + 1}"] or {hide:true}
# Add special items (contrib gear, backer gear, etc)
_.defaults changes, _.reduce(_.where(items.gear.flat, {klass:'special'}), (m,v) ->
m[v.key] = v if v.canOwn?(user) && !user.items.gear.owned[v.key]
m
, {})
changes.potion = items.potion changes.potion = items.potion
changes.reroll = items.reroll changes.reroll = items.reroll
changes changes
@ -472,5 +468,5 @@ module.exports.updateStore = (user) ->
### ###
module.exports.getItem = getItem = (user, type) -> module.exports.getItem = getItem = (user, type) ->
item = items.gear.flat[user.items.gear.equipped[type]] item = items.gear.flat[user.items.gear.equipped[type]]
return items.gear.flat["#{type}_#{_class(user)}_0"] unless item return items.gear.flat["#{type}_#{user.stats.class}_0"] unless item
item item