From 25cc01e7cd4e16ff5c91d179a46de913692fbb86 Mon Sep 17 00:00:00 2001 From: Blade Barringer Date: Sat, 4 Jun 2016 12:41:26 -0500 Subject: [PATCH] fix: Supply random value as seed so quest collection is random --- test/api/v3/unit/models/group.test.js | 23 ++++++++++++++++++++++- website/server/models/group.js | 5 +++-- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/test/api/v3/unit/models/group.test.js b/test/api/v3/unit/models/group.test.js index 533dced9a6..93d80878b5 100644 --- a/test/api/v3/unit/models/group.test.js +++ b/test/api/v3/unit/models/group.test.js @@ -379,7 +379,7 @@ describe('Group Model', () => { expect(Group.processCollectionQuest).to.not.be.called; }); - it('calls processCollectionQuest if quest is a boss quest', async () => { + it('calls processCollectionQuest if quest is a collection quest', async () => { party.quest.key = 'evilsanta2'; await party.save(); @@ -608,6 +608,27 @@ describe('Group Model', () => { expect(party.sendChat).to.be.calledWith('`Participating Member found nothing.`'); }); + it('handles collection quests with multiple items', async () => { + progress.collect = 10; + party.quest.key = 'evilsanta2'; + party.quest.active = false; + quest = questScrolls.evilsanta2; + + await party.save(); + await party.startQuest(questLeader); + + await Group.processCollectionQuest({ + user: participatingMember, + progress, + quest, + group: party, + }); + + expect(party.sendChat).to.be.calledOnce; + expect(party.sendChat).to.be.calledWithMatch(/`Participating Member found/);; + expect(party.sendChat).to.be.calledWithMatch(/\d* (Tracks|Broken Twigs)/); + }); + it('sends message about victory', async () => { progress.collect = 500; diff --git a/website/server/models/group.js b/website/server/models/group.js index 678269791c..f11227bf43 100644 --- a/website/server/models/group.js +++ b/website/server/models/group.js @@ -500,7 +500,8 @@ async function processCollectionQuest (options) { let itemsFound = {}; _.times(progress.collect, () => { - let item = shared.fns.randomVal(user, quest.collect, {key: true}); + let item = shared.fns.randomVal(user, quest.collect, {key: true, seed: Math.random()}); + if (!itemsFound[item]) { itemsFound[item] = 0; } @@ -518,7 +519,7 @@ async function processCollectionQuest (options) { group.markModified('quest.progress.collect'); // Still needs completing - if (_.find(shared.content.quests[group.quest.key].collect, (v, k) => { + if (_.find(quest.collect, (v, k) => { return group.quest.progress.collect[k] < v.count; })) return await group.save();