-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathMainEntryPoint.cs
110 lines (94 loc) · 3.17 KB
/
MainEntryPoint.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
using BattleRoyale.Structure;
using GTANetworkServer;
using GTANetworkShared;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
namespace BattleRoyale
{
public class MainEntryPoint : Script
{
public delegate void CheckBattleRoyale();
public static CheckBattleRoyale onCheckBattleRoyale;
#region Variables
public static List<Player> Players = new List<Player>();
public static BattleRoyale BattleRoyale;
public static Map Map;
#endregion
public MainEntryPoint()
{
API.onResourceStart += OnResourceStart;
onCheckBattleRoyale += CheckStartConditions;
}
public void DisplaySettings()
{
API.consoleOutput("~~~ BATTLE ROYALE SETTINGS ~~~");
API.consoleOutput("Players needed to start: " + Map.PlayersToStart);
API.consoleOutput("Waiting location: " + Map.WaitingPosition.ToString());
API.consoleOutput("Spawn Positions: ");
foreach (Vehicle p in Map.Vehicles)
API.consoleOutput(p.Hash + " at " + p.Position);
foreach (Structure.Object o in Map.Objects)
API.consoleOutput(o.Model + " at " + o.Position);
foreach (Weapon w in Map.Weapons)
API.consoleOutput(w.Hash + " at " + w.Position);
API.consoleOutput("Sphere spawn location: " + Map.SphereLocation.ToString());
API.consoleOutput("Sphere scale: " + Map.SphereScale);
API.consoleOutput("Countdown time: " + Map.CountdownTime);
API.consoleOutput("~~~ BATTLE ROYALE SETTINGS ~~~");
}
private void OnResourceStart()
{
API.consoleOutput("BattleRoyale has been started!");
LoadMap();
DisplaySettings();
//onCheckBattleRoyale();
}
public void CheckStartConditions()
{
if (API.getAllPlayers().Count == MainEntryPoint.Map.PlayersToStart)
{
if (BattleRoyale.currentlyRunning == false)
{
API.consoleOutput("Minimum player count has been reached");
API.sendChatMessageToAll("Starting new BattleRoyale round");
BattleRoyale = new BattleRoyale();
BattleRoyale.StartBattleRoyale();
}
}
}
private void LoadMap(string name = "default")
{
string rootPath = API.getResourceFolder() + "/" + name;
string mapJSON = File.ReadAllText(rootPath +"/map.json");
Map map = JsonConvert.DeserializeObject<Map>(mapJSON);
string vehiclesJSON = File.ReadAllText(rootPath + "/vehicles.json");
map.Vehicles = JsonConvert.DeserializeObject<List<Vehicle>>(vehiclesJSON);
string objectsJSON = File.ReadAllText(rootPath + "/objects.json");
map.Objects = JsonConvert.DeserializeObject<List<Structure.Object>>(objectsJSON);
string weaponsJSON = File.ReadAllText(rootPath + "/weapons.json");
map.Weapons = JsonConvert.DeserializeObject<List<Weapon>>(weaponsJSON);
string spawnsJSON = File.ReadAllText(rootPath + "/spawns.json");
map.Spawns = JsonConvert.DeserializeObject<List<Vector3>>(spawnsJSON);
MainEntryPoint.Map = map;
}
private void CheckBattleRoyaleWin()
{
int playersLeft = 0;
foreach (Player p in Players)
{
if (p.inBattleRoyale)
playersLeft++;
}
if (playersLeft <= 1)
{
API.sendChatMessageToAll("BattleRoyale has been won.");
MainEntryPoint.onCheckBattleRoyale();
}
}
}
}