fix: Simplifies fastwalk detection (#907)

* Uses a circular buffer for steps.
* Limits to 3 steps instead of 4.
* Gives a 5% buffer on the first step.
This commit is contained in:
Kamron Batman 2022-02-27 02:20:03 -08:00 • committed by GitHub
parent 5b7b99e0de
commit e873d2ed7e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 186 additions and 78 deletions

View file

@ -0,0 +1,67 @@
using System.Collections.Generic;
using Server.Commands.Generic;
namespace Server.Network;
public static class FastwalkDetection
{
private static readonly HashSet<Mobile> _debugFastwalk = new();
public static void Initialize()
{
TargetCommands.Register(new DebugFastwalk());
EventSink.FastWalk += OnFastwalk;
}
private static void OnFastwalk(FastWalkEventArgs e)
{
var from = e.NetState.Mobile;
if (from == null)
{
return;
}
if (!_debugFastwalk.Contains(from))
{
return;
}
from.PublicOverheadMessage(MessageType.Emote, from.EmoteHue, false, "Fastwalk Detected", accessLevel: AccessLevel.GameMaster);
}
public class DebugFastwalk : BaseCommand
{
public DebugFastwalk()
{
AccessLevel = AccessLevel.GameMaster;
Supports = CommandSupport.AllMobiles;
Commands = new[] { "DebugFastwalk" };
ObjectTypes = ObjectTypes.Mobiles;
ListOptimized = true;
Usage = "DebugFastwalk <on|off>";
Description = "Enables fastwalk debug messages";
}
public override void ExecuteList(CommandEventArgs e, List<object> list)
{
var on = e.Arguments.Length == 0 || e.GetBoolean(0);
foreach (var o in list)
{
if (o is not Mobile m)
{
continue;
}
if (on)
{
_debugFastwalk.Add(m);
}
else
{
_debugFastwalk.Remove(m);
}
}
}
}
}