fix: Codegens spell items (#1765)
### Summary - Fixes some serialization issues with spell items - Fixes accessibility issues with field spells and removes the awkward "InternalItem" concept - Codegens the fields/items used in spells
This commit is contained in:
parent
542b672d9d
commit
8efa90b3ce
25 changed files with 1389 additions and 1507 deletions
|
|
@ -1,60 +1,40 @@
|
|||
using System;
|
||||
using ModernUO.Serialization;
|
||||
|
||||
namespace Server.Items
|
||||
namespace Server.Items;
|
||||
|
||||
[SerializationGenerator(0, false)]
|
||||
public partial class ArcaneFocus : TransientItem
|
||||
{
|
||||
public class ArcaneFocus : TransientItem
|
||||
[SerializableField(0)]
|
||||
[SerializedCommandProperty(AccessLevel.GameMaster)]
|
||||
private int _strengthBonus;
|
||||
|
||||
[Constructible]
|
||||
public ArcaneFocus() : this(TimeSpan.FromHours(1), 1)
|
||||
{
|
||||
[Constructible]
|
||||
public ArcaneFocus()
|
||||
: this(TimeSpan.FromHours(1), 1)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
[Constructible]
|
||||
public ArcaneFocus(int lifeSpan, int strengthBonus)
|
||||
: this(TimeSpan.FromSeconds(lifeSpan), strengthBonus)
|
||||
{
|
||||
}
|
||||
[Constructible]
|
||||
public ArcaneFocus(int lifeSpan, int strengthBonus) : this(TimeSpan.FromSeconds(lifeSpan), strengthBonus)
|
||||
{
|
||||
}
|
||||
|
||||
public ArcaneFocus(TimeSpan lifeSpan, int strengthBonus) : base(0x3155, lifeSpan)
|
||||
{
|
||||
LootType = LootType.Blessed;
|
||||
StrengthBonus = strengthBonus;
|
||||
}
|
||||
public ArcaneFocus(TimeSpan lifeSpan, int strengthBonus) : base(0x3155, lifeSpan)
|
||||
{
|
||||
LootType = LootType.Blessed;
|
||||
_strengthBonus = strengthBonus;
|
||||
}
|
||||
|
||||
public ArcaneFocus(Serial serial) : base(serial)
|
||||
{
|
||||
}
|
||||
public override int LabelNumber => 1032629; // Arcane Focus
|
||||
|
||||
public override int LabelNumber => 1032629; // Arcane Focus
|
||||
public override TextDefinition InvalidTransferMessage => 1073480; // Your arcane focus disappears.
|
||||
public override bool Nontransferable => true;
|
||||
|
||||
[CommandProperty(AccessLevel.GameMaster)]
|
||||
public int StrengthBonus { get; set; }
|
||||
public override void GetProperties(IPropertyList list)
|
||||
{
|
||||
base.GetProperties(list);
|
||||
|
||||
public override TextDefinition InvalidTransferMessage { get; } = 1073480; // Your arcane focus disappears.
|
||||
public override bool Nontransferable => true;
|
||||
|
||||
public override void GetProperties(IPropertyList list)
|
||||
{
|
||||
base.GetProperties(list);
|
||||
|
||||
list.Add(1060485, StrengthBonus); // strength bonus ~1_val~
|
||||
}
|
||||
|
||||
public override void Serialize(IGenericWriter writer)
|
||||
{
|
||||
base.Serialize(writer);
|
||||
writer.Write(0);
|
||||
|
||||
writer.Write(StrengthBonus);
|
||||
}
|
||||
|
||||
public override void Deserialize(IGenericReader reader)
|
||||
{
|
||||
base.Deserialize(reader);
|
||||
var version = reader.ReadInt();
|
||||
|
||||
StrengthBonus = reader.ReadInt();
|
||||
}
|
||||
list.Add(1060485, _strengthBonus); // strength bonus ~1_val~
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,105 +1,94 @@
|
|||
using System;
|
||||
using ModernUO.Serialization;
|
||||
|
||||
namespace Server.Items
|
||||
namespace Server.Items;
|
||||
|
||||
[SerializationGenerator(1, false)]
|
||||
public partial class TransientItem : Item
|
||||
{
|
||||
public class TransientItem : Item
|
||||
private TimerExecutionToken _timerToken;
|
||||
|
||||
[DeltaDateTime]
|
||||
[SerializableField(0)]
|
||||
[SerializedCommandProperty(AccessLevel.GameMaster)]
|
||||
private DateTime _expiration;
|
||||
|
||||
[Constructible]
|
||||
public TransientItem(int itemID, TimeSpan lifeSpan) : base(itemID)
|
||||
{
|
||||
private TimerExecutionToken _timerToken;
|
||||
_expiration = Core.Now + lifeSpan;
|
||||
|
||||
[Constructible]
|
||||
public TransientItem(int itemID, TimeSpan lifeSpan)
|
||||
: base(itemID)
|
||||
Timer.StartTimer(TimeSpan.FromSeconds(5), TimeSpan.FromSeconds(5), CheckExpiry, out _timerToken);
|
||||
}
|
||||
|
||||
public override bool Nontransferable => true;
|
||||
|
||||
public virtual TextDefinition InvalidTransferMessage => TextDefinition.Empty;
|
||||
|
||||
public override void HandleInvalidTransfer(Mobile from)
|
||||
{
|
||||
InvalidTransferMessage.SendMessageTo(from);
|
||||
|
||||
Delete();
|
||||
}
|
||||
|
||||
public virtual void Expire(Mobile parent)
|
||||
{
|
||||
parent?.SendLocalizedMessage(1072515, Name ?? $"#{LabelNumber}"); // The ~1_name~ expired...
|
||||
|
||||
Effects.PlaySound(GetWorldLocation(), Map, 0x201);
|
||||
|
||||
Delete();
|
||||
}
|
||||
|
||||
public virtual void SendTimeRemainingMessage(Mobile to)
|
||||
{
|
||||
var remaining = Utility.Max(_expiration - Core.Now, TimeSpan.Zero);
|
||||
to.SendLocalizedMessage(
|
||||
1072516, // ~1_name~ will expire in ~2_val~ seconds!
|
||||
$"{Name ?? $"#{LabelNumber}"}\t{remaining.TotalSeconds:F0}"
|
||||
);
|
||||
}
|
||||
|
||||
public override void OnDelete()
|
||||
{
|
||||
_timerToken.Cancel();
|
||||
base.OnDelete();
|
||||
}
|
||||
|
||||
public virtual void CheckExpiry()
|
||||
{
|
||||
if (_expiration - Core.Now <= TimeSpan.Zero)
|
||||
{
|
||||
CreationTime = Core.Now;
|
||||
LifeSpan = lifeSpan;
|
||||
|
||||
Timer.StartTimer(TimeSpan.FromSeconds(5), TimeSpan.FromSeconds(5), CheckExpiry, out _timerToken);
|
||||
Expire(RootParent as Mobile);
|
||||
}
|
||||
|
||||
public TransientItem(Serial serial)
|
||||
: base(serial)
|
||||
else
|
||||
{
|
||||
}
|
||||
|
||||
[CommandProperty(AccessLevel.GameMaster)]
|
||||
public TimeSpan LifeSpan { get; set; }
|
||||
|
||||
[CommandProperty(AccessLevel.GameMaster)]
|
||||
public DateTime CreationTime { get; set; }
|
||||
|
||||
public override bool Nontransferable => true;
|
||||
|
||||
public virtual TextDefinition InvalidTransferMessage => TextDefinition.Empty;
|
||||
|
||||
public override void HandleInvalidTransfer(Mobile from)
|
||||
{
|
||||
InvalidTransferMessage.SendMessageTo(from);
|
||||
|
||||
Delete();
|
||||
}
|
||||
|
||||
public virtual void Expire(Mobile parent)
|
||||
{
|
||||
parent?.SendLocalizedMessage(1072515, Name ?? $"#{LabelNumber}"); // The ~1_name~ expired...
|
||||
|
||||
Effects.PlaySound(GetWorldLocation(), Map, 0x201);
|
||||
|
||||
Delete();
|
||||
}
|
||||
|
||||
public virtual void SendTimeRemainingMessage(Mobile to)
|
||||
{
|
||||
to.SendLocalizedMessage(
|
||||
1072516, // ~1_name~ will expire in ~2_val~ seconds!
|
||||
$"{Name ?? $"#{LabelNumber}"}\t{LifeSpan.TotalSeconds:F0}"
|
||||
);
|
||||
}
|
||||
|
||||
public override void OnDelete()
|
||||
{
|
||||
_timerToken.Cancel();
|
||||
base.OnDelete();
|
||||
}
|
||||
|
||||
public virtual void CheckExpiry()
|
||||
{
|
||||
if (CreationTime + LifeSpan < Core.Now)
|
||||
{
|
||||
Expire(RootParent as Mobile);
|
||||
}
|
||||
else
|
||||
{
|
||||
InvalidateProperties();
|
||||
}
|
||||
}
|
||||
|
||||
public override void GetProperties(IPropertyList list)
|
||||
{
|
||||
base.GetProperties(list);
|
||||
|
||||
var remaining = CreationTime + LifeSpan - Core.Now;
|
||||
|
||||
list.Add(1072517, $"{remaining.TotalSeconds:F0}"); // Lifespan: ~1_val~ seconds
|
||||
}
|
||||
|
||||
public override void Serialize(IGenericWriter writer)
|
||||
{
|
||||
base.Serialize(writer);
|
||||
writer.Write(0);
|
||||
|
||||
writer.Write(LifeSpan);
|
||||
writer.Write(CreationTime);
|
||||
}
|
||||
|
||||
public override void Deserialize(IGenericReader reader)
|
||||
{
|
||||
base.Deserialize(reader);
|
||||
var version = reader.ReadInt();
|
||||
|
||||
LifeSpan = reader.ReadTimeSpan();
|
||||
CreationTime = reader.ReadDateTime();
|
||||
|
||||
Timer.StartTimer(TimeSpan.FromSeconds(5), TimeSpan.FromSeconds(5), CheckExpiry, out _timerToken);
|
||||
InvalidateProperties();
|
||||
}
|
||||
}
|
||||
|
||||
public void ResetExpiration(TimeSpan duration) => Expiration = Core.Now + duration;
|
||||
|
||||
public override void GetProperties(IPropertyList list)
|
||||
{
|
||||
base.GetProperties(list);
|
||||
|
||||
var remaining = Utility.Max(_expiration - Core.Now, TimeSpan.Zero);
|
||||
list.Add(1072517, $"{remaining.TotalSeconds:F0}"); // Lifespan: ~1_val~ seconds
|
||||
}
|
||||
|
||||
private void Deserialize(IGenericReader reader, int version)
|
||||
{
|
||||
var lifespan = reader.ReadTimeSpan();
|
||||
var creationTime = reader.ReadDateTime(); // CreationTime
|
||||
|
||||
_expiration = creationTime + lifespan;
|
||||
}
|
||||
|
||||
[AfterDeserialization]
|
||||
private void AfterDeserialization()
|
||||
{
|
||||
Timer.StartTimer(TimeSpan.FromSeconds(5), TimeSpan.FromSeconds(5), CheckExpiry, out _timerToken);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue