Skip to content

Instantly share code, notes, and snippets.

@lefnire
Last active December 30, 2015 02:28
Show Gist options
  • Save lefnire/7762451 to your computer and use it in GitHub Desktop.
Save lefnire/7762451 to your computer and use it in GitHub Desktop.
coffee
# Aggregate all intrinsic stats, buffs, weapon, & armor into computed stats
Object.defineProperty user, '_statsComputed',
get: ->
_.reduce(['per','con','str','int'], (m,stat) =>
m[stat] = _.reduce('stats stats.buffs items.gear.current.weapon items.gear.current.armor items.gear.current.head items.gear.current.shield'.split(' '), (m2,path) =>
val = helpers.dotGet(path, @)
m2 +
if ~path.indexOf('items.gear')
# get the gear stat, and multiply it by 1.2 if it's class-gear
(+items.items.gear.flat[val]?[stat] or 0) * (if ~val?.indexOf(@stats.class) then 1.2 else 1)
else
+val[stat] or 0
, 0); m
, {})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment