fix: Optimizes OPL using string interpolation (#1041)

## Breaking Changes (New API)
ObjectPropertyList supports the following API:
```cs
list.Add(500000);
list.Add(500001, stringArgument);
list.Add("Some text");
list.Add($"Some text with {argument}");
list.Add(500002, $"{arg1}\t{arg2}");
```

## Notes
1. All API uses that require a formatter like this:
    ```cs
    list.Add(500002, "{0}\t{1}", arg1, arg2);
    ```
    Should be changed to use string interpolation, for example:
    ```cs
    list.Add(500002, $"{arg1}\t{arg2}");
    ```
2. The following paradigm should no longer be used:
    ```cs
    list.Add(1061170, prop.ToString()); // strength requirement ~1_val~
    ```
    The new string interpolation API will avoid having to convert the argument to a string before writing it to the packet. Instead use the following:
    ```cs
    list.Add(1061170, $"{prop}"); // strength requirement ~1_val~
    ```

### Benchmarks
```cs
|                         Method |     Mean |   Error |  StdDev |  Gen 0 | Allocated |
|------------------------------- |---------:|--------:|--------:|-------:|----------:|
|                BenchmarkOldOPL | 241.0 ns | 0.56 ns | 0.47 ns | 0.0105 |      88 B |
| BenchmarkStringInterpolatedOPL | 199.9 ns | 2.44 ns | 2.39 ns |      - |         - |
```

### Changes
- [X] Removes crash in STArray.Return when array is null.
- [X] Fixes NPE in OPL when entity is null. Serial in packet will be 0 when entity is null.
- [X] Fixes NPE in AosAttributes when Parent is null.
- [X] Changes OPL to use string interpolation.
- [X] Introduces `IPropertyList` to allow extending PropertyList for other uses.
This commit is contained in:
Kamron Batman 2022-06-02 10:09:53 -07:00 • committed by GitHub
parent fe31470f05
commit ecbee17690
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
227 changed files with 1426 additions and 1008 deletions

View file

@ -59,7 +59,7 @@ namespace Server.Items
bool ICommodity.IsDeedable => true;
public override void GetProperties(ObjectPropertyList list)
public override void GetProperties(IPropertyList list)
{
base.GetProperties(list);

View file

@ -253,7 +253,7 @@ namespace Server.Items
public Item Deed => new TrophyDeed(WestID, NorthID, DeedNumber, m_AddonNumber, m_Hunter, m_AnimalWeight);
public override void GetProperties(ObjectPropertyList list)
public override void GetProperties(IPropertyList list)
{
base.GetProperties(list);
@ -264,7 +264,7 @@ namespace Server.Items
list.Add(1070857, m_Hunter.Name); // Caught by ~1_fisherman~
}
list.Add(1070858, m_AnimalWeight.ToString()); // ~1_weight~ stones
list.Add(1070858, $"{m_AnimalWeight}"); // ~1_weight~ stones
}
}
@ -428,7 +428,7 @@ namespace Server.Items
public override int LabelNumber => m_DeedNumber;
public override void GetProperties(ObjectPropertyList list)
public override void GetProperties(IPropertyList list)
{
base.GetProperties(list);
@ -439,7 +439,7 @@ namespace Server.Items
list.Add(1070857, m_Hunter.Name); // Caught by ~1_fisherman~
}
list.Add(1070858, m_AnimalWeight.ToString()); // ~1_weight~ stones
list.Add(1070858, $"{m_AnimalWeight}"); // ~1_weight~ stones
}
}

View file

@ -51,7 +51,7 @@ namespace Server.Items
LabelTo(from, 1050039, $"#{LabelNumber}\t#1041645");
}
public override void AddNameProperties(ObjectPropertyList list)
public override void AddNameProperties(IPropertyList list)
{
base.AddNameProperties(list);
list.Add(1041645); // recovered from a shipwreck

View file

@ -63,14 +63,14 @@ namespace Server.Items
public virtual bool RequireDeepWater => true;
public override void GetProperties(ObjectPropertyList list)
public override void GetProperties(IPropertyList list)
{
base.GetProperties(list);
AddNetProperties(list);
}
protected virtual void AddNetProperties(ObjectPropertyList list)
protected virtual void AddNetProperties(IPropertyList list)
{
// as if the name wasn't enough..
list.Add(1017410); // Special Fishing Net
@ -435,7 +435,7 @@ namespace Server.Items
public override int LabelNumber => 1063451; // a fabled fishing net
protected override void AddNetProperties(ObjectPropertyList list)
protected override void AddNetProperties(IPropertyList list)
{
}

View file

@ -109,7 +109,7 @@ namespace Server.Items
return 100;
}
public override void GetProperties(ObjectPropertyList list)
public override void GetProperties(IPropertyList list)
{
base.GetProperties(list);
@ -122,7 +122,7 @@ namespace Server.Items
list.Add(1060636); // exceptional
}
list.Add(1060584, m_UsesRemaining.ToString()); // uses remaining: ~1_val~
list.Add(1060584, $"{m_UsesRemaining}"); // uses remaining: ~1_val~
}
public virtual void DisplayDurabilityTo(Mobile m)

View file

@ -40,7 +40,7 @@ namespace Server.Items
bool ICommodity.IsDeedable => true;
public override void GetProperties(ObjectPropertyList list)
public override void GetProperties(IPropertyList list)
{
base.GetProperties(list);

View file

@ -98,7 +98,7 @@ namespace Server.Items
}
}
public override void GetProperties(ObjectPropertyList list)
public override void GetProperties(IPropertyList list)
{
base.GetProperties(list);

View file

@ -217,7 +217,7 @@ namespace Server.Items
InvalidateProperties();
}
public override void GetProperties(ObjectPropertyList list)
public override void GetProperties(IPropertyList list)
{
base.GetProperties(list);
@ -232,23 +232,23 @@ namespace Server.Items
if (m_TargetMap == Map.Tokuno)
{
list.Add(House != null ? 1063260 : 1063259, RuneFormat, desc); // ~1_val~ (Tokuno Islands)[(House)]
list.Add(House != null ? 1063260 : 1063259, $"a recall rune for {desc}"); // ~1_val~ (Tokuno Islands)[(House)]
}
else if (m_TargetMap == Map.Malas)
{
list.Add(House != null ? 1062454 : 1060804, RuneFormat, desc); // ~1_val~ (Malas)[(House)]
list.Add(House != null ? 1062454 : 1060804, $"a recall rune for {desc}"); // ~1_val~ (Malas)[(House)]
}
else if (m_TargetMap == Map.Felucca)
{
list.Add(House != null ? 1062452 : 1060805, RuneFormat, desc); // ~1_val~ (Felucca)[(House)]
list.Add(House != null ? 1062452 : 1060805, $"a recall rune for {desc}"); // ~1_val~ (Felucca)[(House)]
}
else if (m_TargetMap == Map.Trammel)
{
list.Add(House != null ? 1062453 : 1060806, RuneFormat, desc); // ~1_val~ (Trammel)[(House)]
list.Add(House != null ? 1062453 : 1060806, $"a recall rune for {desc}"); // ~1_val~ (Trammel)[(House)]
}
else
{
list.Add(House != null ? "{0} ({1})(House)" : "{0} ({1})", string.Format(RuneFormat, desc), m_TargetMap);
list.Add(House != null ? $"a recall rune for {desc} ({m_TargetMap})(House)" : $"a recall rune for {desc} ({m_TargetMap})");
}
}
}
@ -263,33 +263,33 @@ namespace Server.Items
{
LabelTo(
from,
House != null ? 1063260 : 1063259,
House != null ? 1063260 : 1063259, // ~1_val~ (Tokuno Islands)[(House)]
string.Format(RuneFormat, desc)
); // ~1_val~ (Tokuno Islands)[(House)]
);
}
else if (m_TargetMap == Map.Malas)
{
LabelTo(
from,
House != null ? 1062454 : 1060804,
House != null ? 1062454 : 1060804, // ~1_val~ (Malas)[(House)]
string.Format(RuneFormat, desc)
); // ~1_val~ (Malas)[(House)]
);
}
else if (m_TargetMap == Map.Felucca)
{
LabelTo(
from,
House != null ? 1062452 : 1060805,
House != null ? 1062452 : 1060805, // ~1_val~ (Felucca)[(House)]
string.Format(RuneFormat, desc)
); // ~1_val~ (Felucca)[(House)]
);
}
else if (m_TargetMap == Map.Trammel)
{
LabelTo(
from,
House != null ? 1062453 : 1060806,
House != null ? 1062453 : 1060806, // ~1_val~ (Trammel)[(House)]
string.Format(RuneFormat, desc)
); // ~1_val~ (Trammel)[(House)]
);
}
else
{

View file

@ -276,7 +276,7 @@ namespace Server.Items
return false;
}
public override void GetProperties(ObjectPropertyList list)
public override void GetProperties(IPropertyList list)
{
base.GetProperties(list);

View file

@ -695,7 +695,7 @@ namespace Server.Items
to.NetState.SendSpellbookContent(Serial, ItemID, BookOffset + 1, m_Content);
}
public override void GetProperties(ObjectPropertyList list)
public override void GetProperties(IPropertyList list)
{
base.GetProperties(list);
@ -738,72 +738,72 @@ namespace Server.Items
if ((prop = Attributes.WeaponDamage) != 0)
{
list.Add(1060401, prop.ToString()); // damage increase ~1_val~%
list.Add(1060401, $"{prop}"); // damage increase ~1_val~%
}
if ((prop = Attributes.DefendChance) != 0)
{
list.Add(1060408, prop.ToString()); // defense chance increase ~1_val~%
list.Add(1060408, $"{prop}"); // defense chance increase ~1_val~%
}
if ((prop = Attributes.BonusDex) != 0)
{
list.Add(1060409, prop.ToString()); // dexterity bonus ~1_val~
list.Add(1060409, $"{prop}"); // dexterity bonus ~1_val~
}
if ((prop = Attributes.EnhancePotions) != 0)
{
list.Add(1060411, prop.ToString()); // enhance potions ~1_val~%
list.Add(1060411, $"{prop}"); // enhance potions ~1_val~%
}
if ((prop = Attributes.CastRecovery) != 0)
{
list.Add(1060412, prop.ToString()); // faster cast recovery ~1_val~
list.Add(1060412, $"{prop}"); // faster cast recovery ~1_val~
}
if ((prop = Attributes.CastSpeed) != 0)
{
list.Add(1060413, prop.ToString()); // faster casting ~1_val~
list.Add(1060413, $"{prop}"); // faster casting ~1_val~
}
if ((prop = Attributes.AttackChance) != 0)
{
list.Add(1060415, prop.ToString()); // hit chance increase ~1_val~%
list.Add(1060415, $"{prop}"); // hit chance increase ~1_val~%
}
if ((prop = Attributes.BonusHits) != 0)
{
list.Add(1060431, prop.ToString()); // hit point increase ~1_val~
list.Add(1060431, $"{prop}"); // hit point increase ~1_val~
}
if ((prop = Attributes.BonusInt) != 0)
{
list.Add(1060432, prop.ToString()); // intelligence bonus ~1_val~
list.Add(1060432, $"{prop}"); // intelligence bonus ~1_val~
}
if ((prop = Attributes.LowerManaCost) != 0)
{
list.Add(1060433, prop.ToString()); // lower mana cost ~1_val~%
list.Add(1060433, $"{prop}"); // lower mana cost ~1_val~%
}
if ((prop = Attributes.LowerRegCost) != 0)
{
list.Add(1060434, prop.ToString()); // lower reagent cost ~1_val~%
list.Add(1060434, $"{prop}"); // lower reagent cost ~1_val~%
}
if ((prop = Attributes.Luck) != 0)
{
list.Add(1060436, prop.ToString()); // luck ~1_val~
list.Add(1060436, $"{prop}"); // luck ~1_val~
}
if ((prop = Attributes.BonusMana) != 0)
{
list.Add(1060439, prop.ToString()); // mana increase ~1_val~
list.Add(1060439, $"{prop}"); // mana increase ~1_val~
}
if ((prop = Attributes.RegenMana) != 0)
{
list.Add(1060440, prop.ToString()); // mana regeneration ~1_val~
list.Add(1060440, $"{prop}"); // mana regeneration ~1_val~
}
if (Attributes.NightSight != 0)
@ -813,17 +813,17 @@ namespace Server.Items
if ((prop = Attributes.ReflectPhysical) != 0)
{
list.Add(1060442, prop.ToString()); // reflect physical damage ~1_val~%
list.Add(1060442, $"{prop}"); // reflect physical damage ~1_val~%
}
if ((prop = Attributes.RegenStam) != 0)
{
list.Add(1060443, prop.ToString()); // stamina regeneration ~1_val~
list.Add(1060443, $"{prop}"); // stamina regeneration ~1_val~
}
if ((prop = Attributes.RegenHits) != 0)
{
list.Add(1060444, prop.ToString()); // hit point regeneration ~1_val~
list.Add(1060444, $"{prop}"); // hit point regeneration ~1_val~
}
if (Attributes.SpellChanneling != 0)
@ -833,30 +833,30 @@ namespace Server.Items
if ((prop = Attributes.SpellDamage) != 0)
{
list.Add(1060483, prop.ToString()); // spell damage increase ~1_val~%
list.Add(1060483, $"{prop}"); // spell damage increase ~1_val~%
}
if ((prop = Attributes.BonusStam) != 0)
{
list.Add(1060484, prop.ToString()); // stamina increase ~1_val~
list.Add(1060484, $"{prop}"); // stamina increase ~1_val~
}
if ((prop = Attributes.BonusStr) != 0)
{
list.Add(1060485, prop.ToString()); // strength bonus ~1_val~
list.Add(1060485, $"{prop}"); // strength bonus ~1_val~
}
if ((prop = Attributes.WeaponSpeed) != 0)
{
list.Add(1060486, prop.ToString()); // swing speed increase ~1_val~%
list.Add(1060486, $"{prop}"); // swing speed increase ~1_val~%
}
if (Core.ML && (prop = Attributes.IncreasedKarmaLoss) != 0)
{
list.Add(1075210, prop.ToString()); // Increased Karma Loss ~1val~%
list.Add(1075210, $"{prop}"); // Increased Karma Loss ~1val~%
}
list.Add(1042886, SpellCount.ToString()); // ~1_NUMBERS_OF_SPELLS~ Spells
list.Add(1042886, $"{SpellCount}"); // ~1_NUMBERS_OF_SPELLS~ Spells
}
public override void OnSingleClick(Mobile from)

View file

@ -42,7 +42,7 @@ namespace Server.Items
}
}
public override void GetProperties(ObjectPropertyList list)
public override void GetProperties(IPropertyList list)
{
base.GetProperties(list);
@ -50,7 +50,7 @@ namespace Server.Items
if (r != null)
{
list.Add(1049644, r.TextDefinition.ToString()); // [~1_stuff~]
list.Add(1049644, $"{r.TextDefinition}"); // [~1_stuff~]
}
}

View file

@ -92,7 +92,7 @@ namespace Server.Items
}
}
public override void AddNameProperty(ObjectPropertyList list)
public override void AddNameProperty(IPropertyList list)
{
list.Add(
1061133,
@ -100,7 +100,7 @@ namespace Server.Items
); // A repair service contract from ~1_SKILL_TITLE~ ~2_SKILL_NAME~.
}
public override void GetProperties(ObjectPropertyList list)
public override void GetProperties(IPropertyList list)
{
base.GetProperties(list);

View file

@ -359,7 +359,7 @@ namespace Server.Items
m_Instruments[from] = item;
}
public override void GetProperties(ObjectPropertyList list)
public override void GetProperties(IPropertyList list)
{
var oldUses = m_UsesRemaining;
CheckReplenishUses(false);
@ -376,7 +376,7 @@ namespace Server.Items
list.Add(1060636); // exceptional
}
list.Add(1060584, m_UsesRemaining.ToString()); // uses remaining: ~1_val~
list.Add(1060584, $"{m_UsesRemaining}"); // uses remaining: ~1_val~
if (m_ReplenishesCharges)
{

View file

@ -87,11 +87,11 @@ namespace Server.Items
from.MovingEffect(to, 0x2804, 5, 0, false, false);
}
public override void GetProperties(ObjectPropertyList list)
public override void GetProperties(IPropertyList list)
{
base.GetProperties(list);
list.Add(1060584, m_UsesRemaining.ToString()); // uses remaining: ~1_val~
list.Add(1060584, $"{m_UsesRemaining}"); // uses remaining: ~1_val~
if (m_Poison != null && m_PoisonCharges > 0)
{

View file

@ -73,11 +73,11 @@ namespace Server.Items
set { }
}
public override void GetProperties(ObjectPropertyList list)
public override void GetProperties(IPropertyList list)
{
base.GetProperties(list);
list.Add(1060584, m_UsesRemaining.ToString()); // uses remaining: ~1_val~
list.Add(1060584, $"{m_UsesRemaining}"); // uses remaining: ~1_val~
if (m_Poison != null && m_PoisonCharges > 0)
{

View file

@ -89,11 +89,11 @@ namespace Server.Items
from.MovingEffect(to, 0x27AC, 1, 0, false, false);
}
public override void GetProperties(ObjectPropertyList list)
public override void GetProperties(IPropertyList list)
{
base.GetProperties(list);
list.Add(1060584, m_UsesRemaining.ToString()); // uses remaining: ~1_val~
list.Add(1060584, $"{m_UsesRemaining}"); // uses remaining: ~1_val~
if (m_Poison != null && m_PoisonCharges > 0)
{

View file

@ -74,11 +74,11 @@ namespace Server.Items
set { }
}
public override void GetProperties(ObjectPropertyList list)
public override void GetProperties(IPropertyList list)
{
base.GetProperties(list);
list.Add(1060584, m_UsesRemaining.ToString()); // uses remaining: ~1_val~
list.Add(1060584, $"{m_UsesRemaining}"); // uses remaining: ~1_val~
if (m_Poison != null && m_PoisonCharges > 0)
{

View file

@ -29,7 +29,7 @@ namespace Server.Items
base.OnDoubleClick(from);
}
public override void GetProperties(ObjectPropertyList list)
public override void GetProperties(IPropertyList list)
{
base.GetProperties(list);

View file

@ -30,7 +30,7 @@ namespace Server.Items
base.OnDoubleClick(from);
}
public override void GetProperties(ObjectPropertyList list)
public override void GetProperties(IPropertyList list)
{
base.GetProperties(list);

View file

@ -14,7 +14,7 @@ namespace Server.Items
public override bool MetallicHues => true;
public override void GetProperties(ObjectPropertyList list)
public override void GetProperties(IPropertyList list)
{
base.GetProperties(list);

View file

@ -30,7 +30,7 @@ namespace Server.Items
base.OnDoubleClick(from);
}
public override void GetProperties(ObjectPropertyList list)
public override void GetProperties(IPropertyList list)
{
base.GetProperties(list);

View file

@ -30,7 +30,7 @@ namespace Server.Items
base.OnDoubleClick(from);
}
public override void GetProperties(ObjectPropertyList list)
public override void GetProperties(IPropertyList list)
{
base.GetProperties(list);

View file

@ -26,7 +26,7 @@ namespace Server.Items
base.OnDoubleClick(from);
}
public override void GetProperties(ObjectPropertyList list)
public override void GetProperties(IPropertyList list)
{
base.GetProperties(list);

View file

@ -30,7 +30,7 @@ namespace Server.Items
base.OnDoubleClick(from);
}
public override void GetProperties(ObjectPropertyList list)
public override void GetProperties(IPropertyList list)
{
base.GetProperties(list);

View file

@ -114,7 +114,7 @@ namespace Server.Items
return 100;
}
public override void GetProperties(ObjectPropertyList list)
public override void GetProperties(IPropertyList list)
{
base.GetProperties(list);
@ -127,7 +127,7 @@ namespace Server.Items
list.Add(1060636); // exceptional
}
list.Add(1060584, m_UsesRemaining.ToString()); // uses remaining: ~1_val~
list.Add(1060584, $"{m_UsesRemaining}"); // uses remaining: ~1_val~
}
public virtual void DisplayDurabilityTo(Mobile m)

View file

@ -42,7 +42,7 @@ namespace Server.Items
}
}
public override void AddNameProperties(ObjectPropertyList list)
public override void AddNameProperties(IPropertyList list)
{
base.AddNameProperties(list);

View file

@ -24,7 +24,7 @@ namespace Server.Items
public override CraftSystem CraftSystem => DefTailoring.CraftSystem;
public override void AddNameProperty(ObjectPropertyList list)
public override void AddNameProperty(IPropertyList list)
{
var v = " ";