## 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.
151 lines
4.7 KiB
C#
151 lines
4.7 KiB
C#
using System;
|
|
using Server.Engines.ConPVP;
|
|
using Server.Targeting;
|
|
|
|
namespace Server.Items
|
|
{
|
|
public class PileOfGlacialSnow : Item
|
|
{
|
|
[Constructible]
|
|
public PileOfGlacialSnow() : base(0x913)
|
|
{
|
|
Hue = 0x480;
|
|
Weight = 1.0;
|
|
LootType = LootType.Blessed;
|
|
}
|
|
|
|
public PileOfGlacialSnow(Serial serial) : base(serial)
|
|
{
|
|
}
|
|
|
|
public override int LabelNumber => 1070874; // a Pile of Glacial Snow
|
|
|
|
public override void Serialize(IGenericWriter writer)
|
|
{
|
|
base.Serialize(writer);
|
|
|
|
writer.Write(1); // version
|
|
}
|
|
|
|
public override void Deserialize(IGenericReader reader)
|
|
{
|
|
base.Deserialize(reader);
|
|
|
|
var version = reader.ReadInt();
|
|
|
|
if (version == 0)
|
|
{
|
|
Weight = 1.0;
|
|
LootType = LootType.Blessed;
|
|
}
|
|
}
|
|
|
|
public override void OnSingleClick(Mobile from)
|
|
{
|
|
base.OnSingleClick(from);
|
|
|
|
LabelTo(from, 1070880); // Winter 2004
|
|
}
|
|
|
|
public override void GetProperties(IPropertyList list)
|
|
{
|
|
base.GetProperties(list);
|
|
|
|
list.Add(1070880); // Winter 2004
|
|
}
|
|
|
|
public override void OnDoubleClick(Mobile from)
|
|
{
|
|
if (!IsChildOf(from.Backpack))
|
|
{
|
|
from.SendLocalizedMessage(1042010); // You must have the object in your backpack to use it.
|
|
}
|
|
else if (from.Mounted)
|
|
{
|
|
from.SendLocalizedMessage(1010097); // You cannot use this while mounted.
|
|
}
|
|
else if (from.CanBeginAction<SnowPile>())
|
|
{
|
|
from.SendLocalizedMessage(1005575); // You carefully pack the snow into a ball...
|
|
from.Target = new SnowTarget(from, this);
|
|
}
|
|
else
|
|
{
|
|
from.SendLocalizedMessage(1005574); // The snow is not ready to be packed yet. Keep trying.
|
|
}
|
|
}
|
|
|
|
private class InternalTimer : Timer
|
|
{
|
|
private readonly Mobile m_From;
|
|
|
|
public InternalTimer(Mobile from) : base(TimeSpan.FromSeconds(5.0)) => m_From = from;
|
|
|
|
protected override void OnTick()
|
|
{
|
|
m_From.EndAction<SnowPile>();
|
|
}
|
|
}
|
|
|
|
private class SnowTarget : Target
|
|
{
|
|
private Item m_Snow;
|
|
private Mobile m_Thrower;
|
|
|
|
public SnowTarget(Mobile thrower, Item snow) : base(10, false, TargetFlags.None)
|
|
{
|
|
m_Thrower = thrower;
|
|
m_Snow = snow;
|
|
}
|
|
|
|
protected override void OnTarget(Mobile from, object target)
|
|
{
|
|
if (target == from)
|
|
{
|
|
from.SendLocalizedMessage(1005576); // You can't throw this at yourself.
|
|
}
|
|
else if (target is Mobile targ)
|
|
{
|
|
var pack = targ.Backpack;
|
|
|
|
if (from.Region.IsPartOf<SafeZone>() || targ.Region.IsPartOf<SafeZone>())
|
|
{
|
|
from.SendMessage("You may not throw snow here.");
|
|
}
|
|
else if (pack?.FindItemByType(new[] { typeof(SnowPile), typeof(PileOfGlacialSnow) }) != null)
|
|
{
|
|
if (from.BeginAction<SnowPile>())
|
|
{
|
|
new InternalTimer(from).Start();
|
|
|
|
from.PlaySound(0x145);
|
|
|
|
from.Animate(9, 1, 1, true, false, 0);
|
|
|
|
targ.SendLocalizedMessage(1010572); // You have just been hit by a snowball!
|
|
from.SendLocalizedMessage(1010573); // You throw the snowball and hit the target!
|
|
|
|
Effects.SendMovingEffect(from, targ, 0x36E4, 7, 0, false, true, 0x47F);
|
|
}
|
|
else
|
|
{
|
|
from.SendLocalizedMessage(1005574); // The snow is not ready to be packed yet. Keep trying.
|
|
}
|
|
}
|
|
else
|
|
{
|
|
from.SendLocalizedMessage(
|
|
1005577
|
|
); // You can only throw a snowball at something that can throw one back.
|
|
}
|
|
}
|
|
else
|
|
{
|
|
from.SendLocalizedMessage(
|
|
1005577
|
|
); // You can only throw a snowball at something that can throw one back.
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|