Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using COServer.Game.ConquerStructures.Society;
- using COServer.Network.GamePackets;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using Core;
- using Core.Packet;
- namespace COServer.Game
- {
- public class GuildWar
- {
- public static MsgNpcInfoEX Pole, RightGate, LeftGate;
- public static MsgNpcInfoEX Poles;
- public static SafeDictionary<uint, Guild> Scores = new SafeDictionary<uint, Guild>(100);
- public static bool IsWar = false, Flame10th = false, FirstRound = false;
- public static Time32 ScoreSendStamp, LastWin;
- public static Guild PoleKeeper, CurrentTopLeader;
- private static bool changed = false;
- private static string[] scoreMessages;
- public static DateTime StartTime;
- public static bool Claim
- {
- get { return Server.Vars["gwclaim"]; }
- set { Server.Vars["gwclaim"] = value; }
- }
- public static uint KeeperID
- {
- get { return Server.Vars["gwkeeperid"]; }
- set { Server.Vars["gwkeeperid"] = value; }
- }
- public static void Initiate()
- {
- var Map = Kernel.Maps[1038];
- Pole = (MsgNpcInfoEX)Map.Npcs[810];
- LeftGate = (MsgNpcInfoEX)Map.Npcs[516074];
- RightGate = (MsgNpcInfoEX)Map.Npcs[516075];
- }
- public static void EliteGwint()
- {
- var Map = Kernel.Maps[2071];
- Poles = (MsgNpcInfoEX)Map.Npcs[811];
- }
- public static void Start()
- {
- if (LeftGate == null) return;
- Scores = new SafeDictionary<uint, Guild>(100);
- StartTime = DateTime.Now;
- LeftGate.Mesh = (ushort)(240 + LeftGate.Mesh % 10);
- RightGate.Mesh = (ushort)(270 + LeftGate.Mesh % 10);
- Kernel.SendWorldMessage(new MsgTalk("Guild war has began!", System.Drawing.Color.Red, (uint)PacketMsgTalk.MsgTalkType.Center), Server.GamePool);
- FirstRound = true;
- foreach (Guild guild in Kernel.Guilds.Values)
- {
- guild.sWarScore = 0;
- }
- MsgUpdate upd = new MsgUpdate(true);
- upd.UID = LeftGate.UID;
- upd.Append((byte)Core.Packet.PacketFlag.DataType.Mesh, LeftGate.Mesh);
- upd.Append((byte)Core.Packet.PacketFlag.DataType.Hitpoints, LeftGate.Hitpoints);
- Kernel.SendWorldMessage(upd, Server.GamePool, (ushort)1038);
- upd.Clear();
- upd.UID = RightGate.UID;
- upd.Append((byte)Core.Packet.PacketFlag.DataType.Mesh, RightGate.Mesh);
- upd.Append((byte)Core.Packet.PacketFlag.DataType.Hitpoints, RightGate.Hitpoints);
- Kernel.SendWorldMessage(upd, Server.GamePool, (ushort)1038);
- Claim = false;
- IsWar = true;
- }
- public static void Reset()
- {
- Scores = new SafeDictionary<uint, Guild>(100);
- LeftGate.Mesh = (ushort)(240 + LeftGate.Mesh % 10);
- RightGate.Mesh = (ushort)(270 + LeftGate.Mesh % 10);
- LeftGate.Hitpoints = LeftGate.MaxHitpoints;
- RightGate.Hitpoints = RightGate.MaxHitpoints;
- Pole.Hitpoints = Pole.MaxHitpoints;
- MsgUpdate upd = new MsgUpdate(true);
- upd.UID = LeftGate.UID;
- upd.Append((byte)Core.Packet.PacketFlag.DataType.Mesh, LeftGate.Mesh);
- upd.Append((byte)Core.Packet.PacketFlag.DataType.Hitpoints, LeftGate.Hitpoints);
- Kernel.SendWorldMessage(upd, Server.GamePool, (ushort)1038);
- upd.Clear();
- upd.UID = RightGate.UID;
- upd.Append((byte)Core.Packet.PacketFlag.DataType.Mesh, RightGate.Mesh);
- upd.Append((byte)Core.Packet.PacketFlag.DataType.Hitpoints, RightGate.Hitpoints);
- Kernel.SendWorldMessage(upd, Server.GamePool, (ushort)1038);
- foreach (Guild guild in Kernel.Guilds.Values)
- {
- guild.sWarScore = 0;
- }
- IsWar = true;
- }
- public static void FinishRound()
- {
- if (PoleKeeper != null && !FirstRound)
- {
- if (PoleKeeper.Wins == 0)
- PoleKeeper.Losts++;
- else
- PoleKeeper.Wins--;
- GuildTable.UpdateGuildWarStats(PoleKeeper);
- }
- LastWin = Time32.Now;
- FirstRound = false;
- SortScores(out PoleKeeper);
- if (PoleKeeper != null)
- {
- KeeperID = PoleKeeper.ID;
- 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);
- 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);
- if (PoleKeeper.Losts == 0)
- PoleKeeper.Wins++;
- else
- PoleKeeper.Losts--;
- GuildTable.UpdateGuildWarStats(PoleKeeper);
- Pole.Name = PoleKeeper.Name;
- }
- Pole.Hitpoints = Pole.MaxHitpoints;
- Kernel.SendWorldMessage(Pole, Server.GamePool, (ushort)1038);
- Reset();
- }
- public static void End()
- {
- if (PoleKeeper != null)
- {
- 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);
- }
- else
- {
- Kernel.SendWorldMessage(new MsgTalk("Guild war has ended and there was no winner!", System.Drawing.Color.Red, (uint)PacketMsgTalk.MsgTalkType.Center), Server.GamePool);
- }
- IsWar = false;
- Claim = true;
- UpdatePole(Pole);
- }
- public static void AddScore(uint addScore, Guild guild)
- {
- if (guild != null)
- {
- guild.sWarScore += addScore;
- changed = true;
- if (!Scores.ContainsKey(guild.ID))
- Scores.Add(guild.ID, guild);
- if ((int)Pole.Hitpoints <= 0)
- {
- FinishRound();
- return;
- }
- }
- }
- public static void SendScores()
- {
- if (scoreMessages == null)
- scoreMessages = new string[0];
- if (Scores.Count == 0)
- return;
- if (changed)
- SortScores(out CurrentTopLeader);
- for (int c = 0; c < scoreMessages.Length; c++)
- {
- MsgTalk msg = new MsgTalk(scoreMessages[c], System.Drawing.Color.Red, c == 0 ? (uint)PacketMsgTalk.MsgTalkType.FirstRightCorner : (uint)PacketMsgTalk.MsgTalkType.ContinueRightCorner);
- Kernel.SendWorldMessage(msg, Server.GamePool, (ushort)1038);
- Kernel.SendWorldMessage(msg, Server.GamePool, (ushort)6001);
- }
- }
- private static void SortScores(out Guild winner)
- {
- winner = null;
- List<string> ret = new List<string>();
- int Place = 0;
- foreach (Guild guild in Scores.Values.OrderByDescending((p) => p.sWarScore))
- {
- if (Place == 0)
- winner = guild;
- string str = "No " + (Place + 1).ToString() + ": " + guild.Name + "(" + guild.sWarScore + ")";
- ret.Add(str);
- Place++;
- if (Place == 4)
- break;
- }
- changed = false;
- scoreMessages = ret.ToArray();
- }
- private static void UpdatePole(MsgNpcInfoEX pole)
- {
- new MySqlCommand(MySqlCommandType.UPDATE)
- .Update("sobnpcs").Set("name", pole.Name).Set("life", Pole.Hitpoints).Where("id", pole.UID).Execute();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement