fix: Fixes out of range crash with murder context (#1429)

This commit is contained in:
Kamron Batman 2023-07-22 09:12:04 -07:00 committed by GitHub
parent f77dd91811
commit 8eb480bdf5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 23 additions and 37 deletions

View file

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