Collection quest progress reports "found no [item names]" fixes #7816 (#7883)

* Updated collection quest tests for no found items.

Single-item quests state [user] found no [items]. instead of [user] found nothing. If a
quest has two items, the chat message is [user] found no [item1] and no [item2].

* Collection quest messages changed from [user] found nothing to [user] found no [item]

* Tests for no collection quest items found changed to [user] found 0 [item1], 0 [item2]

* Changed chat messages for no found collection quest items to [user] found 0 [item1], 0 [item2]

* Sort items alphabetically in multi-item quests so that it always returns the same string

* Formatting updates to conform to test specifications (for collection quest progress reports with no items found

* Simplified handling of items not found: any items not found are added to the list of found items with quantity 0 for reporting in the group chat. This also causes all items to appear, in the list, even if only one type is found in a multi-item quest.

* Test the group chat message when no items are found in multi-item quests. Test succes no longer depends on the order items are listed.
This commit is contained in:
Alyssa Batula
2016-09-11 00:03:28 -04:00
committed by Blade Barringer
parent b8878df6bd
commit 923b6c495e
2 changed files with 28 additions and 2 deletions

View File

@@ -350,7 +350,25 @@ describe('Group Model', () => {
party = await Group.findOne({_id: party._id}); party = await Group.findOne({_id: party._id});
expect(Group.prototype.sendChat).to.be.calledOnce; expect(Group.prototype.sendChat).to.be.calledOnce;
expect(Group.prototype.sendChat).to.be.calledWith('`Participating Member found nothing.`'); expect(Group.prototype.sendChat).to.be.calledWith('`Participating Member found 0 Bars of Soap.`');
});
it('sends a chat message if no progress is made on quest with multiple items', async () => {
progress.collectedItems = 0;
party.quest.key = 'dilatoryDistress1';
party.quest.active = false;
await party.startQuest(questLeader);
await party.save();
await Group.processQuestProgress(participatingMember, progress);
party = await Group.findOne({_id: party._id});
expect(Group.prototype.sendChat).to.be.calledOnce;
expect(Group.prototype.sendChat).to.be.calledWithMatch(/`Participating Member found/);
expect(Group.prototype.sendChat).to.be.calledWithMatch(/0 Blue Fins/);
expect(Group.prototype.sendChat).to.be.calledWithMatch(/0 Fire Coral/);
}); });
it('handles collection quests with multiple items', async () => { it('handles collection quests with multiple items', async () => {

View File

@@ -607,12 +607,20 @@ schema.methods._processCollectionQuest = async function processCollectionQuest (
group.quest.progress.collect[item]++; group.quest.progress.collect[item]++;
}); });
// Add 0 for all items not found
let questItems = Object.keys(this.quest.progress.collect);
for (let i = 0; i < questItems.length; i++) {
if (!itemsFound[questItems[i]]) {
itemsFound[questItems[i]] = 0;
}
}
let foundText = _.reduce(itemsFound, (m, v, k) => { let foundText = _.reduce(itemsFound, (m, v, k) => {
m.push(`${v} ${quest.collect[k].text('en')}`); m.push(`${v} ${quest.collect[k].text('en')}`);
return m; return m;
}, []); }, []);
foundText = foundText.length > 0 ? foundText.join(', ') : 'nothing'; foundText = foundText.join(', ');
group.sendChat(`\`${user.profile.name} found ${foundText}.\``); group.sendChat(`\`${user.profile.name} found ${foundText}.\``);
group.markModified('quest.progress.collect'); group.markModified('quest.progress.collect');