mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-19 15:48:04 +01:00
fix: Supply random value as seed so quest collection is random
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user