diff --git a/ReallifeGamemode.Server/Gangwar/Turf.cs b/ReallifeGamemode.Server/Gangwar/Turf.cs new file mode 100644 index 00000000..53b36591 --- /dev/null +++ b/ReallifeGamemode.Server/Gangwar/Turf.cs @@ -0,0 +1,112 @@ +using System; +using System.Collections.Generic; +using System.Text; +using GTANetworkAPI; +using System.Timers; +using System.Linq; +using ReallifeGamemode.Server.Extensions; + +namespace ReallifeGamemode.Server.Gangwar +{ + public class Turf + { + + public int TurfID { get; set; } + public string TurfName { get; set; } + public int Color { get; set; } + public string Owner { get; set; } + public string Attacker { get; set; } + public int Att_Score { get; set; } + public int Def_Score { get; set; } + public string status { get; set; } + public Client[] playerInside { get; set; } + public Timer timer { get; set; } + + + public Turf(int TurfID, string TurfName, int color, string Owner) + { + this.TurfID = TurfID; + this.TurfName = TurfName; + this.Color = color; + this.Owner = Owner; + this.Attacker = null; + this.Att_Score = 50; + this.Def_Score = 50; + this.status = "normal"; + this.playerInside = null; + this.timer = null; + } + + public int getId() + { + return this.TurfID; + } + + public string getName() + { + return this.TurfName; + } + + public int getColor() + { + return this.Color; + } + + public string getOwner() + { + return this.TurfName; + } + + public string getAttacker() + { + return this.Attacker; + } + + private void TurfTick() + { + this.timer = new System.Timers.Timer(1000); + + this.timer.Elapsed += Tick; + this.timer.AutoReset = true; + this.timer.Enabled = true; + } + + private void Tick(object sender, System.Timers.ElapsedEventArgs e) + { + if(this.status == "attack") + { + update(); + } + } + + private void update() + { + Client[] owners = this.playerInside.Where(c => c.GetUser().Faction.Name == this.Owner ).ToArray(); + Client[] attackers = this.playerInside.Where(c => c.GetUser().Faction.Name == this.Attacker).ToArray(); + + if (owners.Length > attackers.Length) + this.Att_Score -= owners.Length - attackers.Length; + if(owners.Length < attackers.Length) + this.Def_Score -= attackers.Length - owners.Length; + } + + public void enter(Client client) + { + if(Array.IndexOf(this.playerInside, client) == -1) { + Client[] refObj = this.playerInside; + Array.Resize(ref refObj, this.playerInside.Length + 1); + this.playerInside = refObj; + this.playerInside[this.playerInside.GetUpperBound(0)] = client; + } + } + + public void leave(Client client) + { + if(Array.IndexOf(this.playerInside, client) > -1) + { + this.playerInside = this.playerInside.Where(c => c != client).ToArray(); + } + } + + } +}