fix: Fixes mount blocking and adds permanent option for customization (#1005)

This commit is contained in:
Kamron Batman 2022-04-19 14:23:10 -07:00 • committed by GitHub
parent f2275cb65b
commit 848db6fc4b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 15 deletions

View file

@ -181,7 +181,7 @@ namespace Server.Mobiles
private DateTime m_LastYoungMessage = DateTime.MinValue; private DateTime m_LastYoungMessage = DateTime.MinValue;
private TimeSpan m_LongTermElapse; private TimeSpan m_LongTermElapse;
private MountBlock m_MountBlock; private MountBlock _mountBlock;
private DateTime m_NextJustAward; private DateTime m_NextJustAward;
@ -240,7 +240,7 @@ namespace Server.Mobiles
public DesignContext DesignContext { get; set; } public DesignContext DesignContext { get; set; }
public BlockMountType MountBlockReason => CheckBlock(m_MountBlock) ? m_MountBlock.m_Type : BlockMountType.None; public BlockMountType MountBlockReason => _mountBlock?.MountBlockReason ?? BlockMountType.None;
public override int MaxWeight => (Core.ML && Race == Race.Human ? 100 : 40) + (int)(3.5 * Str); public override int MaxWeight => (Core.ML && Race == Race.Human ? 100 : 40) + (int)(3.5 * Str);
@ -394,7 +394,7 @@ namespace Server.Mobiles
public bool NinjaWepCooldown { get; set; } public bool NinjaWepCooldown { get; set; }
public List<Mobile> AllFollowers => m_AllFollowers ?? (m_AllFollowers = new List<Mobile>()); public List<Mobile> AllFollowers => m_AllFollowers ??= new List<Mobile>();
public RankDefinition GuildRank public RankDefinition GuildRank
{ {
@ -1102,8 +1102,8 @@ namespace Server.Mobiles
} }
} }
[MethodImpl(MethodImplOptions.AggressiveInlining)] public void SetMountBlock(BlockMountType type, bool dismount) =>
private static bool CheckBlock(MountBlock block) => block?._timerToken.Running == true; SetMountBlock(type, TimeSpan.MaxValue, dismount);
public void SetMountBlock(BlockMountType type, TimeSpan duration, bool dismount) public void SetMountBlock(BlockMountType type, TimeSpan duration, bool dismount)
{ {
@ -1119,9 +1119,10 @@ namespace Server.Mobiles
} }
} }
if (!CheckBlock(m_MountBlock) || m_MountBlock._timerToken.Next < Core.Now + duration) if (!_mountBlock.CheckBlock() || _mountBlock.Expiration < Core.Now + duration)
{ {
m_MountBlock = new MountBlock(duration, type, this); _mountBlock?.RemoveBlock(this);
_mountBlock = new MountBlock(duration, type, this);
} }
} }
@ -4634,21 +4635,30 @@ namespace Server.Mobiles
private class MountBlock private class MountBlock
{ {
public TimerExecutionToken _timerToken; private TimerExecutionToken _timerToken;
public readonly BlockMountType m_Type; private BlockMountType _type;
public MountBlock(TimeSpan duration, BlockMountType type, Mobile mobile) public MountBlock(TimeSpan duration, BlockMountType type, Mobile mobile)
{ {
m_Type = type; _type = type;
Timer.StartTimer(duration, () => RemoveBlock(mobile), out _timerToken); if (duration < TimeSpan.MaxValue)
{
Timer.StartTimer(duration, () => RemoveBlock(mobile), out _timerToken);
}
} }
private void RemoveBlock(Mobile mobile) public DateTime Expiration => _timerToken.Next;
public BlockMountType MountBlockReason => CheckBlock() ? _type : BlockMountType.None;
public bool CheckBlock() => _timerToken.Next == DateTime.MinValue || _timerToken.Running;
public void RemoveBlock(Mobile mobile)
{ {
if (mobile is PlayerMobile pm) if (mobile is PlayerMobile pm)
{ {
pm.m_MountBlock = null; pm._mountBlock = null;
} }
_timerToken.Cancel(); _timerToken.Cancel();

View file

@ -589,8 +589,7 @@ namespace Server.Spells.Ninjitsu
m_LastTarget = m_Mobile.Combatant; m_LastTarget = m_Mobile.Combatant;
} }
if (m_Mobile.Warmode && m_LastTarget?.Alive == true && m_LastTarget?.Deleted != true && if (m_Mobile.Warmode && m_LastTarget is { Alive: true, Deleted: false } && m_Counter-- <= 0)
m_Counter-- <= 0)
{ {
if (m_Mobile.CanBeHarmful(m_LastTarget) && m_LastTarget.Map == m_Mobile.Map && if (m_Mobile.CanBeHarmful(m_LastTarget) && m_LastTarget.Map == m_Mobile.Map &&
m_LastTarget.InRange(m_Mobile.Location, BaseCreature.DefaultRangePerception) && m_LastTarget.InRange(m_Mobile.Location, BaseCreature.DefaultRangePerception) &&