Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed pickup & filtering #60

Merged
merged 1 commit into from
Mar 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Application/RSBot/Views/SplashScreen.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using RSBot.Core;
using RSBot.Core.Components;
using RSBot.Theme.Controls;
using System;
using System.IO;
Expand Down
91 changes: 50 additions & 41 deletions Library/RSBot.Core/Components/PickupManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,59 +76,68 @@ public static void Run(Position centerPosition, int radius = 50)
return;

Running = true;
var playerJid = Game.Player.JID;

bool condition(SpawnedItem e)
{
var tolarance = 15;
var isInside = e.Movement.Source.DistanceTo(centerPosition) <= radius + tolarance;
var selfish = JustPickMyItems && e.OwnerJID == playerJid;

return isInside && (selfish || !JustPickMyItems);
}

if (!SpawnManager.TryGetEntities<SpawnedItem>(out var entites, p => condition(p)))
{
Stop();
return;
}

foreach (var item in entites.OrderBy(item => item.Movement.Source.DistanceTo(centerPosition)).Take(5))
try
{
if (!Running)
return;
var playerJid = Game.Player.JID;

if (PickupGold && item.Record.IsGold)
bool condition(SpawnedItem e)
{
if (UseAbilityPet && Game.Player.HasActiveAbilityPet)
Game.Player.AbilityPet.Pickup(item.UniqueId);
else
item.Pickup();
var tolarance = 15;
var isInside = e.Movement.Source.DistanceTo(centerPosition) <= radius + tolarance;
var selfish = JustPickMyItems && e.OwnerJID == playerJid;

continue;
return isInside && (selfish || !JustPickMyItems);
}

//Pickup regular items
if (PickupFilter.Invoke(item.Record))
if (!SpawnManager.TryGetEntities<SpawnedItem>(out var entites, p => condition(p)))
{
if (UseAbilityPet && Game.Player.HasActiveAbilityPet && !Game.Player.AbilityPet.Full)
Game.Player.AbilityPet.Pickup(item.UniqueId);
else
item.Pickup();

continue;
Stop();
return;
}

if (PickupRareItems && (byte)item.Rarity >= 2)
foreach (var item in entites.OrderBy(item => item.Movement.Source.DistanceTo(centerPosition)).Take(5))
{
if (UseAbilityPet && Game.Player.HasActiveAbilityPet && !Game.Player.AbilityPet.Full)
Game.Player.AbilityPet.Pickup(item.UniqueId);
else
item.Pickup();
if (!Running)
return;

if (PickupGold && item.Record.IsGold)
{
if (UseAbilityPet && Game.Player.HasActiveAbilityPet)
Game.Player.AbilityPet.Pickup(item.UniqueId);
else
item.Pickup();

continue;
}

//Pickup regular items
if (PickupFilter.Invoke(item.Record))
{
if (UseAbilityPet && Game.Player.HasActiveAbilityPet && !Game.Player.AbilityPet.Full)
Game.Player.AbilityPet.Pickup(item.UniqueId);
else
item.Pickup();

continue;
}

if (PickupRareItems && (byte)item.Rarity >= 2)
{
if (UseAbilityPet && Game.Player.HasActiveAbilityPet && !Game.Player.AbilityPet.Full)
Game.Player.AbilityPet.Pickup(item.UniqueId);
else
item.Pickup();
}
}
}

Running = false;
catch (System.Exception e)
{
Log.Fatal(e);
}
finally
{
Running = false;
}
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion Library/RSBot.Core/Components/SpawnManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public static bool TryGetEntities<T>(out IEnumerable<T> entities, Func<T, bool>
{
lock (_lock)
{
entities = _entities.Cast<T>().Where(p => predicate(p));
entities = _entities.FindAll(p => p is T && predicate(p as T)).Cast<T>();

return entities != null;
}
Expand Down
2 changes: 2 additions & 0 deletions Library/RSBot.Core/Log.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ public static void AppendFormat(LogLevel logLevel, string format, params object[
/// <param name="obj">The message</param>
public static void Fatal(Exception obj)
{
Warn(obj.Message);

var filePath = Path.Combine(Environment.CurrentDirectory, "User", "Logs", "Exceptions", $"{DateTime.Now:dd-MM-yyyy}.txt");
if (!Directory.Exists(filePath))
Directory.CreateDirectory(Path.GetDirectoryName(filePath));
Expand Down