2013-02-08 17:50:37 +00:00
_ = require ' underscore '
2013-02-08 19:33:12 +00:00
items = module.exports.items =
2013-02-08 07:09:03 +00:00
weapon: [
2013-03-02 18:23:43 +00:00
{ index: 0 , text: " Training Sword " , classes: " weapon_0 " , notes : ' Training weapon. ' , strength: 0 , value : 0 }
{ index: 1 , text: " Sword " , classes : ' weapon_1 ' , notes : ' Increases experience gain by 3%. ' , strength: 3 , value : 20 }
{ index: 2 , text: " Axe " , classes : ' weapon_2 ' , notes : ' Increases experience gain by 6%. ' , strength: 6 , value : 30 }
{ index: 3 , text: " Morningstar " , classes : ' weapon_3 ' , notes : ' Increases experience gain by 9%. ' , strength: 9 , value : 45 }
{ index: 4 , text: " Blue Sword " , classes : ' weapon_4 ' , notes : ' Increases experience gain by 12%. ' , strength: 12 , value : 65 }
{ index: 5 , text: " Red Sword " , classes : ' weapon_5 ' , notes : ' Increases experience gain by 15%. ' , strength: 15 , value : 90 }
{ index: 6 , text: " Golden Sword " , classes : ' weapon_6 ' , notes : ' Increases experience gain by 18%. ' , strength: 18 , value : 120 }
2013-05-08 14:42:44 +00:00
{ index: 7 , text: " Dark Souls Blade " , classes : ' weapon_7 ' , notes : ' Increases experience gain by 21%. ' , strength: 21 , value : 150 }
2013-02-08 07:09:03 +00:00
]
armor: [
2013-03-02 18:23:43 +00:00
{ index: 0 , text: " Cloth Armor " , classes: ' armor_0 ' , notes : ' Training armor. ' , defense: 0 , value : 0 }
{ index: 1 , text: " Leather Armor " , classes: ' armor_1 ' , notes : ' Decreases HP loss by 4%. ' , defense: 4 , value : 30 }
{ index: 2 , text: " Chain Mail " , classes: ' armor_2 ' , notes : ' Decreases HP loss by 6%. ' , defense: 6 , value : 45 }
{ index: 3 , text: " Plate Mail " , classes: ' armor_3 ' , notes : ' Decreases HP loss by 7%. ' , defense: 7 , value : 65 }
{ index: 4 , text: " Red Armor " , classes: ' armor_4 ' , notes : ' Decreases HP loss by 8%. ' , defense: 8 , value : 90 }
{ index: 5 , text: " Golden Armor " , classes: ' armor_5 ' , notes : ' Decreases HP loss by 10%. ' , defense: 10 , value : 120 }
2013-05-08 14:42:44 +00:00
{ index: 6 , text: " Shade Armor " , classes: ' armor_6 ' , notes : ' Decreases HP loss by 12%. ' , defense: 12 , value : 150 }
2013-02-08 07:09:03 +00:00
]
head: [
2013-03-02 18:23:43 +00:00
{ index: 0 , text: " No Helm " , classes: ' head_0 ' , notes : ' Training helm. ' , defense: 0 , value : 0 }
{ index: 1 , text: " Leather Helm " , classes: ' head_1 ' , notes : ' Decreases HP loss by 2%. ' , defense: 2 , value : 15 }
{ index: 2 , text: " Chain Coif " , classes: ' head_2 ' , notes : ' Decreases HP loss by 3%. ' , defense: 3 , value : 25 }
{ index: 3 , text: " Plate Helm " , classes: ' head_3 ' , notes : ' Decreases HP loss by 4%. ' , defense: 4 , value : 45 }
{ index: 4 , text: " Red Helm " , classes: ' head_4 ' , notes : ' Decreases HP loss by 5%. ' , defense: 5 , value : 60 }
{ index: 5 , text: " Golden Helm " , classes: ' head_5 ' , notes : ' Decreases HP loss by 6%. ' , defense: 6 , value : 80 }
2013-05-08 15:42:55 +00:00
{ index: 6 , text: " Shade Helm " , classes: ' head_6 ' , notes : ' Decreases HP loss by 7%. ' , defense: 7 , value : 100 }
2013-02-08 07:09:03 +00:00
]
shield: [
2013-03-02 18:23:43 +00:00
{ index: 0 , text: " No Shield " , classes: ' shield_0 ' , notes : ' No Shield. ' , defense: 0 , value : 0 }
{ index: 1 , text: " Wooden Shield " , classes: ' shield_1 ' , notes : ' Decreases HP loss by 3% ' , defense: 3 , value : 20 }
{ index: 2 , text: " Buckler " , classes: ' shield_2 ' , notes : ' Decreases HP loss by 4%. ' , defense: 4 , value : 35 }
{ index: 3 , text: " Enforced Shield " , classes: ' shield_3 ' , notes : ' Decreases HP loss by 5%. ' , defense: 5 , value : 55 }
{ index: 4 , text: " Red Shield " , classes: ' shield_4 ' , notes : ' Decreases HP loss by 7%. ' , defense: 7 , value : 70 }
{ index: 5 , text: " Golden Shield " , classes: ' shield_5 ' , notes : ' Decreases HP loss by 8%. ' , defense: 8 , value : 90 }
2013-05-08 14:42:44 +00:00
{ index: 6 , text: " Tormented Skull " , classes: ' shield_6 ' , notes : ' Decreases HP loss by 9%. ' , defense: 9 , value : 120 }
2013-02-08 07:09:03 +00:00
]
2013-02-08 19:13:52 +00:00
potion: { type: ' potion ' , text: " Potion " , notes: " Recover 15 HP " , value: 25 , classes: ' potion ' }
2013-03-17 13:13:25 +00:00
reroll: { type: ' reroll ' , text: " Re-Roll " , classes: ' reroll ' , notes: " Resets your task values back to 0 (yellow). Useful when everything ' s red and it ' s hard to stay alive. " , value : 0 }
2013-02-08 07:09:03 +00:00
2013-02-11 05:13:44 +00:00
pets: [
2013-03-27 18:46:10 +00:00
{ text: ' Wolf ' , name: ' Wolf ' , value: 3 }
{ text: ' Tiger Cub ' , name: ' TigerCub ' , value: 3 }
2013-03-09 17:03:38 +00:00
#{text: 'Polar Bear Cub', name: 'PolarBearCub', value: 3} #commented out because there are no polarbear modifiers yet, special drop?
2013-03-27 18:46:10 +00:00
{ text: ' Panda Cub ' , name: ' PandaCub ' , value: 3 }
{ text: ' Lion Cub ' , name: ' LionCub ' , value: 3 }
{ text: ' Fox ' , name: ' Fox ' , value: 3 }
{ text: ' Flying Pig ' , name: ' FlyingPig ' , value: 3 }
{ text: ' Dragon ' , name: ' Dragon ' , value: 3 }
{ text: ' Cactus ' , name: ' Cactus ' , value: 3 }
{ text: ' Bear Cub ' , name: ' BearCub ' , value: 3 }
2013-02-11 05:13:44 +00:00
]
2013-03-27 18:24:06 +00:00
hatchingPotions: [
2013-03-28 07:34:05 +00:00
{ text: ' Base ' , name: ' Base ' , notes: " Hatches your pet in it ' s base form. " , value: 1 }
2013-03-27 05:22:13 +00:00
{ text: ' White ' , name: ' White ' , notes: ' Turns your animal into a White pet. ' , value: 2 }
{ text: ' Desert ' , name: ' Desert ' , notes: ' Turns your animal into a Desert pet. ' , value: 2 }
2013-03-25 18:42:38 +00:00
{ text: ' Red ' , name: ' Red ' , notes: ' Turns your animal into a Red pet. ' , value: 3 }
2013-03-27 05:22:13 +00:00
{ text: ' Shade ' , name: ' Shade ' , notes: ' Turns your animal into a Shade pet. ' , value: 3 }
{ text: ' Skeleton ' , name: ' Skeleton ' , notes: ' Turns your animal into a Skeleton. ' , value: 3 }
{ text: ' Zombie ' , name: ' Zombie ' , notes: ' Turns your animal into a Zombie. ' , value: 4 }
{ text: ' Cotton Candy Pink ' , name: ' CottonCandyPink ' , notes: ' Turns your animal into a Cotton Candy Pink pet. ' , value: 4 }
{ text: ' Cotton Candy Blue ' , name: ' CottonCandyBlue ' , notes: ' Turns your animal into a Cotton Candy Blue pet. ' , value: 4 }
{ text: ' Golden ' , name: ' Golden ' , notes: ' Turns your animal into a Golden pet. ' , value: 5 }
2013-03-09 13:17:02 +00:00
]
2013-02-11 05:13:44 +00:00
2013-02-08 17:50:37 +00:00
# add "type" to each item, so we can reference that as "weapon" or "armor" in the html
2013-02-08 19:13:52 +00:00
_ . each [ ' weapon ' , ' armor ' , ' head ' , ' shield ' ] , (key) ->
_ . each items [ key ] , (item) -> item.type = key
2013-02-08 17:50:37 +00:00
2013-03-27 19:32:18 +00:00
_ . each items . pets , (pet) -> pet.notes = ' Find a hatching potion to pour on this egg, and one day it will hatch into a loyal pet. '
2013-03-27 18:57:40 +00:00
_ . each items . hatchingPotions , (hatchingPotion) -> hatchingPotion.notes = " Pour this on an egg, and it will hatch as a #{ hatchingPotion . text } pet. "
2013-03-21 20:56:25 +00:00
2013-02-08 07:09:03 +00:00
# ##
server exports
# ##
module.exports.server = (model) ->
2013-05-10 15:42:21 +00:00
model . set ' _items ' , items
2013-02-08 07:09:03 +00:00
updateStore ( model )
# ##
app exports
# ##
module.exports.app = (appExports, model) ->
user = model . at ' _user '
appExports.buyItem = (e, el, next) ->
user = model . at ' _user '
#TODO: this should be working but it's not. so instead, i'm passing all needed values as data-attrs
# item = model.at(e.target)
gp = user . get ' stats.gp '
[ type , value , index ] = [ $ ( el ) . attr ( ' data-type ' ) , $ ( el ) . attr ( ' data-value ' ) , $ ( el ) . attr ( ' data-index ' ) ]
return if gp < value
2013-04-08 00:23:19 +00:00
# make sure deduction doesn't happen unless purchase was successful, see https://github.com/lefnire/habitrpg/issues/233
deductGP = -> user . set ' stats.gp ' , gp - value
2013-02-08 07:09:03 +00:00
if type == ' weapon '
2013-04-08 00:23:19 +00:00
user . set ' items.weapon ' , index , deductGP
2013-02-08 07:09:03 +00:00
updateStore model
else if type == ' armor '
2013-04-08 00:23:19 +00:00
user . set ' items.armor ' , index , deductGP
2013-02-08 07:09:03 +00:00
updateStore model
else if type == ' head '
2013-04-08 00:23:19 +00:00
user . set ' items.head ' , index , deductGP
2013-02-08 07:09:03 +00:00
updateStore model
else if type == ' shield '
2013-04-08 00:23:19 +00:00
user . set ' items.shield ' , index , deductGP
2013-02-08 07:09:03 +00:00
updateStore model
else if type == ' potion '
hp = user . get ' stats.hp '
hp += 15
hp = 50 if hp > 50
2013-04-08 00:23:19 +00:00
user . set ' stats.hp ' , hp , deductGP
2013-02-08 07:09:03 +00:00
2013-02-11 05:13:44 +00:00
2013-02-11 06:17:41 +00:00
appExports.activateRewardsTab = ->
2013-04-08 00:29:13 +00:00
model . set ' _activeTabRewards ' , true
model . set ' _activeTabPets ' , false
2013-02-11 06:17:41 +00:00
appExports.activatePetsTab = ->
2013-04-08 00:29:13 +00:00
model . set ' _activeTabPets ' , true
model . set ' _activeTabRewards ' , false
2013-02-11 06:17:41 +00:00
2013-02-08 07:09:03 +00:00
# ##
update store
# ##
module.exports.updateStore = updateStore = (model) ->
2013-05-10 15:42:21 +00:00
model . setNull ' _items.next ' , { }
2013-05-08 20:30:23 +00:00
user = model . at ( ' _user ' )
equipped = user . get ( ' items ' )
2013-02-08 18:04:31 +00:00
_ . each [ ' weapon ' , ' armor ' , ' shield ' , ' head ' ] , (type) ->
2013-05-08 20:30:23 +00:00
i = parseInt ( equipped ? [ type ] || 0 ) + 1
showNext = true
if i is items [ type ] . length - 1
if ( type in [ ' armor ' , ' shield ' , ' head ' ] )
showNext = user . get ( ' backer.tier ' ) >= 45 # backer armor
else
showNext = user . get ( ' backer.tier ' ) >= 70 # backer weapon
else if i is items [ type ] . length
showNext = false
2013-05-10 15:42:21 +00:00
model . set " _items.next. #{ type } " , if showNext then items [ type ] [ i ] else { hide : true }
2013-02-08 17:50:37 +00:00
2013-02-08 07:09:03 +00:00