Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace COServer.Utility.PVP
- {
- public unsafe interface ITournment
- {
- int ID { get; set; }
- string Name { get; set; }
- ushort MapFace { get; set; }
- Game.Enums.PrizeType PrizeSort { get; set; }
- uint Prize { get; set; }
- ulong TopID { get; set; }
- int StartDate { get; set; }
- int EndTime { get; set; }
- }
- }
- using COServer.Game;
- using COServer.Network.GamePackets;
- using System;
- using System.Collections.Generic;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace COServer.Utility.PVP
- {
- public unsafe class Tournment : ITournment
- {
- private int _id;
- public int ID
- {
- get
- {
- return _id;
- }
- set
- {
- _id = value;
- }
- }
- private string _name;
- public string Name
- {
- get
- {
- return _name;
- }
- set
- {
- _name = value;
- }
- }
- private ushort _mapbase;
- public ushort MapFace
- {
- get
- {
- return _mapbase;
- }
- set
- {
- _mapbase = value;
- }
- }
- private Game.Enums.PrizeType sort;
- public Game.Enums.PrizeType PrizeSort
- {
- get
- {
- return sort;
- }
- set
- {
- sort = value;
- }
- }
- private uint _prize;
- public uint Prize
- {
- get
- {
- return _prize;
- }
- set
- {
- _prize = value;
- }
- }
- private ulong _top;
- public ulong TopID
- {
- get
- {
- return _top;
- }
- set
- {
- _top = value;
- }
- }
- private int SD;
- private int ED;
- public int StartDate
- {
- get
- {
- return SD;
- }
- set
- {
- SD = value;
- }
- }
- public int EndTime
- {
- get
- {
- return ED;
- }
- set
- {
- ED = value;
- }
- }
- private bool running = false;
- public bool IsRunning
- {
- get
- {
- return running;
- }
- }
- public bool CanStart
- {
- get
- {
- return DateTime.Now.Minute == StartDate && !running;
- }
- }
- public bool CanFinish
- {
- get
- {
- return DateTime.Now.Minute >= EndTime && running;
- }
- }
- public Map Map = null;
- public void Create()
- {
- if (CanStart)
- {
- if (!Kernel.Maps.ContainsKey(MapFace))
- new Map(MapFace, Database.DMaps.MapPaths[MapFace]);
- Map origMap = Kernel.Maps[MapFace];
- Map = origMap.MakeDynamicMap();
- if (Database.ServerData.Servers.Count > 1)
- {
- Constants.CrossedMapIDs.Add(Map.ID);
- }
- Kernel.Maps[1002].Npcs[62317].Name = Name;
- running = true;
- Kernel.SendWorldMessage(new MsgTalk(Name + " Has Started Go And Join It.", Color.Red, MsgTalk.Center));
- }
- }
- public void SignUp(Client.GameState client)
- {
- if (IsRunning)
- {
- var coordinates = Kernel.Maps[MapFace].RandomCoordinates();
- client.Player.Teleport(MapFace, Map.ID, coordinates.Item1, coordinates.Item2);
- client.OnDisconnect += delegate
- {
- client.Player.Teleport(1002, 300, 278);
- };
- }
- }
- public void Finish()
- {
- if (CanFinish)
- {
- Client.GameState client = null;
- var count = Kernel.GamePool.Values.Where((o) => o.Player.MapID == Map.ID && !o.Player.Dead).Count();
- if (count == 1)
- {
- client = Kernel.GamePool.Values.Where((o) => o.Player.MapID == Map.ID && !o.Player.Dead).FirstOrDefault();
- Kernel.SendWorldMessage(new MsgTalk(client.Player.Name + " won the " + Name + "!", Color.Red, MsgTalk.Center));
- switch (PrizeSort)
- {
- case Enums.PrizeType.Silver:
- client.Player.Money += Prize;
- break;
- case Enums.PrizeType.ConquerPoints:
- client.Player.ConquerPoints += Prize;
- break;
- case Enums.PrizeType.BoundConquerPoints:
- client.Player.BoundCps += Prize;
- break;
- }
- if (TopID > 0)
- {
- client.Player.AddTopStatus(TopID, DateTime.Now.AddHours(1));
- }
- client.Player.Teleport(1002, 300, 278);
- Map = null;
- }
- if (Kernel.Maps[1002].Npcs[62317].Name == Name)
- {
- Kernel.Maps[1002].Npcs[62317].Name = "PvPManager";
- }
- running = false;
- }
- }
- }
- }
- using COServer.Database;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace COServer.Utility.PVP
- {
- public unsafe class TournmentManager
- {
- public static Dictionary<int, Tournment> Tournments = new Dictionary<int, Tournment>();
- public static void Load()
- {
- lock (Tournments)
- {
- Console.Write("Loading Pole Tournments information... ");
- using (var cmd = new MySqlCommand(MySqlCommandType.SELECT).Select("pvptournments"))
- using (var reader = new MySqlReader(cmd))
- {
- while (reader.Read())
- {
- Console.Write("\b{0}", Loading.NextChar());
- var to = new Tournment();
- to.ID = (int)reader.ReadUInt32("ID");
- to.Name = reader.ReadString("Name");
- to.StartDate = reader.ReadInt32("StartDate");
- to.EndTime = reader.ReadInt32("EndTime");
- to.Prize = reader.ReadUInt32("Prize");
- to.PrizeSort = (Game.Enums.PrizeType)reader.ReadByte("FinancialType");
- to.MapFace = reader.ReadUInt16("MapBase");
- int IDTop = (int)reader.ReadUInt32("TOPID");
- if (IDTop > 0)
- {
- to.TopID = 1UL << IDTop;
- }
- else
- to.TopID = 0;
- if (!Tournments.ContainsKey(to.ID))
- Tournments.Add(to.ID, to);
- }
- }
- Console.WriteLine("OK!");
- }
- }
- public static void Process()
- {
- var tournments = Tournments.Values.ToArray();
- for (int x = 0; x < tournments.Length; x++)
- {
- if (tournments[x].CanStart)
- tournments[x].Create();
- else if (tournments[x].CanFinish)
- tournments[x].Finish();
- }
- }
- public static Tournment GetStartedTournment
- {
- get
- {
- foreach (var qu in Tournments.Values)
- {
- if (qu.IsRunning)
- {
- return Tournments[qu.ID];
- }
- }
- return null;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement