Advertisement
XConquer

GW Baka

Feb 21st, 2023
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.32 KB | None | 0 0
  1. using COServer.Game.ConquerStructures.Society;
  2. using COServer.Network.GamePackets;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using Core;
  8. using Core.Packet;
  9.  
  10. namespace COServer.Game
  11. {
  12. public class GuildWar
  13. {
  14. public static MsgNpcInfoEX Pole, RightGate, LeftGate;
  15.  
  16. public static MsgNpcInfoEX Poles;
  17.  
  18. public static SafeDictionary<uint, Guild> Scores = new SafeDictionary<uint, Guild>(100);
  19.  
  20. public static bool IsWar = false, Flame10th = false, FirstRound = false;
  21.  
  22. public static Time32 ScoreSendStamp, LastWin;
  23.  
  24. public static Guild PoleKeeper, CurrentTopLeader;
  25.  
  26. private static bool changed = false;
  27.  
  28. private static string[] scoreMessages;
  29.  
  30. public static DateTime StartTime;
  31.  
  32. public static bool Claim
  33. {
  34. get { return Server.Vars["gwclaim"]; }
  35. set { Server.Vars["gwclaim"] = value; }
  36. }
  37. public static uint KeeperID
  38. {
  39. get { return Server.Vars["gwkeeperid"]; }
  40. set { Server.Vars["gwkeeperid"] = value; }
  41. }
  42. public static void Initiate()
  43. {
  44. var Map = Kernel.Maps[1038];
  45. Pole = (MsgNpcInfoEX)Map.Npcs[810];
  46. LeftGate = (MsgNpcInfoEX)Map.Npcs[516074];
  47. RightGate = (MsgNpcInfoEX)Map.Npcs[516075];
  48. }
  49.  
  50. public static void EliteGwint()
  51. {
  52. var Map = Kernel.Maps[2071];
  53. Poles = (MsgNpcInfoEX)Map.Npcs[811];
  54. }
  55.  
  56. public static void Start()
  57. {
  58. if (LeftGate == null) return;
  59. Scores = new SafeDictionary<uint, Guild>(100);
  60. StartTime = DateTime.Now;
  61. LeftGate.Mesh = (ushort)(240 + LeftGate.Mesh % 10);
  62. RightGate.Mesh = (ushort)(270 + LeftGate.Mesh % 10);
  63. Kernel.SendWorldMessage(new MsgTalk("Guild war has began!", System.Drawing.Color.Red, (uint)PacketMsgTalk.MsgTalkType.Center), Server.GamePool);
  64. FirstRound = true;
  65. foreach (Guild guild in Kernel.Guilds.Values)
  66. {
  67. guild.sWarScore = 0;
  68. }
  69. MsgUpdate upd = new MsgUpdate(true);
  70. upd.UID = LeftGate.UID;
  71. upd.Append((byte)Core.Packet.PacketFlag.DataType.Mesh, LeftGate.Mesh);
  72. upd.Append((byte)Core.Packet.PacketFlag.DataType.Hitpoints, LeftGate.Hitpoints);
  73. Kernel.SendWorldMessage(upd, Server.GamePool, (ushort)1038);
  74. upd.Clear();
  75. upd.UID = RightGate.UID;
  76. upd.Append((byte)Core.Packet.PacketFlag.DataType.Mesh, RightGate.Mesh);
  77. upd.Append((byte)Core.Packet.PacketFlag.DataType.Hitpoints, RightGate.Hitpoints);
  78. Kernel.SendWorldMessage(upd, Server.GamePool, (ushort)1038);
  79. Claim = false;
  80. IsWar = true;
  81. }
  82.  
  83. public static void Reset()
  84. {
  85. Scores = new SafeDictionary<uint, Guild>(100);
  86.  
  87. LeftGate.Mesh = (ushort)(240 + LeftGate.Mesh % 10);
  88. RightGate.Mesh = (ushort)(270 + LeftGate.Mesh % 10);
  89.  
  90. LeftGate.Hitpoints = LeftGate.MaxHitpoints;
  91. RightGate.Hitpoints = RightGate.MaxHitpoints;
  92. Pole.Hitpoints = Pole.MaxHitpoints;
  93.  
  94. MsgUpdate upd = new MsgUpdate(true);
  95. upd.UID = LeftGate.UID;
  96. upd.Append((byte)Core.Packet.PacketFlag.DataType.Mesh, LeftGate.Mesh);
  97. upd.Append((byte)Core.Packet.PacketFlag.DataType.Hitpoints, LeftGate.Hitpoints);
  98. Kernel.SendWorldMessage(upd, Server.GamePool, (ushort)1038);
  99. upd.Clear();
  100. upd.UID = RightGate.UID;
  101. upd.Append((byte)Core.Packet.PacketFlag.DataType.Mesh, RightGate.Mesh);
  102. upd.Append((byte)Core.Packet.PacketFlag.DataType.Hitpoints, RightGate.Hitpoints);
  103. Kernel.SendWorldMessage(upd, Server.GamePool, (ushort)1038);
  104.  
  105. foreach (Guild guild in Kernel.Guilds.Values)
  106. {
  107. guild.sWarScore = 0;
  108. }
  109.  
  110. IsWar = true;
  111. }
  112.  
  113. public static void FinishRound()
  114. {
  115. if (PoleKeeper != null && !FirstRound)
  116. {
  117. if (PoleKeeper.Wins == 0)
  118. PoleKeeper.Losts++;
  119. else
  120. PoleKeeper.Wins--;
  121. GuildTable.UpdateGuildWarStats(PoleKeeper);
  122. }
  123. LastWin = Time32.Now;
  124.  
  125. FirstRound = false;
  126. SortScores(out PoleKeeper);
  127. if (PoleKeeper != null)
  128. {
  129. KeeperID = PoleKeeper.ID;
  130. Kernel.SendWorldMessage(new MsgTalk("The guild, " + PoleKeeper.Name + ", owned by " + PoleKeeper.LeaderName + " has won this guild war round!", System.Drawing.Color.Red, (uint)PacketMsgTalk.MsgTalkType.Center), Server.GamePool);
  131. Kernel.SendWorldMessage(new MsgTalk("It is generald pardon time. You have 5 minutes to leave, run for your life!", System.Drawing.Color.White, (uint)PacketMsgTalk.MsgTalkType.TopLeft), Server.GamePool, (ushort)6001);
  132. if (PoleKeeper.Losts == 0)
  133. PoleKeeper.Wins++;
  134. else
  135. PoleKeeper.Losts--;
  136. GuildTable.UpdateGuildWarStats(PoleKeeper);
  137. Pole.Name = PoleKeeper.Name;
  138. }
  139. Pole.Hitpoints = Pole.MaxHitpoints;
  140. Kernel.SendWorldMessage(Pole, Server.GamePool, (ushort)1038);
  141. Reset();
  142. }
  143.  
  144. public static void End()
  145. {
  146. if (PoleKeeper != null)
  147. {
  148. Kernel.SendWorldMessage(new MsgTalk("The guild, " + PoleKeeper.Name + ", owned by " + PoleKeeper.LeaderName + " has won this guild war!---Guild war has ended!", System.Drawing.Color.White, (uint)PacketMsgTalk.MsgTalkType.Center), Server.GamePool);
  149. }
  150. else
  151. {
  152. Kernel.SendWorldMessage(new MsgTalk("Guild war has ended and there was no winner!", System.Drawing.Color.Red, (uint)PacketMsgTalk.MsgTalkType.Center), Server.GamePool);
  153. }
  154. IsWar = false;
  155. Claim = true;
  156. UpdatePole(Pole);
  157. }
  158.  
  159. public static void AddScore(uint addScore, Guild guild)
  160. {
  161. if (guild != null)
  162. {
  163. guild.sWarScore += addScore;
  164. changed = true;
  165. if (!Scores.ContainsKey(guild.ID))
  166. Scores.Add(guild.ID, guild);
  167. if ((int)Pole.Hitpoints <= 0)
  168. {
  169. FinishRound();
  170.  
  171. return;
  172. }
  173. }
  174. }
  175.  
  176. public static void SendScores()
  177. {
  178. if (scoreMessages == null)
  179. scoreMessages = new string[0];
  180. if (Scores.Count == 0)
  181. return;
  182. if (changed)
  183. SortScores(out CurrentTopLeader);
  184.  
  185. for (int c = 0; c < scoreMessages.Length; c++)
  186. {
  187. MsgTalk msg = new MsgTalk(scoreMessages[c], System.Drawing.Color.Red, c == 0 ? (uint)PacketMsgTalk.MsgTalkType.FirstRightCorner : (uint)PacketMsgTalk.MsgTalkType.ContinueRightCorner);
  188. Kernel.SendWorldMessage(msg, Server.GamePool, (ushort)1038);
  189. Kernel.SendWorldMessage(msg, Server.GamePool, (ushort)6001);
  190. }
  191. }
  192.  
  193. private static void SortScores(out Guild winner)
  194. {
  195. winner = null;
  196. List<string> ret = new List<string>();
  197.  
  198. int Place = 0;
  199. foreach (Guild guild in Scores.Values.OrderByDescending((p) => p.sWarScore))
  200. {
  201. if (Place == 0)
  202. winner = guild;
  203. string str = "No " + (Place + 1).ToString() + ": " + guild.Name + "(" + guild.sWarScore + ")";
  204. ret.Add(str);
  205. Place++;
  206. if (Place == 4)
  207. break;
  208. }
  209.  
  210. changed = false;
  211. scoreMessages = ret.ToArray();
  212. }
  213.  
  214. private static void UpdatePole(MsgNpcInfoEX pole)
  215. {
  216. new MySqlCommand(MySqlCommandType.UPDATE)
  217. .Update("sobnpcs").Set("name", pole.Name).Set("life", Pole.Hitpoints).Where("id", pole.UID).Execute();
  218. }
  219. }
  220. }
  221.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement