Files
reallife-gamemode/ReallifeGamemode.Server/Util/CheckPointHandle.cs
2019-09-12 19:40:36 +02:00

94 lines
2.5 KiB
C#

using System;
using System.Collections.Generic;
using System.Text;
using ReallifeGamemode.Server.Entities;
using ReallifeGamemode.Server.Extensions;
using ReallifeGamemode.Server.Finance;
using ReallifeGamemode.Server.Models;
using ReallifeGamemode.Server.Services;
using ReallifeGamemode.Server.Util;
using GTANetworkAPI;
using System.Collections;
using System.Linq;
namespace ReallifeGamemode.Server.Util
{
public class CheckPointHandle : Script
{
public static List<CheckPointListForPlayer> listHandle = new List<CheckPointListForPlayer>();
public static void StartCheckPointRoute(Client player, IEnumerable<Vector3> nListCps)
{
CheckPointListForPlayer playerHandle = new CheckPointListForPlayer(player, nListCps);
listHandle.Add(playerHandle);
playerHandle.StartRoute();
}
public static void RemovePlayerHandlerFromList(Client player)
{
CheckPointListForPlayer temp = null;
for (int a = 0; a < listHandle.Count; a++)
{
temp = listHandle[a];
if (temp.player == player)
{
listHandle.Remove(temp);
}
}
}
[RemoteEvent("playerInCheckpoint")]
public void PlayerInCheckpoint(Client user)
{
CheckPointListForPlayer temp = null;
for (int a = 0; a < listHandle.Count; a++)
{
temp = listHandle[a];
if (temp.player == user)
{
break;
}
}
temp.NextCheckpoint();
ChatService.Broadcast("neuer cp");
}
}
public class CheckPointListForPlayer
{
public IEnumerable<Vector3> list = new List<Vector3>();
public Client player;
Vector3 checkPoint;
bool done;
int checkPointsDone = 0;
public CheckPointListForPlayer(Client nPlayer, IEnumerable<Vector3> nList)
{
this.player = nPlayer;
this.list = nList;
}
public void StartRoute()
{
player.TriggerEvent("setCheckPoint", this.list.ElementAt(0), player);
}
public void NextCheckpoint()
{
this.checkPointsDone++;
if (this.list.Count() > checkPointsDone)
{
Vector3 nextCp = list.ElementAt(checkPointsDone);
ChatService.SendMessage(this.player, "cp set at " + nextCp.ToString());
this.player.TriggerEvent("setCheckPoint", nextCp, player);
}
if (this.list.Count() == checkPointsDone)
{
ChatService.SendMessage(this.player, "Du hast alle Checkpoints abgefahren!");
CheckPointHandle.RemovePlayerHandlerFromList(this.player);
}
}
}
}