Advertisement
Guest User

Untitled

a guest
Oct 18th, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.02 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using Server;
  5. using Server.Targeting;
  6. using Server.Items;
  7.  
  8. namespace Server.SkillHandlers
  9. {
  10. public class Inscribe
  11. {
  12. public static void Initialize()
  13. {
  14. SkillInfo.Table[(int)SkillName.Inscribe].Callback = new SkillUseCallback( OnUse );
  15. }
  16.  
  17. public static TimeSpan OnUse( Mobile m )
  18. {
  19. Target target = new InternalTargetSrc();
  20. m.Target = target;
  21. m.SendLocalizedMessage( 1046295 ); // Target the book you wish to copy.
  22. target.BeginTimeout( m, TimeSpan.FromMinutes( 1.0 ) );
  23.  
  24. return TimeSpan.FromSeconds( 1.0 );
  25. }
  26.  
  27. private static Hashtable m_UseTable = new Hashtable();
  28.  
  29. private static void SetUser( BaseBook book, Mobile mob )
  30. {
  31. m_UseTable[book] = mob;
  32. }
  33.  
  34. private static void CancelUser( BaseBook book )
  35. {
  36. m_UseTable.Remove( book );
  37. }
  38.  
  39. public static Mobile GetUser( BaseBook book )
  40. {
  41. return (Mobile)m_UseTable[book];
  42. }
  43.  
  44. public static bool IsEmpty( BaseBook book )
  45. {
  46. foreach ( BookPageInfo page in book.Pages )
  47. {
  48. foreach ( string line in page.Lines )
  49. {
  50. if ( line.Trim() != "" )
  51. return false;
  52. }
  53. }
  54. return true;
  55. }
  56.  
  57. public static void Copy( BaseBook bookSrc, BaseBook bookDst, Mobile from )
  58. {
  59. bookDst.Title = bookSrc.Title;
  60. bookDst.Author = bookSrc.Author;
  61.  
  62. BookPageInfo[] pagesSrc = bookSrc.Pages;
  63. BookPageInfo[] pagesDst = bookDst.Pages;
  64. for ( int i = 0; i < pagesSrc.Length && i < pagesDst.Length; i++ )
  65. {
  66. BookPageInfo pageSrc = pagesSrc[i];
  67. BookPageInfo pageDst = pagesDst[i];
  68.  
  69. int length = pageSrc.Lines.Length;
  70. pageDst.Lines = new string[length];
  71.  
  72. for ( int j = 0; j < length; j++ )
  73. pageDst.Lines[j] = pageSrc.Lines[j];
  74. }
  75.  
  76. /* mod */
  77. if ( bookSrc is HTMLBook && bookDst is HTMLBook )
  78. {
  79. HTMLBook bookSource = bookSrc as HTMLBook;
  80. HTMLBook bookDestination = bookDst as HTMLBook;
  81. if ( bookSource.CharactersPerLineMax == bookDestination.CharactersPerLineMax &&
  82. bookSource.MaxLines == bookDestination.MaxLines )
  83. {
  84. if ( bookSource.RequiresFormatting )
  85. {
  86. bookSource.FixContent();
  87. bookSource.RequiresFormatting = false;
  88. }
  89. /* copy all html style-related data to the target book
  90. members are not cloned, but that's irrelevant, because we never modify them anywhere */
  91. bookDestination.HTMLContent.WordsTable = new Dictionary<int, List<HTMLTag>>( bookSource.HTMLContent.WordsTable );
  92. bookDestination.HTMLContent.LinesTable = new Dictionary<int, List<HTMLTag>>( bookSource.HTMLContent.LinesTable );
  93. bookDestination.HTMLContent.PagesTable = new Dictionary<int, List<HTMLTag>>( bookSource.HTMLContent.PagesTable );
  94. bookDestination.HTMLContent.Body = new List<HTMLTag>( bookSource.HTMLContent.Body );
  95. bookDestination.HTMLContent.HTMLPage = new Dictionary<int, int>( bookSource.HTMLContent.HTMLPage );
  96. bookDestination.HTMLContent.HTMLLines = new Dictionary<int, int>( bookSource.HTMLContent.HTMLLines );
  97. bookDestination.FixContent();
  98. bookDestination.FixStyling();
  99. bookDestination.HTMLContent.UpdateCache();
  100. bookDestination.RequiresFormatting = false;
  101. bookDestination.Writable = bookSource.Writable;
  102. if ( bookDestination.Writable == false )
  103. bookDestination.SealedBy = from;
  104. bookDestination.Cypher = bookSource.Cypher;
  105. bookDestination.Language = bookSource.Language;
  106. }
  107. else
  108. {
  109. bookDestination.FixContent();
  110. from.SendMessage( "Because the books have different page dimensions, you've been able to copy the content, but not the styles." );
  111. }
  112. }
  113. else if ( bookDst is HTMLBook ) // copying from normal -> htmlbook
  114. {
  115. ((HTMLBook)bookDst).RequiresFormatting = true;
  116. }
  117. /* mod end */
  118. }
  119.  
  120. private class InternalTargetSrc : Target
  121. {
  122. public InternalTargetSrc() : base ( 3, false, TargetFlags.None )
  123. {
  124. }
  125.  
  126. protected override void OnTarget( Mobile from, object targeted )
  127. {
  128. BaseBook book = targeted as BaseBook;
  129. if ( book == null )
  130. from.SendLocalizedMessage( 1046296 ); // That is not a book
  131. else if ( Inscribe.IsEmpty( book ) )
  132. from.SendLocalizedMessage( 501611 ); // Can't copy an empty book.
  133. else if ( Inscribe.GetUser( book ) != null )
  134. from.SendLocalizedMessage( 501621 ); // Someone else is inscribing that item.
  135. else if( book is HTMLBook && ((HTMLBook)book).SealedBy == null )
  136. from.SendMessage( "You cannot copy a book that has not been sealed." );
  137. else if( book is HTMLBook && ((HTMLBook)book).SealedBy != from && from.AccessLevel < AccessLevel.GameMaster )
  138. from.SendMessage( "You cannot copy a book that has been sealed by someone else." );
  139. else
  140. {
  141. Target target = new InternalTargetDst( book );
  142. from.Target = target;
  143. from.SendLocalizedMessage( 501612 ); // Select a book to copy this to.
  144. target.BeginTimeout( from, TimeSpan.FromMinutes( 1.0 ) );
  145. Inscribe.SetUser( book, from );
  146. }
  147. }
  148.  
  149. protected override void OnTargetCancel( Mobile from, TargetCancelType cancelType )
  150. {
  151. if ( cancelType == TargetCancelType.Timeout )
  152. from.SendLocalizedMessage( 501619 ); // You have waited too long to make your inscribe selection, your inscription attempt has timed out.
  153. }
  154. }
  155.  
  156. private class InternalTargetDst : Target
  157. {
  158. private BaseBook m_BookSrc;
  159.  
  160. public InternalTargetDst( BaseBook bookSrc ) : base ( 3, false, TargetFlags.None )
  161. {
  162. m_BookSrc = bookSrc;
  163. }
  164.  
  165. protected override void OnTarget( Mobile from, object targeted )
  166. {
  167. if ( m_BookSrc.Deleted )
  168. return;
  169.  
  170. BaseBook bookDst = targeted as BaseBook;
  171.  
  172. if ( bookDst == null )
  173. from.SendLocalizedMessage( 1046296 ); // That is not a book
  174. else if ( Inscribe.IsEmpty( m_BookSrc ) )
  175. from.SendLocalizedMessage( 501611 ); // Can't copy an empty book.
  176. else if ( bookDst == m_BookSrc )
  177. from.SendLocalizedMessage( 501616 ); // Cannot copy a book onto itself.
  178. else if ( !bookDst.Writable )
  179. from.SendLocalizedMessage( 501614 ); // Cannot write into that book.
  180. else if ( Inscribe.GetUser( bookDst ) != null )
  181. from.SendLocalizedMessage( 501621 ); // Someone else is inscribing that item.
  182. else
  183. {
  184. if ( from.CheckTargetSkill( SkillName.Inscribe, bookDst, 0, 50 ) )
  185. {
  186. Inscribe.Copy( m_BookSrc, bookDst, from );
  187.  
  188. from.SendLocalizedMessage( 501618 ); // You make a copy of the book.
  189. from.PlaySound( 0x249 );
  190. }
  191. else
  192. {
  193. from.SendLocalizedMessage( 501617 ); // You fail to make a copy of the book.
  194. }
  195. }
  196. }
  197.  
  198. protected override void OnTargetCancel( Mobile from, TargetCancelType cancelType )
  199. {
  200. if ( cancelType == TargetCancelType.Timeout )
  201. from.SendLocalizedMessage( 501619 ); // You have waited too long to make your inscribe selection, your inscription attempt has timed out.
  202. }
  203.  
  204. protected override void OnTargetFinish( Mobile from )
  205. {
  206. Inscribe.CancelUser( m_BookSrc );
  207. }
  208. }
  209. }
  210. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement