Can buy items, storing to user now. many bug fixes

This commit is contained in:
Tyler Renelle 2012-07-08 18:58:11 -04:00
parent 2ddbe61141
commit 3305697a4e
3 changed files with 51 additions and 25 deletions

View file

@ -119,27 +119,24 @@ module.exports = {
title: "Item Store Unlocked"
content: "Congradulations, you have unlocked the Item Store! You can now buy weapons, armor, potions, etc. Read each item's comment for more information."
weapon: [
{text: "Sword 1", icon: "item-sword1", notes:'', value:0}
{text: "Sword 2", icon:'item-sword2', notes:'', value:100}
{text: "Blue Sword", icon:'item-bluesword', notes:'', value:200}
{text: "Axe", icon:'item-axe', notes:'', value:300}
{text: "Morningstar", icon:'item-morningstar', notes:'', value:400}
{text: "Red Sword", icon:'item-redsword', notes:'', value:500}
{text: "Gold Sword", icon:'item-goldsword', notes:'', value:600}
{type: 'weapon', index: 0, text: "Sword 1", icon: "item-sword1", notes:'', value:0}
{type: 'weapon', index: 1, text: "Sword 2", icon:'item-sword2', notes:'', value:100}
{type: 'weapon', index: 2, text: "Blue Sword", icon:'item-bluesword', notes:'', value:200}
{type: 'weapon', index: 3, text: "Axe", icon:'item-axe', notes:'', value:300}
{type: 'weapon', index: 4, text: "Morningstar", icon:'item-morningstar', notes:'', value:400}
{type: 'weapon', index: 5, text: "Red Sword", icon:'item-redsword', notes:'', value:500}
{type: 'weapon', index: 6, text: "Gold Sword", icon:'item-goldsword', notes:'', value:600}
]
armor: [
{text: "Cloth Armor", icon: 'item-clotharmor', notes:'', value:0}
{text: "Leather Armor", icon: 'item-leatherarmor', notes:'', value:100}
{text: "Chain Mail", icon: 'item-mailarmor', notes:'', value:200}
{text: "Plate Mail", icon: 'item-platearmor', notes:'', value:200}
{text: "Red Armor", icon: 'item-redarmor', notes:'', value:200}
{text: "Golden Armor", icon: 'item-goldenarmor', notes:'', value:200}
{type: 'armor', index: 0, text: "Cloth Armor", icon: 'item-clotharmor', notes:'', value:0}
{type: 'armor', index: 1, text: "Leather Armor", icon: 'item-leatherarmor', notes:'', value:100}
{type: 'armor', index: 2, text: "Chain Mail", icon: 'item-mailarmor', notes:'', value:200}
{type: 'armor', index: 3, text: "Plate Mail", icon: 'item-platearmor', notes:'', value:200}
{type: 'armor', index: 4, text: "Red Armor", icon: 'item-redarmor', notes:'', value:200}
{type: 'armor', index: 5, text: "Golden Armor", icon: 'item-goldenarmor', notes:'', value:200}
]
potion: {text: "Potion", notes: "Recover 15 HP", value: 100, icon: 'item-flask'}
reroll:
text: "Re-Roll"
icon: 'chest'
notes: "Reset your task values to 0. Do this only if you're floundering."
potion: {type: 'potion', text: "Potion", notes: "Recover 15 HP", value: 100, icon: 'item-flask'}
reroll: {type: 'reroll', text: "Re-Roll", icon: 'chest', notes: "Reset your task values to 0. Do this only if you're floundering."}
}
}

View file

@ -30,10 +30,16 @@ view.fn "round", (num) ->
Math.round num
view.fn "gold", (num) ->
num.toFixed(1).split('.')[0] if num
if num
return num.toFixed(1).split('.')[0]
else
return "0"
view.fn "silver", (num) ->
num.toFixed(1).split('.')[1] if num
if num
num.toFixed(1).split('.')[1]
else
return "0"
## ROUTES ##
@ -106,6 +112,7 @@ ready (model) ->
$('ul.items').popover
title: content.items.unlockedMessage.title
placement: 'left'
trigger: 'manual'
html: true
content: "<div class='item-store-popover'>\
<img src='/img/BrowserQuest/chest.png' />\
@ -116,7 +123,8 @@ ready (model) ->
user.set 'stats.exp', stats.exp
if stats.money?
user.set 'money', stats.money
money = 0.0 if (!money? or money<0)
user.set 'stats.money', stats.money
# Note: Set 12am daily cron for this
# At end of day, add value to all incomplete Daily & Todo tasks (further incentive)
@ -257,8 +265,8 @@ ready (model) ->
task = model.at(e.target)
#TODO bug where I have to delete from _users.tasks AND _{type}List,
# fix when query subscriptions implemented properly
console.log model.del('_user.tasks.'+task.get('id'))
console.log task.remove()
model.del('_user.tasks.'+task.get('id'))
task.remove()
exports.toggleTaskEdit = (e, el) ->
task = model.at $(el).parents('li')[0]
@ -288,7 +296,27 @@ ready (model) ->
chart = new google.visualization.LineChart(document.getElementById( chartSelector ))
chart.draw(data, options)
exports.buyItem = (e, el) ->
exports.buyItem = (e, el, next) ->
user = model.at '_user'
item = model.at e.target
money = user.get 'stats.money'
[type, value] = [item.get('type'), item.get('value')]
return if money < value
user.set 'stats.money', money - value
if type == 'armor'
user.set 'items.armor', item.get('index')
model.set '_items.0', content.items.armor[item.get('index') + 1]
else if type == 'weapon'
user.set 'items.weapon', item.get('index')
model.set '_items.1', content.items.weapon[item.get('index') + 1]
else if type == 'potion'
hp = user.get 'stats.hp'
hp += 15
hp = 50 if hp > 50
user.set 'stats.hp', hp
else if type == 'reroll'
console.log 'reroll'
exports.vote = (e, el, next) ->

View file

@ -217,7 +217,8 @@
<span data-placement="left" data-content="{:item.notes}" data-original-title="{:item.text}" class='task-notes'><i class="icon-comment"></i></span>
</div>
<div class="task-controls">
<a x-bind=click:buy-item class="item-buy-link" data-direction=down>{:item.value}<img src="img/coin_single_gold.png"/></a>
<!-- need to come up with a better identifier -->
<a x-bind=click:buyItem class="item-buy-link" data-item-id={:item.id}>{:item.value}<img src="img/coin_single_gold.png"/></a>
</div>
<div class="task-text"><img src="/img/BrowserQuest/{:item.icon}.png" /> {:item.text}</div>
</pre>