fix: Overhauls murder system (#1419)
## MAJOR CHANGE (API BREAKING) Added a player murder system to facilitate reporting murders. This should make it easier to extend to create a bounty system or other related game content. Player murders will be saved in a folder called _PlayerMurders_. ### Motivation The motivation was two-fold, performance, and bug fixes. First, murders are one of two systems that do a pre-world-save check on _every mobile in the game_ to decay kills and set their expiring murders. This is taxing since it freezes the world and makes world saves take longer. Every mobile has ShortTermMurders even though it is a player concept. And next, 90%+ of players are not murderers but had an ever increasing MurderElapse time that was being tracked against GameTime. These properties were also serialized unnecessarily for all mobs. Second, when I tried to optimize/refactor the code, it was obvious that the system has bugs. ### Major API Changes - [X] Created a player murder system and moved `ShortTermMurders`, `ShortTermElapse`, and `LongTermElapse` to the system. - [X] Added convenience property `PlayerMobile.ShortTermMurders`. - [X] Added convenience properties `PlayerMobile.ShortTermMurderExpiration` and `PlayerMobile.LongTermMurderExpiration` - [X] Moved ReportMurdererGump.cs - [X] Adds an `EventSink.PlayerDeleted` event. ### Notes The system currently does not support NPCs. To support expiring murders on NPCs I highly recommend a different architecture for large servers (500k+ mobs including players). Specifically switching from looping through all MurderContext to a time-order link list.
This commit is contained in:
parent
d65e5bb37b
commit
26f784f45d
13 changed files with 650 additions and 335 deletions
|
|
@ -10,6 +10,7 @@ using Server.Engines.Help;
|
|||
using Server.Engines.MLQuests;
|
||||
using Server.Engines.MLQuests.Gumps;
|
||||
using Server.Engines.PartySystem;
|
||||
using Server.Engines.PlayerMurderSystem;
|
||||
using Server.Engines.Quests;
|
||||
using Server.Ethics;
|
||||
using Server.Factions;
|
||||
|
|
@ -175,7 +176,6 @@ namespace Server.Mobiles
|
|||
private DateTime m_LastYoungHeal = DateTime.MinValue;
|
||||
|
||||
private DateTime m_LastYoungMessage = DateTime.MinValue;
|
||||
private TimeSpan m_LongTermElapse;
|
||||
|
||||
private MountBlock _mountBlock;
|
||||
|
||||
|
|
@ -191,7 +191,6 @@ namespace Server.Mobiles
|
|||
private int m_NonAutoreinsuredItems;
|
||||
|
||||
private DateTime m_SavagePaintExpiration;
|
||||
private TimeSpan m_ShortTermElapse;
|
||||
|
||||
private DateTime[] m_StuckMenuUses;
|
||||
|
||||
|
|
@ -201,13 +200,10 @@ namespace Server.Mobiles
|
|||
{
|
||||
VisibilityList = new List<Mobile>();
|
||||
PermaFlags = new List<Mobile>();
|
||||
RecentlyReported = new List<Mobile>();
|
||||
|
||||
BOBFilter = new BOBFilter();
|
||||
|
||||
m_GameTime = TimeSpan.Zero;
|
||||
m_ShortTermElapse = TimeSpan.FromHours(8.0);
|
||||
m_LongTermElapse = TimeSpan.FromHours(40.0);
|
||||
|
||||
JusticeProtectors = new List<Mobile>();
|
||||
m_GuildRank = RankDefinition.Lowest;
|
||||
|
|
@ -730,6 +726,23 @@ namespace Server.Mobiles
|
|||
[CommandProperty(AccessLevel.GameMaster)]
|
||||
public ChampionTitleInfo ChampionTitles { get; private set; }
|
||||
|
||||
[CommandProperty(AccessLevel.GameMaster)]
|
||||
public int ShortTermMurders
|
||||
{
|
||||
get => PlayerMurderSystem.GetOrCreateContext(this, out var context) ? context.ShortTermMurders : 0;
|
||||
set => PlayerMurderSystem.ManuallySetShortTermMurders(this, value);
|
||||
}
|
||||
|
||||
[CommandProperty(AccessLevel.GameMaster)]
|
||||
public DateTime ShortTermMurderExpiration => PlayerMurderSystem.GetOrCreateContext(this, out var context)
|
||||
? Core.Now + (context.ShortTermElapse - GameTime)
|
||||
: DateTime.MinValue;
|
||||
|
||||
[CommandProperty(AccessLevel.GameMaster)]
|
||||
public DateTime LongTermMurderExpiration => PlayerMurderSystem.GetOrCreateContext(this, out var context)
|
||||
? Core.Now + (context.LongTermElapse - GameTime)
|
||||
: DateTime.MinValue;
|
||||
|
||||
[CommandProperty(AccessLevel.GameMaster)]
|
||||
public int KnownRecipes => m_AcquiredRecipes?.Count ?? 0;
|
||||
|
||||
|
|
@ -2885,6 +2898,7 @@ namespace Server.Mobiles
|
|||
|
||||
switch (version)
|
||||
{
|
||||
case 31: // Removed Short/Long Term Elapse
|
||||
case 30:
|
||||
{
|
||||
Stabled = reader.ReadEntitySet<Mobile>(true);
|
||||
|
|
@ -3132,8 +3146,14 @@ namespace Server.Mobiles
|
|||
}
|
||||
case 1:
|
||||
{
|
||||
m_LongTermElapse = reader.ReadTimeSpan();
|
||||
m_ShortTermElapse = reader.ReadTimeSpan();
|
||||
if (version < 31)
|
||||
{
|
||||
var longTermElapse = reader.ReadTimeSpan();
|
||||
var shortTermElapse = reader.ReadTimeSpan();
|
||||
|
||||
PlayerMurderSystem.MigrateContext(this, shortTermElapse, longTermElapse);
|
||||
}
|
||||
|
||||
m_GameTime = reader.ReadTimeSpan();
|
||||
goto case 0;
|
||||
}
|
||||
|
|
@ -3181,7 +3201,6 @@ namespace Server.Mobiles
|
|||
}
|
||||
}
|
||||
|
||||
CheckKillDecay();
|
||||
CheckAtrophies();
|
||||
|
||||
if (Hidden) // Hiding is the only buff where it has an effect that's serialized.
|
||||
|
|
@ -3194,7 +3213,7 @@ namespace Server.Mobiles
|
|||
{
|
||||
base.Serialize(writer);
|
||||
|
||||
writer.Write(30); // version
|
||||
writer.Write(31); // version
|
||||
|
||||
if (Stabled == null)
|
||||
{
|
||||
|
|
@ -3332,19 +3351,16 @@ namespace Server.Mobiles
|
|||
|
||||
writer.Write((int)Flags);
|
||||
|
||||
writer.Write(m_LongTermElapse);
|
||||
writer.Write(m_ShortTermElapse);
|
||||
writer.Write(GameTime);
|
||||
}
|
||||
|
||||
// Do we need to run an after serialize?
|
||||
public override bool ShouldExecuteAfterSerialize => ShouldKillDecay() || ShouldAtrophy();
|
||||
public override bool ShouldExecuteAfterSerialize => ShouldAtrophy();
|
||||
|
||||
public override void AfterSerialize()
|
||||
{
|
||||
base.AfterSerialize();
|
||||
|
||||
CheckKillDecay();
|
||||
CheckAtrophies();
|
||||
}
|
||||
|
||||
|
|
@ -3368,35 +3384,6 @@ namespace Server.Mobiles
|
|||
ChampionTitleInfo.CheckAtrophy(this);
|
||||
}
|
||||
|
||||
public bool ShouldKillDecay() => m_ShortTermElapse < GameTime || m_LongTermElapse < GameTime;
|
||||
|
||||
public void CheckKillDecay()
|
||||
{
|
||||
if (m_ShortTermElapse < GameTime)
|
||||
{
|
||||
m_ShortTermElapse += TimeSpan.FromHours(8);
|
||||
if (ShortTermMurders > 0)
|
||||
{
|
||||
--ShortTermMurders;
|
||||
}
|
||||
}
|
||||
|
||||
if (m_LongTermElapse < GameTime)
|
||||
{
|
||||
m_LongTermElapse += TimeSpan.FromHours(40);
|
||||
if (Kills > 0)
|
||||
{
|
||||
--Kills;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void ResetKillTime()
|
||||
{
|
||||
m_ShortTermElapse = GameTime + TimeSpan.FromHours(8);
|
||||
m_LongTermElapse = GameTime + TimeSpan.FromHours(40);
|
||||
}
|
||||
|
||||
public override bool CanSee(Mobile m)
|
||||
{
|
||||
if (m is CharacterStatue statue)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue