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:
Kamron Batman 2021-08-07 14:33:35 -07:00 • committed by GitHub
parent b4de631f96
commit 9b554f69b0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
219 changed files with 1897 additions and 2241 deletions

View file

@ -405,7 +405,7 @@ namespace Server.Accounting
_totalGameTime = reader.ReadTimeSpan();
Timer.DelayCall(AfterDeserialization);
Timer.StartTimer(AfterDeserialization);
}
/// <summary>

View file

@ -128,7 +128,7 @@ namespace Server.Engines.BulkOrders
RequireExceptional = reader.ReadBool();
Material = (BulkMaterialType)reader.ReadInt();
Timer.DelayCall(AfterDeserialization);
Timer.StartTimer(AfterDeserialization);
}
}
}

View file

@ -42,9 +42,10 @@ namespace Server.Engines.CannedEvil
//Goes back each level, below level 0 and it goes off!
private Timer m_Timer;
private TimerExecutionToken _timerToken;
private IdolOfTheChampion m_Idol;
private TimerExecutionToken _restartTimerToken;
public virtual string BroadcastMessage => "The Champion has sensed your presence! Beware its wrath!";
public virtual bool ProximitySpawn => false;
@ -58,8 +59,6 @@ namespace Server.Engines.CannedEvil
public Dictionary<Mobile, int> DamageEntries { get; private set; }
public Timer RestartTimer { get; set; }
[CommandProperty(AccessLevel.GameMaster)]
public bool ConfinedRoaming { get; set; }
@ -92,7 +91,7 @@ namespace Server.Engines.CannedEvil
RestartDelay = TimeSpan.FromMinutes(30.0);
DamageEntries = new Dictionary<Mobile, int>();
Timer.DelayCall(TimeSpan.Zero, SetInitialSpawnArea);
Timer.StartTimer(TimeSpan.Zero, SetInitialSpawnArea);
}
public void SetInitialSpawnArea()
@ -303,13 +302,10 @@ namespace Server.Engines.CannedEvil
HasBeenAdvanced = false;
m_MaxLevel = 16 + Utility.Random(3);
m_Timer?.Stop();
_timerToken.Cancel();
Timer.StartTimer(TimeSpan.FromSeconds(1.0), TimeSpan.FromSeconds(1.0), OnSlice, out _timerToken);
m_Timer = Timer.DelayCall(TimeSpan.FromSeconds(1.0), TimeSpan.FromSeconds(1.0), OnSlice);
m_Timer.Start();
RestartTimer?.Stop();
RestartTimer = null;
_restartTimerToken.Cancel();
if (m_Altar != null)
{
@ -336,12 +332,8 @@ namespace Server.Engines.CannedEvil
HasBeenAdvanced = false;
m_MaxLevel = 0;
m_Timer?.Stop();
m_Timer = null;
RestartTimer?.Stop();
RestartTimer = null;
_timerToken.Cancel();
_restartTimerToken.Cancel();
if (m_Altar != null)
{
@ -363,17 +355,14 @@ namespace Server.Engines.CannedEvil
NextProximityTime = Core.Now + TimeSpan.FromHours(6.0);
}
Timer.DelayCall(TimeSpan.FromMinutes(10.0), ExpireCreatures);
Timer.StartTimer(TimeSpan.FromMinutes(10.0), ExpireCreatures);
}
public void BeginRestart(TimeSpan ts)
{
RestartTimer?.Stop();
RestartTime = Core.Now + ts;
RestartTimer = Timer.DelayCall(ts, EndRestart);
RestartTimer.Start();
_restartTimerToken.Cancel();
Timer.StartTimer(ts, EndRestart, out _restartTimerToken);
}
public void EndRestart()
@ -1314,12 +1303,15 @@ namespace Server.Engines.CannedEvil
writer.Write(Champion);
writer.Write(RestartDelay);
writer.Write(RestartTimer != null);
if (RestartTimer != null)
if (_restartTimerToken.Running)
{
writer.Write(true);
writer.WriteDeltaTime(RestartTime);
}
else
{
writer.Write(false);
}
}
public override void Deserialize(IGenericReader reader)
@ -1456,7 +1448,7 @@ namespace Server.Engines.CannedEvil
}
}
Timer.DelayCall(TimeSpan.Zero, UpdateRegion);
Timer.StartTimer(TimeSpan.Zero, UpdateRegion);
}
}

View file

@ -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>";

View file

@ -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);
}
}

View file

@ -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)

View file

@ -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();
}
}
}

View file

@ -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();
}
}
}

View file

@ -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)
{

View file

@ -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();
}
}
}

View file

@ -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>";

View file

@ -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++]);
}
);
}
}
}

View file

@ -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);
}
}
}

View file

@ -262,7 +262,7 @@ namespace Server.Engines.Craft
toDelete = true;
from.BeginAction<Golem>();
Timer.DelayCall(TimeSpan.FromSeconds(12.0), from.EndAction<Golem>);
Timer.StartTimer(TimeSpan.FromSeconds(12.0), from.EndAction<Golem>);
}
else
{

View file

@ -22,7 +22,7 @@ namespace Server.Engines.Doom
private GauntletSpawnerState m_State;
private Timer m_Timer;
private TimerExecutionToken _timerToken;
[Constructible]
public GauntletSpawner(string typeName = null) : base(0x36FE)
@ -136,7 +136,7 @@ namespace Server.Engines.Doom
CreateRegion();
FullSpawn();
m_Timer = Timer.DelayCall(TimeSpan.FromSeconds(1.0), TimeSpan.FromSeconds(1.0), Slice);
Timer.StartTimer(TimeSpan.FromSeconds(1.0), TimeSpan.FromSeconds(1.0), Slice, out _timerToken);
}
else
{
@ -176,8 +176,7 @@ namespace Server.Engines.Doom
ClearTraps();
DestroyRegion();
m_Timer?.Stop();
m_Timer = null;
_timerToken.Cancel();
}
public override void OnDelete()

View file

@ -96,7 +96,7 @@ namespace Server.Engines.Doom
private static readonly int[] ms2 = { 0x13F, 0x14B };
private static readonly int[] cs1 = { 0x244 };
private static readonly int[] exp = { 0x307 };
private Timer l_Timer;
private TimerExecutionToken _resetTimerToken;
private LampRoomBox m_Box;
private Region m_LampRoom;
@ -331,15 +331,8 @@ namespace Server.Engines.Doom
public virtual void KillTimers()
{
if (l_Timer?.Running == true)
{
l_Timer.Stop();
}
if (m_Timer?.Running == true)
{
m_Timer.Stop();
}
_resetTimerToken.Cancel();
m_Timer?.Stop();
}
public virtual void RemoveSuccessful()
@ -357,7 +350,7 @@ namespace Server.Engines.Doom
if ((TheirKey = (ushort)(code | (TheirKey <<= 4))) < 0x0FFF)
{
l_Timer = Timer.DelayCall(TimeSpan.FromSeconds(30.0), ResetPuzzle);
Timer.StartTimer(TimeSpan.FromSeconds(30.0), ResetPuzzle, out _resetTimerToken);
return;
}

View file

@ -38,7 +38,7 @@ namespace Server.Engines.Doom
m_Wanderer = new WandererOfTheVoid();
m_Wanderer.MoveToWorld(LeverPuzzleController.lr_Enter, Map.Malas);
m_Wanderer.PublicOverheadMessage(MessageType.Regular, 0x3B2, 1060002); // I am the guardian of...
Timer.DelayCall(TimeSpan.FromSeconds(5.0), CallBackMessage);
Timer.StartTimer(TimeSpan.FromSeconds(5.0), CallBackMessage);
}
}

View file

@ -268,7 +268,7 @@ namespace Server.Ethics
if (pl.Mobile != null)
{
Timer.DelayCall(pl.CheckAttach);
Timer.StartTimer(pl.CheckAttach);
}
}

View file

@ -13,7 +13,7 @@ namespace Server.Factions
public static readonly TimeSpan CampaignPeriod = TimeSpan.FromDays(1.0);
public static readonly TimeSpan VotingPeriod = TimeSpan.FromDays(3.0);
private Timer m_Timer;
private TimerExecutionToken _timerToken;
public Election(Faction faction)
{
@ -109,7 +109,7 @@ namespace Server.Factions
public void StartTimer()
{
m_Timer = Timer.DelayCall(TimeSpan.FromMinutes(1.0), TimeSpan.FromMinutes(1.0), Slice);
Timer.StartTimer(TimeSpan.FromMinutes(1.0), TimeSpan.FromMinutes(1.0), Slice, out _timerToken);
}
public void Serialize(IGenericWriter writer)
@ -274,9 +274,7 @@ namespace Server.Factions
{
if (Faction.Election != this)
{
m_Timer?.Stop();
m_Timer = null;
_timerToken.Cancel();
return;
}

View file

@ -621,9 +621,9 @@ namespace Server.Factions
EventSink.Login += EventSink_Login;
EventSink.Logout += EventSink_Logout;
Timer.DelayCall(TimeSpan.FromMinutes(1.0), TimeSpan.FromMinutes(10.0), HandleAtrophy);
Timer.StartTimer(TimeSpan.FromMinutes(1.0), TimeSpan.FromMinutes(10.0), HandleAtrophy);
Timer.DelayCall(TimeSpan.FromSeconds(30.0), TimeSpan.FromSeconds(30.0), ProcessTick);
Timer.StartTimer(TimeSpan.FromSeconds(30.0), TimeSpan.FromSeconds(30.0), ProcessTick);
CommandSystem.Register("FactionElection", AccessLevel.GameMaster, FactionElection_OnCommand);
CommandSystem.Register("FactionCommander", AccessLevel.Administrator, FactionCommander_OnCommand);
@ -1332,7 +1332,7 @@ namespace Server.Factions
}
}
context.m_Timer = Timer.DelayCall(SkillLossPeriod, ClearSkillLoss_Event, mob);
Timer.StartTimer(SkillLossPeriod, () => ClearSkillLoss_Event(mob), out context._timerToken);
}
private static void ClearSkillLoss_Event(Mobile mob) => ClearSkillLoss(mob);
@ -1353,7 +1353,7 @@ namespace Server.Factions
mob.RemoveSkillMod(mods[i]);
}
context.m_Timer.Stop();
context._timerToken.Cancel();
return true;
}
@ -1373,7 +1373,7 @@ namespace Server.Factions
private class SkillLossContext
{
public List<SkillMod> m_Mods;
public Timer m_Timer;
public TimerExecutionToken _timerToken;
}
}

View file

@ -124,7 +124,7 @@ namespace Server.Factions
{
var factionItem = new FactionItem(reader, m_Faction);
Timer.DelayCall(factionItem.CheckAttach); // sandbox attachment
Timer.StartTimer(factionItem.CheckAttach); // sandbox attachment
}
}

View file

@ -176,7 +176,7 @@ namespace Server.Factions
if (pl != null)
{
Timer.DelayCall(ShowScore_Sandbox, pl);
Timer.StartTimer(() => ShowScore_Sandbox(pl));
}
break;

View file

@ -12,7 +12,7 @@ namespace Server.Factions
public static readonly TimeSpan TaxChangePeriod = TimeSpan.FromHours(12.0);
public static readonly TimeSpan IncomePeriod = TimeSpan.FromDays(1.0);
private Timer m_IncomeTimer;
private Timer _incomeTimer;
private TownState m_State;
public Town()
@ -222,16 +222,12 @@ namespace Server.Factions
public void StartIncomeTimer()
{
m_IncomeTimer?.Stop();
m_IncomeTimer = Timer.DelayCall(TimeSpan.FromMinutes(1.0), TimeSpan.FromMinutes(1.0), CheckIncome);
_incomeTimer ??= Timer.DelayCall(TimeSpan.FromMinutes(1.0), TimeSpan.FromMinutes(1.0), CheckIncome);
}
public void StopIncomeTimer()
public void Delete()
{
m_IncomeTimer?.Stop();
m_IncomeTimer = null;
_incomeTimer?.Stop();
}
public void CheckIncome()

View file

@ -43,7 +43,7 @@ namespace Server
from.PlaySound(0x1EE);
from.AddStatMod(new StatMod(StatType.Int, "clarity-potion", amount, TimeSpan.FromMinutes(time)));
Timer.DelayCall(TimeSpan.FromMinutes(time), from.EndAction<ClarityPotion>);
Timer.StartTimer(TimeSpan.FromMinutes(time), from.EndAction<ClarityPotion>);
return true;
}

View file

@ -109,7 +109,7 @@ namespace Server
"The object vanishes from your hands as you touch it."
);
Timer.DelayCall(
Timer.StartTimer(
TimeSpan.FromSeconds(1.0),
() => from.LocalOverheadMessage(
MessageType.Regular,
@ -119,7 +119,7 @@ namespace Server
)
);
Timer.DelayCall(
Timer.StartTimer(
TimeSpan.FromSeconds(4.0),
() => { from.LocalOverheadMessage(MessageType.Regular, 2118, false, "Your skin begins to burn."); }
);

View file

@ -60,7 +60,7 @@ namespace Server
Hue - 1
);
Timer.DelayCall(TimeSpan.FromSeconds(0.5), OnDelay, from, stormsEye, origin, facet);
Timer.StartTimer(TimeSpan.FromSeconds(0.5), () => OnDelay(from, stormsEye, origin, facet));
},
this
);
@ -85,7 +85,7 @@ namespace Server
2
);
Timer.DelayCall(TimeSpan.FromSeconds(1.0), OnHit, from, origin, facet);
Timer.StartTimer(TimeSpan.FromSeconds(1.0), () => OnHit(from, origin, facet));
}
private static void OnHit(Mobile from, Point3D origin, Map facet)
@ -165,7 +165,7 @@ namespace Server
100
);
Timer.DelayCall(TimeSpan.FromSeconds(0.50), mob.PlaySound, 0x1FB);
Timer.StartTimer(TimeSpan.FromSeconds(0.50), () => mob.PlaySound(0x1FB));
}
}

View file

@ -15,7 +15,7 @@ namespace Server.Factions
public abstract class BaseFactionTrap : BaseTrap
{
private Timer m_Concealing;
private TimerExecutionToken _concealingTimerToken;
public BaseFactionTrap(Faction f, Mobile m, int itemID) : base(itemID)
{
@ -52,18 +52,7 @@ namespace Server.Factions
public virtual TimeSpan ConcealPeriod => TimeSpan.FromMinutes(1.0);
public virtual TimeSpan DecayPeriod
{
get
{
if (Core.AOS)
{
return TimeSpan.FromDays(1.0);
}
return TimeSpan.MaxValue; // no decay
}
}
public virtual TimeSpan DecayPeriod => Core.AOS ? TimeSpan.FromDays(1.0) : TimeSpan.MaxValue;
public override void OnTrigger(Mobile from)
{
@ -206,7 +195,7 @@ namespace Server.Factions
if (TimeOfPlacement + decayPeriod < Core.Now)
{
Timer.DelayCall(Delete);
Timer.StartTimer(Delete);
return true;
}
@ -215,16 +204,13 @@ namespace Server.Factions
public virtual void BeginConceal()
{
m_Concealing?.Stop();
m_Concealing = Timer.DelayCall(ConcealPeriod, Conceal);
_concealingTimerToken.Cancel();
Timer.StartTimer(ConcealPeriod, Conceal, out _concealingTimerToken);
}
public virtual void Conceal()
{
m_Concealing?.Stop();
m_Concealing = null;
_concealingTimerToken.Cancel();
if (!Deleted)
{

View file

@ -468,7 +468,7 @@ namespace Server.Factions
m_Town = Town.ReadReference(reader);
Orders = new Orders(this, reader);
Timer.DelayCall(Register);
Timer.StartTimer(Register);
}
}

View file

@ -487,7 +487,7 @@ namespace Server.Engines.Harvest
if (GetHarvestDetails(from, tool, toHarvest, out _, out var map, out var loc))
{
Timer.DelayCall(
Timer.StartTimer(
TimeSpan.FromSeconds(1.5),
() =>
{

View file

@ -153,8 +153,7 @@ namespace Server.Items
var delay = m_CloseTime - Core.Now;
static void start(Timer timer) => timer.Start();
DelayCall(delay, start, this);
StartTimer(delay, () => Start());
return;
}

View file

@ -224,7 +224,7 @@ namespace Server.Items
var version = reader.ReadEncodedInt();
Timer.DelayCall(Refresh);
Timer.StartTimer(Refresh);
}
}
}

View file

@ -104,7 +104,7 @@ namespace Server.Engines.MLQuests.Gumps
{
if (m_Pending.TryGetValue(ns, out var state))
{
state.m_Timeout.Stop();
state._timeoutToken.Cancel();
m_Pending.Remove(ns);
}
@ -273,13 +273,13 @@ namespace Server.Engines.MLQuests.Gumps
public readonly IRaceChanger m_Owner;
public readonly Race m_TargetRace;
public readonly Timer m_Timeout;
public TimerExecutionToken _timeoutToken;
public RaceChangeState(IRaceChanger owner, NetState ns, Race targetRace)
{
m_Owner = owner;
m_TargetRace = targetRace;
m_Timeout = Timer.DelayCall(m_TimeoutDelay, Timeout, ns);
Timer.StartTimer(m_TimeoutDelay, () => Timeout(ns), out _timeoutToken);
}
}
}

View file

@ -20,7 +20,7 @@ namespace Server.Engines.MLQuests
private MLQuestInstanceFlags m_Flags;
private IQuestGiver m_Quester;
private Timer m_Timer;
private TimerExecutionToken _timerToken;
public MLQuestInstance(MLQuest quest, IQuestGiver quester, PlayerMobile player)
{
@ -52,7 +52,7 @@ namespace Server.Engines.MLQuests
if (timed)
{
m_Timer = Timer.DelayCall(TimeSpan.FromSeconds(5), TimeSpan.FromSeconds(5), Slice);
Timer.StartTimer(TimeSpan.FromSeconds(5), TimeSpan.FromSeconds(5), Slice, out _timerToken);
}
}
@ -476,13 +476,7 @@ namespace Server.Engines.MLQuests
private void StopTimer()
{
if (m_Timer == null)
{
return;
}
m_Timer.Stop();
m_Timer = null;
_timerToken.Cancel();
}
public void OnQuesterDeleted()

View file

@ -76,7 +76,7 @@ namespace Server.Engines.MLQuests.Mobiles
if (from.CanBeginAction(this))
{
from.BeginAction(this);
Timer.DelayCall(m_ShoutCooldown, EndLock, from);
Timer.StartTimer(m_ShoutCooldown, () => EndLock(from));
}
MLQuestSystem.TurnToFace(this, from);

View file

@ -98,14 +98,14 @@ namespace Server.Engines.MLQuests.Objectives
private readonly BaseCreature m_Escort;
private readonly EscortObjective m_Objective;
private DateTime m_LastSeenEscorter;
private Timer m_Timer;
private TimerExecutionToken _timerToken;
public EscortObjectiveInstance(EscortObjective objective, MLQuestInstance instance)
: base(instance, objective)
{
m_Objective = objective;
HasCompleted = false;
m_Timer = Timer.DelayCall(TimeSpan.FromSeconds(5), TimeSpan.FromSeconds(5), CheckDestination);
Timer.StartTimer(TimeSpan.FromSeconds(5), TimeSpan.FromSeconds(5), CheckDestination, out _timerToken);
m_LastSeenEscorter = Core.Now;
m_Escort = instance.Quester as BaseCreature;
@ -183,11 +183,7 @@ namespace Server.Engines.MLQuests.Objectives
private void StopTimer()
{
if (m_Timer != null)
{
m_Timer.Stop();
m_Timer = null;
}
_timerToken.Cancel();
}
public static void BeginFollow(BaseCreature quester, PlayerMobile pm)

View file

@ -8,7 +8,7 @@ namespace Server.Engines.Quests
{
private int m_Charges;
private Timer m_PlayTimer;
private TimerExecutionToken _timerToken;
[Constructible]
public HornOfRetreat() : base(0xFC4)
@ -62,7 +62,7 @@ namespace Server.Engines.Quests
{
from.SendLocalizedMessage(1076154); // You can only use this in Trammel and Malas.
}
else if (m_PlayTimer != null)
else if (_timerToken.Running)
{
SendLocalizedMessageTo(from, 1042144); // This is currently in use.
}
@ -74,7 +74,7 @@ namespace Server.Engines.Quests
--Charges;
m_PlayTimer = Timer.DelayCall(TimeSpan.FromSeconds(5.0), PlayTimer_Callback, from);
Timer.StartTimer(TimeSpan.FromSeconds(5.0), () => PlayTimer_Callback(from), out _timerToken);
}
else
{
@ -89,7 +89,7 @@ namespace Server.Engines.Quests
public virtual void PlayTimer_Callback(Mobile from)
{
m_PlayTimer = null;
_timerToken.Cancel();
var gate = new HornOfRetreatMoongate(DestLoc, DestMap, from, Hue);
@ -146,7 +146,7 @@ namespace Server.Engines.Quests
Dispellable = false;
Timer.DelayCall(TimeSpan.FromSeconds(10.0), Delete);
Timer.StartTimer(TimeSpan.FromSeconds(10.0), Delete);
}
public HornOfRetreatMoongate(Serial serial) : base(serial)

View file

@ -38,7 +38,7 @@ namespace Server.Engines.Quests
typeof(TerribleHatchlingsQuest)
};
private Timer m_Timer;
private TimerExecutionToken _timerToken;
public QuestSystem(PlayerMobile from)
{
@ -69,19 +69,18 @@ namespace Server.Engines.Quests
public virtual void StartTimer()
{
if (m_Timer != null)
if (_timerToken.Running)
{
return;
}
m_Timer = Timer.DelayCall(TimeSpan.FromSeconds(0.5), TimeSpan.FromSeconds(0.5), Slice);
// TODO: Find out if this can go on forever. We should not allow timers to leak if this is the case.
Timer.StartTimer(TimeSpan.FromSeconds(0.5), TimeSpan.FromSeconds(0.5), Slice, out _timerToken);
}
public virtual void StopTimer()
{
m_Timer?.Stop();
m_Timer = null;
_timerToken.Cancel();
}
public virtual void Slice()
@ -344,36 +343,38 @@ namespace Server.Engines.Quests
{
StopTimer();
if (From.Quest == this)
if (From.Quest != this)
{
From.Quest = null;
return;
}
var restartDelay = RestartDelay;
From.Quest = null;
if (completed && restartDelay > TimeSpan.Zero || !completed && restartDelay == TimeSpan.MaxValue)
var restartDelay = RestartDelay;
if (completed && restartDelay > TimeSpan.Zero || !completed && restartDelay == TimeSpan.MaxValue)
{
From.DoneQuests ??= new List<QuestRestartInfo>();
var found = false;
var ourQuestType = GetType();
for (var i = 0; i < From.DoneQuests.Count; ++i)
{
From.DoneQuests ??= new List<QuestRestartInfo>();
var restartInfo = From.DoneQuests[i];
var found = false;
var ourQuestType = GetType();
for (var i = 0; i < From.DoneQuests.Count; ++i)
if (restartInfo.QuestType == ourQuestType)
{
var restartInfo = From.DoneQuests[i];
if (restartInfo.QuestType == ourQuestType)
{
restartInfo.Reset(restartDelay);
found = true;
break;
}
restartInfo.Reset(restartDelay);
found = true;
break;
}
}
if (!found)
{
From.DoneQuests.Add(new QuestRestartInfo(ourQuestType, restartDelay));
}
if (!found)
{
From.DoneQuests.Add(new QuestRestartInfo(ourQuestType, restartDelay));
}
}
}

View file

@ -44,7 +44,7 @@ namespace Server.Engines.Quests.Necro
Maabus = new Maabus { Location = SpawnLocation, Map = Map };
Maabus.Direction = Maabus.GetDirectionTo(caller);
Timer.DelayCall(TimeSpan.FromSeconds(7.5), BeginSleep);
Timer.StartTimer(TimeSpan.FromSeconds(7.5), BeginSleep);
}
public void BeginSleep()
@ -56,7 +56,7 @@ namespace Server.Engines.Quests.Necro
Effects.PlaySound(Maabus.Location, Maabus.Map, 0x48E);
Timer.DelayCall(TimeSpan.FromSeconds(2.5), Sleep);
Timer.StartTimer(TimeSpan.FromSeconds(2.5), Sleep);
}
public void Sleep()

View file

@ -91,7 +91,7 @@ namespace Server.Engines.Quests.Necro
m_ToDelete = true;
Timer.DelayCall(TimeSpan.FromSeconds(5.0), Delete);
Timer.StartTimer(TimeSpan.FromSeconds(5.0), Delete);
}
else if (m_Necromancer.Map != Map || GetDistanceToSqrt(m_Necromancer) > RangePerception + 1)
{
@ -239,7 +239,7 @@ namespace Server.Engines.Quests.Necro
Hue = 0x482;
Light = LightType.Circle300;
Timer.DelayCall(TimeSpan.FromSeconds(10.0), Delete);
Timer.StartTimer(TimeSpan.FromSeconds(10.0), Delete);
}
public SummonedPaladinMoongate(Serial serial) : base(serial)

View file

@ -82,7 +82,7 @@ namespace Server.Engines.Quests.Samurai
}
}
Timer.DelayCall(TimeSpan.FromMinutes(2.0), GenerateTreasure);
Timer.StartTimer(TimeSpan.FromMinutes(2.0), GenerateTreasure);
}
public override void Serialize(IGenericWriter writer)
@ -98,7 +98,7 @@ namespace Server.Engines.Quests.Samurai
var version = reader.ReadEncodedInt();
Timer.DelayCall(GenerateTreasure);
Timer.StartTimer(GenerateTreasure);
}
}
}

View file

@ -39,16 +39,14 @@ namespace Server.Engines.Quests.Naturalist
if (m_CurrentNest.Special)
{
from.SendLocalizedMessage(
1054057
); // You complete your examination of this bizarre Egg Nest. The Naturalist will undoubtedly be quite interested in these notes!
// You complete your examination of this bizarre Egg Nest. The Naturalist will undoubtedly be quite interested in these notes!
from.SendLocalizedMessage(1054057);
StudiedSpecialNest = true;
}
else
{
from.SendLocalizedMessage(
1054054
); // You have completed your study of this Solen Egg Nest. You put your notes away.
// You have completed your study of this Solen Egg Nest. You put your notes away.
from.SendLocalizedMessage(1054054);
CurProgress++;
}
}
@ -56,9 +54,8 @@ namespace Server.Engines.Quests.Naturalist
{
if (!nest.Special)
{
from.SendLocalizedMessage(
1054058
); // You begin recording your completed notes on a bit of parchment.
// You begin recording your completed notes on a bit of parchment.
from.SendLocalizedMessage(1054058);
}
m_StudyState = StudyState.SecondStep;
@ -69,9 +66,8 @@ namespace Server.Engines.Quests.Naturalist
{
if (m_StudyState != StudyState.Inactive)
{
from.SendLocalizedMessage(
1054046
); // You abandon your study of the Solen Egg Nest without gathering the needed information.
// You abandon your study of the Solen Egg Nest without gathering the needed information.
from.SendLocalizedMessage(1054046);
}
m_CurrentNest = null;
@ -90,9 +86,8 @@ namespace Server.Engines.Quests.Naturalist
{
m_StudyState = StudyState.Inactive;
from.SendLocalizedMessage(
1054047
); // You glance at the Egg Nest, realizing you've already studied this one.
// You glance at the Egg Nest, realizing you've already studied this one.
from.SendLocalizedMessage(1054047);
}
else
{
@ -100,15 +95,13 @@ namespace Server.Engines.Quests.Naturalist
if (nest.Special)
{
from.SendLocalizedMessage(
1054056
); // You notice something very odd about this Solen Egg Nest. You begin taking notes.
// You notice something very odd about this Solen Egg Nest. You begin taking notes.
from.SendLocalizedMessage(105405);
}
else
{
from.SendLocalizedMessage(
1054045
); // You begin studying the Solen Egg Nest to gather information.
// You begin studying the Solen Egg Nest to gather information.
from.SendLocalizedMessage(1054045);
}
if (from.Female)

View file

@ -61,7 +61,7 @@ namespace Server.Engines.Quests.Doom
Effects.PlaySound(GetWorldLocation(), Map, 0x100);
Timer.DelayCall(TimeSpan.FromSeconds(8.0), EndSummon, from);
Timer.StartTimer(TimeSpan.FromSeconds(8.0), () => EndSummon(from));
}
}

View file

@ -56,7 +56,7 @@ namespace Server.Engines.Quests.Doom
return;
}
Timer.DelayCall(TimeSpan.FromSeconds(4.0), EndGiveWarning);
Timer.StartTimer(TimeSpan.FromSeconds(4.0), EndGiveWarning);
}
public virtual void EndGiveWarning()
@ -84,12 +84,12 @@ namespace Server.Engines.Quests.Doom
return;
}
Timer.DelayCall(TimeSpan.FromSeconds(30.0), EndSummonDragon);
Timer.StartTimer(TimeSpan.FromSeconds(30.0), EndSummonDragon);
}
public virtual void BeginRemove(TimeSpan delay)
{
Timer.DelayCall(delay, EndRemove);
Timer.StartTimer(delay, EndRemove);
}
public virtual void EndRemove()

View file

@ -94,7 +94,7 @@ namespace Server.Engines.Quests.Hag
{
PublicOverheadMessage(MessageType.Regular, 0x3B2, 500849); // *hic*
Timer.DelayCall(TimeSpan.FromSeconds(Utility.RandomMinMax(60, 180)), Heave);
Timer.StartTimer(TimeSpan.FromSeconds(Utility.RandomMinMax(60, 180)), Heave);
}
public override void Serialize(IGenericWriter writer)

View file

@ -58,7 +58,7 @@ namespace Server.Engines.Quests.Hag
// * You see a strange imp stealing a scrap of paper from the bloodied corpse *
Corpse.SendLocalizedMessageTo(player, 1055049);
Timer.DelayCall(TimeSpan.FromSeconds(3.0), DeleteImp, imp);
Timer.StartTimer(TimeSpan.FromSeconds(3.0), () => DeleteImp(imp));
}
private void DeleteImp(Mobile m)
@ -221,7 +221,7 @@ namespace Server.Engines.Quests.Hag
imp.Direction = imp.GetDirectionTo(from);
Timer.DelayCall(TimeSpan.FromSeconds(3.0), DeleteImp, imp);
Timer.StartTimer(TimeSpan.FromSeconds(3.0), () => DeleteImp(imp));
}
private void DeleteImp(object imp)

View file

@ -247,7 +247,7 @@ namespace Server.Mobiles
if (m_SculptedBy == null || Map == Map.Internal) // Remove preview statues
{
Timer.DelayCall(Delete);
Timer.StartTimer(Delete);
}
}

View file

@ -101,7 +101,7 @@ namespace Server.Items
if (m_Statue?.SculptedBy == null || Map == Map.Internal)
{
Timer.DelayCall(Delete);
Timer.StartTimer(Delete);
}
}

View file

@ -88,7 +88,7 @@ namespace Server
pm.HonorActive = true;
pm.SendLocalizedMessage(1063235); // You embrace your honor
Timer.DelayCall(
Timer.StartTimer(
TimeSpan.FromSeconds(duration),
() =>
{
@ -227,7 +227,7 @@ namespace Server
m_Timer.Start();
source.m_hontime = Core.Now + TimeSpan.FromMinutes(40);
Timer.DelayCall(
Timer.StartTimer(
TimeSpan.FromMinutes(40),
() =>
{

View file

@ -171,7 +171,7 @@ namespace Server
if (protector.BeginAction<JusticeVirtue>())
{
Timer.DelayCall(TimeSpan.FromMinutes(15.0), protector.EndAction<JusticeVirtue>);
Timer.StartTimer(TimeSpan.FromMinutes(15.0), protector.EndAction<JusticeVirtue>);
}
}

View file

@ -156,7 +156,7 @@ namespace Server
from.SendLocalizedMessage(1052010); // You have set the creature free.
Timer.DelayCall(TimeSpan.FromSeconds(1.0), targ.Delete);
Timer.StartTimer(TimeSpan.FromSeconds(1.0), targ.Delete);
pm.LastSacrificeGain = Core.Now;

View file

@ -146,7 +146,7 @@ namespace Server.Gumps
if (Core.SE)
{
from.RecentlyReported.Add(killer);
Timer.DelayCall(TimeSpan.FromMinutes(10), ReportedListExpiry_Callback, from, killer);
Timer.StartTimer(TimeSpan.FromMinutes(10), () => ReportedListExpiry_Callback(from, killer));
}
if (killer is PlayerMobile pk)

View file

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using Server.Events.Halloween;
using Server.Items;
using Server.Mobiles;
@ -64,7 +65,7 @@ namespace Server.Engines.Events
{
target.SolidHueOverride = Utility.RandomMinMax(2501, 2644);
Timer.DelayCall(TimeSpan.FromSeconds(10), RemoveHueMod, target);
Timer.StartTimer(TimeSpan.FromSeconds(10), () => RemoveHueMod(target));
}
}
@ -113,7 +114,7 @@ namespace Server.Engines.Events
twin.MoveToWorld(m_From.Map.CanSpawnMobile(point) ? point : m_From.Location, m_From.Map);
Timer.DelayCall(TimeSpan.FromSeconds(5), DeleteTwin, twin);
Timer.StartTimer(TimeSpan.FromSeconds(5), () => DeleteTwin(twin));
}
}
@ -134,6 +135,7 @@ namespace Server.Engines.Events
return loc;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool CheckMobile(Mobile mobile) =>
mobile?.Map != null && !mobile.Deleted && mobile.Alive && mobile.Map != Map.Internal;
@ -214,15 +216,15 @@ namespace Server.Engines.Events
if (action == 0)
{
Timer.DelayCall(OneSecond, OneSecond, 10, Bleeding, from);
Timer.StartTimer(OneSecond, OneSecond, 10, () => Bleeding(from));
}
else if (action == 1)
{
Timer.DelayCall(TimeSpan.FromSeconds(2), SolidHueMobile, from);
Timer.StartTimer(TimeSpan.FromSeconds(2), () => SolidHueMobile(from));
}
else
{
Timer.DelayCall(TimeSpan.FromSeconds(2), MakeTwin, from);
Timer.StartTimer(TimeSpan.FromSeconds(2), () => MakeTwin(from));
}
}
}
@ -283,7 +285,7 @@ namespace Server.Engines.Events
m_From = from;
Name = $"{from.Name}\'s Naughty Twin";
Timer.DelayCall(TrickOrTreat.OneSecond, StealCandyOrGate, m_From);
Timer.StartTimer(TrickOrTreat.OneSecond, () => StealCandyOrGate(m_From));
}
}

View file

@ -7,7 +7,7 @@ namespace Server.Engines.Events
{
public static class PumpkinPatchSpawner
{
private static Timer m_Timer;
private static Timer _timer;
private static readonly Rectangle2D[] m_PumpkinFields =
{
@ -25,9 +25,10 @@ namespace Server.Engines.Events
{
var now = Core.Now;
// TODO: World timer to turn these on/off
if (now >= HolidaySettings.StartHalloween && now <= HolidaySettings.FinishHalloween)
{
m_Timer = Timer.DelayCall(TimeSpan.Zero, TimeSpan.FromSeconds(30), 0, PumpkinPatchSpawnerCallback);
_timer = Timer.DelayCall(TimeSpan.FromSeconds(30), 0, PumpkinPatchSpawnerCallback);
}
}
@ -35,6 +36,12 @@ namespace Server.Engines.Events
{
AddPumpkin(Map.Felucca);
AddPumpkin(Map.Trammel);
if (Core.Now > HolidaySettings.FinishHalloween)
{
_timer.Stop();
_timer = null;
}
}
private static void AddPumpkin(Map map)

View file

@ -92,16 +92,12 @@ namespace Server.Mobiles
}
}
public override Item NewHarmfulItem()
{
Item bad = new AcidSlime(TimeSpan.FromSeconds(10), 25, 30);
bad.Name = "gooey nasty pumpkin hummus";
bad.Hue = 144;
return bad;
}
public override Item NewHarmfulItem() =>
new PoolOfAcid(TimeSpan.FromSeconds(10), 25, 30)
{
Name = "gooey nasty pumpkin hummus",
Hue = 144
};
public override void OnDamage(int amount, Mobile from, bool willKill)
{

View file

@ -8,15 +8,15 @@ namespace Server.Engines.Events
{
public static class HalloweenHauntings
{
private static Timer m_Timer;
private static Timer m_ClearTimer;
private static Timer _timer;
private static Timer _clearTimer;
private static int m_TotalZombieLimit;
private static int m_DeathQueueLimit;
private static int m_QueueDelaySeconds;
private static int m_QueueClearIntervalSeconds;
private static List<PlayerMobile> m_DeathQueue;
private static HashSet<PlayerMobile> _deathQueue;
private static readonly Rectangle2D[] m_Cemetaries =
{
@ -39,7 +39,7 @@ namespace Server.Engines.Events
new(5224, 3655, 5, 14) // T2A
};
public static Dictionary<PlayerMobile, ZombieSkeleton> ReAnimated { get; set; }
internal static Dictionary<PlayerMobile, ZombieSkeleton> _reAnimated;
public static void Initialize()
{
@ -52,14 +52,13 @@ namespace Server.Engines.Events
var tick = TimeSpan.FromSeconds(m_QueueDelaySeconds);
var clear = TimeSpan.FromSeconds(m_QueueClearIntervalSeconds);
ReAnimated = new Dictionary<PlayerMobile, ZombieSkeleton>();
m_DeathQueue = new List<PlayerMobile>();
_reAnimated = new Dictionary<PlayerMobile, ZombieSkeleton>();
_deathQueue = new HashSet<PlayerMobile>();
if (today >= HolidaySettings.StartHalloween && today <= HolidaySettings.FinishHalloween)
{
m_Timer = Timer.DelayCall(tick, tick, Timer_Callback);
m_ClearTimer = Timer.DelayCall(clear, clear, Clear_Callback);
_timer = Timer.DelayCall(tick, 0, Timer_Callback);
_clearTimer = Timer.DelayCall(clear, 0, Clear_Callback);
EventSink.PlayerDeath += EventSink_PlayerDeath;
}
@ -67,65 +66,69 @@ namespace Server.Engines.Events
public static void EventSink_PlayerDeath(Mobile m)
{
if (m is PlayerMobile pm && !pm.Deleted && m_Timer.Running && !m_DeathQueue.Contains(pm) &&
m_DeathQueue.Count < m_DeathQueueLimit)
if (m is PlayerMobile { Deleted: false } pm &&
_timer.Running && !_deathQueue.Contains(pm) && _deathQueue.Count < m_DeathQueueLimit)
{
m_DeathQueue.Add(pm);
_deathQueue.Add(pm);
}
}
private static void Clear_Callback()
{
ReAnimated.Clear();
m_DeathQueue.Clear();
if (Core.Now <= HolidaySettings.FinishHalloween)
if (Core.Now > HolidaySettings.FinishHalloween)
{
m_ClearTimer.Stop();
_clearTimer.Stop();
_clearTimer = null;
_reAnimated = null;
_deathQueue = null;
return;
}
_reAnimated.Clear();
_deathQueue.Clear();
}
private static void Timer_Callback()
{
if (Core.Now > HolidaySettings.FinishHalloween)
{
_timer.Stop();
_timer = null;
return;
}
PlayerMobile player = null;
if (Core.Now <= HolidaySettings.FinishHalloween)
foreach (var entry in _deathQueue)
{
for (var index = 0; m_DeathQueue.Count > 0 && index < m_DeathQueue.Count; index++)
if (!_reAnimated.ContainsKey(entry))
{
var entry = m_DeathQueue[index];
if (!ReAnimated.ContainsKey(entry))
{
player = entry;
break;
}
}
if (player?.Deleted == false && ReAnimated.Count < m_TotalZombieLimit)
{
var map = Utility.RandomBool() ? Map.Trammel : Map.Felucca;
var home = GetRandomPointInRect(m_Cemetaries.RandomElement(), map);
if (map.CanSpawnMobile(home))
{
var zombieskel = new ZombieSkeleton(player);
ReAnimated.Add(player, zombieskel);
zombieskel.Home = home;
zombieskel.RangeHome = 10;
zombieskel.MoveToWorld(home, map);
m_DeathQueue.Remove(player);
}
player = entry;
break;
}
}
else
if (player?.Deleted != false || _reAnimated.Count >= m_TotalZombieLimit)
{
m_Timer.Stop();
return;
}
var map = Utility.RandomBool() ? Map.Trammel : Map.Felucca;
var home = GetRandomPointInRect(m_Cemetaries.RandomElement(), map);
if (map.CanSpawnMobile(home))
{
var zombieskel = new ZombieSkeleton(player);
_reAnimated.Add(player, zombieskel);
zombieskel.Home = home;
zombieskel.RangeHome = 10;
zombieskel.MoveToWorld(home, map);
_deathQueue.Remove(player);
}
}
@ -248,7 +251,7 @@ namespace Server.Engines.Events
{
if (_deadPlayer?.Deleted == false)
{
HalloweenHauntings.ReAnimated?.Remove(_deadPlayer);
HalloweenHauntings._reAnimated?.Remove(_deadPlayer);
}
}
}

View file

@ -26,7 +26,6 @@ namespace Server.Items
};
private int m_Flour;
private Timer m_Timer;
[Constructible]
public FlourMillEastAddon()
@ -49,7 +48,7 @@ namespace Server.Items
public bool IsFull => m_Flour >= MaxFlour;
[CommandProperty(AccessLevel.GameMaster)]
public bool IsWorking => m_Timer != null;
public bool IsWorking { get; private set; }
[CommandProperty(AccessLevel.GameMaster)]
public int MaxFlour => 2;
@ -72,17 +71,14 @@ namespace Server.Items
return;
}
m_Timer = Timer.DelayCall(TimeSpan.FromSeconds(5.0), FinishWorking_Callback, from);
Timer.StartTimer(TimeSpan.FromSeconds(5.0), () => FinishWorking_Callback(from));
IsWorking = true;
UpdateStage();
}
private void FinishWorking_Callback(Mobile from)
{
if (m_Timer != null)
{
m_Timer.Stop();
m_Timer = null;
}
IsWorking = false;
if (from?.Deleted == false && !Deleted && IsFull)
{

View file

@ -13,7 +13,6 @@ namespace Server.Items
};
private int m_Flour;
private Timer m_Timer;
[Constructible]
public FlourMillSouthAddon()
@ -36,7 +35,7 @@ namespace Server.Items
public bool IsFull => m_Flour >= MaxFlour;
[CommandProperty(AccessLevel.GameMaster)]
public bool IsWorking => m_Timer != null;
public bool IsWorking { get; private set; }
[CommandProperty(AccessLevel.GameMaster)]
public int MaxFlour => 2;
@ -59,17 +58,14 @@ namespace Server.Items
return;
}
m_Timer = Timer.DelayCall(TimeSpan.FromSeconds(5.0), FinishWorking_Callback, from);
Timer.StartTimer(TimeSpan.FromSeconds(5.0), () => FinishWorking_Callback(from));
IsWorking = true;
UpdateStage();
}
private void FinishWorking_Callback(Mobile from)
{
if (m_Timer != null)
{
m_Timer.Stop();
m_Timer = null;
}
IsWorking = false;
if (from?.Deleted == false && !Deleted && IsFull)
{

View file

@ -60,7 +60,7 @@ namespace Server.Items
if (version <= 1)
{
Timer.DelayCall(Fix, version);
Timer.StartTimer(() => Fix(version));
}
}

View file

@ -38,7 +38,7 @@ namespace Server.Items
SendLocalizedMessageTo(from, 500803); // You feel as though you've slept for days!
}
Timer.DelayCall(TimeSpan.FromHours(2.0), ReleaseUseLock_Callback, from, random);
Timer.StartTimer(TimeSpan.FromHours(2.0), () => ReleaseUseLock_Callback(from, random));
}
}

View file

@ -33,7 +33,7 @@ namespace Server.Items
private bool m_RewardAvailable;
// evaluate timer
private Timer m_Timer;
private Timer _timer;
// vacation info
private int m_VacationLeft;
@ -68,7 +68,7 @@ namespace Server.Items
Events = new List<int>();
m_Timer = Timer.DelayCall(EvaluationInterval, EvaluationInterval, Evaluate);
_timer = Timer.DelayCall(EvaluationInterval, EvaluationInterval, Evaluate);
}
public Aquarium(Serial serial) : base(serial)
@ -76,7 +76,6 @@ namespace Server.Items
}
// items info
[CommandProperty(AccessLevel.GameMaster)]
public int LiveCreatures { get; private set; }
@ -193,11 +192,8 @@ namespace Server.Items
public override void OnDelete()
{
if (m_Timer != null)
{
m_Timer.Stop();
m_Timer = null;
}
_timer.Stop();
_timer = null;
}
public override void OnDoubleClick(Mobile from)
@ -529,14 +525,7 @@ namespace Server.Items
writer.Write(3); // Version
// version 1
if (m_Timer != null)
{
writer.Write(m_Timer.Next);
}
else
{
writer.Write(Core.Now + EvaluationInterval);
}
writer.Write(_timer?.Running == true ? _timer.Next : Core.Now + EvaluationInterval);
// version 0
writer.Write(LiveCreatures);
@ -574,7 +563,7 @@ namespace Server.Items
next = Core.Now;
}
m_Timer = Timer.DelayCall(next - Core.Now, EvaluationInterval, Evaluate);
_timer = Timer.DelayCall(next - Core.Now, EvaluationInterval, Evaluate);
goto case 0;
}

View file

@ -6,7 +6,7 @@ namespace Server.Items
{
private static readonly TimeSpan DeathDelay = TimeSpan.FromMinutes(5);
private Timer m_Timer;
private TimerExecutionToken _timerToken;
[Constructible]
public BaseFish(int itemID) : base(itemID)
@ -23,19 +23,15 @@ namespace Server.Items
public virtual void StartTimer()
{
m_Timer?.Stop();
m_Timer = Timer.DelayCall(DeathDelay, Kill);
_timerToken.Cancel();
Timer.StartTimer(DeathDelay, Kill, out _timerToken);
InvalidateProperties();
}
public virtual void StopTimer()
{
m_Timer?.Stop();
m_Timer = null;
_timerToken.Cancel();
InvalidateProperties();
}
@ -74,7 +70,7 @@ namespace Server.Items
list.Add(GetDescription());
if (!Dead && m_Timer != null)
if (!Dead && _timerToken.Running)
{
list.Add(1074507); // Gasping for air
}

View file

@ -9,11 +9,9 @@ namespace Server.Items
protected FillableContent m_Content;
protected DateTime m_NextRespawnTime;
protected Timer m_RespawnTimer;
protected TimerExecutionToken _respawnTimerToken;
public FillableContainer(int itemID)
: base(itemID) =>
Movable = false;
public FillableContainer(int itemID) : base(itemID) => Movable = false;
public FillableContainer(Serial serial)
: base(serial)
@ -98,11 +96,7 @@ namespace Server.Items
{
base.OnAfterDelete();
if (m_RespawnTimer != null)
{
m_RespawnTimer.Stop();
m_RespawnTimer = null;
}
_respawnTimerToken.Cancel();
}
public int GetItemsCount()
@ -124,29 +118,24 @@ namespace Server.Items
if (canSpawn)
{
if (m_RespawnTimer == null)
if (!_respawnTimerToken.Running)
{
var mins = Utility.RandomMinMax(MinRespawnMinutes, MaxRespawnMinutes);
var delay = TimeSpan.FromMinutes(mins);
m_NextRespawnTime = Core.Now + delay;
m_RespawnTimer = Timer.DelayCall(delay, Respawn);
Timer.StartTimer(delay, Respawn, out _respawnTimerToken);
}
}
else if (m_RespawnTimer != null)
else if (_respawnTimerToken.Running)
{
m_RespawnTimer.Stop();
m_RespawnTimer = null;
_respawnTimerToken.Cancel();
}
}
public void Respawn()
{
if (m_RespawnTimer != null)
{
m_RespawnTimer.Stop();
m_RespawnTimer = null;
}
_respawnTimerToken.Cancel();
if (m_Content == null || Deleted)
{
@ -249,7 +238,7 @@ namespace Server.Items
writer.Write((int)ContentType);
if (m_RespawnTimer != null)
if (_respawnTimerToken.Running)
{
writer.Write(true);
writer.WriteDeltaTime(m_NextRespawnTime);
@ -280,7 +269,7 @@ namespace Server.Items
m_NextRespawnTime = reader.ReadDeltaTime();
var delay = m_NextRespawnTime - Core.Now;
m_RespawnTimer = Timer.DelayCall(delay > TimeSpan.Zero ? delay : TimeSpan.Zero, Respawn);
Timer.StartTimer(delay, Respawn, out _respawnTimerToken);
}
else
{
@ -341,7 +330,7 @@ namespace Server.Items
if (version == 0 && m_Content == null)
{
Timer.DelayCall(AcquireContent);
Timer.StartTimer(AcquireContent);
}
}
}

View file

@ -77,7 +77,7 @@ namespace Server.Items
}
}
Timer.DelayCall(TimeSpan.FromSeconds(1.0), Validate);
Timer.StartTimer(TimeSpan.FromSeconds(1.0), Validate);
}
private void Validate()

View file

@ -9,7 +9,7 @@ namespace Server.Items
private static Type[] m_TypesOfEntries;
private StealableInstance[] m_Artifacts;
private Timer m_RespawnTimer;
private Timer _respawnTimer;
private Dictionary<Item, StealableInstance> m_Table;
private StealableArtifactsSpawner() : base(1)
@ -24,7 +24,7 @@ namespace Server.Items
m_Artifacts[i] = new StealableInstance(Entries[i]);
}
m_RespawnTimer = Timer.DelayCall(TimeSpan.Zero, TimeSpan.FromMinutes(15.0), CheckRespawn);
_respawnTimer = Timer.DelayCall(TimeSpan.Zero, TimeSpan.FromMinutes(15.0), CheckRespawn);
}
public StealableArtifactsSpawner(Serial serial) : base(serial) => Instance = this;
@ -244,11 +244,8 @@ namespace Server.Items
{
base.OnDelete();
if (m_RespawnTimer != null)
{
m_RespawnTimer.Stop();
m_RespawnTimer = null;
}
_respawnTimer.Stop();
_respawnTimer = null;
foreach (var si in m_Artifacts)
{
@ -316,7 +313,7 @@ namespace Server.Items
m_Artifacts[i] = new StealableInstance(Entries[i]);
}
m_RespawnTimer = Timer.DelayCall(TimeSpan.Zero, TimeSpan.FromMinutes(15.0), CheckRespawn);
_respawnTimer = Timer.DelayCall(TimeSpan.Zero, TimeSpan.FromMinutes(15.0), CheckRespawn);
}
public class StealableEntry

View file

@ -48,7 +48,7 @@ namespace Server.Items
Unlink();
Timer.DelayCall(TimeSpan.FromMinutes(5.0), Delete);
Timer.StartTimer(TimeSpan.FromMinutes(5.0), Delete);
}
public void Unlink()

View file

@ -158,7 +158,7 @@ namespace Server.Items
if (Guild.NewGuildSystem && m_BeforeChangeover)
{
Timer.DelayCall(AddToHouse);
Timer.StartTimer(AddToHouse);
}
if (!Guild.NewGuildSystem && Guild == null)

View file

@ -1023,7 +1023,7 @@ namespace Server.Items
{
Movable = false;
Timer.DelayCall(TimeSpan.FromMinutes(2.0), Delete);
Timer.StartTimer(TimeSpan.FromMinutes(2.0), Delete);
}
public TreasureChestDirt(Serial serial) : base(serial)

View file

@ -1,106 +0,0 @@
using System;
using System.Collections.Generic;
using Server.Mobiles;
namespace Server.Items
{
public class AcidSlime : Item
{
private readonly DateTime m_Created;
private readonly TimeSpan m_Duration;
private readonly int m_MaxDamage;
private readonly int m_MinDamage;
private readonly Timer m_Timer;
private bool m_Drying;
[Constructible]
public AcidSlime() : this(TimeSpan.FromSeconds(10.0), 5, 10)
{
}
[Constructible]
public AcidSlime(TimeSpan duration, int minDamage, int maxDamage)
: base(0x122A)
{
Hue = 0x3F;
Movable = false;
m_MinDamage = minDamage;
m_MaxDamage = maxDamage;
m_Created = Core.Now;
m_Duration = duration;
m_Timer = Timer.DelayCall(TimeSpan.Zero, TimeSpan.FromSeconds(1), OnTick);
}
public AcidSlime(Serial serial) : base(serial)
{
}
public override string DefaultName => "slime";
public override void OnAfterDelete()
{
m_Timer?.Stop();
}
private void OnTick()
{
var now = Core.Now;
var age = now - m_Created;
if (age > m_Duration)
{
Delete();
}
else
{
if (!m_Drying && age > m_Duration - age)
{
m_Drying = true;
ItemID = 0x122B;
}
var toDamage = new List<Mobile>();
foreach (var m in GetMobilesInRange(0))
{
if (m.Alive && !m.IsDeadBondedPet && (!(m is BaseCreature bc) || bc.Controlled || bc.Summoned))
{
toDamage.Add(m);
}
}
for (var i = 0; i < toDamage.Count; i++)
{
Damage(toDamage[i]);
}
}
}
public override bool OnMoveOver(Mobile m)
{
Damage(m);
return true;
}
public void Damage(Mobile m)
{
var damage = Utility.RandomMinMax(m_MinDamage, m_MaxDamage);
if (Core.AOS)
{
AOS.Damage(m, damage, 0, 0, 0, 100, 0);
}
else
{
m.Damage(damage);
}
}
public override void Serialize(IGenericWriter writer)
{
}
public override void Deserialize(IGenericReader reader)
{
}
}
}

View file

@ -104,7 +104,7 @@ namespace Server.Items
to.Damage(1);
Timer.DelayCall(TimeSpan.FromSeconds(2.0), from.EndAction<Bola>);
Timer.StartTimer(TimeSpan.FromSeconds(2.0), from.EndAction<Bola>);
}
private static bool HasFreeHands(Mobile from)
@ -213,7 +213,7 @@ namespace Server.Items
from.Animate(11, 5, 1, true, false, 0);
from.MovingEffect(to, 0x26AC, 10, 0, false, false);
Timer.DelayCall(TimeSpan.FromSeconds(0.5), FinishThrow, from, to);
Timer.StartTimer(TimeSpan.FromSeconds(0.5), () => FinishThrow(from, to));
}
else
{

View file

@ -7,7 +7,7 @@ namespace Server.Items
{
public class DeceitBrazier : Item
{
private Timer m_Timer;
private TimerExecutionToken _timerToken;
[Constructible]
public DeceitBrazier() : base(0xE31)
@ -95,22 +95,21 @@ namespace Server.Items
PublicOverheadMessage(
MessageType.Regular,
0x3B2,
500761
); // Heed this warning well, and use this brazier at your own peril.
500761 // Heed this warning well, and use this brazier at your own peril.
);
_timerToken.Cancel();
}
public override void OnMovement(Mobile m, Point3D oldLocation)
{
if (NextSpawn < Core.Now) // means we haven't spawned anything if the next spawn is below
// means we haven't spawned anything if the next spawn is below
if (NextSpawn < Core.Now &&
Utility.InRange(m.Location, Location, 1) &&
!Utility.InRange(oldLocation, Location, 1) &&
m.Player && !(m.AccessLevel > AccessLevel.Player || m.Hidden) && !_timerToken.Running)
{
if (Utility.InRange(m.Location, Location, 1) && !Utility.InRange(oldLocation, Location, 1) && m.Player &&
!(m.AccessLevel > AccessLevel.Player || m.Hidden))
{
if (m_Timer?.Running != true)
{
m_Timer = Timer.DelayCall(TimeSpan.FromSeconds(2), HeedWarning);
}
}
Timer.StartTimer(TimeSpan.FromSeconds(2), HeedWarning, out _timerToken);
}
base.OnMovement(m, oldLocation);
@ -180,7 +179,7 @@ namespace Server.Items
DoEffect(spawnLoc, map);
Timer.DelayCall(TimeSpan.FromSeconds(1), SummonCreatureToWorld, bc, spawnLoc, map);
Timer.StartTimer(TimeSpan.FromSeconds(1), () => SummonCreatureToWorld(bc, spawnLoc, map));
NextSpawn = Core.Now + NextSpawnDelay;
}

View file

@ -286,24 +286,24 @@ namespace Server.Items
return;
}
if (trigger is Mobile mobile && mobile.Hidden && mobile.AccessLevel > AccessLevel.Player)
if (trigger is Mobile { Hidden: true } mobile && mobile.AccessLevel > AccessLevel.Player)
{
return;
}
if (SoundID > 0)
{
Timer.DelayCall(SoundDelay, PlaySound, trigger);
Timer.StartTimer(SoundDelay, () => PlaySound(trigger));
}
if (Sequence != null)
{
Timer.DelayCall(TriggerDelay, Sequence.DoEffect, trigger);
Timer.StartTimer(TriggerDelay, () => Sequence.DoEffect(trigger));
}
if (EffectType != ECEffectType.None)
{
Timer.DelayCall(EffectDelay, InternalDoEffect, trigger);
Timer.StartTimer(EffectDelay, () => InternalDoEffect(trigger));
}
}

View file

@ -11,7 +11,7 @@ namespace Server.Items
{
private Mobile m_LitBy;
private int m_Ticks;
private Timer m_Timer;
private TimerExecutionToken _timerToken;
private List<Mobile> m_Users;
[Constructible]
@ -55,15 +55,15 @@ namespace Server.Items
return;
}
if (m_Timer == null)
if (_timerToken.Running)
{
m_Timer = Timer.DelayCall(TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(1), OnFirebombTimerTick);
m_LitBy = from;
from.SendLocalizedMessage(1060582); // You light the firebomb. Throw it now!
from.SendLocalizedMessage(1060581); // You've already lit it! Better throw it now!
}
else
{
from.SendLocalizedMessage(1060581); // You've already lit it! Better throw it now!
Timer.StartTimer(TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(1), OnFirebombTimerTick, out _timerToken);
m_LitBy = from;
from.SendLocalizedMessage(1060582); // You light the firebomb. Throw it now!
}
m_Users ??= new List<Mobile>();
@ -80,7 +80,7 @@ namespace Server.Items
{
if (Deleted)
{
m_Timer.Stop();
_timerToken.Cancel();
return;
}
@ -158,7 +158,7 @@ namespace Server.Items
new FirebombField(m_LitBy, toDamage).MoveToWorld(Location, Map);
}
m_Timer.Stop();
_timerToken.Cancel();
Delete();
break;
}
@ -172,33 +172,35 @@ namespace Server.Items
return;
}
if (!(obj is IPoint3D p))
if (obj is not IPoint3D p)
{
return;
}
SpellHelper.GetSurfaceTop(ref p);
var loc = new Point3D(p);
var map = Map;
from.RevealingAction();
var to = p as IEntity ?? new Entity(Serial.Zero, new Point3D(p), Map);
var to = p as IEntity ?? new Entity(Serial.Zero, loc, map);
Effects.SendMovingEffect(from, to, ItemID, 7, 0, false, false, Hue);
Timer.DelayCall(TimeSpan.FromSeconds(1.0), FirebombReposition_OnTick, p, Map);
Timer.StartTimer(TimeSpan.FromSeconds(1.0),
() =>
{
if (Deleted)
{
return;
}
MoveToWorld(loc, map);
}
);
Internalize();
}
private void FirebombReposition_OnTick(IPoint3D p, Map map)
{
if (Deleted)
{
return;
}
MoveToWorld(new Point3D(p), map);
}
private class ThrowTarget : Target
{
public ThrowTarget(Firebomb bomb)
@ -219,7 +221,7 @@ namespace Server.Items
private readonly List<Mobile> m_Burning;
private readonly DateTime m_Expire;
private readonly Mobile m_LitBy;
private readonly Timer m_Timer;
private TimerExecutionToken _timerToken;
public FirebombField(Mobile litBy, List<Mobile> toDamage) : base(0x376A)
{
@ -227,7 +229,7 @@ namespace Server.Items
m_LitBy = litBy;
m_Expire = Core.Now + TimeSpan.FromSeconds(10);
m_Burning = toDamage;
m_Timer = Timer.DelayCall(TimeSpan.FromSeconds(1.0), TimeSpan.FromSeconds(1.0), OnFirebombFieldTimerTick);
Timer.StartTimer(TimeSpan.FromSeconds(1.0), TimeSpan.FromSeconds(1.0), OnFirebombFieldTimerTick, out _timerToken);
}
public FirebombField(Serial serial) : base(serial)
@ -266,7 +268,7 @@ namespace Server.Items
{
if (Deleted)
{
m_Timer.Stop();
_timerToken.Cancel();
return;
}
@ -297,7 +299,7 @@ namespace Server.Items
if (Core.Now >= m_Expire)
{
m_Timer.Stop();
_timerToken.Cancel();
Delete();
}
}

View file

@ -37,10 +37,10 @@ namespace Server.Items
Effects.PlaySound(GetWorldLocation(), Map, 0x387);
Timer.DelayCall(TimeSpan.FromSeconds(0.25), Down1);
Timer.DelayCall(TimeSpan.FromSeconds(0.50), Down2);
Timer.StartTimer(TimeSpan.FromSeconds(0.25), Down1);
Timer.StartTimer(TimeSpan.FromSeconds(0.50), Down2);
Timer.DelayCall(TimeSpan.FromSeconds(5.00), BackUp);
Timer.StartTimer(TimeSpan.FromSeconds(5.00), BackUp);
m_NextUse = Core.Now + TimeSpan.FromSeconds(10.0);
}

View file

@ -139,7 +139,7 @@ namespace Server.Items
}
}
Timer.DelayCall(Refresh);
Timer.StartTimer(Refresh);
}
}
}

View file

@ -4,13 +4,14 @@ using Server.Mobiles;
namespace Server.Items
{
[TypeAlias("Server.Items.AcidSlime")]
public class PoolOfAcid : Item
{
private readonly DateTime m_Created;
private readonly TimeSpan m_Duration;
private readonly int m_MaxDamage;
private readonly int m_MinDamage;
private readonly Timer m_Timer;
private TimerExecutionToken _timerToken;
private bool m_Drying;
[Constructible]
@ -30,7 +31,7 @@ namespace Server.Items
m_Created = Core.Now;
m_Duration = duration;
m_Timer = Timer.DelayCall(TimeSpan.Zero, TimeSpan.FromSeconds(1), OnTick);
Timer.StartTimer(TimeSpan.Zero, TimeSpan.FromSeconds(1), OnTick, out _timerToken);
}
public PoolOfAcid(Serial serial) : base(serial)
@ -39,9 +40,9 @@ namespace Server.Items
public override string DefaultName => "a pool of acid";
public override void OnAfterDelete()
public override void OnDelete()
{
m_Timer?.Stop();
_timerToken.Cancel();
}
private void OnTick()

View file

@ -234,7 +234,7 @@ namespace Server.Items
}
else
{
Timer.DelayCall(m_Delay, DoTeleport, m);
Timer.StartTimer(m_Delay, () => DoTeleport(m));
}
}
@ -454,7 +454,7 @@ namespace Server.Items
);
}
Timer.DelayCall(TimeSpan.FromSeconds(5.0), m.EndAction, this);
Timer.StartTimer(TimeSpan.FromSeconds(5.0), () => m.EndAction(this));
}
return false;
@ -671,7 +671,7 @@ namespace Server.Items
public class WaitTeleporter : KeywordTeleporter
{
private static Dictionary<Mobile, TeleportingInfo> m_Table;
private static Dictionary<Mobile, TeleportingInfo> m_Table = new Dictionary<Mobile, TeleportingInfo>();
[Constructible]
public WaitTeleporter()
@ -700,8 +700,6 @@ namespace Server.Items
public static void Initialize()
{
m_Table = new Dictionary<Mobile, TeleportingInfo>();
EventSink.Logout += EventSink_Logout;
}
@ -709,7 +707,7 @@ namespace Server.Items
{
if (from != null && m_Table.Remove(from, out var info))
{
info.Timer.Stop();
info.TimerToken.Cancel();
}
}
@ -731,11 +729,6 @@ namespace Server.Items
return $"{s} second{(s == 1 ? "" : "s")}";
}
private void EndLock(Mobile m)
{
m.EndAction(this);
}
public override void StartTeleport(Mobile m)
{
if (m_Table.TryGetValue(m, out var info))
@ -755,16 +748,16 @@ namespace Server.Items
if (ShowTimeRemaining)
{
m.SendMessage("Time remaining: {0}", FormatTime(info.Timer.Next - Core.Now));
m.SendMessage("Time remaining: {0}", FormatTime(info.TimerToken.Next - Core.Now));
}
Timer.DelayCall(TimeSpan.FromSeconds(5), EndLock, m);
Timer.StartTimer(TimeSpan.FromSeconds(5), () => m.EndAction(this));
}
return;
}
info.Timer.Stop();
info.TimerToken.Cancel();
}
if (StartMessage != null)
@ -782,7 +775,8 @@ namespace Server.Items
}
else
{
m_Table[m] = new TeleportingInfo(this, Timer.DelayCall(Delay, DoTeleport, m));
Timer.StartTimer(Delay, () => DoTeleport(m), out var timerToken);
m_Table[m] = new TeleportingInfo(this, timerToken);
}
}
@ -821,21 +815,21 @@ namespace Server.Items
private class TeleportingInfo
{
public TeleportingInfo(WaitTeleporter tele, Timer t)
public TeleportingInfo(WaitTeleporter tele, TimerExecutionToken token)
{
Teleporter = tele;
Timer = t;
TimerToken = token;
}
public WaitTeleporter Teleporter { get; }
public Timer Timer { get; }
public TimerExecutionToken TimerToken { get; }
}
}
public class TimeoutTeleporter : Teleporter
{
private Dictionary<Mobile, Timer> m_Teleporting;
private Dictionary<Mobile, TimerExecutionToken> m_Teleporting;
[Constructible]
public TimeoutTeleporter() : this(new Point3D(0, 0, 0))
@ -845,7 +839,7 @@ namespace Server.Items
[Constructible]
public TimeoutTeleporter(Point3D pointDest, Map mapDest = null, bool creatures = false)
: base(pointDest, mapDest, creatures) =>
m_Teleporting = new Dictionary<Mobile, Timer>();
m_Teleporting = new Dictionary<Mobile, TimerExecutionToken>();
public TimeoutTeleporter(Serial serial)
: base(serial)
@ -862,19 +856,16 @@ namespace Server.Items
private void StartTimer(Mobile m, TimeSpan delay)
{
if (m_Teleporting.TryGetValue(m, out var t))
{
t.Stop();
}
m_Teleporting[m] = Timer.DelayCall(delay, StartTeleport, m);
StopTimer(m);
Timer.StartTimer(delay, () => StartTeleport(m), out var timerToken);
m_Teleporting[m] = timerToken;
}
public void StopTimer(Mobile m)
{
if (m_Teleporting.Remove(m, out var t))
{
t.Stop();
t.Cancel();
}
}
@ -923,7 +914,7 @@ namespace Server.Items
var version = reader.ReadInt();
TimeoutDelay = reader.ReadTimeSpan();
m_Teleporting = new Dictionary<Mobile, Timer>();
m_Teleporting = new Dictionary<Mobile, TimerExecutionToken>();
var count = reader.ReadInt();

View file

@ -129,7 +129,7 @@ namespace Server.Items
}
}
Timer.DelayCall(StopBroadcasting);
Timer.StartTimer(StopBroadcasting);
}
private void StopBroadcasting()

View file

@ -74,7 +74,7 @@ namespace Server.Items
private class LogoutGump : Gump
{
private readonly Bedroll m_Bedroll;
private readonly Timer m_CloseTimer;
private TimerExecutionToken _closeTimerToken;
private readonly CampfireEntry m_Entry;
@ -83,7 +83,7 @@ namespace Server.Items
m_Entry = entry;
m_Bedroll = bedroll;
m_CloseTimer = Timer.DelayCall(TimeSpan.FromSeconds(10.0), CloseGump);
Timer.StartTimer(TimeSpan.FromSeconds(10.0), CloseGump, out _closeTimerToken);
AddBackground(0, 0, 400, 350, 0xA28);
@ -108,7 +108,7 @@ namespace Server.Items
{
var pm = m_Entry.Player;
m_CloseTimer.Stop();
_closeTimerToken.Cancel();
if (Campfire.GetEntry(pm) != m_Entry)
{

View file

@ -20,7 +20,7 @@ namespace Server.Items
private readonly List<CampfireEntry> m_Entries;
private readonly Timer m_Timer;
private TimerExecutionToken _timerToken;
public Campfire() : base(0xDE3)
{
@ -30,7 +30,7 @@ namespace Server.Items
m_Entries = new List<CampfireEntry>();
Created = Core.Now;
m_Timer = Timer.DelayCall(TimeSpan.FromSeconds(1.0), TimeSpan.FromSeconds(1.0), OnTick);
Timer.StartTimer(TimeSpan.FromSeconds(1.0), TimeSpan.FromSeconds(1.0), OnTick, out _timerToken);
}
public Campfire(Serial serial) : base(serial)
@ -161,7 +161,7 @@ namespace Server.Items
public override void OnAfterDelete()
{
m_Timer?.Stop();
_timerToken.Cancel();
ClearEntries();
}

View file

@ -307,7 +307,7 @@ namespace Server.Items
}
}
Timer.DelayCall(FixMovingCrate);
Timer.StartTimer(FixMovingCrate);
}
private void FixMovingCrate()

View file

@ -181,7 +181,7 @@ namespace Server.Items
var index = 0;
Timer.DelayCall(
Timer.StartTimer(
TimeSpan.FromSeconds(1.0),
TimeSpan.FromSeconds(1.25),
14,

View file

@ -94,7 +94,7 @@ namespace Server.Items
if (version < 1)
{
Timer.DelayCall(UpdateWeight);
Timer.StartTimer(UpdateWeight);
}
}

View file

@ -7,7 +7,7 @@ namespace Server.Items
{
public abstract class BaseConflagrationPotion : BasePotion
{
private static readonly Dictionary<Mobile, Timer> m_Delay = new();
private static readonly Dictionary<Mobile, TimerExecutionToken> m_Delay = new();
private readonly List<Mobile> m_Users = new();
public BaseConflagrationPotion(PotionEffect effect) : base(0xF06, effect) => Hue = 0x489;
@ -107,8 +107,10 @@ namespace Server.Items
public static void AddDelay(Mobile m)
{
m_Delay.TryGetValue(m, out var timer);
timer?.Stop();
m_Delay[m] = Timer.DelayCall(TimeSpan.FromSeconds(30), EndDelay, m);
timer.Cancel();
Timer.StartTimer(TimeSpan.FromSeconds(30), () => EndDelay(m), out timer);
m_Delay[m] = timer;
}
public static int GetDelay(Mobile m)
@ -125,7 +127,7 @@ namespace Server.Items
{
if (m_Delay.Remove(m, out var timer))
{
timer.Stop();
timer.Cancel();
}
}
@ -142,7 +144,7 @@ namespace Server.Items
return;
}
if (!(targeted is IPoint3D p) || from.Map == null)
if (targeted is not IPoint3D p || from.Map == null)
{
return;
}
@ -151,6 +153,8 @@ namespace Server.Items
AddDelay(from);
SpellHelper.GetSurfaceTop(ref p);
var loc = new Point3D(p);
var map = from.Map;
from.RevealingAction();
@ -162,11 +166,11 @@ namespace Server.Items
}
else
{
to = new Entity(Serial.Zero, new Point3D(p), from.Map);
to = new Entity(Serial.Zero, loc, map);
}
Effects.SendMovingEffect(from, to, 0xF0D, 7, 0, false, false, Potion.Hue);
Timer.DelayCall(TimeSpan.FromSeconds(1.5), Potion.Explode, from, new Point3D(p), from.Map);
Timer.StartTimer(TimeSpan.FromSeconds(1.5), () => Potion.Explode(from, loc, map));
}
}

View file

@ -9,7 +9,7 @@ namespace Server.Items
{
public abstract class BaseConfusionBlastPotion : BasePotion
{
private static readonly Dictionary<Mobile, Timer> m_Delay = new();
private static readonly Dictionary<Mobile, TimerExecutionToken> m_Delay = new();
private readonly List<Mobile> m_Users = new();
public BaseConfusionBlastPotion(PotionEffect effect) : base(0xF06, effect) => Hue = 0x48D;
@ -93,7 +93,7 @@ namespace Server.Items
Geometry.Circle2D(loc, map, Radius, BlastEffect, 270, 90);
Timer.DelayCall(TimeSpan.FromSeconds(0.3), CircleEffect2, loc, map);
Timer.StartTimer(TimeSpan.FromSeconds(0.3), () => CircleEffect2(loc, map));
foreach (var mobile in map.GetMobilesInRange(loc, Radius))
{
@ -125,8 +125,10 @@ namespace Server.Items
public static void AddDelay(Mobile m)
{
m_Delay.TryGetValue(m, out var timer);
timer?.Stop();
m_Delay[m] = Timer.DelayCall(TimeSpan.FromSeconds(60), EndDelay, m);
timer.Cancel();
Timer.StartTimer(TimeSpan.FromSeconds(60), () => EndDelay(m), out timer);
m_Delay[m] = timer;
}
public static int GetDelay(Mobile m)
@ -143,7 +145,7 @@ namespace Server.Items
{
if (m_Delay.Remove(m, out var timer))
{
timer.Stop();
timer.Cancel();
}
}
@ -169,6 +171,8 @@ namespace Server.Items
AddDelay(from);
SpellHelper.GetSurfaceTop(ref p);
var loc = new Point3D(p);
var map = from.Map;
from.RevealingAction();
@ -180,11 +184,11 @@ namespace Server.Items
}
else
{
to = new Entity(Serial.Zero, new Point3D(p), from.Map);
to = new Entity(Serial.Zero, loc, map);
}
Effects.SendMovingEffect(from, to, 0xF0D, 7, 0, false, false, Potion.Hue);
Timer.DelayCall(TimeSpan.FromSeconds(1.0), Potion.Explode, from, new Point3D(p), from.Map);
Timer.StartTimer(TimeSpan.FromSeconds(1.0), () => Potion.Explode(from, loc, map));
}
}
}

View file

@ -15,7 +15,7 @@ namespace Server.Items
private static readonly bool InstantExplosion = false; // Should explosion potions explode on impact?
private static readonly bool RelativeLocation = false; // Is the explosion target location relative for mobiles?
private Timer m_Timer;
private TimerExecutionToken _timerToken;
public BaseExplosionPotion(PotionEffect effect) : base(0xF0D, effect)
{
@ -93,7 +93,7 @@ namespace Server.Items
from.Target = new ThrowTarget(this);
if (m_Timer == null)
if (!_timerToken.Running)
{
from.SendLocalizedMessage(500236); // You should throw it now!
@ -101,21 +101,25 @@ namespace Server.Items
if (Core.ML)
{
m_Timer = Timer.DelayCall(
// 3.6 seconds explosion delay
Timer.StartTimer(
TimeSpan.FromSeconds(1.0),
TimeSpan.FromSeconds(1.25),
5,
() => Detonate_OnTick(from, timer--)
); // 3.6 seconds explosion delay
5, // TODO: Should this be 4?
() => Detonate_OnTick(from, timer--),
out _timerToken
);
}
else
{
m_Timer = Timer.DelayCall(
// 2.6 seconds explosion delay
Timer.StartTimer(
TimeSpan.FromSeconds(0.75),
TimeSpan.FromSeconds(1.0),
4,
() => Detonate_OnTick(from, timer--)
); // 2.6 seconds explosion delay
() => Detonate_OnTick(from, timer--),
out _timerToken
);
}
}
}
@ -150,7 +154,7 @@ namespace Server.Items
}
Explode(from, true, loc, map);
m_Timer = null;
_timerToken.Cancel();
}
else
{
@ -282,7 +286,7 @@ namespace Server.Items
return;
}
if (!(targeted is IPoint3D p))
if (targeted is not IPoint3D p)
{
return;
}
@ -295,16 +299,17 @@ namespace Server.Items
}
SpellHelper.GetSurfaceTop(ref p);
var loc = new Point3D(p);
from.RevealingAction();
IEntity to = new Entity(Serial.Zero, new Point3D(p), map);
IEntity to = new Entity(Serial.Zero, loc, map);
if (p is Mobile m)
{
if (!RelativeLocation) // explosion location = current mob location.
{
p = m.Location;
loc = m.Location;
}
else
{
@ -320,7 +325,7 @@ namespace Server.Items
}
Potion.Internalize();
Timer.DelayCall(TimeSpan.FromSeconds(1.0), Potion.Reposition_OnTick, from, new Point3D(p), map);
Timer.StartTimer(TimeSpan.FromSeconds(1.0), () => Potion.Reposition_OnTick(from, loc, map));
}
}
}

View file

@ -65,7 +65,7 @@ namespace Server.Items
Consume();
}
Timer.DelayCall(TimeSpan.FromSeconds(Delay), from.EndAction<BaseHealPotion>);
Timer.StartTimer(TimeSpan.FromSeconds(Delay), from.EndAction<BaseHealPotion>);
}
else
{

View file

@ -5,7 +5,7 @@ namespace Server.Items
{
public class InvisibilityPotion : BasePotion
{
private static readonly Dictionary<Mobile, Timer> m_Table = new();
private static readonly Dictionary<Mobile, TimerExecutionToken> m_Table = new();
[Constructible]
public InvisibilityPotion() : base(0xF0A, PotionEffect.Invisibility) => Hue = 0x48D;
@ -31,7 +31,8 @@ namespace Server.Items
}
Consume();
m_Table[from] = Timer.DelayCall(TimeSpan.FromSeconds(2), Hide, from);
Timer.StartTimer(TimeSpan.FromSeconds(2), () => Hide(from), out var timerToken);
m_Table[from] = timerToken;
PlayDrinkEffect(from);
}
@ -53,7 +54,7 @@ namespace Server.Items
RemoveTimer(m);
Timer.DelayCall(TimeSpan.FromSeconds(30), EndHide, m);
Timer.StartTimer(TimeSpan.FromSeconds(30), () => EndHide(m));
}
public static void EndHide(Mobile m)
@ -73,7 +74,7 @@ namespace Server.Items
m.SendLocalizedMessage(1073187); // The invisibility effect is interrupted.
}
timer.Stop();
timer.Cancel();
}
}

View file

@ -66,7 +66,13 @@ namespace Server.Items
}
from.BeginAction<FireHorn>();
Timer.DelayCall(Core.AOS ? TimeSpan.FromSeconds(6.0) : TimeSpan.FromSeconds(12.0), EndAction, from);
Timer.StartTimer(Core.AOS ? TimeSpan.FromSeconds(6.0) : TimeSpan.FromSeconds(12.0),
() =>
{
from.EndAction<FireHorn>();
from.SendLocalizedMessage(1049621); // You catch your breath.
}
);
var music = from.Skills.Musicianship.Fixed;
@ -199,12 +205,6 @@ namespace Server.Items
}
}
private static void EndAction(Mobile m)
{
m?.EndAction<FireHorn>();
m?.SendLocalizedMessage(1049621); // You catch your breath.
}
public override void Serialize(IGenericWriter writer)
{
base.Serialize(writer);

View file

@ -403,7 +403,7 @@ namespace Server.Items
if (m_UsesRemaining != oldUses)
{
Timer.DelayCall(InvalidateProperties);
Timer.StartTimer(InvalidateProperties);
}
}
@ -567,8 +567,8 @@ namespace Server.Items
{
SetInstrument(from, this);
// Delay of 7 second before being able to play another instrument again
new InternalTimer(from).Start();
// Delay of 6 second before being able to play another instrument again
Timer.StartTimer(TimeSpan.FromSeconds(6), from.EndAction<BaseInstrument>);
if (CheckMusicianship(from))
{
@ -601,20 +601,5 @@ namespace Server.Items
{
from.PlaySound(FailureSound);
}
private class InternalTimer : Timer
{
private readonly Mobile m_From;
public InternalTimer(Mobile from) : base(TimeSpan.FromSeconds(6.0))
{
m_From = from;
}
protected override void OnTick()
{
m_From.EndAction<BaseInstrument>();
}
}
}
}

View file

@ -69,10 +69,10 @@ namespace Server.Items
if (CombatCheck(from, target))
{
Timer.DelayCall(TimeSpan.FromSeconds(1.0), OnHit, from, target, weapon);
Timer.StartTimer(TimeSpan.FromSeconds(1.0), () => OnHit(from, target, weapon));
}
Timer.DelayCall(TimeSpan.FromSeconds(2.5), ResetUsing, from);
Timer.StartTimer(TimeSpan.FromSeconds(2.5), () => from.NinjaWepCooldown = false);
}
else
{
@ -81,11 +81,6 @@ namespace Server.Items
}
}
private static void ResetUsing(PlayerMobile from)
{
from.NinjaWepCooldown = false;
}
private static void Unload(Mobile from, INinjaWeapon weapon)
{
if (weapon.UsesRemaining > 0)

View file

@ -99,7 +99,7 @@ namespace Server.Items
private int m_Count;
private int m_ItemID;
private Timer m_Timer;
private TimerExecutionToken _timerToken;
[Constructible]
public DawnsMusicBox() : base(0x2AF9)
@ -214,7 +214,7 @@ namespace Server.Items
public void PlayMusic(Mobile m, MusicName music)
{
if (m_Timer?.Running == true)
if (_timerToken.Running)
{
EndMusic(m);
}
@ -224,16 +224,12 @@ namespace Server.Items
}
m.NetState.SendPlayMusic(music);
m_Timer = Timer.DelayCall(TimeSpan.FromSeconds(0.5), TimeSpan.FromSeconds(0.5), 4, Animate);
Timer.StartTimer(TimeSpan.FromSeconds(0.5), TimeSpan.FromSeconds(0.5), 4, Animate, out _timerToken);
}
public void EndMusic(Mobile m)
{
if (m_Timer?.Running == true)
{
m_Timer.Stop();
}
_timerToken.Cancel();
m.NetState.SendStopMusic();
if (m_Count > 0)

View file

@ -47,7 +47,7 @@ namespace Server.Items
{
private int m_Charges;
private Timer m_Timer;
private TimerExecutionToken _timerToken;
[Constructible]
public FountainOfLife(int charges = 10)
@ -55,7 +55,7 @@ namespace Server.Items
{
m_Charges = charges;
m_Timer = Timer.DelayCall(RechargeTime, RechargeTime, Recharge);
Timer.StartTimer(RechargeTime, RechargeTime, Recharge, out _timerToken);
}
public FountainOfLife(Serial serial)
@ -130,7 +130,7 @@ namespace Server.Items
public override void OnDelete()
{
m_Timer?.Stop();
_timerToken.Cancel();
base.OnDelete();
}
@ -142,7 +142,7 @@ namespace Server.Items
writer.WriteEncodedInt(0); // version
writer.Write(m_Charges);
writer.Write(m_Timer.Next);
writer.Write(_timerToken.Next);
}
public override void Deserialize(IGenericReader reader)
@ -159,11 +159,11 @@ namespace Server.Items
if (next < now)
{
m_Timer = Timer.DelayCall(RechargeTime, Recharge);
Timer.StartTimer(RechargeTime, Recharge, out _timerToken);
}
else
{
m_Timer = Timer.DelayCall(next - now, RechargeTime, Recharge);
Timer.StartTimer(next - now, RechargeTime, Recharge, out _timerToken);
}
}

View file

@ -38,7 +38,7 @@ namespace Server.Items
if (ItemID == 0x2A69 || ItemID == 0x2A6D)
{
Up();
Timer.DelayCall(TimeSpan.FromSeconds(0.5), TimeSpan.FromSeconds(0.5), 2, Up);
Timer.StartTimer(TimeSpan.FromSeconds(0.5), TimeSpan.FromSeconds(0.5), 2, Up);
}
}
else if (Utility.InRange(old, Location, 2) && !Utility.InRange(m.Location, Location, 2))
@ -46,7 +46,7 @@ namespace Server.Items
if (ItemID == 0x2A6C || ItemID == 0x2A70)
{
Down();
Timer.DelayCall(TimeSpan.FromSeconds(0.5), TimeSpan.FromSeconds(0.5), 2, Down);
Timer.StartTimer(TimeSpan.FromSeconds(0.5), TimeSpan.FromSeconds(0.5), 2, Down);
}
}
}

View file

@ -6,13 +6,12 @@ namespace Server.Items
[Flippable(0x2A5D, 0x2A61)]
public class DisturbingPortraitComponent : AddonComponent
{
private Timer m_Timer;
private TimerExecutionToken _timerToken;
public DisturbingPortraitComponent() : base(0x2A5D) => m_Timer = Timer.DelayCall(
TimeSpan.FromMinutes(3),
TimeSpan.FromMinutes(3),
Change
);
public DisturbingPortraitComponent() : base(0x2A5D)
{
Timer.StartTimer(TimeSpan.FromMinutes(3), TimeSpan.FromMinutes(3), Change, out _timerToken);
}
public DisturbingPortraitComponent(Serial serial) : base(serial)
{
@ -36,10 +35,7 @@ namespace Server.Items
{
base.OnAfterDelete();
if (m_Timer?.Running == true)
{
m_Timer.Stop();
}
_timerToken.Cancel();
}
public override void Serialize(IGenericWriter writer)
@ -55,7 +51,7 @@ namespace Server.Items
var version = reader.ReadEncodedInt();
m_Timer = Timer.DelayCall(TimeSpan.FromMinutes(3), TimeSpan.FromMinutes(3), Change);
Timer.StartTimer(TimeSpan.FromMinutes(3), TimeSpan.FromMinutes(3), Change, out _timerToken);
}
private void Change()

View file

@ -5,7 +5,7 @@ namespace Server.Items
[FlippableAddon(Direction.South, Direction.East)]
public class SacrificialAltarAddon : BaseAddonContainer
{
private Timer m_Timer;
private TimerExecutionToken _timerToken;
[Constructible]
public SacrificialAltarAddon() : base(0x2A9B)
@ -25,6 +25,12 @@ namespace Server.Items
public override int DefaultGumpID => 0x107;
public override int DefaultDropSound => 0x42;
private void StartTimer()
{
_timerToken.Cancel();
Timer.StartTimer(TimeSpan.FromMinutes(3), Empty, out _timerToken);
}
public override bool OnDragDrop(Mobile from, Item dropped)
{
if (!base.OnDragDrop(from, dropped))
@ -41,9 +47,7 @@ namespace Server.Items
{
SendLocalizedMessageTo(from, 1010442); // The item will be deleted in three minutes
m_Timer?.Stop();
m_Timer = Timer.DelayCall(TimeSpan.FromMinutes(3), Empty);
StartTimer();
}
return true;
@ -65,9 +69,7 @@ namespace Server.Items
{
SendLocalizedMessageTo(from, 1010442); // The item will be deleted in three minutes
m_Timer?.Stop();
m_Timer = Timer.DelayCall(TimeSpan.FromMinutes(3), Empty);
StartTimer();
}
return true;
@ -88,7 +90,7 @@ namespace Server.Items
if (Items.Count > 0)
{
m_Timer = Timer.DelayCall(TimeSpan.FromMinutes(3), Empty);
StartTimer();
}
}
@ -131,9 +133,7 @@ namespace Server.Items
}
}
m_Timer?.Stop();
m_Timer = null;
_timerToken.Cancel();
}
}

View file

@ -6,13 +6,17 @@ namespace Server.Items
[Flippable(0x2A65, 0x2A67)]
public class UnsettlingPortraitComponent : AddonComponent
{
private Timer m_Timer;
private TimerExecutionToken _timerToken;
public UnsettlingPortraitComponent() : base(0x2A65) => m_Timer = Timer.DelayCall(
TimeSpan.FromMinutes(3),
TimeSpan.FromMinutes(3),
ChangeDirection
);
public UnsettlingPortraitComponent() : base(0x2A65)
{
Timer.StartTimer(
TimeSpan.FromMinutes(3),
TimeSpan.FromMinutes(3),
ChangeDirection,
out _timerToken
);
}
public UnsettlingPortraitComponent(Serial serial) : base(serial)
{
@ -36,7 +40,7 @@ namespace Server.Items
{
base.OnAfterDelete();
m_Timer?.Stop();
_timerToken.Cancel();
}
public override void Serialize(IGenericWriter writer)
@ -52,7 +56,7 @@ namespace Server.Items
var version = reader.ReadEncodedInt();
m_Timer = Timer.DelayCall(TimeSpan.FromMinutes(3), TimeSpan.FromMinutes(3), ChangeDirection);
Timer.StartTimer(TimeSpan.FromMinutes(3), TimeSpan.FromMinutes(3), ChangeDirection, out _timerToken);
}
private void ChangeDirection()

View file

@ -9,7 +9,7 @@ namespace Server.Items
public BaseFruitTreeAddon()
{
Timer.DelayCall(TimeSpan.FromMinutes(5), Respawn);
Timer.StartTimer(TimeSpan.FromMinutes(5), Respawn);
}
public BaseFruitTreeAddon(Serial serial) : base(serial)
@ -48,7 +48,7 @@ namespace Server.Items
{
if (--m_Fruits == 0)
{
Timer.DelayCall(TimeSpan.FromMinutes(30), Respawn);
Timer.StartTimer(TimeSpan.FromMinutes(30), Respawn);
}
from.SendLocalizedMessage(501016); // You pick some fruit and put it in your backpack.

View file

@ -54,15 +54,15 @@ namespace Server.Items
{
from.Location = Location;
Timer.DelayCall(TimeSpan.FromSeconds(0.5), Activate, c, from);
Timer.StartTimer(TimeSpan.FromSeconds(0.5), () => Activate(c, from));
}
else
{
from.LocalOverheadMessage(
MessageType.Regular,
0,
501777
); // Hmm... you suspect that if you used this again, it might hurt.
501777 // Hmm... you suspect that if you used this again, it might hurt.
);
}
}
else
@ -135,27 +135,19 @@ namespace Server.Items
); // Hmm... you suspect that if you used this again, it might hurt.
SpellHelper.Damage(TimeSpan.Zero, from, Utility.Dice(2, 10, 5));
Timer.DelayCall(TimeSpan.FromSeconds(0.5), TimeSpan.FromSeconds(0.5), 2, Deactivate, c);
Timer.StartTimer(TimeSpan.FromSeconds(0.5), TimeSpan.FromSeconds(0.5), 2, () => Deactivate(c));
}
private void Deactivate(AddonComponent c)
{
if (c.ItemID == 0x1269)
c.ItemID = c.ItemID switch
{
c.ItemID = 0x1260;
}
else if (c.ItemID == 0x1260)
{
c.ItemID = 0x125E;
}
else if (c.ItemID == 0x1247)
{
c.ItemID = 0x1246;
}
else if (c.ItemID == 0x1246)
{
c.ItemID = 0x1230;
}
0x1269 => 0x1260,
0x1260 => 0x125E,
0x1247 => 0x1246,
0x1246 => 0x1230,
_ => c.ItemID
};
}
}

View file

@ -26,15 +26,15 @@ namespace Server.Items
from.Location = Location;
c.ItemID = 0x124A;
Timer.DelayCall(TimeSpan.FromSeconds(0.5), TimeSpan.FromSeconds(0.5), 3, Activate, c, from);
Timer.StartTimer(TimeSpan.FromSeconds(0.5), TimeSpan.FromSeconds(0.5), 3, () => Activate(c, from));
}
else
{
from.LocalOverheadMessage(
MessageType.Regular,
0,
501777
); // Hmm... you suspect that if you used this again, it might hurt.
501777 // Hmm... you suspect that if you used this again, it might hurt.
);
}
}
else
@ -98,12 +98,7 @@ namespace Server.Items
); // Hmm... you suspect that if you used this again, it might hurt.
SpellHelper.Damage(TimeSpan.Zero, from, Utility.Dice(2, 10, 5));
Timer.DelayCall(TimeSpan.FromSeconds(1), Deactivate, c);
}
private void Deactivate(AddonComponent c)
{
c.ItemID = 0x1249;
Timer.StartTimer(TimeSpan.FromSeconds(1), () => c.ItemID = 0x1249);
}
}

View file

@ -175,7 +175,7 @@ namespace Server.Items
}
}
Timer.DelayCall(ValidatePlacement);
Timer.StartTimer(ValidatePlacement);
}
public void ValidatePlacement()

Some files were not shown because too many files have changed in this diff Show more