Untitled


SUBMITTED BY: moudixblack

DATE: Aug. 5, 2017, 12:39 a.m.

FORMAT: Text only

SIZE: 7.0 kB

HITS: 589

  1. using ProtoBuf;
  2. using System;
  3. using System.Runtime.InteropServices;
  4. using System.Collections.Generic;
  5. using System.IO;
  6. using System.Linq;
  7. using System.Collections.Concurrent;
  8. using System.Text;
  9. using LordsRoad;
  10. using LordsRoad.Database;
  11. using System.Threading.Tasks;
  12. namespace LordsRoad.Network.GamePackets
  13. {
  14. public class MsgGlobalLottery
  15. {
  16. public MsgGlobalLottery() { }
  17. public MsgGlobalLotteryProtoBlossom Info;
  18. [ProtoContract]
  19. public class MsgGlobalLotteryProtoBlossom
  20. {
  21. [ProtoMember(1, IsRequired = true)]
  22. public uint Type;
  23. [ProtoMember(2, IsRequired = true)]
  24. public uint PrizesType;
  25. [ProtoMember(3, IsRequired = true)]
  26. ///0 = Not Opened, 1 = Ready, 2 = Opened, 3 = Ranking
  27. public uint GUI;
  28. [ProtoMember(4, IsRequired = true)]
  29. public uint Time;
  30. [ProtoMember(5, IsRequired = true)]
  31. public uint Remain;
  32. [ProtoMember(6, IsRequired = true)]
  33. public uint TotalCount;
  34. }
  35. [ProtoContract]
  36. public class MsgGlobalLotteryProtoPick
  37. {
  38. [ProtoMember(1, IsRequired = true)]
  39. public uint Type;
  40. [ProtoMember(2, IsRequired = true)]
  41. public uint UID;
  42. [ProtoMember(3, IsRequired = true)]
  43. public uint GUI;
  44. [ProtoMember(4, IsRequired = true)]
  45. public uint PickItemID;
  46. [ProtoMember(5, IsRequired = true)]
  47. public string Name;
  48. [ProtoMember(6, IsRequired = true)]
  49. public uint Remain;
  50. [ProtoMember(7, IsRequired = true)]
  51. public uint TotalCount;
  52. }
  53. public bool Read(byte[] packet)
  54. {
  55. using (var memoryStream = new MemoryStream(packet))
  56. {
  57. Info = Serializer.DeserializeWithLengthPrefix<MsgGlobalLotteryProtoBlossom>(memoryStream, PrefixStyle.Fixed32);
  58. }
  59. return true;
  60. }
  61. public static Dictionary<string, uint> Ranking;
  62. public const double GoldenTreeHours = 2;//120 min
  63. public const uint Max = 2500;
  64. public void Handle(Client.GameClient client)
  65. {
  66. if (Kernel.GoldenTree == null) return;
  67. if (Ranking == null) Ranking = new Dictionary<string, uint>();
  68. switch (Info.Type)
  69. {
  70. case 1:
  71. {
  72. if (client.Inventory.Remove(Kernel.GoldenTree.CostItemID, 1))
  73. {
  74. Kernel.GoldenTreeTimes++;
  75. var proto = new MsgGlobalLotteryProtoPick();
  76. proto.UID = client.Entity.UID;
  77. proto.Name = client.Entity.Name;
  78. proto.Remain = (uint)(Max - Kernel.GoldenTreeTimes);
  79. proto.TotalCount = Max;
  80. proto.Type = 1;
  81. proto.PickItemID = Kernel.RandomTree(LordsRoad.Database.GoldenTreeTable.Pools.Values.Where(i => i.Type == Kernel.GoldenTree.Type).ToArray());
  82. client.Inventory.AddBound(LordsRoad.Database.GoldenTreeTable.Pools[proto.PickItemID].ItemID, 0, 1);
  83. if (LordsRoad.Database.GoldenTreeTable.Pools[proto.PickItemID].PerfectLevel == 1)
  84. {
  85. if (!Ranking.ContainsKey(client.Entity.Name)) Ranking.Add(client.Entity.Name, LordsRoad.Database.GoldenTreeTable.Pools[proto.PickItemID].ID);
  86. else
  87. {
  88. Ranking[client.Entity.Name] = LordsRoad.Database.GoldenTreeTable.Pools[proto.PickItemID].ID;
  89. }
  90. }
  91. foreach (var player in Kernel.GamePool.Values)
  92. player.Send(Kernel.FinalizeProtoBuf(proto, 3282));
  93. }
  94. break;
  95. }
  96. case 5:
  97. {
  98. Info = new MsgGlobalLotteryProtoBlossom();
  99. Info.Type = 5;
  100. Info.GUI = 2;
  101. Info.PrizesType = Kernel.GoldenTree.ID;
  102. client.Send(Kernel.FinalizeProtoBuf(Info, 3282));
  103. break;
  104. }
  105. default: Console.WriteLine("MsgGlobalLottery UNKNOWN ACTION: " + Info.Type.ToString(), ConsoleColor.DarkRed); break;
  106. }
  107. }
  108. public void Ready(Client.GameClient client)
  109. {
  110. Info = new MsgGlobalLotteryProtoBlossom();
  111. Info.PrizesType = Kernel.GoldenTree.ID;
  112. Info.GUI = 1;
  113. Info.Time = 5;
  114. client.Send(Kernel.FinalizeProtoBuf(Info, 3282));
  115. }
  116. public void Login(Client.GameClient client)
  117. {
  118. if ((DateTime.Now > Kernel.GoldenTree.StartTime.AddHours(GoldenTreeHours) || DateTime.Now < Kernel.GoldenTree.StartTime))
  119. {
  120. if (Ranking == null)
  121. {
  122. Info = new MsgGlobalLotteryProtoBlossom();
  123. Info.PrizesType = Kernel.GoldenTree.ID;
  124. Info.GUI = 0;
  125. }
  126. else
  127. {
  128. Info = new MsgGlobalLotteryProtoBlossom();
  129. Info.PrizesType = Kernel.GoldenTree.ID;
  130. Info.GUI = 3;
  131. }
  132. client.Send(Kernel.FinalizeProtoBuf(Info, 3282));
  133. return;
  134. }
  135. Blossom(client);
  136. }
  137. public void Blossom(Client.GameClient client)
  138. {
  139. Info = new MsgGlobalLotteryProtoBlossom();
  140. Info.PrizesType = Kernel.GoldenTree.ID;
  141. Info.GUI = 2;
  142. TimeSpan span = Kernel.GoldenTree.StartTime.AddHours(GoldenTreeHours) - DateTime.Now;
  143. Info.Time = (uint)(span.TotalSeconds);
  144. Info.Remain = (uint)(Max - Kernel.GoldenTreeTimes);
  145. Info.TotalCount = Max;
  146. client.Send(Kernel.FinalizeProtoBuf(Info, 3282));
  147. }
  148. public void End(Client.GameClient client)
  149. {
  150. if (Ranking == null)
  151. {
  152. Info = new MsgGlobalLotteryProtoBlossom();
  153. Info.PrizesType = Kernel.GoldenTree.ID;
  154. Info.GUI = 0;
  155. }
  156. else
  157. {
  158. Info = new MsgGlobalLotteryProtoBlossom();
  159. Info.PrizesType = Kernel.GoldenTree.ID;
  160. Info.GUI = 3;
  161. }
  162. client.Send(Kernel.FinalizeProtoBuf(Info, 3282));
  163. return;
  164. }
  165. }
  166. }

comments powered by Disqus