Skip to content

Commit 946cf10

Browse files
author
Chomp
committedNov 24, 2024·
Second pass at ensuring failed quests let player pick items up in raid
Now checks if multiple quests match requirements, fails when >1
1 parent 7ba772d commit 946cf10

File tree

1 file changed

+29
-17
lines changed

1 file changed

+29
-17
lines changed
 

‎project/src/services/LocationLifecycleService.ts

+29-17
Original file line numberDiff line numberDiff line change
@@ -733,41 +733,53 @@ export class LocationLifecycleService {
733733
) {
734734
// Exclude completed quests
735735
const activeQuestIdsInProfile = profileQuests
736-
.filter((quest) => quest.status !== QuestStatus.Success)
736+
.filter((quest) => ![QuestStatus.Success, QuestStatus.AvailableForStart].includes(quest.status))
737737
.map((status) => status.qid);
738738

739739
// Get db details of quests we found above
740-
const questDb = Object.values(this.databaseService.getQuests()).filter((x) =>
741-
activeQuestIdsInProfile.includes(x._id),
740+
const questDb = Object.values(this.databaseService.getQuests()).filter((quest) =>
741+
activeQuestIdsInProfile.includes(quest._id),
742742
);
743743

744744
for (const lostItem of lostQuestItems) {
745-
for (const quest of questDb) {
746-
// Find a quest in the db that has the lost item in one of its conditions that is also a 'find' type of condition
745+
let matchingConditionId: string;
746+
// Find a quest that has a FindItem condition that has the list items tpl as a target
747+
const matchingQuests = questDb.filter((quest) => {
747748
const matchingCondition = quest.conditions.AvailableForFinish.find(
748749
(questCondition) =>
749750
questCondition.conditionType === "FindItem" && questCondition.target.includes(lostItem._tpl),
750751
);
751752
if (!matchingCondition) {
752753
// Quest doesnt have a matching condition
753-
continue;
754+
return false;
754755
}
755756

756-
// We have a match, remove the condition id from profile to reset progress and let player pick item up again
757-
const profileQuestToUpdate = profileQuests.find((questStatus) => questStatus.qid === quest._id);
758-
if (!profileQuestToUpdate) {
759-
// Profile doesnt have a matching quest
760-
continue;
761-
}
757+
// We found a condition, save id for later
758+
matchingConditionId = matchingCondition.id;
759+
return true;
760+
});
762761

763-
// Filter out the matching condition we found
764-
profileQuestToUpdate.completedConditions = profileQuestToUpdate.completedConditions.filter(
765-
(conditionId) => conditionId !== matchingCondition.id,
762+
// Fail if multiple were found
763+
if (matchingQuests.length !== 1) {
764+
this.logger.error(
765+
`Unable to fix quest item: ${lostItem}, ${matchingQuests.length} matching quests found, expected 1`,
766766
);
767767

768-
// We found and updated the relevant quest, no more work to do with this lost item
769-
break;
768+
continue;
770769
}
770+
771+
const matchingQuest = matchingQuests[0];
772+
// We have a match, remove the condition id from profile to reset progress and let player pick item up again
773+
const profileQuestToUpdate = profileQuests.find((questStatus) => questStatus.qid === matchingQuest._id);
774+
if (!profileQuestToUpdate) {
775+
// Profile doesnt have a matching quest
776+
continue;
777+
}
778+
779+
// Filter out the matching condition we found
780+
profileQuestToUpdate.completedConditions = profileQuestToUpdate.completedConditions.filter(
781+
(conditionId) => conditionId !== matchingConditionId,
782+
);
771783
}
772784
}
773785

0 commit comments

Comments
 (0)
Please sign in to comment.