126 lines
2.7 KiB
C#
126 lines
2.7 KiB
C#
using System;
|
|
using Server;
|
|
using Server.Network;
|
|
using Server.Regions;
|
|
|
|
namespace Server.Items
|
|
{
|
|
public abstract class FarmableCrop : Item
|
|
{
|
|
private bool m_Picked;
|
|
|
|
public abstract Item GetCropObject();
|
|
public abstract int GetPickedID();
|
|
|
|
public FarmableCrop( int itemID ) : base( itemID )
|
|
{
|
|
Movable = false;
|
|
}
|
|
public override bool HandlesOnMovement { get { return true; } }
|
|
|
|
public override void OnMovement( Mobile m, Point3D oldLocation )
|
|
{
|
|
if ( m_Picked || !m.Alive || !m.Player )
|
|
return;
|
|
|
|
int harvestRange = (int)Server.ValidSettings.HarvestRange();
|
|
|
|
if ( m.InRange( this.Location, harvestRange ) )
|
|
{
|
|
Map map = this.Map;
|
|
Point3D loc = this.Location;
|
|
|
|
if ( Parent != null || Movable || IsLockedDown || IsSecure || map == null || map == Map.Internal )
|
|
return;
|
|
|
|
if ( m.InLOS( this ) )
|
|
{
|
|
OnPicked( m, loc, map );
|
|
}
|
|
}
|
|
}
|
|
public override void OnDoubleClick( Mobile from )
|
|
{
|
|
Map map = this.Map;
|
|
Point3D loc = this.Location;
|
|
|
|
if ( Parent != null || Movable || IsLockedDown || IsSecure || map == null || map == Map.Internal )
|
|
return;
|
|
|
|
if ( !from.InRange( loc, 2 ) || !from.InLOS( this ) )
|
|
from.LocalOverheadMessage( MessageType.Regular, 0x3B2, 1019045 ); // I can't reach that.
|
|
else if ( !m_Picked )
|
|
OnPicked( from, loc, map );
|
|
}
|
|
|
|
public virtual void OnPicked( Mobile from, Point3D loc, Map map )
|
|
{
|
|
ItemID = GetPickedID();
|
|
|
|
Item spawn = GetCropObject();
|
|
|
|
if ( spawn != null )
|
|
{
|
|
if ( from.Backpack != null && from.Backpack.TryDropItem( from, spawn, false ) )
|
|
{
|
|
from.SendMessage( 0x35, "You harvest the crop and place it in your backpack." );
|
|
}
|
|
else
|
|
{
|
|
from.SendMessage( 0x22, "Your backpack is full, so the crop drops to the ground." );
|
|
spawn.MoveToWorld( loc, map );
|
|
}
|
|
}
|
|
|
|
m_Picked = true;
|
|
|
|
Unlink();
|
|
|
|
Timer.DelayCall( TimeSpan.FromMinutes( 5.0 ), new TimerCallback( Delete ) );
|
|
}
|
|
|
|
public void Unlink()
|
|
{
|
|
ISpawner se = this.Spawner;
|
|
|
|
if ( se != null )
|
|
{
|
|
this.Spawner.Remove( this );
|
|
this.Spawner = null;
|
|
}
|
|
|
|
}
|
|
|
|
public FarmableCrop( Serial serial ) : base( serial )
|
|
{
|
|
}
|
|
|
|
public override void Serialize( GenericWriter writer )
|
|
{
|
|
base.Serialize( writer );
|
|
|
|
writer.WriteEncodedInt( 0 ); // version
|
|
|
|
writer.Write( m_Picked );
|
|
}
|
|
|
|
public override void Deserialize( GenericReader reader )
|
|
{
|
|
base.Deserialize( reader );
|
|
|
|
int version = reader.ReadEncodedInt();
|
|
|
|
switch ( version )
|
|
{
|
|
case 0:
|
|
m_Picked = reader.ReadBool();
|
|
break;
|
|
}
|
|
if ( m_Picked )
|
|
{
|
|
Unlink();
|
|
Delete();
|
|
}
|
|
}
|
|
}
|
|
}
|