From 091e4fa41b25c12059c863d57967c34927c13a94 Mon Sep 17 00:00:00 2001 From: CWXDEV Date: Fri, 12 Jan 2024 23:44:58 +0000 Subject: [PATCH] added check to make sure same item isnt used, still has an edge case, if maxRequestedAmount is too high, and we cant offer enough items, dupes will appear, but this will fix normal use --- project/src/generators/RepeatableQuestGenerator.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/project/src/generators/RepeatableQuestGenerator.ts b/project/src/generators/RepeatableQuestGenerator.ts index 76c03747..7322d549 100644 --- a/project/src/generators/RepeatableQuestGenerator.ts +++ b/project/src/generators/RepeatableQuestGenerator.ts @@ -559,9 +559,19 @@ export class RepeatableQuestGenerator // Draw items to ask player to retrieve let isAmmo = 0 + const randomNumbersUsed = []; for (let i = 0; i < distinctItemsToRetrieveCount; i++) { - const itemSelected = itemSelection[this.randomUtil.randInt(itemSelection.length)]; + let randomNumber = this.randomUtil.randInt(itemSelection.length); + + while (randomNumbersUsed.includes(randomNumber) && randomNumbersUsed.length !== itemSelection.length) + { + randomNumber = this.randomUtil.randInt(itemSelection.length); + } + + randomNumbersUsed.push(randomNumber); + + const itemSelected = itemSelection[randomNumber]; const itemUnitPrice = this.itemHelper.getItemPrice(itemSelected[0]); let minValue = completionConfig.minRequestedAmount; let maxValue = completionConfig.maxRequestedAmount;