XConquer

LuckyWhel (Handler Packet)

Oct 21st, 2019
96
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using COServer;
  2. using COServer.Client;
  3. using COServer.Interfaces;
  4. using COServer.Network.GamePackets;
  5. using MsgServer.Database;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11.  
  12. namespace COServer.Network.GamePackets
  13. {
  14. public class LuckyWheel : Writer, IPacket
  15. {
  16.  
  17. public enum Reward
  18. {
  19. Open = 0,
  20. Draw = 1,
  21. Lottery = 2,
  22. Claim = 3,
  23. Redraw = 4,
  24. RedrawAfterClaim = 5,
  25. }
  26. private byte[] _packet;
  27. public LuckyWheel(byte[] packet)
  28. {
  29. _packet = packet;
  30.  
  31. }
  32. public LuckyWheel()
  33. {
  34. _packet = new byte[17];
  35. WriteUInt16(9, 0, _packet);
  36. WriteUInt16(2811, 2, _packet);
  37. }
  38. public Reward Type
  39. {
  40. get { return (Reward)_packet[4]; }
  41. set { WriteByte((byte)value, 4, _packet); }
  42. }
  43. public int ID
  44. {
  45. get { return BitConverter.ToInt32(_packet, 5); }
  46. set { WriteInt32(value, 5, _packet); }
  47. }
  48.  
  49. public byte[] ToArray()
  50. {
  51. return _packet;
  52. }
  53.  
  54. public void Deserialize(byte[] buffer)
  55. {
  56. _packet = buffer;
  57. }
  58.  
  59. public void Send(GameState client)
  60. {
  61. client.Send(_packet);
  62. }
  63. public static void Poroces(byte[] packet, GameState client)
  64. {
  65.  
  66. var _packet = new LuckyWheel(packet);
  67. var stage = LuckyWheel1.Stages[(int)_packet.ID];
  68. switch (_packet.Type)
  69. {
  70. case LuckyWheel.Reward.Lottery:
  71. {
  72. _packet.Type = LuckyWheel.Reward.Draw;
  73. _packet.ID = Kernel.Random.Next(-1, stage.Items.Length);
  74. client.LastTaskRewardID = _packet.ID;
  75. client.Send(_packet);
  76. break;
  77. }
  78. case LuckyWheel.Reward.Claim:
  79. {
  80. if (client.LastTaskRewardID > 0)
  81. {
  82. if (client.Player.LuckyWheel < 10)
  83. {
  84. var itemID = (uint)stage.Items[client.LastTaskRewardID];
  85. client.Inventory.AddTime(itemID, 3);
  86. client.LastTaskRewardID = 0;
  87. client.Player.LuckyWheel++;
  88. }
  89. }
  90. break;
  91. }
  92. case LuckyWheel.Reward.Redraw:
  93. {
  94. if (client.Player.ConquerPoints < 27)
  95. {
  96. client.Send(new MsgTalk("You don't have enough cps", System.Drawing.Color.Red, MsgTalk.System));
  97. return;
  98. }
  99. client.Player.ConquerPoints -= 27;
  100. _packet.Type = LuckyWheel.Reward.Draw;
  101. _packet.ID = Kernel.Random.Next(-1, stage.Items.Length);
  102. client.LastTaskRewardID = _packet.ID;
  103. client.Send(_packet);
  104. break;
  105. }
  106. case LuckyWheel.Reward.RedrawAfterClaim:
  107. {
  108. if (client.Player.ConquerPoints < 27)
  109. {
  110. client.Send(new MsgTalk("You don't have enough cps", System.Drawing.Color.Red, MsgTalk.System));
  111. return;
  112. }
  113. client.Player.ConquerPoints -= 27;
  114. _packet.Type = LuckyWheel.Reward.Draw;
  115. _packet.ID = Kernel.Random.Next(-1, stage.Items.Length);
  116. client.LastTaskRewardID = _packet.ID;
  117. client.Send(_packet);
  118. break;
  119. }
  120. }
  121. }
  122. }
  123. }
RAW Paste Data