feat(timers): Adds timer pooling, fixes timer related bugs, and changes timer api (#667)
### Changes/Fixes:
* Adds timer pooling.
* Allows pool to be configurable in ModernUO.json
* Pool replenishes itself asynchronously if depleted.
* Fixes an issue with barkeeps and town criers
* Fixes an issue with incognito buff icons not being removed
* Fixes an issue with polymorph name mod not being removed
* Fixes several places where timers go on forever even after an object is deleted, keeping a reference (memory leak)
* Eliminates the timer for MiningCart altogether.
* Deletes `AcidSlime` since it is a duplicate of `PoolOfAcid`
* Fixes HonorableExecution and standardizes the code for other Bushido moves.
## Changes to the Timer API:
```cs
public class Timer
{
// Creates a timer that will be returned to the pool once execution stops.
public static void StartTimer(Action callback);
public static void StartTimer(TimeSpan delay, Action callback);
public static void StartTimer(TimeSpan delay, TimeSpan interval, Action callback);
public static void StartTimer(TimeSpan interval, int count, Action callback);
public static void StartTimer(TimeSpan delay, TimeSpan interval, int count, Action callback);
// Creates a timer and returns a token for more control. Requires manual cancellation in order for the timer to be returned to the pool.
// If the token is dereferenced, the timer will be dereferenced too. While not returning a timer to the pool is not considered hazardous, it does defeat the purpose of pooled timers.
public static void StartTimer(Action callback, out TimerExecutionToken token);
public static void StartTimer(TimeSpan delay, Action callback, out TimerExecutionToken token);
public static void StartTimer(TimeSpan delay, TimeSpan interval, Action callback, out TimerExecutionToken token);
public static void StartTimer(TimeSpan interval, int count, Action callback, out TimerExecutionToken token);
public static void StartTimer(TimeSpan delay, TimeSpan interval, int count, Action callback, out TimerExecutionToken token);
// If you aren't sure how to use the API above, or you don't care about performance, then you can use the old RunUO Timer.DelayCall
public static DelayCallTimer DelayCall(Action callback);
public static DelayCallTimer DelayCall(TimeSpan delay, Action callback);
public static DelayCallTimer DelayCall(TimeSpan delay, TimeSpan interval, Action callback);
public static DelayCallTimer DelayCall(TimeSpan interval, int count, Action callback);
public static DelayCallTimer DelayCall(TimeSpan delay, TimeSpan interval, int count, Action callback);
}
public struct TimerExecutionToken
{
public bool Running { get; }
public int Index { get; }
public int RemainingCount { get; }
public DateTime Next { get; }
}
```
## When to use `TimerExecutionToken`?
Use tokens when you want to gain the performance benefit of using a pooled timer, but you need one of the following:
* Access to the next time the timer will tick:`token.Next`
* Access to which interval, how many intervals there are, or how many are remaining: `token.Index`, `token.Count`, and `token.RemainingCount`
* Stop a timer manually.
* Determine if the timer is running: `timer.Running`
* See notes below about requirements for using tokens!
## Notes about using the TimerExecutionToken:
When you opt-in to receive a token, you must call `Cancel()` to return the timer. This can be done inside of the callback, or outside of the callback at any time.
If this is not called and your timer is an infinite interval, then you will create a potential memory leak, or null pointer exception in your callback.
If the timer ends and is stopped, but cancel is not called, then the timer will never return to the pool and stay referenced until the token is deleted or cancel is called. (Memory leak)
## Is this thread safe?
No. The ModernUO timer system is not thread safe at all. If you require a thread safe timer system, contact me and I'll help adapt this system. Keep in mind that there is a massive performance hit to make this thread safe when there are literally no use cases for it.
If you need to synchronize execution, meaning you want to execute code from another thread on the core thread. Let's say you have a discord bot that is pushing commands to the game server. Then use `EventLoopContext.Post(SendOrPostCallback callback, object state);`.
This commit is contained in:
parent
b4de631f96
commit
9b554f69b0
219 changed files with 1897 additions and 2241 deletions
|
|
@ -98,7 +98,7 @@ namespace Server.Engines.ConPVP
|
|||
|
||||
AddButton(314, 173, 247, 248, 1);
|
||||
|
||||
Timer.DelayCall(TimeSpan.FromSeconds(15.0), AutoReject);
|
||||
Timer.StartTimer(TimeSpan.FromSeconds(15.0), AutoReject);
|
||||
}
|
||||
|
||||
public string Center(string text) => $"<CENTER>{text}</CENTER>";
|
||||
|
|
|
|||
|
|
@ -333,12 +333,12 @@ namespace Server.Engines.ConPVP
|
|||
|
||||
if (IsOccupied)
|
||||
{
|
||||
Timer.DelayCall(TimeSpan.FromSeconds(2.0), Evict);
|
||||
Timer.StartTimer(TimeSpan.FromSeconds(2.0), Evict);
|
||||
}
|
||||
|
||||
if (m_Tournament != null)
|
||||
{
|
||||
Timer.DelayCall(AttachToTournament_Sandbox);
|
||||
Timer.StartTimer(AttachToTournament_Sandbox);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -30,9 +30,10 @@ namespace Server.Engines.ConPVP
|
|||
|
||||
private readonly List<Item> m_Walls = new();
|
||||
|
||||
private Timer m_AutoTieTimer;
|
||||
|
||||
private Timer m_Countdown;
|
||||
private TimerExecutionToken _autoTieTimerToken;
|
||||
private TimerExecutionToken _countdownTimerToken;
|
||||
private TimerExecutionToken _SdWarnTimerToken;
|
||||
private TimerExecutionToken _SdActivateTimerToken;
|
||||
|
||||
public EventGame m_EventGame;
|
||||
private Map m_GateFacet;
|
||||
|
|
@ -42,7 +43,6 @@ namespace Server.Engines.ConPVP
|
|||
|
||||
public Arena m_OverrideArena;
|
||||
|
||||
private Timer m_SDWarnTimer, m_SDActivateTimer;
|
||||
public Tournament m_Tournament;
|
||||
|
||||
private bool m_Yielding;
|
||||
|
|
@ -109,7 +109,7 @@ namespace Server.Engines.ConPVP
|
|||
|
||||
public void DelayBounce(TimeSpan ts, Mobile mob, Container corpse)
|
||||
{
|
||||
Timer.DelayCall(ts, DelayBounce_Callback, mob, corpse);
|
||||
Timer.StartTimer(ts, () => DelayBounce_Callback(mob, corpse));
|
||||
}
|
||||
|
||||
public static bool AllowSpecialMove(Mobile from, string name, SpecialMove move) =>
|
||||
|
|
@ -766,7 +766,7 @@ namespace Server.Engines.ConPVP
|
|||
return;
|
||||
}
|
||||
|
||||
EndAutoTie();
|
||||
_autoTieTimerToken.Cancel();
|
||||
StopSDTimers();
|
||||
|
||||
Finished = true;
|
||||
|
|
@ -844,7 +844,7 @@ namespace Server.Engines.ConPVP
|
|||
|
||||
m_EventGame?.OnStop();
|
||||
|
||||
Timer.DelayCall(TimeSpan.FromSeconds(9.0), UnregisterRematch);
|
||||
Timer.StartTimer(TimeSpan.FromSeconds(9.0), UnregisterRematch);
|
||||
}
|
||||
|
||||
public void Award(Mobile us, Mobile them, bool won)
|
||||
|
|
@ -1057,23 +1057,20 @@ namespace Server.Engines.ConPVP
|
|||
|
||||
public void StartCountdown(int count, CountdownCallback cb)
|
||||
{
|
||||
cb(count);
|
||||
m_Countdown = Timer.DelayCall(
|
||||
TimeSpan.FromSeconds(1.0),
|
||||
Timer.StartTimer(
|
||||
TimeSpan.FromSeconds(1.0),
|
||||
count,
|
||||
() => Countdown_Callback(--count, cb)
|
||||
() => Countdown_Callback(cb),
|
||||
out _countdownTimerToken
|
||||
);
|
||||
}
|
||||
|
||||
public void StopCountdown()
|
||||
{
|
||||
m_Countdown?.Stop();
|
||||
m_Countdown = null;
|
||||
}
|
||||
public void StopCountdown() => _countdownTimerToken.Cancel();
|
||||
|
||||
private void Countdown_Callback(int count, CountdownCallback cb)
|
||||
private void Countdown_Callback(CountdownCallback cb)
|
||||
{
|
||||
var count = _countdownTimerToken.RemainingCount;
|
||||
|
||||
if (count == 0)
|
||||
{
|
||||
StopCountdown();
|
||||
|
|
@ -1084,24 +1081,17 @@ namespace Server.Engines.ConPVP
|
|||
|
||||
public void StopSDTimers()
|
||||
{
|
||||
m_SDWarnTimer?.Stop();
|
||||
|
||||
m_SDWarnTimer = null;
|
||||
|
||||
m_SDActivateTimer?.Stop();
|
||||
|
||||
m_SDActivateTimer = null;
|
||||
_SdWarnTimerToken.Cancel();
|
||||
_SdActivateTimerToken.Cancel();
|
||||
}
|
||||
|
||||
public void StartSuddenDeath(TimeSpan timeUntilActive)
|
||||
{
|
||||
m_SDWarnTimer?.Stop();
|
||||
_SdWarnTimerToken.Cancel();
|
||||
Timer.StartTimer(TimeSpan.FromMinutes(timeUntilActive.TotalMinutes * 0.9), WarnSuddenDeath, out _SdWarnTimerToken);
|
||||
|
||||
m_SDWarnTimer = Timer.DelayCall(TimeSpan.FromMinutes(timeUntilActive.TotalMinutes * 0.9), WarnSuddenDeath);
|
||||
|
||||
m_SDActivateTimer?.Stop();
|
||||
|
||||
m_SDActivateTimer = Timer.DelayCall(timeUntilActive, ActivateSuddenDeath);
|
||||
_SdActivateTimerToken.Cancel();
|
||||
Timer.StartTimer(timeUntilActive, ActivateSuddenDeath, out _SdActivateTimerToken);
|
||||
}
|
||||
|
||||
public void WarnSuddenDeath()
|
||||
|
|
@ -1127,9 +1117,7 @@ namespace Server.Engines.ConPVP
|
|||
|
||||
m_Tournament?.Alert(Arena, "Sudden death will be active soon!");
|
||||
|
||||
m_SDWarnTimer?.Stop();
|
||||
|
||||
m_SDWarnTimer = null;
|
||||
_SdWarnTimerToken.Cancel();
|
||||
}
|
||||
|
||||
public static bool CheckSuddenDeath(Mobile mob) => mob is PlayerMobile pm && pm.DuelPlayer?.Eliminated == false &&
|
||||
|
|
@ -1163,32 +1151,22 @@ namespace Server.Engines.ConPVP
|
|||
|
||||
IsSuddenDeath = true;
|
||||
|
||||
m_SDActivateTimer?.Stop();
|
||||
|
||||
m_SDActivateTimer = null;
|
||||
_SdActivateTimerToken.Cancel();
|
||||
}
|
||||
|
||||
public void BeginAutoTie()
|
||||
{
|
||||
m_AutoTieTimer?.Stop();
|
||||
|
||||
var ts = m_Tournament == null || m_Tournament.TourneyType == TourneyType.Standard
|
||||
? AutoTieDelay
|
||||
: TimeSpan.FromMinutes(90.0);
|
||||
|
||||
m_AutoTieTimer = Timer.DelayCall(ts, InvokeAutoTie);
|
||||
}
|
||||
|
||||
public void EndAutoTie()
|
||||
{
|
||||
m_AutoTieTimer?.Stop();
|
||||
|
||||
m_AutoTieTimer = null;
|
||||
_autoTieTimerToken.Cancel();
|
||||
Timer.StartTimer(ts, InvokeAutoTie, out _autoTieTimerToken);
|
||||
}
|
||||
|
||||
public void InvokeAutoTie()
|
||||
{
|
||||
m_AutoTieTimer = null;
|
||||
_autoTieTimerToken.Cancel();
|
||||
|
||||
if (!Started || Finished)
|
||||
{
|
||||
|
|
@ -1258,7 +1236,7 @@ namespace Server.Engines.ConPVP
|
|||
|
||||
m_Tournament?.HandleTie(Arena, m_Match, remaining);
|
||||
|
||||
Timer.DelayCall(TimeSpan.FromSeconds(10.0), Unregister);
|
||||
Timer.StartTimer(TimeSpan.FromSeconds(10.0), Unregister);
|
||||
}
|
||||
|
||||
public static void Initialize()
|
||||
|
|
@ -1640,9 +1618,7 @@ namespace Server.Engines.ConPVP
|
|||
}
|
||||
else
|
||||
{
|
||||
pm.DuelContext.m_Countdown?.Stop();
|
||||
pm.DuelContext.m_Countdown = null;
|
||||
|
||||
pm.DuelContext.StopCountdown();
|
||||
pm.DuelContext.StartedReadyCountdown = false;
|
||||
p.Broadcast(0x22, null, "{0} has yielded.", "You have yielded.");
|
||||
|
||||
|
|
@ -2777,7 +2753,7 @@ namespace Server.Engines.ConPVP
|
|||
TitleColor = 0x7800;
|
||||
TitleNumber = 1062051; // Gate Warning
|
||||
|
||||
Timer.DelayCall(TimeSpan.FromSeconds(10.0), Delete);
|
||||
Timer.StartTimer(TimeSpan.FromSeconds(10.0), Delete);
|
||||
}
|
||||
|
||||
public ArenaMoongate(Serial serial) : base(serial)
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ namespace Server.Engines.ConPVP
|
|||
}
|
||||
}
|
||||
|
||||
Timer.DelayCall(Delete); // delete this after the world loads
|
||||
Timer.StartTimer(Delete); // delete this after the world loads
|
||||
}
|
||||
|
||||
public override void Serialize(IGenericWriter writer)
|
||||
|
|
@ -243,7 +243,7 @@ namespace Server.Engines.ConPVP
|
|||
m_Path.Clear();
|
||||
m_PathIdx = 0;
|
||||
|
||||
Timer.DelayCall(TimeSpan.FromSeconds(0.05), ContinueFlight);
|
||||
Timer.StartTimer(TimeSpan.FromSeconds(0.05), ContinueFlight);
|
||||
}
|
||||
|
||||
private bool CheckCatch(Mobile m, Point3D myLoc)
|
||||
|
|
@ -640,7 +640,7 @@ namespace Server.Engines.ConPVP
|
|||
DoAnim(GetWorldLocation(), m_Path[m_PathIdx - 1], Map);
|
||||
}
|
||||
|
||||
Timer.DelayCall(TimeSpan.FromSeconds(0.1), ContinueFlight);
|
||||
Timer.StartTimer(TimeSpan.FromSeconds(0.1), ContinueFlight);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -864,7 +864,7 @@ namespace Server.Engines.ConPVP
|
|||
// has to be delayed in case some other target canceled us...
|
||||
if (m_Resend)
|
||||
{
|
||||
Timer.DelayCall(ResendBombTarget);
|
||||
Timer.StartTimer(ResendBombTarget);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1613,24 +1613,13 @@ namespace Server.Engines.ConPVP
|
|||
{
|
||||
private BRBomb m_Bomb;
|
||||
|
||||
private Timer m_FinishTimer;
|
||||
private TimerExecutionToken _finishTimerToken;
|
||||
|
||||
public BRGame(BRController controller, DuelContext context) : base(context) => Controller = controller;
|
||||
|
||||
public BRController Controller { get; }
|
||||
|
||||
public Map Facet
|
||||
{
|
||||
get
|
||||
{
|
||||
if (m_Context.Arena != null)
|
||||
{
|
||||
return m_Context.Arena.Facet;
|
||||
}
|
||||
|
||||
return Controller.Map;
|
||||
}
|
||||
}
|
||||
public Map Facet => m_Context.Arena != null ? m_Context.Arena.Facet : Controller.Map;
|
||||
|
||||
public override bool CantDoAnything(Mobile mob) =>
|
||||
mob.Backpack?.FindItemByType<BRBomb>() != null && GetTeamInfo(mob) != null;
|
||||
|
|
@ -1641,7 +1630,7 @@ namespace Server.Engines.ConPVP
|
|||
{
|
||||
m_Bomb.Visible = false;
|
||||
m_Bomb.MoveToWorld(Controller.BombHome, Controller.Map);
|
||||
Timer.DelayCall(TimeSpan.FromSeconds(Utility.RandomMinMax(5, 15)), UnhideBomb);
|
||||
Timer.StartTimer(TimeSpan.FromSeconds(Utility.RandomMinMax(5, 15)), UnhideBomb);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1724,7 +1713,7 @@ namespace Server.Engines.ConPVP
|
|||
|
||||
public void DelayBounce(TimeSpan ts, Mobile mob, Container corpse)
|
||||
{
|
||||
Timer.DelayCall(ts, DelayBounce_Callback, mob, corpse);
|
||||
Timer.StartTimer(ts, () => DelayBounce_Callback(mob, corpse));
|
||||
}
|
||||
|
||||
private void DelayBounce_Callback(Mobile mob, Container corpse)
|
||||
|
|
@ -1821,12 +1810,12 @@ namespace Server.Engines.ConPVP
|
|||
);
|
||||
}
|
||||
|
||||
m_FinishTimer?.Stop();
|
||||
_finishTimerToken.Cancel();
|
||||
|
||||
m_Bomb = new BRBomb(this);
|
||||
ReturnBomb();
|
||||
|
||||
m_FinishTimer = Timer.DelayCall(Controller.Duration, Finish_Callback);
|
||||
Timer.StartTimer(Controller.Duration, Finish_Callback, out _finishTimerToken);
|
||||
}
|
||||
|
||||
private void Finish_Callback()
|
||||
|
|
@ -2047,8 +2036,7 @@ namespace Server.Engines.ConPVP
|
|||
ApplyHues(m_Context.Participants[i], -1);
|
||||
}
|
||||
|
||||
m_FinishTimer?.Stop();
|
||||
m_FinishTimer = null;
|
||||
_finishTimerToken.Cancel();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -252,7 +252,7 @@ namespace Server.Engines.ConPVP
|
|||
|
||||
public Mobile m_Returner;
|
||||
public DateTime m_ReturnTime;
|
||||
private Timer m_ReturnTimer;
|
||||
private TimerExecutionToken _returnTimerToken;
|
||||
public CTFTeamInfo m_TeamInfo;
|
||||
|
||||
[Constructible]
|
||||
|
|
@ -370,18 +370,11 @@ namespace Server.Engines.ConPVP
|
|||
}
|
||||
}
|
||||
|
||||
private void StopCountdown()
|
||||
{
|
||||
m_ReturnTimer?.Stop();
|
||||
|
||||
m_ReturnTimer = null;
|
||||
}
|
||||
|
||||
private void BeginCountdown(int returnCount)
|
||||
{
|
||||
StopCountdown();
|
||||
_returnTimerToken.Cancel();
|
||||
|
||||
m_ReturnTimer = Timer.DelayCall(TimeSpan.FromSeconds(1.0), TimeSpan.FromSeconds(1.0), Countdown_OnTick);
|
||||
Timer.StartTimer(TimeSpan.FromSeconds(1.0), TimeSpan.FromSeconds(1.0), Countdown_OnTick, out _returnTimerToken);
|
||||
m_ReturnCount = returnCount;
|
||||
}
|
||||
|
||||
|
|
@ -518,7 +511,7 @@ namespace Server.Engines.ConPVP
|
|||
|
||||
public void SendHome()
|
||||
{
|
||||
StopCountdown();
|
||||
_returnTimerToken.Cancel();
|
||||
|
||||
if (m_TeamInfo == null)
|
||||
{
|
||||
|
|
@ -897,7 +890,7 @@ namespace Server.Engines.ConPVP
|
|||
|
||||
public sealed class CTFGame : EventGame
|
||||
{
|
||||
private Timer m_FinishTimer;
|
||||
private TimerExecutionToken _finishTimerToken;
|
||||
|
||||
public CTFGame(CTFController controller, DuelContext context) : base(context) => Controller = controller;
|
||||
|
||||
|
|
@ -1004,7 +997,7 @@ namespace Server.Engines.ConPVP
|
|||
|
||||
public void DelayBounce(TimeSpan ts, Mobile mob, Container corpse)
|
||||
{
|
||||
Timer.DelayCall(ts, DelayBounce_Callback, mob, corpse);
|
||||
Timer.StartTimer(ts, () => DelayBounce_Callback(mob, corpse));
|
||||
}
|
||||
|
||||
private void DelayBounce_Callback(Mobile mob, Container corpse)
|
||||
|
|
@ -1135,9 +1128,8 @@ namespace Server.Engines.ConPVP
|
|||
ApplyHues(m_Context.Participants[i], Controller.TeamInfo[i % 8].Color);
|
||||
}
|
||||
|
||||
m_FinishTimer?.Stop();
|
||||
|
||||
m_FinishTimer = Timer.DelayCall(Controller.Duration, Finish_Callback);
|
||||
_finishTimerToken.Cancel();
|
||||
Timer.StartTimer(Controller.Duration, Finish_Callback, out _finishTimerToken);
|
||||
}
|
||||
|
||||
private void Finish_Callback()
|
||||
|
|
@ -1364,9 +1356,7 @@ namespace Server.Engines.ConPVP
|
|||
ApplyHues(m_Context.Participants[i], -1);
|
||||
}
|
||||
|
||||
m_FinishTimer?.Stop();
|
||||
|
||||
m_FinishTimer = null;
|
||||
_finishTimerToken.Cancel();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -495,10 +495,9 @@ namespace Server.Engines.ConPVP
|
|||
private int m_CapStage;
|
||||
|
||||
private bool m_Capturable = true;
|
||||
private Timer m_CaptureTimer;
|
||||
|
||||
private Timer m_FinishTimer;
|
||||
private Timer m_UncaptureTimer;
|
||||
private TimerExecutionToken _captureTimerToken;
|
||||
private TimerExecutionToken _finishTimerToken;
|
||||
private TimerExecutionToken _uncaptureTimerToken;
|
||||
|
||||
public DDGame(DDController controller, DuelContext context) : base(context) => Controller = controller;
|
||||
|
||||
|
|
@ -587,7 +586,7 @@ namespace Server.Engines.ConPVP
|
|||
|
||||
public void DelayBounce(TimeSpan ts, Mobile mob, Container corpse)
|
||||
{
|
||||
Timer.DelayCall(ts, DelayBounce_Callback, mob, corpse);
|
||||
Timer.StartTimer(ts, () => DelayBounce_Callback(mob, corpse));
|
||||
}
|
||||
|
||||
private void DelayBounce_Callback(Mobile mob, Container corpse)
|
||||
|
|
@ -668,17 +667,8 @@ namespace Server.Engines.ConPVP
|
|||
{
|
||||
m_Capturable = true;
|
||||
|
||||
if (m_CaptureTimer != null)
|
||||
{
|
||||
m_CaptureTimer.Stop();
|
||||
m_CaptureTimer = null;
|
||||
}
|
||||
|
||||
if (m_UncaptureTimer != null)
|
||||
{
|
||||
m_UncaptureTimer.Stop();
|
||||
m_UncaptureTimer = null;
|
||||
}
|
||||
_captureTimerToken.Cancel();
|
||||
_uncaptureTimerToken.Cancel();
|
||||
|
||||
for (var i = 0; i < Controller.TeamInfo.Length; ++i)
|
||||
{
|
||||
|
|
@ -706,8 +696,8 @@ namespace Server.Engines.ConPVP
|
|||
);
|
||||
}
|
||||
|
||||
m_FinishTimer?.Stop();
|
||||
m_FinishTimer = Timer.DelayCall(Controller.Duration, Finish_Callback);
|
||||
_finishTimerToken.Cancel();
|
||||
Timer.StartTimer(Controller.Duration, Finish_Callback, out _finishTimerToken);
|
||||
}
|
||||
|
||||
private void Finish_Callback()
|
||||
|
|
@ -933,25 +923,15 @@ namespace Server.Engines.ConPVP
|
|||
|
||||
m_Capturable = false;
|
||||
|
||||
if (m_CaptureTimer != null)
|
||||
{
|
||||
m_CaptureTimer.Stop();
|
||||
m_CaptureTimer = null;
|
||||
}
|
||||
|
||||
if (m_UncaptureTimer != null)
|
||||
{
|
||||
m_UncaptureTimer.Stop();
|
||||
m_UncaptureTimer = null;
|
||||
}
|
||||
_captureTimerToken.Cancel();
|
||||
_uncaptureTimerToken.Cancel();
|
||||
|
||||
for (var i = 0; i < m_Context.Participants.Count; ++i)
|
||||
{
|
||||
ApplyHues(m_Context.Participants[i], -1);
|
||||
}
|
||||
|
||||
m_FinishTimer?.Stop();
|
||||
m_FinishTimer = null;
|
||||
_finishTimerToken.Cancel();
|
||||
}
|
||||
|
||||
public void Dominate(DDWayPoint point, Mobile from, DDTeamInfo team)
|
||||
|
|
@ -975,14 +955,13 @@ namespace Server.Engines.ConPVP
|
|||
|
||||
Controller.PointA?.SetNonCaptureHue();
|
||||
Controller.PointB?.SetNonCaptureHue();
|
||||
m_CaptureTimer?.Stop();
|
||||
m_CaptureTimer = null;
|
||||
_captureTimerToken.Cancel();
|
||||
}
|
||||
|
||||
if (!wasDom && isDom)
|
||||
{
|
||||
m_CapStage = 0;
|
||||
m_CaptureTimer = Timer.DelayCall(TimeSpan.Zero, TimeSpan.FromSeconds(1.0), CaptureTick);
|
||||
Timer.StartTimer(TimeSpan.Zero, TimeSpan.FromSeconds(1.0), CaptureTick, out _captureTimerToken);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -993,8 +972,7 @@ namespace Server.Engines.ConPVP
|
|||
if (team == null)
|
||||
{
|
||||
m_Capturable = true;
|
||||
m_CaptureTimer?.Stop();
|
||||
m_CaptureTimer = null;
|
||||
_captureTimerToken.Cancel();
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -1014,8 +992,7 @@ namespace Server.Engines.ConPVP
|
|||
|
||||
m_Capturable = false;
|
||||
m_CapStage = 0;
|
||||
m_CaptureTimer.Stop();
|
||||
m_CaptureTimer = null;
|
||||
_captureTimerToken.Cancel();
|
||||
|
||||
if (Controller.PointA != null)
|
||||
{
|
||||
|
|
@ -1029,8 +1006,7 @@ namespace Server.Engines.ConPVP
|
|||
Controller.PointB.SetUncapturableHue();
|
||||
}
|
||||
|
||||
m_UncaptureTimer = Timer.DelayCall(TimeSpan.FromSeconds(30.0), UncaptureTick);
|
||||
m_UncaptureTimer.Start();
|
||||
Timer.StartTimer(TimeSpan.FromSeconds(30.0), UncaptureTick, out _uncaptureTimerToken);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1038,17 +1014,8 @@ namespace Server.Engines.ConPVP
|
|||
{
|
||||
m_Capturable = true;
|
||||
|
||||
if (m_CaptureTimer != null)
|
||||
{
|
||||
m_CaptureTimer.Stop();
|
||||
m_CaptureTimer = null;
|
||||
}
|
||||
|
||||
if (m_UncaptureTimer != null)
|
||||
{
|
||||
m_UncaptureTimer.Stop();
|
||||
m_UncaptureTimer = null;
|
||||
}
|
||||
_captureTimerToken.Cancel();
|
||||
_uncaptureTimerToken.Cancel();
|
||||
|
||||
if (Controller.PointA != null)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -25,8 +25,7 @@ namespace Server.Engines.ConPVP
|
|||
Name = "the hill";
|
||||
}
|
||||
|
||||
public HillOfTheKing(Serial s)
|
||||
: base(s)
|
||||
public HillOfTheKing(Serial s) : base(s)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -49,18 +48,7 @@ namespace Server.Engines.ConPVP
|
|||
[CommandProperty(AccessLevel.GameMaster)]
|
||||
public int ScoreInterval { get; set; }
|
||||
|
||||
public int CapturesSoFar
|
||||
{
|
||||
get
|
||||
{
|
||||
if (m_KingTimer != null)
|
||||
{
|
||||
return m_KingTimer.Captures;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
public int CapturesSoFar => m_KingTimer?.Captures ?? 0;
|
||||
|
||||
public override void Deserialize(IGenericReader reader)
|
||||
{
|
||||
|
|
@ -864,7 +852,7 @@ namespace Server.Engines.ConPVP
|
|||
|
||||
public sealed class KHGame : EventGame
|
||||
{
|
||||
private Timer m_FinishTimer;
|
||||
private TimerExecutionToken _finishTimerToken;
|
||||
|
||||
public KHGame(KHController controller, DuelContext context) : base(context) => Controller = controller;
|
||||
|
||||
|
|
@ -969,7 +957,7 @@ namespace Server.Engines.ConPVP
|
|||
|
||||
public void DelayBounce(TimeSpan ts, Mobile mob, Container corpse)
|
||||
{
|
||||
Timer.DelayCall(ts, DelayBounce_Callback, mob, corpse);
|
||||
Timer.StartTimer(ts, () => DelayBounce_Callback(mob, corpse));
|
||||
}
|
||||
|
||||
private void DelayBounce_Callback(Mobile mob, Container corpse)
|
||||
|
|
@ -994,7 +982,7 @@ namespace Server.Engines.ConPVP
|
|||
|
||||
if (corpse?.Deleted == false)
|
||||
{
|
||||
Timer.DelayCall(TimeSpan.FromSeconds(30), corpse.Delete);
|
||||
Timer.StartTimer(TimeSpan.FromSeconds(30), corpse.Delete);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1067,8 +1055,6 @@ namespace Server.Engines.ConPVP
|
|||
);
|
||||
}
|
||||
|
||||
m_FinishTimer?.Stop();
|
||||
|
||||
for (var i = 0; i < Controller.Hills.Length; i++)
|
||||
{
|
||||
if (Controller.Hills[i] != null)
|
||||
|
|
@ -1085,7 +1071,8 @@ namespace Server.Engines.ConPVP
|
|||
}
|
||||
}
|
||||
|
||||
m_FinishTimer = Timer.DelayCall(Controller.Duration, Finish_Callback);
|
||||
_finishTimerToken.Cancel();
|
||||
Timer.StartTimer(Controller.Duration, Finish_Callback, out _finishTimerToken);
|
||||
}
|
||||
|
||||
private void Finish_Callback()
|
||||
|
|
@ -1310,8 +1297,7 @@ namespace Server.Engines.ConPVP
|
|||
ApplyHues(m_Context.Participants[i], -1);
|
||||
}
|
||||
|
||||
m_FinishTimer?.Stop();
|
||||
m_FinishTimer = null;
|
||||
_finishTimerToken.Cancel();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -244,7 +244,7 @@ namespace Server.Engines.ConPVP
|
|||
y -= 3;
|
||||
AddButton(314, y, 247, 248, 1);
|
||||
|
||||
Timer.DelayCall(TimeSpan.FromSeconds(15.0), AutoReject);
|
||||
Timer.StartTimer(TimeSpan.FromSeconds(15.0), AutoReject);
|
||||
}
|
||||
|
||||
public string Center(string text) => $"<CENTER>{text}</CENTER>";
|
||||
|
|
|
|||
|
|
@ -107,7 +107,7 @@ namespace Server.Engines.ConPVP
|
|||
}
|
||||
}
|
||||
|
||||
Timer.DelayCall(SliceInterval, SliceInterval, Slice);
|
||||
Timer.StartTimer(SliceInterval, SliceInterval, Slice);
|
||||
}
|
||||
|
||||
public Tournament()
|
||||
|
|
@ -122,7 +122,7 @@ namespace Server.Engines.ConPVP
|
|||
Arenas = new List<Arena>();
|
||||
SignupPeriod = TimeSpan.FromMinutes(10.0);
|
||||
|
||||
Timer.DelayCall(SliceInterval, SliceInterval, Slice);
|
||||
Timer.StartTimer(SliceInterval, SliceInterval, Slice);
|
||||
}
|
||||
|
||||
public bool IsNotoRestricted => TourneyType != TourneyType.Standard;
|
||||
|
|
@ -992,18 +992,19 @@ namespace Server.Engines.ConPVP
|
|||
|
||||
public void Alert(Arena arena, params string[] alerts)
|
||||
{
|
||||
if (arena?.Announcer != null)
|
||||
if (arena?.Announcer == null)
|
||||
{
|
||||
for (var j = 0; j < alerts.Length; ++j)
|
||||
{
|
||||
Timer.DelayCall(
|
||||
TimeSpan.FromSeconds(Math.Max(j - 0.5, 0.0)),
|
||||
(announcer, alert) => announcer.PublicOverheadMessage(MessageType.Regular, 0x35, false, alert),
|
||||
arena.Announcer,
|
||||
alerts[j]
|
||||
);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
var count = 0;
|
||||
|
||||
Timer.StartTimer(TimeSpan.FromSeconds(0.5), alerts.Length,
|
||||
() =>
|
||||
{
|
||||
arena.Announcer.PublicOverheadMessage(MessageType.Regular, 0x35, false, alerts[count++]);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ namespace Server.Engines.ConPVP
|
|||
[Constructible]
|
||||
public TournamentRegistrar()
|
||||
{
|
||||
Timer.DelayCall(TimeSpan.FromSeconds(30.0), TimeSpan.FromSeconds(30.0), Announce_Callback);
|
||||
Timer.StartTimer(TimeSpan.FromSeconds(30.0), TimeSpan.FromSeconds(30.0), Announce_Callback);
|
||||
}
|
||||
|
||||
public TournamentRegistrar(Serial serial) : base(serial)
|
||||
|
|
@ -70,7 +70,7 @@ namespace Server.Engines.ConPVP
|
|||
m.NetState
|
||||
);
|
||||
m.BeginAction(this);
|
||||
Timer.DelayCall(TimeSpan.FromSeconds(10.0), ReleaseLock_Callback, m);
|
||||
Timer.StartTimer(TimeSpan.FromSeconds(10.0), () => ReleaseLock_Callback(m));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -103,7 +103,7 @@ namespace Server.Engines.ConPVP
|
|||
}
|
||||
}
|
||||
|
||||
Timer.DelayCall(TimeSpan.FromSeconds(30.0), TimeSpan.FromSeconds(30.0), Announce_Callback);
|
||||
Timer.StartTimer(TimeSpan.FromSeconds(30.0), TimeSpan.FromSeconds(30.0), Announce_Callback);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue