Advertisement
Guest User

Untitled

a guest
Dec 20th, 2014
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.98 KB | None | 0 0
  1. using System;
  2. using System.Reflection;
  3. using Server.Items;
  4. using Server.Targeting;
  5. using Server.Gumps;
  6. using Server.Network;
  7. using System.Collections.Generic;
  8. using EDI = Server.Mobiles.EscortDestinationInfo;
  9.  
  10. namespace Server.Commands
  11. {
  12. public class CordCalc
  13. {
  14. public static void Initialize()
  15. {
  16. CommandSystem.Register("CordCalc", AccessLevel.GameMaster, new CommandEventHandler(CordCalc_OnCommand));
  17. }
  18.  
  19. [Usage("CordCalc")]
  20. [Description( "Returns Variance in location" )]
  21. private static void CordCalc_OnCommand( CommandEventArgs e )
  22. {
  23. e.Mobile.Target = new CordCalcTarget( new List<string>() );
  24. e.Mobile.SendMessage( "Target the point for a distance calculation?" );
  25. }
  26.  
  27. private class CordCalcTarget : Target
  28. {
  29. List<string> m_CoordList;
  30.  
  31. private static string[] m_TownNames = new string[]
  32. {
  33. "Cove", "Britain", "Jhelom",
  34. "Minoc", "Ocllo", "Trinsic",
  35. "Vesper", "Yew", "Skara Brae",
  36. "Nujel'm", "Moonglow", "Magincia",
  37. "Buccaneer's Den", "Wind"
  38. };
  39.  
  40. public CordCalcTarget( List<string> coordList )
  41. : base(15,true, TargetFlags.None)
  42. {
  43. m_CoordList = coordList;
  44. }
  45.  
  46. protected override void OnTarget( Mobile from, object targ )
  47. {
  48.  
  49. int x = 0;
  50. int y = 0;
  51.  
  52. if ( targ is Item )
  53. {
  54. Item item = (Item)targ;
  55.  
  56. if (item != null)
  57. {
  58. x = item.X;
  59. y = item.Y;
  60. }
  61. }
  62. else if (targ is StaticTarget)
  63. {
  64. StaticTarget stattarg = (StaticTarget)targ;
  65.  
  66. if (stattarg != null)
  67. {
  68. x = stattarg.X;
  69. y = stattarg.Y;
  70. }
  71. }
  72. else if (targ is LandTarget)
  73. {
  74. LandTarget landtarg = (LandTarget)targ;
  75. if (landtarg != null)
  76. {
  77. x = landtarg.X;
  78. y = landtarg.Y;
  79. }
  80. }
  81.  
  82. string town = "";
  83. for ( int i=0; i < m_TownNames.Length; i++ )
  84. {
  85. town = m_TownNames[i];
  86. EDI test = EDI.Find( town );
  87. if ( test != null && test.Contains( from.Location ) )
  88. {
  89. break;
  90. }
  91. else
  92. town = "";
  93. }
  94.  
  95. m_CoordList.Add( String.Format("<rect x=\"{0}\" y=\"{1}\" width=\"{2}\" height=\"{3}\" />", from.X, from.Y, x - from.X, y - from.Y) );
  96.  
  97. if ( from.HasGump ( typeof( InternalGump ) ) );
  98. from.CloseGump( typeof( InternalGump ) );
  99. from.SendGump( new InternalGump( m_CoordList, town ) );
  100. }
  101. }
  102.  
  103. private class InternalGump : Gump
  104. {
  105. List<string> m_CoordList;
  106. string m_Town;
  107.  
  108. public void AddTextField(int x, int y, int width, int height, int index)
  109. {
  110. AddImage(x -2, y -2, 0x475);
  111. AddTextEntry(x + 4, y + 1, width - 4, height - 4, 0, index, "");
  112. }
  113.  
  114. public void BaseBackground( int alignLeft, int alignTop, int x, int y, bool addCloseButton )
  115. {
  116. AddPage(0);
  117.  
  118. AddImageTiled(alignLeft+12, alignTop+12, x-12, y-12, 200); // background
  119.  
  120. AddImageTiled(alignLeft+18, alignTop, x, 27, 201); // Top bar
  121. AddImageTiled(alignLeft+18, alignTop+y, x, 44, 2607); // bottom bar
  122. AddImageTiled(alignLeft+x, alignTop+18, 42, y-10, 2605); // RHS
  123. AddImageTiled(alignLeft, alignTop+18, 32, y-10, 2603); // LHS
  124.  
  125. AddImage(alignLeft, alignTop, 206); // top left corner
  126. AddImage(alignLeft+x, alignTop, 207); // top right corner - STATIC
  127.  
  128. AddImage(alignLeft, alignTop+y, 2606); // bottom left
  129. AddImage(alignLeft+x, alignTop+y, 2608); // bottom right
  130.  
  131. if ( addCloseButton )
  132. {
  133. AddButton( alignLeft+50, y+50, 4017, 4018, 0, GumpButtonType.Reply, 0);
  134. AddLabel( alignLeft+88, y+51, 0, @"Close" );
  135. }
  136. }
  137.  
  138. public void AddTitle( int offset, string title )
  139. {
  140. AddLabel( offset + 50, 75, 2057, @title );
  141. }
  142.  
  143. public InternalGump( List<string> coordList, string town ) : base( 0, 0 )
  144. {
  145. m_CoordList = coordList;
  146. m_Town = town;
  147.  
  148. BaseBackground(50,50,300,300,true);
  149. AddTitle(140,@"Coordinates");
  150.  
  151. int i = 0;
  152. foreach( string s in m_CoordList )
  153. {
  154. AddLabel( 110,100+i*25,0,@s );
  155. i++;
  156. }
  157.  
  158. AddButton( 200, 350, 0xFA5, 0xFA6, 1, GumpButtonType.Reply, 0);
  159. AddLabel( 238, 351, 0, @"NextCoord" );
  160.  
  161. AddButton( 100, 297, 0xFB7, 0xFB8, 2, GumpButtonType.Reply, 0);
  162. AddLabel( 138, 298, 0, @"Enter Rune Name and Complete" );
  163. AddTextField(88, 323, 315, 20, 1);
  164. }
  165.  
  166. public override void OnResponse(NetState sender, RelayInfo info)
  167. {
  168. Mobile from = sender.Mobile;
  169.  
  170. if ( info.ButtonID != 0 && info.ButtonID != 1 && info.ButtonID != 2 )
  171. return;
  172.  
  173. switch(info.ButtonID)
  174. {
  175. case 0:
  176. {
  177. break;
  178. }
  179. case 1:
  180. {
  181. from.Target = new CordCalcTarget( m_CoordList );
  182. break;
  183. }
  184. case 2:
  185. {
  186. string runeName = "";
  187. if ( info.GetTextEntry(1) != null)
  188. {
  189. TextRelay c = info.GetTextEntry(1);
  190. if (c != null)
  191. runeName = c.Text;
  192. }
  193.  
  194. if ( String.IsNullOrEmpty( runeName ) )
  195. runeName = "an unnamed rune";
  196.  
  197. string dataPath = @"C:\Users\Jack\Desktop\RunUO stuff\Runes.xml";
  198. System.IO.StreamWriter file = new System.IO.StreamWriter( dataPath, true);
  199.  
  200. file.WriteLine( "<region>" );
  201. file.WriteLine( "\t<region name=\"{0} in {1}\">", runeName, String.IsNullOrEmpty( m_Town ) ? "" : m_Town );
  202. file.WriteLine( "\t<rune name=\"{0}\">", runeName );
  203.  
  204. foreach( string coords in m_CoordList )
  205. {
  206. file.WriteLine( "\t{0}",coords );
  207. }
  208.  
  209. file.WriteLine( "</region>" );
  210.  
  211. file.Close();
  212.  
  213. break;
  214. }
  215. }
  216. }
  217. }
  218. }
  219. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement