Skip to content

Commit 016fc2a

Browse files
author
Chomp
committed
Ensure verifyQuestProductionUnlocks() skips quests that cannot be found in db
1 parent e5067b0 commit 016fc2a

File tree

1 file changed

+21
-16
lines changed

1 file changed

+21
-16
lines changed

project/src/services/ProfileFixerService.ts

+21-16
Original file line numberDiff line numberDiff line change
@@ -280,26 +280,30 @@ export class ProfileFixerService {
280280
const quests = this.databaseService.getQuests();
281281
const profileQuests = pmcProfile.Quests;
282282

283-
for (const profileQuest of profileQuests)
284-
{
283+
for (const profileQuest of profileQuests) {
285284
const quest = quests[profileQuest.qid];
285+
if (!quest) {
286+
continue;
287+
}
286288

287289
// For started or successful quests, check for unlocks in the `Started` rewards
288-
if (profileQuest.status == QuestStatus.Started || profileQuest.status == QuestStatus.Success)
289-
{
290-
const productionRewards = quest.rewards.Started?.filter(reward => reward.type == QuestRewardType.PRODUCTIONS_SCHEME);
291-
productionRewards?.forEach(reward => this.verifyQuestProductionUnlock(pmcProfile, reward, quest));
290+
if (profileQuest.status == QuestStatus.Started || profileQuest.status == QuestStatus.Success) {
291+
const productionRewards = quest.rewards.Started?.filter(
292+
(reward) => reward.type == QuestRewardType.PRODUCTIONS_SCHEME,
293+
);
294+
productionRewards?.forEach((reward) => this.verifyQuestProductionUnlock(pmcProfile, reward, quest));
292295
}
293296

294297
// For successful quests, check for unlocks in the `Success` rewards
295-
if (profileQuest.status == QuestStatus.Success)
296-
{
297-
const productionRewards = quest.rewards.Success?.filter(reward => reward.type == QuestRewardType.PRODUCTIONS_SCHEME);
298-
productionRewards?.forEach(reward => this.verifyQuestProductionUnlock(pmcProfile, reward, quest));
298+
if (profileQuest.status == QuestStatus.Success) {
299+
const productionRewards = quest.rewards.Success?.filter(
300+
(reward) => reward.type == QuestRewardType.PRODUCTIONS_SCHEME,
301+
);
302+
productionRewards?.forEach((reward) => this.verifyQuestProductionUnlock(pmcProfile, reward, quest));
299303
}
300304
}
301305

302-
const validateTime = performance.now() - start
306+
const validateTime = performance.now() - start;
303307
this.logger.debug(`Quest Production Unlock validation took: ${validateTime.toFixed(2)}ms`);
304308
}
305309

@@ -308,12 +312,12 @@ export class ProfileFixerService {
308312
* @param pmcProfile Profile to check
309313
* @param productionUnlockReward The quest reward to validate
310314
* @param questDetails The quest the reward belongs to
311-
* @returns
315+
* @returns
312316
*/
313317
protected verifyQuestProductionUnlock(
314318
pmcProfile: IPmcData,
315319
productionUnlockReward: IQuestReward,
316-
questDetails: IQuest
320+
questDetails: IQuest,
317321
): void {
318322
const matchingProductions = this.questHelper.getRewardProductionMatch(productionUnlockReward, questDetails);
319323
if (matchingProductions.length !== 1) {
@@ -329,10 +333,11 @@ export class ProfileFixerService {
329333

330334
// Add above match to pmc profile
331335
const matchingProductionId = matchingProductions[0]._id;
332-
if (!pmcProfile.UnlockedInfo.unlockedProductionRecipe.includes(matchingProductionId))
333-
{
336+
if (!pmcProfile.UnlockedInfo.unlockedProductionRecipe.includes(matchingProductionId)) {
334337
pmcProfile.UnlockedInfo.unlockedProductionRecipe.push(matchingProductionId);
335-
this.logger.debug(`Added production ${matchingProductionId} to unlocked production recipes for ${questDetails.QuestName}`);
338+
this.logger.debug(
339+
`Added production ${matchingProductionId} to unlocked production recipes for ${questDetails.QuestName}`,
340+
);
336341
}
337342
}
338343

0 commit comments

Comments
 (0)