Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Reflection;
- using Server.Items;
- using Server.Targeting;
- using Server.Gumps;
- using Server.Network;
- using System.Collections.Generic;
- using EDI = Server.Mobiles.EscortDestinationInfo;
- namespace Server.Commands
- {
- public class CordCalc
- {
- public static void Initialize()
- {
- CommandSystem.Register("CordCalc", AccessLevel.GameMaster, new CommandEventHandler(CordCalc_OnCommand));
- }
- [Usage("CordCalc")]
- [Description( "Returns Variance in location" )]
- private static void CordCalc_OnCommand( CommandEventArgs e )
- {
- e.Mobile.Target = new CordCalcTarget( new List<string>() );
- e.Mobile.SendMessage( "Target the point for a distance calculation?" );
- }
- private class CordCalcTarget : Target
- {
- List<string> m_CoordList;
- private static string[] m_TownNames = new string[]
- {
- "Cove", "Britain", "Jhelom",
- "Minoc", "Ocllo", "Trinsic",
- "Vesper", "Yew", "Skara Brae",
- "Nujel'm", "Moonglow", "Magincia",
- "Buccaneer's Den", "Wind"
- };
- public CordCalcTarget( List<string> coordList )
- : base(15,true, TargetFlags.None)
- {
- m_CoordList = coordList;
- }
- protected override void OnTarget( Mobile from, object targ )
- {
- int x = 0;
- int y = 0;
- if ( targ is Item )
- {
- Item item = (Item)targ;
- if (item != null)
- {
- x = item.X;
- y = item.Y;
- }
- }
- else if (targ is StaticTarget)
- {
- StaticTarget stattarg = (StaticTarget)targ;
- if (stattarg != null)
- {
- x = stattarg.X;
- y = stattarg.Y;
- }
- }
- else if (targ is LandTarget)
- {
- LandTarget landtarg = (LandTarget)targ;
- if (landtarg != null)
- {
- x = landtarg.X;
- y = landtarg.Y;
- }
- }
- string town = "";
- for ( int i=0; i < m_TownNames.Length; i++ )
- {
- town = m_TownNames[i];
- EDI test = EDI.Find( town );
- if ( test != null && test.Contains( from.Location ) )
- {
- break;
- }
- else
- town = "";
- }
- m_CoordList.Add( String.Format("<rect x=\"{0}\" y=\"{1}\" width=\"{2}\" height=\"{3}\" />", from.X, from.Y, x - from.X, y - from.Y) );
- if ( from.HasGump ( typeof( InternalGump ) ) );
- from.CloseGump( typeof( InternalGump ) );
- from.SendGump( new InternalGump( m_CoordList, town ) );
- }
- }
- private class InternalGump : Gump
- {
- List<string> m_CoordList;
- string m_Town;
- public void AddTextField(int x, int y, int width, int height, int index)
- {
- AddImage(x -2, y -2, 0x475);
- AddTextEntry(x + 4, y + 1, width - 4, height - 4, 0, index, "");
- }
- public void BaseBackground( int alignLeft, int alignTop, int x, int y, bool addCloseButton )
- {
- AddPage(0);
- AddImageTiled(alignLeft+12, alignTop+12, x-12, y-12, 200); // background
- AddImageTiled(alignLeft+18, alignTop, x, 27, 201); // Top bar
- AddImageTiled(alignLeft+18, alignTop+y, x, 44, 2607); // bottom bar
- AddImageTiled(alignLeft+x, alignTop+18, 42, y-10, 2605); // RHS
- AddImageTiled(alignLeft, alignTop+18, 32, y-10, 2603); // LHS
- AddImage(alignLeft, alignTop, 206); // top left corner
- AddImage(alignLeft+x, alignTop, 207); // top right corner - STATIC
- AddImage(alignLeft, alignTop+y, 2606); // bottom left
- AddImage(alignLeft+x, alignTop+y, 2608); // bottom right
- if ( addCloseButton )
- {
- AddButton( alignLeft+50, y+50, 4017, 4018, 0, GumpButtonType.Reply, 0);
- AddLabel( alignLeft+88, y+51, 0, @"Close" );
- }
- }
- public void AddTitle( int offset, string title )
- {
- AddLabel( offset + 50, 75, 2057, @title );
- }
- public InternalGump( List<string> coordList, string town ) : base( 0, 0 )
- {
- m_CoordList = coordList;
- m_Town = town;
- BaseBackground(50,50,300,300,true);
- AddTitle(140,@"Coordinates");
- int i = 0;
- foreach( string s in m_CoordList )
- {
- AddLabel( 110,100+i*25,0,@s );
- i++;
- }
- AddButton( 200, 350, 0xFA5, 0xFA6, 1, GumpButtonType.Reply, 0);
- AddLabel( 238, 351, 0, @"NextCoord" );
- AddButton( 100, 297, 0xFB7, 0xFB8, 2, GumpButtonType.Reply, 0);
- AddLabel( 138, 298, 0, @"Enter Rune Name and Complete" );
- AddTextField(88, 323, 315, 20, 1);
- }
- public override void OnResponse(NetState sender, RelayInfo info)
- {
- Mobile from = sender.Mobile;
- if ( info.ButtonID != 0 && info.ButtonID != 1 && info.ButtonID != 2 )
- return;
- switch(info.ButtonID)
- {
- case 0:
- {
- break;
- }
- case 1:
- {
- from.Target = new CordCalcTarget( m_CoordList );
- break;
- }
- case 2:
- {
- string runeName = "";
- if ( info.GetTextEntry(1) != null)
- {
- TextRelay c = info.GetTextEntry(1);
- if (c != null)
- runeName = c.Text;
- }
- if ( String.IsNullOrEmpty( runeName ) )
- runeName = "an unnamed rune";
- string dataPath = @"C:\Users\Jack\Desktop\RunUO stuff\Runes.xml";
- System.IO.StreamWriter file = new System.IO.StreamWriter( dataPath, true);
- file.WriteLine( "<region>" );
- file.WriteLine( "\t<region name=\"{0} in {1}\">", runeName, String.IsNullOrEmpty( m_Town ) ? "" : m_Town );
- file.WriteLine( "\t<rune name=\"{0}\">", runeName );
- foreach( string coords in m_CoordList )
- {
- file.WriteLine( "\t{0}",coords );
- }
- file.WriteLine( "</region>" );
- file.Close();
- break;
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement