Apply experience deduction logic to money
This commit is contained in:
@@ -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')})
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user