feat: Updates to Serialization Generator v2.2 (#1157)
* Adds `SerializationProperty` - This will generate the private variable for serialization. Also provides an option `useField` to specify your own. Example: ```cs [SerializationProperty(0, useField: nameof(_resource)] ```
This commit is contained in:
parent
d82028a071
commit
89815ad4d3
50 changed files with 242 additions and 361 deletions
|
|
@ -6,9 +6,6 @@ namespace Server.Items;
|
|||
[SerializationGenerator(2, false)]
|
||||
public abstract partial class FillableContainer : LockableContainer
|
||||
{
|
||||
[SerializableField(0)]
|
||||
protected FillableContentType _rawContentType;
|
||||
|
||||
[TimerDrift]
|
||||
[SerializableField(1)]
|
||||
private Timer _respawnTimer;
|
||||
|
|
@ -35,19 +32,20 @@ public abstract partial class FillableContainer : LockableContainer
|
|||
[CommandProperty(AccessLevel.GameMaster)]
|
||||
public DateTime NextRespawnTime => _respawnTimer?.Next ?? DateTime.MinValue;
|
||||
|
||||
[SerializableProperty(0)]
|
||||
[CommandProperty(AccessLevel.GameMaster)]
|
||||
public FillableContentType ContentType
|
||||
{
|
||||
get => _rawContentType;
|
||||
get => _contentType;
|
||||
set
|
||||
{
|
||||
if (_rawContentType == value)
|
||||
if (_contentType == value)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ClearContents();
|
||||
_rawContentType = value;
|
||||
_contentType = value;
|
||||
Respawn();
|
||||
}
|
||||
}
|
||||
|
|
@ -77,14 +75,15 @@ public abstract partial class FillableContainer : LockableContainer
|
|||
|
||||
public virtual void AcquireContent()
|
||||
{
|
||||
if (_rawContentType != FillableContentType.None)
|
||||
if (_contentType != FillableContentType.None)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
RawContentType = FillableContent.Acquire(GetWorldLocation(), Map);
|
||||
// Don't trigger serialization code
|
||||
_contentType = FillableContent.Acquire(GetWorldLocation(), Map);
|
||||
|
||||
if (_rawContentType != FillableContentType.None)
|
||||
if (_contentType != FillableContentType.None)
|
||||
{
|
||||
Respawn();
|
||||
}
|
||||
|
|
@ -118,7 +117,7 @@ public abstract partial class FillableContainer : LockableContainer
|
|||
public void CheckRespawn()
|
||||
{
|
||||
var canSpawn =
|
||||
_rawContentType != FillableContentType.None &&
|
||||
_contentType != FillableContentType.None &&
|
||||
!Deleted && !Movable && Parent == null && !IsLockedDown && !IsSecure &&
|
||||
(
|
||||
GetItemsCount() <= SpawnThreshold ||
|
||||
|
|
@ -147,14 +146,14 @@ public abstract partial class FillableContainer : LockableContainer
|
|||
_respawnTimer?.Stop();
|
||||
_respawnTimer = null;
|
||||
|
||||
if (_rawContentType == FillableContentType.None || Deleted)
|
||||
if (_contentType == FillableContentType.None || Deleted)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
GenerateContent();
|
||||
|
||||
var level = FillableContent.Lookup(_rawContentType).Level;
|
||||
var level = FillableContent.Lookup(_contentType).Level;
|
||||
|
||||
if (IsLockable)
|
||||
{
|
||||
|
|
@ -199,12 +198,12 @@ public abstract partial class FillableContainer : LockableContainer
|
|||
|
||||
public virtual void GenerateContent()
|
||||
{
|
||||
if (_rawContentType == FillableContentType.None || Deleted)
|
||||
if (_contentType == FillableContentType.None || Deleted)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var content = FillableContent.Lookup(_rawContentType);
|
||||
var content = FillableContent.Lookup(_contentType);
|
||||
|
||||
var toSpawn = GetSpawnCount();
|
||||
|
||||
|
|
@ -238,7 +237,7 @@ public abstract partial class FillableContainer : LockableContainer
|
|||
|
||||
private void Deserialize(IGenericReader reader, int version)
|
||||
{
|
||||
_rawContentType = (FillableContentType)reader.ReadInt();
|
||||
_contentType = (FillableContentType)reader.ReadInt();
|
||||
var respawnTimerNext = reader.ReadDeltaTime();
|
||||
DeserializeRespawnTimer(respawnTimerNext == DateTime.MinValue ? TimeSpan.MinValue : respawnTimerNext - Core.Now);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,13 +16,12 @@ public partial class LibraryBookcase : FillableContainer
|
|||
|
||||
public override void AcquireContent()
|
||||
{
|
||||
if (_rawContentType != FillableContentType.None)
|
||||
if (ContentType != FillableContentType.None)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
RawContentType = FillableContentType.Library;
|
||||
Respawn();
|
||||
ContentType = FillableContentType.Library;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ public abstract partial class LockableContainer : TrappableContainer, ILockable,
|
|||
|
||||
public override bool TrapOnOpen => !_trapOnLockpick;
|
||||
|
||||
public override bool DisplaysContent => !_rawLocked;
|
||||
public override bool DisplaysContent => !_locked;
|
||||
|
||||
public int OnCraft(
|
||||
int quality, bool makersMark, Mobile from, CraftSystem craftSystem, Type typeRes, BaseTool tool,
|
||||
|
|
@ -72,18 +72,16 @@ public abstract partial class LockableContainer : TrappableContainer, ILockable,
|
|||
[SerializableFieldAttr("[CommandProperty(AccessLevel.GameMaster)]")]
|
||||
private int _lockLevel;
|
||||
|
||||
[SerializableField(6, getter: "private", setter: "private")]
|
||||
private bool _rawLocked;
|
||||
|
||||
[SerializableProperty(6)]
|
||||
[CommandProperty(AccessLevel.GameMaster)]
|
||||
public virtual bool Locked
|
||||
{
|
||||
get => _rawLocked;
|
||||
get => _locked;
|
||||
set
|
||||
{
|
||||
_rawLocked = value;
|
||||
_locked = value;
|
||||
|
||||
if (_rawLocked)
|
||||
if (_locked)
|
||||
{
|
||||
Picker = null;
|
||||
}
|
||||
|
|
@ -104,11 +102,11 @@ public abstract partial class LockableContainer : TrappableContainer, ILockable,
|
|||
}
|
||||
}
|
||||
|
||||
public override bool CheckContentDisplay(Mobile from) => !_rawLocked && base.CheckContentDisplay(from);
|
||||
public override bool CheckContentDisplay(Mobile from) => !_locked && base.CheckContentDisplay(from);
|
||||
|
||||
public override bool TryDropItem(Mobile from, Item dropped, bool sendFullMessage)
|
||||
{
|
||||
if (from.AccessLevel < AccessLevel.GameMaster && _rawLocked)
|
||||
if (from.AccessLevel < AccessLevel.GameMaster && _locked)
|
||||
{
|
||||
from.SendLocalizedMessage(501747); // It appears to be locked.
|
||||
return false;
|
||||
|
|
@ -119,7 +117,7 @@ public abstract partial class LockableContainer : TrappableContainer, ILockable,
|
|||
|
||||
public override bool OnDragDropInto(Mobile from, Item item, Point3D p)
|
||||
{
|
||||
if (from.AccessLevel < AccessLevel.GameMaster && _rawLocked)
|
||||
if (from.AccessLevel < AccessLevel.GameMaster && _locked)
|
||||
{
|
||||
from.SendLocalizedMessage(501747); // It appears to be locked.
|
||||
return false;
|
||||
|
|
@ -130,7 +128,7 @@ public abstract partial class LockableContainer : TrappableContainer, ILockable,
|
|||
|
||||
public override bool CheckLift(Mobile from, Item item, ref LRReason reject) =>
|
||||
base.CheckLift(from, item, ref reject) &&
|
||||
(item == this || from.AccessLevel >= AccessLevel.GameMaster || !_rawLocked);
|
||||
(item == this || from.AccessLevel >= AccessLevel.GameMaster || !_locked);
|
||||
|
||||
public override bool CheckItemUse(Mobile from, Item item)
|
||||
{
|
||||
|
|
@ -139,7 +137,7 @@ public abstract partial class LockableContainer : TrappableContainer, ILockable,
|
|||
return false;
|
||||
}
|
||||
|
||||
if (item != this && from.AccessLevel < AccessLevel.GameMaster && _rawLocked)
|
||||
if (item != this && from.AccessLevel < AccessLevel.GameMaster && _locked)
|
||||
{
|
||||
from.LocalOverheadMessage(MessageType.Regular, 0x3B2, 1019045); // I can't reach that.
|
||||
return false;
|
||||
|
|
@ -150,7 +148,7 @@ public abstract partial class LockableContainer : TrappableContainer, ILockable,
|
|||
|
||||
public virtual bool CheckLocked(Mobile from)
|
||||
{
|
||||
if (!_rawLocked)
|
||||
if (!_locked)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,9 +6,6 @@ namespace Server.Items;
|
|||
[SerializationGenerator(0, false)]
|
||||
public partial class MarkContainer : LockableContainer
|
||||
{
|
||||
[SerializableField(0, getter: "private", setter: "private")]
|
||||
private bool _rawAutoLock;
|
||||
|
||||
[TimerDrift]
|
||||
[SerializableField(1, getter: "private", setter: "private")]
|
||||
private InternalTimer _relockTimer;
|
||||
|
|
@ -16,7 +13,7 @@ public partial class MarkContainer : LockableContainer
|
|||
[DeserializeTimerField(1)]
|
||||
private void DeserializeRelockTimer(TimeSpan delay)
|
||||
{
|
||||
if (!Locked && _rawAutoLock)
|
||||
if (!Locked && _autoLock)
|
||||
{
|
||||
_relockTimer = new InternalTimer(this, delay);
|
||||
}
|
||||
|
|
@ -44,7 +41,7 @@ public partial class MarkContainer : LockableContainer
|
|||
Hue = 1102;
|
||||
}
|
||||
|
||||
_rawAutoLock = locked;
|
||||
_autoLock = locked;
|
||||
Locked = locked;
|
||||
|
||||
if (locked)
|
||||
|
|
@ -53,15 +50,16 @@ public partial class MarkContainer : LockableContainer
|
|||
}
|
||||
}
|
||||
|
||||
[SerializableProperty(0)]
|
||||
[CommandProperty(AccessLevel.GameMaster)]
|
||||
public bool AutoLock
|
||||
{
|
||||
get => _rawAutoLock;
|
||||
get => _autoLock;
|
||||
set
|
||||
{
|
||||
_rawAutoLock = value;
|
||||
_autoLock = value;
|
||||
|
||||
if (!_rawAutoLock)
|
||||
if (!_autoLock)
|
||||
{
|
||||
StopTimer();
|
||||
}
|
||||
|
|
@ -93,7 +91,7 @@ public partial class MarkContainer : LockableContainer
|
|||
{
|
||||
base.Locked = value;
|
||||
|
||||
if (_rawAutoLock)
|
||||
if (_autoLock)
|
||||
{
|
||||
StopTimer();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue