Code:
using System;
using System.Collections;
using MayaConquer_v2.World;
using MayaConquer_v2.Kernel;
using MayaConquer_v2.Features;
using MayaConquer_v2.Structures;
using MayaConquer_v2.GameSystem;
using System.Collections.Generic;
namespace MayaConquer_v2.Features
{
public partial class GuildWars
{
public static string PoleHolder = "None";
public static Pole ThePole;
public static Gate TheLeftGate;
public static Gate TheRightGate;
public static bool War;
public static Dictionary<uint, GWScore> Points;
public static Hashtable Scores;
public static DateTime LastScores;
public static Guild LastWinner;
public struct Gate
{
public Location Loc;
public uint MaxHP;
public uint CurHP;
public uint EntityID;
public uint Mesh;
public bool Opened
{
set
{
if (EntityID == 6701)//Left Gate
{
if (value) Mesh = 250;
else Mesh = 240;
}
else if (EntityID == 6702)//Right Gate
{
if (value) Mesh = 280;
else Mesh = 270;
}
}
get
{
if (EntityID == 6701)//Left Gate
{
if (Mesh == 250) return true;
else return false;
}
else if (EntityID == 6702)//Right Gate
{
if (Mesh == 280) return true;
else return false;
}
return false;
}
}
public void Spawn(Character C, bool Check)
{
if (C.Loc.Map == Loc.Map && Calculate.InBox(C.Loc.X, C.Loc.Y, Loc.X, Loc.Y, 16) && (!Calculate.InBox(C.Loc.PreviousX, C.Loc.PreviousY, Loc.X, Loc.Y, 16) || !Check))
C.Client.Send(ConquerPacket.SpawnNPCWithHP(EntityID, (ushort)Mesh, 26, Loc, true, "Gate", CurHP, MaxHP));
}
public void ReSpawn()
{
foreach (Character C in Game.H_Chars.Values)
{
if (C.Loc.Map == Loc.Map && Calculate.InBox(C.Loc.X, C.Loc.Y, Loc.X, Loc.Y, 16))
C.Client.Send(ConquerPacket.SpawnNPCWithHP(EntityID, (ushort)Mesh, 26, Loc, true, "Gate", CurHP, MaxHP));
}
}
public void ReciveDamage(Character C, uint Damage, byte AtkType)
{
if (AtkType != 21)
{
Actions.Action(C, ConquerPacket.AttackPacket(C.EntityID, EntityID, Loc.X, Loc.Y, Damage, AtkType).Get);
}
if (Damage >= CurHP)
{
C.AtkMem.Attacking = false;
C.AtkMem.Target = 0;
Actions.Action(C, ConquerPacket.AttackPacket(C.EntityID, EntityID, Loc.X, Loc.Y, 0, 14).Get);
Opened = true;
ReSpawn();
}
else
{
CurHP -= Damage;
}
}
}
public struct Pole
{
public Location Loc;
public uint MaxHP;
public uint CurHP;
public uint Mesh;
public uint EntityID;
public void Spawn(Character C, bool Check)
{
if (C.Loc.Map == Loc.Map && Calculate.InBox(C.Loc.X, C.Loc.Y, Loc.X, Loc.Y, 16) && (!Calculate.InBox(C.Loc.PreviousX, C.Loc.PreviousY, Loc.X, Loc.Y, 16) || !Check))
{
if (LastWinner == null)
C.Client.Send(ConquerPacket.SpawnNPCWithHP(EntityID, (ushort)Mesh, 10, Loc, true, "Pole", CurHP, MaxHP));
else
C.Client.Send(ConquerPacket.SpawnNPCWithHP(EntityID, (ushort)Mesh, 10, Loc, true, LastWinner.Name, CurHP, MaxHP));
}
}
public void ReSpawn()
{
foreach (Character C in Game.H_Chars.Values)
{
if (C.Loc.Map == Loc.Map && Calculate.InBox(C.Loc.X, C.Loc.Y, Loc.X, Loc.Y, 16))
{
if (LastWinner == null)
C.Client.Send(ConquerPacket.SpawnNPCWithHP(EntityID, (ushort)Mesh, 10, Loc, true, "Pole", CurHP, MaxHP));
else
C.Client.Send(ConquerPacket.SpawnNPCWithHP(EntityID, (ushort)Mesh, 10, Loc, true, LastWinner.Name, CurHP, MaxHP));
}
}
}
public void TakeAttack(Character C, uint Damage, byte AtkType)
{
if (War && C.Guild != null && C.Guild != LastWinner)
{
if (AtkType != 21)
Actions.Action(C, ConquerPacket.AttackPacket(C.EntityID, EntityID, Loc.X, Loc.Y, Damage, AtkType).Get);
if (Damage >= CurHP)
{
AddScore(C.Guild, CurHP);
C.AtkMem.Attacking = false;
C.AtkMem.Target = 0;
Actions.Action(C, ConquerPacket.AttackPacket(C.EntityID, EntityID, Loc.X, Loc.Y, 0, 14).Get);
CurHP = MaxHP;
EndWar();
}
else
{
CurHP -= Damage;
AddScore(C.Guild, ((Damage * 20) / 100));
}
}
}
}
public static void Init()
{
War = false;
Points = new Dictionary<uint, GWScore>();
LastScores = DateTime.Now;
ThePole = new Pole();
ThePole.EntityID = 6700;
ThePole.Mesh = 1137;
ThePole.CurHP = 20000000;
ThePole.MaxHP = 20000000;
ThePole.Loc = new Location();
ThePole.Loc.Map = 1038;
ThePole.Loc.X = 84;
ThePole.Loc.Y = 99;
TheLeftGate = new Gate();
TheLeftGate.EntityID = 6701;
TheLeftGate.Opened = false;
TheLeftGate.MaxHP = 10000000;
TheLeftGate.CurHP = 10000000;
TheLeftGate.Loc = new Location();
TheLeftGate.Loc.Map = 1038;
TheLeftGate.Loc.X = 163;
TheLeftGate.Loc.Y = 210;
TheLeftGate.ReSpawn();
TheRightGate = new Gate();
TheRightGate.EntityID = 6702;
TheRightGate.Opened = false;
TheRightGate.MaxHP = 10000000;
TheRightGate.CurHP = 10000000;
TheRightGate.Loc = new Location();
TheRightGate.Loc.Map = 1038;
TheRightGate.Loc.X = 222;
TheRightGate.Loc.Y = 177;
TheRightGate.ReSpawn();
}
public static void AddScore(Guild G, uint Damage)
{
if (!Scores.Contains(G.ID))
{
GWScore S = new GWScore();
S.Score = (Damage * 20 / 100);
S.TheGuild = G;
S.TheGuild.Fund += (Damage / 1000);
Points.Add(G.ID, S);
}
else
{
Points[G.ID].Score += (Damage * 20 / 100);
Points[G.ID].TheGuild.Fund += (Damage / 1000);
}
}
public static string[] ShuffleGuildScores()
{
try
{
string[] ret = new string[5];
DictionaryEntry[] Vals = new DictionaryEntry[5];
for (sbyte i = 0; i < 5; i++)
{
Vals[i] = new DictionaryEntry();
Vals[i].Key = (ushort)0;
Vals[i].Value = (uint)0;
}
foreach (DictionaryEntry Score in Scores)
{
sbyte Pos = -1;
for (sbyte i = 0; i < 5; i++)
{
if (((GWScore)Score.Value).Score > (uint)Vals[i].Value)
{
Pos = i;
break;
}
}
if (Pos == -1)
continue;
for (sbyte i = 4; i > Pos; i--)
Vals[i] = Vals[i - 1];
Vals[Pos] = Score;
}
for (sbyte i = 0; i < 5; i++)
{
if ((ushort)Vals[i].Key == 0)
{
ret[i] = "";
continue;
}
Guild eGuild = Game.GameGuilds[(ushort)Vals[i].Key];
ret[i] = "N° " + (i + 1).ToString() + ": " + eGuild.Name + "(" + ((GWScore)Vals[i].Value).Score + ")";
}
return ret;
}
catch (Exception Exc) { Game.WriteLine(Exc); return null; }
}
public static void SendScores()
{
LastScores = DateTime.Now;
string[] ShuffledScores = ShuffleGuildScores();
if (ShuffledScores != null)
{
foreach (Character C in Game.H_Chars.Values)
{
if (C.Loc.Map == 1038)
{
byte c = 0;
foreach (string t in ShuffledScores)
{
if (t != "")
{
if (c == 0)
C.Client.Send(ConquerPacket.ChatMessage(0, "SYSTEM", "ALLUSERS", t, 0x83c, 0));
else
C.Client.Send(ConquerPacket.ChatMessage(0, "SYSTEM", "ALLUSERS", t, 0x83d, 0));
}
c++;
}
}
}
}
}
public static void StartWar()
{
Init();
Actions.SendMsgToAll("SYSTEM", "Guild War has Started!", 2011, 0);
War = true;
}
public static void EndWar()
{
War = false;
TheLeftGate.Opened = false;
TheRightGate.Opened = false;
TheLeftGate.CurHP = TheLeftGate.MaxHP;
TheRightGate.CurHP = TheRightGate.MaxHP;
TheLeftGate.ReSpawn();
TheRightGate.ReSpawn();
GWScore Highest = new GWScore();
Highest.Score = 0;
foreach (GWScore Score in Points.Values)
{
if (Highest.TheGuild.ID != Score.TheGuild.ID)
if (Highest.Score < Score.Score)
Highest = Score;
}
if (Highest.TheGuild != null)
{
LastWinner = Highest.TheGuild;
LastWinner.Wins++;
ThePole.ReSpawn();
Actions.SendMsgToAll("SYSTEM", Highest.TheGuild.Name + " has won!", 2011, 0);
}
SendScores();
Points = new Dictionary<uint, GWScore>();
//StartWar();
}
public static void StopWar()
{
War = false;
TheLeftGate.Opened = false;
TheRightGate.Opened = false;
TheLeftGate.CurHP = TheLeftGate.MaxHP;
TheRightGate.CurHP = TheRightGate.MaxHP;
TheLeftGate.ReSpawn();
TheRightGate.ReSpawn();
GWScore Highest = new GWScore();
Highest.Score = 0;
foreach (GWScore Score in Points.Values)
{
if (Highest.TheGuild.ID != Score.TheGuild.ID)
if (Highest.Score < Score.Score)
Highest = Score;
}
if (Highest.TheGuild != null)
{
LastWinner = Highest.TheGuild;
LastWinner.Wins++;
ThePole.ReSpawn();
Actions.SendMsgToAll("SYSTEM", Highest.TheGuild.Name + " has won!", 2011, 0);
}
SendScores();
Points = new Dictionary<uint, GWScore>();
}
public class GWScore
{
public Guild TheGuild;
public uint Score;
}
}
}