From f86a8f78b20137d4f12bd8ba16ab9e393b3e6e9a Mon Sep 17 00:00:00 2001 From: Adrian Klingen Date: Fri, 3 Jan 2025 14:05:42 +0100 Subject: [PATCH] Add previous gear fallback on error --- ui/core/components/suggest_reforges_action.tsx | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/ui/core/components/suggest_reforges_action.tsx b/ui/core/components/suggest_reforges_action.tsx index f3de0edf1e..d4d8d32f7c 100644 --- a/ui/core/components/suggest_reforges_action.tsx +++ b/ui/core/components/suggest_reforges_action.tsx @@ -92,6 +92,7 @@ export class ReforgeOptimizer { readonly freezeItemSlotsChangeEmitter = new TypedEvent(); protected freezeItemSlots = false; protected frozenItemSlots = new Map(); + protected previousGear: Gear | null = null; protected previousReforges = new Map(); protected currentReforges = new Map(); @@ -742,9 +743,9 @@ export class ReforgeOptimizer { console.log('The following slots will not be cleared:'); console.log(Array.from(this.frozenItemSlots.keys()).filter(key => this.frozenItemSlots.get(key))); } - const previousGear = this.player.getGear(); - this.previousReforges = previousGear.getAllReforges(); - const baseGear = previousGear.withoutReforges(this.player.canDualWield2H(), this.frozenItemSlots); + this.previousGear = this.player.getGear(); + this.previousReforges = this.previousGear.getAllReforges(); + const baseGear = this.previousGear.withoutReforges(this.player.canDualWield2H(), this.frozenItemSlots); const baseStats = await this.updateGear(baseGear); // Compute effective stat caps for just the Reforge contribution @@ -916,10 +917,15 @@ export class ReforgeOptimizer { tolerance: 0.01, }; const solution = solve(model, options); + if (isDevMode()) { console.log('LP solution for this iteration:'); console.log(solution); } + + if (solution.status === 'timedout') { + throw solution + } // Apply the current solution const updatedGear = await this.applyLPSolution(gear, solution); @@ -1172,6 +1178,7 @@ export class ReforgeOptimizer { onReforgeError(error: any) { if (isDevMode()) console.log(error); + if (this.previousGear) this.updateGear(this.previousGear); new Toast({ variant: 'error', body: 'Reforge optimization failed. Please try again, or report the issue if it persists.',