188 lines
6 KiB
C#
188 lines
6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using Server;
|
|
using Server.Items;
|
|
using Server.Mobiles;
|
|
using Server.Targeting;
|
|
|
|
namespace Server.Items
|
|
{
|
|
public class EnchantedBandage : Item
|
|
{
|
|
public static Dictionary<Mobile, DateTime> CooldownTable = new Dictionary<Mobile, DateTime>();
|
|
|
|
private int m_Charges;
|
|
|
|
[CommandProperty( AccessLevel.GameMaster )]
|
|
public int Charges
|
|
{
|
|
get { return m_Charges; }
|
|
set { m_Charges = value; InvalidateProperties(); }
|
|
}
|
|
|
|
public int MaxCharges { get { return 200; } }
|
|
|
|
[Constructable]
|
|
public EnchantedBandage() : base( 0xE21 )
|
|
{
|
|
Name = "an enchanted bandage roll";
|
|
Hue = 1150;
|
|
Weight = 1.0;
|
|
m_Charges = 0;
|
|
}
|
|
|
|
public override void OnDoubleClick( Mobile from )
|
|
{
|
|
if ( !IsChildOf( from.Backpack ) )
|
|
{
|
|
from.SendLocalizedMessage( 1042001 );
|
|
return;
|
|
}
|
|
|
|
if ( m_Charges <= 0 )
|
|
{
|
|
from.SendMessage( 33, "There are no bandages stored in this roll." );
|
|
return;
|
|
}
|
|
|
|
if ( BandageContext.GetContext( from ) != null )
|
|
{
|
|
from.SendMessage( 33, "You are already applying a bandage." );
|
|
return;
|
|
}
|
|
|
|
if ( CooldownTable.ContainsKey( from ) && CooldownTable[from] > DateTime.UtcNow )
|
|
{
|
|
from.SendMessage( 33, "You must wait a moment before using the enchanted roll again." );
|
|
return;
|
|
}
|
|
|
|
from.SendMessage( "Who do you wish to heal?" );
|
|
from.Target = new InternalTarget( this );
|
|
}
|
|
|
|
public override bool OnDragDrop( Mobile from, Item dropped )
|
|
{
|
|
if ( dropped is Bandage )
|
|
{
|
|
int amount = dropped.Amount;
|
|
int room = MaxCharges - m_Charges;
|
|
|
|
if ( room <= 0 )
|
|
{
|
|
from.SendMessage( 33, "This enchanted roll is already full." );
|
|
return false;
|
|
}
|
|
|
|
if ( amount > room )
|
|
{
|
|
m_Charges += room;
|
|
dropped.Consume( room );
|
|
from.SendMessage( 63, String.Format( "You add {0} bandages to the roll. It is now completely full.", room ) );
|
|
from.PlaySound( 0x249 );
|
|
return false;
|
|
}
|
|
else
|
|
{
|
|
m_Charges += amount;
|
|
dropped.Delete();
|
|
from.SendMessage( 63, String.Format( "You add {0} bandages to the roll. It now holds {1}.", amount, m_Charges ) );
|
|
from.PlaySound( 0x249 );
|
|
return true;
|
|
}
|
|
}
|
|
|
|
from.SendMessage( 33, "You can only add standard bandages to this roll." );
|
|
return false;
|
|
}
|
|
|
|
public override void OnSingleClick( Mobile from )
|
|
{
|
|
base.OnSingleClick( from );
|
|
this.LabelTo( from, String.Format( "[Charges: {0}/{1}]", m_Charges, MaxCharges ) );
|
|
}
|
|
|
|
public override void GetProperties( ObjectPropertyList list )
|
|
{
|
|
base.GetProperties( list );
|
|
list.Add( 1049644, "Charges: {0} / {1}", m_Charges, MaxCharges );
|
|
}
|
|
|
|
private class InternalTarget : Target
|
|
{
|
|
private EnchantedBandage m_Item;
|
|
|
|
public InternalTarget( EnchantedBandage item ) : base( 1, false, TargetFlags.Beneficial )
|
|
{
|
|
m_Item = item;
|
|
}
|
|
|
|
protected override void OnTarget( Mobile from, object targeted )
|
|
{
|
|
if ( m_Item.Deleted || m_Item.Charges <= 0 ) return;
|
|
|
|
if ( !m_Item.IsChildOf( from.Backpack ) )
|
|
{
|
|
from.SendLocalizedMessage( 1042001 );
|
|
return;
|
|
}
|
|
|
|
if ( BandageContext.GetContext( from ) != null )
|
|
{
|
|
from.SendMessage( 33, "You are already applying a bandage." );
|
|
return;
|
|
}
|
|
|
|
if ( targeted is Mobile )
|
|
{
|
|
Mobile m = (Mobile)targeted;
|
|
|
|
if ( Utility.RandomDouble() < 0.30 )
|
|
{
|
|
m.Poison = null;
|
|
m.Hits = m.HitsMax;
|
|
|
|
m.PlaySound( 0x1F2 );
|
|
m.FixedParticles( 0x376A, 9, 32, 5030, EffectLayer.Waist );
|
|
|
|
if ( m == from )
|
|
from.SendMessage( 63, "The enchanted bandage glows brightly, instantly curing and fully healing you!" );
|
|
else
|
|
from.SendMessage( 63, "The enchanted bandage glows brightly, instantly curing and fully healing them!" );
|
|
|
|
CooldownTable[from] = DateTime.UtcNow + TimeSpan.FromSeconds( 5 );
|
|
}
|
|
else
|
|
{
|
|
if ( BandageContext.BeginHeal( from, m ) != null )
|
|
{
|
|
m_Item.Charges--;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
from.SendMessage( "You cannot heal that." );
|
|
}
|
|
}
|
|
}
|
|
|
|
public EnchantedBandage( Serial serial ) : base( serial )
|
|
{
|
|
}
|
|
|
|
public override void Serialize( GenericWriter writer )
|
|
{
|
|
base.Serialize( writer );
|
|
writer.Write( (int) 0 );
|
|
writer.Write( (int) m_Charges );
|
|
}
|
|
|
|
public override void Deserialize( GenericReader reader )
|
|
{
|
|
base.Deserialize( reader );
|
|
int version = reader.ReadInt();
|
|
m_Charges = reader.ReadInt();
|
|
}
|
|
}
|
|
}
|