private static void ChainLink_OnTarget( Mobile from, object targeted, object state )
{
BaseDoor door = targeted as BaseDoor;
if ( door == null )
{
from.BeginTarget( -1, false, TargetFlags.None, new TargetStateCallback( ChainLink_OnTarget ), state );
from.SendMessage( "That is not a door. Try again." );
}
else
{
List<BaseDoor> list = (List<BaseDoor>)state;
if ( list.Count > 0 && list[0] == door )
{
if ( list.Count >= 2 )
{
for ( int i = 0; i < list.Count; ++i )
list[i].Link = list[(i + 1) % list.Count];
from.SendMessage( "The chain of doors have been linked." );
}
else
{
from.BeginTarget( -1, false, TargetFlags.None, new TargetStateCallback( ChainLink_OnTarget ), state );
from.SendMessage( "You have not yet targeted two unique doors. Target the second door to link." );
}
}
else if ( list.Contains( door ) )
{
from.BeginTarget( -1, false, TargetFlags.None, new TargetStateCallback( ChainLink_OnTarget ), state );
from.SendMessage( "You have already targeted that door. Target another door, or retarget the first door to complete the chain." );
}
else
{
list.Add( door );
from.BeginTarget( -1, false, TargetFlags.None, new TargetStateCallback( ChainLink_OnTarget ), state );
if ( list.Count == 1 )
from.SendMessage( "Target the second door to link." );
else
from.SendMessage( "Target another door to link. To complete the chain, retarget the first door." );
}
}
}