From d74755942936090b7e2bbb0997dcbfb866848429 Mon Sep 17 00:00:00 2001 From: Tyler Renelle Date: Sun, 10 Nov 2013 13:25:13 -0800 Subject: [PATCH] mounts: rewrite item definitions as objects, rather than arrays, to support UserSchema overhaul. Add items.food & items.mounts --- script/HISTORY_PREEN.js | 59 -------------------------------------- script/algos.coffee | 20 ++++++------- script/helpers.coffee | 18 ++++++++---- script/items.coffee | 63 +++++++++++++++++++++++++---------------- 4 files changed, 59 insertions(+), 101 deletions(-) delete mode 100644 script/HISTORY_PREEN.js diff --git a/script/HISTORY_PREEN.js b/script/HISTORY_PREEN.js deleted file mode 100644 index 8adc22bb5c..0000000000 --- a/script/HISTORY_PREEN.js +++ /dev/null @@ -1,59 +0,0 @@ -// FIXME this needs to be ported into algos.cron so it's run for each individual user on the server. It used to be a migration script -/** - * Preen history for users with > 7 history entries - * This takes an infinite array of single day entries [day day day day day...], and turns it into a condensed array - * of averages, condensing more the further back in time we go. Eg, 7 entries each for last 7 days; 4 entries for last - * 4 weeks; 12 entries for last 12 months; 1 entry per year before that: [day*7 week*4 month*12 year*infinite] - */ -function preenHistory(history) { - history = _.filter(history, function(h) {return !!h}); // discard nulls (corrupted somehow) - var newHistory = []; - function preen(amount, groupBy) { - var groups, avg, start; - groups = _(history) - .groupBy(function(h) { return moment(h.date).format(groupBy) }) // get date groupings to average against - .sortBy(function(h,k) {return k;}) // sort by date - .value(); // turn into an array - amount++; // if we want the last 4 weeks, we're going 4 weeks back excluding this week. so +1 to account for exclusion - start = (groups.length - amount > 0) ? groups.length - amount : 0; - groups = groups.slice(start, groups.length - 1) - _.each(groups, function(group){ - avg = _.reduce(group, function(mem, obj){ return mem + obj.value }, 0) / group.length; - newHistory.push({date: +moment(group[0].date), value: avg}); - return true; - }) - } - - preen(50, 'YYYY'); // last 50 years - preen(12, 'YYYYMM'); // last 12 months - preen(4, 'YYYYww'); // last 4 weeks - newHistory = newHistory.concat(history.slice(-7)); // last 7 days - return newHistory; -} - -var minHistLen = 7; -db.users.find({ - - // Registered users with some history - $or: [ - { 'auth.local': { $exists: true }}, - { 'auth.facebook': { $exists: true }} - ], - 'history': {$exists: true} - -}).forEach(function(user) { - var update = {$set:{}}; - - _.each(user.tasks, function(task) { - if ( task.history && task.history.length > minHistLen ) - update['$set']['tasks.' + task.id + '.history'] = preenHistory(task.history); - return true; - }) - - if (user.history.exp && user.history.exp.length > minHistLen) - update['$set']['history.exp'] = preenHistory(user.history.exp); - if (user.history.todos && user.history.todos.length > minHistLen) - update['$set']['history.todos'] = preenHistory(user.history.todos); - - if (!_.isEmpty(update['$set'])) db.users.update({_id: user._id}, update); - }); \ No newline at end of file diff --git a/script/algos.coffee b/script/algos.coffee index 8ec7cad4b1..d35983e6d0 100644 --- a/script/algos.coffee +++ b/script/algos.coffee @@ -2,7 +2,7 @@ moment = require('moment') _ = require('lodash') helpers = require('./helpers.coffee') items = require('./items.coffee') -{pets, hatchingPotions} = items.items +{eggs, hatchingPotions} = items.items XP = 15 HP = 2 @@ -313,10 +313,10 @@ updateStats = (user, newStats, options={}) -> if newStats.hp? # Game Over if newStats.hp <= 0 - user.stats.hp = 0; paths['stats.hp'] = true # signifies dead + user.stats.hp = 0 return else - user.stats.hp = newStats.hp; paths['stats.hp'] = true + user.stats.hp = newStats.hp if newStats.exp? tnl = obj.tnl(user.stats.lvl) @@ -341,21 +341,17 @@ updateStats = (user, newStats, options={}) -> user.stats.exp = newStats.exp - paths["stats.exp"]=true; paths['stats.lvl']=true; paths['stats.gp']=true; paths['stats.hp']=true; - #if silent - #console.log("pushing silent :" + obj.stats.exp) - - # Set flags when they unlock features user.flags ?= {} if !user.flags.customizationsNotification and (user.stats.exp > 10 or user.stats.lvl > 1) - user.flags.customizationsNotification = true; paths['flags.customizationsNotification']=true; + user.flags.customizationsNotification = true if !user.flags.itemsEnabled and user.stats.lvl >= 2 - user.flags.itemsEnabled = true; paths['flags.itemsEnabled']=true; + user.flags.itemsEnabled = true if !user.flags.partyEnabled and user.stats.lvl >= 3 - user.flags.partyEnabled = true; paths['flags.partyEnabled']=true; + user.flags.partyEnabled = true if !user.flags.dropsEnabled and user.stats.lvl >= 4 - user.flags.dropsEnabled = true; paths['flags.dropsEnabled']=true; + user.flags.dropsEnabled = true + user.items.eggs["Wolf"] = 1 if newStats.gp? #FIXME what was I doing here? I can't remember, gp isn't defined diff --git a/script/helpers.coffee b/script/helpers.coffee index 9dce6653fa..7ab7a3f58a 100644 --- a/script/helpers.coffee +++ b/script/helpers.coffee @@ -81,7 +81,18 @@ module.exports = # _id / id handled by Racer stats: { gp: 0, exp: 0, lvl: 1, hp: 50 } invitations: {party:null, guilds: []} - items: { weapon: 0, armor: 0, head: 0, shield: 0, lastDrop: { date: +new Date, count: 0 } } + items: + weapon: 0 + armor: 0 + head: 0 + shield: 0 + lastDrop: { date: +new Date, count: 0 } + eggs: {} + food: {} + hatchingPotions: {} + pets: {} + mounts: {} + preferences: { gender: 'm', skin: 'white', hair: 'blond', armorSet: 'v1', dayStart:0, showHelm: true } apiToken: uuid() # set in newUserObject below lastCron: +new Date #this will be replaced with `+new Date` on first run @@ -274,11 +285,6 @@ module.exports = classes += ' color-best' return classes - ### - Does the user own this pet? - ### - ownsPet: (pet, userPets) -> _.isArray(userPets) and userPets.indexOf(pet) != -1 - ### Friendly timestamp ### diff --git a/script/items.coffee b/script/items.coffee index 19a166d239..68ff955f1e 100644 --- a/script/items.coffee +++ b/script/items.coffee @@ -45,31 +45,45 @@ items = module.exports.items = potion: {type: 'potion', text: "Potion", notes: "Recover 15 HP (Instant Use)", value: 25, classes: 'potion'} 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: 3} - {text: 'Tiger Cub', name: 'TigerCub', value: 3} + eggs: + Wolf: {text: 'Wolf', name: 'Wolf', value: 3} + TigerCub: {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: 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} - ] + PandaCub: {text: 'Panda Cub', name: 'PandaCub', value: 3} + LionCub: {text: 'Lion Cub', name: 'LionCub', value: 3} + Fox: {text: 'Fox', name: 'Fox', value: 3} + FlyingPig: {text: 'Flying Pig', name: 'FlyingPig', value: 3} + Dragon: {text: 'Dragon', name: 'Dragon', value: 3} + Cactus: {text: 'Cactus', name: 'Cactus', value: 3} + BearCub: {text: 'Bear Cub', name: 'BearCub', value: 3} - hatchingPotions: [ - {text: 'Base', 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} - {text: 'Red', name: 'Red', notes: 'Turns your animal into a Red pet.', value: 3} - {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} - ] + hatchingPotions: + Base: {text: 'Base', name: 'Base', notes: "Hatches your pet in it's base form.", value: 1} + White: {text: 'White', name: 'White', notes: 'Turns your animal into a White pet.', value: 2} + Desert: {text: 'Desert', name: 'Desert', notes: 'Turns your animal into a Desert pet.', value: 2} + Red: {text: 'Red', name: 'Red', notes: 'Turns your animal into a Red pet.', value: 3} + Shade: {text: 'Shade', name: 'Shade', notes: 'Turns your animal into a Shade pet.', value: 3} + Skeleton: {text: 'Skeleton', name: 'Skeleton', notes: 'Turns your animal into a Skeleton.', value: 3} + Zombie: {text: 'Zombie', name: 'Zombie', notes: 'Turns your animal into a Zombie.', value: 4} + CottonCandyPink: {text: 'Cotton Candy Pink', name: 'CottonCandyPink', notes: 'Turns your animal into a Cotton Candy Pink pet.', value: 4} + CottonCandyBlue: {text: 'Cotton Candy Blue', name: 'CottonCandyBlue', notes: 'Turns your animal into a Cotton Candy Blue pet.', value: 4} + Golden: {text: 'Golden', name: 'Golden', notes: 'Turns your animal into a Golden pet.', value: 5} + + food: + Meat: {text: 'Meat', name: 'Meat', value: 1, target: 'Base'} + Milk: {text: 'Milk', name: 'Milk', value: 1, target: 'White'} + Potatoe: {text: 'Potatoe', name: 'Potatoe', value: 1, target: 'Desert'} + Strawberry: {text: 'Strawberry', name: 'Strawberry', value: 1, target: 'Red'} + Chocolate: {text: 'Chocolate', name: 'Chocolate', value: 1, target: 'Shade'} + Fish: {text: 'Fish', name: 'Fish', value: 1, target: 'Skeleton'} + RottenMeat: {text: 'Rotten Meat', name: 'RottenMeat', value: 1, target: 'Zombie'} + CottonCandyPink: {text: 'Pink Cotton Candy', name: 'CottonCandyPink', value: 1, target: 'CottonCandyPink'} + CottonCandyBlue: {text: 'Blue Cotton Candy', name: 'CottonCandyBlue', value: 1, target: 'CottonCandyBlue'} + Honey: {text: 'Honey', name: 'Honey', value: 1, target: 'Golden'} + #Cheese: {text: 'Cheese', name: 'Cheese', value: 1, target: 'Golden'} + #Watermelon: {text: 'Watermelon', name: 'Watermelon', value: 1, target: 'Golden'} + #SeaWeed: {text: 'SeaWeed', name: 'SeaWeed', value: 1, target: 'Golden'} + Saddle: {text: 'Saddle', name: 'Saddle', value: 10} # we somtimes want item arrays above in reverse order, for backward lookups (you'll see later in the code) reversed = {} @@ -80,8 +94,9 @@ _.each ['weapon', 'armor', 'head', 'shield'], (type) -> # Also add canOwn(), which we use when comparing if user is a backer or contributor - but defaulted to `return true` _.each items[type], (item) -> _.defaults(item, {type, canOwn: ->true}) -_.each items.pets, (pet) -> pet.notes = 'Find a hatching potion to pour on this egg, and it will hatch into a loyal pet.' +_.each items.eggs, (pet) -> pet.notes = 'Find a hatching potion to pour on this egg, and 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." +_.each items.food, (food) -> food.notes = "Feed this to a pet and it may grown into a sturdy steed." module.exports.buyItem = (user, type) -> nextItem =