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:
Kamron Batman 2023-10-01 22:10:47 -07:00 committed by GitHub
parent e0225c6e59
commit f2de2fbb77
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
34 changed files with 721 additions and 970 deletions

View file

@ -2,8 +2,9 @@ using System;
namespace Server.Factions;
public static class FactionSystem
public class FactionSystem : GenericPersistence
{
private static FactionSystem _factionSystem;
public static bool Enabled { get; private set; }
public static void Configure()
@ -12,10 +13,14 @@ public static class FactionSystem
if (Enabled)
{
GenericPersistence.Register("Factions", Serialize, Deserialize);
_factionSystem = new();
}
}
public FactionSystem() : base("Factions", 10)
{
}
// This does not do the actual work of removing faction stuff, only turns off the persistence.
public static void Disable()
{
@ -24,7 +29,7 @@ public static class FactionSystem
return;
}
Persistence.Unregister("Factions");
_factionSystem.Unregister();
Enabled = false;
ServerConfiguration.SetSetting("factions.enabled", false);
}
@ -37,12 +42,12 @@ public static class FactionSystem
return;
}
GenericPersistence.Register("Factions", Serialize, Deserialize);
_factionSystem.Register();
Enabled = true;
ServerConfiguration.SetSetting("factions.enabled", true);
}
private static void Serialize(IGenericWriter writer)
public override void Serialize(IGenericWriter writer)
{
writer.WriteEncodedInt(0); // version
@ -59,7 +64,7 @@ public static class FactionSystem
}
}
private static void Deserialize(IGenericReader reader)
public override void Deserialize(IGenericReader reader)
{
var version = reader.ReadEncodedInt();