Piotr
Member
Hi,
I'm struggling with adding charges to a custom dye tub. The remaining uses get spent when I double-click the tub instead of when targeting a valid item.
It was the only way I managed to do it, but I'm not satisfied with the result.
Maybe someone can take a look and help?
Thanks
I'm struggling with adding charges to a custom dye tub. The remaining uses get spent when I double-click the tub instead of when targeting a valid item.
It was the only way I managed to do it, but I'm not satisfied with the result.
C#:
using System;
using Server.Targeting;
namespace Server.Items
{
public class SpecialGreenDyeTub : DyeTub
{
private int m_UsesRemaining;
[CommandProperty(AccessLevel.GameMaster)]
public int UsesRemaining { get { return m_UsesRemaining; } set { m_UsesRemaining = value; InvalidateProperties(); } }
[Constructable]
public SpecialGreenDyeTub()
{
Weight = 1.0;
m_UsesRemaining = 10;
ItemID = 0x0F00;
}
public SpecialGreenDyeTub(Serial serial)
: base(serial)
{
}
public override CustomHuePicker CustomHuePicker
{
get
{
return CustomHuePicker.SpecialGreen;
}
}
public override int LabelNumber
{
get
{
return 1041285;
}
}// Special Dye Tub
public virtual bool ShowUsesRemaining
{
get
{
return true;
}
set
{
}
}
public override void OnDoubleClick(Mobile from)
{
base.OnDoubleClick(from);
if (UsesRemaining > 1)
{
--UsesRemaining;
}
else
{
if (from != null)
from.SendLocalizedMessage(1116800); // no uses left msg
Delete();
}
}
public override void GetProperties(ObjectPropertyList list)
{
base.GetProperties(list);
list.Add(1060584, m_UsesRemaining.ToString()); // uses remaining: ~1_val~
}
public override void Serialize(GenericWriter writer)
{
base.Serialize(writer);
writer.Write((int)1); // version
writer.Write(m_UsesRemaining);
}
public override void Deserialize(GenericReader reader)
{
base.Deserialize(reader);
int version = reader.ReadInt();
switch (version)
{
case 1:
m_UsesRemaining = reader.ReadInt();
break;
case 0:
break;
}
}
}
}
Maybe someone can take a look and help?
Thanks