fix: avoid pushing to quest progress in updateQuestStage

This commit is contained in:
Sainan 2025-10-05 17:50:35 +02:00
parent 1ecf53c96b
commit 90da0e5326

View File

@ -68,22 +68,22 @@ export const updateQuestStage = (
throw new Error(`Progress should always exist when giving keychain triggered items or messages`); throw new Error(`Progress should always exist when giving keychain triggered items or messages`);
} }
const questStage = quest.Progress[ChainStage]; ChainStage -= 1; // They are 1-indexed in the client, but we need 0-indexing
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition if (ChainStage == quest.Progress.length) {
if (!questStage) { logger.debug(`pushing to quest progress in updateQuestStage`);
const questStageIndex = quest.Progress.push({
quest.Progress.push({ c: 0,
c: questStageUpdate.c ?? 0, i: false,
i: questStageUpdate.i ?? false, m: false,
m: questStageUpdate.m ?? false, b: []
b: questStageUpdate.b ?? [] });
}) - 1; } else if (ChainStage >= quest.Progress.length) {
if (questStageIndex !== ChainStage) { throw new Error(
throw new Error(`Quest stage index mismatch: ${questStageIndex} !== ${ChainStage}`); `Quest stage index mismatch: stage is ${ChainStage} but array size is ${quest.Progress.length}`
} );
return;
} }
const questStage = quest.Progress[ChainStage]; // guaranteed in-bounds now
for (const [key, value] of Object.entries(questStageUpdate) as [keyof IQuestStage, number | boolean | any[]][]) { for (const [key, value] of Object.entries(questStageUpdate) as [keyof IQuestStage, number | boolean | any[]][]) {
(questStage[key] as any) = value; (questStage[key] as any) = value;