fix: Fixes out of range crash with murder context (#1429)
This commit is contained in:
parent
f77dd91811
commit
8eb480bdf5
4 changed files with 23 additions and 37 deletions
|
|
@ -10,11 +10,11 @@ public partial class MurderContext
|
|||
{
|
||||
[SerializableField(0)]
|
||||
[SerializedCommandProperty(AccessLevel.GameMaster)]
|
||||
private TimeSpan _shortTermElapse = TimeSpan.MaxValue;
|
||||
private TimeSpan _shortTermElapse;
|
||||
|
||||
[SerializableField(1)]
|
||||
[SerializedCommandProperty(AccessLevel.GameMaster)]
|
||||
private TimeSpan _longTermElapse = TimeSpan.MaxValue;
|
||||
private TimeSpan _longTermElapse;
|
||||
|
||||
[SerializableProperty(2)]
|
||||
[CommandProperty(AccessLevel.GameMaster)]
|
||||
|
|
@ -24,7 +24,6 @@ public partial class MurderContext
|
|||
set => _shortTermMurders = Math.Max(value, 0);
|
||||
}
|
||||
|
||||
[DirtyTrackingEntity]
|
||||
public PlayerMobile _player;
|
||||
|
||||
public PlayerMobile Player => _player;
|
||||
|
|
@ -34,16 +33,16 @@ public partial class MurderContext
|
|||
|
||||
public MurderContext(PlayerMobile player) => _player = player;
|
||||
|
||||
public void ResetKillTime(bool isShort = true, bool isLong = true)
|
||||
public void ResetKillTime()
|
||||
{
|
||||
var gameTime = _player.GameTime;
|
||||
|
||||
if (isShort)
|
||||
if (ShortTermMurders > 0)
|
||||
{
|
||||
ShortTermElapse = gameTime + PlayerMurderSystem.ShortTermMurderDuration;
|
||||
}
|
||||
|
||||
if (isLong)
|
||||
if (_player.Kills > 0)
|
||||
{
|
||||
LongTermElapse = gameTime + PlayerMurderSystem.LongTermMurderDuration;
|
||||
}
|
||||
|
|
@ -53,22 +52,16 @@ public partial class MurderContext
|
|||
{
|
||||
var gameTime = _player.GameTime;
|
||||
|
||||
if (ShortTermElapse < gameTime)
|
||||
if (ShortTermMurders > 0 && _shortTermElapse < gameTime)
|
||||
{
|
||||
ShortTermElapse += PlayerMurderSystem.ShortTermMurderDuration;
|
||||
if (ShortTermMurders > 0)
|
||||
{
|
||||
--ShortTermMurders;
|
||||
}
|
||||
--ShortTermMurders;
|
||||
}
|
||||
|
||||
if (LongTermElapse < gameTime)
|
||||
if (_player.Kills > 0 && _longTermElapse < gameTime)
|
||||
{
|
||||
LongTermElapse += PlayerMurderSystem.LongTermMurderDuration;
|
||||
if (_player.Kills > 0)
|
||||
{
|
||||
--_player.Kills;
|
||||
}
|
||||
--_player.Kills;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -144,43 +144,36 @@ public static class PlayerMurderSystem
|
|||
return context;
|
||||
}
|
||||
|
||||
public static void ManuallySetShortTermMurders(PlayerMobile player, int shortTermMurders, bool resetKillTime = true)
|
||||
public static void ManuallySetShortTermMurders(PlayerMobile player, int shortTermMurders)
|
||||
{
|
||||
var context = player.GetOrCreateMurderContext();
|
||||
context.ShortTermMurders = shortTermMurders;
|
||||
UpdateMurderContext(context, resetKillTime);
|
||||
UpdateMurderContext(context);
|
||||
}
|
||||
|
||||
public static void OnPlayerMurder(PlayerMobile player, bool resetKillTime = false)
|
||||
public static void OnPlayerMurder(PlayerMobile player)
|
||||
{
|
||||
var context = player.GetOrCreateMurderContext();
|
||||
context.ShortTermMurders++;
|
||||
player.Kills++;
|
||||
|
||||
UpdateMurderContext(context, resetKillTime);
|
||||
context.ResetKillTime();
|
||||
UpdateMurderContext(context);
|
||||
}
|
||||
|
||||
private static void UpdateMurderContext(MurderContext context, bool resetKillTime = false)
|
||||
private static void UpdateMurderContext(MurderContext context)
|
||||
{
|
||||
var player = context.Player;
|
||||
// Either we are resetting their decay time, or they got their first kill
|
||||
context.ResetKillTime(
|
||||
context.ShortTermMurders > 0 && (!resetKillTime || context.ShortTermElapse == TimeSpan.MaxValue),
|
||||
player.Kills > 0 && (!resetKillTime || context.LongTermElapse == TimeSpan.MaxValue)
|
||||
);
|
||||
|
||||
if (context.CheckStart())
|
||||
{
|
||||
if (player.NetState != null)
|
||||
{
|
||||
_contextTerms.Add(context);
|
||||
}
|
||||
}
|
||||
else
|
||||
if (!context.CheckStart())
|
||||
{
|
||||
_murderContexts.Remove(player);
|
||||
_contextTerms.Remove(context);
|
||||
}
|
||||
else if (player.NetState != null)
|
||||
{
|
||||
_contextTerms.Add(context);
|
||||
}
|
||||
}
|
||||
|
||||
private class MurdererTimer : Timer
|
||||
|
|
|
|||
|
|
@ -160,7 +160,7 @@ public class ReportMurdererGump : Gump
|
|||
if (killer is PlayerMobile pk)
|
||||
{
|
||||
// Increment their short term murders, their kills, and reset the murder decay time
|
||||
PlayerMurderSystem.OnPlayerMurder(pk, true);
|
||||
PlayerMurderSystem.OnPlayerMurder(pk);
|
||||
|
||||
pk.SendLocalizedMessage(1049067); // You have been reported for murder!
|
||||
|
||||
|
|
|
|||
|
|
@ -704,12 +704,12 @@ namespace Server.Mobiles
|
|||
}
|
||||
|
||||
[CommandProperty(AccessLevel.GameMaster)]
|
||||
public DateTime ShortTermMurderExpiration => this.GetMurderContext(out var context)
|
||||
public DateTime ShortTermMurderExpiration => this.GetMurderContext(out var context) && context.ShortTermMurders > 0
|
||||
? Core.Now + (context.ShortTermElapse - GameTime)
|
||||
: DateTime.MinValue;
|
||||
|
||||
[CommandProperty(AccessLevel.GameMaster)]
|
||||
public DateTime LongTermMurderExpiration => this.GetMurderContext(out var context)
|
||||
public DateTime LongTermMurderExpiration => Kills > 0 && this.GetMurderContext(out var context)
|
||||
? Core.Now + (context.LongTermElapse - GameTime)
|
||||
: DateTime.MinValue;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue