From 8c243a72ca321b9488c37ce7790548cca90c332f Mon Sep 17 00:00:00 2001 From: Vld Mrk Date: Sat, 9 Nov 2024 16:39:59 +0100 Subject: [PATCH] Enhance EmpoweredWeaponsofNulgath to include retry mechanism for fetching EmpoweredWep from config --- Nation/Various/EmpoweredNationItem.cs | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/Nation/Various/EmpoweredNationItem.cs b/Nation/Various/EmpoweredNationItem.cs index eb0efdc22..898ecfb69 100644 --- a/Nation/Various/EmpoweredNationItem.cs +++ b/Nation/Various/EmpoweredNationItem.cs @@ -31,7 +31,7 @@ public void ScriptMain(IScriptInterface bot) Core.BankingBlackList.AddRange(Nation.bagDrops); Core.SetOptions(); - GetEmpoweredItem(Bot.Config.Get("EmpoweredWep")); + GetEmpoweredItem(Bot.Config!.Get("EmpoweredWep")); Core.SetOptions(false); } @@ -53,19 +53,35 @@ public void GetEmpoweredItem(EmpoweredItems Item) foreach (EmpoweredItems item in (EmpoweredItems[])Enum.GetValues(typeof(EmpoweredItems))) { - // Get the selected item from config - EmpoweredItems? selectedItem = Bot.Config?.Get("EmpoweredWep"); + // Retry mechanism to get the selected item from config + EmpoweredItems? selectedItem = null; + for (int i = 0; i < 5; i++) + { + selectedItem = Bot.Config?.Get("EmpoweredWep"); + if (selectedItem != null) + break; + Core.Logger($"Attempt {i + 1}: EmpoweredWep not found in config. Retrying..."); + Core.Sleep(1000); // Wait for 1 second before retrying + } // Ensure we have a valid item selection from the config if (selectedItem == null) + { + Core.Logger("EmpoweredWep not found in config after 5 attempts."); continue; + } // Convert the enum value to a string for checking in the inventory - string itemName = selectedItem.ToString().Replace('_', ' '); + string? itemName = selectedItem?.ToString()?.Replace('_', ' '); + + if (string.IsNullOrEmpty(itemName)) + { + Core.Logger("Item name is null or empty after conversion."); + continue; + } if (Core.CheckInventory(itemName, toInv: false)) return; - switch (Bot.Config?.Get("EmpoweredWep")) { //Empowered Bloodletter 8696