fix: Cleans up entity persistence. Generalizes Mobiles/Items/Guilds (#1528)
### Summary - [X] Fixed a bug where entity persistence was serialized out of order, causing world corruption. - [X] Fixed LastSerialized not being utilized properly and dangling references still becoming an issue. - [X] Added a new `GenericEntityPersistence<T>` type to encapsulate `ISerializable` serialization. - [X] Removing the custom logic and moved Items, Mobiles, Guilds, and Accounts to GenericEntityPersistence. - [X] Changed serialization to use the singleton pattern to reduce calling methods from stored variables.
This commit is contained in:
parent
e0225c6e59
commit
f2de2fbb77
34 changed files with 721 additions and 970 deletions
|
|
@ -8,8 +8,10 @@ using Server.Mobiles;
|
|||
|
||||
namespace Server.Engines.PlayerMurderSystem;
|
||||
|
||||
public static class PlayerMurderSystem
|
||||
public class PlayerMurderSystem : GenericPersistence
|
||||
{
|
||||
private static PlayerMurderSystem _playerMurderPersistence;
|
||||
|
||||
private static readonly ILogger logger = LogFactory.GetLogger(typeof(PlayerMurderSystem));
|
||||
|
||||
// All of the players with murders
|
||||
|
|
@ -28,10 +30,10 @@ public static class PlayerMurderSystem
|
|||
|
||||
public static void Configure()
|
||||
{
|
||||
GenericPersistence.Register("PlayerMurders", Serialize, Deserialize);
|
||||
|
||||
_shortTermMurderDuration = ServerConfiguration.GetOrUpdateSetting("murderSystem.shortTermMurderDuration", TimeSpan.FromHours(8));
|
||||
_longTermMurderDuration = ServerConfiguration.GetOrUpdateSetting("murderSystem.longTermMurderDuration", TimeSpan.FromHours(40));
|
||||
|
||||
_playerMurderPersistence = new PlayerMurderSystem();
|
||||
}
|
||||
|
||||
public static void Initialize()
|
||||
|
|
@ -49,6 +51,10 @@ public static class PlayerMurderSystem
|
|||
}
|
||||
}
|
||||
|
||||
public PlayerMurderSystem() : base("PlayerMurders", 10)
|
||||
{
|
||||
}
|
||||
|
||||
// Only used for migrations!
|
||||
public static void MigrateContext(PlayerMobile player, TimeSpan shortTerm, TimeSpan longTerm)
|
||||
{
|
||||
|
|
@ -61,7 +67,7 @@ public static class PlayerMurderSystem
|
|||
return;
|
||||
}
|
||||
|
||||
var context = player.GetOrCreateMurderContext();
|
||||
var context = GetOrCreateMurderContext(player);
|
||||
|
||||
// We make a big assumption that by the time this is called, the Mobile/PlayerMobile info is deserialized
|
||||
if (Mobile.MurderMigrations?.TryGetValue(player, out var shortTermMurders) == true)
|
||||
|
|
@ -100,7 +106,7 @@ public static class PlayerMurderSystem
|
|||
}
|
||||
}
|
||||
|
||||
private static void Deserialize(IGenericReader reader)
|
||||
public override void Deserialize(IGenericReader reader)
|
||||
{
|
||||
var version = reader.ReadEncodedInt();
|
||||
|
||||
|
|
@ -114,7 +120,7 @@ public static class PlayerMurderSystem
|
|||
}
|
||||
}
|
||||
|
||||
private static void Serialize(IGenericWriter writer)
|
||||
public override void Serialize(IGenericWriter writer)
|
||||
{
|
||||
writer.WriteEncodedInt(0); // version
|
||||
|
||||
|
|
@ -126,10 +132,10 @@ public static class PlayerMurderSystem
|
|||
}
|
||||
}
|
||||
|
||||
public static bool GetMurderContext(this PlayerMobile player, out MurderContext context) =>
|
||||
public static bool GetMurderContext(PlayerMobile player, out MurderContext context) =>
|
||||
_murderContexts.TryGetValue(player, out context);
|
||||
|
||||
public static MurderContext GetOrCreateMurderContext(this PlayerMobile player)
|
||||
public static MurderContext GetOrCreateMurderContext(PlayerMobile player)
|
||||
{
|
||||
ref var context = ref CollectionsMarshal.GetValueRefOrAddDefault(_murderContexts, player, out var exists);
|
||||
if (!exists)
|
||||
|
|
@ -142,14 +148,14 @@ public static class PlayerMurderSystem
|
|||
|
||||
public static void ManuallySetShortTermMurders(PlayerMobile player, int shortTermMurders)
|
||||
{
|
||||
var context = player.GetOrCreateMurderContext();
|
||||
var context = GetOrCreateMurderContext(player);
|
||||
context.ShortTermMurders = shortTermMurders;
|
||||
UpdateMurderContext(context);
|
||||
}
|
||||
|
||||
public static void OnPlayerMurder(PlayerMobile player)
|
||||
{
|
||||
var context = player.GetOrCreateMurderContext();
|
||||
var context = GetOrCreateMurderContext(player);
|
||||
context.ShortTermMurders++;
|
||||
player.Kills++;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue