feat(quests): allow quests to drop multiple items

This commit is contained in:
Tyler Renelle
2014-01-21 13:13:15 -08:00
parent f71d6957e8
commit d9e5725ee1
2 changed files with 22 additions and 19 deletions
+20 -19
View File
@@ -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
+2
View File
@@ -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);