forked from Draakoor/Scp650Plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEventHandler.cs
More file actions
95 lines (83 loc) · 3.12 KB
/
EventHandler.cs
File metadata and controls
95 lines (83 loc) · 3.12 KB
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
using System.Linq;
using FrikanUtils.ProjectMer;
using LabApi.Events.Arguments.PlayerEvents;
using LabApi.Events.Arguments.ServerEvents;
using LabApi.Events.Handlers;
using LabApi.Features.Wrappers;
using MEC;
using SCP_650.Debugging;
using UnityEngine;
using BreakableDoor = Interactables.Interobjects.BreakableDoor;
using Logger = LabApi.Features.Console.Logger;
namespace SCP_650
{
public static class EventHandler
{
private static Config Config => Scp650Plugin.Instance.Config;
private static CoroutineHandle _debugRoutine;
public static void RegisterEvents()
{
ServerEvents.RoundStarted += OnRoundStart;
ServerEvents.RoundEnded += OnRoundEnd;
PlayerEvents.Death += OnPlayerDead;
if (!Scp650Plugin.Instance.Config.FollowTargetToPocketDimension)
{
PlayerEvents.EnteredPocketDimension += OnPocketed;
}
}
public static void UnregisterEvents()
{
ServerEvents.RoundStarted -= OnRoundStart;
ServerEvents.RoundEnded -= OnRoundEnd;
PlayerEvents.Death -= OnPlayerDead;
PlayerEvents.EnteredPocketDimension -= OnPocketed;
}
private static void OnRoundStart()
{
if (!Loader.DataLoaded)
{
Logger.Warn($"Not loaded yet... | {Loader.Poses != null} | {Loader.Scp650Schematic != null}");
return;
}
for (var i = 0; i < Config.MaximumSpawnNumber; i++)
{
var possibleDoors = Door.List
.Where(x => Config.SpawnableZone.Contains(x.Zone) && x.Base is BreakableDoor).ToArray();
if (possibleDoors.Length == 0)
{
continue;
}
var door = possibleDoors.RandomItem();
var transform = door.Transform;
var pos = transform.position + 0.75f * (Random.Range(0, 1) * 2f - 1f) * transform.forward;
var rotation = Quaternion.Euler(new Vector3(0f, Random.Range(0f, 360f), 0f));
var spawned = Loader.Scp650Schematic.SpawnSchematic(pos, rotation);
var ai = spawned.gameObject.AddComponent<Scp650Ai>();
ai.ChildRegister(spawned);
}
if (_debugRoutine.IsValid)
{
Timing.KillCoroutines(_debugRoutine);
}
_debugRoutine = Timing.RunCoroutine(DebugMenu.DebugRoutine());
}
private static void OnRoundEnd(RoundEndedEventArgs ev)
{
Timing.KillCoroutines(_debugRoutine);
}
private static void OnPlayerDead(PlayerDeathEventArgs ev)
{
foreach (var ai in Scp650Ai.Instances.Where(ai => ai.Target == ev.Player))
{
ai.TargetKilled(ev.Attacker);
}
}
private static void OnPocketed(PlayerEnteredPocketDimensionEventArgs ev)
{
foreach (var ai in Scp650Ai.Instances.Where(ai => ai.Target == ev.Player))
{
ai.Target = null;
}
}
}
}