fwiffo
Sorceror
Here it is....almost a complete rewrite, I hope that I haven't used any c#4.0 reference or sintax, but anyway tell me if it doesn't compile, switching to .net4 without using the internals in .net4 format is really easy...
Code:
using System;
using Server;
namespace Server.Items
{
public class HalfLifeBow : CompositeBow
{
public override int InitMinHits{ get{ return 255; } }
public override int InitMaxHits{ get{ return 255; } }
private static readonly TimeSpan m_Delay = TimeSpan.FromMinutes( 30 );
private InternalTimer m_Halflifetimer;
// starting the item itself
[Constructable]
public HalfLifeBow() : base()
{
Name = "Half Life Bow";
Hue = 2711;
Attributes.WeaponDamage = 40;
Attributes.WeaponSpeed = 20;
WeaponAttributes.HitLeechHits = 25;
WeaponAttributes.HitLeechMana = 40;
WeaponAttributes.HitFireball = 35;
WeaponAttributes.SelfRepair = 5;
Attributes.SpellChanneling = 1;
Attributes.CastSpeed = 1;
Attributes.Luck = 20;
Attributes.RegenMana = 5;
Attributes.SpellDamage = 15;
}
// this controls the list you see when you mouse-over the item
public override void AddNameProperty( ObjectPropertyList list )
{
// make sure the normal mouse-over props show up
base.AddNameProperty( list );
// determine the info the timer display shows
if(m_Halflifetimer!=null)
{
string lisths;
TimeSpan timetouse = m_Halflifetimer.GetDelay().Subtract(DateTime.Now);
if ( timetouse.Minutes > 0 )
{
int min = timetouse.Minutes;
lisths = String.Format( "{0} minutes.", min.ToString() );
}
else if ( timetouse.Seconds > 0 )
{
int sec = timetouse.Seconds;
lisths = String.Format( "{0} seconds.", sec.ToString() );
}
else
{
lisths = ( "<BASEFONT COLOR=#00FF00>Dormant<BASEFONT COLOR=#FFFFFF>" ); //FFFFFF
}
// adding the timer to the property list
list.Add( "<BASEFONT COLOR=#00FF00>Half Life Remaining: {0}<BASEFONT COLOR=#FFFFFF>", lisths ); //FFFFFF
[FONT=Consolas]Timer.DelayCall( TimeSpan.FromSeconds( 1.0 ), new TimerCallback( InvalidateProperties ) );[/FONT]
}
}
public override bool OnEquip( Mobile from )
{
if(base.OnEquip(from))
{
if(m_Halflifetimer==null)
{
m_Halflifetimer=new HalfLifeBow.InternalTimer(this, DateTime.Now+m_Delay);
m_Halflifetimer.Start();
Timer.DelayCall( TimeSpan.FromSeconds( 1.0 ), new TimerCallback( InvalidateProperties ) );
}
}
return true;
}
public HalfLifeBow( Serial serial ) : base( serial )
{
}
public override void Serialize( GenericWriter writer ) // generic info to write and save
{
base.Serialize( writer );
writer.Write( (int) 1 );
//version 1
writer.Write( (bool)(m_Halflifetimer!=null));
if(m_Halflifetimer!=null)
{
writer.WriteDeltaTime( m_Halflifetimer.GetDelay() );
}
}
public override void Deserialize(GenericReader reader) // make sure proper variables are read
{
base.Deserialize( reader );
int version = reader.ReadInt();
switch(version)
{
case 0:
{
reader.ReadDateTime();
break;
}
case 1:
{
if(reader.ReadBool())
{
DateTime end = reader.ReadDeltaTime();
m_Halflifetimer = new HalfLifeBow.InternalTimer(this, end);
m_Halflifetimer.Start();
}
break;
}
}
}
[CommandProperty(AccessLevel.GameMaster, true)]
public TimeSpan Remaining
{
get{if(m_Halflifetimer!=null) return m_Halflifetimer.GetDelay().Subtract(DateTime.Now); else return TimeSpan.Zero;}
}
protected class InternalTimer : Timer
{
private Item m_Item;
public InternalTimer(Item item, DateTime end) : base(end.Subtract(DateTime.Now))
{
m_Item=item;
Priority = TimerPriority.FiveSeconds;
}
public DateTime GetDelay()
{
return this.Next;
}
protected override void OnTick()
{
if(m_Item!=null && !m_Item.Deleted)
{
if(m_Item.Parent is Mobile)
((Mobile)m_Item.Parent).SendMessage("The bow turns to dust");
m_Item.Delete();
}
Stop();
}
}
}
}