-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMethods.cs
More file actions
159 lines (118 loc) · 4.77 KB
/
Methods.cs
File metadata and controls
159 lines (118 loc) · 4.77 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
using System.Collections.Generic;
using AdminToys;
using Exiled.API.Features;
using Exiled.API.Features.Roles;
using Exiled.API.Features.Toys;
using MEC;
using Mirror;
using PlayerRoles;
#if PMER
using ProjectMER.Features;
using ProjectMER.Features.Extensions;
using ProjectMER.Features.Objects;
#endif
using ProjectSCRAMBLE.Configs;
using ProjectSCRAMBLE.Extensions;
using UnityEngine;
namespace ProjectSCRAMBLE
{
public class Methods
{
internal static Dictionary<Player, GameObject> Scp96Censors { get; private set; } = [];
internal static Dictionary<Player, HashSet<CoroutineHandle>> Coroutines { get; private set; } = [];
internal static void AddCensor(Player player)
{
if (player.Role.Type != RoleTypeId.Scp096)
return;
if (!player.TryGetScp96Head(out Transform head))
{
Log.Error("Scp096 head not found.");
return;
}
if (Scp96Censors.ContainsKey(player))
RemoveCensor(player);
Config config = Plugin.Instance.Config;
#if PMER
if (!ObjectSpawner.TrySpawnSchematic(config.CensorSchematic, head.position, head.rotation,
config.CensorScale , out SchematicObject Censor))
{
Log.Error("Censor Schematic failed to spawn");
return;
}
Censor.transform.SetParent(player.Transform, true);
if (config.AttachCensorToHead && !Coroutines.ContainsKey(player))
Coroutines[player] = [];
if (config.AttachCensorToHead)
Coroutines[player].Add(Timing.RunCoroutine(TrackHead(Censor.transform, head, config.AttachToHeadsyncInterval)));
Scp96Censors.Add(player, Censor.gameObject);
HideForUnGlassesPlayer(Censor.gameObject);
#else
Primitive Censor = Primitive.Create(primitiveType: config.CensorType, flags: PrimitiveFlags.Visible, position: head.position,
rotation: head.rotation.eulerAngles, scale: config.CensorScale, spawn: true, color: config.CensorColor);
Censor.MovementSmoothing = 0;
Censor.Transform.SetParent(player.Transform, true);
if ((config.AttachCensorToHead || config.CensorRotate) && !Coroutines.ContainsKey(player))
Coroutines[player] = [];
if (config.AttachCensorToHead)
Coroutines[player].Add(Timing.RunCoroutine(TrackHead(Censor.Transform, head, config.AttachToHeadsyncInterval)));
if (config.CensorRotate)
Coroutines[player].Add(Timing.RunCoroutine(RotateRandom(Censor.Transform)));
Scp96Censors.Add(player, Censor.GameObject);
HideForUnGlassesPlayer(Censor.GameObject);
#endif
}
internal static void RemoveCensor(Player player)
{
if (!Scp96Censors.ContainsKey(player))
return;
GameObject Censor = Scp96Censors[player];
Scp96Censors.Remove(player);
NetworkServer.Destroy(Censor);
foreach (CoroutineHandle handle in Coroutines[player])
{
Timing.KillCoroutines(handle);
}
}
private static void HideForUnGlassesPlayer(GameObject gameObject)
{
HashSet<Player> activeScramblePlayers = ProjectSCRAMBLE.SCRAMBLE.ActiveScramblePlayers;
foreach (Player ply in Player.List)
{
if (activeScramblePlayers.Contains(ply))
continue;
if (ply.Role is SpectatorRole spcRole && activeScramblePlayers.Contains(spcRole.SpectatedPlayer))
{
Plugin.Instance.EventHandlers.DirtyPlayers.Add(spcRole.SpectatedPlayer);
continue;
}
ply.HideNetworkObject(gameObject);
}
}
private static IEnumerator<float> TrackHead(Transform censor, Transform head, float syncinterval)
{
while (censor != null && head != null)
{
censor.position = head.position;
yield return syncinterval;
}
}
private static IEnumerator<float> RotateRandom(Transform tr)
{
float t = 0f;
while (tr != null)
{
t += 0.1f;
float t1 = t * 1.1f;
float t2 = t * 1.7f;
float t3 = t * 2.3f;
float x = Mathf.Sin(t1) * 180f;
float y = Mathf.Cos(t2) * 180f;
float z = Mathf.Sin(t3) * 180f;
tr.localRotation = Quaternion.Euler(x, y, z);
if (t >= 1000f)
t = 0f;
yield return 0.1f;
}
}
}
}