Created
May 3, 2013 18:10
-
-
Save lefnire/5512199 to your computer and use it in GitHub Desktop.
Streaks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/app/algos.coffee b/src/app/algos.coffee | |
index 5a24d1b..fe4d9d1 100644 | |
--- a/src/app/algos.coffee | |
+++ b/src/app/algos.coffee | |
@@ -48,8 +48,9 @@ module.exports.hpModifier = (value, armorDef, helmDef, shieldDef, level, priorit | |
Future use | |
{priority} user-defined priority multiplier | |
### | |
-module.exports.gpModifier = (value, modifier, priority='!') -> | |
- return value * modifier * priorityValue(priority) | |
+module.exports.gpModifier = (value, modifier, priority='!', streak=0) -> | |
+ streakBonus = streak / 100 + 1 # eg, 1-day streak is 1.1, 2-day is 1.2, etc | |
+ return value * modifier * priorityValue(priority) * streakBonus | |
### | |
Calculates the next task.value based on direction | |
diff --git a/src/app/scoring.coffee b/src/app/scoring.coffee | |
index d487909..d470654 100644 | |
--- a/src/app/scoring.coffee | |
+++ b/src/app/scoring.coffee | |
@@ -12,7 +12,7 @@ MODIFIER = algos.MODIFIER # each new level, armor, weapon add 2% modifier (this | |
### | |
Drop System | |
### | |
-randomDrop = (model, delta, priority) -> | |
+randomDrop = (model, delta, priority, streak=0) -> | |
user = model.at('_user') | |
# limit drops to 2 / day | |
@@ -27,7 +27,10 @@ randomDrop = (model, delta, priority) -> | |
chanceMultiplier = if (model.flags.nodeEnv is 'development') then 50 else 1 | |
# TODO temporary min cap of 1 so people still get rewarded for good habits. Will change once we have streaks | |
deltaMultiplier = if Math.abs(delta) < 1 then 1 else Math.abs(delta) | |
- chanceMultiplier = chanceMultiplier * deltaMultiplier * algos.priorityValue(priority) # multiply chance by reddness | |
+ chanceMultiplier *= deltaMultiplier | |
+ chanceMultiplier *= algos.priorityValue(priority) # multiply chance by reddness | |
+ chanceMultiplier += (streak+ 1) # streak bonus | |
+ console.log chanceMultiplier | |
if user.get('flags.dropsEnabled') and Math.random() < (.05 * chanceMultiplier) | |
# current breakdown - 3% (adjustable) chance on drop | |
@@ -120,7 +123,7 @@ score = (model, taskId, direction, times, batch, cron) -> | |
level = user.get('stats.lvl') | |
weaponStrength = items.items.weapon[user.get('items.weapon')].strength | |
exp += algos.expModifier(delta,weaponStrength,level, priority) / 2 # / 2 hack for now bcause people leveling too fast | |
- gp += algos.gpModifier(delta, 1, priority) | |
+ gp += algos.gpModifier(delta, 1, priority, taskObj.streak) | |
subtractPoints = -> | |
level = user.get('stats.lvl') | |
@@ -144,10 +147,16 @@ score = (model, taskId, direction, times, batch, cron) -> | |
if cron? # cron | |
calculateDelta() | |
subtractPoints() | |
+ batch.set "#{taskPath}.streak", 0 | |
else | |
calculateDelta(false) | |
if delta != 0 | |
addPoints() # obviously for delta>0, but also a trick to undo accidental checkboxes | |
+ if direction is 'up' | |
+ taskObj.streak = if taskObj.streak then taskObj.streak + 1 else 1 | |
+ else | |
+ taskObj.streak = if taskObj.streak then taskObj.streak - 1 else 0 | |
+ batch.set "#{taskPath}.streak", taskObj.streak | |
when 'todo' | |
if cron? #cron | |
@@ -183,7 +192,7 @@ score = (model, taskId, direction, times, batch, cron) -> | |
batch.commit() | |
# Drop system | |
- randomDrop(model, delta, priority) if direction is 'up' | |
+ randomDrop(model, delta, priority, taskObj.streak) if direction is 'up' | |
return delta | |
diff --git a/src/app/unlock.coffee b/src/app/unlock.coffee | |
index 742aa14..8946eb9 100644 | |
--- a/src/app/unlock.coffee | |
+++ b/src/app/unlock.coffee | |
@@ -68,20 +68,22 @@ module.exports.app = (appExports, model) -> | |
user.on 'push', 'items.pets', (after, before) -> | |
return if user.get('achievements.beastMaster') | |
if before >= 90 # evidently before is the count? | |
- dontPersist = model._dontPersist | |
- model._dontPersist = false | |
- user.set 'achievements.beastMaster', true, -> | |
- model._dontPersist = dontPersist | |
+ dontPersist = model._dontPersist; model._dontPersist = false | |
+ user.set 'achievements.beastMaster', true, (-> model._dontPersist = dontPersist) | |
$('#beastmaster-achievement-modal').modal('show') | |
user.on 'set', 'items.*', (after, before) -> | |
return if user.get('achievements.ultimateGear') | |
items = user.get('items') | |
if parseInt(items.weapon) == 6 and parseInt(items.armor) == 5 and parseInt(items.head) == 5 and parseInt(items.shield) == 5 | |
- debugger | |
- dontPersist = model._dontPersist | |
- model._dontPersist = false | |
- user.set 'achievements.ultimateGear', true, -> | |
- model._dontPersist = dontPersist | |
+ dontPersist = model._dontPersist; model._dontPersist = false | |
+ user.set 'achievements.ultimateGear', true, (-> model._dontPersist = dontPersist) | |
$('#max-gear-achievement-modal').modal('show') | |
+ user.on 'set', 'tasks.*.streak', (id, val) -> | |
+ # 21-day streak, as per the old philosophy of doign a thing 21-days in a row makes a habit | |
+ if val > 0 and (val % 21) is 0 | |
+ dontPersist = model._dontPersist; model._dontPersist = false | |
+ user.incr 'achievements.streak', 1, (-> model._dontPersist = dontPersist) | |
+ $('#streak-achievement-modal').modal('show') | |
+ | |
diff --git a/views/app/avatar.html b/views/app/avatar.html | |
index 975a50d..29f4ef2 100644 | |
--- a/views/app/avatar.html | |
+++ b/views/app/avatar.html | |
@@ -179,9 +179,12 @@ | |
<!--<div class='achievement achievement-bow'></div>--> | |
<!--<div class='achievement achievement-heart'></div>--> | |
<!--<div class='achievement achievement-shield'></div>--> | |
- <!--<div class='achievement achievement-thermometer'></div>--> | |
<!--<div class='achievement achievement-firefox'></div>--> | |
<!--<div class='achievement achievement-karaoke'></div>--> | |
+ {#if @profile.achievements.streak} | |
+ <div class='achievement achievement-thermometer'></div> {@profile.achievements.streak} Streak Achievement(s) | |
+ <hr/> | |
+ {/} | |
{#if @profile.achievements.originalUser} | |
<div class='achievement achievement-cake'></div>Original User | |
<hr/> | |
diff --git a/views/app/modals.html b/views/app/modals.html | |
index 5122e56..0408125 100644 | |
--- a/views/app/modals.html | |
+++ b/views/app/modals.html | |
@@ -5,6 +5,7 @@ | |
<app:pets:modals /> | |
<app:alerts:modals /> | |
<app:rewards:modals /> | |
+ <app:tasks:modals /> | |
<!-- Game Over Modal --> | |
<div style="{#unless equal(_user.stats.lvl,0)}display:none;{/}"> | |
diff --git a/views/app/tasks.html b/views/app/tasks.html | |
index 86a6225..8f326c3 100644 | |
--- a/views/app/tasks.html | |
+++ b/views/app/tasks.html | |
@@ -1,3 +1,13 @@ | |
+<modals:> | |
+ <app:modals:modal modalId='streak-achievement-modal' header="Achievement!"> | |
+ <p> | |
+ <div class='achievement achievement-thermometer'></div>You have stacked your "Streaker" Achievement! Every 21 days of streak, you gain 1 achievement point here. | |
+ </p> | |
+ <@footer> | |
+ <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button> | |
+ </@footer> | |
+ </app:modals:modal> | |
+ | |
<ads: nonvoid> | |
{{#if and( _loggedIn, notEqual(_user.flags.ads,'hide') )}} | |
<span class='pull-right'> | |
@@ -98,6 +108,10 @@ | |
<!-- right-hand side control buttons --> | |
<div class="task-meta-controls"> | |
+ <!-- Streak --> | |
+ <span class='{#unless :task.streak}hide{/}'> | |
+ {:task.streak}<span rel='tooltip' title='Streak Counter'><i class='icon-forward'></i></span> | |
+ </span> | |
<!-- edit --> | |
<a x-bind=click:toggleTaskEdit data-hide-id="{{:task.id}}-chart" data-toggle-id="{{:task.id}}-edit" rel=tooltip title="Edit"><i class="icon-pencil"></i></a> | |
<!-- delete --> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment