feat(timers): Adds timer pooling, fixes timer related bugs, and changes timer api (#667)
### Changes/Fixes:
* Adds timer pooling.
* Allows pool to be configurable in ModernUO.json
* Pool replenishes itself asynchronously if depleted.
* Fixes an issue with barkeeps and town criers
* Fixes an issue with incognito buff icons not being removed
* Fixes an issue with polymorph name mod not being removed
* Fixes several places where timers go on forever even after an object is deleted, keeping a reference (memory leak)
* Eliminates the timer for MiningCart altogether.
* Deletes `AcidSlime` since it is a duplicate of `PoolOfAcid`
* Fixes HonorableExecution and standardizes the code for other Bushido moves.
## Changes to the Timer API:
```cs
public class Timer
{
// Creates a timer that will be returned to the pool once execution stops.
public static void StartTimer(Action callback);
public static void StartTimer(TimeSpan delay, Action callback);
public static void StartTimer(TimeSpan delay, TimeSpan interval, Action callback);
public static void StartTimer(TimeSpan interval, int count, Action callback);
public static void StartTimer(TimeSpan delay, TimeSpan interval, int count, Action callback);
// Creates a timer and returns a token for more control. Requires manual cancellation in order for the timer to be returned to the pool.
// If the token is dereferenced, the timer will be dereferenced too. While not returning a timer to the pool is not considered hazardous, it does defeat the purpose of pooled timers.
public static void StartTimer(Action callback, out TimerExecutionToken token);
public static void StartTimer(TimeSpan delay, Action callback, out TimerExecutionToken token);
public static void StartTimer(TimeSpan delay, TimeSpan interval, Action callback, out TimerExecutionToken token);
public static void StartTimer(TimeSpan interval, int count, Action callback, out TimerExecutionToken token);
public static void StartTimer(TimeSpan delay, TimeSpan interval, int count, Action callback, out TimerExecutionToken token);
// If you aren't sure how to use the API above, or you don't care about performance, then you can use the old RunUO Timer.DelayCall
public static DelayCallTimer DelayCall(Action callback);
public static DelayCallTimer DelayCall(TimeSpan delay, Action callback);
public static DelayCallTimer DelayCall(TimeSpan delay, TimeSpan interval, Action callback);
public static DelayCallTimer DelayCall(TimeSpan interval, int count, Action callback);
public static DelayCallTimer DelayCall(TimeSpan delay, TimeSpan interval, int count, Action callback);
}
public struct TimerExecutionToken
{
public bool Running { get; }
public int Index { get; }
public int RemainingCount { get; }
public DateTime Next { get; }
}
```
## When to use `TimerExecutionToken`?
Use tokens when you want to gain the performance benefit of using a pooled timer, but you need one of the following:
* Access to the next time the timer will tick:`token.Next`
* Access to which interval, how many intervals there are, or how many are remaining: `token.Index`, `token.Count`, and `token.RemainingCount`
* Stop a timer manually.
* Determine if the timer is running: `timer.Running`
* See notes below about requirements for using tokens!
## Notes about using the TimerExecutionToken:
When you opt-in to receive a token, you must call `Cancel()` to return the timer. This can be done inside of the callback, or outside of the callback at any time.
If this is not called and your timer is an infinite interval, then you will create a potential memory leak, or null pointer exception in your callback.
If the timer ends and is stopped, but cancel is not called, then the timer will never return to the pool and stay referenced until the token is deleted or cancel is called. (Memory leak)
## Is this thread safe?
No. The ModernUO timer system is not thread safe at all. If you require a thread safe timer system, contact me and I'll help adapt this system. Keep in mind that there is a massive performance hit to make this thread safe when there are literally no use cases for it.
If you need to synchronize execution, meaning you want to execute code from another thread on the core thread. Let's say you have a discord bot that is pushing commands to the game server. Then use `EventLoopContext.Post(SendOrPostCallback callback, object state);`.
This commit is contained in:
parent
b4de631f96
commit
9b554f69b0
219 changed files with 1897 additions and 2241 deletions
|
|
@ -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)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ namespace Server.Items
|
|||
|
||||
if (version <= 1)
|
||||
{
|
||||
Timer.DelayCall(Fix, version);
|
||||
Timer.StartTimer(() => Fix(version));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -77,7 +77,7 @@ namespace Server.Items
|
|||
}
|
||||
}
|
||||
|
||||
Timer.DelayCall(TimeSpan.FromSeconds(1.0), Validate);
|
||||
Timer.StartTimer(TimeSpan.FromSeconds(1.0), Validate);
|
||||
}
|
||||
|
||||
private void Validate()
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -158,7 +158,7 @@ namespace Server.Items
|
|||
|
||||
if (Guild.NewGuildSystem && m_BeforeChangeover)
|
||||
{
|
||||
Timer.DelayCall(AddToHouse);
|
||||
Timer.StartTimer(AddToHouse);
|
||||
}
|
||||
|
||||
if (!Guild.NewGuildSystem && Guild == null)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -139,7 +139,7 @@ namespace Server.Items
|
|||
}
|
||||
}
|
||||
|
||||
Timer.DelayCall(Refresh);
|
||||
Timer.StartTimer(Refresh);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
||||
|
|
|
|||
|
|
@ -129,7 +129,7 @@ namespace Server.Items
|
|||
}
|
||||
}
|
||||
|
||||
Timer.DelayCall(StopBroadcasting);
|
||||
Timer.StartTimer(StopBroadcasting);
|
||||
}
|
||||
|
||||
private void StopBroadcasting()
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -307,7 +307,7 @@ namespace Server.Items
|
|||
}
|
||||
}
|
||||
|
||||
Timer.DelayCall(FixMovingCrate);
|
||||
Timer.StartTimer(FixMovingCrate);
|
||||
}
|
||||
|
||||
private void FixMovingCrate()
|
||||
|
|
|
|||
|
|
@ -181,7 +181,7 @@ namespace Server.Items
|
|||
|
||||
var index = 0;
|
||||
|
||||
Timer.DelayCall(
|
||||
Timer.StartTimer(
|
||||
TimeSpan.FromSeconds(1.0),
|
||||
TimeSpan.FromSeconds(1.25),
|
||||
14,
|
||||
|
|
|
|||
|
|
@ -94,7 +94,7 @@ namespace Server.Items
|
|||
|
||||
if (version < 1)
|
||||
{
|
||||
Timer.DelayCall(UpdateWeight);
|
||||
Timer.StartTimer(UpdateWeight);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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>();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -175,7 +175,7 @@ namespace Server.Items
|
|||
}
|
||||
}
|
||||
|
||||
Timer.DelayCall(ValidatePlacement);
|
||||
Timer.StartTimer(ValidatePlacement);
|
||||
}
|
||||
|
||||
public void ValidatePlacement()
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ namespace Server.Items
|
|||
if (freeze)
|
||||
{
|
||||
m.Frozen = true;
|
||||
Timer.DelayCall(TimeSpan.FromSeconds(message == 1095162 ? 2.0 : 1.25), EndFall_Callback, m);
|
||||
Timer.StartTimer(TimeSpan.FromSeconds(message == 1095162 ? 2.0 : 1.25), () => m.Frozen = false);
|
||||
}
|
||||
|
||||
m.SendLocalizedMessage(message);
|
||||
|
|
@ -68,10 +68,11 @@ namespace Server.Items
|
|||
}
|
||||
|
||||
var p = new Point3D(Location);
|
||||
var map = Map;
|
||||
|
||||
if (SpellHelper.FindValidSpawnLocation(Map, ref p, true))
|
||||
if (SpellHelper.FindValidSpawnLocation(map, ref p, true))
|
||||
{
|
||||
Timer.DelayCall(TimeSpan.FromSeconds(0), m.MoveToWorld, p, m.Map);
|
||||
Timer.StartTimer(TimeSpan.FromSeconds(0), () => m.MoveToWorld(p, map));
|
||||
}
|
||||
|
||||
action = 21 + Utility.Random(2);
|
||||
|
|
@ -85,25 +86,20 @@ namespace Server.Items
|
|||
|
||||
if (action > 0)
|
||||
{
|
||||
Timer.DelayCall(TimeSpan.FromSeconds(0.4), BeginFall_Callback, m, action, sound);
|
||||
Timer.StartTimer(TimeSpan.FromSeconds(0.4),
|
||||
() =>
|
||||
{
|
||||
if (!m.Mounted)
|
||||
{
|
||||
m.Animate(action, 1, 1, false, true, 0);
|
||||
}
|
||||
|
||||
m.PlaySound(sound);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private static void BeginFall_Callback(Mobile m, int action, int sound)
|
||||
{
|
||||
if (!m.Mounted)
|
||||
{
|
||||
m.Animate(action, 1, 1, false, true, 0);
|
||||
}
|
||||
|
||||
m.PlaySound(sound);
|
||||
}
|
||||
|
||||
private static void EndFall_Callback(Mobile m)
|
||||
{
|
||||
m.Frozen = false;
|
||||
}
|
||||
|
||||
public override void Serialize(IGenericWriter writer)
|
||||
{
|
||||
base.Serialize(writer);
|
||||
|
|
|
|||
|
|
@ -77,7 +77,7 @@ namespace Server.Items
|
|||
|
||||
var version = reader.ReadInt();
|
||||
|
||||
Timer.DelayCall(FixMovingCrate);
|
||||
Timer.StartTimer(FixMovingCrate);
|
||||
}
|
||||
|
||||
private void FixMovingCrate()
|
||||
|
|
|
|||
|
|
@ -275,7 +275,7 @@ namespace Server.Items
|
|||
}
|
||||
}
|
||||
|
||||
Timer.DelayCall(TimeSpan.FromMinutes(1.0), TimeSpan.FromMinutes(1.0), CheckEnd_OnTick);
|
||||
Timer.StartTimer(TimeSpan.FromMinutes(1.0), TimeSpan.FromMinutes(1.0), CheckEnd_OnTick);
|
||||
}
|
||||
|
||||
public bool ValidLocation() =>
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ namespace Server.Mobiles
|
|||
|
||||
if (version < 1)
|
||||
{
|
||||
Timer.DelayCall(TimeSpan.FromSeconds(0), OnAfterDeserialize_Callback);
|
||||
Timer.StartTimer(TimeSpan.FromSeconds(0), OnAfterDeserialize_Callback);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,14 +5,15 @@ namespace Server.Items
|
|||
{
|
||||
public class PlagueBeastBlood : PlagueBeastComponent
|
||||
{
|
||||
private readonly Timer m_Timer;
|
||||
|
||||
public PlagueBeastBlood() : base(0x122C, 0) => m_Timer = Timer.DelayCall(
|
||||
TimeSpan.FromSeconds(1.5),
|
||||
TimeSpan.FromSeconds(1.5),
|
||||
3,
|
||||
Hemorrhage
|
||||
);
|
||||
public PlagueBeastBlood() : base(0x122C, 0)
|
||||
{
|
||||
Timer.StartTimer(
|
||||
TimeSpan.FromSeconds(1.5),
|
||||
TimeSpan.FromSeconds(1.5),
|
||||
3,
|
||||
Hemorrhage
|
||||
);
|
||||
}
|
||||
|
||||
public PlagueBeastBlood(Serial serial) : base(serial)
|
||||
{
|
||||
|
|
@ -22,69 +23,57 @@ namespace Server.Items
|
|||
|
||||
public bool Starting => ItemID == 0x122C;
|
||||
|
||||
public override void OnAfterDelete()
|
||||
{
|
||||
if (m_Timer?.Running == true)
|
||||
{
|
||||
m_Timer.Stop();
|
||||
}
|
||||
}
|
||||
|
||||
public override bool OnBandage(Mobile from)
|
||||
{
|
||||
if (IsAccessibleTo(from) && !Patched)
|
||||
if (!IsAccessibleTo(from) || Patched)
|
||||
{
|
||||
if (m_Timer?.Running == true)
|
||||
{
|
||||
m_Timer.Stop();
|
||||
}
|
||||
|
||||
if (Starting)
|
||||
{
|
||||
X += 2;
|
||||
Y -= 9;
|
||||
|
||||
if (Organ is PlagueBeastRubbleOrgan)
|
||||
{
|
||||
Y -= 5;
|
||||
}
|
||||
else if (Organ is PlagueBeastBackupOrgan)
|
||||
{
|
||||
X += 7;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
X -= 4;
|
||||
Y -= 2;
|
||||
}
|
||||
|
||||
ItemID = 0x1765;
|
||||
|
||||
var pack = Owner?.Backpack;
|
||||
|
||||
if (pack != null)
|
||||
{
|
||||
for (var i = 0; i < pack.Items.Count; i++)
|
||||
{
|
||||
if (pack.Items[i] is PlagueBeastMainOrgan main && main.Complete)
|
||||
{
|
||||
main.FinishOpening(from);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PublicOverheadMessage(MessageType.Regular, 0x3B2, 1071916); // * You patch up the wound with a bandage *
|
||||
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
if (Starting)
|
||||
{
|
||||
X += 2;
|
||||
Y -= 9;
|
||||
|
||||
switch (Organ)
|
||||
{
|
||||
case PlagueBeastRubbleOrgan:
|
||||
Y -= 5;
|
||||
break;
|
||||
case PlagueBeastBackupOrgan:
|
||||
X += 7;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
X -= 4;
|
||||
Y -= 2;
|
||||
}
|
||||
|
||||
ItemID = 0x1765;
|
||||
|
||||
var pack = Owner?.Backpack;
|
||||
|
||||
if (pack != null)
|
||||
{
|
||||
for (var i = 0; i < pack.Items.Count; i++)
|
||||
{
|
||||
if (pack.Items[i] is PlagueBeastMainOrgan main && main.Complete)
|
||||
{
|
||||
main.FinishOpening(from);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PublicOverheadMessage(MessageType.Regular, 0x3B2, 1071916); // * You patch up the wound with a bandage *
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void Hemorrhage()
|
||||
{
|
||||
if (Patched)
|
||||
if (Deleted || Patched)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,7 +41,13 @@ namespace Server.Items
|
|||
|
||||
if (owner != null)
|
||||
{
|
||||
Timer.DelayCall(TimeSpan.FromSeconds(1), KillParent, owner);
|
||||
Timer.StartTimer(TimeSpan.FromSeconds(1),
|
||||
() =>
|
||||
{
|
||||
owner.Unfreeze();
|
||||
owner.Kill();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
@ -50,12 +56,6 @@ namespace Server.Items
|
|||
return false;
|
||||
}
|
||||
|
||||
private void KillParent(PlagueBeastLord parent)
|
||||
{
|
||||
parent.Unfreeze();
|
||||
parent.Kill();
|
||||
}
|
||||
|
||||
public override void Serialize(IGenericWriter writer)
|
||||
{
|
||||
base.Serialize(writer);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ namespace Server.Items
|
|||
{
|
||||
public class PlagueBeastOrgan : PlagueBeastInnard
|
||||
{
|
||||
private Timer m_Timer;
|
||||
private bool _opening;
|
||||
|
||||
public PlagueBeastOrgan(int itemID = 1, int hue = 0) : base(itemID, hue)
|
||||
{
|
||||
|
|
@ -15,7 +15,7 @@ namespace Server.Items
|
|||
Movable = false;
|
||||
Visible = itemID <= 1;
|
||||
|
||||
Timer.DelayCall(Initialize);
|
||||
Timer.StartTimer(Initialize);
|
||||
}
|
||||
|
||||
public PlagueBeastOrgan(Serial serial) : base(serial)
|
||||
|
|
@ -52,9 +52,20 @@ namespace Server.Items
|
|||
{
|
||||
if (IsCuttable && IsAccessibleTo(from))
|
||||
{
|
||||
if (!Opened && m_Timer == null)
|
||||
if (!Opened && !_opening)
|
||||
{
|
||||
m_Timer = Timer.DelayCall(TimeSpan.FromSeconds(3), FinishOpening, from);
|
||||
_opening = true;
|
||||
void Open()
|
||||
{
|
||||
_opening = false;
|
||||
if (!Deleted)
|
||||
{
|
||||
FinishOpening(from);
|
||||
}
|
||||
}
|
||||
|
||||
Timer.StartTimer(TimeSpan.FromSeconds(3), Open);
|
||||
|
||||
scissors.PublicOverheadMessage(MessageType.Regular, 0x3B2, 1071897); // You carefully cut into the organ.
|
||||
return true;
|
||||
}
|
||||
|
|
@ -65,14 +76,6 @@ namespace Server.Items
|
|||
return false;
|
||||
}
|
||||
|
||||
public override void OnAfterDelete()
|
||||
{
|
||||
if (m_Timer?.Running == true)
|
||||
{
|
||||
m_Timer.Stop();
|
||||
}
|
||||
}
|
||||
|
||||
public virtual bool OnLifted(Mobile from, PlagueBeastComponent c) => c.IsGland || c.IsBrain;
|
||||
|
||||
public virtual bool OnDropped(Mobile from, Item item, PlagueBeastComponent to) => false;
|
||||
|
|
@ -80,7 +83,6 @@ namespace Server.Items
|
|||
public virtual void FinishOpening(Mobile from)
|
||||
{
|
||||
Opened = true;
|
||||
|
||||
Owner?.PlaySound(0x50);
|
||||
}
|
||||
|
||||
|
|
@ -177,8 +179,8 @@ namespace Server.Items
|
|||
with.PublicOverheadMessage(
|
||||
MessageType.Regular,
|
||||
0x3B2,
|
||||
1071896
|
||||
); // This is too crude an implement for such a procedure.
|
||||
1071896 // This is too crude an implement for such a procedure.
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -314,8 +316,8 @@ namespace Server.Items
|
|||
from.LocalOverheadMessage(
|
||||
MessageType.Regular,
|
||||
0x3B2,
|
||||
1071901
|
||||
); // * As you cut the vein, a cloud of poison is expelled from the plague beast's organ, and the plague beast dissolves into a puddle of goo *
|
||||
1071901 // * As you cut the vein, a cloud of poison is expelled from the plague beast's organ, and the plague beast dissolves into a puddle of goo *
|
||||
);
|
||||
from.ApplyPoison(from, Poison.Greater);
|
||||
from.PlaySound(0x22F);
|
||||
|
||||
|
|
@ -378,8 +380,8 @@ namespace Server.Items
|
|||
with.PublicOverheadMessage(
|
||||
MessageType.Regular,
|
||||
0x3B2,
|
||||
1071896
|
||||
); // This is too crude an implement for such a procedure.
|
||||
1071896 // This is too crude an implement for such a procedure.
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -405,7 +407,7 @@ namespace Server.Items
|
|||
if (to.Hue == 0x1 && m_Gland == null && item is PlagueBeastGland)
|
||||
{
|
||||
m_Gland = item;
|
||||
Timer.DelayCall(TimeSpan.FromSeconds(3), FinishHealing);
|
||||
Timer.StartTimer(TimeSpan.FromSeconds(3), FinishHealing);
|
||||
from.SendAsciiMessage(0x3B2, "* You place the healthy gland inside the organ sac *");
|
||||
item.Movable = false;
|
||||
|
||||
|
|
@ -435,7 +437,7 @@ namespace Server.Items
|
|||
Components[i].Hue = 0x6;
|
||||
}
|
||||
|
||||
Timer.DelayCall(TimeSpan.FromSeconds(2), OpenOrgan);
|
||||
Timer.StartTimer(TimeSpan.FromSeconds(2), OpenOrgan);
|
||||
}
|
||||
|
||||
public void OpenOrgan()
|
||||
|
|
@ -524,8 +526,8 @@ namespace Server.Items
|
|||
from.LocalOverheadMessage(
|
||||
MessageType.Regular,
|
||||
0x34,
|
||||
1071913
|
||||
); // You place the organ in the fleshy receptacle near the core.
|
||||
1071913 // You place the organ in the fleshy receptacle near the core.
|
||||
);
|
||||
|
||||
if (Owner != null)
|
||||
{
|
||||
|
|
@ -536,8 +538,8 @@ namespace Server.Items
|
|||
from.LocalOverheadMessage(
|
||||
MessageType.Regular,
|
||||
0x34,
|
||||
1071922
|
||||
); // The plague beast is still bleeding from open wounds. You must seal any bleeding wounds before the core will open!
|
||||
1071922 // The plague beast is still bleeding from open wounds. You must seal any bleeding wounds before the core will open!
|
||||
);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ namespace Server.Items
|
|||
{
|
||||
public class PlagueBeastVein : PlagueBeastComponent
|
||||
{
|
||||
private Timer m_Timer;
|
||||
private bool _cutting;
|
||||
|
||||
public PlagueBeastVein(int itemID, int hue) : base(itemID, hue) => Cut = false;
|
||||
|
||||
|
|
@ -19,14 +19,15 @@ namespace Server.Items
|
|||
{
|
||||
if (IsAccessibleTo(from))
|
||||
{
|
||||
if (!Cut && m_Timer == null)
|
||||
if (!Cut && !_cutting)
|
||||
{
|
||||
m_Timer = Timer.DelayCall(TimeSpan.FromSeconds(3), CuttingDone, from);
|
||||
_cutting = true;
|
||||
Timer.StartTimer(TimeSpan.FromSeconds(3), () => CuttingDone(from));
|
||||
scissors.PublicOverheadMessage(
|
||||
MessageType.Regular,
|
||||
0x3B2,
|
||||
1071899
|
||||
); // You begin cutting through the vein.
|
||||
1071899 // You begin cutting through the vein.
|
||||
);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -36,26 +37,12 @@ namespace Server.Items
|
|||
return false;
|
||||
}
|
||||
|
||||
public override void OnAfterDelete()
|
||||
{
|
||||
if (m_Timer?.Running == true)
|
||||
{
|
||||
m_Timer.Stop();
|
||||
}
|
||||
}
|
||||
|
||||
private void CuttingDone(Mobile from)
|
||||
{
|
||||
_cutting = false;
|
||||
Cut = true;
|
||||
|
||||
if (ItemID == 0x1B1C)
|
||||
{
|
||||
ItemID = 0x1B1B;
|
||||
}
|
||||
else
|
||||
{
|
||||
ItemID = 0x1B1C;
|
||||
}
|
||||
ItemID = ItemID == 0x1B1C ? 0x1B1B : 0x1B1C;
|
||||
|
||||
Owner?.PlaySound(0x199);
|
||||
|
||||
|
|
|
|||
|
|
@ -97,7 +97,7 @@ namespace Server.Items
|
|||
Effects.SendTargetParticles(from, 0x373A, 35, 45, 0x00, 0x00, 9502, (EffectLayer)255, 0x100);
|
||||
|
||||
pm.AcceleratedStart = Core.Now + TimeSpan.FromMinutes(15);
|
||||
Timer.DelayCall(TimeSpan.FromMinutes(15), Expire_Callback, from);
|
||||
Timer.StartTimer(TimeSpan.FromMinutes(15), () => Expire_Callback(from));
|
||||
|
||||
pm.AcceleratedSkill = Skill;
|
||||
|
||||
|
|
|
|||
|
|
@ -16,8 +16,6 @@ namespace Server.Items
|
|||
|
||||
public class MiningCart : BaseAddon, IRewardItem
|
||||
{
|
||||
private Timer m_Timer;
|
||||
|
||||
[Constructible]
|
||||
public MiningCart(MiningCartType type)
|
||||
{
|
||||
|
|
@ -67,7 +65,7 @@ namespace Server.Items
|
|||
break;
|
||||
}
|
||||
|
||||
m_Timer = Timer.DelayCall(TimeSpan.FromDays(1), TimeSpan.FromDays(1), GiveResources);
|
||||
_lastResourceTime = Core.Now;
|
||||
}
|
||||
|
||||
public MiningCart(Serial serial) : base(serial)
|
||||
|
|
@ -78,42 +76,68 @@ namespace Server.Items
|
|||
{
|
||||
get
|
||||
{
|
||||
var deed = new MiningCartDeed();
|
||||
deed.IsRewardItem = IsRewardItem;
|
||||
deed.Gems = Gems;
|
||||
deed.Ore = Ore;
|
||||
|
||||
return deed;
|
||||
GiveResources();
|
||||
return new MiningCartDeed { IsRewardItem = IsRewardItem, Gems = _gems, Ore = _ore };
|
||||
}
|
||||
}
|
||||
|
||||
[CommandProperty(AccessLevel.GameMaster)]
|
||||
public MiningCartType CartType { get; private set; }
|
||||
|
||||
[CommandProperty(AccessLevel.GameMaster)]
|
||||
public int Gems { get; set; }
|
||||
private int _gems;
|
||||
|
||||
[CommandProperty(AccessLevel.GameMaster)]
|
||||
public int Ore { get; set; }
|
||||
public int Gems
|
||||
{
|
||||
get
|
||||
{
|
||||
GiveResources();
|
||||
return _gems;
|
||||
}
|
||||
set => _gems = value;
|
||||
}
|
||||
|
||||
private int _ore;
|
||||
|
||||
[CommandProperty(AccessLevel.GameMaster)]
|
||||
public int Ore
|
||||
{
|
||||
get
|
||||
{
|
||||
GiveResources();
|
||||
return _ore;
|
||||
}
|
||||
set => _ore = value;
|
||||
}
|
||||
|
||||
[CommandProperty(AccessLevel.GameMaster)]
|
||||
public bool IsRewardItem { get; set; }
|
||||
|
||||
private void GiveResources()
|
||||
{
|
||||
var amount = (Core.Now - _lastResourceTime).Days;
|
||||
if (amount <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
switch (CartType)
|
||||
{
|
||||
case MiningCartType.OreSouth:
|
||||
case MiningCartType.OreEast:
|
||||
Ore = Math.Min(100, Ore + 10);
|
||||
_ore = Math.Min(100, _ore + amount * 10);
|
||||
break;
|
||||
case MiningCartType.GemSouth:
|
||||
case MiningCartType.GemEast:
|
||||
Gems = Math.Min(50, Gems + 5);
|
||||
_gems = Math.Min(50, _gems + amount * 5);
|
||||
break;
|
||||
}
|
||||
|
||||
_lastResourceTime += TimeSpan.FromDays(amount);
|
||||
}
|
||||
|
||||
private DateTime _lastResourceTime;
|
||||
|
||||
public override void OnComponentUsed(AddonComponent c, Mobile from)
|
||||
{
|
||||
var house = BaseHouse.FindHouseAt(this);
|
||||
|
|
@ -140,100 +164,105 @@ namespace Server.Items
|
|||
if (!from.InRange(GetWorldLocation(), 2) || !from.InLOS(this) || !(from.Z - Z > -3 && from.Z - Z < 3))
|
||||
{
|
||||
from.LocalOverheadMessage(MessageType.Regular, 0x3B2, 1019045); // I can't reach that.
|
||||
return;
|
||||
}
|
||||
else if (house?.HasSecureAccess(from, SecureLevel.Friends) == true)
|
||||
{
|
||||
switch (CartType)
|
||||
{
|
||||
case MiningCartType.OreSouth:
|
||||
case MiningCartType.OreEast:
|
||||
if (Ore > 0)
|
||||
{
|
||||
var ingots = Utility.Random(9) switch
|
||||
{
|
||||
0 => (Item)new IronIngot(),
|
||||
1 => new DullCopperIngot(),
|
||||
2 => new ShadowIronIngot(),
|
||||
3 => new CopperIngot(),
|
||||
4 => new BronzeIngot(),
|
||||
5 => new GoldIngot(),
|
||||
6 => new AgapiteIngot(),
|
||||
7 => new VeriteIngot(),
|
||||
8 => new ValoriteIngot(),
|
||||
_ => null
|
||||
};
|
||||
|
||||
var amount = Math.Min(10, Ore);
|
||||
// ReSharper disable once PossibleNullReferenceException
|
||||
ingots.Amount = amount;
|
||||
|
||||
if (!from.PlaceInBackpack(ingots))
|
||||
{
|
||||
ingots.Delete();
|
||||
from.SendLocalizedMessage(1078837); // Your backpack is full! Please make room and try again.
|
||||
}
|
||||
else
|
||||
{
|
||||
PublicOverheadMessage(MessageType.Regular, 0, 1094724, amount.ToString()); // Ore: ~1_COUNT~
|
||||
Ore -= amount;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
from.SendLocalizedMessage(1094725); // There are no more resources available at this time.
|
||||
}
|
||||
|
||||
break;
|
||||
case MiningCartType.GemSouth:
|
||||
case MiningCartType.GemEast:
|
||||
if (Gems > 0)
|
||||
{
|
||||
Item gems = Utility.Random(15) switch
|
||||
{
|
||||
0 => new Amber(),
|
||||
1 => new Amethyst(),
|
||||
2 => new Citrine(),
|
||||
3 => new Diamond(),
|
||||
4 => new Emerald(),
|
||||
5 => new Ruby(),
|
||||
6 => new Sapphire(),
|
||||
7 => new StarSapphire(),
|
||||
8 => new Tourmaline(),
|
||||
|
||||
// Mondain's Legacy gems
|
||||
9 => new PerfectEmerald(),
|
||||
10 => new DarkSapphire(),
|
||||
11 => new Turquoise(),
|
||||
12 => new EcruCitrine(),
|
||||
13 => new FireRuby(),
|
||||
_ => new BlueDiamond() // 14
|
||||
};
|
||||
|
||||
var amount = Math.Min(5, Gems);
|
||||
gems.Amount = amount;
|
||||
|
||||
if (!from.PlaceInBackpack(gems))
|
||||
{
|
||||
gems.Delete();
|
||||
from.SendLocalizedMessage(1078837); // Your backpack is full! Please make room and try again.
|
||||
}
|
||||
else
|
||||
{
|
||||
PublicOverheadMessage(MessageType.Regular, 0, 1094723, amount.ToString()); // Gems: ~1_COUNT~
|
||||
Gems -= amount;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
from.SendLocalizedMessage(1094725); // There are no more resources available at this time.
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
if (house?.HasSecureAccess(from, SecureLevel.Friends) != true)
|
||||
{
|
||||
from.SendLocalizedMessage(1061637); // You are not allowed to access this.
|
||||
return;
|
||||
}
|
||||
|
||||
GiveResources();
|
||||
|
||||
switch (CartType)
|
||||
{
|
||||
case MiningCartType.OreSouth:
|
||||
case MiningCartType.OreEast:
|
||||
if (_ore > 0)
|
||||
{
|
||||
var ingots = Utility.Random(9) switch
|
||||
{
|
||||
0 => (Item)new IronIngot(),
|
||||
1 => new DullCopperIngot(),
|
||||
2 => new ShadowIronIngot(),
|
||||
3 => new CopperIngot(),
|
||||
4 => new BronzeIngot(),
|
||||
5 => new GoldIngot(),
|
||||
6 => new AgapiteIngot(),
|
||||
7 => new VeriteIngot(),
|
||||
_ => new ValoriteIngot(),
|
||||
};
|
||||
|
||||
var amount = Math.Min(10, _ore);
|
||||
ingots.Amount = amount;
|
||||
|
||||
if (!from.PlaceInBackpack(ingots))
|
||||
{
|
||||
ingots.Delete();
|
||||
from.SendLocalizedMessage(
|
||||
1078837
|
||||
); // Your backpack is full! Please make room and try again.
|
||||
}
|
||||
else
|
||||
{
|
||||
PublicOverheadMessage(MessageType.Regular, 0, 1094724, amount.ToString()); // Ore: ~1_COUNT~
|
||||
_ore -= amount;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
from.SendLocalizedMessage(1094725); // There are no more resources available at this time.
|
||||
}
|
||||
|
||||
break;
|
||||
case MiningCartType.GemSouth:
|
||||
case MiningCartType.GemEast:
|
||||
if (_gems > 0)
|
||||
{
|
||||
Item gems = Utility.Random(15) switch
|
||||
{
|
||||
0 => new Amber(),
|
||||
1 => new Amethyst(),
|
||||
2 => new Citrine(),
|
||||
3 => new Diamond(),
|
||||
4 => new Emerald(),
|
||||
5 => new Ruby(),
|
||||
6 => new Sapphire(),
|
||||
7 => new StarSapphire(),
|
||||
8 => new Tourmaline(),
|
||||
|
||||
// Mondain's Legacy gems
|
||||
9 => new PerfectEmerald(),
|
||||
10 => new DarkSapphire(),
|
||||
11 => new Turquoise(),
|
||||
12 => new EcruCitrine(),
|
||||
13 => new FireRuby(),
|
||||
_ => new BlueDiamond() // 14
|
||||
};
|
||||
|
||||
var amount = Math.Min(5, _gems);
|
||||
gems.Amount = amount;
|
||||
|
||||
if (!from.PlaceInBackpack(gems))
|
||||
{
|
||||
gems.Delete();
|
||||
from.SendLocalizedMessage(
|
||||
1078837 // Your backpack is full! Please make room and try again.
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
PublicOverheadMessage(MessageType.Regular, 0, 1094723, amount.ToString()); // Gems: ~1_COUNT~
|
||||
_gems -= amount;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
from.SendLocalizedMessage(1094725); // There are no more resources available at this time.
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -241,22 +270,15 @@ namespace Server.Items
|
|||
{
|
||||
base.Serialize(writer);
|
||||
|
||||
writer.WriteEncodedInt(1); // version
|
||||
writer.WriteEncodedInt(2); // version
|
||||
|
||||
writer.Write((int)CartType);
|
||||
|
||||
writer.Write(IsRewardItem);
|
||||
writer.Write(Gems);
|
||||
writer.Write(Ore);
|
||||
writer.Write(_gems);
|
||||
writer.Write(_ore);
|
||||
|
||||
if (m_Timer != null)
|
||||
{
|
||||
writer.Write(m_Timer.Next);
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.Write(Core.Now + TimeSpan.FromDays(1));
|
||||
}
|
||||
writer.Write(_lastResourceTime);
|
||||
}
|
||||
|
||||
public override void Deserialize(IGenericReader reader)
|
||||
|
|
@ -267,24 +289,20 @@ namespace Server.Items
|
|||
|
||||
switch (version)
|
||||
{
|
||||
case 2:
|
||||
case 1:
|
||||
CartType = (MiningCartType)reader.ReadInt();
|
||||
goto case 0;
|
||||
case 0:
|
||||
IsRewardItem = reader.ReadBool();
|
||||
Gems = reader.ReadInt();
|
||||
Ore = reader.ReadInt();
|
||||
_gems = reader.ReadInt();
|
||||
_ore = reader.ReadInt();
|
||||
|
||||
var next = reader.ReadDateTime();
|
||||
|
||||
if (next < Core.Now)
|
||||
{
|
||||
next = Core.Now;
|
||||
}
|
||||
|
||||
m_Timer = Timer.DelayCall(next - Core.Now, TimeSpan.FromDays(1), GiveResources);
|
||||
_lastResourceTime = reader.ReadDateTime() - (version < 2 ? TimeSpan.FromDays(1.0) : TimeSpan.Zero);
|
||||
break;
|
||||
}
|
||||
|
||||
GiveResources();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -303,18 +321,8 @@ namespace Server.Items
|
|||
|
||||
public override int LabelNumber => 1080385; // deed for a mining cart decoration
|
||||
|
||||
public override BaseAddon Addon
|
||||
{
|
||||
get
|
||||
{
|
||||
var addon = new MiningCart(m_CartType);
|
||||
addon.IsRewardItem = m_IsRewardItem;
|
||||
addon.Gems = Gems;
|
||||
addon.Ore = Ore;
|
||||
|
||||
return addon;
|
||||
}
|
||||
}
|
||||
public override BaseAddon Addon =>
|
||||
new MiningCart(m_CartType) { IsRewardItem = m_IsRewardItem, Gems = Gems, Ore = Ore };
|
||||
|
||||
[CommandProperty(AccessLevel.GameMaster)]
|
||||
public int Gems { get; set; }
|
||||
|
|
|
|||
|
|
@ -9,17 +9,15 @@ namespace Server.Items
|
|||
public class TreeStump : BaseAddon, IRewardItem
|
||||
{
|
||||
private bool m_IsRewardItem;
|
||||
|
||||
private int m_Logs;
|
||||
|
||||
private Timer m_Timer;
|
||||
private TimerExecutionToken _timerToken;
|
||||
|
||||
[Constructible]
|
||||
public TreeStump(int itemID)
|
||||
{
|
||||
AddComponent(new AddonComponent(itemID), 0, 0, 0);
|
||||
|
||||
m_Timer = Timer.DelayCall(TimeSpan.FromDays(1), TimeSpan.FromDays(1), GiveLogs);
|
||||
Timer.StartTimer(TimeSpan.FromDays(1), TimeSpan.FromDays(1), GiveLogs, out _timerToken);
|
||||
}
|
||||
|
||||
public TreeStump(Serial serial) : base(serial)
|
||||
|
|
@ -65,6 +63,11 @@ namespace Server.Items
|
|||
m_Logs = Math.Min(100, m_Logs + 10);
|
||||
}
|
||||
|
||||
public override void OnAfterDelete()
|
||||
{
|
||||
_timerToken.Cancel();
|
||||
}
|
||||
|
||||
public override void OnComponentUsed(AddonComponent c, Mobile from)
|
||||
{
|
||||
var house = BaseHouse.FindHouseAt(this);
|
||||
|
|
@ -104,12 +107,10 @@ namespace Server.Items
|
|||
3 => new YewLog(),
|
||||
4 => new HeartwoodLog(),
|
||||
5 => new BloodwoodLog(),
|
||||
6 => new FrostwoodLog(),
|
||||
_ => null
|
||||
_ => new FrostwoodLog()
|
||||
};
|
||||
|
||||
var amount = Math.Min(10, m_Logs);
|
||||
// ReSharper disable once PossibleNullReferenceException
|
||||
logs.Amount = amount;
|
||||
|
||||
if (!from.PlaceInBackpack(logs))
|
||||
|
|
@ -143,9 +144,9 @@ namespace Server.Items
|
|||
writer.Write(m_IsRewardItem);
|
||||
writer.Write(m_Logs);
|
||||
|
||||
if (m_Timer != null)
|
||||
if (_timerToken.Running)
|
||||
{
|
||||
writer.Write(m_Timer.Next);
|
||||
writer.Write(_timerToken.Next);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -169,7 +170,7 @@ namespace Server.Items
|
|||
next = Core.Now;
|
||||
}
|
||||
|
||||
m_Timer = Timer.DelayCall(next - Core.Now, TimeSpan.FromDays(1), GiveLogs);
|
||||
Timer.StartTimer(next - Core.Now, TimeSpan.FromDays(1), GiveLogs, out _timerToken);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -144,7 +144,7 @@ namespace Server.Items
|
|||
|
||||
private TalismanAttribute m_Summoner;
|
||||
|
||||
private Timer m_Timer;
|
||||
private TimerExecutionToken _timerToken;
|
||||
|
||||
public BaseTalisman()
|
||||
: this(GetRandomItemID())
|
||||
|
|
@ -1026,20 +1026,25 @@ namespace Server.Items
|
|||
|
||||
public virtual void StartTimer()
|
||||
{
|
||||
if (m_Timer?.Running != true)
|
||||
if (!_timerToken.Running)
|
||||
{
|
||||
m_Timer = Timer.DelayCall(TimeSpan.FromSeconds(10), TimeSpan.FromSeconds(10), Slice);
|
||||
Timer.StartTimer(TimeSpan.FromSeconds(10), TimeSpan.FromSeconds(10), Slice, out _timerToken);
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void StopTimer()
|
||||
{
|
||||
m_Timer?.Stop();
|
||||
m_Timer = null;
|
||||
_timerToken.Cancel();
|
||||
}
|
||||
|
||||
public virtual void Slice()
|
||||
{
|
||||
if (Deleted)
|
||||
{
|
||||
StopTimer();
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_ChargeTime - 10 > 0)
|
||||
{
|
||||
m_ChargeTime -= 10;
|
||||
|
|
@ -1197,9 +1202,9 @@ namespace Server.Items
|
|||
if (m_Talisman.ChargeTime > 0)
|
||||
{
|
||||
from.SendLocalizedMessage(
|
||||
1074882,
|
||||
1074882, // You must wait ~1_val~ seconds for this to recharge.
|
||||
m_Talisman.ChargeTime.ToString()
|
||||
); // You must wait ~1_val~ seconds for this to recharge.
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -571,7 +571,7 @@ namespace Server.Mobiles
|
|||
Hue = 0x480;
|
||||
BaseSoundID = 0xC9;
|
||||
|
||||
Timer.DelayCall(TimeSpan.FromMinutes(30.0), BeginTunnel);
|
||||
Timer.StartTimer(TimeSpan.FromMinutes(30.0), BeginTunnel);
|
||||
}
|
||||
|
||||
public SummonedVorpalBunny(Serial serial) : base(serial)
|
||||
|
|
@ -593,7 +593,7 @@ namespace Server.Mobiles
|
|||
Say("* The bunny begins to dig a tunnel back to its underground lair *");
|
||||
PlaySound(0x247);
|
||||
|
||||
Timer.DelayCall(TimeSpan.FromSeconds(5.0), Delete);
|
||||
Timer.StartTimer(TimeSpan.FromSeconds(5.0), Delete);
|
||||
}
|
||||
|
||||
public override void Serialize(IGenericWriter writer)
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ namespace Server.Items
|
|||
public class FlameSpurtTrap : BaseTrap
|
||||
{
|
||||
private Item m_Spurt;
|
||||
private Timer m_Timer;
|
||||
private TimerExecutionToken _timerToken;
|
||||
|
||||
[Constructible]
|
||||
public FlameSpurtTrap() : base(0x1B71) => Visible = false;
|
||||
|
|
@ -18,14 +18,15 @@ namespace Server.Items
|
|||
|
||||
public virtual void StartTimer()
|
||||
{
|
||||
m_Timer ??= Timer.DelayCall(TimeSpan.FromSeconds(1.0), TimeSpan.FromSeconds(1.0), Refresh);
|
||||
if (!_timerToken.Running)
|
||||
{
|
||||
Timer.StartTimer(TimeSpan.FromSeconds(1.0), TimeSpan.FromSeconds(1.0), Refresh, out _timerToken);
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void StopTimer()
|
||||
{
|
||||
m_Timer?.Stop();
|
||||
|
||||
m_Timer = null;
|
||||
_timerToken.Cancel();
|
||||
}
|
||||
|
||||
public virtual void CheckTimer()
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ namespace Server.Items
|
|||
|
||||
SpellHelper.Damage(TimeSpan.FromSeconds(0.5), from, from, Utility.Dice(2, 4, 0));
|
||||
|
||||
Timer.DelayCall(TimeSpan.FromSeconds(2.0), OnMushroomReset);
|
||||
Timer.StartTimer(TimeSpan.FromSeconds(2.0), OnMushroomReset);
|
||||
}
|
||||
|
||||
public virtual void OnMushroomReset()
|
||||
|
|
|
|||
|
|
@ -118,7 +118,7 @@ namespace Server.Items
|
|||
}
|
||||
}
|
||||
|
||||
Timer.DelayCall(TimeSpan.FromSeconds(1.0), OnSpikeExtended);
|
||||
Timer.StartTimer(TimeSpan.FromSeconds(1.0), OnSpikeExtended);
|
||||
|
||||
from.LocalOverheadMessage(MessageType.Regular, 0x22, 500852); // You stepped onto a spike trap!
|
||||
}
|
||||
|
|
@ -126,7 +126,7 @@ namespace Server.Items
|
|||
public virtual void OnSpikeExtended()
|
||||
{
|
||||
Extended = true;
|
||||
Timer.DelayCall(TimeSpan.FromSeconds(5.0), OnSpikeRetracted);
|
||||
Timer.StartTimer(TimeSpan.FromSeconds(5.0), OnSpikeRetracted);
|
||||
}
|
||||
|
||||
public virtual void OnSpikeRetracted()
|
||||
|
|
|
|||
|
|
@ -100,8 +100,8 @@ namespace Server.Items
|
|||
|
||||
Breathing = true;
|
||||
|
||||
Timer.DelayCall(TimeSpan.FromSeconds(2.0), FinishBreath);
|
||||
Timer.DelayCall(TimeSpan.FromSeconds(1.0), TriggerDamage);
|
||||
Timer.StartTimer(TimeSpan.FromSeconds(2.0), FinishBreath);
|
||||
Timer.StartTimer(TimeSpan.FromSeconds(1.0), TriggerDamage);
|
||||
}
|
||||
|
||||
public virtual void FinishBreath()
|
||||
|
|
|
|||
|
|
@ -104,12 +104,17 @@ namespace Server.Items
|
|||
public virtual void ApplyDelayTo(Mobile from)
|
||||
{
|
||||
from.BeginAction<BaseWand>();
|
||||
Timer.DelayCall(GetUseDelay, ReleaseWandLock_Callback, from);
|
||||
Timer.StartTimer(GetUseDelay,
|
||||
() =>
|
||||
{
|
||||
from.EndAction<BaseWand>();
|
||||
ReleaseWandLock_Callback(from);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public virtual void ReleaseWandLock_Callback(Mobile state)
|
||||
{
|
||||
state.EndAction<BaseWand>();
|
||||
}
|
||||
|
||||
public override void OnDoubleClick(Mobile from)
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ namespace Server.Items
|
|||
attacker.AddResistanceMod(mod);
|
||||
|
||||
info = new DefenseMasteryInfo(attacker, 80 - modifier, mod);
|
||||
info.m_Timer = Timer.DelayCall(TimeSpan.FromSeconds(3.0), EndDefense, info);
|
||||
Timer.StartTimer(TimeSpan.FromSeconds(3.0), () => EndDefense(info), out info._timerToken);
|
||||
|
||||
_table[attacker] = info;
|
||||
|
||||
|
|
@ -77,7 +77,7 @@ namespace Server.Items
|
|||
info.m_From.RemoveResistanceMod(info.m_Mod);
|
||||
}
|
||||
|
||||
info.m_Timer?.Stop();
|
||||
info._timerToken.Cancel();
|
||||
|
||||
// No message is sent to the player.
|
||||
|
||||
|
|
@ -91,7 +91,7 @@ namespace Server.Items
|
|||
public readonly int m_DamageMalus;
|
||||
public readonly Mobile m_From;
|
||||
public readonly ResistanceMod m_Mod;
|
||||
public Timer m_Timer;
|
||||
public TimerExecutionToken _timerToken;
|
||||
|
||||
public DefenseMasteryInfo(Mobile from, int damageMalus, ResistanceMod mod)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -81,7 +81,7 @@ namespace Server.Items
|
|||
attacker.PlaySound(0x2A1);
|
||||
}
|
||||
|
||||
Timer.DelayCall(TimeSpan.FromSeconds(2.0), RepeatEffect, attacker);
|
||||
Timer.StartTimer(TimeSpan.FromSeconds(2.0), () => RepeatEffect(attacker));
|
||||
}
|
||||
|
||||
private void RepeatEffect(Mobile attacker)
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ namespace Server.Items
|
|||
public static readonly TimeSpan PlayerDuration = TimeSpan.FromSeconds(6.0);
|
||||
public static readonly TimeSpan NPCDuration = TimeSpan.FromSeconds(12.0);
|
||||
|
||||
private static readonly Dictionary<Mobile, Timer> _table = new();
|
||||
private static readonly Dictionary<Mobile, TimerExecutionToken> _table = new();
|
||||
|
||||
public override int BaseMana => 30;
|
||||
|
||||
|
|
@ -41,26 +41,26 @@ namespace Server.Items
|
|||
|
||||
public static bool IsWounded(Mobile m) => _table.ContainsKey(m);
|
||||
|
||||
private static void StopTimer(Mobile m)
|
||||
{
|
||||
if (_table.Remove(m, out var timerToken))
|
||||
{
|
||||
timerToken.Cancel();
|
||||
}
|
||||
}
|
||||
|
||||
public static void BeginWound(Mobile m, TimeSpan duration)
|
||||
{
|
||||
if (_table.TryGetValue(m, out var timer))
|
||||
{
|
||||
timer?.Stop();
|
||||
}
|
||||
|
||||
_table[m] = timer = Timer.DelayCall(duration, EndWound, m);
|
||||
timer.Start();
|
||||
StopTimer(m);
|
||||
Timer.StartTimer(duration, () => EndWound(m), out var timerToken);
|
||||
_table[m] = timerToken;
|
||||
|
||||
m.YellowHealthbar = true;
|
||||
}
|
||||
|
||||
public static void EndWound(Mobile m)
|
||||
{
|
||||
if (_table.Remove(m, out var timer))
|
||||
{
|
||||
timer.Stop();
|
||||
}
|
||||
|
||||
StopTimer(m);
|
||||
m.YellowHealthbar = false;
|
||||
m.SendLocalizedMessage(1060208); // You are no longer mortally wounded.
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ namespace Server.Items
|
|||
|
||||
public static readonly TimeSpan FreezeDelayDuration = TimeSpan.FromSeconds(8.0);
|
||||
|
||||
private static readonly Dictionary<Mobile, Timer> _table = new();
|
||||
private static readonly Dictionary<Mobile, TimerExecutionToken> _table = new();
|
||||
|
||||
public override int BaseMana => 30;
|
||||
|
||||
|
|
@ -84,20 +84,16 @@ namespace Server.Items
|
|||
|
||||
public static void BeginImmunity(Mobile m, TimeSpan duration)
|
||||
{
|
||||
if (_table.TryGetValue(m, out var timer))
|
||||
{
|
||||
timer?.Stop();
|
||||
}
|
||||
|
||||
_table[m] = timer = Timer.DelayCall(duration, EndImmunity, m);
|
||||
timer.Start();
|
||||
EndImmunity(m);
|
||||
Timer.StartTimer(duration, () => EndImmunity(m), out var timerToken);
|
||||
_table[m] = timerToken;
|
||||
}
|
||||
|
||||
public static void EndImmunity(Mobile m)
|
||||
{
|
||||
if (_table.Remove(m, out var timer))
|
||||
if (_table.Remove(m, out var timerToken))
|
||||
{
|
||||
timer?.Stop();
|
||||
timerToken.Cancel();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -83,7 +83,7 @@ namespace Server.Items
|
|||
0
|
||||
);
|
||||
|
||||
Timer.DelayCall(TimeSpan.FromSeconds(1.0), FinishLaunch, endLoc, map);
|
||||
Timer.StartTimer(TimeSpan.FromSeconds(1.0), () => FinishLaunch(endLoc, map));
|
||||
}
|
||||
|
||||
private static void FinishLaunch(Point3D endLoc, Map map)
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ namespace Server.Items
|
|||
{
|
||||
private bool m_Balanced;
|
||||
|
||||
private Timer m_RecoveryTimer; // so we don't start too many timers
|
||||
private TimerExecutionToken _recoveryTimerToken;
|
||||
private int m_Velocity;
|
||||
|
||||
public BaseRanged(int itemID) : base(itemID)
|
||||
|
|
@ -154,11 +154,16 @@ namespace Server.Items
|
|||
|
||||
if (!pm.Warmode)
|
||||
{
|
||||
m_RecoveryTimer ??= Timer.DelayCall(TimeSpan.FromSeconds(10), pm.RecoverAmmo);
|
||||
|
||||
if (!m_RecoveryTimer.Running)
|
||||
if (!_recoveryTimerToken.Running)
|
||||
{
|
||||
m_RecoveryTimer.Start();
|
||||
Timer.StartTimer(TimeSpan.FromSeconds(10),
|
||||
() =>
|
||||
{
|
||||
_recoveryTimerToken.Cancel();
|
||||
pm.RecoverAmmo();
|
||||
},
|
||||
out _recoveryTimerToken
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue