Advertisement
MrPoP

Untitled

Jul 19th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.53 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace COServer.Utility.PVP
  8. {
  9. public unsafe interface ITournment
  10. {
  11. int ID { get; set; }
  12. string Name { get; set; }
  13. ushort MapFace { get; set; }
  14. Game.Enums.PrizeType PrizeSort { get; set; }
  15. uint Prize { get; set; }
  16. ulong TopID { get; set; }
  17. int StartDate { get; set; }
  18. int EndTime { get; set; }
  19. }
  20. }
  21.  
  22. using COServer.Game;
  23. using COServer.Network.GamePackets;
  24. using System;
  25. using System.Collections.Generic;
  26. using System.Drawing;
  27. using System.Linq;
  28. using System.Text;
  29. using System.Threading.Tasks;
  30.  
  31. namespace COServer.Utility.PVP
  32. {
  33. public unsafe class Tournment : ITournment
  34. {
  35. private int _id;
  36. public int ID
  37. {
  38. get
  39. {
  40. return _id;
  41. }
  42. set
  43. {
  44. _id = value;
  45. }
  46. }
  47. private string _name;
  48. public string Name
  49. {
  50. get
  51. {
  52. return _name;
  53. }
  54. set
  55. {
  56. _name = value;
  57. }
  58. }
  59. private ushort _mapbase;
  60. public ushort MapFace
  61. {
  62. get
  63. {
  64. return _mapbase;
  65. }
  66. set
  67. {
  68. _mapbase = value;
  69. }
  70. }
  71. private Game.Enums.PrizeType sort;
  72. public Game.Enums.PrizeType PrizeSort
  73. {
  74. get
  75. {
  76. return sort;
  77. }
  78. set
  79. {
  80. sort = value;
  81. }
  82. }
  83. private uint _prize;
  84. public uint Prize
  85. {
  86. get
  87. {
  88. return _prize;
  89. }
  90. set
  91. {
  92. _prize = value;
  93. }
  94. }
  95. private ulong _top;
  96. public ulong TopID
  97. {
  98. get
  99. {
  100. return _top;
  101. }
  102. set
  103. {
  104. _top = value;
  105. }
  106. }
  107. private int SD;
  108. private int ED;
  109. public int StartDate
  110. {
  111. get
  112. {
  113. return SD;
  114. }
  115. set
  116. {
  117. SD = value;
  118. }
  119. }
  120. public int EndTime
  121. {
  122. get
  123. {
  124. return ED;
  125. }
  126. set
  127. {
  128. ED = value;
  129. }
  130. }
  131. private bool running = false;
  132. public bool IsRunning
  133. {
  134. get
  135. {
  136. return running;
  137. }
  138. }
  139. public bool CanStart
  140. {
  141. get
  142. {
  143. return DateTime.Now.Minute == StartDate && !running;
  144. }
  145. }
  146. public bool CanFinish
  147. {
  148. get
  149. {
  150. return DateTime.Now.Minute >= EndTime && running;
  151. }
  152. }
  153. public Map Map = null;
  154. public void Create()
  155. {
  156. if (CanStart)
  157. {
  158. if (!Kernel.Maps.ContainsKey(MapFace))
  159. new Map(MapFace, Database.DMaps.MapPaths[MapFace]);
  160. Map origMap = Kernel.Maps[MapFace];
  161. Map = origMap.MakeDynamicMap();
  162. if (Database.ServerData.Servers.Count > 1)
  163. {
  164. Constants.CrossedMapIDs.Add(Map.ID);
  165. }
  166. Kernel.Maps[1002].Npcs[62317].Name = Name;
  167. running = true;
  168. Kernel.SendWorldMessage(new MsgTalk(Name + " Has Started Go And Join It.", Color.Red, MsgTalk.Center));
  169. }
  170. }
  171. public void SignUp(Client.GameState client)
  172. {
  173. if (IsRunning)
  174. {
  175. var coordinates = Kernel.Maps[MapFace].RandomCoordinates();
  176. client.Player.Teleport(MapFace, Map.ID, coordinates.Item1, coordinates.Item2);
  177. client.OnDisconnect += delegate
  178. {
  179. client.Player.Teleport(1002, 300, 278);
  180. };
  181. }
  182. }
  183. public void Finish()
  184. {
  185. if (CanFinish)
  186. {
  187. Client.GameState client = null;
  188. var count = Kernel.GamePool.Values.Where((o) => o.Player.MapID == Map.ID && !o.Player.Dead).Count();
  189. if (count == 1)
  190. {
  191. client = Kernel.GamePool.Values.Where((o) => o.Player.MapID == Map.ID && !o.Player.Dead).FirstOrDefault();
  192. Kernel.SendWorldMessage(new MsgTalk(client.Player.Name + " won the " + Name + "!", Color.Red, MsgTalk.Center));
  193. switch (PrizeSort)
  194. {
  195. case Enums.PrizeType.Silver:
  196. client.Player.Money += Prize;
  197. break;
  198. case Enums.PrizeType.ConquerPoints:
  199. client.Player.ConquerPoints += Prize;
  200. break;
  201. case Enums.PrizeType.BoundConquerPoints:
  202. client.Player.BoundCps += Prize;
  203. break;
  204. }
  205. if (TopID > 0)
  206. {
  207. client.Player.AddTopStatus(TopID, DateTime.Now.AddHours(1));
  208. }
  209. client.Player.Teleport(1002, 300, 278);
  210. Map = null;
  211. }
  212. if (Kernel.Maps[1002].Npcs[62317].Name == Name)
  213. {
  214. Kernel.Maps[1002].Npcs[62317].Name = "PvPManager";
  215. }
  216. running = false;
  217. }
  218. }
  219. }
  220. }
  221.  
  222. using COServer.Database;
  223. using System;
  224. using System.Collections.Generic;
  225. using System.Linq;
  226. using System.Text;
  227. using System.Threading.Tasks;
  228.  
  229. namespace COServer.Utility.PVP
  230. {
  231. public unsafe class TournmentManager
  232. {
  233. public static Dictionary<int, Tournment> Tournments = new Dictionary<int, Tournment>();
  234. public static void Load()
  235. {
  236. lock (Tournments)
  237. {
  238. Console.Write("Loading Pole Tournments information... ");
  239. using (var cmd = new MySqlCommand(MySqlCommandType.SELECT).Select("pvptournments"))
  240. using (var reader = new MySqlReader(cmd))
  241. {
  242. while (reader.Read())
  243. {
  244. Console.Write("\b{0}", Loading.NextChar());
  245. var to = new Tournment();
  246. to.ID = (int)reader.ReadUInt32("ID");
  247. to.Name = reader.ReadString("Name");
  248. to.StartDate = reader.ReadInt32("StartDate");
  249. to.EndTime = reader.ReadInt32("EndTime");
  250. to.Prize = reader.ReadUInt32("Prize");
  251. to.PrizeSort = (Game.Enums.PrizeType)reader.ReadByte("FinancialType");
  252. to.MapFace = reader.ReadUInt16("MapBase");
  253. int IDTop = (int)reader.ReadUInt32("TOPID");
  254. if (IDTop > 0)
  255. {
  256. to.TopID = 1UL << IDTop;
  257. }
  258. else
  259. to.TopID = 0;
  260. if (!Tournments.ContainsKey(to.ID))
  261. Tournments.Add(to.ID, to);
  262. }
  263. }
  264. Console.WriteLine("OK!");
  265. }
  266. }
  267. public static void Process()
  268. {
  269. var tournments = Tournments.Values.ToArray();
  270. for (int x = 0; x < tournments.Length; x++)
  271. {
  272. if (tournments[x].CanStart)
  273. tournments[x].Create();
  274. else if (tournments[x].CanFinish)
  275. tournments[x].Finish();
  276. }
  277. }
  278. public static Tournment GetStartedTournment
  279. {
  280. get
  281. {
  282. foreach (var qu in Tournments.Values)
  283. {
  284. if (qu.IsRunning)
  285. {
  286. return Tournments[qu.ID];
  287. }
  288. }
  289. return null;
  290. }
  291. }
  292. }
  293. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement