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`);
}
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 (!questStage) {
const questStageIndex =
quest.Progress.push({
c: questStageUpdate.c ?? 0,
i: questStageUpdate.i ?? false,
m: questStageUpdate.m ?? false,
b: questStageUpdate.b ?? []
}) - 1;
if (questStageIndex !== ChainStage) {
throw new Error(`Quest stage index mismatch: ${questStageIndex} !== ${ChainStage}`);
}
return;
if (ChainStage == quest.Progress.length) {
logger.debug(`pushing to quest progress in updateQuestStage`);
quest.Progress.push({
c: 0,
i: false,
m: false,
b: []
});
} else if (ChainStage >= quest.Progress.length) {
throw new Error(
`Quest stage index mismatch: stage is ${ChainStage} but array size is ${quest.Progress.length}`
);
}
const questStage = quest.Progress[ChainStage]; // guaranteed in-bounds now
for (const [key, value] of Object.entries(questStageUpdate) as [keyof IQuestStage, number | boolean | any[]][]) {
(questStage[key] as any) = value;