Updates movement packets & Fastwalk (#324)

- [X] Updates Movement packets
- [X] Adds OSI fastwalk packets. These aren't used on OSi anymore.
- [X] Adds new movement handling, but looks like the client doesn't use it. (Also leaving the 0x4000 Character List Flag off)
- [X] Adds time sync request handler, but also looks like the client doesn't use it.
- [X] Adds time sync response for time sync, just in case, but it isn't used, so not sure about the arguments.
- [X] Reimplements RunUO's fastwalk to use a circular array on the netstate instead of every mobile
- [X] Removes ClearFastwalkStack from RunUO implementation. This shouldn't be needed anymore

Changed fastwalk settings:
```cs
        public static int WalkFootDelay { get; set; } = 440;
        public static int RunFootDelay { get; set; } = 220;
        public static int WalkMountDelay { get; set; } = 220;
        public static int RunMountDelay { get; set; } = 110;

        public static bool EnableFastwalkPrevention { get; set; } = true;
        public static AccessLevel FastwalkExemptionLevel { get; set; } = AccessLevel.Counselor;

        // If this is changed during runtime, then the steps array needs resizing.
        public static int MaxSteps { get; private set; } = 4;
```

modernuo.json
```json
{
  "settings": {
    "movement.delay.runFoot": "220",
    "movement.delay.runMount": "110",
    "movement.delay.walkFoot": "440",
    "movement.delay.walkMount": "220",
    "movement.enableFastWalkPrevention": "True",
    "movement.fastwalkExemptionLevel": "Counselor",
    "movement.maxSteps": "4"
  }
}
```

Notes about OSI fastwalk:
While it does work, I can't find a benefit in using it because of the variable speeds. If players moved at a single speed then we could refill the stack every X milliseconds with 6 keys and use a naive token bucket implementation.
Unfortunately variable speeds mount/run/walk/etc means we would have to use a leaky bucket algorithm.
If we are using a leaky bucket algorithm with a variable leak, then we don't need to send tokens because we are already tracking it on the server side.

ModernUO vs OSI Fastwalk:
When the fastwalk was implemented on OSI, it used up to 6 tokens. These tokens were probably distributed every 600-750 milliseconds. To get the same effect, the new fastwalk settings might need to be adjusted. I would tweak them and feel free to let me know what worked for you!

Bumps release version
This commit is contained in:
Kamron Batman 2020-11-26 23:53:47 -08:00 • committed by GitHub
parent b6cd408623
commit 351611a23a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
25 changed files with 781 additions and 490 deletions

View file

@ -18,6 +18,7 @@ using Server.Network;
using Server.Prompts;
using Server.Targeting;
using Server.Utilities;
using CalcMoves = Server.Movement.Movement;
namespace Server
{
@ -502,7 +503,6 @@ namespace Server
private Direction m_Direction;
private bool m_DisplayGuildTitle;
private long m_EndQueue;
private Timer m_ExpireAggrTimer;
private Timer m_ExpireCombatant;
private Timer m_ExpireCriminal;
@ -550,7 +550,6 @@ namespace Server
*/
private Item m_MountItem;
private Queue<MovementRecord> m_MoveRecords;
private string m_Name;
private string m_NameMod;
@ -1081,22 +1080,6 @@ namespace Server
public bool Pushing { get; set; }
public static int WalkFoot { get; set; } = 400;
public static int RunFoot { get; set; } = 200;
public static int WalkMount { get; set; } = 200;
public static int RunMount { get; set; } = 100;
public static AccessLevel FwdAccessOverride { get; set; } = AccessLevel.Counselor;
public static bool FwdEnabled { get; set; } = true;
public static bool FwdUOTDOverride { get; set; }
public static int FwdMaxSteps { get; set; } = 4;
public virtual bool IsDeadBondedPet => false;
public ISpell Spell
@ -2861,8 +2844,6 @@ namespace Server
{
ns.Send(new MobileUpdateOld(this));
}
ClearFastwalkStack();
}
if (ns != null)
@ -2873,7 +2854,6 @@ namespace Server
}
ns.Sequence = 0;
ClearFastwalkStack();
ns.Send(MobileIncoming.Create(ns, this, this));
@ -2897,7 +2877,6 @@ namespace Server
if (ns != null)
{
ns.Sequence = 0;
ClearFastwalkStack();
ns.Send(MobileIncoming.Create(ns, this, this));
@ -2997,8 +2976,6 @@ namespace Server
{
ns.Send(new MobileUpdateOld(this));
}
ClearFastwalkStack();
}
}
else
@ -3014,7 +2991,6 @@ namespace Server
}
ns.Sequence = 0;
ClearFastwalkStack();
ns.Send(MobileIncoming.Create(ns, this, this));
@ -3038,7 +3014,6 @@ namespace Server
if (ns != null)
{
ns.Sequence = 0;
ClearFastwalkStack();
ns.Send(MobileIncoming.Create(ns, this, this));
@ -3228,8 +3203,6 @@ namespace Server
{
ourState.Send(new MobileUpdateOld(m));
}
ClearFastwalkStack();
}
if (sendIncoming)
@ -4512,17 +4485,188 @@ namespace Server
return true;
}
public virtual void ClearFastwalkStack()
public virtual bool CheckMovement(Direction d, out int newZ) => Movement.Movement.CheckMovement(this, d, out newZ);
private bool CanMove(Direction d, Point3D oldLocation, ref Point3D newLocation)
{
if (m_MoveRecords != null && m_MoveRecords.Count > 0)
if (m_Spell?.OnCasterMoving(d) == false)
{
m_MoveRecords.Clear();
return false;
}
m_EndQueue = Core.TickCount;
}
if (m_Paralyzed || m_Frozen)
{
SendLocalizedMessage(500111); // You are frozen and can not move.
public virtual bool CheckMovement(Direction d, out int newZ) => Movement.Movement.CheckMovement(this, d, out newZ);
return false;
}
if (!CheckMovement(d, out var newZ))
{
return false;
}
int x = oldLocation.m_X, y = oldLocation.m_Y;
int oldX = x, oldY = y;
var oldZ = oldLocation.m_Z;
switch (d & Direction.Mask)
{
case Direction.North:
--y;
break;
case Direction.Right:
++x;
--y;
break;
case Direction.East:
++x;
break;
case Direction.Down:
++x;
++y;
break;
case Direction.South:
++y;
break;
case Direction.Left:
--x;
++y;
break;
case Direction.West:
--x;
break;
case Direction.Up:
--x;
--y;
break;
}
newLocation.m_X = x;
newLocation.m_Y = y;
newLocation.m_Z = newZ;
Pushing = false;
var map = m_Map;
if (map == null || !Region.CanMove(this, d, newLocation, oldLocation, map))
{
return false;
}
var oldSector = map.GetSector(oldX, oldY);
var newSector = map.GetSector(x, y);
if (oldSector != newSector)
{
for (var i = 0; i < oldSector.Mobiles.Count; ++i)
{
var m = oldSector.Mobiles[i];
if (m != this && m.X == oldX && m.Y == oldY && m.Z + 15 > oldZ && oldZ + 15 > m.Z &&
!m.OnMoveOff(this))
{
return false;
}
}
for (var i = 0; i < oldSector.Items.Count; ++i)
{
var item = oldSector.Items[i];
if (item.AtWorldPoint(oldX, oldY) &&
(item.Z == oldZ || item.Z + item.ItemData.Height > oldZ && oldZ + 15 > item.Z) &&
!item.OnMoveOff(this))
{
return false;
}
}
for (var i = 0; i < newSector.Mobiles.Count; ++i)
{
var m = newSector.Mobiles[i];
if (m.X == x && m.Y == y && m.Z + 15 > newZ && newZ + 15 > m.Z && !m.OnMoveOver(this))
{
return false;
}
}
for (var i = 0; i < newSector.Items.Count; ++i)
{
var item = newSector.Items[i];
if (item.AtWorldPoint(x, y) &&
(item.Z == newZ || item.Z + item.ItemData.Height > newZ && newZ + 15 > item.Z) &&
!item.OnMoveOver(this))
{
return false;
}
}
}
else
{
for (var i = 0; i < oldSector.Mobiles.Count; ++i)
{
var m = oldSector.Mobiles[i];
if (m != this && m.X == oldX && m.Y == oldY && m.Z + 15 > oldZ && oldZ + 15 > m.Z &&
!m.OnMoveOff(this))
{
return false;
}
if (m.X == x && m.Y == y && m.Z + 15 > newZ && newZ + 15 > m.Z && !m.OnMoveOver(this))
{
return false;
}
}
for (var i = 0; i < oldSector.Items.Count; ++i)
{
var item = oldSector.Items[i];
if (item.AtWorldPoint(oldX, oldY) &&
(item.Z == oldZ || item.Z + item.ItemData.Height > oldZ && oldZ + 15 > item.Z) &&
!item.OnMoveOff(this))
{
return false;
}
if (item.AtWorldPoint(x, y) &&
(item.Z == newZ || item.Z + item.ItemData.Height > newZ && newZ + 15 > item.Z) &&
!item.OnMoveOver(this))
{
return false;
}
}
}
if (!InternalOnMove(d))
{
return false;
}
if (
CalcMoves.EnableFastwalkPrevention &&
AccessLevel < CalcMoves.FastwalkExemptionLevel &&
m_NetState?.AddStep(d) == false
)
{
var fw = new FastWalkEventArgs(m_NetState);
EventSink.InvokeFastWalk(fw);
if (fw.Blocked)
{
return false;
}
}
LastMoveTime = Core.TickCount;
return true;
}
public virtual bool Move(Direction d)
{
@ -4538,227 +4682,13 @@ namespace Server
box.Close();
}
var newLocation = m_Location;
var oldLocation = newLocation;
var oldLocation = m_Location;
Point3D newLocation = oldLocation;
if ((m_Direction & Direction.Mask) == (d & Direction.Mask))
{
// We are actually moving (not just a direction change)
if (m_Spell?.OnCasterMoving(d) == false)
{
return false;
}
if (m_Paralyzed || m_Frozen)
{
SendLocalizedMessage(500111); // You are frozen and can not move.
return false;
}
if (CheckMovement(d, out var newZ))
{
int x = oldLocation.m_X, y = oldLocation.m_Y;
int oldX = x, oldY = y;
var oldZ = oldLocation.m_Z;
switch (d & Direction.Mask)
{
case Direction.North:
--y;
break;
case Direction.Right:
++x;
--y;
break;
case Direction.East:
++x;
break;
case Direction.Down:
++x;
++y;
break;
case Direction.South:
++y;
break;
case Direction.Left:
--x;
++y;
break;
case Direction.West:
--x;
break;
case Direction.Up:
--x;
--y;
break;
}
newLocation.m_X = x;
newLocation.m_Y = y;
newLocation.m_Z = newZ;
Pushing = false;
var map = m_Map;
if (map != null)
{
var oldSector = map.GetSector(oldX, oldY);
var newSector = map.GetSector(x, y);
if (oldSector != newSector)
{
for (var i = 0; i < oldSector.Mobiles.Count; ++i)
{
var m = oldSector.Mobiles[i];
if (m != this && m.X == oldX && m.Y == oldY && m.Z + 15 > oldZ && oldZ + 15 > m.Z &&
!m.OnMoveOff(this))
{
return false;
}
}
for (var i = 0; i < oldSector.Items.Count; ++i)
{
var item = oldSector.Items[i];
if (item.AtWorldPoint(oldX, oldY) &&
(item.Z == oldZ || item.Z + item.ItemData.Height > oldZ && oldZ + 15 > item.Z) &&
!item.OnMoveOff(this))
{
return false;
}
}
for (var i = 0; i < newSector.Mobiles.Count; ++i)
{
var m = newSector.Mobiles[i];
if (m.X == x && m.Y == y && m.Z + 15 > newZ && newZ + 15 > m.Z && !m.OnMoveOver(this))
{
return false;
}
}
for (var i = 0; i < newSector.Items.Count; ++i)
{
var item = newSector.Items[i];
if (item.AtWorldPoint(x, y) &&
(item.Z == newZ || item.Z + item.ItemData.Height > newZ && newZ + 15 > item.Z) &&
!item.OnMoveOver(this))
{
return false;
}
}
}
else
{
for (var i = 0; i < oldSector.Mobiles.Count; ++i)
{
var m = oldSector.Mobiles[i];
if (m != this && m.X == oldX && m.Y == oldY && m.Z + 15 > oldZ && oldZ + 15 > m.Z &&
!m.OnMoveOff(this))
{
return false;
}
if (m.X == x && m.Y == y && m.Z + 15 > newZ && newZ + 15 > m.Z && !m.OnMoveOver(this))
{
return false;
}
}
for (var i = 0; i < oldSector.Items.Count; ++i)
{
var item = oldSector.Items[i];
if (item.AtWorldPoint(oldX, oldY) &&
(item.Z == oldZ || item.Z + item.ItemData.Height > oldZ && oldZ + 15 > item.Z) &&
!item.OnMoveOff(this))
{
return false;
}
if (item.AtWorldPoint(x, y) &&
(item.Z == newZ || item.Z + item.ItemData.Height > newZ && newZ + 15 > item.Z) &&
!item.OnMoveOver(this))
{
return false;
}
}
}
if (!Region.CanMove(this, d, newLocation, oldLocation, m_Map))
{
return false;
}
}
else
{
return false;
}
if (!InternalOnMove(d))
{
return false;
}
if (FwdEnabled && m_NetState != null && m_AccessLevel < FwdAccessOverride &&
(!FwdUOTDOverride || !m_NetState.IsUOTDClient))
{
m_MoveRecords ??= new Queue<MovementRecord>(6);
while (m_MoveRecords.Count > 0)
{
var r = m_MoveRecords.Peek();
if (r.Expired())
{
m_MoveRecords.Dequeue();
}
else
{
break;
}
}
if (m_MoveRecords.Count >= FwdMaxSteps)
{
var fw = new FastWalkEventArgs(m_NetState);
EventSink.InvokeFastWalk(fw);
if (fw.Blocked)
{
return false;
}
}
var delay = ComputeMovementSpeed(d);
long end;
if (m_MoveRecords.Count > 0)
{
end = m_EndQueue + delay;
}
else
{
end = Core.TickCount + delay;
}
m_MoveRecords.Enqueue(MovementRecord.NewInstance(end));
m_EndQueue = end;
}
LastMoveTime = Core.TickCount;
}
else
if (!CanMove(d, oldLocation, ref newLocation))
{
return false;
}
@ -4766,12 +4696,7 @@ namespace Server
DisruptiveAction();
}
m_NetState?.Send(
MovementAck.Instantiate(
m_NetState.Sequence,
this
)
);
m_NetState?.SendMovementAck(m_NetState.Sequence, this);
SetLocation(newLocation, false);
SetDirection(d);
@ -4886,22 +4811,14 @@ namespace Server
public int ComputeMovementSpeed() => ComputeMovementSpeed(Direction, false);
public int ComputeMovementSpeed(Direction dir) => ComputeMovementSpeed(dir, true);
public virtual int ComputeMovementSpeed(Direction dir, bool checkTurning)
public virtual int ComputeMovementSpeed(Direction dir, bool checkTurning = true)
{
int delay;
if (Mounted)
{
delay = (dir & Direction.Running) != 0 ? RunMount : WalkMount;
}
else
{
delay = (dir & Direction.Running) != 0 ? RunFoot : WalkFoot;
return (dir & Direction.Running) != 0 ? CalcMoves.RunMountDelay : CalcMoves.WalkMountDelay;
}
return delay;
return (dir & Direction.Running) != 0 ? CalcMoves.RunFootDelay : CalcMoves.WalkFootDelay;
}
/// <summary>
@ -7856,8 +7773,6 @@ namespace Server
{
m_NetState.Send(new MobileUpdateOld(this));
}
ClearFastwalkStack();
}
var map = m_Map;

View file

@ -1,8 +1,48 @@
/*************************************************************************
* ModernUO *
* Copyright 2019-2020 - ModernUO Development Team *
* Email: hi@modernuo.com *
* File: Movement.cs *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
*************************************************************************/
namespace Server.Movement
{
public static class Movement
{
// Movement implementation algorithm
public static IMovementImpl Impl { get; set; }
public static int WalkFootDelay { get; set; } = 440;
public static int RunFootDelay { get; set; } = 220;
public static int WalkMountDelay { get; set; } = 220;
public static int RunMountDelay { get; set; } = 110;
public static bool EnableFastwalkPrevention { get; set; } = true;
public static AccessLevel FastwalkExemptionLevel { get; set; } = AccessLevel.Counselor;
// If this is changed during runtime, then the steps array needs resizing.
public static int MaxSteps { get; private set; } = 4;
public static void Configure()
{
EnableFastwalkPrevention = ServerConfiguration.GetOrUpdateSetting("movement.enableFastWalkPrevention", EnableFastwalkPrevention);
MaxSteps = ServerConfiguration.GetOrUpdateSetting("movement.maxSteps", MaxSteps);
FastwalkExemptionLevel = ServerConfiguration.GetOrUpdateSetting("movement.fastwalkExemptionLevel", FastwalkExemptionLevel);
WalkFootDelay = ServerConfiguration.GetOrUpdateSetting("movement.delay.walkFoot", WalkFootDelay);
RunFootDelay = ServerConfiguration.GetOrUpdateSetting("movement.delay.runFoot", RunFootDelay);
WalkMountDelay = ServerConfiguration.GetOrUpdateSetting("movement.delay.walkMount", WalkMountDelay);
RunMountDelay = ServerConfiguration.GetOrUpdateSetting("movement.delay.runMount", RunMountDelay);
// Testing
FastwalkExemptionLevel = (AccessLevel)((int)AccessLevel.Owner + 1);
}
public static bool CheckMovement(Mobile m, Direction d, out int newZ)
{

View file

@ -1,57 +0,0 @@
/*************************************************************************
* ModernUO *
* Copyright 2019-2020 - ModernUO Development Team *
* Email: hi@modernuo.com *
* File: MovementRecord.cs *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
*************************************************************************/
using System.Collections.Generic;
namespace Server.Mobiles
{
public class MovementRecord
{
private static readonly Queue<MovementRecord> m_InstancePool = new Queue<MovementRecord>();
private long m_End;
private MovementRecord(long end) => m_End = end;
public static MovementRecord NewInstance(long end)
{
MovementRecord r;
if (m_InstancePool.Count > 0)
{
r = m_InstancePool.Dequeue();
r.m_End = end;
}
else
{
r = new MovementRecord(end);
}
return r;
}
public bool Expired()
{
var v = Core.TickCount - m_End >= 0;
if (v)
{
m_InstancePool.Enqueue(this);
}
return v;
}
}
}