From 1e422db9e8638e56a9cdf84cad79cb8e4b224cfb Mon Sep 17 00:00:00 2001 From: Kamron Batman <3953314+kamronbatman@users.noreply.github.com> Date: Wed, 16 Aug 2023 00:05:07 -0700 Subject: [PATCH] fix: Fixes boat movement switching (#1458) --- Projects/UOContent/Multis/Boats/BaseBoat.cs | 33 ++++++++++----------- 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/Projects/UOContent/Multis/Boats/BaseBoat.cs b/Projects/UOContent/Multis/Boats/BaseBoat.cs index def1f1235..0d64ea634 100644 --- a/Projects/UOContent/Multis/Boats/BaseBoat.cs +++ b/Projects/UOContent/Multis/Boats/BaseBoat.cs @@ -1372,7 +1372,7 @@ namespace Server.Multis if (_moveTimer != null) { // Do not allow them to travel faster simply by respamming the command - if (_moveTimer.Running && _moveTimer.Interval == interval && _moveTimer.Single == singleNum) + if (_moveTimer.Running && _moveTimer.Interval == interval && _moveTimer.Count == singleNum) { return false; } @@ -1393,9 +1393,17 @@ namespace Server.Multis } _moveTimer.Stop(); - _moveTimer.Delay = delay; - _moveTimer.Interval = interval; - _moveTimer.Single = singleNum; + + // We can reuse the timer if it's not a single count + if (_moveTimer.Count == 0 && singleNum == 0) + { + _moveTimer.Delay = delay; + _moveTimer.Interval = interval; + } + else + { + _moveTimer = new MoveTimer(this, delay, interval, singleNum); + } } else { @@ -2113,23 +2121,12 @@ namespace Server.Multis } } - private class MoveTimer : Timer + private class MoveTimer(BaseBoat boat, TimeSpan delay, TimeSpan interval, int single) + : Timer(delay, interval, single) { - public TimeSpan BoatMoveDelay; - public TimeSpan BoatMoveInterval; - public int Single; - private BaseBoat _boat; - - public MoveTimer(BaseBoat boat, TimeSpan delay, TimeSpan interval, int single = 0) : base(delay, interval, single) - { - BoatMoveInterval = interval; - BoatMoveDelay = delay; - Single = single; - _boat = boat; - } protected override void OnTick() { - _boat?.StopBoat(); + boat?.StopBoat(); } }