fix: Converts ethics system to generic entity persistence (#1824)

### Summary

Converts ethics system to entity persistence and removes the persistence item.


### TODO

1. The enable/disable toggle doesn't propagate to all code that does Ethics checks (notoriety, pvp, etc).
2. We need commands to remove them from an ethic.
This commit is contained in:
Kamron Batman 2024-06-16 10:26:09 -07:00 committed by GitHub
parent f87c8f73ab
commit 20596e52fa
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
36 changed files with 1327 additions and 1338 deletions

View file

@ -0,0 +1,59 @@
using System;
using Server.Ethics.Evil;
using Server.Ethics.Hero;
namespace Server.Ethics;
public class EthicsSystem : GenericEntityPersistence<EthicsEntity>
{
private static EthicsSystem _persistence;
public static void Configure()
{
_persistence = new EthicsSystem();
}
public EthicsSystem() : base("Ethics", 3, 0x1, 0x7FFFFFFF)
{
}
public static Serial NewProfile => _persistence.NewEntity;
public static void Add(EthicsEntity entity) => _persistence.AddEntity(entity);
public static void Remove(EthicsEntity entity) => _persistence.RemoveEntity(entity);
public static T Find<T>(Serial serial) where T : EthicsEntity => _persistence.FindEntity<T>(serial);
}
[ManualDirtyChecking]
[TypeAlias("Server.Ethics.EthicsPersistance")]
[Obsolete("Deprecated in favor of the static system. Only used for legacy deserialization")]
public class EthicsPersistence : Item
{
public EthicsPersistence()
{
Delete();
}
public EthicsPersistence(Serial serial) : base(serial)
{
}
public override void Serialize(IGenericWriter writer)
{
}
public override void Deserialize(IGenericReader reader)
{
base.Deserialize(reader);
var heroEthic = new HeroEthic();
heroEthic.Deserialize(reader);
var evilEthic = new EvilEthic();
evilEthic.Deserialize(reader);
Timer.DelayCall(Delete);
}
}