/**********************************************************
RunUO 2.0 AoV C# script file
Official Age of Valor Script :: www.uovalor.com
Last modified by 
Filepath: scripts\_custom\gumps\linkgump.cs
Lines of code: 108
***********************************************************/


using Server.Targeting;
using Server.Mobiles;
using Server.Items;
using Server.Network;

namespace Server.Gumps
{
	public class LinkGump : Gump
	{
	private Mobile from;
	private object tolink;
		public LinkGump(Mobile pfrom,Item ptolink): base( 5, 30 )
		{
			from=pfrom;
			tolink=ptolink;
		
			this.Closable=true;
			this.Disposable=true;
			this.Dragable=true;
			this.Resizable=false;
			this.AddPage(0);
			this.AddBackground(0, 0, 300, 50, 9200);
			this.AddLabel(5, 5, 0, "Link to another teleporter, moongate, or item");	
			this.AddButton(3, 29, 247, 248, 1, GumpButtonType.Reply, 0);			
		}
		

	
	
	
		public override void OnResponse( NetState sender, RelayInfo info )
		{
			Mobile from = sender.Mobile;
			

			if(info.ButtonID==1)
			{
			from.Target = new InternalTarget( from,tolink );
			}
		}	
		
		
		
		public class InternalTarget : Target
		{
		private object firstitem;
		private Mobile from;
		
			private void SetLoc(object o,Point3D loc,Map map)
			{
				if(o is Teleporter)
				{
				Teleporter tele = o as Teleporter;
				tele.PointDest=loc;
				tele.MapDest=map;
				}
				else if(o is SkillTeleporter)
				{
				SkillTeleporter tele = o as SkillTeleporter;
				tele.PointDest=loc;
				tele.MapDest=map;
				}
				else if(o is Moongate)
				{
				Moongate tele = o as Moongate;
				tele.Target=loc;
				tele.TargetMap=map;
				}
				else if(o is RecallRune)
				{
				RecallRune tele = o as RecallRune;
				tele.Target=loc;
				tele.TargetMap=map;
				tele.Marked=true;
				}				
			}
			
			private void GetLoc(object o,ref Point3D loc,ref Map map)
			{
				if(o is Item)
				{
				Item item = o as Item;
				loc=item.Location;
				map=item.Map;
				}
				if(o is Mobile)
				{
				Mobile item = o as Mobile;
				loc=item.Location;
				map=item.Map;
				}				
				else if(o is StaticTarget)
				{
				StaticTarget item = o as StaticTarget;
				loc=item.Location;				
				}
				else if(o is LandTarget)
				{
				LandTarget item = o as LandTarget;
				loc=item.Location;				
				}				
				
			
			}
			
		
		
		
			public InternalTarget(Mobile pfrom,object pfirstitem) : base( 12, false, TargetFlags.None )
			{
			firstitem=pfirstitem;
			from=pfrom;
			
			from.SendMessage("Target spot or item to link to");
			}
			
			protected override void OnTarget( Mobile from, object o )
			{
			if(from.AccessLevel<AccessLevel.GameMaster)return;
			
			Point3D loc=new Point3D(0,0,0);
			Map map=from.Map;			
			
			GetLoc(firstitem,ref loc,ref map);
			SetLoc(o,loc, map);
			
			GetLoc(o,ref loc,ref map);
			SetLoc(firstitem,loc, map);
			
			from.SendMessage("Linked - be sure to test to ensure it worked as wanted");
			}

		}	


		
	
	}	
}