## Changes
- [X] Adds OPL convenience methods
- `opl.Add(cliloc, value)` and `opl.Add(value)` - value as an integer or string works just like `opl.Add(cliloc, $"{value}")`
- `opl.AddLocalized(cliloc, clilocValue)` - works the same as `opl.Add(cliloc, $"#{clilocValue}");`
- [X] Simplifies basic `list.Add()` situations
- [X] Changes cliloc as an argument so it works with custom IPropertyList implementations (HTML)
- [X] Fixes plants so they support the old localization and new (changed in 7.0.12.0+)
- [X] Exposes more methods to override for Item to make creating custom OPL possible.
## Important Notes
* Using a ternary as an argument, like this `opl.Add(number, showType ? $"{type}\t{value}" : $"{value}");` _will not use the correct string interpolation_. This means if you use a custom PropertyList (for HTML or some other purpose), the property list won't be localized properly.
* All localization values must be interpolated, even if they are literal strings, or integers. Example: `opl.Add(number, $"{"Charges"}\t{m_Charges}");` is correct. Using the following: `$"Charges\t{m_Charges}"` will not work for custom PropertyList implementations!
197 lines
6.5 KiB
C#
197 lines
6.5 KiB
C#
using Server.Network;
|
|
using Server.Targeting;
|
|
|
|
namespace Server.Items
|
|
{
|
|
public class PowderOfTemperament : Item, IUsesRemaining
|
|
{
|
|
private int m_UsesRemaining;
|
|
|
|
[Constructible]
|
|
public PowderOfTemperament(int charges = 10) : base(4102)
|
|
{
|
|
Weight = 1.0;
|
|
Hue = 2419;
|
|
UsesRemaining = charges;
|
|
}
|
|
|
|
public PowderOfTemperament(Serial serial) : base(serial)
|
|
{
|
|
}
|
|
|
|
public override int LabelNumber => 1049082; // powder of fortifying
|
|
|
|
[CommandProperty(AccessLevel.GameMaster)]
|
|
public int UsesRemaining
|
|
{
|
|
get => m_UsesRemaining;
|
|
set
|
|
{
|
|
m_UsesRemaining = value;
|
|
InvalidateProperties();
|
|
}
|
|
}
|
|
|
|
bool IUsesRemaining.ShowUsesRemaining
|
|
{
|
|
get => true;
|
|
set { }
|
|
}
|
|
|
|
public override void Serialize(IGenericWriter writer)
|
|
{
|
|
base.Serialize(writer);
|
|
|
|
writer.Write(0);
|
|
writer.Write(m_UsesRemaining);
|
|
}
|
|
|
|
public override void Deserialize(IGenericReader reader)
|
|
{
|
|
base.Deserialize(reader);
|
|
|
|
var version = reader.ReadInt();
|
|
|
|
switch (version)
|
|
{
|
|
case 0:
|
|
{
|
|
m_UsesRemaining = reader.ReadInt();
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
public override void GetProperties(IPropertyList list)
|
|
{
|
|
base.GetProperties(list);
|
|
|
|
list.Add(1060584, m_UsesRemaining); // uses remaining: ~1_val~
|
|
}
|
|
|
|
public virtual void DisplayDurabilityTo(Mobile m)
|
|
{
|
|
LabelToAffix(m, 1017323, AffixType.Append, $": {m_UsesRemaining}"); // Durability
|
|
}
|
|
|
|
public override void OnSingleClick(Mobile from)
|
|
{
|
|
DisplayDurabilityTo(from);
|
|
|
|
base.OnSingleClick(from);
|
|
}
|
|
|
|
public override void OnDoubleClick(Mobile from)
|
|
{
|
|
if (IsChildOf(from.Backpack))
|
|
{
|
|
from.Target = new InternalTarget(this);
|
|
}
|
|
else
|
|
{
|
|
from.SendLocalizedMessage(1042001); // That must be in your pack for you to use it.
|
|
}
|
|
}
|
|
|
|
private class InternalTarget : Target
|
|
{
|
|
private readonly PowderOfTemperament m_Powder;
|
|
|
|
public InternalTarget(PowderOfTemperament powder) : base(2, false, TargetFlags.None) => m_Powder = powder;
|
|
|
|
protected override void OnTarget(Mobile from, object targeted)
|
|
{
|
|
if (m_Powder?.Deleted != false || m_Powder.UsesRemaining <= 0)
|
|
{
|
|
from.SendLocalizedMessage(1049086); // You have used up your powder of temperament.
|
|
return;
|
|
}
|
|
|
|
if (targeted is Item item && item is IDurability wearable)
|
|
{
|
|
if (!wearable.CanFortify)
|
|
{
|
|
from.SendLocalizedMessage(1049083); // You cannot use the powder on that item.
|
|
return;
|
|
}
|
|
|
|
if ((item.IsChildOf(from.Backpack) || Core.ML && item.Parent == from) &&
|
|
m_Powder.IsChildOf(from.Backpack))
|
|
{
|
|
var origMaxHP = wearable.MaxHitPoints;
|
|
var origCurHP = wearable.HitPoints;
|
|
|
|
if (origMaxHP > 0)
|
|
{
|
|
var initMaxHP = Core.AOS ? 255 : wearable.InitMaxHits;
|
|
|
|
wearable.UnscaleDurability();
|
|
|
|
if (wearable.MaxHitPoints < initMaxHP)
|
|
{
|
|
var bonus = initMaxHP - wearable.MaxHitPoints;
|
|
|
|
if (bonus > 10)
|
|
{
|
|
bonus = 10;
|
|
}
|
|
|
|
wearable.MaxHitPoints += bonus;
|
|
wearable.HitPoints += bonus;
|
|
|
|
wearable.ScaleDurability();
|
|
|
|
if (wearable.MaxHitPoints > 255)
|
|
{
|
|
wearable.MaxHitPoints = 255;
|
|
}
|
|
|
|
if (wearable.HitPoints > 255)
|
|
{
|
|
wearable.HitPoints = 255;
|
|
}
|
|
|
|
if (wearable.MaxHitPoints > origMaxHP)
|
|
{
|
|
from.SendLocalizedMessage(1049084); // You successfully use the powder on the item.
|
|
from.PlaySound(0x247);
|
|
|
|
--m_Powder.UsesRemaining;
|
|
|
|
if (m_Powder.UsesRemaining <= 0)
|
|
{
|
|
from.SendLocalizedMessage(1049086); // You have used up your powder of fortifying.
|
|
m_Powder.Delete();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
wearable.MaxHitPoints = origMaxHP;
|
|
wearable.HitPoints = origCurHP;
|
|
from.SendLocalizedMessage(1049085); // The item cannot be improved any further.
|
|
}
|
|
}
|
|
else
|
|
{
|
|
from.SendLocalizedMessage(1049085); // The item cannot be improved any further.
|
|
wearable.ScaleDurability();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
from.SendLocalizedMessage(1049083); // You cannot use the powder on that item.
|
|
}
|
|
}
|
|
else
|
|
{
|
|
from.SendLocalizedMessage(1042001); // That must be in your pack for you to use it.
|
|
}
|
|
}
|
|
else
|
|
{
|
|
from.SendLocalizedMessage(1049083); // You cannot use the powder on that item.
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|