|
|
المشاركات 1,993 |
+التقييم 1.00 |
تاريخ التسجيل Jun 2019 |
الاقامة |
نظام التشغيل ويندوز 0 |
رقم العضوية 279 |
public unsafe class ElitePK
using System;
using System.IO;
using System.Linq;
using System.Text;
using XMeGo.Client;
using System.Collections.Generic;
using XMeGo.Network.GamePackets;
using System.Collections.Concurrent;
using XMeGo.Game.Features.Tournaments;
using XMeGo.MaTrix;
namespace XMeGo.Game
{
public unsafe class ElitePK
{
public const int EventTime = 16;
public class States
{
public const byte
GUI_Top8Ranking = 0,
GUI_Knockout = 3,
GUI_Top8Qualifier = 4,
GUI_Top4Qualifier = 5,
GUI_Top2Qualifier = 6,
GUI_Top3 = 7,
GUI_Top1 = 8,
GUI_ReconstructTop = 9;
public const byte
T_Organize = 0,
T_CreateMatches = 1,
T_Wait = 2,
T_Fights = 3,
T_Finished = 4,
T_ReOrganize = 5;
}
public FighterStats[] Top8 = new FighterStats[0];
public ConcurrentDictionary<uint, GameState> Players;
public ConcurrentDictionary<uint, Match> Matches;
private Match[] MatchArray;
private Match[] Top4MatchArray;
private Match[] ExtendedMatchArray;
private Counter MatchCounter;
private ushort MatchIndex;
public bool IsAlive = false;
public DateTime ConstructTop8 = DateTime.Now;
public Map WaitingArea;
public int State;
private int pState = States.T_Organize;
public int GroupID;
public bool EliteStarted = false;
private bool willAdvance;
private IDisposable Subscriber;
private Time32 pStamp;
private bool SentNoWagers;
public DateTime EndDateTime;
public ElitePK(int group)
{
if (!IsAlive)
{
IsAlive = true;
Players = new ConcurrentDictionary<uint, GameState>();
Matches = new ConcurrentDictionary<uint, Match>();
GroupID = group;
MatchCounter = new Counter((uint)(GroupID * 100000 + 100000));
LoadTop8();
WaitingArea = Kernel.Maps[(ushort)ElitePKTournament.WaitingAreaID].MakeDynamicMap();
Constants.PKForbiddenMaps.Add(WaitingArea.ID);
State = States.GUI_Top8Ranking;
pState = States.T_Organize;
}
}
public void SaveTop8()
{
int len = Top8.Count(p => p.UID != 0);
using (var stream = new MemoryStream())
using (var writer = new BinaryWriter(stream))
{
writer.Write(len);
for (int i = 0; i < len; i++)
{
writer.Write(Top8[i].UID);
writer.Write(Top8[i].Name);
writer.Write(Top8[i].Mesh);
writer.Write(Top8[i].ReceiveReward);
}
Program.Vars["epk" + GroupID] = stream.ToArray();
}
}
private void LoadTop8()
{
Top8 = new FighterStats[8];
byte[] bytes = Program.Vars["epk" + GroupID];
if (bytes == null)
{
for (int i = 0; i < 8; i++)
Top8[i] = new FighterStats(0, "", 0);
SaveTop8();
return;
}
using (var stream = new MemoryStream(bytes))
using (var reader = new BinaryReader(stream))
{
int len = reader.ReadInt32();
for (int i = 0; i < len; i++)
{
Top8[i] = new FighterStats(reader.ReadUInt32(), reader.ReadString(), reader.ReadUInt32());
Top8[i].ReceiveReward = reader.ReadByte();
}
for (int i = len; i < 8; i++)
Top8[i] = new FighterStats(0, "", 0);
}
}
public bool GetReward(Client.GameState client, out byte Rank)
{
if (Top8.Length == 8)
{
for (int x = 0; x < Top8.Length; x++)
{
if (Top8[x] != null)
{
if (Top8[x].UID == client.Entity.UID)
{
if (Top8[x].ReceiveReward == 0)
{
Top8[x].ReceiveReward = 1;
Rank = (byte)(x + 1);
return true;
}
else
{
Rank = (byte)(x + 1);
return false;
}
}
}
}
}
Rank = 0;
return false;
}
public static bool GetReward(GameState client, out byte rank, out byte elitestage)
{
if (ElitePKTournament.Tournaments != null)
for (byte x = 0; x < ElitePKTournament.Tournaments.Length; x++)
{
if (ElitePKTournament.Tournaments[x] != null)
{
if (ElitePKTournament.Tournaments[x].Top8 != null)
{
for (byte i = 0; i < ElitePKTournament.Tournaments[x].Top8.Length; i++)
{
if (ElitePKTournament.Tournaments[x].Top8[i] != null)
{
if (ElitePKTournament.Tournaments[x].Top8[i].UID == client.Entity.UID)
{
if (ElitePKTournament.Tournaments[x].Top8[i].RceiveReward == 0)
{
rank = (byte)(i + 1);
elitestage = x;
ElitePKTournament.Tournaments[x].Top8[i].RceiveReward = 1;
return true;
}
}
}
}
}
}
}
rank = 0;
elitestage = 0;
return false;
}
public class FighterStats
{
public enum StatusFlag : int
{
None = 0,
Fighting = 1,
Lost = 2,
Qualified = 3,
Waiting = 4,
Bye = 5,
Inactive = 7,
WonMatch = 8
}
public ConcurrentDictionary<uint, uint> Wagers;
public string Name;
public uint UID;
public byte ReceiveReward;
public uint Mesh;
public uint Wager;
public uint Cheers;
public uint Points;
public StatusFlag Flag;
public bool Advance;
public byte RceiveReward;
public bool Waiting
{
get { return Flag == StatusFlag.Waiting; }
}
public bool NoFlag
{
get { return Flag == StatusFlag.None; }
}
public bool Fighting
{
get { return Flag == StatusFlag.Fighting; }
}
public bool Winner
{
get { return Flag == StatusFlag.Qualified || Flag == StatusFlag.WonMatch; }
}
public bool Lost
{
get { return Flag == StatusFlag.Lost; }
}
public FighterStats(uint id, string name, uint mesh)
{
Wagers = new ConcurrentDictionary<uint, uint>();
UID = id;
Name = name;
Mesh = mesh;
}
public void Reset(bool setflag = false)
{
Wagers.Clear();
Wager = 0;
Points = 0;
Cheers = 0;
if (setflag) Flag = StatusFlag.None;
}
public FighterStats Clone()
{
FighterStats stats = new FighterStats(UID, Name, Mesh);
stats.Points = this.Points;
stats.Flag = this.Flag;
stats.Wager = this.Wager;
return stats;
}
}
public class Match
{
public enum StatusFlag : int
{
AcceptingWagers = 0,
Watchable = 1,
SwitchOut = 2,
InFight = 3,
OK = 4,
FinalMatch = 5,
}
public GameState[] Players;
public FighterStats[] MatchStats;
public FighterStats[] FightersStats
{
get { return MatchStats.Where(p => p.NoFlag | p.Fighting).ToArray(); }
}
public bool OnGoing
{
get { return Flag != StatusFlag.AcceptingWagers; }
}
public int GroupID
{
get { return (int)ID / 100000 - 1; }
}
public uint TimeLeft
{
get
{
int val = (int)((ImportTime.AddMinutes(3).TotalMilliseconds - Time32.Now.TotalMilliseconds) / 1000);
if (val < 0) val = 0;
return (uint)val;
}
}
public ConcurrentDictionary<uint, GameState> Watchers;
public uint ID;
public StatusFlag Flag;
public bool Inside;
public bool Done;
public bool Exported;
public bool Completed;
public ushort Index;
private Time32 ImportTime;
private Map Map;
private Time32 DoneStamp;
public int Imports;
public uint TotalWagers;
public Match(params GameState[] players)
{
Players = players;
Watchers = new ConcurrentDictionary<uint, GameState>();
MatchStats = new FighterStats[players.Length];
if (players.Length == 1)
{
Players[0].ElitePKMatch = this;
MatchStats[0] = players[0].ElitePKStats;
MatchStats[0].Reset(true);
MatchStats[0].Flag = FighterStats.StatusFlag.Qualified;
}
else
{
Players = players;
for (int i = 0; i < players.Length; i++)
{
players[i].ElitePKMatch = this;
MatchStats[i] = players[i].ElitePKStats;
MatchStats[i].Reset(true);
}
if (MatchStats.Length == 3)
if (Players[0] != null)
MatchStats[0].Flag = ElitePK.FighterStats.StatusFlag.Waiting;
}
Imports = 0;
Flag = StatusFlag.AcceptingWagers;
}
public void Import(StatusFlag flag = StatusFlag.OK)
{
Imports++;
Exported = Done = false;
Inside = true;
Flag = flag;
ImportTime = Time32.Now;
Map = Kernel.Maps[700].MakeDynamicMap();
if (Players.Length > 1)
{
GameState player1 = null, player2 = null;
for (int i = 0; i < Players.Length; i++)
{
if (!MatchStats[i].Waiting)
{
if (player1 == null)
player1 = Players[i];
else
player2 = Players[i];
}
}
if (!player1.Socket.IsAlive)
{
Exported = Done = true;
Flag = StatusFlag.OK;
if (Players.Length == 3)
Flag = StatusFlag.SwitchOut;
Completed = true;
var statsArray = FightersStats;
if (Players.Length == 3)
foreach (var stats in statsArray)
stats.Flag = FighterStats.StatusFlag.WonMatch;
else
foreach (var stats in statsArray)
stats.Flag = FighterStats.StatusFlag.Qualified;
player1.ElitePKStats.Flag = FighterStats.StatusFlag.Lost;
return;
}
if (!player2.Socket.IsAlive)
{
Exported = Done = true;
Flag = StatusFlag.OK;
if (Players.Length == 3)
Flag = StatusFlag.SwitchOut;
Completed = true;
var statsArray = FightersStats;
if (Players.Length == 3)
foreach (var stats in statsArray)
stats.Flag = FighterStats.StatusFlag.WonMatch;
else
foreach (var stats in statsArray)
stats.Flag = FighterStats.StatusFlag.Qualified;
player2.ElitePKStats.Flag = FighterStats.StatusFlag.Lost;
return;
}
player1.ElitePKStats.Flag = FighterStats.StatusFlag.Fighting;
player2.ElitePKStats.Flag = FighterStats.StatusFlag.Fighting;
importPlayer(player1, player2);
importPlayer(player2, player1);
ElitePKBrackets brackets = new ElitePKBrackets(true, 1);
brackets.Group = (ushort)GroupID;
brackets.GUIType = (ushort)ElitePKTournament.Tournaments[GroupID].State;
brackets.TotalMatches = brackets.MatchCount = 1;
brackets.Type = ElitePKBrackets.StaticUpdate;
brackets.Append(this);
Kernel.SendWorldMessage(brackets);
}
else
{
Exported = Done = true;
Flag = StatusFlag.OK;
Completed = true;
foreach (var stats in MatchStats)
if (stats != null)
stats.Flag = FighterStats.StatusFlag.Qualified;
}
}
private void importPlayer(GameState player, GameState opponent)
{
if (Players.Length > 1)
{
var coords = Map.RandomCoordinates();
player.Entity.Teleport(Map.BaseID, Map.ID, coords.Item1, coords.Item2);
player.Entity.BringToLife();
ElitePKMatchUI ui = new ElitePKMatchUI(true);
ui.Append(opponent);
ui.TimeLeft = TimeLeft;
ui.Type = ElitePKMatchUI.BeginMatch;
player.Send(ui);
player.Send(CreateUpdate());
player.CantAttack = Time32.Now.AddSeconds(11);
player.Entity.PrevPKMode = player.Entity.PKMode;
player.Entity.PKMode = Enums.PKMode.PK;
Data dat = new Data(true);
dat.UID = player.Entity.UID;
dat.ID = Data.ChangePKMode;
dat.dwParam = (uint)player.Entity.PKMode;
player.Send(dat);
}
player.Entity.OnDeath = p => { p.Owner.ElitePKMatch.End(p.Owner); };
}
public void End(GameState client)
{
if (Players.Length == 1)
{
Players[0].ElitePKStats.Flag = FighterStats.StatusFlag.Qualified;
Flag = StatusFlag.OK;
return;
}
if (Done) return;
if (client.ElitePKStats.Flag != FighterStats.StatusFlag.Fighting) return;
Done = true;
DoneStamp = Time32.Now;
Flag = StatusFlag.OK;
client.ElitePKStats.Flag = FighterStats.StatusFlag.Lost;
ElitePKMatchUI ui = new ElitePKMatchUI(true);
ui.Type = ElitePKMatchUI.Effect;
ui.dwParam = ElitePKMatchUI.Effect_Lose;
client.Send(ui);
client.ElitePKStats.Wager = 0;
client.ElitePKStats.Wagers.Clear();
var target = targetOf(client);
if (target != null)
{
ui.Append(client);
ui.dwParam = ElitePKMatchUI.Effect_Win;
target.Send(ui);
ui.Type = ElitePKMatchUI.EndMatch;
client.Send(ui);
target.Send(ui);
if (Imports == 2 || Players.Length != 3)
{
target.ElitePKStats.Flag = FighterStats.StatusFlag.Qualified;
}
else
{
Flag = StatusFlag.SwitchOut;
target.ElitePKStats.Flag = FighterStats.StatusFlag.None;
}
if (TotalWagers != 0)
{
double totalWager = target.ElitePKStats.Wager;
foreach (var kvp in target.ElitePKStats.Wagers)
{
double ratio = (double)kvp.Value / totalWager;
Client.GameState pClient;
if (Kernel.GamePool.TryGetValue(kvp.Key, out pClient))
{
uint gain = (uint)(ratio * totalWager * 100000);
pClient.Entity.Money += gain;
pClient.Send("You have gained " + gain + " gold from the winning of " + target.ElitePKStats.Name);
}
}
target.ElitePKStats.Wager = 0;
target.ElitePKStats.Wagers.Clear();
TotalWagers = 0;
}
}
ElitePKBrackets brackets = new ElitePKBrackets(true, 1);
brackets.Group = (ushort)GroupID;
brackets.GUIType = (ushort)ElitePKTournament.Tournaments[GroupID].State;
brackets.TotalMatches = brackets.MatchCount = 1;
brackets.Type = ElitePKBrackets.StaticUpdate;
brackets.Append(this);
Kernel.SendWorldMessage(brackets);
//target.Entity.BringToLife();
var array = Watchers.Values.ToArray();
foreach (var watcher in array)
LeaveWatch(watcher);
}
public GameState targetOf(GameState client)
{
for (int i = 0; i < Players.Length; i++)
if (Players[i] != null)
if (Players[i].Entity.UID != client.Entity.UID)
if (!Players[i].ElitePKStats.Waiting)
return Players[i];
return null;
}
public ElitePKMatchStats CreateUpdate()
{
ElitePKMatchStats stats = new ElitePKMatchStats();
stats.Append(this);
return stats;
}
public void Export()
{
if (Time32.Now > DoneStamp.AddSeconds(3) || TimeLeft == 0)
{
#region !Done
if (!Done)
{
if (Players.Length == 1)
{
Players[0].ElitePKStats.Flag = FighterStats.StatusFlag.Qualified;
Flag = StatusFlag.OK;
}
else
{
var fighters = FightersStats;
if (fighters[0].Fighting && fighters[1].Fighting)
{
if (fighters[0].Points == fighters[1].Points)
{
if (fighters[0].Wager <= fighters[1].Wager)
{
End(Players.First(p => p.Entity.UID == fighters[0].UID));
}
else
{
End(Players.First(p => p.Entity.UID == fighters[1].UID));
}
}
else
{
if (fighters[0].Points > fighters[1].Points)
{
End(Players.First(p => p.Entity.UID == fighters[0].UID));
}
else
{
End(Players.First(p => p.Entity.UID == fighters[1].UID));
}
}
}
}
}
#endregion
foreach (var player in Players)
{
if (player != null)
{
if (!player.ElitePKStats.Waiting)
{
// player.CurrentHonor += 1000;
//player.HistoryHonor += 1000;
player.IncreaseExperience(player.ExpBall, false);
var map = ElitePKTournament.Tournaments[GroupID].WaitingArea;
var coords = map.RandomCoordinates();
player.Entity.Teleport(map.ID, coords.Item1, coords.Item2);
player.Entity.BringToLife();
}
}
}
Exported = true;
Completed = true;
var array = Watchers.Values.ToArray();
foreach (var watcher in array)
LeaveWatch(watcher);
}
}
public void SwitchBetween()
{
if (Imports == 1)
{
if (Players.Length == 3)
{
if (Players[0] != null)
{
MatchStats[0].Flag = FighterStats.StatusFlag.None;
if (MatchStats[1].Winner)
MatchStats[1].Flag = FighterStats.StatusFlag.None;
if (MatchStats[2].Winner)
MatchStats[2].Flag = FighterStats.StatusFlag.None;
Completed = false;
}
}
}
else
Flag = StatusFlag.OK;
}
public void Send(GameState client, int gui_state)
{
ElitePKBrackets brackets = new ElitePKBrackets(true, 1);
brackets.Group = (ushort)GroupID;
brackets.GUIType = (ushort)gui_state;
brackets.TotalMatches = brackets.MatchCount = 1;
brackets.Type = ElitePKBrackets.StaticUpdate;
brackets.Append(this);
client.Send(brackets);
}
public void Commit()
{
var matchStats = new FighterStats[MatchStats.Length];
for (int i = 0; i < matchStats.Length; i++)
{
matchStats[i] = MatchStats[i].Clone();
if (matchStats[i].Winner)
matchStats[i].Advance = true;
}
MatchStats = matchStats;
}
public void BeginWatch(GameState client)
{
if (Watchers.ContainsKey(client.Entity.UID)) return;
if (client.ElitePKMatch != null)
if (!client.ElitePKStats.Waiting && !client.ElitePKStats.Lost)
return;
Watchers.TryAdd(client.Entity.UID, client);
var coords = Map.RandomCoordinates();
client.WatchingElitePKMatch = this;
client.Entity.Teleport(Map.BaseID, Map.ID, coords.Item1, coords.Item2);
if (FightersStats.Length == 2)
{
ElitePKWatch watch = new ElitePKWatch(true, Watchers.Count);
watch.ID = ID;
watch.Type = ElitePKWatch.Fighters;
watch.dwCheers1 = FightersStats[0].Cheers;
watch.dwCheers2 = FightersStats[1].Cheers;
watch.Append(FightersStats[0].Name);
watch.Append(FightersStats[1].Name);
client.Send(watch);
watch = new ElitePKWatch(true, Watchers.Count);
watch.ID = ID;
watch.dwCheers1 = FightersStats[0].Cheers;
watch.dwCheers2 = FightersStats[1].Cheers;
foreach (var pClient in Watchers.Values)
watch.Append(pClient.Entity.Mesh, pClient.Entity.Name);
client.Send(watch);
}
client.Send(CreateUpdate());
UpdateWatchers();
}
public void Update()
{
var update = CreateUpdate();
if (Players != null)
foreach (var player in Players)
if (player != null)
if (player.ElitePKStats.Fighting)
player.Send(update);
}
public void UpdateWatchers()
{
var watch = new ElitePKWatch(true, Watchers.Count);
watch.ID = ID;
watch.Type = ElitePKWatch.Watchers;
watch.dwCheers1 = FightersStats[0].Cheers;
watch.dwCheers2 = FightersStats[1].Cheers;
foreach (var pClient in Watchers.Values)
watch.Append(pClient.Entity.Mesh, pClient.Entity.Name);
foreach (var pClient in Watchers.Values)
pClient.Send(watch);
foreach (var pClient in Players)
if (pClient != null)
pClient.Send(watch);
}
public void LeaveWatch(GameState client)
{
var epk = ElitePKTournament.Tournaments[GroupID];
client.WatchingElitePKMatch = null;
Watchers.Remove(client.Entity.UID);
try
{
ElitePKWatch watch = new ElitePKWatch(true);
watch.ID = ID;
watch.Type = ElitePKWatch.Leave;
client.Send(watch);
if (!epk.Players.ContainsKey(client.Entity.UID))
client.Entity.PreviousTeleport();
else
{
var map = epk.WaitingArea;
var coords = map.RandomCoordinates();
client.Entity.Teleport(map.ID, coords.Item1, coords.Item2);
}
}
catch
{
var map = epk.WaitingArea;
var coords = map.RandomCoordinates();
client.Entity.Teleport(map.ID, coords.Item1, coords.Item2);
}
}
public void Cheer(GameState client, uint fighter)
{
Players.First(p => p != null && p.Entity.UID == fighter)
.ElitePKStats.Cheers++;
UpdateWatchers();
}
public GameState Return(Func<FighterStats, bool> fn)
{
foreach (var stat in MatchStats)
if (stat != null)
if (fn(stat))
return ElitePKTournament.Tournaments[GroupID].Players[stat.UID];
return null;
}
public void Check()
{
if (Exported) return;
foreach (var player in Players)
{
if (!player.ElitePKStats.Lost && !player.ElitePKStats.Waiting)
{
if (player.Entity.MapID != Map.ID)
{
End(player);
}
}
}
}
}
public void SignUp(GameState client)
{
var coords = WaitingArea.RandomCoordinates();
client.Entity.Teleport(WaitingArea.ID, coords.Item1, coords.Item2);
Players.Add(client.Entity.UID, client);
ElitePKMatchUI ui = new ElitePKMatchUI(true);
ui.Type = ElitePKMatchUI.Information;
ui.Append(client);
ui.Send(client);
client.SignedUpForEPK = true;
client.OnDisconnect = p =>
{
if (p.ElitePKStats.Fighting)
p.ElitePKMatch.End(p);
p.Entity.Teleport(1002, 313, 289);
};
}
public void SubscribeTimer()
{
Organization = true;
if (Subscriber == null)
Subscriber = World.Subscribe(timerCallback, 1000);
}
public void Purge()
{
foreach (var Player in Players.Values)
{
if (Players.Count > 8)
{
if (Player.ElitePKStats.Lost)
{
Players.Remove(Player.Entity.UID);
}
}
}
}
public static List<AI> Ais = new List<AI>();
public bool Organization = false;
private void timerCallback(int time)
{
try
{
DateTime Now64 = DateTime.Now;
if (State == States.GUI_ReconstructTop)
{
if (Now64.AddMinutes(1) > ConstructTop8)
{
Program.Vars["epk_" + GroupID + "_edt"] = EndDateTime = DateTime.Now;
State = States.GUI_Top8Ranking;
var brackets = CreateBrackets(new Match[0], 0, ElitePKBrackets.RequestInformation);
Kernel.SendWorldMessage(brackets);
Kernel.SendWorldMessage(new ElitePKBrackets(true)
{
Group = (ushort)GroupID,
Type = 6,
OnGoing = false
});
EliteStarted = false;
Subscriber.Dispose();
}
return;
}
//#warning EPK AT 20 not
if (Now64.Hour == (EventTime + 1) && Now64.Minute >= (3 - GroupID) * 2)
{
EliteStarted = true;
#region GetState
if (Organization)
{
foreach (var players in Players.Values)
Top8 = new FighterStats[8];
for (int i = 0; i < 8; i++)
Top8[i] = new FighterStats(0, "", 0);
Organization = false;
}
if (State == States.GUI_Top8Ranking)
{
willAdvance = Players.Count > 8;
if (Players.Count == 0)
{
Program.Vars["epk_" + GroupID + "_edt"] = EndDateTime = DateTime.Now;
State = States.GUI_Top8Ranking;
Kernel.SendWorldMessage(new ElitePKBrackets(true)
{
Group = (ushort)GroupID,
Type = 6,
OnGoing = false
});
EliteStarted = false;
Subscriber.Dispose();
return;
}
else if (Players.Count == 1)
{
Top8[0] = Players.Values.FirstOrDefault().ElitePKStats;
foreach (var player in Players.Values)
player.Entity.Teleport();
SaveTop8();
ConstructTop8 = DateTime.Now;
State = States.GUI_ReconstructTop;
foreach (var client in Program.GamePool) Rankings(client);
var brackets = CreateBrackets(ExtendedMatchArray, 0, ElitePKBrackets.UpdateList);
Kernel.SendWorldMessage(brackets);
Kernel.SendWorldMessage(new ElitePKBrackets(true)
{
Group = (ushort)GroupID,
Type = 6,
OnGoing = true
});
}
else if (Players.Count == 2)
{
State = States.GUI_Top1;
pState = States.T_Organize;
}
else if (Players.Count > 2 && Players.Count <= 4)
{
State = States.GUI_Top2Qualifier;
pState = States.T_Organize;
}
else if (Players.Count > 4 && Players.Count <= 8)
{
State = States.GUI_Top4Qualifier;
pState = States.T_Organize;
}
else if (willAdvance && Players.Count <= 24)
State = States.GUI_Top8Qualifier;
else if (Players.Count > 24)
State = States.GUI_Knockout;
}
#endregion
#region Knockout
if (State == States.GUI_Knockout)
{
if (pState == States.T_Organize)
{
if (willAdvance && Players.Count <= 24)
{
State = States.GUI_Top8Qualifier;
}
else
{
MatchIndex = 0;
var array = Players.Values.ToArray();
try
{
foreach (var player in array)
{
player["epk_id"] = GroupID;
player["epk_prize"] = false;
}
}
catch (Exception exception)
{
Console.WriteLine(exception); Program.SaveException(exception);
}
ushort counter = 0;
if (array.Length % 2 == 0)
{
for (ushort x = 0; x < array.Length; x++)
{
int r = counter;
counter++;
int t = counter;
counter++;
if (counter <= array.Length)
{
Match match = new Match(array[r], array[t]);
match.Index = MatchIndex++;
match.ID = MatchCounter.Next;
Matches.Add(match.ID, match);
}
}
}
else
{
for (ushort x = 0; x < array.Length - 1; x++)
{
int r = counter;
counter++;
int t = counter;
counter++;
if (counter <= array.Length)
{
Match match = new Match(array[r], array[t]);
match.Index = MatchIndex++;
match.ID = MatchCounter.Next;
Matches.Add(match.ID, match);
}
}
Match match_single = new Match(array[array.Length - 1]);
match_single.Index = MatchIndex++;
match_single.ID = MatchCounter.Next;
Matches.Add(match_single.ID, match_single);
}
pStamp = Time32.Now.AddSeconds(60);
pState = States.T_Wait;
SentNoWagers = false;
MatchArray = Matches.Values.OrderByDescending(p => p.Players.Length).ToArray();
var brackets = CreateBrackets(MatchArray, 0);
Kernel.SendWorldMessage(brackets);
Kernel.SendWorldMessage(new ElitePKBrackets(true) { Group = (ushort)GroupID, Type = 6, OnGoing = true });
}
}
else if (pState == States.T_Wait)
{
if (TimeLeft == 0)
{
int doneMatches = 0;
SendNoWagers();
foreach (var match in MatchArray)
{
if (!match.Completed)
{
if (!match.Inside)
{
match.Import(Match.StatusFlag.InFight);
}
else
{
match.Check();
if (!match.Exported && (match.Done || match.TimeLeft == 0))
match.Export();
if (match.Exported)
doneMatches++;
foreach (var stats in match.MatchStats)
if (stats.Winner && match.Imports == 2)
stats.Flag = FighterStats.StatusFlag.Qualified;
}
}
else
doneMatches++;
}
if (doneMatches == Matches.Count)
{
foreach (var match in Matches.Values)
foreach (var stats in match.MatchStats)
if (stats != null)
if (stats.Flag != FighterStats.StatusFlag.Qualified)
Remove(stats.UID);
Matches.Clear();
pState = States.T_Organize;
}
}
}
}
#endregion
#region Top8Qualifier
if (State == States.GUI_Top8Qualifier)
{
if (pState == States.T_Organize)
{
if (Players.Count == 8)
{
State = States.GUI_Top4Qualifier;
}
else
{
var Brackets = CreateBrackets(MatchArray, 0, ElitePKBrackets.GUIEdit);
MatchIndex = 0;
var array = Players.Values.ToArray();
int[] taken = new int[array.Length];
if (array.Length <= 14)
{
ushort counter = 0;
int t1Group = array.Length - 8;
int lim = taken.Length / 2;
int len = array.Length;
for (int i = 0; i < t1Group; i++)
{
int r = counter++;
int t = counter++;
Match match = new Match(array[r], array[t]);
match.Index = MatchIndex++;
match.ID = MatchCounter.Next;
Matches.TryAdd(match.ID, match);
}
for (int i = 0; i < 8 - t1Group; i++)
{
ushort r = counter++;
Match match = new Match(array[r]);
match.Index = MatchIndex++;
match.ID = MatchCounter.Next;
Matches.TryAdd(match.ID, match);
}
}
else
{
ushort counter = 0;
int t3GroupCount = array.Length - 16;
for (int i = 0; i < t3GroupCount; i++)
{
int r = counter++;
int t = counter++;
int y = counter++;
Match match = new Match(array[r], array[t], array[y]);
match.Index = MatchIndex++;
match.ID = MatchCounter.Next;
Matches.TryAdd(match.ID, match);
}
int t2GroupCount = array.Length - counter;
for (int i = 0; i < t2GroupCount / 2; i++)
{
int r = counter++;
int t = counter++;
Match match = new Match(array[r], array[t]);
match.Index = MatchIndex++;
match.ID = MatchCounter.Next;
Matches.TryAdd(match.ID, match);
}
}
pStamp = Time32.Now.AddSeconds(60);
pState = States.T_Wait;
SentNoWagers = false;
MatchArray = Matches.Values.OrderByDescending(p => p.Players.Length).ToArray();
Brackets = CreateBrackets(MatchArray, 0, ElitePKBrackets.UpdateList);
Kernel.SendWorldMessage(Brackets);
ElitePKBrackets brackets = new ElitePKBrackets(true);
brackets.Type = ElitePKBrackets.EPK_State;
brackets.OnGoing = true;
Kernel.SendWorldMessage(brackets);
}
}
else if (pState == States.T_Wait)
{
if (TimeLeft == 0)
{
int doneMatches = 0;
SendNoWagers();
foreach (var match in MatchArray)
{
if (!match.Completed)
{
if (!match.Inside)
{
if (match.MatchStats.Length > 1)
{
match.Import(Match.StatusFlag.InFight);
}
else
{
match.Inside = true;
match.Completed = true;
match.Done = true;
match.Flag = Match.StatusFlag.OK;
match.MatchStats
.First(p => p != null).Flag
= FighterStats.StatusFlag.Qualified;
}
}
else
{
match.Check();
if (!match.Exported && (match.Done || match.TimeLeft == 0))
{
match.Export();
match.Flag = Match.StatusFlag.OK;
if (match.Players.Length == 3)
{
match.SwitchBetween();
var stat = match.MatchStats.Where(p => p.Lost).ToArray();
foreach (var tea in stat)
Remove(tea.UID);
}
else
{
var stat = match.MatchStats.Where(p => p.Lost).ToArray();
foreach (var tea in stat)
Remove(tea.UID);
match.Flag = Match.StatusFlag.OK;
}
}
if (match.Exported)
doneMatches++;
}
}
else
{
doneMatches++;
}
}
if (doneMatches == Matches.Count)
{
bool finishedRound = true;
foreach (var match in MatchArray)
{
if (!match.Completed)
{
finishedRound = false;
}
}
if (!finishedRound)
{
foreach (var match in MatchArray)
{
if (!match.Completed)
{
foreach (var stats in match.MatchStats)
{
stats.Reset(false);
}
match.Inside = false;
match.Done = false;
match.Exported = false;
match.Flag = Match.StatusFlag.SwitchOut;
}
}
pStamp = Time32.Now.AddSeconds(60);
pState = States.T_Wait;
SentNoWagers = false;
// Kernel.SendWorldMessage(CreateBrackets(MatchArray, 0 ,ElitePKBrackets.GUIEdit));
Kernel.SendWorldMessage(CreateBrackets(MatchArray, 0, ElitePKBrackets.RequestInformation));
}
else
{
Matches.Clear();
Purge();
pState = States.T_Organize;
}
}
}
}
}
#endregion
#region Top4Qualifier
if (State == States.GUI_Top4Qualifier)
{
if (pState == States.T_Organize)
{
MatchIndex = 0;
var array = Players.Values.ToArray();
foreach (var player in array)
{
player["epk_prize"] = true;
}
int[] taken = new int[array.Length];
int lim = taken.Length / 2;
for (int i = 0; i < taken.Length; i += 2)
{
if (array.Length > i + 1)
{
Match match = new Match(array[i], array[i + 1]);
match.Index = MatchIndex++;
//match.Flag = Match.StatusFlag.FinalMatch;
match.ID = MatchCounter.Next;
Matches.TryAdd(match.ID, match);
}
else
{
Match match = new Match(array[i]);
match.Index = MatchIndex++;
//match.Flag = Match.StatusFlag.FinalMatch;
match.ID = MatchCounter.Next;
Matches.TryAdd(match.ID, match);
}
}
pStamp = Time32.Now.AddSeconds(60);
pState = States.T_Wait;
SentNoWagers = false;
MatchArray = Matches.Values.ToArray();
var brackets = CreateBrackets(MatchArray, 0, ElitePKBrackets.GUIEdit);
Kernel.SendWorldMessage(brackets);
var bracket = CreateBrackets(MatchArray, 0, ElitePKBrackets.UpdateList);
Kernel.SendWorldMessage(bracket);
Kernel.SendWorldMessage(new ElitePKBrackets(true)
{
Group = (ushort)GroupID,
Type = 6,
OnGoing = true
});
}
else if (pState == States.T_Wait)
{
if (TimeLeft == 0)
{
SendNoWagers();
int doneMatches = 0;
foreach (var match in MatchArray)
{
if (!match.Completed)
{
if (!match.Inside)
{
match.Import(Match.StatusFlag.Watchable);
}
else
{
match.Check();
if (!match.Exported && (match.Done || match.TimeLeft == 0))
match.Export();
if (match.Exported)
doneMatches++;
}
}
else
doneMatches++;
}
if (doneMatches == MatchArray.Length)
{
int i = 4;
foreach (var match in MatchArray)
{
foreach (var stats in match.MatchStats)
if (stats.Flag == FighterStats.StatusFlag.Lost)
Top8[Math.Min(7, i++)] = stats.Clone();
match.Commit();
}
foreach (var list in Players.Values)
if (list.ElitePKStats.Lost)
{
Remove(list.Entity.UID);
}
State = States.GUI_Top8Ranking;
}
}
}
}
#endregion
#region Top2Qualifier
if (State == States.GUI_Top2Qualifier)
{
if (pState == States.T_Organize)
{
MatchIndex = 0;
Top4MatchArray = new Match[2];
if (MatchArray == null || MatchArray.Length == 0)
{
var array = Players.Values.ToArray();
int[] taken = new int[array.Length];
int mac = 0;
for (int i = 0; i < taken.Length; i += 2)
{
if (array.Length > i + 1)
{
Match match = new Match(array[i], array[i + 1]);
match.Index = MatchIndex++;
match.ID = MatchCounter.Next;
Top4MatchArray[mac++] = match;
Matches.TryAdd(match.ID, match);
}
else
{
Match match = new Match(array[i]);
match.Index = MatchIndex++;
match.ID = MatchCounter.Next;
Top4MatchArray[mac++] = match;
Matches.TryAdd(match.ID, match);
}
}
MatchArray = Matches.Values.ToArray();
}
else
{
for (int i = 0; i < Top4MatchArray.Length; i++)
{
if (MatchArray.Length > i + 2)
{
foreach (var players in Players.Values)
{
}
Match match = new Match(
MatchArray[i].Return(p => p.Winner),
MatchArray[i + 2].Return(p => p.Winner));
match.Index = MatchIndex++;
match.ID = MatchCounter.Next;
Top4MatchArray[i] = match;
Matches.TryAdd(match.ID, match);
}
else
{
Match match = null;
match = new Match(//p.winer este
MatchArray[i].Return(p => p.Winner));//.MatchStats.First(p => p.Team.SkillFighterStats.Winner));
match.Index = MatchIndex++;
match.ID = MatchCounter.Next;
Top4MatchArray[i] = match;
Matches.TryAdd(match.ID, match);
}
}
}
pStamp = Time32.Now.AddSeconds(60);
pState = States.T_Wait;
SentNoWagers = false;
var brackets = CreateBrackets(MatchArray, 0, ElitePKBrackets.GUIEdit);
Kernel.SendWorldMessage(brackets);
brackets = CreateBrackets(Top4MatchArray, 0, ElitePKBrackets.UpdateList);
Kernel.SendWorldMessage(brackets);
Kernel.SendWorldMessage(new ElitePKBrackets(true)
{
Group = (ushort)GroupID,
Type = 6,
OnGoing = true
});
}
else if (pState == States.T_Wait)
{
if (TimeLeft == 0)
{
SendNoWagers();
int doneMatches = 0;
foreach (var match in Top4MatchArray)
{
if (!match.Completed)
{
if (!match.Inside)
{
match.Import();
}
else
{
match.Check();
if (!match.Exported && (match.Done || match.TimeLeft == 0))
match.Export();
if (match.Exported)
doneMatches++;
}
}
else
doneMatches++;
}
if (doneMatches == Top4MatchArray.Length)
{
List<GameState> list = new List<GameState>();
foreach (var player in Players.Values)
if (player.ElitePKStats.Lost)
list.Add(player);
foreach (var match in Top4MatchArray)
match.Commit();
if (list.Count == 1)
{
foreach (GameState current in list)
{
Remove(current.Entity.UID);
this.Top8[2] = current.ElitePKStats;
}
this.State = States.GUI_Top8Ranking;
}
else
{
pState = States.T_Organize;
State = States.GUI_Top3;
}
}
}
}
}
#endregion
#region Top3
if (State == States.GUI_Top3)
{
if (pState == States.T_Organize)
{
MatchIndex = 0;
var brackets = CreateBrackets(MatchArray, 0, ElitePKBrackets.GUIEdit);
Kernel.SendWorldMessage(brackets);
ExtendedMatchArray = new Match[1];
Match match = new Match(
Top4MatchArray[0].Return(p => !p.Winner),
Top4MatchArray[1].Return(p => !p.Winner));
match.Index = MatchIndex++;
match.ID = MatchCounter.Next;
ExtendedMatchArray[0] = match;
Matches.TryAdd(match.ID, match);
pStamp = Time32.Now.AddSeconds(60);
pState = States.T_Wait;
SentNoWagers = false;
var bracket = CreateBrackets(ExtendedMatchArray, 0, ElitePKBrackets.UpdateList);
Kernel.SendWorldMessage(bracket);
Kernel.SendWorldMessage(new ElitePKBrackets(true)
{
Group = (ushort)GroupID,
Type = 6,
OnGoing = true
});
}
else if (pState == States.T_Wait)
{
if (TimeLeft == 0)
{
SendNoWagers();
int doneMatches = 0;
var match = ExtendedMatchArray[0];
{
if (!match.Completed)
{
if (!match.Inside)
{
match.Import();
}
else
{
match.Check();
if (!match.Exported && (match.Done || match.TimeLeft == 0))
match.Export();
if (match.Exported)
doneMatches++;
}
}
else
doneMatches++;
}
if (doneMatches == ExtendedMatchArray.Length)
{
var top3 = ExtendedMatchArray[0].Players
.First(p => p.ElitePKStats.Winner);
var top4 = ExtendedMatchArray[0].Players
.First(p => !p.ElitePKStats.Winner);
Top8[2] = top3.ElitePKStats.Clone();
Top8[3] = top4.ElitePKStats.Clone();
top3.Entity.Teleport();
top4.Entity.Teleport();
Remove(top3.Entity.UID);
Remove(top4.Entity.UID);
pState = States.T_Organize;
State = States.GUI_Top8Ranking;
}
}
}
}
#endregion
#region Top1
if (State == States.GUI_Top1)
{
if (pState == States.T_Organize)
{
MatchIndex = 0;
ExtendedMatchArray = new Match[1];
Match match = new Match(Players.Values.First(), Players.Values.Last());
match.Index = MatchIndex++;
match.ID = MatchCounter.Next;
ExtendedMatchArray[0] = match;
Matches.TryAdd(match.ID, match);
pStamp = Time32.Now.AddSeconds(60);
pState = States.T_Wait;
SentNoWagers = false;
if (MatchArray != null)
{
var brackets = CreateBrackets(MatchArray, 0, ElitePKBrackets.GUIEdit);
Kernel.SendWorldMessage(brackets);
}
if (Top4MatchArray != null)
{
// Kernel.SendWorldMessage(CreateBrackets(Top4MatchArray, 0, ElitePKBrackets.UpdateList));
}
Kernel.SendWorldMessage(CreateBrackets(ExtendedMatchArray, 0, ElitePKBrackets.UpdateList));
Kernel.SendWorldMessage(new ElitePKBrackets(true)
{
Group = (ushort)GroupID,
Type = 6,
OnGoing = true
});
}
else if (pState == States.T_Wait)
{
if (TimeLeft == 0)
{
SendNoWagers();
int doneMatches = 0;
foreach (var match in ExtendedMatchArray)
{
if (!match.Inside)
{
match.Import();
}
else
{
match.Check();
if (!match.Exported && (match.Done || match.TimeLeft == 0))
match.Export();
if (match.Exported)
doneMatches++;
}
}
if (doneMatches == ExtendedMatchArray.Length)
{
var top1 = ExtendedMatchArray[0].Players
.First(p => p.ElitePKStats.Winner).ElitePKStats;
var top2 = ExtendedMatchArray[0].Players
.First(p => !p.ElitePKStats.Winner).ElitePKStats;
Top8[0] = top1.Clone();
Top8[1] = top2.Clone();
ConstructTop8 = DateTime.Now;
foreach (var ai in Ais)
ai.Bot = null;
foreach (var player in Players.Values)
player.Entity.Teleport();
SaveTop8();
EliteStarted = false;
State = States.GUI_ReconstructTop;
foreach (var client in Program.GamePool) Rankings(client);
var brackets = CreateBrackets(ExtendedMatchArray, 0, ElitePKBrackets.UpdateList);
Kernel.SendWorldMessage(brackets);
Kernel.SendWorldMessage(new ElitePKBrackets(true)
{
Group = (ushort)GroupID,
Type = 6,
OnGoing = true
});
foreach (var player in Players.Values)
Remove(player.Entity.UID);
}
}
}
}
#endregion
}
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
}
private void SendNoWagers()
{
if (!SentNoWagers)
{
SentNoWagers = true;
ElitePKBrackets noWagers = new ElitePKBrackets(true);
noWagers.Group = (ushort)GroupID;
noWagers.GUIType = (ushort)State;
noWagers.Type = ElitePKBrackets.StopWagers;
Kernel.SendWorldMessage(noWagers);
}
}
private ElitePKBrackets CreateBrackets(Match[] matches, int page = 0, byte type = 0)
{
int lim = 0, count = 0;
if (matches == null) return new ElitePKBrackets(true);
if (State == States.GUI_Knockout)
{
if (page > matches.Length / 5) page = 0;
lim = 5;
}
else lim = matches.Length;
count = Math.Min(lim, matches.Length - page * lim);
ElitePKBrackets brackets = new ElitePKBrackets(true, count);
brackets.Group = (ushort)GroupID;
brackets.GUIType = (ushort)State;
brackets.TotalMatches = (ushort)count;
brackets.Page = (byte)page;
brackets.TimeLeft = TimeLeft;
if (type == States.GUI_Top2Qualifier)
brackets.MatchCount = 2;
else
brackets.MatchCount = (ushort)matches.Length;
brackets.Type = type;
for (int i = page * lim; i < page * lim + count; i++)
brackets.Append(matches[i]);
return brackets;
}
private void Remove(uint uid)
{
if (!Players.ContainsKey(uid))
return;
if (MaTrix.AI.Ais.ContainsKey(uid))
{
Players[uid].RemoveScreenSpawn(Players[uid].Entity, false);
MaTrix.AI.Ais.Remove(uid);
Players.Remove(uid);
return;
}
Players[uid].Entity.Teleport();
Players.Remove(uid);
}
public ushort TimeLeft
{
get
{
int value = (int)((pStamp.TotalMilliseconds - Time32.Now.TotalMilliseconds) / 1000);
if (value < 0) return 0;
return (ushort)value;
}
}
public void Update(GameState client, int page = 0)
{
try
{
if (State == States.GUI_Top8Ranking)
{
Rankings(client);
}
else
{
if (State >= States.GUI_Top4Qualifier)
{
var brackets = CreateBrackets(MatchArray, 0, ElitePKBrackets.GUIEdit);
client.Send(brackets);
if (ExtendedMatchArray != null)
{
brackets = CreateBrackets(ExtendedMatchArray, 0, ElitePKBrackets.UpdateList);
client.Send(brackets);
foreach (var match in ExtendedMatchArray)
match.Send(client, State);
}
else if (Top4MatchArray != null)
{
brackets = CreateBrackets(Top4MatchArray, 0, ElitePKBrackets.UpdateList);
client.Send(brackets);
foreach (var match in Top4MatchArray)
match.Send(client, State);
}
else
{
brackets = CreateBrackets(MatchArray, 0, ElitePKBrackets.UpdateList);
client.Send(brackets);
foreach (var match in MatchArray)
{
if (match.Inside && !match.Done)
match.Flag = Match.StatusFlag.Watchable;
match.Send(client, State);
}
}
}
else
{
var brackets = CreateBrackets(MatchArray, page);
client.Send(brackets);
}
if (State >= States.GUI_Top1)
Rankings(client);
}
}
catch (Exception e) { Console.WriteLine(e.ToString()); }
}
public void Rankings(GameState client)
{
ElitePKRanking ranks = new ElitePKRanking(true);
ranks.Type = ElitePKRanking.Top8;
ranks.Group = (uint)GroupID;
ranks.GroupStatus = (uint)State;
ranks.UID = client.Entity.UID;
if (State >= States.GUI_Top1)
{
ranks.Type = ElitePKRanking.Top3;
if (State == States.GUI_Top1)
{
ranks.Count = 1;
ranks.Append(Top8[2], 3);
}
else
{
ranks.Count = 3;
for (int i = 0; i < 3; i++)
ranks.Append(Top8[i], i + 1);
}
client.Send(ranks);
}
else
{
ranks.Count = (uint)Top8.Length;
for (int i = 0; i < ranks.Count; i++)
if (Top8[i] != null)
ranks.Append(Top8[i], i);
client.Send(ranks);
}
}
}
}
public unsafe class ElitePKBrackets
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using XMeGo.Game;
using XMeGo.Client;
namespace XMeGo.Network.GamePackets
{
public unsafe class ElitePKBrackets : Writer, Interfaces.IPacket
{
public const byte
InitialList = 0,
StaticUpdate = 1,
GUIEdit = 2,
UpdateList = 3,
RequestInformation = 4,
StopWagers = 5,
EPK_State = 6;
private byte[] Buffer;
public ElitePKBrackets(bool create, int matches = 0)
{
if (create)
{
Buffer = new byte[124 + 112 * matches + 8];
WriteUInt16((ushort)(Buffer.Length - 8), 0, Buffer);
WriteUInt16(2219, 2, Buffer);
}
}
public byte Type
{
get { return Buffer[4]; }
set { Buffer[4] = value; }
}
public byte Page
{
get { return Buffer[6]; }
set { Buffer[6] = value; }
}
public byte Unknown
{
get { return Buffer[8]; }
set { Buffer[8] = value; }
}
public uint MatchCount
{
get { return BitConverter.ToUInt32(Buffer, 10); }
set { WriteUInt32(value, 10, Buffer); }
}
public ushort Group
{
get { return BitConverter.ToUInt16(Buffer, 14); }
set { WriteUInt16(value, 14, Buffer); }
}
public ushort GUIType
{
get { return BitConverter.ToUInt16(Buffer, 16); }
set { WriteUInt16(value, 16, Buffer); }
}
public ushort TimeLeft
{
get { return BitConverter.ToUInt16(Buffer, 18); }
set { WriteUInt16(value, 18, Buffer); }
}
public uint TotalMatches
{
get { return BitConverter.ToUInt16(Buffer, 20); }
set { WriteUInt32(value, 20, Buffer); }
}
public bool OnGoing
{
get { return Buffer[20] == 1; }
set { WriteBoolean(value, 20, Buffer); }
}
private int offset = 24;
public void Append(ElitePK.Match match)
{
if (match == null)
{
return;
}
if (Type != GUIEdit)
WriteUInt32(match.ID, offset, Buffer);
offset += 4;
WriteUInt16((ushort)match.Players.Length, offset, Buffer);
offset += 2;
WriteUInt16((ushort)match.Index, offset, Buffer);
offset += 2;
WriteUInt16((ushort)match.Flag, offset, Buffer);
offset += 2;
for (int i = 0; i < match.Players.Length; i++)
{
AppendPlayer(match.MatchStats[i], offset);
offset += 34;
}
if (match.Players.Length == 2) offset += 34;
if (match.Players.Length == 1) offset += 68;
// if (match.Players.Length == 0) offset += 102;
}
private void AppendPlayer(ElitePK.FighterStats stats, int _offset)
{
WriteUInt32(stats.UID, _offset, Buffer);
_offset += 4;
WriteUInt32(stats.Mesh, _offset, Buffer);
_offset += 4;
WriteString(stats.Name, _offset, Buffer);
_offset += 16;
WriteInt32(0, _offset, Buffer);
_offset += 4;
WriteInt32((int)stats.Flag, _offset, Buffer);
_offset += 4;
WriteInt32(stats.Advance ? 1 : 0, _offset, Buffer);
}
public void Send(GameState client)
{
client.Send(Buffer);
}
public byte[] ToArray()
{
return Buffer;
}
public void Deserialize(byte[] buffer)
{
Buffer = buffer;
}
}
}
public unsafe class ElitePKMatchU
// Project by Avalanche
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using XMeGo.Client;
namespace XMeGo.Network.GamePackets
{
public unsafe class ElitePKMatchUI : Writer, Interfaces.IPacket
{
public const byte
Information = 1,
BeginMatch = 2,
Effect = 3,
EndMatch = 4;
public const uint
Effect_Win = 1,
Effect_Lose = 0;
byte[] Buffer;
public ElitePKMatchUI(bool create)
{
if (create)
{
Buffer = new byte[52 + 8];
WriteUInt16(52, 0, Buffer);
WriteUInt16(2218, 2, Buffer);
}
}
public uint Type
{
get { return BitConverter.ToUInt32(Buffer, 4); }
set { WriteUInt32(value, 4, Buffer); }
}
public uint dwParam
{
get { return BitConverter.ToUInt32(Buffer, 8); }
set { WriteUInt32(value, 8, Buffer); }
}
public uint OpponentUID
{
get { return BitConverter.ToUInt32(Buffer, 12); }
set { WriteUInt32(value, 12, Buffer); }
}
public string OpponentName
{
get { return Encoding.Default.GetString(Buffer, 20, 16).Trim(); }
set { WriteString(value, 20, Buffer); }
}
public uint TimeLeft
{
get { return BitConverter.ToUInt32(Buffer, 48); }
set { WriteUInt32(value, 48, Buffer); }
}
public void Append(GameState opponent)
{
OpponentUID = opponent.Entity.UID;
OpponentName = opponent.Entity.Name;
}
public void Send(GameState client)
{
client.Send(Buffer);
}
public byte[] ToArray()
{
return Buffer;
}
public void Deserialize(byte[] buffer)
{
Buffer = buffer;
}
}
}
public unsafe class ElitePKMatchStats
// Project by Avalanche
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using XMeGo.Client;
using XMeGo.Game;
namespace XMeGo.Network.GamePackets
{
public unsafe class ElitePKMatchStats : Writer, Interfaces.IPacket
{
byte[] Buffer;
public ElitePKMatchStats()
{
Buffer = new byte[64 + 8];
WriteUInt16(64, 0, Buffer);
WriteUInt16(2222, 2, Buffer);
}
public void Append(ElitePK.Match match)
{
int offset = 4;
var array = match.FightersStats;
if (array.Length >= 2)
{
AppendPlayer(array[0], offset);
offset += 28;
AppendPlayer(array[1], offset);
}
}
private void AppendPlayer(ElitePK.FighterStats player, int offset)
{
WriteUInt32(player.UID, offset, Buffer); offset += 4;
WriteString(player.Name, offset, Buffer); offset += 16;
WriteUInt32(0, offset, Buffer); offset += 4;
WriteUInt32(player.Points, offset, Buffer); offset += 4;
}
public void Send(GameState client)
{
client.Send(Buffer);
}
public byte[] ToArray()
{
return Buffer;
}
public void Deserialize(byte[] buffer)
{
Buffer = buffer;
}
}
}
public unsafe class ElitePKRanking
// Project by Avalanche
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using XMeGo.Game;
namespace XMeGo.Network.GamePackets
{
public unsafe class ElitePKRanking : Writer, Interfaces.IPacket
{
public const byte Top8 = 0, Top3 = 2;
private byte[] buffer;
public ElitePKRanking(bool create)
{
if (create)
{
buffer = new byte[420 + 8];
WriteUInt16(420, 0, buffer);
WriteUInt16(2223, 2, buffer);
}
}
public uint Type
{
get { return BitConverter.ToUInt32(buffer, 4); }
set { WriteUInt32(value, 4, buffer); }
}
public uint Group
{
get { return BitConverter.ToUInt32(buffer, 8); }
set { WriteUInt32(value, 8, buffer); }
}
public uint GroupStatus
{
get { return BitConverter.ToUInt32(buffer, 12); }
set { WriteUInt32(value, 12, buffer); }
}
public uint Count
{
get { return BitConverter.ToUInt32(buffer, 16); }
set { WriteUInt32(value, 16, buffer); }
}
public uint UID
{
get { return BitConverter.ToUInt32(buffer, 20); }
set { WriteUInt32(value, 20, buffer); }
}
private int Index = 0;
public void Append(ElitePK.FighterStats stats, int rank)
{
if (stats == null)
return;
int offset = 36 + Index * 44; Index++;
WriteInt32(rank, offset, buffer); offset += 4;
WriteString(stats.Name, offset, buffer); offset += 16;
WriteUInt32(stats.Mesh, offset, buffer); offset += 4;
WriteUInt32(0, offset, buffer); offset += 4;
WriteUInt32(0, offset, buffer); offset += 4;
WriteUInt32(stats.UID, offset, buffer);
}
public byte[] ToArray()
{
return buffer;
}
public void Send(Client.GameState client)
{
client.Send(ToArray());
}
public void Deserialize(byte[] buffer)
{
this.buffer = buffer;
}
}
}
public class ElitePKTournament
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using XMeGo.Client;
using XMeGo.Network.GamePackets;
namespace XMeGo.Game
{
public class ElitePKTournament
{
public const byte
EPK_Lvl100Minus = 0,
EPK_Lvl100To119 = 1,
EPK_Lvl120To129 = 2,
EPK_Lvl130Plus = 3;
public class top_typ
{
public const byte Elite_PK_Champion__Low_ = 12,
Elite_PK_2nd_Place_Low_ = 13,
Elite_PK_3rd_Place_Low_ = 14,
Elite_PK_Top_8__Low_ = 15,
Elite_PK_Champion_High_ = 16,
Elite_PK_2nd_Place_High_ = 17,
Elite_PK_3rd_Place__High_ = 18,
Elite_PK_Top_8_High_ = 19;
}
public enum GroupTyp : ushort
{
EPK_Lvl100Minus = 0,
EPK_Lvl100To119 = 1,
EPK_Lvl120To129 = 2,
EPK_Lvl130Plus = 3,
Count = 4
}
public static void ReceiceTitle(ElitePK tournament, byte Rank, Client.GameState client)
{
if (tournament.GroupID == (int)GroupTyp.EPK_Lvl130Plus)
{
if (Rank == 1) client.Entity.AddTopStatus((ulong)XMeGo.Network.GamePackets.TitlePacket.Titles.ElitePKChamption_High, 0, DateTime.Now.AddDays(1), true);
else if (Rank == 2) client.Entity.AddTopStatus((ulong)XMeGo.Network.GamePackets.TitlePacket.Titles.ElitePK2ndPlace_High, 0, DateTime.Now.AddDays(1), true);
else if (Rank == 3) client.Entity.AddTopStatus((ulong)XMeGo.Network.GamePackets.TitlePacket.Titles.ElitePK3ndPlace_High, 0, DateTime.Now.AddDays(1), true);
else client.Entity.AddTopStatus((ulong)XMeGo.Network.GamePackets.TitlePacket.Titles.ElitePK3ndPlace_Low, 0, DateTime.Now.AddDays(1), true);
}
else
{
if (Rank == 1) client.Entity.AddTopStatus((ulong)XMeGo.Network.GamePackets.TitlePacket.Titles.ElitePKChamption_Low, 0, DateTime.Now.AddDays(1), true);
else if (Rank == 2) client.Entity.AddTopStatus((ulong)XMeGo.Network.GamePackets.TitlePacket.Titles.ElitePK2ndPlace_Low, 0, DateTime.Now.AddDays(1), true);
else if (Rank == 3) client.Entity.AddTopStatus((ulong)XMeGo.Network.GamePackets.TitlePacket.Titles.ElitePK3ndPlace_Low, 0, DateTime.Now.AddDays(1), true);
else client.Entity.AddTopStatus((ulong)XMeGo.Network.GamePackets.TitlePacket.Titles.ElitePK3ndPlace_Low, 0, DateTime.Now.AddDays(1), true);
}
}
public static bool GetReward(Client.GameState client)
{
foreach (var tournament in ElitePKTournament.Tournaments)
{
byte Rank = 0;
if (!client.Inventory.HaveSpace(1))
{
client.MessageBox("Please Empty Some Space", null, null);
return false;
}
if (tournament.GetReward(client, out Rank))
{
if (tournament.GroupID == (int)GroupTyp.EPK_Lvl130Plus && Rank == 1)
{
new TitleStorage().AddTitle(client, 6001, 20, false);
}
tournament.SaveTop8();
ReceiceTitle(tournament, Rank, client);
uint ItemID = GetItemID(tournament, Rank);
Database.ConquerItemBaseInformation DBItem;
if (Database.ConquerItemInformation.BaseInformations.TryGetValue(ItemID, out DBItem))
{
if (client.Inventory.HaveSpace(1))
client.Inventory.Add(ItemID, 0, 1);
}
if (tournament.GroupID == (int)GroupTyp.EPK_Lvl130Plus)
{
if (Rank == 1)
{
client.Entity.ConquerPoints += 250000000;
//client.Entity.BoundCps += ServerRates.BoundCpsElitePk1;
client.MessageBox("You've received a " + DBItem.Name + " , [" + 250000000 + "] ConquerPoints wing (WingsofInfernal)");
string MSG = "Congratulation to " + client.Entity.Name + " he/she get rank " + Rank + " on Elite PK Tournament and claimed [" + 250000000 + "] ConquerPoints & wing (WingsofInfernal).";
Kernel.SendWorldMessage(new Message(MSG, System.Drawing.Color.Red, Message.System));
XMeGo.Kernel.SendWorldMessage(new Message("Congratulation to " + client.Entity.Name + " ! he/she managed to get rank " + Rank + " on Elite PK Tournament and claimed [" + 250000000 + "] ConquerPoints & wing (WingsofInfernal).", System.Drawing.Color.Black, Message.Center), Program.Values);
}
else if (Rank == 2)
{
client.Entity.ConquerPoints += 200000000;
//client.Entity.BoundCps += ServerRates.BoundCpsElitePk2;
client.MessageBox("You've received a " + DBItem.Name + " , [" + 200000000 + "] ConquerPoints ");
string MSG = "Congratulation to " + client.Entity.Name + " ! he/she managed to get rank " + Rank + " on Elite PK Tournament and claimed [" + 200000000 + "] ConquerPoints";
Kernel.SendWorldMessage(new Message(MSG, System.Drawing.Color.Red, Message.System));
XMeGo.Kernel.SendWorldMessage(new Message("Congratulation to " + client.Entity.Name + " ! he/she managed to get rank " + Rank + " on Elite PK Tournament and claimed [" + 200000000 + "] ConquerPoints ", System.Drawing.Color.Black, Message.Center), Program.Values);
}
else if (Rank == 3)
{
client.Entity.ConquerPoints += 150000000;
//client.Entity.BoundCps += ServerRates.BoundCpsElitePk3;
client.MessageBox("You've received a " + DBItem.Name + " , [" + 150000000 + "] ConquerPoints");
string MSG = "Congratulation to " + client.Entity.Name + " ! he/she managed to get rank " + Rank + " on Elite PK Tournament and claimed [" + 150000000 + "] ConquerPoints ";
Kernel.SendWorldMessage(new Message(MSG, System.Drawing.Color.Red, Message.System));
XMeGo.Kernel.SendWorldMessage(new Message("Congratulation to " + client.Entity.Name + " ! he/she managed to get rank " + Rank + " on Elite PK Tournament and claimed [" + 150000000 + "] ConquerPoints ", System.Drawing.Color.Black, Message.Center), Program.Values);
}
else
{
client.Entity.ConquerPoints += 100000000;
//client.Entity.BoundCps += ServerRates.BoundCpsElitePkOthe;
client.MessageBox("You've received a " + DBItem.Name + " , [" + 100000000 + "] ConquerPoints ");
string MSG = "Congratulation to " + client.Entity.Name + " ! he/she managed to get rank " + Rank + " on Elite PK Tournament and claimed [" + 100000000 + "] ConquerPoints";
Kernel.SendWorldMessage(new Message(MSG, System.Drawing.Color.Red, Message.System));
XMeGo.Kernel.SendWorldMessage(new Message("Congratulation to " + client.Entity.Name + " ! he/she managed to get rank " + Rank + " on Elite PK Tournament and claimed [" + 100000000 + "] ConquerPoints ", System.Drawing.Color.Black, Message.Center), Program.Values);
Kernel.SendWorldMessage(new Message(MSG, System.Drawing.Color.Red, Message.System));
}
}
return true;
}
}
return false;
}
public static uint GetItemID(ElitePK tournament, byte Rank)
{
return (uint)(720714 + 1 * (byte)tournament.GroupID + Math.Min(3, (Rank - 1)) * 4);
}
public static ElitePK[] Tournaments;
public const ushort WaitingAreaID = 2068;
public static bool TimersRegistered;
public static void Create()
{
Tournaments = new ElitePK[4];
for (int i = 0; i < 4; i++)
Tournaments[i] = new ElitePK(i);
// ElitePK.LoadTop(ElitePKTournament.Tournaments, "ElitePkTop8");
}
//public static void GiveClientReward(Client.GameState client)
//{
// DateTime timer = new DateTime();
// timer = DateTime.Now.AddDays(1);
// bool ReceiveHightRward = false;
// //for (int i = 0; i < EPK_Lvl130Plus+1; i++)
// //{
// // var Tops = Tournaments[i].Top8;
// // if (Tops != null)
// // {
// // for (ushort x = 0; x < Tops.Length; x++)
// // {
// // if (Tops[x] != null)
// // {
// // var obj_client = Tops[x];
// // if (obj_client.UID == client.Entity.UID)
// // {
// // //الاكونت في التوب
// // }
// // }
// // }
// // }
// //}
// var BigRewaurdDictionary = Tournaments[EPK_Lvl130Plus].Top8;
// if (BigRewaurdDictionary != null)
// {
// sbyte client_rank = -1;
// for (ushort x = 0; x < BigRewaurdDictionary.Length; x++)
// {
// if (BigRewaurdDictionary[x] != null)
// {
// var obj_client = BigRewaurdDictionary[x];
// if (obj_client.UID == client.Entity.UID)
// client_rank = (sbyte)x;
// }
// }
// if (client_rank != -1)
// {
// ReceiveHightRward = true;
// if (client_rank == 0)
// {
// if (!client.Entity.Titles.ContainsKey(Network.GamePackets.TitlePacket.Titles.ElitePKChamption_High))
// client.Entity.AddTopStatus((ulong)Network.GamePackets.TitlePacket.Titles.ElitePKChamption_High, timer, true);
// var EliteSecond = Network.GamePackets.TitlePacket.Titles.ElitePK2ndPlace_High;
// var EliteThird = Network.GamePackets.TitlePacket.Titles.ElitePK3ndPlace_High;
// var EliteEight = Network.GamePackets.TitlePacket.Titles.ElitePKChamption_Low;
// if (client.Entity.Titles.ContainsKey(EliteSecond))
// client.Entity.RemoveTopStatus((ulong)EliteSecond);
// if (client.Entity.Titles.ContainsKey(EliteThird))
// client.Entity.RemoveTopStatus((ulong)EliteThird);
// if (client.Entity.Titles.ContainsKey(EliteEight))
// client.Entity.RemoveTopStatus((ulong)EliteEight);
// }
// else if (client_rank == 1)
// {
// if (!client.Entity.Titles.ContainsKey(Network.GamePackets.TitlePacket.Titles.ElitePK2ndPlace_High))
// client.Entity.AddTopStatus((ulong)Network.GamePackets.TitlePacket.Titles.ElitePK2ndPlace_High, timer, true);
// var EliteChampion = Network.GamePackets.TitlePacket.Titles.ElitePKChamption_High;
// var EliteThird = Network.GamePackets.TitlePacket.Titles.ElitePK3ndPlace_High;
// var EliteEight = Network.GamePackets.TitlePacket.Titles.ElitePKChamption_Low;
// if (client.Entity.Titles.ContainsKey(EliteChampion))
// client.Entity.RemoveTopStatus((ulong)EliteChampion);
// if (client.Entity.Titles.ContainsKey(EliteThird))
// client.Entity.RemoveTopStatus((ulong)EliteThird);
// if (client.Entity.Titles.ContainsKey(EliteEight))
// client.Entity.RemoveTopStatus((ulong)EliteEight);
// }
// else if (client_rank == 2)
// {
// if (!client.Entity.Titles.ContainsKey(Network.GamePackets.TitlePacket.Titles.ElitePK3ndPlace_High))
// client.Entity.AddTopStatus((ulong)Network.GamePackets.TitlePacket.Titles.ElitePK3ndPlace_High, timer, true);
// var EliteChampion = Network.GamePackets.TitlePacket.Titles.ElitePKChamption_High;
// var EliteSecond = Network.GamePackets.TitlePacket.Titles.ElitePK2ndPlace_High;
// var EliteEight = Network.GamePackets.TitlePacket.Titles.ElitePKChamption_Low;
// if (client.Entity.Titles.ContainsKey(EliteChampion))
// client.Entity.RemoveTopStatus((ulong)EliteChampion);
// if (client.Entity.Titles.ContainsKey(EliteSecond))
// client.Entity.RemoveTopStatus((ulong)EliteSecond);
// if (client.Entity.Titles.ContainsKey(EliteEight))
// client.Entity.RemoveTopStatus((ulong)EliteEight);
// }
// else
// {
// if (!client.Entity.Titles.ContainsKey(Network.GamePackets.TitlePacket.Titles.ElitePKTopEight_High))
// client.Entity.AddTopStatus((ulong)Network.GamePackets.TitlePacket.Titles.ElitePKTopEight_High, timer, true);
// var EliteChampion = Network.GamePackets.TitlePacket.Titles.ElitePKChamption_High;
// var EliteSecond = Network.GamePackets.TitlePacket.Titles.ElitePK2ndPlace_High;
// var EliteThird = Network.GamePackets.TitlePacket.Titles.ElitePK3ndPlace_High;
// if (client.Entity.Titles.ContainsKey(EliteChampion))
// client.Entity.RemoveTopStatus((ulong)EliteChampion);
// if (client.Entity.Titles.ContainsKey(EliteSecond))
// client.Entity.RemoveTopStatus((ulong)EliteSecond);
// if (client.Entity.Titles.ContainsKey(EliteThird))
// client.Entity.RemoveTopStatus((ulong)EliteThird);
// }
// }
// }
// if (!ReceiveHightRward)
// {
// sbyte client_rank = -1;
// for (byte i = 0; i < EPK_Lvl130Plus; i++)
// {
// var ditionaryLow = Tournaments[i].Top8;
// if (ditionaryLow != null)
// {
// for (byte x = 0; x < ditionaryLow.Length; x++)
// {
// if (ditionaryLow[x] != null)
// {
// var obj = ditionaryLow[x];
// if (obj.UID == client.Entity.UID)
// client_rank = (sbyte)x;
// }
// }
// if (client_rank != -1)
// {
// if (client_rank == 0)
// {
// if (!client.Entity.Titles.ContainsKey(Network.GamePackets.TitlePacket.Titles.ElitePKChamption_Low))
// client.Entity.AddTopStatus((ulong)Network.GamePackets.TitlePacket.Titles.ElitePKChamption_Low, timer, true);
// var EliteEightSecond = Network.GamePackets.TitlePacket.Titles.ElitePK2ndPlace_Low;
// var EliteEightThird = Network.GamePackets.TitlePacket.Titles.ElitePK3ndPlace_Low;
// var EliteEight = Network.GamePackets.TitlePacket.Titles.ElitePKTopEight_Low;
// if (client.Entity.Titles.ContainsKey(EliteEightSecond))
// client.Entity.RemoveTopStatus((ulong)EliteEightSecond);
// if (client.Entity.Titles.ContainsKey(EliteEightThird))
// client.Entity.RemoveTopStatus((ulong)EliteEightThird);
// if (client.Entity.Titles.ContainsKey(EliteEight))
// client.Entity.RemoveTopStatus((ulong)EliteEight);
// }
// else if (client_rank == 1)
// {
// if (!client.Entity.Titles.ContainsKey(Network.GamePackets.TitlePacket.Titles.ElitePK2ndPlace_Low))
// client.Entity.AddTopStatus((ulong)Network.GamePackets.TitlePacket.Titles.ElitePK2ndPlace_Low, timer, true);
// var EliteEightChampion = Network.GamePackets.TitlePacket.Titles.ElitePKChamption_Low;
// var EliteEightThird = Network.GamePackets.TitlePacket.Titles.ElitePK3ndPlace_Low;
// var EliteEight = Network.GamePackets.TitlePacket.Titles.ElitePKTopEight_Low;
// if (client.Entity.Titles.ContainsKey(EliteEightChampion))
// client.Entity.RemoveTopStatus((ulong)EliteEightChampion);
// if (client.Entity.Titles.ContainsKey(EliteEightThird))
// client.Entity.RemoveTopStatus((ulong)EliteEightThird);
// if (client.Entity.Titles.ContainsKey(EliteEight))
// client.Entity.RemoveTopStatus((ulong)EliteEight);
// }
// else if (client_rank == 2)
// {
// if (!client.Entity.Titles.ContainsKey(Network.GamePackets.TitlePacket.Titles.ElitePK3ndPlace_Low))
// client.Entity.AddTopStatus((ulong)Network.GamePackets.TitlePacket.Titles.ElitePK3ndPlace_Low, timer, true);
// var EliteEightChampion = Network.GamePackets.TitlePacket.Titles.ElitePKChamption_Low;
// var EliteEightSecond = Network.GamePackets.TitlePacket.Titles.ElitePK2ndPlace_Low;
// var EliteEight = Network.GamePackets.TitlePacket.Titles.ElitePKTopEight_Low;
// if (client.Entity.Titles.ContainsKey(EliteEightChampion))
// client.Entity.RemoveTopStatus((ulong)EliteEightChampion);
// if (client.Entity.Titles.ContainsKey(EliteEightSecond))
// client.Entity.RemoveTopStatus((ulong)EliteEightSecond);
// if (client.Entity.Titles.ContainsKey(EliteEight))
// client.Entity.RemoveTopStatus((ulong)EliteEight);
// }
// else
// {
// if (!client.Entity.Titles.ContainsKey(Network.GamePackets.TitlePacket.Titles.ElitePKTopEight_Low))
// client.Entity.AddTopStatus((ulong)Network.GamePackets.TitlePacket.Titles.ElitePKTopEight_Low, timer, true);
// var EliteEightChampion = Network.GamePackets.TitlePacket.Titles.ElitePKChamption_Low;
// var EliteEightSecond = Network.GamePackets.TitlePacket.Titles.ElitePK2ndPlace_Low;
// var EliteEightThird = Network.GamePackets.TitlePacket.Titles.ElitePK3ndPlace_Low;
// if (client.Entity.Titles.ContainsKey(EliteEightChampion))
// client.Entity.RemoveTopStatus((ulong)EliteEightChampion);
// if (client.Entity.Titles.ContainsKey(EliteEightSecond))
// client.Entity.RemoveTopStatus((ulong)EliteEightSecond);
// if (client.Entity.Titles.ContainsKey(EliteEightThird))
// client.Entity.RemoveTopStatus((ulong)EliteEightThird);
// } break;
// }
// }
// }
// }
//}
public static byte GetEliteGroup(byte p)
{
if (p <= 99)
return 0;
if (p >= 100 && p <= 119)
return 1;
if (p >= 120 && p <= 130)
return 2;
return 3;
}
public static bool SignUp(GameState client)
{
DateTime Now = DateTime.Now;
//if (Now.DayOfWeek != DayOfWeek.Friday) return false;
byte tournament = 0;
if (client.Entity.Level >= 130)
tournament = EPK_Lvl130Plus;
else if (client.Entity.Level >= 120)
tournament = EPK_Lvl120To129;
else if (client.Entity.Level >= 100)
tournament = EPK_Lvl100To119;
else
tournament = EPK_Lvl100Minus;
// tournament = EPK_Lvl130Plus;
int extraTime = 3 - tournament;
extraTime *= 2;
//if((Now.Hour == 19 && Now.Minute >= 55) || (Now.Hour == 20 && Now.Minute < extraTime))
if (((Now.Hour == ElitePK.EventTime) && Now.Minute >= 1) || ((Now.Hour == ElitePK.EventTime + 1) && Now.Minute < extraTime))
{
Tournaments[tournament].SignUp(client);
return true;
}
return false;
}
public static void RegisterTimers()
{
if (Tournaments == null) return;
TimersRegistered = true;
foreach (var epk in Tournaments)
if (epk != null)
epk.SubscribeTimer();
}
}
}
public unsafe class ElitePKWager
// Project by Avalanche
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using XMeGo.Game;
using XMeGo.Client;
namespace XMeGo.Network.GamePackets
{
public unsafe class ElitePKWager : Writer, Interfaces.IPacket
{
public const byte
SetWager = 2;
byte[] Buffer;
public ElitePKWager()
{
}
public byte Type
{
get { return Buffer[4]; }
set { Buffer[4] = value; }
}
public uint dwParam
{
get { return BitConverter.ToUInt32(Buffer, 8); }
set { WriteUInt32(value, 8, Buffer); }
}
public uint WagedUID
{
get { return BitConverter.ToUInt32(Buffer, 12); }
set { WriteUInt32(value, 12, Buffer); }
}
public uint Wager
{
get { return BitConverter.ToUInt32(Buffer, 20); }
set { WriteUInt32(value, 20, Buffer); }
}
public void Send(GameState client)
{
client.Send(Buffer);
}
public byte[] ToArray()
{
return Buffer;
}
public void Deserialize(byte[] buffer)
{
Buffer = buffer;
}
}
}
public unsafe class ElitePKWagersList
// Project by Avalanche
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using XMeGo.Game;
using XMeGo.Client;
namespace XMeGo.Network.GamePackets
{
public unsafe class ElitePKWagersList : Writer, Interfaces.IPacket
{
public const byte
SendList = 3,
RequestList = 4;
byte[] Buffer;
public ElitePKWagersList(bool create, int matchcount = 0)
{
if (create)
{
Buffer = new byte[12 + matchcount * 16 + 8];
WriteUInt16((ushort)(Buffer.Length - 8), 0, Buffer);
WriteUInt16(1065, 2, Buffer);
}
}
public byte Group
{
get { return Buffer[4]; }
set { Buffer[4] = value; }
}
public byte Page //not sure.
{
get { return Buffer[6]; }
set { Buffer[6] = value; }
}
public uint TotalMatches
{
get { return BitConverter.ToUInt32(Buffer, 8); }
set { WriteUInt32(value, 8, Buffer); }
}
public uint WagedUID
{
get { return BitConverter.ToUInt32(Buffer, 12); }
set { WriteUInt32(value, 12, Buffer); }
}
public void Append(ElitePK.Match match, int index)
{
int offset = 12 + index * 16;
var array = match.FightersStats;
if (array.Length == 2)
{
WriteUInt32(array[0].UID, offset, Buffer); offset += 4;
WriteUInt32(array[1].UID, offset, Buffer); offset += 4;
WriteUInt32(array[0].Wager, offset, Buffer); offset += 4;
WriteUInt32(array[1].Wager, offset, Buffer); offset += 4;
}
}
public void Send(GameState client)
{
client.Send(Buffer);
}
public byte[] ToArray()
{
return Buffer;
}
public void Deserialize(byte[] buffer)
{
Buffer = buffer;
}
}
}
public class ElitePKWatch
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using XMeGo.Game;
using XMeGo.Client;
namespace XMeGo.Network.GamePackets
{
public class ElitePKWatch : Writer, Interfaces.IPacket
{
public const byte
RequestView = 0,
Watchers = 2,
Leave = 3,
Fighters = 4;
byte[] Buffer;
public byte Typ;
public ElitePKWatch(bool create, int watchers = 0)
{
if (create)
{
Buffer = new byte[30 + watchers * 36 + 8];
WriteUInt16((ushort)(Buffer.Length - 8), 0, Buffer);
WriteUInt16(2211, 2, Buffer);
WatcherCount = (uint)watchers;
}
}
public byte Type
{
get { return Buffer[4]; }
set { Buffer[4] = value; }
}
public uint dwParam
{
get { return BitConverter.ToUInt32(Buffer, 6); }
set { WriteUInt32(value, 6, Buffer); }
}
public uint ID
{
get { return BitConverter.ToUInt32(Buffer, 10); }
set { WriteUInt32(value, 10, Buffer); }
}
public uint WatcherCount
{
get { return BitConverter.ToUInt32(Buffer, 14); }
set { WriteUInt32(value, 14, Buffer); }
}
public uint dwCheers1
{
get { return BitConverter.ToUInt32(Buffer, 18); }
set { WriteUInt32(value, 18, Buffer); }
}
public uint dwCheers2
{
get { return BitConverter.ToUInt32(Buffer, 22); }
set { WriteUInt32(value, 22, Buffer); }
}
int index = 0;
public void Append(string name)
{
int offset = 34 + index * 32;
WriteString(name, offset, Buffer);
index++;
}
public void Append(uint mesh, string name)
{
int offset = 26 + index * 36;
//if (Typ == 1)
// {
// offset = 18 + index * 36;
// }
WriteUInt32(mesh, offset, Buffer);
offset += 4;
WriteString(name, offset, Buffer);
index++;
}
public void Send(GameState client)
{
client.Send(Buffer);
}
public byte[] ToArray()
{
return Buffer;
}
public void Deserialize(byte[] buffer)
{
Buffer = buffer;
}
}
}
#region ElitePk
case 448582:
{
switch (npcRequest.OptionID)
{
case 0:
{
dialog.Text("Glad to see you! I take it that you haven`t heard of the Elite PK Tournament, have you? No? Aha, please allow me to introduce this exciting event for you! It`s a new PK Tournament that takes place every Friday. You will be divided into four groups, based");
dialog.Text("~on your level. Not only will the top 3 winners of each group receive nice prizes, you will also receive EXP worth 1 EXP Ball and 1000 Honor points for each match you take part in at the end of that round. Do you want to have a go?");
dialog.Option("Tell~me~more~about~the~rules.", 1);
dialog.Option("Sign~me~up!", 3);
dialog.Option("I~want~to~claim~my~prize!", 5);
dialog.Option("Not~interested.", 255);
dialog.Avatar(26);
break;
}
case 1:
{
dialog.Text("The Elite PK Tournament begins at 15:55 every day night, and players will be divided into four groups, which are the Under 100 group, the 100-119 group, the 120-129 group, and the 130+ group. You can sign up for it");
dialog.Text("~between 15:55 and 15:59. No admittance after the tournament begins. Players should first wait in the Waiting Area, and if you leave the area before your round, you will forfeit your chance. There will be a Knockout round before the Final.");
dialog.Text("~But if there are less than 8 players at the start of the Elite PK Tournament, the Final will be replaced by the Knockout. Each round in the Knockout lasts 3 minutes. At the end of 3 minutes, if no one is killed, the player with a higher score wins.");
dialog.Text("~After you finish your round, you`ll have to wait for all the other players to finish this round to enter the next round.");
dialog.Option("There~is~a~Final?", 2);
dialog.Avatar(26);
break;
}
case 2:
{
dialog.Text("Sure. When there are less than 8 players left in the field, the Final starts. Each round of the Final lasts for 5 minutes. Though all of the Top 8 players will receive nice prizes, the top 3 will earn special prizes! Claim your reward before the next");
dialog.Text("~week`s Elite PK Tournament begins, or you won`t get them. We hope everyone will join this tournament, and so not only will the top 3 winners of each group receive nice prizes, you will also receive EXP worth 1 EXP Ball and 1000 Honor");
dialog.Text("~points for each match you take part in at the end of that match!");
dialog.Option("Sign~me~up!", 3);
dialog.Option("Not~interested.", 255);
dialog.Avatar(26);
break;
}
case 3:
{
if (!ElitePKTournament.SignUp(client))//dy test only hmmmm oki
{
dialog.Text("Please sign up between " + ElitePK.EventTime + ":55 and " + ElitePK.EventTime + ":59 every night for the Elite PK Tournament.");
dialog.Option("Okay.", 255);
dialog.Avatar(26);
}
break;
}
case 5:
{
byte rank = 0;
byte elitestage = 0;
if (ElitePKTournament.GetReward(client))
{
uint cpsprice = 0;
if (rank == 1)
{
cpsprice = 150000000;
if (elitestage == 3)
client.Entity.AddTopStatus((ulong)XMeGo.Network.GamePackets.TitlePacket.Titles.ElitePKChamption_High, 0, DateTime.Now.AddDays(1), true);
else
client.Entity.AddTopStatus((ulong)XMeGo.Network.GamePackets.TitlePacket.Titles.ElitePKChamption_Low, 0, DateTime.Now.AddDays(1), true);
}
else if (rank == 2)
{
cpsprice = 100000000;
if (elitestage == 3)
client.Entity.AddTopStatus((ulong)XMeGo.Network.GamePackets.TitlePacket.Titles.ElitePK2ndPlace_High, 0, DateTime.Now.AddDays(1), true);
else
client.Entity.AddTopStatus((ulong)XMeGo.Network.GamePackets.TitlePacket.Titles.ElitePK2ndPlace_Low, 0, DateTime.Now.AddDays(1), true);
}
else if (rank == 3)
{
cpsprice = 50000000;
if (elitestage == 3)
client.Entity.AddTopStatus((ulong)XMeGo.Network.GamePackets.TitlePacket.Titles.ElitePK3ndPlace_High, 0, DateTime.Now.AddDays(1), true);
else
client.Entity.AddTopStatus((ulong)XMeGo.Network.GamePackets.TitlePacket.Titles.ElitePK3ndPlace_Low, 0, DateTime.Now.AddDays(1), true);
}
else
{
cpsprice = 50000000;
if (elitestage == 3)
client.Entity.AddTopStatus((ulong)XMeGo.Network.GamePackets.TitlePacket.Titles.ElitePKTopEight_High, 0, DateTime.Now.AddDays(1), true);
else
client.Entity.AddTopStatus((ulong)XMeGo.Network.GamePackets.TitlePacket.Titles.ElitePKTopEight_Low, 0, DateTime.Now.AddDays(1), true);
}
client.Entity.ConquerPoints += cpsprice;
Kernel.SendWorldMessage(new Network.GamePackets.Message("" + client.Entity.Name + " has receive " + cpsprice + " for rank " + rank + " in Elite Pk Tournament", Color.Red, Network.GamePackets.Message.System).ToArray());
}
else
{
dialog.Text("Sorry, just the lider of 8 top teams will receive the reward!");
dialog.Option("Ok thx.", 255);
dialog.Send();
}
break;
}
}
break;
}
#endregion
#region Elite PK Tournament
if (((Now64.Hour == ElitePK.EventTime) && Now64.Minute >= 55) && !ElitePKTournament.TimersRegistered)
{
ElitePKTournament.RegisterTimers();
ElitePKBrackets brackets = new ElitePKBrackets(true, 0);
brackets.Type = ElitePKBrackets.EPK_State;
brackets.OnGoing = true;
foreach (var client in Program.Values)
{
new TitleStorage().RemoveTitle(client, 6001, 20, false);
client.Send(brackets);
foreach (Client.GameState Client in Kernel.GamePool.Values)
{
if (client.Map.BaseID != 6001 && client.Map.BaseID != 6000 && !client.Entity.Dead)
{
client.ClaimedElitePk = 0;
EventAlert alert = new EventAlert
{
StrResID = 10533,
Countdown = 60,
UK12 = 1
};
client.Entity.StrResID = 10533;
client.Send(alert);
}
}
}
}
if ((((Now64.Hour == ElitePK.EventTime + 1)) && Now64.Minute >= 10) && ElitePKTournament.TimersRegistered)
{
bool done = true;
foreach (var epk in ElitePKTournament.Tournaments)
//if (epk.Entitys.Count != 0)
done = false;
if (done)
{
ElitePKTournament.TimersRegistered = false;
ElitePKBrackets brackets = new ElitePKBrackets(true, 0);
brackets.Type = ElitePKBrackets.EPK_State;
brackets.OnGoing = false;
foreach (var client in Program.Values)
client.Send(brackets);
}
}
#endregion
public class TeamPkStatus
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.Concurrent;
using XMeGo.Network.GamePackets;
using System.IO;
using XMeGo.Database;
using XMeGo.MaTrix;
namespace XMeGo.Game.Features.Tournaments
{
public class TeamPkStatus
{
public static int EventTime = 18;
public void GetTeamPkReward(Client.GameState client, byte Rank)
{
uint ITEM_ID = 0;
switch (Rank)
{
case 0:
ITEM_ID = (uint)(0 + GetTeamGroup(client.Entity.Level));
break;
case 1:
ITEM_ID = (uint)(720798 + GetTeamGroup(client.Entity.Level));
break;
case 2:
ITEM_ID = (uint)(720802 + GetTeamGroup(client.Entity.Level));
break;
default:
ITEM_ID = (uint)(720806 + GetTeamGroup(client.Entity.Level));
break;
}
client.Inventory.Add(ITEM_ID, 0, 1);
}
public static byte[] BlockOpenArena = new byte[] { 20, 0, 86, 4, 255, 87, 14, 0, 160, 187, 13, 0, 103, 0, 21, 64, 204, 17, 0, 0, 84, 81, 83, 101, 114, 118, 101, 114 };
public byte GetTeamGroup(byte level)
{
if (level >= 130)
return 3;
if (level >= 120)
return 3;
if (level >= 100)
return 1;
else
return 0;
}
public enum top_typ
{
Elite_PK_Champion__Low_ = 12,
Elite_PK_2nd_Place_Low_ = 13,
Elite_PK_3rd_Place_Low_ = 14,
Elite_PK_Top_8__Low_ = 15,
Elite_PK_Champion_High_ = 16,
Elite_PK_2nd_Place_High_ = 17,
Elite_PK_3rd_Place__High_ = 18,
Elite_PK_Top_8_High_ = 19
}
public class States
{
public const byte
GUI_Top8Ranking = 0,
GUI_Knockout = 3,
GUI_Top8Qualifier = 4,
GUI_Top4Qualifier = 5,
GUI_Top2Qualifier = 6,
GUI_Top3 = 7,
GUI_Top1 = 8,
GUI_ReconstructTop = 9;
public const byte
T_Organize = 0,
T_CreateMatches = 1,
T_Wait = 2,
T_Fights = 3,
T_Finished = 4,
T_ReOrganize = 5;
}
}
public class TeamPk : TeamPkStatus
{
public enum GamePackets : ushort
{
SkillEliteSetTeamName = 2260,
SkillElitePkTop = 2253,
SkillElitePkBrackets = 2252,
SkillElitePKMatchStats = 2251,
SkillElitePKMatchUI = 2250,
TeamEliteSetTeamName = 2240,
TeamPkTop = 2233,
TeamPkBrackets = 2232,
TeamPkMatchStats = 2231,
TeamPkMatchUI = 2230,
}
public class TeamTournament
{
public static uint WaitingAreaID = 2068;
public static TeamPk[] Tournaments;
public static bool Opened = false;
public static void Create()
{
try
{
Tournaments = new TeamPk[4];
for (byte x = 0; x < Tournaments.Length; x++)
Tournaments[x] = new TeamPk(x, GamePackets.TeamPkBrackets);
// LoadTop(Tournaments, "TeamPkTop8");
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
}
public static void Save()
{
// SaveTop(Tournaments, "TeamPkTop8");
}
public static bool GetReward(Client.GameState client, out byte rank, out byte elitestage)
{
if (Tournaments != null)
for (byte x = 0; x < Tournaments.Length; x++)
{
if (Tournaments[x] != null)
{
if (Tournaments[x].Top8 != null)
{
for (byte i = 0; i < Tournaments[x].Top8.Length; i++)
{
if (Tournaments[x].Top8[i] != null)
{
if (Tournaments[x].Top8[i].LeaderUID == client.Entity.UID)
{
if (Tournaments[x].Top8[i].RceiveReward == 0)
{
rank = (byte)(i + 1);
elitestage = x;
Tournaments[x].Top8[i].RceiveReward = 1;
return true;
}
}
}
}
}
}
}
rank = 0;
elitestage = 0;
return false;
}
public static void Open()
{
if (!Opened)
{
Opened = true;
for (byte x = 0; x < Tournaments.Length; x++)
{
Tournaments[x].SubscribeTimer(1);
Tournaments[x].AllowJoin = true;
}
Kernel.SendWorldMessage(new Message("The Team PK Tournament has start at 19:00. Prepare Yourself And Sign Up For it As a Team.", System.Drawing.Color.White, Message.BroadcastMessage), Program.Values);
foreach (var client in Program.GamePool)
{
client.ClaimedTeampk = 0;
client.MessageBox("The Team PK Tournament began Would you like to join?",
p => { p.Entity.Teleport(1002, 294, 148); }, null, 60);
}
}
}
public static bool Join(Client.GameState client, byte Grope)
{
if (client.Team == null)
return false;
if (Grope <= 3)
{
client.Team.SetTeamFighterStats(true);
return Tournaments[Grope].SignUp(client);
}
return false;
}
}
private void SaveTop8(string epk)
{
try
{
int len = Top8.Count(p => p.LeaderUID != 0);
var stream = new MemoryStream();
var writer = new BinaryWriter(stream);
writer.Write(len);
for (int i = 0; i < len; i++)
{
writer.Write(Top8[i].LeaderUID);
writer.Write(Top8[i].Name);
writer.Write(Top8[i].LeaderMesh);
writer.Write(Top8[i].Rank);
writer.Write(Top8[i].Title);
writer.Write(Top8[i].RceiveReward);
}
string SQL = "UPDATE `matrixvariable` SET data=@data where ID = '" + epk + "' ;";
byte[] rawData = stream.ToArray();
using (var conn = DataHolder.MySqlConnection)
{
conn.Open();
using (var cmd = new MySql.Data.MySqlClient.MySqlCommand())
{
cmd.Connection = conn;
cmd.CommandText = SQL;
cmd.Parameters.AddWithValue("@data", rawData);
cmd.ExecuteNonQuery();
}
}
}
catch (Exception e)
{
Console.WriteLine(e);
}
}
private void LoadTop8(string epk)
{
try
{
Top8 = new FighterStats[8];
using (var cmd = new MySqlCommand(MySqlCommandType.SELECT))
{
cmd.Select("matrixvariable").Where("ID", epk);
using (MySqlReader rdr = new MySqlReader(cmd))
{
if (rdr.Read())
{
byte[] data = rdr.ReadBlob("data");
if (data.Length > 0)
{
using (var stream = new MemoryStream(data))
using (var reader = new BinaryReader(stream))
{
int len = reader.ReadInt32();
for (int i = 0; i < len; i++)
{
Top8[i] = new FighterStats(reader.ReadUInt32(), reader.ReadString(), reader.ReadUInt32(), null);
Top8[i].Rank = reader.ReadByte();
Top8[i].Title = reader.ReadByte();
Top8[i].RceiveReward = reader.ReadByte();
}
}
}
}
else
{
using (var command = new MySqlCommand(MySqlCommandType.INSERT))
{
command.Insert("matrixvariable").Insert("ID", epk);
command.Execute();
}
}
}
}
}
catch (Exception e)
{
Console.WriteLine(e);
}
}
public class FighterStats
{
public enum StatusFlag : int
{
None = 0,
Fighting = 2,
Lost = 4,
Qualified = 3,
Waiting = 1,
}
public Game.ConquerStructures.Team Team;
public string Name;
public uint LeaderUID;
public uint LeaderMesh;
public bool OnNextMatch = false;
public uint Cheers;
public uint Points;
public StatusFlag Flag;
public bool Teleported;
public byte RceiveReward;
public byte Title;
public byte Rank;
public bool Waiting { get { return Flag == StatusFlag.Waiting; } }
public bool NoFlag { get { return Flag == StatusFlag.None; } }
public bool Fighting { get { return Flag == StatusFlag.Fighting; } }
public bool Winner { get { return Flag == StatusFlag.Qualified; } }
public bool Lost { get { return Flag == StatusFlag.Lost; } }
public FighterStats(uint id, string name, uint mesh, Game.ConquerStructures.Team temate)
{
LeaderUID = id;
Name = name;
LeaderMesh = mesh;
Team = temate;
}
public void Reset(bool noflag = false)
{
Points = 0;
Cheers = 0;
if (!noflag)
{
if (!Lost)
Flag = StatusFlag.Waiting;
}
}
public FighterStats Clone()
{
FighterStats stats = new FighterStats(LeaderUID, Name, LeaderMesh, Team);
stats.Points = this.Points;
stats.Flag = this.Flag;
return stats;
}
public override string ToString()
{
if (Name.Contains('^'))
Name.Replace("^", "");
if (Name.Contains('#'))
Name.Replace('#', ' ');
StringBuilder build = new StringBuilder();
build.Append(LeaderUID + "#" + Name + "#" + LeaderMesh + "#" + Rank + "#" + Title + "#" + RceiveReward + "");
return build.ToString();
}
public void Load(string Line)
{
string[] data = Line.Split('#');
LeaderUID = uint.Parse(data[0]);
Name = data[1];
LeaderMesh = uint.Parse(data[2]);
Rank = byte.Parse(data[3]);
Title = byte.Parse(data[4]);
RceiveReward = byte.Parse(data[5]);
}
}
public class Match
{
public enum StatusFlag : int
{
SwitchOut = 0,
Watchable = 1,
Waiting = 3,
OK = 2,
}
public IEnumerable<Client.GameState> Players
{
get
{
foreach (var team in MatchStats)
foreach (var player in team.Team.Players)
yield return player;
}
}
public List<uint> Cheerers = new List<uint>();
public FighterStats[] MatchStats;
public bool OnGoing { get { return Flag == StatusFlag.Watchable; } }
public int GroupID { get { return (int)ID / 100000 - 1; } }
public uint TimeLeft
{
get
{
int val = 0;
if (MatchStats.Length == 1)
val = 0;
else
val = (int)((ImportTime.AddMinutes(10).TotalMilliseconds - Time32.Now.TotalMilliseconds) / 1000);
if (val < 0)
val = 0;
return (uint)val;
}
}
public void Commit()
{
var matchStats = new FighterStats[MatchStats.Length];
for (int i = 0; i < matchStats.Length; i++)
{
matchStats[i] = MatchStats[i].Clone();
}
MatchStats = matchStats;
}
public ConcurrentDictionary<uint, Client.GameState> Watchers;
public FighterStats Return(Func<FighterStats, bool> fn)
{
foreach (var stat in MatchStats)
if (stat != null)
if (fn(stat))
{
return TeamTournament.Tournaments[GroupID].Teams[stat.Team.UID].TeamFighterStats;
}
MatchStats[0].Flag = FighterStats.StatusFlag.Qualified;
return MatchStats[0];
}
public uint ID;
public StatusFlag Flag;
public bool Inside;
public bool Done;
public bool Exported;
public bool Completed;
public ushort Index;
public Time32 ImportTime;
public Map Map;
private Time32 DoneStamp;
private int Imports;
public void AliveMatch()
{
if (Flag != StatusFlag.OK)
{
if (Inside && !Done)
{
foreach (var dismised in MatchStats)
{
if (Flag != StatusFlag.OK)
{
if (MatchStats.Length == 2)
{
if (MatchStats[0].Winner)
return;
if (MatchStats[1].Winner)
return;
}
if (!dismised.Team.OnPopulates)
{
if (dismised.Waiting)
{
dismised.Flag = FighterStats.StatusFlag.Lost;
dismised.Team.TeamFighterStats.Flag = FighterStats.StatusFlag.Lost;
}
if (!dismised.Lost)
{
Console.WriteLine("team " + dismised.Team.TeamFighterStats.Name + " has lost");
this.End(dismised.Team);
}
}
else
{
CheckAlive(dismised.Team);
}
}
}
}
}
}
public Match(params FighterStats[] teamates)
{
try
{
Map = Kernel.Maps[700].MakeDynamicMap();
if (teamates.Length == 1)
{
Flag = StatusFlag.OK;
MatchStats = new FighterStats[1];
MatchStats[0] = teamates[0].Team.TeamFighterStats;
MatchStats[0].Team.TeamMatch = this;
MatchStats[0].Points = 0;
MatchStats[0].Cheers = 0;
MatchStats[0].Flag = FighterStats.StatusFlag.Qualified;
Flag = StatusFlag.OK;
Completed = true;
}
else
{
Watchers = new ConcurrentDictionary<uint, Client.GameState>();
MatchStats = new FighterStats[teamates.Length];
for (int i = 0; i < teamates.Length; i++)
{
MatchStats[i] = teamates[i].Team.TeamFighterStats;
MatchStats[i].Team.TeamMatch = this;
MatchStats[i].Flag = FighterStats.StatusFlag.Waiting;
MatchStats[i].Points = 0;
MatchStats[i].Cheers = 0;
MatchStats[i].Teleported = false;
}
if (MatchStats.Length == 3)
MatchStats[0].Flag = FighterStats.StatusFlag.None;
Imports = 0;
Flag = StatusFlag.Waiting;
}
}
catch (Exception e) { Console.WriteLine(e.ToString()); }
}
public void Import(StatusFlag flag = StatusFlag.Watchable)
{
try
{
Imports++;
Exported = Done = false;
Inside = true;
Flag = flag;
ImportTime = Time32.Now;
if (MatchStats.Length > 1)
{
Game.ConquerStructures.Team team1 = null, team2 = null;
for (int i = 0; i < MatchStats.Length; i++)
if (!MatchStats[i].NoFlag && !MatchStats[i].Lost)
if (team1 == null)
team1 = MatchStats[i].Team;
else
team2 = MatchStats[i].Team;
if (!team1.CanFightTeamPK)
{
Exported = Done = true;
Flag = StatusFlag.OK;
if (MatchStats.Length == 3)
Flag = StatusFlag.SwitchOut;
Completed = true;
var statsArray = team2.Teammates;
team1.TeamFighterStats.Flag = FighterStats.StatusFlag.Lost;
team2.TeamFighterStats.Flag = FighterStats.StatusFlag.Qualified;
return;
}
if (!team2.CanFightTeamPK)
{
Exported = Done = true;
Flag = StatusFlag.OK;
if (MatchStats.Length == 3)
Flag = StatusFlag.SwitchOut;
Completed = true;
var statsArray = team2.Teammates;
team2.TeamFighterStats.Flag = FighterStats.StatusFlag.Lost;
team1.TeamFighterStats.Flag = FighterStats.StatusFlag.Qualified;
return;
}
team1.TeamFighterStats.Flag = FighterStats.StatusFlag.Fighting;
team2.TeamFighterStats.Flag = FighterStats.StatusFlag.Fighting;
importPlayer(team1, team2);
importPlayer(team2, team1);
team1.TeamMatch = this;
team2.TeamMatch = this;
Network.GamePackets.TeamPkBrackets brackets = new Network.GamePackets.TeamPkBrackets(1);
{
brackets.Group = (ushort)GroupID;
brackets.GUIType = (ushort)TeamTournament.Tournaments[GroupID].State;
brackets.TotalMatchesOnRoom = brackets.MatchCount = 1;
brackets.Type = Network.GamePackets.TeamPkBrackets.StaticUpdate;
brackets.Append(this);
Kernel.SendWorldMessage(brackets.ToArray());
}
MapStatus status = new MapStatus();
status.BaseID = 700;
status.ID = Map.ID;
status.Statu = 768946643047;
SendMapPacket(status.ToArray());
}
else
{
Done = true;
Flag = StatusFlag.OK;
Exported = true;
Completed = true;
MatchStats[0].Flag = FighterStats.StatusFlag.Qualified;
}
}
catch (Exception e)
{
Console.WriteLine(e);
}
}
public void SendMapPacket(byte[] buffer)
{
foreach (var player in Players)
if (player.Entity.MapID == Map.ID)
player.Send(buffer);
}
private void importPlayer(Game.ConquerStructures.Team teamone, Game.ConquerStructures.Team opponent)
{
if (MatchStats.Length > 1)
{
teamone.TeamFighterStats.Teleported = true;
opponent.TeamFighterStats.Teleported = true;
// ushort x = 0; ushort y = 0;
foreach (var player in teamone.Players)
{
if (player.Entity.MapID != TeamPk.TeamTournament.Tournaments[GroupID].WaitingArea.ID)
continue;
if (player.Entity.ContainsFlag(Network.GamePackets.Update.Flags.Ride))
{
player.Entity.RemoveFlag(Network.GamePackets.Update.Flags.Ride);
}
var coords = Map.RandomCoordinates();
player.Entity.Teleport(Map.BaseID, Map.ID, coords.Item1, coords.Item2);
player.Entity.BringToLife();
player.Entity.TeamWatchingMatch = null;
Network.GamePackets.TeamPkMatchUI ui = new Network.GamePackets.TeamPkMatchUI();
{
ui.Append(opponent);
ui.TimeLeft = TimeLeft;
ui.Type = Network.GamePackets.TeamPkMatchUI.BeginMatch;
player.Send(ui.ToArray());
}
player.Send(CreateUpdate().ToArray());
player.CantAttack = Time32.Now.AddSeconds(11);
player.Entity.PrevPKMode = player.Entity.PKMode;
player.Entity.PKMode = Enums.PKMode.Team;
Network.GamePackets.Data dat = new Network.GamePackets.Data(true);
{
dat.UID = player.Entity.UID;
dat.ID = Network.GamePackets.Data.ChangePKMode;
dat.dwParam = (uint)player.Entity.PKMode;
player.Send(dat.ToArray());
}
}
}
else
{
MatchStats[0].Flag = FighterStats.StatusFlag.Qualified;
Done = true;
Flag = StatusFlag.OK;
Exported = true;
Completed = true;
}
}
public void CheckAlive(Game.ConquerStructures.Team team)
{
bool dead = true;
foreach (var players in team.Teammates)
{
if (players.Entity.MapID == Map.ID)
{
if (players.Entity.Hitpoints > 0)
dead = false;
}
}
if (dead)
End(team);
}
public void End(Game.ConquerStructures.Team team)
{
try
{
if (MatchStats.Length == 1)
{
MatchStats[0].Flag = FighterStats.StatusFlag.Qualified;
Flag = StatusFlag.OK;
return;
}
if (Done) return;
Done = true;
DoneStamp = Time32.Now;
Flag = StatusFlag.OK;
team.TeamFighterStats.Flag = FighterStats.StatusFlag.Lost;
Network.GamePackets.TeamPkMatchUI ui = new Network.GamePackets.TeamPkMatchUI();
{
ui.Type = Network.GamePackets.TeamPkMatchUI.Effect;
ui.dwParam = Network.GamePackets.TeamPkMatchUI.Effect_Lose;
team.SendMesageTeam(ui.ToArray(), 0);
var team_win = targetOfWin(team);
if (team_win != null)
{
ui.Append(team_win.Team);
ui.dwParam = Network.GamePackets.TeamPkMatchUI.Effect_Win;
foreach (var target in team_win.Team.Players)
{
target.Send(ui.ToArray());
ui.Type = Network.GamePackets.TeamPkMatchUI.EndMatch;
team.SendMesageTeam(ui.ToArray(), 0);
target.Send(ui.ToArray());
ui.Type = Network.GamePackets.TeamPkMatchUI.Reward;
target.Send(ui.ToArray());
if (Imports == 2 || MatchStats.Length != 3 || MatchStats[0] == null)
{
team_win.Flag = FighterStats.StatusFlag.Qualified;
}
else
{
var dictionar = MatchStats.Where(p => !p.Lost).ToArray();
if (dictionar.Length == 2)
{
Flag = StatusFlag.SwitchOut;
team_win.Flag = FighterStats.StatusFlag.Waiting;
team_win.OnNextMatch = true;
}
else
team_win.Flag = FighterStats.StatusFlag.Qualified;
}
}
}
}
Network.GamePackets.TeamPkBrackets brackets = new Network.GamePackets.TeamPkBrackets(1);
{
brackets.Group = (ushort)GroupID;
brackets.GUIType = (ushort)TeamTournament.Tournaments[GroupID].State;
brackets.TotalMatchesOnRoom = brackets.MatchCount = 1;
brackets.Type = Network.GamePackets.TeamPkBrackets.StaticUpdate;
brackets.Append(this);
Kernel.SendWorldMessage(brackets.ToArray());
}
foreach (var clien in Watchers.Values)
if (clien.Entity.MapID == Map.ID)
LeaveWatch(clien);
}
catch (Exception e) { Console.WriteLine(e.ToString()); }
}
public void Export()
{
try
{
if (Time32.Now > DoneStamp.AddSeconds(3) || TimeLeft == 0)
{
#region !Done
if (!Done)
{
if (MatchStats.Length == 1)
{
MatchStats[0].Flag = FighterStats.StatusFlag.Qualified;
Flag = StatusFlag.OK;
Exported = true;
Exported = true;
Completed = true;
return;
}
else
{
var fighters = MatchStats.Where(p => p.Fighting).OrderBy(p => p.Points).ThenBy(p => p.Cheers).ToArray();
for (int i = 0; i < fighters.Length; i++)
{
var team = fighters[i];
End(team.Team);
}
//var fighters = MatchStats.Where(p => p.Fighting).ToArray();
//if (fighters.Length > 1)
//{
// if (fighters[0].Fighting && fighters[1].Fighting)
// {
// if (fighters[0].Points == fighters[1].Points)
// End(fighters.Last(p => p.Team.UID == fighters[0].Team.UID).Team);
// else
// {
// if (fighters[0].Points > fighters[1].Points)
// End(fighters.Last(p => p.Team.UID == fighters[0].Team.UID).Team);
// else
// End(fighters.Last(p => p.Team.UID == fighters[1].Team.UID).Team);
// }
// }
//}
//else if (fighters.Length == 1)
// End(fighters.First(p => p.Team.UID == fighters[0].Team.UID).Team);
}
}
#endregion
foreach (var teams in MatchStats)
{
if (teams != null)
{
if (!teams.Waiting && teams.Teleported || teams.OnNextMatch)
{
foreach (var player in teams.Team.Players)
{
if (player.Entity.MapID == Map.ID)
{
player.Entity.BringToLife();
Data dat = new Data(true);
dat.UID = player.Entity.UID;
dat.ID = Data.ChangePKMode;
dat.dwParam = (uint)player.Entity.PrevPKMode;
player.Send(dat);
var map = TeamTournament.Tournaments[GroupID].WaitingArea;
var coords = map.RandomCoordinates();
player.Entity.Teleport(map.ID, coords.Item1, coords.Item2);
if (player.Entity.Hitpoints == 0)
player.Entity.BringToLife();
MapStatus status = new MapStatus();
status.BaseID = map.BaseID;
status.ID = map.ID;
status.Statu = 2568946643047;
player.Send(status);
}
}
teams.Teleported = true;
}
}
}
Exported = true;
Completed = true;
}
}
catch (Exception e) { Console.WriteLine(e.ToString()); }
}
public void SwitchBetween()
{
if (Imports == 1 && MatchStats.Length == 3 && MatchStats[0] != null && !MatchStats[0].Lost)
{
MatchStats[0].Flag = FighterStats.StatusFlag.Waiting;
if (MatchStats[1].Winner)
{
MatchStats[1].Teleported = false;
MatchStats[1].Flag = FighterStats.StatusFlag.Waiting;
}
if (MatchStats[2].Winner)
{
MatchStats[2].Teleported = false;
MatchStats[2].Flag = FighterStats.StatusFlag.Waiting;
}
Completed = false;
}
}
public TeamPk.FighterStats targetOfWin(Game.ConquerStructures.Team team)
{
var dictionar = MatchStats.Where(p => p.Fighting).ToArray();
for (int i = 0; i < dictionar.Length; i++)
if (dictionar[i] != null)
if (dictionar[i].Team.UID != team.UID)
return dictionar[i];
return null;
}
public TeamPkMatchStats CreateUpdate()
{
Network.GamePackets.TeamPkMatchStats stats = new Network.GamePackets.TeamPkMatchStats();
stats.Append(this);
return stats;
}
public void BeginWatch(Client.GameState client)
{
if (client.Entity.TeamWatchingMatch != null) return;
if (Watchers.ContainsKey(client.Entity.UID)) return;
Watchers.TryAdd(client.Entity.UID, client);
client.Entity.TeamWatchingMatch = this;
client.Entity.WatchingArena = 1;
var coords = Map.RandomCoordinates();
client.Entity.Teleport(Map.BaseID, Map.ID, coords.Item1, coords.Item2);
Network.GamePackets.ElitePKWatch watch = new Network.GamePackets.ElitePKWatch(true, MatchStats.Length);
watch.dwParam = MatchStats.First().Team.UID;
watch.Type = Network.GamePackets.ElitePKWatch.RequestView;
watch.dwCheers1 = MatchStats[0].Cheers;
watch.dwCheers2 = MatchStats[1].Cheers;
client.Send(watch.ToArray());
client.Send(CreateUpdate().ToArray());
UpdateWatchers();
client.Entity.PKMode = Enums.PKMode.Capture;
client.Entity.Send(new Data(true) { UID = client.Entity.UID, ID = Data.ChangePKMode, dwParam = (uint)client.Entity.PKMode });
}
public void Update()
{
try
{
var update = CreateUpdate();
foreach (var player in Players)
if (player != null)
if (player.Team.TeamFighterStats.Fighting)
player.Send(update.ToArray());
foreach (var watch in Watchers.Values)
if (watch != null)
watch.Send(update.ToArray());
}
catch (Exception e)
{
Console.WriteLine(e);
}
}
public void UpdateWatchers()
{
Network.GamePackets.ElitePKWatch watch = new Network.GamePackets.ElitePKWatch(true, Watchers.Count);
{
watch.ID = ID;
watch.Type = Network.GamePackets.ElitePKWatch.Watchers;
watch.WatcherCount = (uint)Watchers.Count;
watch.dwCheers1 = MatchStats[0].Cheers;
watch.dwCheers2 = MatchStats[1].Cheers;
foreach (var pClient in Watchers.Values)
watch.Append(pClient.Entity.Mesh, pClient.Entity.Name);
foreach (var pClient in Watchers.Values)
pClient.Send(watch.ToArray());
foreach (var pClient in Players)
if (pClient != null)
pClient.Send(watch.ToArray());
}
}
public void LeaveWatch(Client.GameState client)
{
if (Watchers.TryRemove(client.Entity.UID, out client))
{
if (!Done)
UpdateWatchers();
client.Entity.TeamWatchingMatch = null;
client.Send(new Network.GamePackets.ElitePKWatch(true) { ID = ID, Type = Network.GamePackets.ElitePKWatch.Leave }.ToArray());
if (Program.EventsMap.Contains(client.Entity.PreviousMapID))
client.Entity.Teleport(1002, 300, 278);
else
client.Entity.PreviousTeleport();
}
}
public void Cheer(Client.GameState client, uint fighter)
{
if (!this.Cheerers.Contains(client.Entity.UID))
{
Cheerers.Add(client.Entity.UID);
ElitePKWatch watch = new ElitePKWatch(true, MatchStats.Length);
watch.ID = ID;
watch.Type = ElitePKWatch.Fighters;
watch.dwCheers1 = MatchStats[0].Cheers;
watch.dwCheers2 = MatchStats[1].Cheers;
if (MatchStats[0].LeaderUID == fighter)
{
watch.Append(0, MatchStats[0].Name);
MatchStats[0].Cheers += 1;
}
else if (MatchStats[1].LeaderUID == fighter)
{
watch.Append(0, MatchStats[1].Name);
MatchStats[1].Cheers += 1;
}
watch.Append(client.Entity.Name);
foreach (var watchers in Watchers.Values)
watchers.Send(watch);
foreach (var fighters in Players)
fighters.Send(watch);
UpdateWatchers();
SendGlobal(CreateUpdate().ToArray());
}
}
public void SendGlobal(byte[] buffer)
{
foreach (var pClient in Watchers.Values)
if (pClient != null)
pClient.Send(buffer);
foreach (var pClient in Players)
if (pClient != null)
pClient.Send(buffer);
}
}
public FighterStats[] Top8 = new FighterStats[0];
public ConcurrentDictionary<uint, Game.ConquerStructures.Team> Teams;
public ConcurrentDictionary<uint, Match> Matches;
private Match[] MatchArray;
public Match[] Top4MatchArray;
public Match[] ExtendedMatchArray;
private Counter MatchCounter;
private ushort MatchIndex;
public bool IsAlive = false;
public DateTime ConstructTop8 = new DateTime();
public Map WaitingArea;
public int State;
private int pState = States.T_Organize;
public int GroupID;
private bool willAdvance;
private Time32 pStamp;
public GamePackets ID;
public void Remove(uint uid)
{
if (!Teams.ContainsKey(uid))
return;
foreach (var teamtes in Teams[uid].Teammates)
{
//teamtes.Team.TeamMatch = null;
if (teamtes.Entity.MapID == WaitingArea.ID)
teamtes.Entity.Teleport();
teamtes.InTeamPK = false;
}
Teams.Remove(uid);
}
public ushort TimeLeft
{
get
{
int value = (int)((pStamp.TotalMilliseconds - Time32.Now.TotalMilliseconds) / 1000);
if (value < 0) return 0;
return (ushort)value;
}
}
public TeamPk(int group, GamePackets T_ID)
{
if (!IsAlive)
{
ID = T_ID;
IsAlive = true;
Teams = new ConcurrentDictionary<uint, ConquerStructures.Team>();
Matches = new ConcurrentDictionary<uint, Match>();
GroupID = group;
var name = "TeamPk";
LoadTop8(string.Format("{0}{1}", name, GroupID));
MatchCounter = new Counter((uint)(GroupID * 100000 + 100000));
WaitingArea = Kernel.Maps[(ushort)ElitePKTournament.WaitingAreaID].MakeDynamicMap();
Constants.PKForbiddenMaps.Add(WaitingArea.ID);
Interfaces.INpc npc = new Network.GamePackets.NpcSpawn();
npc.UID = 7912;
npc.Name = "TeamPKClerk";
npc.Mesh = 1340;
npc.Type = (Enums.NpcType)2;
npc.X = 49;
npc.Y = 47;
npc.MapID = WaitingArea.ID;
WaitingArea.AddNpc(npc);
State = States.GUI_Top8Ranking;
pState = States.T_Organize;
}
}
public bool SignUp(Client.GameState client)
{
if (AllowJoin || client.Fake)
{
var coords = WaitingArea.RandomCoordinates();
client.Entity.Teleport(WaitingArea.ID, coords.Item1, coords.Item2);
if (!Teams.ContainsKey(client.Team.UID))
Teams.Add(client.Team.UID, client.Team);
client.InTeamPK = true;
Network.GamePackets.TeamPkMatchUI ui = new Network.GamePackets.TeamPkMatchUI();
{
ui.Type = Network.GamePackets.TeamPkMatchUI.Information;
ui.Append(client.Team);
client.Send(ui.ToArray());
ui.Type = 5;
client.Send(ui.ToArray());
}
if (client.Team.TeamLider(client))
{
Network.GamePackets.TeamSetName teamname = new Network.GamePackets.TeamSetName();
{
teamname.TeamID = client.Team.UID;
teamname.TeamName = client.Team.TeamFighterStats.Name;
client.Send(teamname.ToArray());
}
}
return true;
}
return false;
}
DateTime StarTimer = new DateTime();
private bool AllowJoin = false;
private IDisposable Subscriber;
public bool Organization = false;
public void SubscribeTimer(int minutes)
{
StarTimer = DateTime.Now;
StarTimer = StarTimer.AddMinutes(5);
Organization = true;
AllowJoin = true;
if (Subscriber == null)
Subscriber = World.Subscribe(timerCallback, 1000);
}
public void Purge()
{
foreach (var team in Teams.Values)
{
if (State == States.GUI_Top8Qualifier)
{
if (Teams.Count > 8)
{
if (team.TeamFighterStats.Lost || !team.OnPopulates)// && player.Entity.MyLocation.DinamicID != WaitingArea)
{
Remove(team.UID);
}
}
}
else if (team.TeamFighterStats.Lost)
{
if (Teams.Count > 8)
{
Remove(team.UID);
}
}
}
}
public static Time32 Test;
public static List<AI> Ais = new List<AI>();
public bool Started = false;
private void timerCallback(int tim)
{
try
{
if (!IsAlive)
{
TeamTournament.Opened = false;
Started = false;
Subscriber.Dispose();
return;
}
#region ReconstructTop
if (State == States.GUI_ReconstructTop)
{
if (DateTime.Now > ConstructTop8.AddMinutes(2))
{
State = States.GUI_Top8Ranking;
Kernel.SendWorldMessage(new Network.GamePackets.TeamPkBrackets() { Type = 6, OnGoing = false }.ToArray());
IsAlive = false;
}
return;
}
#endregion
DateTime Now64 = DateTime.Now;
if (Now64.Hour == (EventTime + 1) && Now64.Minute >= (3 - GroupID) * 2)
{
TeamTournament.Opened = false;
Started = true;
#region GetState
if (Organization)
{
Organization = false;
this.Top8 = new TeamPk.FighterStats[8];
for (int i = 0; i < this.Top8.Length; i++)
{
this.Top8[i] = new TeamPk.FighterStats(0u, "", 0u, null);
}
foreach (var team in Teams.Values)
{
foreach (var player in team.Players)
{
if (player != null)
{
if (player.Team != null)
{
Network.GamePackets.TeamSetName teamname = new Network.GamePackets.TeamSetName();
{
teamname.Type = Network.GamePackets.TeamSetName.SuccessfulName;
teamname.TeamID = player.Team.UID;
teamname.TeamName = player.Team.TeamFighterStats.Name;
player.Send(teamname.ToArray());
if (player.Team.TeamLider(player))
{
teamname.Type = Network.GamePackets.TeamSetName.Remove;
player.Send(teamname.ToArray());
}
}
//SkillPk A~prize~for~every~participant~in~the~Team~PK~Tournament.~Right~click~it~to~get~1~hour`s~double~EXP.
player.Inventory.Add(720793, 0, 1);
}
}
}
}
if (Teams.Count < 1)
{
foreach (var team in Teams.Values)
foreach (var player in team.Players)
player.Entity.Teleport();
Teams.Clear();
Started = false;
IsAlive = false;
Kernel.SendWorldMessage(new Network.GamePackets.SkillPkBrackets() { Type = 6, OnGoing = false }.ToArray());
return;
}
}
if (State == States.GUI_Top8Ranking)
{
willAdvance = Teams.Count > 8;
Kernel.SendWorldMessage(new Network.GamePackets.TeamPkBrackets() { Type = 6, OnGoing = true }.ToArray());
if (Teams.Count == 1)
{
Top8[0] = Teams.FirstOrDefault().Value.TeamFighterStats;
ConstructTop8 = DateTime.Now;
var name = "TeamPk";
SaveTop8(string.Format("{0}{1}", name, GroupID));
foreach (var team in Teams.Values)
foreach (var player in team.Players)
player.Entity.Teleport();
State = States.GUI_ReconstructTop;
foreach (var client in Kernel.GamePool.Values)
Rankings(client);
var brackets = CreateBrackets(ExtendedMatchArray, 0, Network.GamePackets.TeamPkBrackets.UpdateList);
foreach (var packet in brackets)
Kernel.SendWorldMessage(packet.ToArray());
Kernel.SendWorldMessage(new Network.GamePackets.TeamPkBrackets() { Type = 6, OnGoing = false }.ToArray());
}
else if (Teams.Count == 2)
{
State = States.GUI_Top1;
pState = States.T_Organize;
}
else if (Teams.Count > 2 && Teams.Count <= 4)
{
State = States.GUI_Top2Qualifier;
pState = States.T_Organize;
}
else if (Teams.Count > 4 && Teams.Count <= 8)
{
State = States.GUI_Top4Qualifier;
pState = States.T_Organize;
}
else if (willAdvance && Teams.Count <= 24)
State = States.GUI_Top8Qualifier;
else
State = States.GUI_Knockout;
}
#endregion
#region Knockout
if (State == States.GUI_Knockout)
{
AllowJoin = false;
if (pState == States.T_Organize)
{
if (willAdvance && Teams.Count <= 24)
{
State = States.GUI_Top8Qualifier;
}
else
{
MatchIndex = 0;
var array = Teams.Values.ToArray();
ushort counter = 0;
bool NoPar = array.Length % 2 == 0;
if (NoPar)
{
for (ushort x = 0; x < array.Length; x++)
{
int r = counter;
counter++;
int t = counter;
counter++;
if (counter <= array.Length)
{
Match match = new Match(array[r].TeamFighterStats, array[t].TeamFighterStats);
match.Index = MatchIndex++;
match.ID = MatchCounter.Next;
Matches.TryAdd(match.ID, match);
}
}
}
else
{
for (ushort x = 0; x < array.Length - 1; x++)
{
int r = counter;
counter++;
int t = counter;
counter++;
if (counter <= array.Length)
{
Match match = new Match(array[r].TeamFighterStats, array[t].TeamFighterStats);
match.Index = MatchIndex++;
match.ID = MatchCounter.Next;
Matches.TryAdd(match.ID, match);
}
}
Match math_bye = new Match(array[array.Length - 1].TeamFighterStats);
math_bye.Index = MatchIndex++;
math_bye.ID = MatchCounter.Next;
Matches.TryAdd(math_bye.ID, math_bye);
}
pStamp = Time32.Now.AddSeconds(60);
pState = States.T_Wait;
MatchArray = (from match in Matches.Values orderby match.MatchStats.Length descending select match).ToArray();
var brackets = CreateBrackets(MatchArray, 0);
foreach (var packet in brackets)
{
Kernel.SendWorldMessage(packet.ToArray());
}
}
}
else if (pState == States.T_Wait)
{
if (TimeLeft == 0)
{
int doneMatches = 0;
foreach (var match in MatchArray)
{
match.AliveMatch();
if (!match.Inside)
{
match.Import(Match.StatusFlag.Watchable);
}
else
{
if (!match.Exported && (match.Done || match.TimeLeft == 0))
{
match.Export();
}
if (match.Exported || match.MatchStats.Length == 1)
doneMatches++;
}
}
if (doneMatches == Matches.Count)
{
Matches.Clear();
Purge();
pState = States.T_Organize;
}
}
}
}
#endregion
#region Top8Qualifier
if (State == States.GUI_Top8Qualifier)
{
if (pState == States.T_Organize)
{
if (Teams.Count == 8)
{
State = States.GUI_Top4Qualifier;
}
else
{
MatchIndex = 0;
var array = Teams.Values.ToArray();
int[] taken = new int[array.Length];
if (array.Length <= 16)
{
ushort counter = 0;
int t1Group = array.Length - 8;
int lim = taken.Length / 2;
for (int i = 0; i < t1Group; i++)
{
int r = counter;
counter++;
int t = counter;
counter++;
Match match = new Match(array[r].TeamFighterStats, array[t].TeamFighterStats);
match.Index = MatchIndex++;
match.ID = MatchCounter.Next;
Matches.TryAdd(match.ID, match);
}
for (int i = 0; i < 8 - t1Group; i++)
{
ushort r = counter;
counter++;
Match match = new Match(array[r].TeamFighterStats);
match.Index = MatchIndex++;
match.ID = MatchCounter.Next;
Matches.TryAdd(match.ID, match);
}
}
else
{
ushort counter = 0;
int t3GroupCount = array.Length - 16;
for (int i = 0; i < t3GroupCount; i++)
{
int r = counter;
counter++;
int t = counter;
counter++;
int y = counter;
counter++;
Match match = new Match(array[r].TeamFighterStats, array[t].TeamFighterStats, array[y].TeamFighterStats);
match.Index = MatchIndex++;
match.ID = MatchCounter.Next;
Matches.TryAdd(match.ID, match);
}
int t2GroupCount = array.Length - counter;
for (int i = 0; i < t2GroupCount / 2; i++)
{
int r = counter;
counter++;
int t = counter;
counter++;
Match match = new Match(array[r].TeamFighterStats, array[t].TeamFighterStats);
match.Index = MatchIndex++;
match.ID = MatchCounter.Next;
Matches.TryAdd(match.ID, match);
}
}
pStamp = Time32.Now.AddSeconds(60);
pState = States.T_Wait;
MatchArray = (from match in Matches.Values orderby match.MatchStats.Length descending select match).ToArray();
var brackets = CreateBrackets(MatchArray, 0, Network.GamePackets.TeamPkBrackets.UpdateList);
foreach (var packet in brackets)
{
Kernel.SendWorldMessage(packet.ToArray());
}
Network.GamePackets.TeamPkBrackets brea = new Network.GamePackets.TeamPkBrackets(0);
brea.Type = Network.GamePackets.TeamPkBrackets.EPK_State;
brea.OnGoing = true;
Kernel.SendWorldMessage(brea.ToArray());
}
}
else if (pState == States.T_Wait)
{
if (TimeLeft == 0)
{
int doneMatches = 0;
foreach (var match in MatchArray)
{
match.AliveMatch();
if (!match.Inside)
{
if (match.MatchStats.Length > 1)
{
match.Import(Match.StatusFlag.Watchable);
}
else
{
match.Inside = true;
match.Completed = true;
match.Done = true;
match.MatchStats
.First(p => p != null).Team
.TeamFighterStats.Flag = FighterStats.StatusFlag.Qualified;
}
}
else
{
if (!match.Exported && (match.Done || match.TimeLeft == 0))
{
match.Export();
if (match.MatchStats.Length == 3)
match.SwitchBetween();
else
match.Flag = Match.StatusFlag.OK;
}
if (match.Exported || match.MatchStats.Length == 1)
doneMatches++;
}
}
if (doneMatches == Matches.Count)
{
bool finishedRound = true;
foreach (var match in MatchArray)
{
if (!match.Completed)
{
finishedRound = false;
break;
}
}
if (!finishedRound)
{
foreach (var match in MatchArray)
{
if (!match.Completed)
{
foreach (var stats in match.MatchStats)
stats.Reset(true);
match.Inside = false;
match.Done = false;
match.Exported = false;
if (match.MatchStats.Length != 1)
match.Flag = Match.StatusFlag.Waiting;
}
}
pStamp = Time32.Now.AddSeconds(60);
pState = States.T_Wait;
var brakets = CreateBrackets(MatchArray, 0, Network.GamePackets.TeamPkBrackets.UpdateList);
foreach (var packet in brakets)
{
Kernel.SendWorldMessage(packet.ToArray());
}
}
else
{
Matches.Clear();
Purge();
pState = States.T_Organize;
}
}
}
}
}
#endregion
#region Top4Qualifier
if (State == States.GUI_Top4Qualifier)
{
if (pState == States.T_Organize)
{
try
{
MatchIndex = 0;
var array = Teams.Values.ToArray();
int[] taken = new int[array.Length];
int lim = taken.Length / 2;
for (int i = 0; i < taken.Length; i += 2)
{
if (array.Length > i + 1)
{
Match match = new Match(array[i].TeamFighterStats, array[i + 1].TeamFighterStats);
match.Index = MatchIndex++;
//match.Flag = Match.StatusFlag.FinalMatch;
match.ID = MatchCounter.Next;
Matches.TryAdd(match.ID, match);
}
else
{
Match match = new Match(array[i].TeamFighterStats);
match.Index = MatchIndex++;
//match.Flag = Match.StatusFlag.FinalMatch;
match.ID = MatchCounter.Next;
Matches.TryAdd(match.ID, match);
}
}
pStamp = Time32.Now.AddSeconds(60);
pState = States.T_Wait;
MatchArray = Matches.Values.ToArray();
var brackets = CreateBrackets(MatchArray, 0, TeamPkBrackets.GUIEdit);
foreach (var packet in brackets)
Kernel.SendWorldMessage(packet);
brackets = CreateBrackets(MatchArray, 0, Network.GamePackets.TeamPkBrackets.UpdateList);
foreach (var packet in brackets)
Kernel.SendWorldMessage(packet.ToArray());
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
}
else if (pState == States.T_Wait)
{
if (TimeLeft == 0)
{
try
{
int doneMatches = 0;
foreach (var match in MatchArray)
{
match.AliveMatch();
if (!match.Inside)
{
match.Import(Match.StatusFlag.Watchable);
}
else
{
if (!match.Exported && (match.Done || match.TimeLeft == 0))
match.Export();
if (match.Exported)
doneMatches++;
}
}
if (doneMatches == MatchArray.Length)
{
int i = 4;
foreach (var match in MatchArray)
{
foreach (var stats in match.MatchStats)
if (stats.Flag == FighterStats.StatusFlag.Lost)
{
Top8[Math.Min(7, i++)] = stats.Clone();
}
match.Commit();
}
foreach (var list in Teams.Values)
if (list.TeamFighterStats.Lost)
{
Remove(list.UID);
}
State = States.GUI_Top8Ranking;
pState = States.T_Organize;
}
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
}
}
}
#endregion
#region Top2Qualifier
if (State == States.GUI_Top2Qualifier)
{
if (pState == States.T_Organize)
{
try
{
MatchIndex = 0;
Top4MatchArray = new Match[2];
if (MatchArray == null || MatchArray.Length == 0)
{
var array = Teams.Values.ToArray();
int[] taken = new int[array.Length];
int lim = taken.Length / 2;
int matc = 0;
for (int i = 0; i < taken.Length; i += 2)
{
if (array.Length > i + 1)
{
Match match = new Match(array[i].TeamFighterStats, array[i + 1].TeamFighterStats);
match.Index = MatchIndex++;
match.ID = MatchCounter.Next;
Top4MatchArray[matc] = match;
matc++;
Matches.TryAdd(match.ID, match);
}
else
{
Match match = new Match(array[i].TeamFighterStats);
match.Index = MatchIndex++;
match.ID = MatchCounter.Next;
Top4MatchArray[matc] = match;
Matches.TryAdd(match.ID, match);
}
}
}
else
{
for (int i = 0; i < Top4MatchArray.Length; i++)
{
if (MatchArray.Length > i + 2)
{
Match match = new Match(//p.winer este
MatchArray[i].Return(p => p.Team.TeamFighterStats.Winner),//.MatchStats.First(p => p.Team.TeamFighterStats.Winner),
MatchArray[i + 2].Return(p => p.Team.TeamFighterStats.Winner));//.MatchStats.First(p => p.Team.TeamFighterStats.Winner));
match.Index = MatchIndex++;
match.ID = MatchCounter.Next;
Top4MatchArray[i] = match;
Matches.TryAdd(match.ID, match);
}
else
{
Match match = new Match(//p.winer este
MatchArray[i].Return(p => p.Team.TeamFighterStats.Winner));//.MatchStats.First(p => p.Team.TeamFighterStats.Winner));
match.Index = MatchIndex++;
match.ID = MatchCounter.Next;
Top4MatchArray[i] = match;
Matches.TryAdd(match.ID, match);
}
}
}
pStamp = Time32.Now.AddSeconds(60);
pState = States.T_Wait;
if (MatchArray == null)
MatchArray = Matches.Values.ToArray();
var brackets = CreateBrackets(Top4MatchArray, 0, Network.GamePackets.TeamPkBrackets.UpdateList);
foreach (var packet in brackets)
Kernel.SendWorldMessage(packet.ToArray());
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
}
else if (pState == States.T_Wait)
{
if (TimeLeft == 0)
{
try
{
int doneMatches = 0;
foreach (var match in Top4MatchArray)
{
match.AliveMatch();
if (!match.Inside)
{
match.Import(Match.StatusFlag.Watchable);
}
else
{
if (!match.Exported && (match.Done || match.TimeLeft == 0))
match.Export();
if (match.Exported)
doneMatches++;
}
}
if (doneMatches == Top4MatchArray.Length)
{
List<Game.ConquerStructures.Team> list = new List<Game.ConquerStructures.Team>();
foreach (var player in Teams.Values)
if (player.TeamFighterStats.Lost)
list.Add(player);
foreach (var match in Top4MatchArray)
match.Commit();
if (list.Count == 1)
{
foreach (Game.ConquerStructures.Team current in list)
{
this.Top8[2] = current.TeamFighterStats;
Teams.Remove(current.UID);
}
this.State = States.GUI_Top8Ranking;
this.pState = States.T_Organize;
}
else
{
pState = States.T_Organize;
State = States.GUI_Top3;
}
}
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
}
}
}
#endregion
#region Top3
if (State == States.GUI_Top3)
{
if (pState == States.T_Organize)
{
try
{
MatchIndex = 0;
ExtendedMatchArray = new Match[2];
Match match = new Match(
Top4MatchArray[0].Return(p => !p.Team.TeamFighterStats.Winner),//.MatchStats.First(p => !p.Team.TeamFighterStats.Winner),
Top4MatchArray[1].Return(p => !p.Team.TeamFighterStats.Winner));//.MatchStats.First(p => !p.Team.TeamFighterStats.Winner));
match.Index = MatchIndex++;
match.ID = MatchCounter.Next;
ExtendedMatchArray[0] = match;
Matches.TryAdd(match.ID, match);
pStamp = Time32.Now.AddSeconds(60);
pState = States.T_Wait;
var brackets = CreateBrackets(ExtendedMatchArray, 0, Network.GamePackets.TeamPkBrackets.UpdateList);
foreach (var packet in brackets)
Kernel.SendWorldMessage(packet.ToArray());
Kernel.SendWorldMessage(new Network.GamePackets.TeamPkBrackets() { Type = 6, OnGoing = true }.ToArray());
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
}
else if (pState == States.T_Wait)
{
if (TimeLeft == 0)
{
try
{
var match = ExtendedMatchArray[0];
match.AliveMatch();
if (!match.Inside)
{
match.Import(Match.StatusFlag.Watchable);
}
else
{
if (!match.Exported && (match.Done || match.TimeLeft == 0))
match.Export();
if (match.Exported)
{
//var a_math =ExtendedMatchArray[0].MatchStats;
var top3 = ExtendedMatchArray[0].Return(p => p.Team.TeamFighterStats.Winner);
//.First(p => p.Team.TeamFighterStats.Winner).Team.TeamFighterStats;
var top4 = ExtendedMatchArray[0].Return(p => !p.Team.TeamFighterStats.Winner);
//ExtendedMatchArray[0].MatchStats
//.First(p => !p.Team.TeamFighterStats.Winner).Team.TeamFighterStats;
Top8[2] = top3.Clone();
Top8[3] = top4.Clone();
Remove(top3.Team.UID);
Remove(top4.Team.UID);
pState = States.T_Organize;
State = States.GUI_Top8Ranking;
}
}
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
}
}
}
#endregion
#region Top1
if (State == States.GUI_Top1)
{
if (pState == States.T_Organize)
{
try
{
ExtendedMatchArray = new Match[1];
Match match = new Match(Teams.Values.First().TeamFighterStats, Teams.Values.Last().TeamFighterStats);
match.Index = MatchIndex++;
match.ID = MatchCounter.Next;
ExtendedMatchArray[0] = match;
Matches.TryAdd(match.ID, match);
pStamp = Time32.Now.AddSeconds(60);
pState = States.T_Wait;
if (MatchArray == null)
MatchArray = Matches.Values.ToArray();
var ackets = CreateBrackets(ExtendedMatchArray, 0, Network.GamePackets.TeamPkBrackets.UpdateList);
foreach (var packet in ackets)
Kernel.SendWorldMessage(packet.ToArray());
Kernel.SendWorldMessage(new Network.GamePackets.TeamPkBrackets() { Type = 6, OnGoing = true }.ToArray());
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
}
else if (pState == States.T_Wait)
{
if (TimeLeft == 0)
{
try
{
int doneMatches = 0;
foreach (var match in ExtendedMatchArray)
{
match.AliveMatch();
if (!match.Inside)
{
match.Import(Match.StatusFlag.Watchable);
}
else
{
if (!match.Exported && (match.Done || match.TimeLeft == 0))
match.Export();
if (match.Exported)
doneMatches++;
}
}
if (doneMatches == ExtendedMatchArray.Length)
{
try
{
var top1 = ExtendedMatchArray[0].MatchStats
.First(p => p.Team.TeamFighterStats.Winner).Team.TeamFighterStats;
var top2 = ExtendedMatchArray[0].MatchStats
.First(p => !p.Team.TeamFighterStats.Winner).Team.TeamFighterStats;
Top8[0] = top1;
Top8[1] = top2;
Started = false;
ConstructTop8 = DateTime.Now;
var name = "TeamPk";
SaveTop8(string.Format("{0}{1}", name, GroupID));
foreach (var team in Teams.Values)
foreach (var player in team.Players)
player.Entity.Teleport();
State = States.GUI_ReconstructTop;
foreach (var client in Kernel.GamePool.Values)
Rankings(client);
var brackets = CreateBrackets(ExtendedMatchArray, 0, Network.GamePackets.TeamPkBrackets.UpdateList);
foreach (var packet in brackets)
Kernel.SendWorldMessage(packet.ToArray());
Kernel.SendWorldMessage(new Network.GamePackets.TeamPkBrackets() { Type = 6, OnGoing = false }.ToArray());
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
}
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
}
}
}
#endregion
}
}
catch (Exception e)
{ Console.WriteLine(e.ToString()); }
}
public void FireArena(bool online = false)
{
Kernel.SendWorldMessage(new Network.GamePackets.TeamPkBrackets() { Type = 6, OnGoing = online }.ToArray());
}
public void Update(Client.GameState client, int page = 0)
{
try
{
if (State == States.GUI_Top8Ranking)
{
Rankings(client);
}
else
{
if (State >= States.GUI_Top4Qualifier)
{
var brackets = CreateBrackets(MatchArray, 0, Network.GamePackets.SkillPkBrackets.GUIEdit);
foreach (var packet in brackets)
client.Send(packet.ToArray());
}
else
{
var brackets = CreateBrackets(MatchArray, page);
foreach (var packet in brackets)
client.Send(packet.ToArray());
}
if (State >= States.GUI_Top1)
Rankings(client);
}
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
}
public bool GetReward(Client.GameState client, out byte Rank)
{
if (Top8.Length == 8)
{
for (int x = 0; x < Top8.Length; x++)
{
if (Top8[x] != null)
{
if (Top8[x].LeaderUID == client.Entity.UID || Top8[x].Name == client.Entity.Name)
{
if (Top8[x].RceiveReward == 0)
{
Top8[x].RceiveReward = 1;
Rank = (byte)(x + 1);
return true;
}
else
{
Rank = (byte)(x + 1);
return false;
}
}
}
}
}
Rank = 0;
return false;
}
public static bool GetReward(Client.GameState client)
{
if (!client.Inventory.HaveSpace(1))
{
client.MessageBox("Please Empty Some Space First");
return false;
}
foreach (var tournament in TeamPk.TeamTournament.Tournaments)
{
byte Rank = 0;
if (tournament.GetReward(client, out Rank))
{
var name = "TeamPk";
tournament.SaveTop8(string.Format("{0}{1}", name, tournament.GroupID));
uint ItemID = GetItemID(tournament, Rank);
if (client.Entity.Level >= 100 || client.Entity.Level >= 120 || client.Entity.Level >= 130)
{
if (Rank == 1)
{
client.Entity.ConquerPoints += 250000000;
client.Entity.AddTopStatus((ulong)XMeGo.Network.GamePackets.TitlePacket.Titles.ElitePKChamption_Low, 0, DateTime.Now.AddDays(1), true);
client.MessageBox("You've received [" + 250000000 + "] ConquerPoints");
string MSG = "Congratulation to " + client.Entity.Name + " ! he/she managed to get rank " + Rank + " on Team Pk Tournament and claimed [" + 250000000 + "] ConquerPoints ";
Kernel.SendWorldMessage(new Message(MSG, System.Drawing.Color.Red, Message.System));
XMeGo.Kernel.SendWorldMessage(new Message("Congratulation to " + client.Entity.Name + " ! he/she managed to get rank " + Rank + " on Team Pk Tournament and claimed [" + 250000000 + "] ConquerPoints ", System.Drawing.Color.Black, Message.Center), Program.Values);
}
else if (Rank == 2)
{
client.Entity.ConquerPoints += 200000000;
client.Entity.AddTopStatus((ulong)XMeGo.Network.GamePackets.TitlePacket.Titles.ElitePK2ndPlace_Low, 0, DateTime.Now.AddDays(1), true);
client.MessageBox("You've received [" + 200000000 + "] ConquerPoints");
string MSG = "Congratulation to " + client.Entity.Name + " ! he/she managed to get rank " + Rank + " on Team Pk Tournament and claimed [" + 200000000 + "] ConquerPoints ";
Kernel.SendWorldMessage(new Message(MSG, System.Drawing.Color.Red, Message.System));
XMeGo.Kernel.SendWorldMessage(new Message("Congratulation to " + client.Entity.Name + " ! he/she managed to get rank " + Rank + " on Team Pk Tournament and claimed [" + 200000000 + "] ConquerPoints ", System.Drawing.Color.Black, Message.Center), Program.Values);
}
else if (Rank == 3)
{
client.Entity.ConquerPoints += 150000000;
client.Entity.AddTopStatus((ulong)XMeGo.Network.GamePackets.TitlePacket.Titles.ElitePK3ndPlace_Low, 0, DateTime.Now.AddDays(1), true);
client.MessageBox("You've received [" + 150000000 + "] ConquerPoints");
string MSG = "Congratulation to " + client.Entity.Name + " ! he/she managed to get rank " + Rank + " on Team Pk Tournament and claimed [" + 150000000 + "] ConquerPoints ";
Kernel.SendWorldMessage(new Message(MSG, System.Drawing.Color.Red, Message.System));
XMeGo.Kernel.SendWorldMessage(new Message("Congratulation to " + client.Entity.Name + " ! he/she managed to get rank " + Rank + " on Team Pk Tournament and claimed [" + 150000000 + "] ConquerPoints ", System.Drawing.Color.Black, Message.Center), Program.Values);
}
else
{
client.Entity.ConquerPoints += 100000000;
client.Entity.AddTopStatus((ulong)XMeGo.Network.GamePackets.TitlePacket.Titles.ElitePKTopEight_Low, 0, DateTime.Now.AddDays(1), true);
client.MessageBox("You've received [" + 100000000 + "] ConquerPoints");
string MSG = "Congratulation to " + client.Entity.Name + " ! he/she managed to get rank " + Rank + " on Team Pk Tournament and claimed [" + 100000000 + "] ConquerPoints ";
Kernel.SendWorldMessage(new Message(MSG, System.Drawing.Color.Red, Message.System));
XMeGo.Kernel.SendWorldMessage(new Message("Congratulation to " + client.Entity.Name + " ! he/she managed to get rank " + Rank + " on Team Pk Tournament and claimed [" + 100000000 + "] ConquerPoints ", System.Drawing.Color.Black, Message.Center), Program.Values);
}
}
return true;
}
}
return false;
}
public static uint GetItemID(TeamPk tournament, byte Rank)
{
return (uint)(720794 + 1 * (byte)tournament.GroupID + Math.Min(3, (Rank - 1)) * 4);
}
public void Rankings(Client.GameState client)
{
Network.GamePackets.TeamPkTop ranks = new Network.GamePackets.TeamPkTop();
{
ranks.Type = Network.GamePackets.TeamPkTop.Top8;
ranks.Group = (uint)GroupID;
ranks.GroupStatus = (uint)State;
//ranks.UID = client.Entity.UID;
if (State >= States.GUI_Top1)
{
ranks.Type = Network.GamePackets.TeamPkTop.Top3;
if (State == States.GUI_Top1)
{
ranks.Count = 1;
ranks.AppendTeamPK(Top8[2], 2);
}
else
{
ranks.Count = 3;
for (int i = 0; i < 3; i++)
{
ranks.AppendTeamPK(Top8[i], i);
}
}
client.Send(ranks.ToArray());
}
else
{
ranks.Count = (uint)Top8.Length;
for (int i = 0; i < ranks.Count; i++)
if (Top8[i] != null)
{
ranks.AppendTeamPK(Top8[i], i);
}
client.Send(ranks.ToArray());
}
}
}
public Network.GamePackets.TeamPkBrackets[] CreateBrackets(Match[] matches, int page = 0, byte type = 0)
{
try
{
int lim = 0, count = 0;
if (matches == null) return new Network.GamePackets.TeamPkBrackets[0];
if (State == States.GUI_Knockout)
{
const int max = 5;
int offset = page * max;
int Do_count = matches.Length - page * max;
if (page * max > matches.Length)
Do_count = 0;
uint ccount = (uint)Math.Min(max, Do_count);
Network.GamePackets.TeamPkBrackets brackets = new Network.GamePackets.TeamPkBrackets((int)ccount);
brackets.Group = (ushort)GroupID;
brackets.GUIType = (ushort)State;
brackets.TotalMatchesOnRoom = (ushort)ccount;
brackets.Page = (byte)page;
brackets.TimeLeft = TimeLeft;
brackets.MatchCount = (ushort)matches.Length;
brackets.Type = type;
for (int i = 0; i < ccount; i++)
{
var element = matches[i + offset];
brackets.Append(element);
}
Network.GamePackets.TeamPkBrackets[] buffer = new Network.GamePackets.TeamPkBrackets[1];
buffer[0] = brackets;
return buffer;
}
else if (State == States.GUI_Top8Qualifier)
{
const int max = 5;
int offset = page * max;
int Do_count = matches.Length - page * max;
if (page * max > matches.Length)
Do_count = 0;
uint ccount = (uint)Math.Min(max, Do_count);
Network.GamePackets.TeamPkBrackets[] buffer;
if (matches.Length > ccount)
buffer = new Network.GamePackets.TeamPkBrackets[2];
else
buffer = new Network.GamePackets.TeamPkBrackets[1];
Network.GamePackets.TeamPkBrackets brackets = new Network.GamePackets.TeamPkBrackets((int)ccount);
brackets.Group = (ushort)GroupID;
brackets.GUIType = (ushort)State;
brackets.TotalMatchesOnRoom = (ushort)ccount;
brackets.Page = (byte)page;
brackets.TimeLeft = TimeLeft;
brackets.MatchCount = (ushort)matches.Length;
brackets.Type = type;
for (int i = 0; i < ccount; i++)
{
var element = matches[i + offset];
brackets.Append(element);
}
buffer[0] = brackets;
if (matches.Length > ccount)
{
ushort towcount = (ushort)(matches.Length - ccount);
Network.GamePackets.TeamPkBrackets twobrackets = new Network.GamePackets.TeamPkBrackets((int)towcount);
twobrackets.Group = (ushort)GroupID;
twobrackets.GUIType = (ushort)State;
twobrackets.TotalMatchesOnRoom = (ushort)towcount;
twobrackets.Page = (byte)page;
twobrackets.TimeLeft = TimeLeft;
twobrackets.ListCount = 1;
twobrackets.MatchCount = (ushort)matches.Length;
twobrackets.Type = type;
for (int i = 0; i < towcount; i++)
{
var element = matches[i + ccount];
twobrackets.Append(element);
}
buffer[1] = twobrackets;
return buffer;
}
return buffer;
}
lim = matches.Length;
count = Math.Min(lim, matches.Length - page * lim);
if (State >= States.GUI_Top2Qualifier)
{
Network.GamePackets.TeamPkBrackets[] buffer = new Network.GamePackets.TeamPkBrackets[2];
lim = MatchArray.Length;
count = Math.Min(lim, MatchArray.Length - page * lim);
Network.GamePackets.TeamPkBrackets qbrackets = new Network.GamePackets.TeamPkBrackets(count);
{
qbrackets.Group = (ushort)GroupID;
qbrackets.GUIType = (ushort)State;
qbrackets.TotalMatchesOnRoom = (ushort)(count);
qbrackets.Page = (byte)page;
qbrackets.TimeLeft = TimeLeft;
qbrackets.MatchCount = (byte)(MatchArray.Length * 2);
qbrackets.Type = type;
for (int i = page * lim; i < page * lim + count; i++)
qbrackets.Append(MatchArray[i]);
buffer[0] = qbrackets;
}
if (State >= States.GUI_Top3)
{
Network.GamePackets.TeamPkBrackets Twoqbrackets = new Network.GamePackets.TeamPkBrackets(count);
if (Top4MatchArray != null)
{
lim = 4;
count = (byte)(Top4MatchArray.Length + ExtendedMatchArray.Length);
{
Twoqbrackets.Group = (ushort)GroupID;
Twoqbrackets.GUIType = (ushort)State;
Twoqbrackets.TotalMatchesOnRoom = (ushort)count;
Twoqbrackets.Page = (byte)1;
Twoqbrackets.TimeLeft = TimeLeft;
Twoqbrackets.MatchCount = (byte)((Top4MatchArray.Length + ExtendedMatchArray.Length) * 2);
Twoqbrackets.Type = type;
for (int i = 0; i < 2; i++)
Twoqbrackets.Append(Top4MatchArray[i]);
for (int x = 0; x < ExtendedMatchArray.Length; x++)
Twoqbrackets.Append(ExtendedMatchArray[x]);
buffer[1] = Twoqbrackets;
}
buffer[1] = Twoqbrackets;
}
else
{
lim = 4;
count = (byte)(ExtendedMatchArray.Length);
{
Twoqbrackets.Group = (ushort)GroupID;
Twoqbrackets.GUIType = (ushort)State;
Twoqbrackets.TotalMatchesOnRoom = (ushort)count;
Twoqbrackets.Page = (byte)1;
Twoqbrackets.TimeLeft = TimeLeft;
Twoqbrackets.MatchCount = (byte)((ExtendedMatchArray.Length) * 2);
Twoqbrackets.Type = type;
for (int x = 0; x < ExtendedMatchArray.Length; x++)
Twoqbrackets.Append(ExtendedMatchArray[x]);
buffer[1] = Twoqbrackets;
}
buffer[1] = Twoqbrackets;
}
}
else
{
lim = 2;
count = Top4MatchArray.Length;
Network.GamePackets.TeamPkBrackets Twoqbrackets = new Network.GamePackets.TeamPkBrackets(count);
{
Twoqbrackets.Group = (ushort)GroupID;
Twoqbrackets.GUIType = (ushort)State;
// Twoqbrackets.ListCount = 1;
Twoqbrackets.TotalMatchesOnRoom = (ushort)count;
Twoqbrackets.Page = (byte)1;
Twoqbrackets.TimeLeft = TimeLeft;
Twoqbrackets.MatchCount = (byte)MatchArray.Length;
Twoqbrackets.Type = type;
for (int i = page * lim; i < page * lim + count; i++)
Twoqbrackets.Append(Top4MatchArray[i]);
buffer[1] = Twoqbrackets;
}
}
return buffer;
}
Network.GamePackets.TeamPkBrackets aqbrackets = new Network.GamePackets.TeamPkBrackets(count);
{
aqbrackets.Group = (ushort)GroupID;
aqbrackets.GUIType = (ushort)State;
aqbrackets.TotalMatchesOnRoom = (ushort)count;
aqbrackets.Page = (byte)page;
aqbrackets.TimeLeft = TimeLeft;
aqbrackets.MatchCount = (ushort)matches.Length;
aqbrackets.Type = type;
for (int i = page * lim; i < page * lim + count; i++)
aqbrackets.Append(matches[i]);
Network.GamePackets.TeamPkBrackets[] buffer = new Network.GamePackets.TeamPkBrackets[1];
buffer[0] = aqbrackets;
return buffer;
}
}
catch (Exception e) { Console.WriteLine(e.ToString()); return new Network.GamePackets.TeamPkBrackets[0]; }
}
}
}
public class TeamPkBrackets
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using XMeGo.Game;
using XMeGo.Client;
using XMeGo.Game.Features.Tournaments;
namespace XMeGo.Network.GamePackets
{
public class TeamPkBrackets : Writer, Interfaces.IPacket
{
public const byte
InitialList = 0,
StaticUpdate = 1,
GUIEdit = 2,
UpdateList = 3,
RequestInformation = 4,
StopWagers = 5,
EPK_State = 6;
byte[] Buffer;
public TeamPkBrackets(int matches = 0)
{
{
if (matches > 5)
return;
Buffer = new byte[198 + 166 * matches];
WriteUInt16((ushort)(Buffer.Length - 8), 0, Buffer);
WriteUInt16((ushort)2232, 2, Buffer);
}
}
public byte Type
{
get { return Buffer[4]; }
set { Buffer[4] = value; }
}
public byte Page
{
get { return Buffer[6]; }
set { Buffer[6] = value; }
}
public byte ListCount
{
get { return Buffer[8]; }
set { Buffer[8] = value; }
}
public uint MatchCount
{
get { return BitConverter.ToUInt32(Buffer, 10); }
set { WriteUInt32(value, 10, Buffer); }
}
public ushort Group
{
get { return BitConverter.ToUInt16(Buffer, 14); }
set { WriteUInt16(value, 14, Buffer); }
}
public ushort GUIType
{
get { return BitConverter.ToUInt16(Buffer, 16); }
set { WriteUInt16(value, 16, Buffer); }
}
public ushort TimeLeft
{
get { return BitConverter.ToUInt16(Buffer, 18); }
set { WriteUInt16(value, 18, Buffer); }
}
public uint TotalMatchesOnRoom
{
get { return BitConverter.ToUInt16(Buffer, 20); }
set { WriteUInt32(value, 20, Buffer); }
}
public bool OnGoing
{
get { return Buffer[20] == 1; }
set { WriteBoolean(value, 20, Buffer); }
}
private int offset = 24;
public void Append(TeamPk.Match match)
{
try
{
if (match == null)
{
return;
}
if (Type != GUIEdit)
{
WriteUint(match.ID, offset, Buffer);
}
offset += 4;
WriteUshort((ushort)match.MatchStats.Length, offset, Buffer); offset += 2;
WriteUshort((ushort)match.Index, offset, Buffer); offset += 2;
WriteUshort((ushort)match.Flag, offset, Buffer);
offset += 2;
for (int i = 0; i < match.MatchStats.Length; i++)
{
AppendPlayer(match.MatchStats[i], offset);
offset += 52;
}
if (match.MatchStats.Length == 2) offset += 52;
if (match.MatchStats.Length == 1) offset += 104;
}
catch (Exception e) { Console.WriteLine(e.ToString()); }
}
private void AppendPlayer(TeamPk.FighterStats stats, int _offset)
{
WriteUint(0, _offset, Buffer); _offset += 4;
WriteUint(stats.Team.UID, _offset, Buffer); _offset += 4;
WriteUint(stats.LeaderUID, _offset, Buffer); _offset += 4;
WriteUint(stats.LeaderMesh, _offset, Buffer); _offset += 4;
WriteString(stats.Name, _offset, Buffer); _offset += 32;
WriteUint((uint)stats.Flag, _offset, Buffer); _offset += 4;
}
public void Send(GameState client)
{
client.Send(Buffer);
}
public byte[] ToArray()
{
return Buffer;
}
public void Deserialize(byte[] buffer)
{
Buffer = buffer;
}
}
}
public class TeamPkTop
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace XMeGo.Network.GamePackets
{
public class TeamPkTop : Writer
{
byte[] packet;
public byte[] ToArray()
{
return packet;
}
public const byte Top3 = 2, Top8 = 0;
public TeamPkTop()
{
packet = new byte[464];//Old 452
WriteUInt16((ushort)(packet.Length - 8), 0, packet);
WriteUInt16(2233, 2, packet);
}
public uint Type { get { return BitConverter.ToUInt32(packet, 4); } set { WriteUInt32(value, 4, packet); } }//top 3, top 8
public uint Group { get { return BitConverter.ToUInt32(packet, 8); } set { WriteUInt32(value, 8, packet); } }//8
public uint GroupStatus { get { return BitConverter.ToUInt32(packet, 12); } set { WriteUInt32(value, 12, packet); } }
public uint Count { get { return BitConverter.ToUInt32(packet, 16); } set { WriteUInt32(value, 16, packet); } }
public uint ClientUID { get { return BitConverter.ToUInt32(packet, 20); } set { WriteUInt32(value, 20, packet); } }
private int Index = 0;
public void Appendxx(Game.Features.Tournaments.TeamPk.FighterStats stats, int rank)
{
ushort offset = (ushort)(20 + Index * 44); Index++;
WriteUInt32(stats.LeaderUID, offset, packet); offset += 4;
WriteUInt32((uint)rank, offset, packet); offset += 4;
WriteString(stats.Name, offset, packet); offset += 32;
WriteUInt32(stats.LeaderMesh, offset, packet); offset += 4;
}
public void AppendTeamPK(Game.Features.Tournaments.TeamPk.FighterStats stats, int rank)
{
rank += 1;
ushort offset = (ushort)(24 + Index * 48); Index++;
WriteUInt32(stats.LeaderUID, offset, packet); offset += 4;
WriteUInt32((uint)rank, offset, packet); offset += 4;
WriteString(stats.Name, offset, packet); offset += 32;
WriteUInt32(stats.LeaderMesh, offset, packet); offset += 4;
}
}
}
public class TeamPkMatchUI
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using XMeGo.Client;
using XMeGo.Game.Features.Tournaments;
namespace XMeGo.Network.GamePackets
{
public class TeamPkMatchUI : Writer, Interfaces.IPacket
{
public const byte
BeginMatch = 2,
Effect = 3,
EndMatch = 4,
Information = 7,
Reward = 8;
public const uint
Effect_Win = 1,
Effect_Lose = 0;
byte[] Buffer;
public TeamPkMatchUI()
{
{
Buffer = new byte[52 + 8];
WriteUInt16(52, 0, Buffer);
WriteUshort((ushort)2230, 2, Buffer);
}
}
public uint Type
{
get { return BitConverter.ToUInt32(Buffer, 4); }
set { WriteUInt32(value, 4, Buffer); }
}
public uint dwParam
{
get { return BitConverter.ToUInt32(Buffer, 8); }
set { WriteUInt32(value, 8, Buffer); }
}
public uint OpponentUID
{
get { return BitConverter.ToUInt32(Buffer, 12); }
set { WriteUInt32(value, 12, Buffer); }
}
public string OpponentName
{
get { return Program.Encoding.GetString(Buffer, 16, 16).Trim(); }
set { WriteString(value, 16, Buffer); }
}
public uint TimeLeft
{
get { return BitConverter.ToUInt32(Buffer, 48); }
set { WriteUInt32(value, 48, Buffer); }
}
public void Append(Game.ConquerStructures.Team opponent)
{
OpponentUID = opponent.Lider.Entity.UID;
if (opponent.TeamFighterStats != null)
OpponentName = opponent.TeamFighterStats.Name;
}
public void Send(GameState client)
{
client.Send(Buffer);
}
public byte[] ToArray()
{
return Buffer;
}
public void Deserialize(byte[] buffer)
{
Buffer = buffer;
}
}
}
public class TeamPkMatchStats
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using XMeGo.Client;
using XMeGo.Game;
using XMeGo.Game.Features.Tournaments;
namespace XMeGo.Network.GamePackets
{
public class TeamPkMatchStats : Writer, Interfaces.IPacket
{
byte[] Buffer;
public TeamPkMatchStats()
{
Buffer = new byte[136 + 8];
WriteUInt16(136, 0, Buffer);
WriteUshort((ushort)2231, 2, Buffer);
}
public void Append(TeamPk.Match match)
{
ushort offset = 8;
var array = match.MatchStats.Where(p => p.Fighting).ToArray();
AppendPlayer(array[0], offset); offset = 72;//60
if (array.Length > 1)
AppendPlayer(array[1], offset);
}
public uint val1 = 0;
public uint val2 = 0;
public uint val3 = 0;
public uint val4 = 0;
private void AppendPlayer(TeamPk.FighterStats team, ushort offset)
{
WriteUint(team.LeaderUID, offset, Buffer); offset += 4;
WriteUint(team.Team.UID, offset, Buffer); offset += 4;
WriteString(team.Team.Lider.Entity.Name, offset, Buffer); offset += 16;//???
WriteString(team.Name, offset, Buffer); offset += 32;
WriteUint(team.Points, offset, Buffer);
}
public void Send(GameState client)
{
client.Send(Buffer);
}
public byte[] ToArray()
{
return Buffer;
}
public void Deserialize(byte[] buffer)
{
Buffer = buffer;
}
}
}
#region Teampk
case 8158:
{
switch (npcRequest.OptionID)
{
case 0:
{
dialog.Text("Attention! The Team Pk Tournament will be held every Day at 18.55. The Top 8");
dialog.Text(" teams will be handsomely rewarded, and each player in the team can");
dialog.Text(" receive EXP and 1,000 Honor Points affter each match.");
dialog.Option("What about the rules? ", 1);
dialog.Option("Sign up!", 2);
dialog.Option("Claim prize", 3);
dialog.Option("Leave.", 255);
dialog.Send();
break;
}
case 3:
{
if (client.ClaimedTeampk == 1)
{
dialog.Text("You really get your prizes.");
dialog.Option("Oh Sorry.", 255);
dialog.Avatar(26);
dialog.Send();
break;
}
else
{
if (Game.Features.Tournaments.TeamPk.GetReward(client))
{
client.ClaimedTeampk = 1;
}
else
{
dialog.Text("Sorry, just the lider of 8 top teams will receive the reward!");
dialog.Option("Ok thx.", 255);
dialog.Send();
}
break;
}
}
case 1:
{
dialog.Text("The Team Pk Tournament start at 18.55 every Day, and teams will be divided");
dialog.Text(" into four grups: Level 1-99, Level 100-119, level 120-129 and level 130+ ");
dialog.Text(" Only teams can participate in this Tournament . You can either create a team");
dialog.Text(" befor signin up, or enter the waiting area and create you team. At the start of the");
dialog.Text(" Tournament, any player who`s not in team will be removed from the tournament map.");
dialog.Text(" Where the Tournament ends, only the team leaders of the winning teams can claim the reward.");
dialog.Option("Ok Thanks you!", 255);
dialog.Send();
break;
}
case 2:
{
if (Game.Features.Tournaments.TeamPk.TeamTournament.Opened)
{
if (client.Team != null)
{
if (client.Team.RightTeamElite())
{
if (!Game.Features.Tournaments.TeamPk.TeamTournament.Join(client, client.Team.GetEliteGroup(client.Entity.Level)))
{
dialog.Text("Sorry, but your tournament on grup was staring..");
dialog.Option("Ok thx.", 255);
dialog.Send();
}
}
else
{
dialog.Text("I'm sorry, but your Team must have players with the same level and in the same internships.");
dialog.Text("Exemple: ( full 100-, or full 100-120, or full 120-130, or full 130+)");
dialog.Option("Ok thx.", 255);
dialog.Send();
}
}
else
{
dialog.Text("Please create team");
dialog.Option("Ok thx.", 255);
dialog.Send();
}
}
else
{
dialog.Text("Aha! Can`t wait right? The Team Pk Tournament has not started, yet. Come");
dialog.Text(" see me at 18:55, this Every Day. I can send you the field before the tournament starts at 19:00");
dialog.Option("Ok See, you then!.", 255);
dialog.Send();
}
break;
}
}
break;
}
#endregion
#region TeamPk
if (((Now64.Hour == TeamPk.EventTime) && Now64.Minute >= 55) && !TeamPk.TeamTournament.Opened)
Game.Features.Tournaments.TeamPk.TeamTournament.Open();
#endregion
public class SkillPkStatus
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.Concurrent;
using XMeGo.Network.GamePackets;
using System.IO;
using XMeGo.Database;
namespace XMeGo.Game.Features.Tournaments
{
public class SkillPkStatus
{
public static int EventTime = 21;
public void GetSkillPkReward(Client.GameState client, byte Rank)
{
uint ITEM_ID = 0;
switch (Rank)
{
case 0:
ITEM_ID = (uint)(720794 + GetTeamGroup(client.Entity.Level));
break;
case 1:
ITEM_ID = (uint)(720798 + GetTeamGroup(client.Entity.Level));
break;
case 2:
ITEM_ID = (uint)(720802 + GetTeamGroup(client.Entity.Level));
break;
default:
ITEM_ID = (uint)(720806 + GetTeamGroup(client.Entity.Level));
break;
}
client.Inventory.Add(ITEM_ID, 0, 1);
}
public static byte[] BlockOpenArena = new byte[] { 20, 0, 86, 4, 255, 87, 14, 0, 160, 187, 13, 0, 103, 0, 21, 64, 204, 17, 0, 0, 84, 81, 83, 101, 114, 118, 101, 114 };
public byte GetTeamGroup(byte level)
{
if (level >= 130)
return 3;
if (level >= 120)
return 3;
if (level >= 100)
return 1;
else
return 0;
}
public enum top_typ
{
Elite_PK_Champion__Low_ = 12,
Elite_PK_2nd_Place_Low_ = 13,
Elite_PK_3rd_Place_Low_ = 14,
Elite_PK_Top_8__Low_ = 15,
Elite_PK_Champion_High_ = 16,
Elite_PK_2nd_Place_High_ = 17,
Elite_PK_3rd_Place__High_ = 18,
Elite_PK_Top_8_High_ = 19
}
public class States
{
public const byte
GUI_Top8Ranking = 0,
GUI_Knockout = 3,
GUI_Top8Qualifier = 4,
GUI_Top4Qualifier = 5,
GUI_Top2Qualifier = 6,
GUI_Top3 = 7,
GUI_Top1 = 8,
GUI_ReconstructTop = 9;
public const byte
T_Organize = 0,
T_CreateMatches = 1,
T_Wait = 2,
T_Fights = 3,
T_Finished = 4,
T_ReOrganize = 5;
}
}
public class SkillPk : SkillPkStatus
{
public enum GamePackets : ushort
{
SkillEliteSetTeamName = 2260,
SkillElitePkTop = 2253,
SkillElitePkBrackets = 2252,
SkillElitePKMatchStats = 2251,
SkillElitePKMatchUI = 2250,
TeamEliteSetTeamName = 2240,
SkillPkTop = 2233,
SkillPkBrackets = 2232,
SkillPkMatchStats = 2231,
SkillPkMatchUI = 2230,
}
public class SkillTournament
{
public static uint WaitingAreaID = 2068;
public static SkillPk[] Tournaments;
public static bool Opened = false;
public static void Create()
{
try
{
Tournaments = new SkillPk[4];
for (byte x = 0; x < Tournaments.Length; x++)
Tournaments[x] = new SkillPk(x);
// LoadTop(Tournaments, "SkillPkTop8");
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
}
public static void Save()
{
// SaveTop(Tournaments, "SkillPkTop8");
}
public static bool GetReward(Client.GameState client, out byte rank, out byte elitestage)
{
if (Tournaments != null)
for (byte x = 0; x < Tournaments.Length; x++)
{
if (Tournaments[x] != null)
{
if (Tournaments[x].Top8 != null)
{
for (byte i = 0; i < Tournaments[x].Top8.Length; i++)
{
if (Tournaments[x].Top8[i] != null)
{
if (Tournaments[x].Top8[i].LeaderUID == client.Entity.UID)
{
if (Tournaments[x].Top8[i].RceiveReward == 0)
{
rank = (byte)(i + 1);
elitestage = x;
Tournaments[x].Top8[i].RceiveReward = 1;
return true;
}
}
}
}
}
}
}
rank = 0;
elitestage = 0;
return false;
}
public static void Open()
{
if (!Opened)
{
Opened = true;
for (byte x = 0; x < Tournaments.Length; x++)
{
Tournaments[x].SubscribeTimer(1);
Tournaments[x].AllowJoin = true;
}
Kernel.SendWorldMessage(new Message("The Skill Team PK Tournament will start at 22:00. Prepare Yourself And Sign Up For It As a Team.", System.Drawing.Color.White, Message.BroadcastMessage), Program.Values);
foreach (var client in Program.Values)
{
client.ClaimedSkillTeam = 0;
client.MessageBox("The Skill Team PK Tournament began Would you like to join?",
p => { p.Entity.Teleport(1002, 308, 148); }, null, 60);
}
}
}
public static bool Join(Client.GameState client, byte Grope)
{
if (client.Team == null)
return false;
if (Grope <= 3)
{
client.Team.SetSkillFighterStats(true);
return Tournaments[Grope].SignUp(client);
}
return false;
}
}
private void SaveTop8(string epk)
{
try
{
int len = Top8.Count(p => p.LeaderUID != 0);
var stream = new MemoryStream();
var writer = new BinaryWriter(stream);
writer.Write(len);
for (int i = 0; i < len; i++)
{
writer.Write(Top8[i].LeaderUID);
writer.Write(Top8[i].Name);
writer.Write(Top8[i].LeaderMesh);
writer.Write(Top8[i].Rank);
writer.Write(Top8[i].Title);
writer.Write(Top8[i].RceiveReward);
}
string SQL = "UPDATE `matrixvariable` SET data=@data where ID = '" + epk + "' ;";
byte[] rawData = stream.ToArray();
using (var conn = DataHolder.MySqlConnection)
{
conn.Open();
using (var cmd = new MySql.Data.MySqlClient.MySqlCommand())
{
cmd.Connection = conn;
cmd.CommandText = SQL;
cmd.Parameters.AddWithValue("@data", rawData);
cmd.ExecuteNonQuery();
}
}
}
catch (Exception)
{
Console.WriteLine("Error SkillPk.cs");
}
}
private void LoadTop8(string epk)
{
try
{
Top8 = new FighterStats[8];
using (var cmd = new MySqlCommand(MySqlCommandType.SELECT))
{
cmd.Select("matrixvariable").Where("ID", epk);
using (MySqlReader rdr = new MySqlReader(cmd))
{
if (rdr.Read())
{
byte[] data = rdr.ReadBlob("data");
if (data.Length > 0)
{
using (var stream = new MemoryStream(data))
using (var reader = new BinaryReader(stream))
{
int len = reader.ReadInt32();
for (int i = 0; i < len; i++)
{
Top8[i] = new FighterStats(reader.ReadUInt32(), reader.ReadString(), reader.ReadUInt32(), null);
Top8[i].Rank = reader.ReadByte();
Top8[i].Title = reader.ReadByte();
Top8[i].RceiveReward = reader.ReadByte();
}
}
}
}
else
{
using (var command = new MySqlCommand(MySqlCommandType.INSERT))
{
command.Insert("matrixvariable").Insert("ID", epk);
command.Execute();
}
}
}
}
}
catch (Exception e)
{
Console.WriteLine(e);
}
}
public class FighterStats
{
public enum StatusFlag : int
{
None = 0,
Fighting = 2,
Lost = 4,
Qualified = 3,
Waiting = 1,
}
public Game.ConquerStructures.Team Team;
public string Name;
public uint LeaderUID;
public uint LeaderMesh;
public bool OnNextMatch = false;
public uint Cheers;
public uint Points;
public StatusFlag Flag;
public bool Teleported;
public byte RceiveReward;
public byte Title;
public byte Rank;
public bool Waiting { get { return Flag == StatusFlag.Waiting; } }
public bool NoFlag { get { return Flag == StatusFlag.None; } }
public bool Fighting { get { return Flag == StatusFlag.Fighting; } }
public bool Winner { get { return Flag == StatusFlag.Qualified; } }
public bool Lost { get { return Flag == StatusFlag.Lost; } }
public FighterStats(uint id, string name, uint mesh, Game.ConquerStructures.Team temate)
{
LeaderUID = id;
Name = name;
LeaderMesh = mesh;
Team = temate;
}
public void Reset(bool noflag = false)
{
Points = 0;
Cheers = 0;
if (!noflag)
{
if (!Lost)
Flag = StatusFlag.Waiting;
}
}
public FighterStats Clone()
{
FighterStats stats = new FighterStats(LeaderUID, Name, LeaderMesh, Team);
stats.Points = this.Points;
stats.Flag = this.Flag;
return stats;
}
public override string ToString()
{
if (Name.Contains('^'))
Name.Replace("^", "");
if (Name.Contains('#'))
Name.Replace('#', ' ');
StringBuilder build = new StringBuilder();
build.Append(LeaderUID + "#" + Name + "#" + LeaderMesh + "#" + Rank + "#" + Title + "#" + RceiveReward + "");
return build.ToString();
}
public void Load(string Line)
{
string[] data = Line.Split('#');
LeaderUID = uint.Parse(data[0]);
Name = data[1];
LeaderMesh = uint.Parse(data[2]);
Rank = byte.Parse(data[3]);
Title = byte.Parse(data[4]);
RceiveReward = byte.Parse(data[5]);
}
}
public class Match
{
public enum StatusFlag : int
{
SwitchOut = 0,
Watchable = 1,
Waiting = 3,
OK = 2,
}
public IEnumerable<Client.GameState> Players
{
get
{
foreach (var team in MatchStats)
foreach (var player in team.Team.Players)
yield return player;
}
}
public List<uint> Cheerers = new List<uint>();
public FighterStats[] MatchStats;
public bool OnGoing { get { return Flag == StatusFlag.Watchable; } }
public int GroupID { get { return (int)ID / 100000 - 1; } }
public uint TimeLeft
{
get
{
int val = 0;
if (MatchStats.Length == 1)
val = 0;
else
val = (int)((ImportTime.AddMinutes(10).TotalMilliseconds - Time32.Now.TotalMilliseconds) / 1000);
if (val < 0)
val = 0;
return (uint)val;
}
}
public void Send(Client.GameState client, int gui_state)
{
SkillPkBrackets brackets = new SkillPkBrackets(1);
brackets.Group = (ushort)GroupID;
brackets.GUIType = (ushort)gui_state;
brackets.TotalMatchesOnRoom = brackets.MatchCount = 1;
brackets.Type = ElitePKBrackets.StaticUpdate;
brackets.Append(this);
client.Send(brackets);
}
public void Commit()
{
var matchStats = new FighterStats[MatchStats.Length];
for (int i = 0; i < matchStats.Length; i++)
{
matchStats[i] = MatchStats[i].Clone();
}
MatchStats = matchStats;
}
public ConcurrentDictionary<uint, Client.GameState> Watchers;
public FighterStats Return(Func<FighterStats, bool> fn)
{
try
{
foreach (var stat in MatchStats)
{
if (stat != null)
{
if (fn(stat))
{
return SkillTournament.Tournaments[GroupID].Teams[stat.Team.UID].SkillFighterStats;
}
}
}
MatchStats[0].Flag = FighterStats.StatusFlag.Qualified;
return MatchStats[0];
}
catch (Exception e)
{
Console.WriteLine(e);
}
return null;
}
public uint ID;
public StatusFlag Flag;
public bool Inside;
public bool Done;
public bool Exported;
public bool Completed;
public ushort Index;
public Time32 ImportTime;
public Map Map;
private Time32 DoneStamp;
private int Imports;
public void CheckAlive(Game.ConquerStructures.Team team)
{
if (!Inside)
return;
bool dead = true;
foreach (var players in team.Teammates)
{
if (players.Entity.MapID == Map.ID)
{
if (players.Entity.Hitpoints > 0)
dead = false;
}
}
if (dead)
End(team);
}
public void CheckForEnd()
{
if (Done) return;
foreach (var team in MatchStats)
{
if (Inside)
{
CheckAlive(team.Team);
}
}
}
public void AliveMatch()
{
if (Flag != StatusFlag.OK)
{
if (Inside && !Done)
{
foreach (var dismised in MatchStats)
{
if (Flag != StatusFlag.OK)
{
if (MatchStats.Length == 2)
{
if (MatchStats[0].Winner)
return;
if (MatchStats[1].Winner)
return;
}
if (!dismised.Team.OnPopulates)
{
if (dismised.Waiting)
{
dismised.Flag = FighterStats.StatusFlag.Lost;
dismised.Team.SkillFighterStats.Flag = FighterStats.StatusFlag.Lost;
}
if (!dismised.Lost)
{
Console.WriteLine("team " + dismised.Team.SkillFighterStats.Name + " has lost");
this.End(dismised.Team);
}
}
else
{
CheckAlive(dismised.Team);
}
}
}
}
}
}
public static SafeConcurrentDictionary<uint, Match> ThreadMatch = new SafeConcurrentDictionary<uint, Match>();
public static void AddMatch(Game.ConquerStructures.Team team)
{
if (ThreadMatch.ContainsKey(team.UID))
ThreadMatch.Remove(team.UID);
ThreadMatch.Add(team.UID, team.SkillMatch);
}
public Match(params FighterStats[] teamates)
{
try
{
Map = Kernel.Maps[700].MakeDynamicMap();
if (teamates.Length == 1)
{
Flag = StatusFlag.OK;
MatchStats = new FighterStats[1];
MatchStats[0] = teamates[0].Team.SkillFighterStats;
MatchStats[0].Team.SkillMatch = this;
Match.AddMatch(MatchStats[0].Team);
MatchStats[0].Points = 0;
MatchStats[0].Cheers = 0;
MatchStats[0].Flag = FighterStats.StatusFlag.Qualified;
Flag = StatusFlag.OK;
Exported = true;
}
else
{
Watchers = new ConcurrentDictionary<uint, Client.GameState>();
MatchStats = new FighterStats[teamates.Length];
for (int i = 0; i < teamates.Length; i++)
{
MatchStats[i] = teamates[i].Team.SkillFighterStats;
MatchStats[i].Team.SkillMatch = this;
Match.AddMatch(MatchStats[i].Team);
MatchStats[i].Flag = FighterStats.StatusFlag.Waiting;
MatchStats[i].Points = 0;
MatchStats[i].Cheers = 0;
MatchStats[i].Teleported = false;
}
if (MatchStats.Length == 3)
MatchStats[0].Flag = FighterStats.StatusFlag.None;
Imports = 0;
Flag = StatusFlag.Waiting;
}
}
catch (Exception e) { Console.WriteLine(e.ToString()); }
}
public void Import(StatusFlag flag = StatusFlag.Watchable)
{
try
{
Imports++;
Exported = Done = false;
Inside = true;
Flag = StatusFlag.Watchable;
ImportTime = Time32.Now;
if (MatchStats.Length > 1)
{
Game.ConquerStructures.Team team1 = null, team2 = null;
for (int i = 0; i < MatchStats.Length; i++)
if (!MatchStats[i].NoFlag && !MatchStats[i].Lost)
if (team1 == null)
team1 = MatchStats[i].Team;
else
team2 = MatchStats[i].Team;
if (!team1.CanFightSkillPK)
{
Exported = Done = true;
Flag = StatusFlag.OK;
if (MatchStats.Length == 3)
Flag = StatusFlag.SwitchOut;
Completed = true;
var statsArray = team2.Teammates;
team1.SkillFighterStats.Flag = FighterStats.StatusFlag.Lost;
team2.SkillFighterStats.Flag = FighterStats.StatusFlag.Qualified;
return;
}
if (!team2.CanFightSkillPK)
{
Exported = Done = true;
Flag = StatusFlag.OK;
if (MatchStats.Length == 3)
Flag = StatusFlag.SwitchOut;
Completed = true;
var statsArray = team2.Teammates;
team2.SkillFighterStats.Flag = FighterStats.StatusFlag.Lost;
team1.SkillFighterStats.Flag = FighterStats.StatusFlag.Qualified;
return;
}
team1.SkillFighterStats.Flag = FighterStats.StatusFlag.Fighting;
team2.SkillFighterStats.Flag = FighterStats.StatusFlag.Fighting;
importPlayer(team1, team2);
importPlayer(team2, team1);
team1.SkillMatch = this;
team2.SkillMatch = this;
Match.AddMatch(team1);
Match.AddMatch(team2);
team1.Lider.Match = this;
team2.Lider.Match = this;
Network.GamePackets.SkillPkBrackets brackets = new Network.GamePackets.SkillPkBrackets(1);
{
brackets.Group = (ushort)GroupID;
brackets.GUIType = (ushort)SkillTournament.Tournaments[GroupID].State;
brackets.TotalMatchesOnRoom = brackets.MatchCount = 1;
brackets.Type = Network.GamePackets.SkillPkBrackets.StaticUpdate;
brackets.Append(this);
Kernel.SendWorldMessage(brackets.ToArray());
}
MapStatus status = new MapStatus();
status.BaseID = 700;
status.ID = Map.ID;
status.Statu = 19568946643047;
SendMapPacket(status.ToArray());
}
else
{
Done = true;
Flag = StatusFlag.OK;
Exported = true;
Completed = true;
MatchStats[0].Flag = FighterStats.StatusFlag.Qualified;
}
}
catch (Exception e)
{
Console.WriteLine(e);
}
}
public void SendMapPacket(byte[] buffer)
{
foreach (var player in Players)
if (player.Entity.MapID == Map.ID)
player.Send(buffer);
}
private void importPlayer(Game.ConquerStructures.Team teamone, Game.ConquerStructures.Team opponent)
{
if (MatchStats.Length > 1)
{
teamone.SkillFighterStats.Teleported = true;
opponent.SkillFighterStats.Teleported = true;
// ushort x = 0; ushort y = 0;
foreach (var player in teamone.Players)
{
if (player.Entity.MapID != SkillPk.SkillTournament.Tournaments[GroupID].WaitingArea.ID)
continue;
/*if (player.Entity.ContainsFlag((ulong)Update.Flags.Ride))
{
player.Entity.RemoveFlag(MsgServer.MsgUpdate.Flags.Ride);
}*/
player.LoadItemStats();
var coords = Map.RandomCoordinates();
player.Entity.Teleport(Map.BaseID, Map.ID, coords.Item1, coords.Item2);
player.Entity.BringToLife();
player.Entity.SkillWatchingMatch = null;
if (player.Guild != null)
player.Entity.GuildBattlePower = player.Guild.GetSharedBattlepower(player.AsMember.Rank);
Network.GamePackets.SkillPkMatchUI ui = new Network.GamePackets.SkillPkMatchUI();
{
ui.Append(opponent);
ui.TimeLeft = TimeLeft;
ui.Type = Network.GamePackets.SkillPkMatchUI.BeginMatch;
player.Send(ui.ToArray());
}
player.Send(BlockOpenArena);
player.Send(CreateUpdate().ToArray());
player.CantAttack = Time32.Now.AddSeconds(11);
player.Entity.PrevPKMode = player.Entity.PKMode;
player.Entity.PKMode = Enums.PKMode.Team;
Network.GamePackets.Data dat = new Network.GamePackets.Data(true);
{
dat.UID = player.Entity.UID;
dat.ID = Network.GamePackets.Data.ChangePKMode;
dat.dwParam = (uint)player.Entity.PKMode;
player.Send(dat.ToArray());
}
}
}
else
{
MatchStats[0].Flag = FighterStats.StatusFlag.Qualified;
Done = true;
Flag = StatusFlag.OK;
Exported = true;
Completed = true;
}
}
public void End(Game.ConquerStructures.Team team)
{
try
{
if (MatchStats.Length == 1)
{
MatchStats[0].Flag = FighterStats.StatusFlag.Qualified;
Flag = StatusFlag.OK;
return;
}
if (Done) return;
Done = true;
DoneStamp = Time32.Now;
Flag = StatusFlag.OK;
team.SkillFighterStats.Flag = FighterStats.StatusFlag.Lost;
Network.GamePackets.SkillPkMatchUI ui = new Network.GamePackets.SkillPkMatchUI();
{
ui.Type = Network.GamePackets.SkillPkMatchUI.Effect;
ui.dwParam = Network.GamePackets.SkillPkMatchUI.Effect_Lose;
team.SendMesageTeam(ui.ToArray(), 0);
var team_win = targetOfWin(team);
if (team_win != null)
{
ui.Append(team_win.Team);
ui.dwParam = Network.GamePackets.SkillPkMatchUI.Effect_Win;
foreach (var target in team_win.Team.Players)
{
target.Send(ui.ToArray());
ui.Type = Network.GamePackets.SkillPkMatchUI.EndMatch;
team.SendMesageTeam(ui.ToArray(), 0);
target.Send(ui.ToArray());
target.Inventory.Add(720981, 0, 1);
ui.Type = Network.GamePackets.SkillPkMatchUI.Reward;
target.Send(ui.ToArray());
if (Imports == 2 || MatchStats.Length != 3 || MatchStats[0] == null)
{
team_win.Flag = FighterStats.StatusFlag.Qualified;
}
else
{
var dictionar = MatchStats.Where(p => !p.Lost).ToArray();
if (dictionar.Length == 2)
{
Flag = StatusFlag.SwitchOut;
team_win.Flag = FighterStats.StatusFlag.Waiting;
team_win.OnNextMatch = true;
}
else
team_win.Flag = FighterStats.StatusFlag.Qualified;
}
}
}
}
Network.GamePackets.SkillPkBrackets brackets = new Network.GamePackets.SkillPkBrackets(1);
{
brackets.Group = (ushort)GroupID;
brackets.GUIType = (ushort)SkillTournament.Tournaments[GroupID].State;
brackets.TotalMatchesOnRoom = brackets.MatchCount = 1;
brackets.Type = Network.GamePackets.SkillPkBrackets.StaticUpdate;
brackets.Append(this);
Kernel.SendWorldMessage(brackets.ToArray());
}
foreach (var clien in Watchers.Values)
if (clien.Entity.MapID == Map.ID)
LeaveWatch(clien);
}
catch (Exception e) { Console.WriteLine(e.ToString()); }
}
public void Export()
{
try
{
if (Time32.Now > DoneStamp.AddSeconds(3) || TimeLeft == 0)
{
#region !Done
if (!Done)
{
if (MatchStats.Length == 1)
{
MatchStats[0].Flag = FighterStats.StatusFlag.Qualified;
Flag = StatusFlag.OK;
Exported = true;
Exported = true;
Completed = true;
return;
}
else
{
var fighters = MatchStats.Where(p => p.Fighting).OrderBy(p => p.Points).ToArray();
for (int i = 0; i < fighters.Length; i++)
{
var team = fighters[i];
End(team.Team);
}
//var fighters = MatchStats.Where(p => p.Fighting).ToArray();
//if (fighters.Length > 1)
//{
// if (fighters[0].Fighting && fighters[1].Fighting)
// {
// if (fighters[0].Points == fighters[1].Points)
// End(fighters.Last(p => p.Team.UID == fighters[0].Team.UID).Team);
// else
// {
// if (fighters[0].Points > fighters[1].Points)
// End(fighters.Last(p => p.Team.UID == fighters[0].Team.UID).Team);
// else
// End(fighters.Last(p => p.Team.UID == fighters[1].Team.UID).Team);
// }
// }
//}
//else if (fighters.Length == 1)
// End(fighters.First(p => p.Team.UID == fighters[0].Team.UID).Team);
}
}
#endregion
foreach (var teams in MatchStats)
{
if (teams != null)
{
if (!teams.Waiting && teams.Teleported || teams.OnNextMatch)
{
foreach (var player in teams.Team.Players)
{
if (player.Entity.MapID == Map.ID)
{
player.Entity.InSkillPk = false;
var map = SkillTournament.Tournaments[GroupID].WaitingArea;
var coords = map.RandomCoordinates();
Data dat = new Data(true);
dat.UID = player.Entity.UID;
dat.ID = Data.ChangePKMode;
dat.dwParam = (uint)player.Entity.PrevPKMode;
player.Send(dat);
player.Entity.Teleport(map.ID, coords.Item1, coords.Item2);
if (player.Entity.Hitpoints == 0)
player.Entity.BringToLife();
MapStatus status = new MapStatus();
status.BaseID = map.BaseID;
status.ID = map.ID;
status.Statu = 2568946643047;
player.Send(status);
}
}
teams.Teleported = true;
}
}
}
Exported = true;
Completed = true;
}
}
catch (Exception e) { Console.WriteLine(e.ToString()); }
}
public void SwitchBetween()
{
if (Imports == 1 && MatchStats.Length == 3 && MatchStats[0] != null && !MatchStats[0].Lost)
{
MatchStats[0].Flag = FighterStats.StatusFlag.Waiting;
if (MatchStats[1].Winner)
{
MatchStats[1].Teleported = false;
MatchStats[1].Flag = FighterStats.StatusFlag.Waiting;
}
if (MatchStats[2].Winner)
{
MatchStats[2].Teleported = false;
MatchStats[2].Flag = FighterStats.StatusFlag.Waiting;
}
Completed = false;
}
}
public SkillPk.FighterStats targetOfWin(Game.ConquerStructures.Team team)
{
var dictionar = MatchStats.Where(p => p.Fighting).ToArray();
for (int i = 0; i < dictionar.Length; i++)
if (dictionar[i] != null)
if (dictionar[i].Team.UID != team.UID)
return dictionar[i];
return null;
}
public SkillPkMatchStats CreateUpdate()
{
Network.GamePackets.SkillPkMatchStats stats = new Network.GamePackets.SkillPkMatchStats();
stats.Append(this);
return stats;
}
public void BeginWatch(Client.GameState client)
{
if (client.Entity.SkillWatchingMatch != null) return;
if (Watchers.ContainsKey(client.Entity.UID)) return;
Watchers.TryAdd(client.Entity.UID, client);
client.Entity.SkillWatchingMatch = this;
client.Entity.WatchingArena = 1;
var coords = Map.RandomCoordinates();
client.Entity.Teleport(Map.BaseID, Map.ID, coords.Item1, coords.Item2);
Network.GamePackets.ElitePKWatch watch = new Network.GamePackets.ElitePKWatch(true, MatchStats.Length);
watch.dwParam = MatchStats.First().Team.UID;
watch.Type = Network.GamePackets.ElitePKWatch.RequestView;
watch.dwCheers1 = MatchStats[0].Cheers;
watch.dwCheers2 = MatchStats[1].Cheers;
client.Send(watch.ToArray());
client.Send(CreateUpdate().ToArray());
UpdateWatchers();
MapStatus status = new MapStatus();
status.BaseID = Map.BaseID;
status.ID = Map.ID;
status.Statu = 2568946643047;
client.Send(status);
client.Entity.PKMode = Enums.PKMode.Capture;
client.Entity.Send(new Data(true) { UID = client.Entity.UID, ID = Data.ChangePKMode, dwParam = (uint)client.Entity.PKMode });
}
public void Update()
{
var update = CreateUpdate();
foreach (var player in Players)
if (player != null)
if (player.Team.SkillFighterStats.Fighting)
player.Send(update.ToArray());
foreach (var watch in Watchers.Values)
if (watch != null)
watch.Send(update.ToArray());
}
public void UpdateWatchers()
{
Network.GamePackets.ElitePKWatch watch = new Network.GamePackets.ElitePKWatch(true, Watchers.Count);
{
watch.ID = ID;
watch.Type = Network.GamePackets.ElitePKWatch.Watchers;
watch.WatcherCount = (uint)Watchers.Count;
watch.dwCheers1 = MatchStats[0].Cheers;
watch.dwCheers2 = MatchStats[1].Cheers;
foreach (var pClient in Watchers.Values)
watch.Append(pClient.Entity.Mesh, pClient.Entity.Name);
foreach (var pClient in Watchers.Values)
pClient.Send(watch.ToArray());
foreach (var pClient in Players)
if (pClient != null)
pClient.Send(watch.ToArray());
}
}
public void LeaveWatch(Client.GameState client)
{
if (Watchers.TryRemove(client.Entity.UID, out client))
{
if (!Done)
UpdateWatchers();
client.Entity.SkillWatchingMatch = null;
Network.GamePackets.ElitePKWatch watch = new Network.GamePackets.ElitePKWatch(true);
{
watch.ID = ID;
watch.Type = Network.GamePackets.ElitePKWatch.Leave;
client.Send(watch.ToArray());
}
if (Program.EventsMap.Contains(client.Entity.PreviousMapID))
client.Entity.Teleport(1002, 300, 278);
else
client.Entity.PreviousTeleport();
}
}
public void Cheer(Client.GameState client, uint fighter)
{
if (!this.Cheerers.Contains(client.Entity.UID))
{
Cheerers.Add(client.Entity.UID);
ElitePKWatch watch = new ElitePKWatch(true, MatchStats.Length);
watch.ID = ID;
watch.Type = ElitePKWatch.Fighters;
watch.dwCheers1 = MatchStats[0].Cheers;
watch.dwCheers2 = MatchStats[1].Cheers;
if (MatchStats[0].LeaderUID == fighter)
{
watch.Append(0, MatchStats[0].Name);
MatchStats[0].Cheers += 1;
}
else if (MatchStats[1].LeaderUID == fighter)
{
watch.Append(0, MatchStats[1].Name);
MatchStats[1].Cheers += 1;
}
watch.Append(client.Entity.Name);
foreach (var watchers in Watchers.Values)
watchers.Send(watch);
foreach (var fighters in Players)
fighters.Send(watch);
UpdateWatchers();
SendGlobal(CreateUpdate().ToArray());
}
}
public void SendGlobal(byte[] buffer)
{
foreach (var pClient in Watchers.Values)
if (pClient != null)
pClient.Send(buffer);
foreach (var pClient in Players)
if (pClient != null)
pClient.Send(buffer);
}
}
public FighterStats[] Top8 = new FighterStats[0];
public ConcurrentDictionary<uint, Game.ConquerStructures.Team> Teams;
public ConcurrentDictionary<uint, Match> Matches;
public Match[] MatchArray;
private Match[] Top4MatchArray;
public Match[] ExtendedMatchArray;
public Match FinalMatch;
private Counter MatchCounter;
private ushort MatchIndex;
public bool Alive = false;
public DateTime ConstructTop8 = new DateTime();
public Map WaitingArea;
public int State;
private int pState = States.T_Organize;
public int GroupID;
private bool willAdvance;
private Time32 pStamp;
public GamePackets ID;
public ushort TimeLeft
{
get
{
int value = (int)((pStamp.TotalMilliseconds - Time32.Now.TotalMilliseconds) / 1000);
if (value < 0) return 0;
return (ushort)value;
}
}
public SkillPk(int group)
{
if (!Alive)
{
Alive = true;
Teams = new ConcurrentDictionary<uint, ConquerStructures.Team>();
Matches = new ConcurrentDictionary<uint, Match>();
GroupID = group;
var name = "SkillPk";
LoadTop8(string.Format("{0}{1}", name, GroupID));
MatchCounter = new Counter((uint)(GroupID * 100000 + 100000));
WaitingArea = Kernel.Maps[(ushort)ElitePKTournament.WaitingAreaID].MakeDynamicMap();
Constants.PKForbiddenMaps.Add(WaitingArea.ID);
Interfaces.INpc npc = new Network.GamePackets.NpcSpawn();
npc.UID = 7911;
npc.Name = "SkillPKClerk";
npc.Mesh = 1340;
npc.Type = (Enums.NpcType)2;
npc.X = 49;
npc.Y = 47;
npc.MapID = WaitingArea.ID;
WaitingArea.AddNpc(npc);
State = States.GUI_Top8Ranking;
pState = States.T_Organize;
}
}
public bool SignUp(Client.GameState client)
{
if (AllowJoin || client.Fake)
{
var coords = WaitingArea.RandomCoordinates();
client.Entity.Teleport(WaitingArea.ID, coords.Item1, coords.Item2);
if (!Teams.ContainsKey(client.Team.UID))
Teams.Add(client.Team.UID, client.Team);
client.Entity.InSkillPk = true;
client.LoadItemStats();
Network.GamePackets.SkillPkMatchUI ui = new Network.GamePackets.SkillPkMatchUI();
{
ui.Type = 1;
ui.dwParam = Network.GamePackets.SkillPkMatchUI.Effect_Win;
ui.Append(client.Team);
client.Send(ui.ToArray());
ui.Type = 5;
client.Send(ui.ToArray());
}
if (client.Team.TeamLider(client))
{
Network.GamePackets.TeamSetName teamname = new Network.GamePackets.TeamSetName();
{
teamname.TeamID = client.Team.UID;
teamname.TeamName = client.Team.SkillFighterStats.Name;
client.Send(teamname.ToArray());
}
}
MapStatus status = new MapStatus();
status.BaseID = WaitingArea.BaseID;
status.ID = WaitingArea.ID;
status.Statu = 2568946643047;
client.Send(status);
return true;
}
return false;
}
DateTime StarTimer = new DateTime();
private bool AllowJoin = false;
private IDisposable Subscriber;
public bool Organization = false;
public void SubscribeTimer(int minutes)
{
StarTimer = DateTime.Now;
StarTimer = StarTimer.AddSeconds(10);
AllowJoin = true;
Organization = true;
if (Subscriber == null)
Subscriber = World.Subscribe(timerCallback, 1000);
}
public void Purge()
{
foreach (var team in Teams.Values)
{
if (State == States.GUI_Top8Qualifier)
{
if (Teams.Count > 8)
{
if (team.SkillFighterStats.Lost || !team.OnPopulates)// && player.Player.MyLocation.DinamicID != WaitingArea)
{
Remove(team.UID);
}
}
}
else if (team.SkillFighterStats.Lost)
{
if (Teams.Count > 8)
{
Remove(team.UID);
}
}
}
}
public static Time32 Test;
public static List<MaTrix.AI> Ais = new List<MaTrix.AI>();
public void Remove(uint uid)
{
if (!Teams.ContainsKey(uid))
return;
foreach (var teamtes in Teams[uid].Teammates)
{
if (teamtes.Entity.Dead)
teamtes.Entity.BringToLife();
if (teamtes.Guild != null)
teamtes.Entity.GuildBattlePower = teamtes.Guild.GetSharedBattlepower(teamtes.AsMember.Rank);
teamtes.LoadItemStats();
teamtes.Entity.Teleport();
teamtes.Team.SkillMatch = null;
teamtes.Entity.InSkillPk = false;
}
if (State >= States.GUI_Top4Qualifier)
{
for (int x = 0; x < 8; x++)
{
if (Top8[x] != null && Top8[x].LeaderUID == Teams[uid].Lider.Entity.UID)
{
var Lider = Teams[uid].Lider;
if (Lider != null && Kernel.GamePool.ContainsKey(Lider.Entity.UID))
{
uint UID = (uint)(721300 + 1 * (byte)GroupID + Math.Min(3, (x)) * 4);
if (Lider.Inventory.Count <= 39)
Lider.Inventory.Add(UID, 0, 1);
}
}
}
}
Teams.Remove(uid);
}
public bool Started = false;
public bool SendMatches = false;
private void timerCallback(int tim)
{
try
{
if (!Alive)
{
SkillTournament.Opened = false;
Subscriber.Dispose();
return;
}
#region ReconstructTop
if (State == States.GUI_ReconstructTop)
{
if (DateTime.Now > ConstructTop8.AddMinutes(2))
{
State = States.GUI_Top8Ranking;
Kernel.SendWorldMessage(new Network.GamePackets.SkillPkBrackets() { Type = 6, OnGoing = false }.ToArray());
Alive = false;
}
return;
}
#endregion
DateTime Now64 = DateTime.Now;
if (Now64.Hour == (EventTime + 1) && Now64.Minute >= (3 - GroupID) * 2)
{
SkillTournament.Opened = false;
Started = true;
if (Organization)
{
Organization = false;
this.Top8 = new SkillPk.FighterStats[8];
for (int i = 0; i < this.Top8.Length; i++)
{
this.Top8[i] = new SkillPk.FighterStats(0u, "", 0u, null);
}
foreach (var team in Teams.Values)
{
foreach (var player in team.Players)
{
if (player != null)
{
if (player.Team != null)
{
Network.GamePackets.TeamSetName teamname = new Network.GamePackets.TeamSetName();
{
teamname.Type = Network.GamePackets.TeamSetName.SuccessfulName;
teamname.TeamID = player.Team.UID;
teamname.TeamName = player.Team.SkillFighterStats.Name;
player.Send(teamname.ToArray());
if (player.Team.TeamLider(player))
{
teamname.Type = Network.GamePackets.TeamSetName.Remove;
player.Send(teamname.ToArray());
}
}
//SkillPk A~prize~for~every~participant~in~the~Team~PK~Tournament.~Right~click~it~to~get~1~hour`s~double~EXP.
player.Inventory.Add(720793, 0, 1);
}
}
}
}
if (Teams.Count < 1)
{
// Remove(Teams.First().Value.UID);
Teams.Clear();
Alive = false;
Kernel.SendWorldMessage(new Network.GamePackets.SkillPkBrackets() { Type = 6, OnGoing = false }.ToArray());
return;
}
}
#region GetState
if (State == States.GUI_Top8Ranking)
{
willAdvance = Teams.Count > 8;
Kernel.SendWorldMessage(new Network.GamePackets.SkillPkBrackets() { Type = 6, OnGoing = true }.ToArray());
if (Teams.Count == 1)
{
Top8[0] = Teams.FirstOrDefault().Value.SkillFighterStats;
ConstructTop8 = DateTime.Now;
var name = "SkillPk";
SaveTop8(string.Format("{0}{1}", name, GroupID));
foreach (var team in Teams.Values)
foreach (var player in team.Players)
Remove(player.Team.UID);
State = States.GUI_ReconstructTop;
foreach (var client in Kernel.GamePool.Values)
Rankings(client);
var brackets = CreateBrackets(ExtendedMatchArray, 0, Network.GamePackets.SkillPkBrackets.UpdateList);
foreach (var packet in brackets)
Kernel.SendWorldMessage(packet.ToArray());
Kernel.SendWorldMessage(new Network.GamePackets.SkillPkBrackets() { Type = 6, OnGoing = false }.ToArray());
}
else if (Teams.Count == 2)
{
State = States.GUI_Top1;
pState = States.T_Organize;
}
else if (Teams.Count > 2 && Teams.Count <= 4)
{
State = States.GUI_Top2Qualifier;
pState = States.T_Organize;
}
else if (Teams.Count > 4 && Teams.Count <= 8)
{
State = States.GUI_Top4Qualifier;
pState = States.T_Organize;
}
else if (willAdvance && Teams.Count <= 24)
State = States.GUI_Top8Qualifier;
else
State = States.GUI_Knockout;
}
#endregion
#region Knockout
if (State == States.GUI_Knockout)
{
AllowJoin = false;
if (pState == States.T_Organize)
{
if (willAdvance && Teams.Count <= 24)
{
State = States.GUI_Top8Qualifier;
}
else
{
MatchIndex = 0;
var array = Teams.Values.ToArray();
ushort counter = 0;
bool NoPar = array.Length % 2 == 0;
if (NoPar)
{
for (ushort x = 0; x < array.Length; x++)
{
int r = counter;
counter++;
int t = counter;
counter++;
if (counter <= array.Length)
{
Match match = new Match(array[r].SkillFighterStats, array[t].SkillFighterStats);
match.Index = MatchIndex++;
match.ID = MatchCounter.Next;
Matches.TryAdd(match.ID, match);
}
}
}
else
{
for (ushort x = 0; x < array.Length - 1; x++)
{
int r = counter;
counter++;
int t = counter;
counter++;
if (counter <= array.Length)
{
Match match = new Match(array[r].SkillFighterStats, array[t].SkillFighterStats);
match.Index = MatchIndex++;
match.ID = MatchCounter.Next;
Matches.TryAdd(match.ID, match);
}
}
Match math_bye = new Match(array[array.Length - 1].SkillFighterStats);
math_bye.Index = MatchIndex++;
math_bye.ID = MatchCounter.Next;
Matches.TryAdd(math_bye.ID, math_bye);
}
pStamp = Time32.Now.AddSeconds(60);
pState = States.T_Wait;
MatchArray = (from match in Matches.Values orderby match.MatchStats.Length descending select match).ToArray();
var brackets = CreateBrackets(MatchArray, 0);
foreach (var packet in brackets)
{
Kernel.SendWorldMessage(packet.ToArray());
}
}
}
else if (pState == States.T_Wait)
{
if (TimeLeft == 0)
{
int doneMatches = 0;
foreach (var match in MatchArray)
{
match.AliveMatch();
if (!match.Inside)
{
match.Import(Match.StatusFlag.Watchable);
}
else
{
if (!match.Exported && (match.Done || match.TimeLeft == 0))
{
match.Export();
}
if (match.Exported || match.MatchStats.Length == 1)
doneMatches++;
}
}
if (doneMatches == Matches.Count)
{
Matches.Clear();
Purge();
pState = States.T_Organize;
}
}
}
}
#endregion
#region Top8Qualifier
if (State == States.GUI_Top8Qualifier)
{
if (pState == States.T_Organize)
{
if (Teams.Count == 8)
{
State = States.GUI_Top4Qualifier;
}
else
{
MatchIndex = 0;
var array = Teams.Values.ToArray();
int[] taken = new int[array.Length];
if (array.Length <= 16)
{
ushort counter = 0;
int t1Group = array.Length - 8;
int lim = taken.Length / 2;
for (int i = 0; i < t1Group; i++)
{
int r = counter;
counter++;
int t = counter;
counter++;
Match match = new Match(array[r].SkillFighterStats, array[t].SkillFighterStats);
match.Index = MatchIndex++;
match.ID = MatchCounter.Next;
Matches.TryAdd(match.ID, match);
}
for (int i = 0; i < 8 - t1Group; i++)
{
ushort r = counter;
counter++;
Match match = new Match(array[r].SkillFighterStats);
match.Index = MatchIndex++;
match.ID = MatchCounter.Next;
Matches.TryAdd(match.ID, match);
}
}
else
{
ushort counter = 0;
int t3GroupCount = array.Length - 16;
for (int i = 0; i < t3GroupCount; i++)
{
int r = counter;
counter++;
int t = counter;
counter++;
int y = counter;
counter++;
Match match = new Match(array[r].SkillFighterStats, array[t].SkillFighterStats, array[y].SkillFighterStats);
match.Index = MatchIndex++;
match.ID = MatchCounter.Next;
Matches.TryAdd(match.ID, match);
}
int t2GroupCount = array.Length - counter;
for (int i = 0; i < t2GroupCount / 2; i++)
{
int r = counter;
counter++;
int t = counter;
counter++;
Match match = new Match(array[r].SkillFighterStats, array[t].SkillFighterStats);
match.Index = MatchIndex++;
match.ID = MatchCounter.Next;
Matches.TryAdd(match.ID, match);
}
}
pStamp = Time32.Now.AddSeconds(60);
pState = States.T_Wait;
MatchArray = (from match in Matches.Values orderby match.MatchStats.Length descending select match).ToArray();
var brackets = CreateBrackets(MatchArray, 0, Network.GamePackets.SkillPkBrackets.UpdateList);
foreach (var packet in brackets)
{
Kernel.SendWorldMessage(packet.ToArray());
}
Network.GamePackets.SkillPkBrackets brea = new Network.GamePackets.SkillPkBrackets(0);
brea.Type = Network.GamePackets.SkillPkBrackets.EPK_State;
brea.OnGoing = true;
Kernel.SendWorldMessage(brea.ToArray());
SendMatches = true;
}
}
else if (pState == States.T_Wait)
{
if (TimeLeft == 0)
{
int doneMatches = 0;
foreach (var match in MatchArray)
{
match.AliveMatch();
if (!match.Inside)
{
if (match.MatchStats.Length > 1)
{
match.Import(Match.StatusFlag.Watchable);
}
else
{
match.Inside = true;
match.Completed = true;
match.Done = true;
match.MatchStats
.First(p => p != null).Team
.SkillFighterStats.Flag = FighterStats.StatusFlag.Qualified;
}
}
else
{
if (!match.Exported && (match.Done || match.TimeLeft == 0))
{
match.Export();
if (match.MatchStats.Length == 3)
match.SwitchBetween();
else
match.Flag = Match.StatusFlag.OK;
}
if (match.Exported || match.MatchStats.Length == 1)
doneMatches++;
}
}
if (SendMatches)
{
SendMatches = false;
var brackets = CreateBrackets(MatchArray, 0, 0);
foreach (var packet in brackets)
{
Kernel.SendWorldMessage(packet.ToArray());
}
}
if (doneMatches == Matches.Count)
{
bool finishedRound = true;
foreach (var match in MatchArray)
{
if (!match.Completed)
{
finishedRound = false;
break;
}
}
if (!finishedRound)
{
foreach (var match in MatchArray)
{
if (!match.Completed)
{
foreach (var stats in match.MatchStats)
stats.Reset(true);
match.Inside = false;
match.Done = false;
match.Exported = false;
if (match.MatchStats.Length != 1)
match.Flag = Match.StatusFlag.Waiting;
}
}
pStamp = Time32.Now.AddSeconds(60);
pState = States.T_Wait;
var brakets = CreateBrackets(MatchArray, 0, Network.GamePackets.SkillPkBrackets.UpdateList);
foreach (var packet in brakets)
{
Kernel.SendWorldMessage(packet.ToArray());
}
}
else
{
Matches.Clear();
Purge();
pState = States.T_Organize;
}
}
}
}
}
#endregion
#region Top4Qualifier
if (State == States.GUI_Top4Qualifier)
{
if (pState == States.T_Organize)
{
try
{
MatchIndex = 0;
var array = Teams.Values.ToArray();
int[] taken = new int[array.Length];
int lim = taken.Length / 2;
for (int i = 0; i < taken.Length; i += 2)
{
if (array.Length > i + 1)
{
Match match = new Match(array[i].SkillFighterStats, array[i + 1].SkillFighterStats);
match.Index = MatchIndex++;
match.ID = MatchCounter.Next;
Matches.TryAdd(match.ID, match);
}
else
{
Match match = new Match(array[i].SkillFighterStats);
match.Index = MatchIndex++;
match.ID = MatchCounter.Next;
Matches.TryAdd(match.ID, match);
}
}
pStamp = Time32.Now.AddSeconds(60);
pState = States.T_Wait;
MatchArray = Matches.Values.ToArray();
var brackets = CreateBrackets(MatchArray, 0, Network.GamePackets.SkillPkBrackets.UpdateList);
foreach (var packet in brackets)
Kernel.SendWorldMessage(packet.ToArray());
brackets = CreateBrackets(MatchArray, 0, Network.GamePackets.SkillPkBrackets.InitialList);
foreach (var packet in brackets)
Kernel.SendWorldMessage(packet.ToArray());
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
}
else if (pState == States.T_Wait)
{
if (TimeLeft == 0)
{
try
{
int doneMatches = 0;
foreach (var match in MatchArray)
{
match.AliveMatch();
if (!match.Inside && !match.Completed)
{
match.Import(Match.StatusFlag.Watchable);
}
else
{
if (!match.Exported && (match.Done || match.TimeLeft == 0))
match.Export();
if (match.Exported)
doneMatches++;
}
}
if (doneMatches == MatchArray.Length)
{
int i = 4;
foreach (var match in MatchArray)
{
foreach (var stats in match.MatchStats)
if (stats.Flag == FighterStats.StatusFlag.Lost)
{
Top8[Math.Min(7, i++)] = stats.Clone();
//Remove(stats.Team.UID);
}
match.Commit();
}
foreach (var list in Teams.Values)
if (list.SkillFighterStats.Lost)
{
foreach (var teama in list.Teammates)
Remove(list.UID);
}
State = States.GUI_Top8Ranking;
pState = States.T_Organize;
}
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
}
}
}
#endregion
#region Top2Qualifier
if (State == States.GUI_Top2Qualifier)
{
if (pState == States.T_Organize)
{
try
{
MatchIndex = 0;
Top4MatchArray = new Match[2];
if (MatchArray == null || MatchArray.Length == 0)
{
var array = Teams.Values.ToArray();
int[] taken = new int[array.Length];
int lim = taken.Length / 2;
int mat = 0;
for (int i = 0; i < taken.Length; i += 2)
{
if (array.Length > i + 1)
{
Match match = new Match(array[i].SkillFighterStats, array[i + 1].SkillFighterStats);
match.Index = MatchIndex++;
match.ID = MatchCounter.Next;
Top4MatchArray[mat] = match;
mat++;
Matches.TryAdd(match.ID, match);
}
else
{
Match match = new Match(array[i].SkillFighterStats);
match.Index = MatchIndex++;
match.ID = MatchCounter.Next;
Top4MatchArray[mat] = match;
mat++;
Matches.TryAdd(match.ID, match);
}
}
}
else
{
for (int i = 0; i < Top4MatchArray.Length; i++)
{
if (MatchArray.Length > i + 2)
{
Match match = new Match(//p.winer este
MatchArray[i].Return(p => p.Team.SkillFighterStats.Winner),//.MatchStats.First(p => p.Team.SkillFighterStats.Winner),
MatchArray[i + 2].Return(p => p.Team.SkillFighterStats.Winner));//.MatchStats.First(p => p.Team.SkillFighterStats.Winner));
match.Index = MatchIndex++;
match.ID = MatchCounter.Next;
Top4MatchArray[i] = match;
Matches.TryAdd(match.ID, match);
}
else
{
Match match = new Match(//p.winer este
MatchArray[i].Return(p => p.Team.SkillFighterStats.Winner));//.MatchStats.First(p => p.Team.SkillFighterStats.Winner));
match.Index = MatchIndex++;
match.ID = MatchCounter.Next;
Top4MatchArray[i] = match;
Matches.TryAdd(match.ID, match);
}
}
}
pStamp = Time32.Now.AddSeconds(60);
pState = States.T_Wait;
if (MatchArray == null)
MatchArray = Matches.Values.ToArray();
var brackets = CreateBrackets(Top4MatchArray, 0, Network.GamePackets.SkillPkBrackets.UpdateList);
foreach (var packet in brackets)
Kernel.SendWorldMessage(packet.ToArray());
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
}
else if (pState == States.T_Wait)
{
if (TimeLeft == 0)
{
try
{
int doneMatches = 0;
foreach (var match in Top4MatchArray)
{
match.AliveMatch();
if (!match.Inside && !match.Completed)
{
match.Import(Match.StatusFlag.Watchable);
}
else
{
if (!match.Exported && (match.Done || match.TimeLeft == 0))
match.Export();
if (match.Exported)
doneMatches++;
}
}
if (doneMatches == Top4MatchArray.Length)
{
List<Game.ConquerStructures.Team> list = new List<Game.ConquerStructures.Team>();
foreach (var player in Teams.Values)
if (player.SkillFighterStats.Lost)
list.Add(player);
foreach (var match in Top4MatchArray)
match.Commit();
if (list.Count == 1)
{
foreach (Game.ConquerStructures.Team current in list)
{
Remove(current.UID);
this.Top8[2] = current.SkillFighterStats;
}
this.State = States.GUI_Top8Ranking;
this.pState = States.T_Organize;
}
else
{
pState = States.T_Organize;
State = States.GUI_Top3;
}
}
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
}
}
}
#endregion
#region Top3
if (State == States.GUI_Top3)
{
if (pState == States.T_Organize)
{
try
{
MatchIndex = 0;
ExtendedMatchArray = new Match[2];
Match match = new Match(
Top4MatchArray[0].Return(p => !p.Team.SkillFighterStats.Winner),//.MatchStats.First(p => !p.Team.SkillFighterStats.Winner),
Top4MatchArray[1].Return(p => !p.Team.SkillFighterStats.Winner));//.MatchStats.First(p => !p.Team.SkillFighterStats.Winner));
match.Index = MatchIndex++;
match.ID = MatchCounter.Next;
ExtendedMatchArray[0] = match;
Matches.TryAdd(match.ID, match);
pStamp = Time32.Now.AddSeconds(60);
pState = States.T_Wait;
var brackets = CreateBrackets(ExtendedMatchArray, 0, Network.GamePackets.SkillPkBrackets.UpdateList);
foreach (var packet in brackets)
Kernel.SendWorldMessage(packet.ToArray());
Kernel.SendWorldMessage(new Network.GamePackets.SkillPkBrackets() { Type = 6, OnGoing = true }.ToArray());
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
}
else if (pState == States.T_Wait)
{
if (TimeLeft == 0)
{
try
{
var match = ExtendedMatchArray[0];
match.AliveMatch();
if (!match.Inside && match.Flag != Match.StatusFlag.OK)
{
match.Import(Match.StatusFlag.Watchable);
}
else
{
if (!match.Exported && (match.Done || match.TimeLeft == 0))
match.Export();
if (match.Exported)
{
//var a_math =ExtendedMatchArray[0].MatchStats;
var top3 = ExtendedMatchArray[0].Return(p => p.Team.SkillFighterStats.Winner);
//.First(p => p.Team.SkillFighterStats.Winner).Team.SkillFighterStats;
var top4 = ExtendedMatchArray[0].Return(p => !p.Team.SkillFighterStats.Winner);
//ExtendedMatchArray[0].MatchStats
//.First(p => !p.Team.SkillFighterStats.Winner).Team.SkillFighterStats;
Top8[2] = top3;
Top8[3] = top4;
Remove(top3.Team.UID);
Remove(top4.Team.UID);
pState = States.T_Organize;
State = States.GUI_Top8Ranking;
}
}
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
}
}
}
#endregion
#region Top1
if (State == States.GUI_Top1)
{
if (pState == States.T_Organize)
{
try
{
MatchIndex = 0;
// var brackets = CreateBrackets(MatchArray, 0, Client.GamePackets.SkillElitePkBrackets.GUIEdit);
// foreach (var packet in brackets)
// CMD.MapPackets.Enqueue(new CMD.MapPackets.Models() { data = packet.ToArray() });
Match match = new Match(Teams.Values.First().SkillFighterStats, Teams.Values.Last().SkillFighterStats);
ExtendedMatchArray = new Match[1];
match.Index = MatchIndex++;
match.ID = MatchCounter.Next;
ExtendedMatchArray[0] = match;
Matches.TryAdd(match.ID, match);
pStamp = Time32.Now.AddSeconds(60);
pState = States.T_Wait;
if (MatchArray == null)
MatchArray = Matches.Values.ToArray();
var brackets = CreateBrackets(MatchArray, 0, Network.GamePackets.SkillPkBrackets.GUIEdit);
foreach (var packet in brackets)
Kernel.SendWorldMessage(packet.ToArray());
brackets = CreateBrackets(ExtendedMatchArray, 0, Network.GamePackets.SkillPkBrackets.UpdateList);
foreach (var packet in brackets)
Kernel.SendWorldMessage(packet.ToArray());
Kernel.SendWorldMessage(new Network.GamePackets.SkillPkBrackets() { Type = 6, OnGoing = true }.ToArray());
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
}
else if (pState == States.T_Wait)
{
if (TimeLeft == 0)
{
try
{
int doneMatches = 0;
foreach (var match in ExtendedMatchArray)
{
match.AliveMatch();
if (!match.Inside && !match.Completed)
{
match.Import(Match.StatusFlag.Watchable);
}
else
{
if (!match.Exported && (match.Done || match.TimeLeft == 0))
match.Export();
if (match.Exported)
doneMatches++;
}
}
if (doneMatches == ExtendedMatchArray.Length)
{
try
{
var top1 = ExtendedMatchArray[0].MatchStats
.First(p => p.Team.SkillFighterStats.Winner).Team.SkillFighterStats;
var top2 = ExtendedMatchArray[0].MatchStats
.First(p => !p.Team.SkillFighterStats.Winner).Team.SkillFighterStats;
Top8[0] = top1;
Top8[1] = top2;
ConstructTop8 = DateTime.Now;
var name = "SkillPk";
SaveTop8(string.Format("{0}{1}", name, GroupID));
foreach (var team in Teams.Values)
Remove(team.UID);
State = States.GUI_ReconstructTop;
foreach (var client in Kernel.GamePool.Values)
Rankings(client);
var brackets = CreateBrackets(ExtendedMatchArray, 0, Network.GamePackets.SkillPkBrackets.UpdateList);
foreach (var packet in brackets)
Kernel.SendWorldMessage(packet.ToArray());
Kernel.SendWorldMessage(new Network.GamePackets.SkillPkBrackets() { Type = 6, OnGoing = false }.ToArray());
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
}
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
}
}
}
#endregion
}
}
catch (Exception e)
{ Console.WriteLine(e.ToString()); }
}
public SkillPk.Match[] ArrayMatchesTop3()
{
SkillPk.Match[] array = new SkillPk.Match[((this.Top4MatchArray != null) ? this.Top4MatchArray.Length : 0) + ((this.ExtendedMatchArray != null) ? this.ExtendedMatchArray.Length : 0)];
int num = -1;
for (int i = 0; i < ((this.Top4MatchArray != null) ? this.Top4MatchArray.Length : 0); i++)
{
array[++num] = this.Top4MatchArray[i];
}
for (int i = 0; i < ((this.ExtendedMatchArray != null) ? this.ExtendedMatchArray.Length : 0); i++)
{
array[++num] = this.ExtendedMatchArray[i];
}
return array;
}
public bool GetReward(Client.GameState client, out byte Rank)
{
if (Top8.Length == 8)
{
for (int x = 0; x < Top8.Length; x++)
{
if (Top8[x] != null)
{
if (Top8[x].LeaderUID == client.Entity.UID || Top8[x].Name == client.Entity.Name)
{
if (Top8[x].RceiveReward == 0)
{
Top8[x].RceiveReward = 1;
Rank = (byte)(x + 1);
return true;
}
else
{
Rank = (byte)(x + 1);
return false;
}
}
}
}
}
Rank = 0;
return false;
}
public static bool GetReward(Client.GameState client)
{
if (!client.Inventory.HaveSpace(1))
{
client.MessageBox("Please Empty Some Space First");
return false;
}
foreach (var tournament in SkillPk.SkillTournament.Tournaments)
{
byte Rank = 0;
if (tournament.GetReward(client, out Rank))
{
var name = "SkillPk";
tournament.SaveTop8(string.Format("{0}{1}", name, tournament.GroupID));
uint ItemID = GetItemID(tournament, Rank);
if (client.Entity.Level >= 100 || client.Entity.Level >= 120 || client.Entity.Level >= 130)
{
if (Rank == 1)
{
client.Entity.ConquerPoints += 150000000;
client.Entity.AddTopStatus((ulong)XMeGo.Network.GamePackets.TitlePacket.Titles.ElitePKChamption_Low, 0, DateTime.Now.AddDays(1), true);
client.MessageBox("You've received [" + 150000000 + "] ConquerPoints ");
string MSG = "Congratulation to " + client.Entity.Name + " ! he/she managed to get rank " + Rank + " on SkillPK Tournament and claimed [" + 150000000 + "] ConquerPoints ";
Kernel.SendWorldMessage(new Message(MSG, System.Drawing.Color.Red, Message.System));
XMeGo.Kernel.SendWorldMessage(new Message("Congratulation to " + client.Entity.Name + " ! he/she managed to get rank " + Rank + " on SkillPK Tournament and claimed [" + 150000000 + "] ConquerPoints ", System.Drawing.Color.Black, Message.Center), Program.Values);
}
else if (Rank == 2)
{
client.Entity.ConquerPoints += 100000000;
client.Entity.AddTopStatus((ulong)XMeGo.Network.GamePackets.TitlePacket.Titles.ElitePK2ndPlace_Low, 0, DateTime.Now.AddDays(1), true);
client.MessageBox("You've received [" + 100000000 + "] ConquerPoints ");
string MSG = "Congratulation to " + client.Entity.Name + " ! he/she managed to get rank " + Rank + " on SkillPK Tournament and claimed [" + 100000000 + "] ConquerPoints ";
Kernel.SendWorldMessage(new Message(MSG, System.Drawing.Color.Red, Message.System));
XMeGo.Kernel.SendWorldMessage(new Message("Congratulation to " + client.Entity.Name + " ! he/she managed to get rank " + Rank + " on SkillPK Tournament and claimed [" + 100000000 + "] ConquerPoints ", System.Drawing.Color.Black, Message.Center), Program.Values);
}
else if (Rank == 3)
{
client.Entity.ConquerPoints += 50000000;
client.Entity.AddTopStatus((ulong)XMeGo.Network.GamePackets.TitlePacket.Titles.ElitePK3ndPlace_Low, 0, DateTime.Now.AddDays(1), true);
client.MessageBox("You've received [" + 50000000 + "] ConquerPoints ");
string MSG = "Congratulation to " + client.Entity.Name + " ! he/she managed to get rank " + Rank + " on SkillPK Tournament and claimed [" + 50000000 + "] ConquerPoints ";
Kernel.SendWorldMessage(new Message(MSG, System.Drawing.Color.Red, Message.System));
XMeGo.Kernel.SendWorldMessage(new Message("Congratulation to " + client.Entity.Name + " ! he/she managed to get rank " + Rank + " on SkillPK Tournament and claimed [" + 50000000 + "] ConquerPoints ", System.Drawing.Color.Black, Message.Center), Program.Values);
}
else
{
client.Entity.ConquerPoints += 50000000;
client.Entity.AddTopStatus((ulong)XMeGo.Network.GamePackets.TitlePacket.Titles.ElitePKTopEight_Low, 0, DateTime.Now.AddDays(1), true);
client.MessageBox("You've received [" + 50000000 + "] ConquerPoints ");
string MSG = "Congratulation to " + client.Entity.Name + " ! he/she managed to get rank " + Rank + " on SkillPK Tournament and claimed [" + 50000000 + "] ConquerPoints ";
Kernel.SendWorldMessage(new Message(MSG, System.Drawing.Color.Red, Message.System));
XMeGo.Kernel.SendWorldMessage(new Message("Congratulation to " + client.Entity.Name + " ! he/she managed to get rank " + Rank + " on SkillPK Tournament and claimed [" + 50000000 + "] ConquerPoints ", System.Drawing.Color.Black, Message.Center), Program.Values);
}
}
return true;
}
}
return false;
}
public static uint GetItemID(SkillPk tournament, byte Rank)
{
return (uint)(721300 + 1 * (byte)tournament.GroupID + Math.Min(3, (Rank - 1)) * 4);
}
public void Update(Client.GameState client, int page = 0)
{
try
{
if (State == States.GUI_Top8Ranking)
{
Rankings(client);
}
else
{
if (State >= States.GUI_Top4Qualifier)
{
var brackets = CreateBrackets(MatchArray, 0, Network.GamePackets.SkillPkBrackets.GUIEdit);
foreach (var packet in brackets)
client.Send(packet.ToArray());
}
else
{
var brackets = CreateBrackets(MatchArray, page);
foreach (var packet in brackets)
client.Send(packet.ToArray());
}
if (State >= States.GUI_Top1)
Rankings(client);
}
}
catch (Exception e) { Console.WriteLine(e.ToString()); }
}
public void Rankings(Client.GameState client)
{
Network.GamePackets.SkillPkTop ranks = new Network.GamePackets.SkillPkTop();
{
ranks.Type = Network.GamePackets.SkillPkTop.Top8;
ranks.Group = (uint)GroupID;
ranks.GroupStatus = (uint)State;
//ranks.UID = client.Player.UID;
if (State >= States.GUI_Top1)
{
ranks.Type = Network.GamePackets.SkillPkTop.Top3;
if (State == States.GUI_Top1)
{
ranks.Count = 1;
ranks.Append(Top8[2], 3);
}
else
{
ranks.Count = 3;
for (int i = 0; i < 3; i++)
{
ranks.Append(Top8[i], i + 1);
}
}
client.Send(ranks.ToArray());
}
else
{
ranks.Count = (uint)Top8.Length;
for (int i = 0; i < ranks.Count; i++)
if (Top8[i] != null)
{
ranks.Append(Top8[i], i + 1);
}
client.Send(ranks.ToArray());
}
}
}
public Network.GamePackets.SkillPkBrackets[] CreateBrackets(Match[] matches, int page = 0, byte type = 0)
{
try
{
int lim = 0, count = 0;
if (matches == null) return new Network.GamePackets.SkillPkBrackets[0];
if (State == States.GUI_Knockout)
{
const int max = 5;
int offset = page * max;
int Do_count = matches.Length - page * max;
if (page * max > matches.Length)
Do_count = 0;
uint ccount = (uint)Math.Min(max, Do_count);
Network.GamePackets.SkillPkBrackets brackets = new Network.GamePackets.SkillPkBrackets((int)ccount);
brackets.Group = (ushort)GroupID;
brackets.GUIType = (ushort)State;
brackets.TotalMatchesOnRoom = (ushort)ccount;
brackets.Page = (byte)page;
brackets.TimeLeft = TimeLeft;
brackets.MatchCount = (ushort)matches.Length;
brackets.Type = type;
for (int i = 0; i < ccount; i++)
{
var element = matches[i + offset];
brackets.Append(element);
}
Network.GamePackets.SkillPkBrackets[] buffer = new Network.GamePackets.SkillPkBrackets[1];
buffer[0] = brackets;
return buffer;
}
else if (State == States.GUI_Top8Qualifier)
{
const int max = 5;
int offset = page * max;
int Do_count = matches.Length - page * max;
if (page * max > matches.Length)
Do_count = 0;
uint ccount = (uint)Math.Min(max, Do_count);
Network.GamePackets.SkillPkBrackets[] buffer;
if (matches.Length > ccount)
buffer = new Network.GamePackets.SkillPkBrackets[2];
else
buffer = new Network.GamePackets.SkillPkBrackets[1];
Network.GamePackets.SkillPkBrackets brackets = new Network.GamePackets.SkillPkBrackets((int)ccount);
brackets.Group = (ushort)GroupID;
brackets.GUIType = (ushort)State;
brackets.TotalMatchesOnRoom = (ushort)ccount;
brackets.Page = (byte)page;
brackets.TimeLeft = TimeLeft;
brackets.MatchCount = (ushort)matches.Length;
brackets.Type = type;
for (int i = 0; i < ccount; i++)
{
var element = matches[i + offset];
brackets.Append(element);
}
buffer[0] = brackets;
if (matches.Length > ccount)
{
ushort towcount = (ushort)(matches.Length - ccount);
Network.GamePackets.SkillPkBrackets twobrackets = new Network.GamePackets.SkillPkBrackets((int)towcount);
twobrackets.Group = (ushort)GroupID;
twobrackets.GUIType = (ushort)State;
twobrackets.TotalMatchesOnRoom = (ushort)towcount;
twobrackets.Page = (byte)page;
twobrackets.TimeLeft = TimeLeft;
twobrackets.ListCount = 1;
twobrackets.MatchCount = (ushort)matches.Length;
twobrackets.Type = type;
for (int i = 0; i < towcount; i++)
{
var element = matches[i + ccount];
twobrackets.Append(element);
}
buffer[1] = twobrackets;
return buffer;
}
return buffer;
}
lim = matches.Length;
count = Math.Min(lim, matches.Length - page * lim);
if (State >= States.GUI_Top2Qualifier)
{
lim = MatchArray.Length;
count = Math.Min(lim, MatchArray.Length - page * lim);
Network.GamePackets.SkillPkBrackets[] buffer = new Network.GamePackets.SkillPkBrackets[2];
Network.GamePackets.SkillPkBrackets qbrackets = new Network.GamePackets.SkillPkBrackets(count);
{
qbrackets.Group = (ushort)GroupID;
qbrackets.GUIType = (ushort)State;
qbrackets.TotalMatchesOnRoom = (ushort)(count);
qbrackets.Page = (byte)page;
qbrackets.TimeLeft = TimeLeft;
qbrackets.MatchCount = (byte)(MatchArray.Length * 2);
qbrackets.Type = type;
for (int i = page * lim; i < page * lim + count; i++)
qbrackets.Append(MatchArray[i]);
buffer[0] = qbrackets;
}
if (State >= States.GUI_Top3)
{
lim = 4;
Network.GamePackets.SkillPkBrackets Twoqbrackets = new Network.GamePackets.SkillPkBrackets(count);
if (Top4MatchArray != null)
{
count = (byte)(Top4MatchArray.Length + ExtendedMatchArray.Length);
{
Twoqbrackets.Group = (ushort)GroupID;
Twoqbrackets.GUIType = (ushort)State;
Twoqbrackets.TotalMatchesOnRoom = (ushort)count;
Twoqbrackets.Page = (byte)1;
Twoqbrackets.TimeLeft = TimeLeft;
Twoqbrackets.MatchCount = (byte)((Top4MatchArray.Length + ExtendedMatchArray.Length) * 2);
Twoqbrackets.Type = type;
for (int i = 0; i < 2; i++)
Twoqbrackets.Append(Top4MatchArray[i]);
for (int x = 0; x < ExtendedMatchArray.Length; x++)
Twoqbrackets.Append(ExtendedMatchArray[x]);
buffer[1] = Twoqbrackets;
}
buffer[1] = Twoqbrackets;
}
else
{
lim = 4;
count = (byte)(ExtendedMatchArray.Length);
{
Twoqbrackets.Group = (ushort)GroupID;
Twoqbrackets.GUIType = (ushort)State;
Twoqbrackets.TotalMatchesOnRoom = (ushort)count;
Twoqbrackets.Page = (byte)1;
Twoqbrackets.TimeLeft = TimeLeft;
Twoqbrackets.MatchCount = (byte)((ExtendedMatchArray.Length) * 2);
Twoqbrackets.Type = type;
for (int x = 0; x < ExtendedMatchArray.Length; x++)
Twoqbrackets.Append(ExtendedMatchArray[x]);
buffer[1] = Twoqbrackets;
}
buffer[1] = Twoqbrackets;
}
}
else
{
lim = 2;
count = Top4MatchArray.Length;
Network.GamePackets.SkillPkBrackets Twoqbrackets = new Network.GamePackets.SkillPkBrackets(count);
{
Twoqbrackets.Group = (ushort)GroupID;
Twoqbrackets.GUIType = (ushort)State;
// Twoqbrackets.ListCount = 1;
Twoqbrackets.TotalMatchesOnRoom = (ushort)count;
Twoqbrackets.Page = (byte)1;
Twoqbrackets.TimeLeft = TimeLeft;
Twoqbrackets.MatchCount = (byte)MatchArray.Length;
Twoqbrackets.Type = type;
for (int i = page * lim; i < page * lim + count; i++)
Twoqbrackets.Append(Top4MatchArray[i]);
buffer[1] = Twoqbrackets;
}
}
return buffer;
}
Network.GamePackets.SkillPkBrackets aqbrackets = new Network.GamePackets.SkillPkBrackets(count);
{
aqbrackets.Group = (ushort)GroupID;
aqbrackets.GUIType = (ushort)State;
aqbrackets.TotalMatchesOnRoom = (ushort)count;
aqbrackets.Page = (byte)page;
aqbrackets.TimeLeft = TimeLeft;
aqbrackets.MatchCount = (ushort)matches.Length;
aqbrackets.Type = type;
for (int i = page * lim; i < page * lim + count; i++)
aqbrackets.Append(matches[i]);
Network.GamePackets.SkillPkBrackets[] buffer = new Network.GamePackets.SkillPkBrackets[1];
buffer[0] = aqbrackets;
return buffer;
}
}
catch (Exception e) { Console.WriteLine(e.ToString()); return new Network.GamePackets.SkillPkBrackets[0]; }
}
}
}
public class SkillPkBrackets
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using XMeGo.Game;
using XMeGo.Client;
using XMeGo.Game.Features.Tournaments;
namespace XMeGo.Network.GamePackets
{
public class SkillPkBrackets : Writer, Interfaces.IPacket
{
public const byte
InitialList = 0,
StaticUpdate = 1,
GUIEdit = 2,
UpdateList = 3,
RequestInformation = 4,
StopWagers = 5,
EPK_State = 6;
byte[] Buffer;
public SkillPkBrackets(int matches = 0)
{
{
Buffer = new byte[190 + 154 * matches];
WriteUInt16((ushort)(Buffer.Length - 8), 0, Buffer);
WriteUInt16((ushort)2252, 2, Buffer);
}
}
public byte Type
{
get { return Buffer[4]; }
set { Buffer[4] = value; }
}
public byte Page
{
get { return Buffer[6]; }
set { Buffer[6] = value; }
}
public byte ListCount
{
get { return Buffer[8]; }
set { Buffer[8] = value; }
}
public uint MatchCount
{
get { return BitConverter.ToUInt32(Buffer, 10); }
set { WriteUInt32(value, 10, Buffer); }
}
public ushort Group
{
get { return BitConverter.ToUInt16(Buffer, 14); }
set { WriteUInt16(value, 14, Buffer); }
}
public ushort GUIType
{
get { return BitConverter.ToUInt16(Buffer, 16); }
set { WriteUInt16(value, 16, Buffer); }
}
public ushort TimeLeft
{
get { return BitConverter.ToUInt16(Buffer, 18); }
set { WriteUInt16(value, 18, Buffer); }
}
public uint TotalMatchesOnRoom
{
get { return BitConverter.ToUInt16(Buffer, 20); }
set { WriteUInt32(value, 20, Buffer); }
}
public bool OnGoing
{
get { return Buffer[20] == 1; }
set { WriteBoolean(value, 20, Buffer); }
}
private int offset = 24;
public void Append(SkillPk.Match match)
{
try
{
if (match == null)
return;
if (GUIType != GUIEdit)
WriteUint(match.ID, offset, Buffer);
offset += 4;
WriteUshort((ushort)match.MatchStats.Length, offset, Buffer); offset += 2;
WriteUshort((ushort)match.Index, offset, Buffer); offset += 2;
WriteUshort((ushort)match.Flag, offset, Buffer);
offset += 2;
for (int i = 0; i < match.MatchStats.Length; i++)
{
AppendPlayer(match.MatchStats[i], offset);
offset += 48;
}
if (match.MatchStats.Length == 2) offset += 48;
if (match.MatchStats.Length == 1) offset += 96;
//if (match.MatchStats.Length == 0) offset += 144;
}
catch (Exception e) { Console.WriteLine(e.ToString()); }
}
private void AppendPlayer(SkillPk.FighterStats stats, int _offset)
{
//if (stats == null)
//{
// offset += 48;
// return;
//}
// WriteUint(0, _offset, Buffer); _offset += 4;
WriteUint(stats.Team.UID, _offset, Buffer); _offset += 4;
WriteUint(stats.LeaderUID, _offset, Buffer); _offset += 4;//
WriteUint(stats.LeaderMesh, _offset, Buffer); _offset += 4;
WriteString(stats.Name, _offset, Buffer); _offset += 32;
WriteUint((uint)stats.Flag, _offset, Buffer); _offset += 4;
}
//794 8 Matches
public void Send(GameState client)
{
client.Send(Buffer);
}
public byte[] ToArray()
{
return Buffer;
}
public void Deserialize(byte[] buffer)
{
Buffer = buffer;
}
}
}
public class SkillPkMatchStats
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using XMeGo.Client;
using XMeGo.Game;
using XMeGo.Game.Features.Tournaments;
namespace XMeGo.Network.GamePackets
{
public class SkillPkMatchStats : Writer, Interfaces.IPacket
{
byte[] Buffer;
public SkillPkMatchStats()
{
Buffer = new byte[128 + 8];
WriteUInt16(128, 0, Buffer);
WriteUshort((ushort)2251, 2, Buffer);
}
public void Append(SkillPk.Match match)
{
ushort offset = 4;
var array = match.MatchStats.Where(p => p.Fighting).ToArray();
AppendPlayer(array[0], offset);
offset = 64;//60
if (array.Length > 1)
AppendPlayer(array[1], offset);
}
public uint val1 = 1;
public uint val2 = 0;
public uint val3 = 0;//120
public uint val4 = 0;
private void AppendPlayer(SkillPk.FighterStats team, ushort offset)
{
WriteUint(team.LeaderUID, offset, Buffer); offset += 4; // 16+16+32 64
WriteUint(team.Team.UID, offset, Buffer); offset += 4;
WriteString(team.Team.Lider.Entity.Name, offset, Buffer); offset += 16;//???
WriteString(team.Name, offset, Buffer); offset += 32;
WriteUint(team.Points, offset, Buffer); offset += 4;
}
public void Send(GameState client)
{
client.Send(Buffer);
}
public byte[] ToArray()
{
return Buffer;
}
public void Deserialize(byte[] buffer)
{
Buffer = buffer;
}
}
}
public class SkillPkMatchUI
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using XMeGo.Client;
using XMeGo.Game.Features.Tournaments;
namespace XMeGo.Network.GamePackets
{
public class SkillPkMatchUI : Writer, Interfaces.IPacket
{
public const byte
BeginMatch = 2,
Effect = 3,
EndMatch = 4,
Information = 7,
Reward = 8;
public const uint
Effect_Win = 1,
Effect_Lose = 0;
byte[] Buffer;
public SkillPkMatchUI()
{
{
Buffer = new byte[52 + 8];
WriteUInt16(52, 0, Buffer);
WriteUshort(2250, 2, Buffer);
}
}
public uint Type
{
get { return BitConverter.ToUInt32(Buffer, 4); }
set { WriteUInt32(value, 4, Buffer); }
}
public uint dwParam
{
get { return BitConverter.ToUInt32(Buffer, 8); }
set { WriteUInt32(value, 8, Buffer); }
}
public uint OpponentUID
{
get { return BitConverter.ToUInt32(Buffer, 12); }
set { WriteUInt32(value, 12, Buffer); }
}
public string OpponentName
{
get { return Program.Encoding.GetString(Buffer, 16, 16).Trim(); }
set { WriteString(value, 16, Buffer); }
}
public uint TimeLeft
{
get { return BitConverter.ToUInt32(Buffer, 44); }
set { WriteUInt32(value, 44, Buffer); }
}
public void Append(Game.ConquerStructures.Team opponent)
{
OpponentUID = opponent.Lider.Entity.UID;
if (opponent.SkillFighterStats != null)
OpponentName = opponent.SkillFighterStats.Name;
}
public void Send(GameState client)
{
client.Send(Buffer);
}
public byte[] ToArray()
{
return Buffer;
}
public void Deserialize(byte[] buffer)
{
Buffer = buffer;
}
}
}
public class SkillPkSetTeamName
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace XMeGo.Network.GamePackets
{
public class SkillPkSetTeamName : Writer
{
byte[] packet;
public byte[] ToArray() { return packet; }
public const byte Apprend = 0, SuccessfulName = 1, RenameWasSuccessfulName = 2, Remove = 3;
public SkillPkSetTeamName()
{
packet = new byte[56];
WriteUInt16(48, 0, packet);
WriteUInt16(2260, 2, packet);
}
public uint Type { get { return BitConverter.ToUInt32(packet, 4); } set { WriteUInt32(value, 4, packet); } }
public uint TeamID { get { return BitConverter.ToUInt32(packet, 8); } set { WriteUInt32(value, 8, packet); } }
public string TeamName //BastA`s.team
{
get { return PacketHandler.ReadString(packet, 12, 32); }
set { WriteString(value, 12, packet); }
}
}
}
public class SkillPkTop
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace XMeGo.Network.GamePackets
{
public class SkillPkTop : Writer
{
byte[] packet;
public byte[] ToArray()
{
return packet;
}
public const byte Top3 = 2, Top8 = 0;
public SkillPkTop()
{
packet = new byte[428];
WriteUInt16((ushort)(packet.Length - 8), 0, packet);
WriteUInt16(2253, 2, packet);
}
public uint Type { get { return BitConverter.ToUInt32(packet, 4); } set { WriteUInt32(value, 4, packet); } }//top 3, top 8
public uint Group { get { return BitConverter.ToUInt32(packet, 8); } set { WriteUInt32(value, 8, packet); } }//8
public uint GroupStatus { get { return BitConverter.ToUInt32(packet, 12); } set { WriteUInt32(value, 12, packet); } }
public uint Count { get { return BitConverter.ToUInt32(packet, 16); } set { WriteUInt32(value, 16, packet); } }
public uint ClientUID { get { return BitConverter.ToUInt32(packet, 20); } set { WriteUInt32(value, 20, packet); } }
private int Index = 0;
public void Append(Game.Features.Tournaments.SkillPk.FighterStats stats, int rank)
{
if (stats == null)
{
Console.WriteLine("Rank Null");
return;
}
ushort offset = (ushort)(20 + Index * 44); Index++;
WriteUInt32(stats.LeaderUID, offset, packet); offset += 4;
WriteUInt32((uint)rank, offset, packet); offset += 4;
WriteString(stats.Name, offset, packet); offset += 32;
WriteUInt32(stats.LeaderMesh, offset, packet); offset += 4;
}
}
}
public class SkillPKWager
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using XMeGo.Game;
using XMeGo.Client;
namespace XMeGo.Network.GamePackets
{
public class SkillPKWager : Writer, Interfaces.IPacket
{
public const byte
SetWager = 2;
byte[] Buffer;
public SkillPKWager()
{
}
public byte Type
{
get { return Buffer[4]; }
set { Buffer[4] = value; }
}
public uint dwParam
{
get { return BitConverter.ToUInt32(Buffer, 8); }
set { WriteUInt32(value, 8, Buffer); }
}
public uint WagedUID
{
get { return BitConverter.ToUInt32(Buffer, 12); }
set { WriteUInt32(value, 12, Buffer); }
}
public uint Wager
{
get { return BitConverter.ToUInt32(Buffer, 20); }
set { WriteUInt32(value, 20, Buffer); }
}
public void Send(GameState client)
{
client.Send(Buffer);
}
public byte[] ToArray()
{
return Buffer;
}
public void Deserialize(byte[] buffer)
{
Buffer = buffer;
}
}
}
#region SkillTeam Tournament
case 8592:
{
switch (npcRequest.OptionID)
{
case 0:
{
dialog.Text("The new Skill Team PK Tournament is open! It is held at 21:55, every Day.");
dialog.Text("~The contestants will receive EXP worth 1 EXP Ball and 1,000 Honor Points for each round!");
dialog.Text("~The top 8 teams will receive extra prizes!");
dialog.Option("What about the rules? ", 1);
dialog.Option("Sign up!", 2);
dialog.Option("Claim~prize.", 3);
dialog.Option("Leave.", 255);
dialog.Avatar(40);
dialog.Send();
break;
}
case 3:
{
if (client.ClaimedSkillTeam == 1)
{
dialog.Text("You really get your prizes.");
dialog.Option("Oh Sorry.", 255);
dialog.Avatar(26);
dialog.Send();
break;
}
else
{
if (Game.Features.Tournaments.SkillPk.GetReward(client))
{
client.ClaimedSkillTeam = 1;
}
else
{
dialog.Text("I`m sorry, but only the leaders from the top 8 teams are able to claim the prizes.");
dialog.Option("Oh.", 255);
dialog.Avatar(40);
dialog.Send();
}
break;
}
}
case 1:
{
dialog.Text("There are limits on the Equipment Level and Rank. Moreover, there are restrictions on Equipment Quality, Bonus Level, Sockets, Gems and Blessing effects.");
dialog.Text("~Besides, the effects of the Sub-classes are adjusted, too. (Except for Apothecary.)");
dialog.Text("~By the way, the Battle Power shared from your Clan, Mentor, and Guild won`t count.");
dialog.Option("Go~ahead.", 4);
dialog.Avatar(40);
dialog.Send();
break;
}
case 4:
{
dialog.Text("The Skill Team PK Tournament is held at 21:55, every Wednesday. You need to team up with others to take part in it. Only the team leaders are capable of claiming the rewards.");
dialog.Text("~You can team up with your friends in advance, or while in the waiting area. People who don`t team up will be kicked out, when the contest starts.");
dialog.Text("~There are 4 groups: Level 130+, level 120-129, level 100-119 and level 1-99.");
dialog.Option("What~else?", 5);
dialog.Avatar(40);
dialog.Send();
break;
}
case 5:
{
dialog.Text("You can talk to me to enter the waiting area at 21:55. No teams will be allowed to enter after the contest starts.");
dialog.Text("~The contest for level 130+ starts at 22:00, level 120-129: 22:02, level 100-119: 22:04 and level 1-99: 22:06.");
dialog.Text("~Disbanding/creating a team during the contest will lead to disqualification. In the knockout stage, each round lasts for 10 minutes.");
dialog.Option("Is~that~all?", 6);
dialog.Avatar(40);
dialog.Send();
break;
}
case 6:
{
dialog.Text("If there are no more than 8 teams, it will enter the final stage directly and each round lasts for 15 minutes.");
dialog.Text("~The top 3 teams will be announced. The leaders from the top 8 teams should claim the prize before the next Skill Team PK Tournament starts.");
dialog.Text("~The contestants will receive EXP worth 1 EXP Ball and 1,000 Honor Points, for each round.");
dialog.Option("Sign~up~now!", 2);
dialog.Option("I~see.", 255);
dialog.Avatar(40);
dialog.Send();
break;
}
case 2:
{
if (Game.Features.Tournaments.SkillPk.SkillTournament.Opened)
{
if (client.Team != null)
{
if (client.Team.RightTeamElite())
{
if (!Game.Features.Tournaments.SkillPk.SkillTournament.Join(client, client.Team.GetEliteGroup(client.Entity.Level)))
{
dialog.Text("Sorry, but your tournament on grup was staring..");
dialog.Option("Ok thx.", 255);
dialog.Avatar(40);
dialog.Send();
}
}
else
{
dialog.Text("I'm sorry, but your Team must have players with the same level and in the same internships.");
dialog.Text("Exemple: ( full 100-, or full 100-120, or full 120-130, or full 130+)");
dialog.Option("Ok thx.", 255);
dialog.Avatar(40);
dialog.Send();
}
}
else
{
dialog.Text("Please create team");
dialog.Option("Ok thx.", 255);
dialog.Avatar(40);
dialog.Send();
}
}
else
{
dialog.Text("The Skill Team PK Tournament is held every Day. Please come back on Wed. at 21:55.");
dialog.Option("Alright.", 255);
dialog.Avatar(40);
dialog.Send();
}
break;
}
}
break;
}
#endregion
#region SkillTeamPk
if (((Now64.Hour == SkillPk.EventTime) && Now64.Minute >= 55) && !SkillPk.SkillTournament.Opened)
Game.Features.Tournaments.SkillPk.SkillTournament.Open();
#endregion
public static bool GetReward(Client.GameState client)
|
الذين يشاهدون محتوى الموضوع الآن : 1 ( الأعضاء 0 والزوار 1) | |
|
الموضوع | كاتب الموضوع | المنتدى | مشاركات | آخر مشاركة |
ابجريد التيم بك + الاسكل تيم | Hassan Emprator | تطوير سيرفرات كونكر | 6 | 2022-04-06 08:54 PM |
مشكلة في توبات التيم الاسكل الاليت | ElSaher | مشكلات السيرفيرات كونكر الشخصيه | 5 | 2020-04-20 10:04 PM |
تعديل في مواعيد التيم الاسكل الاليت | ElSaher | مشكلات السيرفيرات كونكر الشخصيه | 9 | 2020-02-20 07:35 PM |
مشكله بخصوص الاسكل تيم بيكي وي التيم بيكي وي اليت جيلد وير | سمير | مشكلات السيرفيرات كونكر الشخصيه | 3 | 2019-10-25 08:44 PM |
مشكلة في الاسكل و التيم بكي | manshestar | مشكلات السيرفيرات كونكر الشخصيه | 1 | 2019-08-05 11:02 AM |