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:
parent
fe31470f05
commit
ecbee17690
227 changed files with 1426 additions and 1008 deletions
|
|
@ -236,7 +236,7 @@ namespace Server.Items
|
|||
}
|
||||
}
|
||||
|
||||
public override void GetProperties(ObjectPropertyList list)
|
||||
public override void GetProperties(IPropertyList list)
|
||||
{
|
||||
base.GetProperties(list);
|
||||
|
||||
|
|
@ -256,23 +256,23 @@ namespace Server.Items
|
|||
{
|
||||
if (ammo is Arrow)
|
||||
{
|
||||
list.Add(1075265, "{0}\t{1}", ammo.Amount, Capacity); // Ammo: ~1_QUANTITY~/~2_CAPACITY~ arrows
|
||||
list.Add(1075265, $"{ammo.Amount}\t{Capacity}"); // Ammo: ~1_QUANTITY~/~2_CAPACITY~ arrows
|
||||
}
|
||||
else if (ammo is Bolt)
|
||||
{
|
||||
list.Add(1075266, "{0}\t{1}", ammo.Amount, Capacity); // Ammo: ~1_QUANTITY~/~2_CAPACITY~ bolts
|
||||
list.Add(1075266, $"{ammo.Amount}\t{Capacity}"); // Ammo: ~1_QUANTITY~/~2_CAPACITY~ bolts
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
list.Add(1075265, "{0}\t{1}", 0, Capacity); // Ammo: ~1_QUANTITY~/~2_CAPACITY~ arrows
|
||||
list.Add(1075265, $"0\t{Capacity}"); // Ammo: ~1_QUANTITY~/~2_CAPACITY~ arrows
|
||||
}
|
||||
|
||||
int prop;
|
||||
|
||||
if ((prop = m_DamageIncrease) != 0)
|
||||
{
|
||||
list.Add(1074762, prop.ToString()); // Damage modifier: ~1_PERCENT~%
|
||||
list.Add(1074762, $"{prop}"); // Damage modifier: ~1_PERCENT~%
|
||||
}
|
||||
|
||||
int phys = 0, fire = 0, cold = 0, pois = 0, nrgy = 0, chaos = 0, direct = 0;
|
||||
|
|
@ -281,104 +281,104 @@ namespace Server.Items
|
|||
|
||||
if (phys != 0)
|
||||
{
|
||||
list.Add(1060403, phys.ToString()); // physical damage ~1_val~%
|
||||
list.Add(1060403, $"{phys}"); // physical damage ~1_val~%
|
||||
}
|
||||
|
||||
if (fire != 0)
|
||||
{
|
||||
list.Add(1060405, fire.ToString()); // fire damage ~1_val~%
|
||||
list.Add(1060405, $"{fire}"); // fire damage ~1_val~%
|
||||
}
|
||||
|
||||
if (cold != 0)
|
||||
{
|
||||
list.Add(1060404, cold.ToString()); // cold damage ~1_val~%
|
||||
list.Add(1060404, $"{cold}"); // cold damage ~1_val~%
|
||||
}
|
||||
|
||||
if (pois != 0)
|
||||
{
|
||||
list.Add(1060406, pois.ToString()); // poison damage ~1_val~%
|
||||
list.Add(1060406, $"{pois}"); // poison damage ~1_val~%
|
||||
}
|
||||
|
||||
if (nrgy != 0)
|
||||
{
|
||||
list.Add(1060407, nrgy.ToString()); // energy damage ~1_val
|
||||
list.Add(1060407, $"{nrgy}"); // energy damage ~1_val
|
||||
}
|
||||
|
||||
if (chaos != 0)
|
||||
{
|
||||
list.Add(1072846, chaos.ToString()); // chaos damage ~1_val~%
|
||||
list.Add(1072846, $"{chaos}"); // chaos damage ~1_val~%
|
||||
}
|
||||
|
||||
if (direct != 0)
|
||||
{
|
||||
list.Add(1079978, direct.ToString()); // Direct Damage: ~1_PERCENT~%
|
||||
list.Add(1079978, $"{direct}"); // Direct Damage: ~1_PERCENT~%
|
||||
}
|
||||
|
||||
list.Add(1075085); // Requirement: Mondain's Legacy
|
||||
|
||||
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)
|
||||
|
|
@ -388,58 +388,54 @@ 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 ((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 ((prop = m_LowerAmmoCost) > 0)
|
||||
{
|
||||
list.Add(1075208, prop.ToString()); // Lower Ammo Cost ~1_Percentage~%
|
||||
list.Add(1075208, $"{prop}"); // Lower Ammo Cost ~1_Percentage~%
|
||||
}
|
||||
|
||||
var weight = ammo != null ? ammo.Weight + ammo.Amount : 0;
|
||||
|
||||
list.Add(
|
||||
1072241,
|
||||
"{0}\t{1}\t{2}\t{3}",
|
||||
Items.Count,
|
||||
DefaultMaxItems,
|
||||
(int)weight,
|
||||
DefaultMaxWeight
|
||||
); // Contents: ~1_COUNT~/~2_MAXCOUNT items, ~3_WEIGHT~/~4_MAXWEIGHT~ stones
|
||||
1072241, // Contents: ~1_COUNT~/~2_MAXCOUNT items, ~3_WEIGHT~/~4_MAXWEIGHT~ stones
|
||||
$"{Items.Count}\t{DefaultMaxItems}\t{(int)weight}\t{DefaultMaxWeight}"
|
||||
);
|
||||
|
||||
if ((prop = m_WeightReduction) != 0)
|
||||
{
|
||||
list.Add(1072210, prop.ToString()); // Weight reduction: ~1_PERCENTAGE~%
|
||||
list.Add(1072210, $"{prop}"); // Weight reduction: ~1_PERCENTAGE~%
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue