ModernUO/Projects/UOContent/Engines/Bulk Orders/Books/BaseBOBEntry.cs
Kamron Batman f2de2fbb77
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.
2023-10-01 22:10:47 -07:00

60 lines
1.5 KiB
C#

using System;
using System.IO;
using ModernUO.Serialization;
namespace Server.Engines.BulkOrders;
[SerializationGenerator(1)]
public abstract partial class BaseBOBEntry : IBOBEntry
{
[SerializableField(0, setter: "protected")]
private bool _requireExceptional;
[SerializableField(1, setter: "protected")]
private BODType _deedType;
[SerializableField(2, setter: "protected")]
private BulkMaterialType _material;
[SerializableField(3, setter: "protected")]
private int _amountMax;
[SerializableField(4)]
private int _price;
public DateTime Created { get; set; } = Core.Now;
public DateTime LastSerialized { get; set; } = Core.Now;
public Serial Serial { get; }
public bool Deleted { get; private set; }
public BaseBOBEntry()
{
Serial = BOBEntries.NewBOBEntry;
BOBEntries.Add(this);
}
public virtual void Delete()
{
Deleted = true;
BOBEntries.Remove(this);
}
public abstract Item Reconstruct();
private void Deserialize(IGenericReader reader, int version)
{
if (version == 0)
{
// version 0 - This class didn't exist, so we are going to skip deserializing
// Seek back 1 byte because encoded int of 0 is 1 byte
reader.Seek(-1, SeekOrigin.Current);
}
else
{
throw new Exception("Unknown deserialization error in presource generated BOB Entries");
}
}
}