Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
SDClowen committed Mar 20, 2023
2 parents 9dae574 + 179ccb9 commit 8d13196
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 53 deletions.
3 changes: 3 additions & 0 deletions Botbases/RSBot.Default/Bot/Botbase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ public void Tick()

var noAttack = PlayerConfig.Get("RSBot.Skills.NoAttack", false);

//Check for protection
Bundles.Protection.Invoke();

//Cast buffs
Bundles.Buff.Invoke();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ public void Invoke()
if (skill == null || skill.HasCooldown)
continue;

skill.Cast(member.Player.UniqueId, buff: true);
if (member.Player != null)
skill.Cast(member.Player.UniqueId, buff: true);
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions Library/RSBot.Core/Components/PickupManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ public static void RunPlayer(Position playerPosition, Position centerPosition, i
while (Game.Player.InAction)
Thread.Sleep(50);

if (item.Record.IsSpecialtyGoodBox && Game.Player.Job2SpecialtyBag.Full)
continue;

//Make sure the player is at the item's location
//Game.Player.MoveTo(item.Movement.Source);
item.Pickup();
Expand Down Expand Up @@ -163,6 +166,9 @@ public static async void RunAbilityPet(Position centerPosition, int radius = 50)
if (!RunningAbilityPetPickup)
return;

if (item.Record.IsSpecialtyGoodBox && Game.Player.Job2SpecialtyBag.Full)
continue;

Game.Player.AbilityPet.Pickup(item.UniqueId);
await Task.Yield();
}
Expand Down
8 changes: 0 additions & 8 deletions Library/RSBot.Core/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,15 +169,7 @@ public static void ShowNotification(string message)
return;

var chatPacket = new Packet(0x3026);

chatPacket.WriteByte(ChatType.Notice);

if (Game.ClientType > GameClientType.Vietnam)
chatPacket.WriteByte(0); // has linking

if (Game.ClientType >= GameClientType.Chinese)
chatPacket.WriteByte(0);

chatPacket.WriteConditonalString(message);

PacketManager.SendPacket(chatPacket, PacketDestination.Client);
Expand Down
4 changes: 2 additions & 2 deletions Library/RSBot.Core/Objects/Spawn/SpawnedEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class SpawnedEntity
/// <summary>
/// Synchroniztion object.
/// </summary>
protected object _lock { get; } = new object();
protected internal object _lock { get; } = new();

/// <summary>
/// Gets or sets the unique identifier.
Expand Down Expand Up @@ -111,7 +111,7 @@ public float ActualSpeed
{
get
{
if(Movement.Type == MovementType.Walking)
if (Movement.Type == MovementType.Walking)
{
if (State.WalkSpeed == 0 && State.RunSpeed != 0)
return State.RunSpeed;
Expand Down
10 changes: 9 additions & 1 deletion Plugins/RSBot.CommandCenter/Network/Hook/ChatRequestHook.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using RSBot.CommandCenter.Components;
using RSBot.Core;
using RSBot.Core.Components;
using RSBot.Core.Extensions;
using RSBot.Core.Network;
Expand All @@ -18,10 +19,17 @@ public Packet ReplacePacket(Packet packet)
return packet;

var type = (ChatType)packet.ReadByte();

if (type == ChatType.Private)
return packet;

packet.ReadByte(); // chatIndex

if (Game.ClientType > GameClientType.Vietnam)
packet.ReadByte(); // has linking

if (Game.ClientType >= GameClientType.Chinese)
packet.ReadByte();

var message = packet.ReadConditonalString();
if (!message.StartsWith("\\"))
return packet;
Expand Down
18 changes: 11 additions & 7 deletions Plugins/RSBot.Map/Views/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,12 @@ private void PopulateMapAndGrid(Graphics graphics)
{
foreach (var member in Game.Party.Members.ToArray())
{
if (!(Game.Player.Movement.Source.DistanceTo(member.Position) < 50))
if (Game.Player.Position.DistanceTo(member.Position) > 50)
continue;

if (member.Name == Game.Player.Name)
continue;

DrawPointAt(graphics, member.Position, 6);
AddGridItem(member.Name, "Party Member", member.Level, member.Position);
}
Expand Down Expand Up @@ -382,12 +386,15 @@ private void DrawCollisions(Graphics gfx)
{
if (CollisionManager.HasActiveMeshes && CollisionManager.Enabled)
{
//Draw collisions
foreach (var collisionNavmesh in CollisionManager.ActiveCollisionMeshes)
{
foreach (var collider in collisionNavmesh.Collisions.Where(c => c.Source.DistanceToPlayer() < 100 || c.Destination.DistanceToPlayer() < 100))
var colliders = collisionNavmesh.Collisions
.Where(c => c.Source.DistanceToPlayer() < 100 || c.Destination.DistanceToPlayer() < 100);

foreach (var collider in colliders)
DrawLineAt(gfx, collider.Source, collider.Destination, Pens.Red);
}

if (!SpawnManager.TryGetEntities<SpawnedEntity>(out var entities))
return;

Expand All @@ -398,11 +405,8 @@ private void DrawCollisions(Graphics gfx)

if (!collision.HasValue)
continue;
var rayPen = new Pen(Color.DeepSkyBlue);
rayPen.DashStyle = DashStyle.Dot;
rayPen.EndCap = LineCap.Square;

DrawLineAt(gfx, Game.Player.Position, collision.Value.CollidedAt, Pens.DeepSkyBlue);
DrawLineAt(gfx, Game.Player.Position, collision.Value.CollidedAt, Pens.GreenYellow);
DrawLineAt(gfx, collision.Value.CollidedWith.Source, collision.Value.CollidedWith.Destination, Pens.Yellow);
}
}
Expand Down
6 changes: 4 additions & 2 deletions Plugins/RSBot.Party/Bundle/AutoParty/AutoPartyBundle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,12 @@ private void CheckForAutoPartyJoin()
while (true)
{
var currentPage = Container.PartyMatching.RequestPartyList(page);

_partyEntriesCache.AddRange(currentPage.Parties);

if (currentPage.Page == currentPage.PageCount - 1)
break;

_partyEntriesCache.AddRange(currentPage.Parties);
page++;
}

Expand All @@ -131,7 +133,7 @@ private void CheckForAutoPartyJoin()

if (Config.AutoJoinByTitle)
{
var partyEntry = _partyEntriesCache.Find(p => p.Title.Equals(Config.AutoJoinByTitleContent, StringComparison.CurrentCultureIgnoreCase));
var partyEntry = _partyEntriesCache.Find(p => p.Title.Contains(Config.AutoJoinByTitleContent, StringComparison.CurrentCultureIgnoreCase));
if (partyEntry == null)
return;

Expand Down
9 changes: 3 additions & 6 deletions Plugins/RSBot.Protection/Components/Town/DeadHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,18 @@ public static void Initialize()
/// </summary>
private static void SubscribeEvents()
{
EventManager.SubscribeEvent("OnUpdateEntityLifeState", new System.Action<uint>(OnEntityLifeStateChanged));
EventManager.SubscribeEvent("OnPlayerDied", OnPlayerDied);
}

/// <summary>
/// Cores the entity life state changed.
/// </summary>
/// <param name="uniqueId">The unique identifier.</param>
private static async void OnEntityLifeStateChanged(uint uniqueId)
private static async void OnPlayerDied()
{
if (!Kernel.Bot.Running)
return;

if (uniqueId != Game.Player.UniqueId)
return;

if(Game.Player.Level < 10)
{
await Task.Delay(5000);
Expand All @@ -53,7 +50,7 @@ private static async void OnEntityLifeStateChanged(uint uniqueId)
return;

var itemsToUse = PlayerConfig.GetArray<string>("RSBot.Inventory.AutoUseAccordingToPurpose");
var inventoryItem = Game.Player.Inventory.GetItem(new TypeIdFilter(3, 3, 13, 6), p => itemsToUse.Contains(p.Record.CodeName));
var inventoryItem = Game.Player.Inventory.GetItem(new(3, 3, 13, 6), p => itemsToUse.Contains(p.Record.CodeName));
if (inventoryItem != null)
{
inventoryItem.Use();
Expand Down
45 changes: 19 additions & 26 deletions Plugins/RSBot.Protection/Views/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,20 +110,17 @@ private void ApplySettings()
PlayerConfig.Set(key + num.Name, num.Value);

SkillInfo skill = null;
if (comboSkillPlayerHP.SelectedIndex > 0)
skill = comboSkillPlayerHP.SelectedItem as SkillInfo;

PlayerConfig.Set(key + "HpSkill", skill == null ? 0 : skill.Id);
skill = comboSkillPlayerHP.SelectedItem as SkillInfo;
PlayerConfig.Set(key + "HpSkill", skill?.Id);

if (comboSkillPlayerMP.SelectedIndex > 0)
skill = comboSkillPlayerMP.SelectedItem as SkillInfo;
skill = comboSkillPlayerMP.SelectedItem as SkillInfo;
PlayerConfig.Set(key + "MpSkill", skill?.Id);

PlayerConfig.Set(key + "MpSkill", skill == null ? 0 : skill.Id);
skill = comboSkillBadStatus.SelectedItem as SkillInfo;
PlayerConfig.Set(key + "BadStatusSkill", skill?.Id);

if (comboSkillBadStatus.SelectedIndex > 0)
skill = comboSkillBadStatus.SelectedItem as SkillInfo;

PlayerConfig.Set(key + "BadStatusSkill", skill == null ? 0 : skill.Id);
skill = null;
}

/// <summary>
Expand All @@ -137,10 +134,6 @@ private void RefreshSkills()
comboSkillPlayerHP.Items.Clear();
comboSkillPlayerMP.Items.Clear();

comboSkillBadStatus.SelectedIndex = comboSkillBadStatus.Items.Add("None");
comboSkillPlayerHP.SelectedIndex = comboSkillPlayerHP.Items.Add("None");
comboSkillPlayerMP.SelectedIndex = comboSkillPlayerMP.Items.Add("None");

foreach (var skill in Game.Player.Skills.KnownSkills)
{
if (!skill.Enabled)
Expand All @@ -153,22 +146,22 @@ private void RefreshSkills()
continue;

// TODO: Check is the cure skill?
var badStatusIndex = comboSkillBadStatus.Items.Add(skill);
var badStatusSkillId = PlayerConfig.Get<uint>("RSBot.Protection.BadStatusSkill");
if (badStatusSkillId == skill.Id)
comboSkillBadStatus.SelectedIndex = badStatusIndex;
var index = comboSkillBadStatus.Items.Add(skill);
var skillId = PlayerConfig.Get<uint>("RSBot.Protection.BadStatusSkill");
if (skillId == skill.Id)
comboSkillBadStatus.SelectedIndex = index;

// TODO: Check is the hp skill?
var hpIndex = comboSkillPlayerHP.Items.Add(skill);
var hpSkillId = PlayerConfig.Get<uint>("RSBot.Protection.HpSkill");
if (hpSkillId == skill.Id)
comboSkillPlayerHP.SelectedIndex = hpIndex;
index = comboSkillPlayerHP.Items.Add(skill);
skillId = PlayerConfig.Get<uint>("RSBot.Protection.HpSkill");
if (skillId == skill.Id)
comboSkillPlayerHP.SelectedIndex = index;

// TODO: Check is the mp skill?
var mpIndex = comboSkillPlayerMP.Items.Add(skill);
var mpSkillId = PlayerConfig.Get<uint>("RSBot.Protection.MpSkill");
if (mpSkillId == skill.Id)
comboSkillPlayerMP.SelectedIndex = mpIndex;
index = comboSkillPlayerMP.Items.Add(skill);
skillId = PlayerConfig.Get<uint>("RSBot.Protection.MpSkill");
if (skillId == skill.Id)
comboSkillPlayerMP.SelectedIndex = index;
}

_skillSettingsLoaded = true;
Expand Down

0 comments on commit 8d13196

Please sign in to comment.