RollDialog.cs 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. using Client.MirControls;
  2. using Client.MirGraphics;
  3. using Client.MirNetwork;
  4. using Client.MirSounds;
  5. using C = ClientPackets;
  6. namespace Client.MirScenes.Dialogs
  7. {
  8. public sealed class RollDialog : MirControl
  9. {
  10. private readonly MirAnimatedControl _animation;
  11. private readonly MirImageControl _image;
  12. private int _currentLoop;
  13. private int _type;
  14. private string _npcPage;
  15. private int _result;
  16. private bool _rolled;
  17. private bool _rolling;
  18. public RollDialog()
  19. {
  20. Movable = false;
  21. Sort = true;
  22. _animation = new MirAnimatedControl
  23. {
  24. Parent = this,
  25. Index = 0,
  26. Library = Libraries.Prguse2,
  27. UseOffSet = true,
  28. Location = new Point(0, 0),
  29. Visible = true
  30. };
  31. _animation.AfterAnimation += (o, e) =>
  32. {
  33. switch (_type)
  34. {
  35. case 0: //Die
  36. {
  37. if (_currentLoop < 5)
  38. {
  39. _currentLoop++;
  40. return;
  41. }
  42. _image.Visible = true;
  43. _animation.Visible = false;
  44. _animation.Animated = false;
  45. ReturnResult();
  46. }
  47. break;
  48. case 1: //Yut
  49. {
  50. _image.Visible = true;
  51. _animation.Visible = false;
  52. _animation.Animated = false;
  53. ReturnResult();
  54. }
  55. break;
  56. }
  57. };
  58. _image = new MirImageControl
  59. {
  60. Parent = this,
  61. Index = 0,
  62. Library = Libraries.Prguse2,
  63. UseOffSet = true,
  64. Location = new Point(0, 0),
  65. Visible = false
  66. };
  67. _image.Click += _image_Click;
  68. }
  69. public void Setup(int type, string page, int result, bool autoRoll)
  70. {
  71. _type = type;
  72. _npcPage = page;
  73. _result = result;
  74. _rolled = false;
  75. _currentLoop = 0;
  76. Visible = true;
  77. switch (type)
  78. {
  79. case 0: //Die
  80. {
  81. Size = new Size(65, 65);
  82. Location = new Point((Settings.ScreenWidth / 2) - 38, (Settings.ScreenHeight / 2) - 40);
  83. _image.Index = 282;
  84. _image.Library = Libraries.Prguse;
  85. _image.Visible = true;
  86. _animation.Loop = true;
  87. _animation.Visible = false;
  88. _animation.Animated = false;
  89. _animation.OffSet = 0;
  90. }
  91. break;
  92. case 1: //Yut
  93. {
  94. Size = new Size(180, 130);
  95. Location = new Point((Settings.ScreenWidth / 2) - 90, (Settings.ScreenHeight / 2) - 65);
  96. _image.Index = 2581;
  97. _image.Library = Libraries.Items;
  98. _image.Visible = true;
  99. _animation.Loop = false;
  100. _animation.Visible = false;
  101. _animation.Animated = false;
  102. _animation.OffSet = 0;
  103. }
  104. break;
  105. }
  106. if (autoRoll)
  107. {
  108. Roll();
  109. }
  110. }
  111. private void Roll()
  112. {
  113. Visible = true;
  114. _rolling = true;
  115. switch (_type)
  116. {
  117. case 0: //Die
  118. {
  119. _image.Index = 281 + _result;
  120. _image.Library = Libraries.Prguse;
  121. _image.Visible = false;
  122. _animation.Index = 290;
  123. _animation.Library = Libraries.Prguse;
  124. _animation.AnimationCount = 4;
  125. _animation.AnimationDelay = 100;
  126. _animation.Loop = true;
  127. _animation.Visible = true;
  128. _animation.Animated = true;
  129. _animation.OffSet = 0;
  130. SoundManager.PlaySound(10600);
  131. }
  132. break;
  133. case 1: //Yut
  134. {
  135. _image.Index = 2587 + _result;
  136. _image.Library = Libraries.Items;
  137. _image.Visible = false;
  138. _animation.Index = 2581;
  139. _animation.Library = Libraries.Items;
  140. _animation.AnimationCount = 6;
  141. _animation.AnimationDelay = 100;
  142. _animation.Loop = false;
  143. _animation.Visible = true;
  144. _animation.Animated = true;
  145. _animation.OffSet = 0;
  146. SoundManager.PlaySound(10601);
  147. }
  148. break;
  149. }
  150. }
  151. private void _image_Click(object sender, EventArgs e)
  152. {
  153. if (_rolling) return;
  154. if (_rolled)
  155. {
  156. Hide();
  157. return;
  158. }
  159. Roll();
  160. }
  161. private void ReturnResult()
  162. {
  163. _rolling = false;
  164. _rolled = true;
  165. if (CMain.Time <= GameScene.NPCTime) return;
  166. GameScene.NPCTime = CMain.Time + 5000;
  167. Network.Enqueue(new C.CallNPC { ObjectID = GameScene.NPCID, Key = $"[{_npcPage}]" });
  168. }
  169. }
  170. }