-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathDoorRandomizerComponent.cs
More file actions
81 lines (70 loc) · 2.62 KB
/
Copy pathDoorRandomizerComponent.cs
File metadata and controls
81 lines (70 loc) · 2.62 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
using BepInEx.Logging;
using Comfort.Common;
using EFT;
using EFT.Interactive;
using UnityEngine;
namespace DrakiaXYZ.DoorRandomizer
{
internal class DoorRandomizerComponent : MonoBehaviour
{
protected static ManualLogSource Logger { get; private set; }
private DoorRandomizerComponent()
{
if (Logger == null)
{
Logger = BepInEx.Logging.Logger.CreateLogSource(nameof(DoorRandomizerComponent));
}
}
public void Awake()
{
int doorCount = 0;
int changedCount = 0;
int invalidStateCount = 0;
int inoperableCount = 0;
int invalidLayerCount = 0;
FindObjectsOfType<Door>().ExecuteForEach(door =>
{
doorCount++;
// We don't support doors that don't start open/closed
if (door.DoorState != EDoorState.Open && door.DoorState != EDoorState.Shut)
{
invalidStateCount++;
return;
}
// We don't support non-operatable doors
if (!door.Operatable || !door.enabled)
{
inoperableCount++;
return;
}
// We don't support doors that aren't on the "Interactive" layer
if (door.gameObject.layer != LayersMaskController.InteractiveLayer)
{
invalidLayerCount++;
return;
}
// Have a 50% chance to change the initial state of the door
if (UnityEngine.Random.Range(0, 100) < 50)
{
changedCount++;
door.DoorState = (door.InitialDoorState == EDoorState.Open ? EDoorState.Shut : EDoorState.Open);
// Trigger "OnEnable" to make sure the properties are set correctly for interaction
door.OnEnable();
}
});
Logger.LogDebug($"Total Doors: {doorCount}");
Logger.LogDebug($"Changed Doors: {changedCount}");
Logger.LogDebug($"Invalid State Doors: {invalidStateCount}");
Logger.LogDebug($"Inoperable Doors: {inoperableCount}");
Logger.LogDebug($"Invalid Layer Doors: {invalidLayerCount}");
}
public static void Enable()
{
if (Singleton<IBotGame>.Instantiated)
{
var gameWorld = Singleton<GameWorld>.Instance;
gameWorld.GetOrAddComponent<DoorRandomizerComponent>();
}
}
}
}