From d9e5725ee13f7e9ad329fc548537d5265cf483ca Mon Sep 17 00:00:00 2001 From: Tyler Renelle Date: Tue, 21 Jan 2014 13:13:15 -0800 Subject: [PATCH] feat(quests): allow quests to drop multiple items --- src/models/group.js | 39 ++++++++++++++++++++------------------- test/api.mocha.js | 2 ++ 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/src/models/group.js b/src/models/group.js index e15a14ac1d..385e78cb78 100644 --- a/src/models/group.js +++ b/src/models/group.js @@ -129,9 +129,7 @@ GroupSchema.statics.cleanQuestProgress = cleanQuestProgress; // Participants: Grant rewards & achievements, finish quest GroupSchema.methods.finishQuest = function(quest, cb) { var group = this; - var questK = quest.key; - var dropK = quest.drop.key; var updates = {$inc:{},$set:{}}; updates['$inc']['achievements.quests.' + questK] = 1; @@ -140,23 +138,26 @@ GroupSchema.methods.finishQuest = function(quest, cb) { updates['$inc']['_v'] = 1; updates['$set']['party.quest'] = cleanQuestProgress({completed:questK}); - switch (quest.drop.type) { - case 'gear': - // TODO This means they can lose their new gear on death, is that what we want? - updates['$set']['items.gear.owned.'+dropK] = true; - break; - case 'eggs': - case 'food': - case 'hatchingPotions': - updates['$inc']['items.'+quest.drop.type+'.'+dropK] = 1; - break; - case 'pets': - updates['$set']['items.pets.'+dropK] = 5; - break; - case 'mounts': - updates['$set']['items.mounts.'+dropK] = true; - break; - } + _.each(quest.drop.items, function(item){ + var dropK = item.key; + switch (item.type) { + case 'gear': + // TODO This means they can lose their new gear on death, is that what we want? + updates['$set']['items.gear.owned.'+dropK] = true; + break; + case 'eggs': + case 'food': + case 'hatchingPotions': + updates['$inc']['items.'+quest.drop.type+'.'+dropK] = 1; + break; + case 'pets': + updates['$set']['items.pets.'+dropK] = 5; + break; + case 'mounts': + updates['$set']['items.mounts.'+dropK] = true; + break; + } + }) var members = _.keys(group.quest.members); group.quest = {};group.markModified('quest'); // FIXME this is TERRIBLE practice. Looks like there are circular dependencies in the models, such that `var User` at diff --git a/test/api.mocha.js b/test/api.mocha.js index 4ce92247aa..ffc1757a3a 100644 --- a/test/api.mocha.js +++ b/test/api.mocha.js @@ -436,6 +436,8 @@ describe('API', function () { function(_group,cb){ expect(_group.quest.key).to.not.be.ok(); expect(user.items.mounts['BearCub-Polar']).to.be(true); + expect(user.stats.exp).to.be.above(shared.content.quests.evilsanta.drop.exp); + expect(user.stats.gp).to.be.above(shared.content.quests.evilsanta.drop.gp); cb(); } ],done);