Skip to content

Commit

Permalink
Update CoreBots.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
wtffidy committed Nov 5, 2024
1 parent 194fdb4 commit fde9111
Showing 1 changed file with 35 additions and 17 deletions.
52 changes: 35 additions & 17 deletions CoreBots.cs
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,10 @@ void modifyPacket(dynamic packet)
else Bot.Send.Packet($"%xt%zm%cmd%1%tfer%{Username()}%{_stopLoc}-{PrivateRoomNumber}%");

if (EquipmentBeforeBot.Any())
{
JumpWait();
Equip(EquipmentBeforeBot.ToArray());
}
}
}

Expand Down Expand Up @@ -1318,33 +1321,41 @@ public void SellItem(string itemName, int quant = 0, bool all = false)
{
if (!(quant > 0 ? CheckInventory(itemName, quant) : CheckInventory(itemName)) || !Bot.Inventory.TryGetItem(itemName, out InventoryItem? item))
return;

ItemBase Item = Bot.Inventory.Items.Concat(Bot.Bank.Items).FirstOrDefault(x => x != null && x.Name == itemName);
if (Bot.Bank.Contains(itemName) && !Bot.Inventory.Contains(itemName))
Unbank(itemName);

int retryCount = 0;
int sell_count = all ? Bot.Inventory.GetQuantity(itemName) : quant;
Retry:
while (!Bot.ShouldExit && Bot.Player.InCombat)
{
JumpWait();
Sleep();
if (!Bot.Player.InCombat)
break;
}

if (!all)
{
// Inv quant >= current quantity.
if (Bot.Options.SafeTimings)
Bot.Wait.ForActionCooldown(GameActions.SellItem);
Bot.Wait.ForActionCooldown(GameActions.SellItem);
Bot.Send.Packet($"%xt%zm%sellItem%{Bot.Map.RoomID}%{item!.ID}%{item!.Quantity - quant}%{item!.CharItemID}%");
if (Bot.Options.SafeTimings)
Bot.Wait.ForItemSell();

Bot.Wait.ForItemSell();
Sleep();
return;
}
else
{
Bot.Shops.SellItem(itemName);
Bot.Wait.ForItemSell();
}

if (!Bot.Inventory.Contains(itemName) && !Bot.Bank.Contains(itemName))
Logger($"{(all ? string.Empty : quant.ToString())} {itemName} sold");
{
Logger($"Sold x{sell_count} \"{itemName}\"");
return;
}
else
{
if (retryCount < 5)
Expand All @@ -1355,6 +1366,7 @@ public void SellItem(string itemName, int quant = 0, bool all = false)
}
else
{
Logger($"{itemName} failed to sell, retrying x{retryCount} times did not succeed");
retryCount = 0;
return;
}
Expand Down Expand Up @@ -2186,7 +2198,10 @@ public int EnsureCompleteMulti(int questID, int amount = -1, int itemID = -1)
//idk why but it wants `var` not `Quest`.. and it just works :|
Quest quest = EnsureLoad(questID);

EnsureAccept(quest.ID);
if (!Bot.Lite.ReacceptQuest || quest != null && !Bot.Quests.Active.Contains(quest))
EnsureAccept(questID);
else Bot.Wait.ForTrue(() => Bot.Quests.IsInProgress(questID), 20);

int turnIns;

string[] requiredItemNames =
Expand All @@ -2199,7 +2214,7 @@ public int EnsureCompleteMulti(int questID, int amount = -1, int itemID = -1)
}
else
{
int possibleTurnin = Bot.Flash.CallGameFunction<int>("world.maximumQuestTurnIns", quest.ID);
int possibleTurnin = Bot.Flash.CallGameFunction<int>("world.maximumQuestTurnIns", questID);
turnIns = possibleTurnin > amount && amount > 0 ? amount : possibleTurnin;
if (turnIns == 0)
{
Expand All @@ -2208,15 +2223,15 @@ public int EnsureCompleteMulti(int questID, int amount = -1, int itemID = -1)
}

// Ensure quest is loaded, and is entirely completable.
if (EnsureAccept(quest.ID) && CheckInventory(requiredItemNames))
if (EnsureAccept(questID) && CheckInventory(requiredItemNames))
{
Bot.Flash.CallGameFunction("world.tryQuestComplete", quest.ID, itemID, false, turnIns);
Bot.Flash.CallGameFunction("world.tryQuestComplete", questID, itemID, false, turnIns);
}

Bot.Wait.ForQuestComplete(quest.ID);
Bot.Wait.ForQuestAccept(quest.ID);
Bot.Wait.ForQuestComplete(questID);
Bot.Wait.ForQuestAccept(questID);

return !Bot.Quests.IsInProgress(quest.ID) ? turnIns : 0;
return !Bot.Quests.IsInProgress(questID) ? turnIns : 0;
}


Expand Down Expand Up @@ -2901,7 +2916,9 @@ public void HuntMonsterMapID(string map, int monsterMapID, string? item = null,
if (isTemp ? Bot.TempInv.Contains(item, quant) : CheckInventory(item, quant))
break;
}
Rest();
if (Bot.Options.RestPackets)
Rest();
Bot.Wait.ForPickup(item);
}
}

Expand Down Expand Up @@ -6010,15 +6027,16 @@ public void AuraHandling(string? targetAuraName)

default:
break;

}
}
}

public void UsePotion()
{
var skill = Bot.Flash.GetArrayObject<dynamic>("world.actions.active", 5);
if (skill == null) return;
Bot.Flash.CallGameFunction("world.testAction", JsonConvert.DeserializeObject<ExpandoObject>(JsonConvert.SerializeObject(skill))!);
if (!Bot.Player.Alive || skill == null) return;
Bot.Flash.CallGameFunction("world.testAction", JsonConvert.DeserializeObject<ExpandoObject>(JsonConvert.SerializeObject(skill)));
}

private void ShutdownSkua() // law asked for this. - not to be used publicly.
Expand Down

0 comments on commit fde9111

Please sign in to comment.