Skip to content

Commit

Permalink
Enhance EmpoweredWeaponsofNulgath to include retry mechanism for fetc…
Browse files Browse the repository at this point in the history
…hing EmpoweredWep from config
  • Loading branch information
PUNK3DAF committed Nov 9, 2024
1 parent 57a06a7 commit 8c243a7
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions Nation/Various/EmpoweredNationItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public void ScriptMain(IScriptInterface bot)
Core.BankingBlackList.AddRange(Nation.bagDrops);
Core.SetOptions();

GetEmpoweredItem(Bot.Config.Get<EmpoweredItems>("EmpoweredWep"));
GetEmpoweredItem(Bot.Config!.Get<EmpoweredItems>("EmpoweredWep"));

Core.SetOptions(false);
}
Expand All @@ -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<EmpoweredItems>("EmpoweredWep");
// Retry mechanism to get the selected item from config
EmpoweredItems? selectedItem = null;
for (int i = 0; i < 5; i++)
{
selectedItem = Bot.Config?.Get<EmpoweredItems>("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<EmpoweredItems>("EmpoweredWep"))
{
//Empowered Bloodletter 8696
Expand Down

0 comments on commit 8c243a7

Please sign in to comment.