WIP: fix: avoid pushing to quest progress in updateQuestStage #2847
@ -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;
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user