## 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.
102 lines
2.8 KiB
C#
102 lines
2.8 KiB
C#
using System;
|
|
using ModernUO.Serialization;
|
|
|
|
namespace Server.Items
|
|
{
|
|
[SerializationGenerator(0, false)]
|
|
public partial class FireworksWand : MagicWand
|
|
{
|
|
[SerializableField(0)]
|
|
[InvalidateProperties]
|
|
[SerializableFieldAttr("[CommandProperty(AccessLevel.GameMaster)]")]
|
|
private int _charges;
|
|
|
|
[Constructible]
|
|
public FireworksWand(int charges = 100)
|
|
{
|
|
Charges = charges;
|
|
LootType = LootType.Blessed;
|
|
}
|
|
|
|
public override int LabelNumber => 1041424; // a fireworks wand
|
|
|
|
public override void AddNameProperties(IPropertyList list)
|
|
{
|
|
base.AddNameProperties(list);
|
|
|
|
list.Add(1060741, $"{_charges}"); // charges: ~1_val~
|
|
}
|
|
|
|
public override void OnDoubleClick(Mobile from)
|
|
{
|
|
BeginLaunch(from, true);
|
|
}
|
|
|
|
public void BeginLaunch(Mobile from, bool useCharges)
|
|
{
|
|
var map = from.Map;
|
|
|
|
if (map == null || map == Map.Internal)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (useCharges)
|
|
{
|
|
if (Charges > 0)
|
|
{
|
|
--Charges;
|
|
}
|
|
else
|
|
{
|
|
from.SendLocalizedMessage(502412); // There are no charges left on that item.
|
|
return;
|
|
}
|
|
}
|
|
|
|
from.SendLocalizedMessage(502615); // You launch a firework!
|
|
|
|
var ourLoc = GetWorldLocation();
|
|
|
|
var startLoc = new Point3D(ourLoc.X, ourLoc.Y, ourLoc.Z + 10);
|
|
var endLoc = new Point3D(
|
|
startLoc.X + Utility.RandomMinMax(-2, 2),
|
|
startLoc.Y + Utility.RandomMinMax(-2, 2),
|
|
startLoc.Z + 32
|
|
);
|
|
|
|
Effects.SendMovingEffect(
|
|
new Entity(Serial.Zero, startLoc, map),
|
|
new Entity(Serial.Zero, endLoc, map),
|
|
0x36E4,
|
|
5,
|
|
0
|
|
);
|
|
|
|
Timer.StartTimer(TimeSpan.FromSeconds(1.0), () => FinishLaunch(endLoc, map));
|
|
}
|
|
|
|
private static void FinishLaunch(Point3D endLoc, Map map)
|
|
{
|
|
var hue = Utility.Random(40) switch
|
|
{
|
|
< 8 => 0x66D,
|
|
< 10 => 0x482,
|
|
< 12 => 0x47E,
|
|
< 16 => 0x480,
|
|
< 20 => 0x47F,
|
|
_ => 0
|
|
};
|
|
|
|
if (Utility.RandomBool())
|
|
{
|
|
hue = Utility.RandomList(0x47E, 0x47F, 0x480, 0x482, 0x66D);
|
|
}
|
|
|
|
var renderMode = Utility.RandomList(0, 2, 3, 4, 5, 7);
|
|
|
|
Effects.PlaySound(endLoc, map, Utility.Random(0x11B, 4));
|
|
Effects.SendLocationEffect(endLoc, map, 0x373A + 0x10 * Utility.Random(4), 16, 10, hue, renderMode);
|
|
}
|
|
}
|
|
}
|