From 9e056cf8f349c0c9a14f87181cc5ff0c1d269b04 Mon Sep 17 00:00:00 2001 From: Dev Date: Tue, 25 Jul 2023 19:50:46 +0100 Subject: [PATCH] Handle failing quests post-raid if they are now failed and were not pre-raid --- project/src/helpers/InRaidHelper.ts | 40 ++++++++++++++++++++++++++++- project/src/helpers/QuestHelper.ts | 7 ++++- 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/project/src/helpers/InRaidHelper.ts b/project/src/helpers/InRaidHelper.ts index 09d13d83..cc9323c7 100644 --- a/project/src/helpers/InRaidHelper.ts +++ b/project/src/helpers/InRaidHelper.ts @@ -1,10 +1,12 @@ import { inject, injectable } from "tsyringe"; import { IPmcData } from "../models/eft/common/IPmcData"; -import { Victim } from "../models/eft/common/tables/IBotBase"; +import { Quest, Victim } from "../models/eft/common/tables/IBotBase"; import { Item } from "../models/eft/common/tables/IItem"; import { ISaveProgressRequestData } from "../models/eft/inRaid/ISaveProgressRequestData"; +import { IFailQuestRequestData } from "../models/eft/quests/IFailQuestRequestData"; import { ConfigTypes } from "../models/enums/ConfigTypes"; +import { QuestStatus } from "../models/enums/QuestStatus"; import { ILostOnDeathConfig } from "../models/spt/config/ILostOnDeathConfig"; import { ILogger } from "../models/spt/utils/ILogger"; import { ConfigServer } from "../servers/ConfigServer"; @@ -16,6 +18,7 @@ import { JsonUtil } from "../utils/JsonUtil"; import { InventoryHelper } from "./InventoryHelper"; import { ItemHelper } from "./ItemHelper"; import { PaymentHelper } from "./PaymentHelper"; +import { QuestHelper } from "./QuestHelper"; @injectable() export class InRaidHelper @@ -29,6 +32,7 @@ export class InRaidHelper @inject("ItemHelper") protected itemHelper: ItemHelper, @inject("DatabaseServer") protected databaseServer: DatabaseServer, @inject("InventoryHelper") protected inventoryHelper: InventoryHelper, + @inject("QuestHelper") protected questHelper: QuestHelper, @inject("PaymentHelper") protected paymentHelper: PaymentHelper, @inject("LocalisationService") protected localisationService: LocalisationService, @inject("ProfileFixerService") protected profileFixerService: ProfileFixerService, @@ -134,6 +138,8 @@ export class InRaidHelper profileData.Stats = saveProgressRequest.profile.Stats; profileData.Encyclopedia = saveProgressRequest.profile.Encyclopedia; profileData.ConditionCounters = saveProgressRequest.profile.ConditionCounters; + + this.processFailedQuests(sessionID, profileData, profileData.Quests, saveProgressRequest.profile.Quests); profileData.Quests = saveProgressRequest.profile.Quests; // Transfer effects from request to profile @@ -158,6 +164,38 @@ export class InRaidHelper return profileData; } + /** + * + * @param sessionId Player id + * @param pmcData Player profile + * @param preRaidQuests Quests prior to starting raid + * @param postRaidQuests Quest after raid + */ + protected processFailedQuests(sessionId: string, pmcData: IPmcData, preRaidQuests: Quest[], postRaidQuests: Quest[]): void + { + // Loop over all quests from post-raid profile + for (const postRaidQuest of postRaidQuests) + { + // Find matching pre-raid quest + const preRaidQuest = preRaidQuests.find(x => x.qid === postRaidQuest.qid); + if (preRaidQuest) + { + // post-raid quest is failed but wasn't pre-raid + if (postRaidQuest.status === QuestStatus.Fail && preRaidQuest.status !== QuestStatus.Fail) + { + // Send failed message + const failBody: IFailQuestRequestData = { + Action: "QuestComplete", + qid: postRaidQuest.qid, + removeExcessItems: true + }; + this.questHelper.failQuest(pmcData, failBody, sessionId); + } + } + + } + } + protected resetSkillPointsEarnedDuringRaid(profile: IPmcData): void { for (const skill of profile.Skills.Common) diff --git a/project/src/helpers/QuestHelper.ts b/project/src/helpers/QuestHelper.ts index 26391c17..eff71480 100644 --- a/project/src/helpers/QuestHelper.ts +++ b/project/src/helpers/QuestHelper.ts @@ -370,7 +370,7 @@ export class QuestHelper * Get quests that can be shown to player after failing a quest * @param failedQuestId Id of the quest failed by player * @param sessionId Session id - * @returns + * @returns IQuest array */ public failedUnlocked(failedQuestId: string, sessionId: string): IQuest[] { @@ -395,6 +395,11 @@ export class QuestHelper return profileQuest && (profileQuest.status === QuestStatus.Fail); }); + if (quests.length === 0) + { + return quests; + } + return this.getQuestsWithOnlyLevelRequirementStartCondition(quests); }