Pulled code out of acceptRepeatableQuest() into new function createAcceptedQuestClientResponse()

This commit is contained in:
Dev 2024-06-03 16:20:16 +01:00
parent 2f21178dc9
commit b010ff87c2

View File

@ -363,8 +363,6 @@ export class QuestController
sessionID: string, sessionID: string,
): IItemEventRouterResponse ): IItemEventRouterResponse
{ {
const acceptQuestResponse = this.eventOutputHolder.getOutput(sessionID);
// Create and store quest status object inside player profile // Create and store quest status object inside player profile
const newRepeatableQuest = this.questHelper.getQuestReadyForProfile( const newRepeatableQuest = this.questHelper.getQuestReadyForProfile(
pmcData, pmcData,
@ -402,16 +400,27 @@ export class QuestController
fullProfile.characters.scav.Quests.push(newRepeatableQuest); fullProfile.characters.scav.Quests.push(newRepeatableQuest);
} }
const repeatableSettings = pmcData.RepeatableQuests.find( const response = this.createAcceptedQuestClientResponse(sessionID, pmcData, repeatableQuestProfile);
(x) => x.name === repeatableQuestProfile.sptRepatableGroupName,
); return response;
}
protected createAcceptedQuestClientResponse(
sessionID: string,
pmcData: IPmcData,
repeatableQuestProfile: IRepeatableQuest): IItemEventRouterResponse
{
const repeatableSettings = pmcData.RepeatableQuests
.find((quest) => quest.name === repeatableQuestProfile.sptRepatableGroupName);
const change = {}; const change = {};
change[repeatableQuestProfile._id] = repeatableSettings.changeRequirement[repeatableQuestProfile._id]; change[repeatableQuestProfile._id] = repeatableSettings!.changeRequirement[repeatableQuestProfile._id];
const responseData: IPmcDataRepeatableQuest = {
const repeatableData: IPmcDataRepeatableQuest = {
id: id:
repeatableSettings.id repeatableSettings.id
?? this.questConfig.repeatableQuests.find((x) => x.name === repeatableQuestProfile.sptRepatableGroupName) ?? this.questConfig.repeatableQuests
.find((repeatableQuest) => repeatableQuest.name === repeatableQuestProfile.sptRepatableGroupName)
.id, .id,
name: repeatableSettings.name, name: repeatableSettings.name,
endTime: repeatableSettings.endTime, endTime: repeatableSettings.endTime,
@ -422,11 +431,15 @@ export class QuestController
freeChangesAvailable: repeatableSettings.freeChangesAvailable, freeChangesAvailable: repeatableSettings.freeChangesAvailable,
}; };
// Nullguard
const acceptQuestResponse = this.eventOutputHolder.getOutput(sessionID);
if (!acceptQuestResponse.profileChanges[sessionID].repeatableQuests) if (!acceptQuestResponse.profileChanges[sessionID].repeatableQuests)
{ {
acceptQuestResponse.profileChanges[sessionID].repeatableQuests = []; acceptQuestResponse.profileChanges[sessionID].repeatableQuests = [];
} }
acceptQuestResponse.profileChanges[sessionID].repeatableQuests.push(responseData);
// Add constructed objet into response
acceptQuestResponse.profileChanges[sessionID].repeatableQuests.push(repeatableData);
return acceptQuestResponse; return acceptQuestResponse;
} }