continue Gangwar System

This commit is contained in:
Lukas Moungos
2019-11-30 18:54:11 +01:00
parent e3dbf7c4e1
commit a4303a1a01
14 changed files with 1904 additions and 6 deletions

View File

@@ -52,7 +52,7 @@ namespace ReallifeGamemode.Server.Events
player.SetData("spec", true);
player.SetData("duty", false);
player.TriggerEvent("SERVER:SET_HANDMONEY", user.Handmoney, 0);
Gangwar.Gangwar.loadClient(player);
if (user.IsAdmin(AdminLevel.HEADADMIN) == true)
{
player.SetData("editmode", false);
@@ -102,8 +102,6 @@ namespace ReallifeGamemode.Server.Events
{
Jail.Check_PutBehindBars(player);
}
}
player.TriggerEvent("draw", player.Name, player.Handle.Value);

View File

@@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;
using System.Text;
using GTANetworkAPI;
using System.Linq;
using ReallifeGamemode.Database.Models;
using ReallifeGamemode.Database.Entities;
using Newtonsoft.Json;
namespace ReallifeGamemode.Server.Gangwar
{
public class Gangwar
{
public static Turf[] _loadedTurfs;
private static List<Turfs> turfs;
public static void loadTurfs()
{
_loadedTurfs = null;
using (var context = new DatabaseContext())
{
turfs = context.Turfs.Select(t => t).ToList();
List<Turf> turfing = new List<Turf>();
foreach (var t in turfs)
{
Turf newTurf = new Turf(t.Id, t.Name, t.Color, t.Owner);
turfing.Add(newTurf);
}
_loadedTurfs = turfing.ToArray();
}
}
public static void loadClient(Client client)
{
client.TriggerEvent("GangAreas:Create", JsonConvert.SerializeObject(turfs.ToArray()));
}
public Turf[] getTurfs()
{
return _loadedTurfs;
}
}
}

View File

@@ -83,11 +83,23 @@ namespace ReallifeGamemode.Server.Gangwar
{
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;
*/
foreach (Client playerInArea in this.playerInside)
{
playerInArea.TriggerEvent("CLIENT:Turf_Update", this.TurfID, this.status, this.Owner, this.Attacker, this.Color, this.Att_Score, this.Def_Score);
}
if(this.Def_Score <= 0)
{
this.takeOver(this.Attacker);
}else if(this.Att_Score <= 0)
{
this.takeOver(this.Owner);
}
}
public void enter(Client client)
@@ -107,6 +119,33 @@ namespace ReallifeGamemode.Server.Gangwar
this.playerInside = this.playerInside.Where(c => c != client).ToArray();
}
}
public void takeOver(string FactionName)
{
this.timer.Stop();
this.timer = null;
}
public void attack(Client client)
{
if(this.status == "normal")
{
if(this.timer != null)
{
this.timer.Stop();
this.timer = null;
}
this.Attacker = client.GetUser().Faction.Name;
this.status = "attack";
foreach(Client playerInArea in this.playerInside)
{
playerInArea.TriggerEvent("CLIENT:Turf_Update", this.TurfID, this.status, this.Owner, this.Attacker, this.Color, this.Att_Score, this.Def_Score);
}
this.TurfTick();
}
}
}
}

View File

@@ -62,6 +62,7 @@ namespace ReallifeGamemode.Server
HouseManager.LoadHouses();
DrivingSchool.DrivingSchool.Setup();
PlaneSchool.Setup();
Gangwar.Gangwar.loadTurfs();
TempBlip tempBlip = new TempBlip()
{

View File

@@ -723,8 +723,15 @@ namespace ReallifeGamemode.Server.Managers
Vector3 lastPosition = v.Position;
if (lastPositions.ContainsKey(v.Handle)) lastPosition = lastPositions[v.Handle];
lastPositions[v.Handle] = v.Position;
double distanceDriven = v.HasSharedData("drivenDistance") ? (double)v.GetSharedData("drivenDistance") : 0D;
double distanceDriven;
try
{
distanceDriven = v.HasSharedData("drivenDistance") ? (double)v.GetSharedData("drivenDistance") : 0D;
}
catch(Microsoft.CSharp.RuntimeBinder.RuntimeBinderException ex)
{
distanceDriven = (double)0;
}
double distance = lastPosition.DistanceTo(v.Position) / 1000.0;
if (distance > 0.2) return;