Merge pull request #9 from lefnire/pets

Keeping my pets branch updated
This commit is contained in:
Shane Lister
2013-03-27 16:59:59 -07:00
9 changed files with 172 additions and 84 deletions
+72
View File
@@ -0,0 +1,72 @@
/**
* Applies backer tokens & items (this file will be updated periodically
*/
// mongo habitrpg ./node_modules/underscore/underscore.js migrations/20130327_apply_tokens.js
var mapping = [
{ // $1
tokens: 0,
users: []
},
{ // $5
tokens: 20,
users: ['9']
},
{ // $10
tokens: 50,
users: []
},
{ // $15
tokens: 100,
users: []
},
{ // $30
tokens: 150,
users: []
},
{ // $45
tokens: 170,
users: []
},
{ // $60
tokens: 200,
users: []
},
{ // $70
tokens: 240,
users: []
},
{ // $80
tokens: 240,
users: []
},
{ // $90
tokens: 280,
users: []
},
{ // $300
tokens: 500,
users: []
},
{ // $800
tokens: 500,
users: []
}
];
_.each(mapping, function(tier){
db.users.update(
{
_id: { $in: tier.users },
'backer.tokensApplied': { $exists: false }
},
{
$set: { 'backer.tokensApplied': true, 'flags.ads': 'hide' },
$inc: { balance: (tier.tokens/4) }
},
{ multi: true}
)
})
+1 -1
View File
@@ -17,7 +17,7 @@
"moment": "*",
"stripe": "*",
"async": "*",
"lodash": "*",
"lodash": "1.0.x",
"coffee-script": "1.4.x",
"underscore": "*",
"mongoskin": "*",
+23 -7
View File
@@ -1,4 +1,4 @@
.Pet_Egg_Wolf, .Pet_Egg_TigerCub, .Pet_Egg_PolarBear, .Pet_Egg_PandaCub, .Pet_Egg_LionCub, .Pet_Egg_Fox, .Pet_Egg_FlyingPig, .Pet_Egg_Dragon, .Pet_Egg_Cactus, .Pet_Egg_BearCub, .Item_HatchingPotion_Basic, .Item_HatchingPotion_White, .Item_HatchingPotion_Desert, .Item_HatchingPotion_Red, .Item_HatchingPotion_Shade, .Item_HatchingPotion_Skeleton {background: url("/img/sprites/Egg_Sprite_Sheet.png") no-repeat}
.Pet_Egg_Wolf, .Pet_Egg_TigerCub, .Pet_Egg_PolarBear, .Pet_Egg_PandaCub, .Pet_Egg_LionCub, .Pet_Egg_Fox, .Pet_Egg_FlyingPig, .Pet_Egg_Dragon, .Pet_Egg_Cactus, .Pet_Egg_BearCub, .Pet_HatchingPotion_Base, .Pet_HatchingPotion_White, .Pet_HatchingPotion_Desert, .Pet_HatchingPotion_Red, .Pet_HatchingPotion_Shade, .Pet_HatchingPotion_Skeleton, .Pet_HatchingPotion_Zombie, .Pet_HatchingPotion_CottonCandyPink, .Pet_HatchingPotion_CottonCandyBlue, .Pet_HatchingPotion_Golden {background: url("/img/sprites/Egg_Sprite_Sheet.png") no-repeat}
.Pet_Egg_Wolf {background-position: 0px 0px; width: 48px; height: 51px}
.Pet_Egg_TigerCub {background-position: 0px -51px; width: 48px; height: 51px}
.Pet_Egg_PolarBear {background-position: 0px -102px; width: 48px; height: 51px}
@@ -9,9 +9,25 @@
.Pet_Egg_Dragon {background-position: 0px -357px; width: 48px; height: 51px}
.Pet_Egg_Cactus {background-position: 0px -408px; width: 48px; height: 51px}
.Pet_Egg_BearCub {background-position: 0px -459px; width: 48px; height: 51px}
.Item_HatchingPotion_Basic {background-position: -48px -0px; width: 48px; height: 51px}
.Item_HatchingPotion_White {background-position: -48px -51px; width: 48px; height: 51px}
.Item_HatchingPotion_Desert {background-position: -48px -102px; width: 48px; height: 51px}
.Item_HatchingPotion_Red {background-position: -48px -153px; width: 48px; height: 51px}
.Item_HatchingPotion_Shade {background-position: -48px -204px; width: 48px; height: 51px}
.Item_HatchingPotion_Skeleton {background-position: -48px -255px; width: 48px; height: 51px}
.Pet_HatchingPotion_Base {background-position: -48px -0px; width: 48px; height: 51px}
.Pet_HatchingPotion_White {background-position: -48px -51px; width: 48px; height: 51px}
.Pet_HatchingPotion_Desert {background-position: -48px -102px; width: 48px; height: 51px}
.Pet_HatchingPotion_Red {background-position: -48px -153px; width: 48px; height: 51px}
.Pet_HatchingPotion_Shade {background-position: -48px -204px; width: 48px; height: 51px}
.Pet_HatchingPotion_Skeleton {background-position: -48px -255px; width: 48px; height: 51px}
/* Temporary until we get the other hatching potions */
.Pet_HatchingPotion_Zombie, .Pet_HatchingPotion_CottonCandyPink, .Pet_HatchingPotion_CottonCandyBlue, .Pet_HatchingPotion_Golden {background-position: -48px -0px; width: 48px; height: 51px}
.Pet_HatchingPotion_Zombie {
-webkit-filter: invert(1);
}
.Pet_HatchingPotion_CottonCandyPink {
-webkit-filter: hue-rotate(120deg);
}
.Pet_HatchingPotion_CottonCandyBlue {
-webkit-filter: saturate(3);
}
.Pet_HatchingPotion_Golden {
-webkit-filter: hue-rotate(220deg);
}
+13 -13
View File
@@ -38,19 +38,19 @@ items = module.exports.items =
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 }
pets: [
{text: 'Wolf', name: 'Wolf', value: 2}
{text: 'Tiger Cub', name: 'TigerCub', value: 2}
{text: 'Wolf', name: 'Wolf', value: 3}
{text: 'Tiger Cub', name: 'TigerCub', value: 3}
#{text: 'Polar Bear Cub', name: 'PolarBearCub', value: 3} #commented out because there are no polarbear modifiers yet, special drop?
{text: 'Panda Cub', name: 'PandaCub', value: 2}
{text: 'Lion Cub', name: 'LionCub', value: 2}
{text: 'Fox', name: 'Fox', value: 2}
{text: 'Flying Pig', name: 'FlyingPig', value: 2}
{text: 'Dragon', name: 'Dragon', value: 2}
{text: 'Cactus', name: 'Cactus', value: 2}
{text: 'Bear Cub', name: 'BearCub', value: 2}
{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}
]
food: [
hatchingPotions: [
{text: 'Common', name: 'Base', notes: "Hatches your pet in it's base form.", value: 1}
{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}
@@ -67,8 +67,8 @@ items = module.exports.items =
_.each ['weapon', 'armor', 'head', 'shield'], (key) ->
_.each items[key], (item) -> item.type = key
_.each items.pets, (pet) -> pet.notes = 'Find some Hatching Powder to sprinkle on this egg, and one day it will hatch into a loyal pet.'
_.each items.food, (food) -> food.notes = "Sprinkle this on an egg, and it will hatch as a #{food.text} pet."
_.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.'
_.each items.hatchingPotions, (hatchingPotion) -> hatchingPotion.notes = "Pour this on an egg, and it will hatch as a #{hatchingPotion.text} pet."
###
view exports
@@ -204,7 +204,7 @@ module.exports.updateStore = updateStore = (model) ->
model.set '_view.items.potion', items.potion
model.set '_view.items.reroll', items.reroll
model.set '_view.items.pets', items.pets
model.set '_view.items.food', items.food
model.set '_view.items.hatchingPotions', items.hatchingPotions
+21 -21
View File
@@ -1,6 +1,6 @@
_ = require 'underscore'
{ randomVal } = require './helpers'
{ pets, food } = require('./items').items
{ pets, hatchingPotions } = require('./items').items
###
app exports
@@ -22,33 +22,33 @@ module.exports.app = (appExports, model) ->
$('#drops-enabled-modal').modal 'show'
appExports.chooseEgg = (e, el) ->
model.ref '_feedEgg', e.at()
model.ref '_hatchEgg', e.at()
appExports.feedEgg = (e, el) ->
foodName = $(el).children('select').val()
myFood = user.get 'items.food'
egg = model.get '_feedEgg'
appExports.hatchEgg = (e, el) ->
hatchingPotionName = $(el).children('select').val()
myHatchingPotion = user.get 'items.hatchingPotions'
egg = model.get '_hatchEgg'
eggs = user.get 'items.eggs'
myPets = user.get 'items.pets'
foodIdx = myFood.indexOf foodName
hatchingPotionIdx = myHatchingPotion.indexOf hatchingPotionName
eggIdx = eggs.indexOf egg
return alert "You don't own that food :\\" if foodIdx is -1
return alert "You don't own that egg :\\" if eggIdx is -1
return alert "You already have that pet." if myPets and myPets.indexOf("#{egg.name}-#{foodName}") != -1
return alert "You don't own that hatching potion yet, complete more tasks!" if hatchingPotionIdx is -1
return alert "You don't own that egg yet, complete more tasks!" if eggIdx is -1
return alert "You already have that pet, hatch a different combo." if myPets and myPets.indexOf("#{egg.name}-#{hatchingPotionName}") != -1
user.push 'items.pets', egg.name + '-' + foodName
user.push 'items.pets', egg.name + '-' + hatchingPotionName
eggs.splice eggIdx, 1
myFood.splice foodIdx, 1
myHatchingPotion.splice hatchingPotionIdx, 1
user.set 'items.eggs', eggs
user.set 'items.food', myFood
user.set 'items.hatchingPotions', myHatchingPotion
alert 'Your egg hatched! Visit your stable to equip your pet.'
#FIXME Bug: this removes from the array properly in the browser, but on refresh is has removed all items from the arrays
# user.remove 'items.food', foodIdx, 1
# user.remove 'items.hatchingPotions', hatchingPotionIdx, 1
# user.remove 'items.eggs', eggIdx, 1
appExports.choosePet = (e, el) ->
@@ -63,14 +63,14 @@ module.exports.app = (appExports, model) ->
pet = {} if user.get('items.currentPet.str') is petStr
user.set 'items.currentPet', pet
appExports.buyFood = (e, el) ->
name = $(el).attr 'data-food'
newFood = _.findWhere food, name: name
appExports.buyHatchingPotion = (e, el) ->
name = $(el).attr 'data-hatchingPotion'
newHatchingPotion = _.findWhere hatchingPotions, name: name
tokens = user.get('balance') * 4
if tokens > newFood.value
if confirm "Buy this food with #{newFood.value} of your #{tokens} tokens?"
user.push 'items.food', newFood.name
user.set 'balance', (tokens - newFood.value) / 4
if tokens > newHatchingPotion.value
if confirm "Buy this hatching potion with #{newHatchingPotion.value} of your #{tokens} tokens?"
user.push 'items.hatchingPotions', newHatchingPotion.name
user.set 'balance', (tokens - newHatchingPotion.value) / 4
else
$('#more-tokens-modal').modal 'show'
+7 -7
View File
@@ -5,7 +5,7 @@ _ = require 'underscore'
browser = require './browser'
character = require './character'
items = require './items'
{ pets, food } = items.items
{ pets, hatchingPotions } = items.items
algos = require './algos'
MODIFIER = algos.MODIFIER # each new level, armor, weapon add 2% modifier (this mechanism will change)
@@ -29,7 +29,7 @@ randomDrop = (model, delta) ->
chanceMultiplier *= Math.abs(delta) # multiply chance by reddness
if user.get('flags.dropsEnabled') and Math.random() < (.01 * chanceMultiplier)
# current breakdown - 3% (adjustable) chance on drop
# If they got a drop: 50% chance of egg, 50% Food. If food, broken down further even further
# If they got a drop: 50% chance of egg, 50% Hatching Potion. If hatchingPotion, broken down further even further
rarity = Math.random()
# Egg, 40% chance
@@ -39,7 +39,7 @@ randomDrop = (model, delta) ->
drop.type = 'Egg'
drop.dialog = "You've found a #{drop.text} Egg! #{drop.notes}"
# Food, 60% chance - break down by rarity even more. FIXME this may not be the best method, so revisit
# Hatching Potion, 60% chance - break down by rarity even more. FIXME this may not be the best method, so revisit
else
acceptableDrops = []
@@ -62,11 +62,11 @@ randomDrop = (model, delta) ->
else
acceptableDrops = ['Base']
acceptableDrops = _.filter(food, (foodItem) -> foodItem.name in acceptableDrops)
acceptableDrops = _.filter(hatchingPotions, (hatchingPotion) -> hatchingPotion.name in acceptableDrops)
drop = randomVal acceptableDrops
user.push 'items.food', drop.name
drop.type = 'Food'
drop.dialog = "You've found #{drop.text} Hatching Powder! #{drop.notes}"
user.push 'items.hatchingPotions', drop.name
drop.type = 'HatchingPotion'
drop.dialog = "You've found a #{drop.text} Hatching Potion! #{drop.notes}"
model.set '_drop', drop
$('#item-dropped-modal').modal 'show'
+1 -1
View File
@@ -46,5 +46,5 @@
clear:both
.pets-menu > div
float:left
.food-menu > div
.hatchingPotions-menu > div
float:left
+12 -12
View File
@@ -249,24 +249,24 @@
</tr>
</table>
{/}
<h4>Hatching Powder</h4>
{#with _view.items.food as :food}
<h4>Hatching Potions</h4>
{#with _view.items.hatchingPotions as :hatchingPotion}
<table>
<tr>
{#with :food[0]}<app:pets:food />{/}
{#with :food[1]}<app:pets:food />{/}
{#with :food[2]}<app:pets:food />{/}
{#with :food[3]}<app:pets:food />{/}
{#with :hatchingPotion[0]}<app:pets:hatchingPotion />{/}
{#with :hatchingPotion[1]}<app:pets:hatchingPotion />{/}
{#with :hatchingPotion[2]}<app:pets:hatchingPotion />{/}
{#with :hatchingPotion[3]}<app:pets:hatchingPotion />{/}
</tr>
<tr>
{#with :food[4]}<app:pets:food />{/}
{#with :food[5]}<app:pets:food />{/}
{#with :food[6]}<app:pets:food />{/}
{#with :food[7]}<app:pets:food />{/}
{#with :hatchingPotion[4]}<app:pets:hatchingPotion />{/}
{#with :hatchingPotion[5]}<app:pets:hatchingPotion />{/}
{#with :hatchingPotion[6]}<app:pets:hatchingPotion />{/}
{#with :hatchingPotion[7]}<app:pets:hatchingPotion />{/}
</tr>
<tr>
{#with :food[8]}<app:pets:food />{/}
{#with :food[9]}<app:pets:food />{/}
{#with :hatchingPotion[8]}<app:pets:hatchingPotion />{/}
{#with :hatchingPotion[9]}<app:pets:hatchingPotion />{/}
</tr>
</table>
{/}
+22 -22
View File
@@ -21,15 +21,15 @@
<img rel=tooltip title="{.text} - {.value} Tokens" x-bind="click:selectPet" data-pet='{.name}' src='img/sprites/{.icon}'/>
</td>
<food:>
<td class="active-food">
<div rel=tooltip class="Pet_Food_{.name}" title="{.text} - {.value} Tokens" x-bind="click:buyFood" data-food='{.name}'></div>
<hatchingPotion:>
<td class="active-hatchingPotion" x-bind="click:buyHatchingPotion" data-hatchingPotion='{.name}'>
<div rel=tooltip class="Pet_HatchingPotion_{.name}" title="{.text} - {.value} Tokens"></div>
{.text}
</td>
<egg:>
<td class="active-egg">
<div rel=tooltip class="Pet_Egg_{.name}" title="{.text} - {.value} Tokens" x-bind="click:buyEgg" data-egg='{.name}'></div>
<td class="active-egg" x-bind="click:buyEgg" data-egg='{.name}'>
<div rel=tooltip class="Pet_Egg_{.name}" title="{.text} - {.value} Tokens"></div>
{.text}
</td>
@@ -38,10 +38,10 @@
<div class='span6 well'>
<menu type="list" class="inventory-list">
<li class="customize-menu">
{#if not(_user.items.eggs)}
<p>You don't have any eggs yet.</p>
{/if}
<menu label="Eggs" class='pets-menu'>
{#if not(_user.items.eggs)}
<p>You don't have any eggs yet.</p>
{/if}
{#each _user.items.eggs as :egg}
<div>
<button rel=tooltip title="{:egg.text}" class="customize-option Pet_Egg_{{:egg.name}}" x-bind="click: chooseEgg"></button>
@@ -51,31 +51,31 @@
</menu>
</li>
<li class="customize-menu">
{#if not(_user.items.food)}
<p>You don't have any hatching powder yet.</p>
{/if}
<menu label="Hatching Powder" class='food-menu'>
{#each _user.items.food as :food}
<menu label="Hatching Potions" class='hatchingPotion-menu'>
{#if not(_user.items.hatchingPotions)}
<p>You don't have any hatching potions yet.</p>
{/if}
{#each _user.items.hatchingPotions as :hatchingPotion}
<div>
<button rel=tooltip title="{:food}" class="customize-option Pet_Food_{{:food}}" x-bind="click: chooseFood"></button>
<p>{:food}</p>
<button rel=tooltip title="{:hatchingPotion}" class="customize-option Pet_HatchingPotion_{{:hatchingPotion}}" x-bind="click: chooseHatching Potion"></button>
<p>{:hatchingPotion}</p>
</div>
{/each}
</menu>
</li>
</menu>
</div>
{#if _feedEgg}
{#if _hatchEgg}
<div class='span6 well'>
<h3>Hatch Your Egg</h3>
{#if not(_user.items.food)}
<p>You don't have any hatching powder yet.</p>
{#if not(_user.items.hatchingPotions)}
<p>You don't have any hatching potions yet.</p>
{else}
<p>What would you like to sprinkle on your {_feedEgg.text} egg?</p>
<form x-bind="submit:feedEgg">
<p>Which hatching potion will you pour on your {_hatchEgg.text} egg?</p>
<form x-bind="submit:hatchEgg">
<select>
{#each _user.items.food as :food}
<option>{:food}</option>
{#each _user.items.hatchingPotions as :hatchingPotion}
<option>{:hatchingPotion}</option>
{/each}
</select>
<button type=submit>Sprinkle</button>