Apply experience deduction logic to money

This commit is contained in:
Tyler Renelle
2012-02-23 18:23:54 -05:00
parent 443e422f94
commit 4d97029ab9
3 changed files with 13 additions and 3 deletions
@@ -14,9 +14,15 @@ class HabitTracker.Models.User extends Backbone.Model
@set({ exp: @get('exp') - @tnl() })
@set({ lvl: @get('lvl') + 1 })
# also add money. Only take away money if it was a mistake (aka, a checkbox)
if delta>0 or (habit.isDaily() or habit.isTodo())
@set({money: @get('money')+delta})
# @deprecated also add money. Only take away money if it was a mistake (aka, a checkbox)
# if delta>0 or (habit.isDaily() or habit.isTodo())
# @set({money: @get('money')+delta})
# apply same logic to money
@set({money: @get('money')+delta})
if @get('money') < 0 then @set({money: 0})
# if buying an item, deduct cost
if habit.isReward()
@set({money: @get('money')-habit.get('score')})
+1
View File
@@ -19,6 +19,7 @@ class Habit < ActiveRecord::Base
# but not for Todos (just increase todo's value)
if(h.habit_type==2)
h.user.exp += value
h.user.money += value
h.user.save
end
h.score += value
+3
View File
@@ -14,6 +14,9 @@ class User < ActiveRecord::Base
before_save :calculate_experience
def calculate_experience
self.money = 0 if self.money < 0
self.exp = 0 if self.exp < 0
if (self.exp > self.tnl)
self.exp -= self.tnl # carry over