setup modifier using constant

This commit is contained in:
Tyler Renelle 2012-09-23 21:07:37 -04:00
parent 1a68f00fb2
commit 1c0d8726c3
3 changed files with 34 additions and 11 deletions

View file

@ -1,5 +1,5 @@
// Generated by CoffeeScript 1.3.3
var content, expModifier, hpModifier, score, statsNotification, updateStats, user;
var MODIFIER, content, expModifier, hpModifier, score, statsNotification, updateStats, user;
content = require('./content');
@ -9,6 +9,8 @@ module.exports.setUser = function(u) {
return user = u;
};
module.exports.MODIFIER = MODIFIER = .03;
statsNotification = function(html, type) {
if (user.get('stats.lvl') === 0) {
return;
@ -26,16 +28,16 @@ statsNotification = function(html, type) {
expModifier = function(value) {
var dmg, modified;
dmg = user.get('items.weapon') * .03;
dmg += user.get('stats.lvl') * .03;
dmg = user.get('items.weapon') * MODIFIER;
dmg += user.get('stats.lvl') * MODIFIER;
modified = value + (value * dmg);
return modified;
};
hpModifier = function(value) {
var ac, modified;
ac = user.get('items.armor') * .03;
ac += user.get('stats.lvl') * .03;
ac = user.get('items.armor') * MODIFIER;
ac += user.get('stats.lvl') * MODIFIER;
modified = value - (value * ac);
return modified;
};

View file

@ -4,6 +4,9 @@ content = require('./content')
user = undefined
module.exports.setUser = (u) ->
user = u
# each new level, armor, weapon add 3% modifier (this number may change)
module.exports.MODIFIER = MODIFIER = .03
statsNotification = (html, type) ->
#don't show notifications if user dead
@ -21,15 +24,15 @@ statsNotification = (html, type) ->
# Calculates Exp modification based on weapon & lvl
expModifier = (value) ->
dmg = user.get('items.weapon') * .03 # each new weapon adds an additional 3% experience
dmg += user.get('stats.lvl') * .03 # same for lvls
dmg = user.get('items.weapon') * MODIFIER # each new weapon increases exp gain
dmg += user.get('stats.lvl') * MODIFIER # same for lvls
modified = value + (value * dmg)
return modified
# Calculates HP-loss modification based on armor & lvl
hpModifier = (value) ->
ac = user.get('items.armor') * .03 # each new armor blocks an additional 3% damage
ac += user.get('stats.lvl') * .03 # same for lvls
ac = user.get('items.armor') * MODIFIER # each new armor decreases HP loss
ac += user.get('stats.lvl') * MODIFIER # same for lvls
modified = value - (value * ac)
return modified

View file

@ -1,9 +1,11 @@
{expect} = require 'derby/node_modules/racer/test/util'
{BrowserModel: Model} = require 'derby/node_modules/racer/test/util/model'
derby = require 'derby'
# Custom modules
scoring = require '../src/app/scoring'
schema = require '../src/app/schema'
_ = require '../public/js/underscore-min'
_ = require '../public/js/underscore-min'
describe 'Scoring', ->
model = null
@ -11,6 +13,7 @@ describe 'Scoring', ->
beforeEach ->
model = new Model
model.set '_user', schema.newUserObject()
scoring.setUser model.at('_user')
it 'should set user defaults correctly', ->
user = model.get '_user'
@ -23,3 +26,18 @@ describe 'Scoring', ->
expect(_.size(user.todoIds)).to.eql 1
expect(_.size(user.completedIds)).to.eql 0
expect(_.size(user.rewardIds)).to.eql 2
it 'should modify damage based on lvl & armor', ->
user = model.at('_user')
[lvl,armor] = [user.get('stats.lvl'), user.get('items.armor')]
expect(lvl).to.eql 1
expect(armor).to.eql 0
uuid = derby.uuid()
model.at('_user.tasks').push {type: 'habit', text: 'Habit', value: 0, up: true, down: true, id: uuid}
task = model.get("_user.tasks")
console.log task
# modified = scoring.score
it 'should always decrease hp with damage, regardless of stats/items'
it 'should always increase exp/gp with gain, regardless of stats/items'