0
0
mirror of https://github.com/sp-tarkov/server.git synced 2025-02-13 01:30:44 -05:00

Second pass at ensuring failed quests let player pick items up in raid

Now checks if multiple quests match requirements, fails when >1
This commit is contained in:
Chomp 2024-11-24 17:00:10 +00:00
parent 7ba772d458
commit 946cf10659

View File

@ -733,28 +733,44 @@ export class LocationLifecycleService {
) { ) {
// Exclude completed quests // Exclude completed quests
const activeQuestIdsInProfile = profileQuests const activeQuestIdsInProfile = profileQuests
.filter((quest) => quest.status !== QuestStatus.Success) .filter((quest) => ![QuestStatus.Success, QuestStatus.AvailableForStart].includes(quest.status))
.map((status) => status.qid); .map((status) => status.qid);
// Get db details of quests we found above // Get db details of quests we found above
const questDb = Object.values(this.databaseService.getQuests()).filter((x) => const questDb = Object.values(this.databaseService.getQuests()).filter((quest) =>
activeQuestIdsInProfile.includes(x._id), activeQuestIdsInProfile.includes(quest._id),
); );
for (const lostItem of lostQuestItems) { for (const lostItem of lostQuestItems) {
for (const quest of questDb) { let matchingConditionId: string;
// Find a quest in the db that has the lost item in one of its conditions that is also a 'find' type of condition // Find a quest that has a FindItem condition that has the list items tpl as a target
const matchingQuests = questDb.filter((quest) => {
const matchingCondition = quest.conditions.AvailableForFinish.find( const matchingCondition = quest.conditions.AvailableForFinish.find(
(questCondition) => (questCondition) =>
questCondition.conditionType === "FindItem" && questCondition.target.includes(lostItem._tpl), questCondition.conditionType === "FindItem" && questCondition.target.includes(lostItem._tpl),
); );
if (!matchingCondition) { if (!matchingCondition) {
// Quest doesnt have a matching condition // Quest doesnt have a matching condition
return false;
}
// We found a condition, save id for later
matchingConditionId = matchingCondition.id;
return true;
});
// Fail if multiple were found
if (matchingQuests.length !== 1) {
this.logger.error(
`Unable to fix quest item: ${lostItem}, ${matchingQuests.length} matching quests found, expected 1`,
);
continue; continue;
} }
const matchingQuest = matchingQuests[0];
// We have a match, remove the condition id from profile to reset progress and let player pick item up again // We have a match, remove the condition id from profile to reset progress and let player pick item up again
const profileQuestToUpdate = profileQuests.find((questStatus) => questStatus.qid === quest._id); const profileQuestToUpdate = profileQuests.find((questStatus) => questStatus.qid === matchingQuest._id);
if (!profileQuestToUpdate) { if (!profileQuestToUpdate) {
// Profile doesnt have a matching quest // Profile doesnt have a matching quest
continue; continue;
@ -762,12 +778,8 @@ export class LocationLifecycleService {
// Filter out the matching condition we found // Filter out the matching condition we found
profileQuestToUpdate.completedConditions = profileQuestToUpdate.completedConditions.filter( profileQuestToUpdate.completedConditions = profileQuestToUpdate.completedConditions.filter(
(conditionId) => conditionId !== matchingCondition.id, (conditionId) => conditionId !== matchingConditionId,
); );
// We found and updated the relevant quest, no more work to do with this lost item
break;
}
} }
} }