This repository was archived by the owner on Feb 19, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathSubclass.cs
426 lines (378 loc) · 15.6 KB
/
Subclass.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
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
using Exiled.API.Enums;
using Exiled.API.Features;
using HarmonyLib;
using MEC;
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using Player = Exiled.Events.Handlers.Player;
using Server = Exiled.Events.Handlers.Server;
using Map = Exiled.Events.Handlers.Map;
using System.Reflection;
using CustomPlayerEffects;
using Exiled.Permissions.Commands.Permissions;
using Subclass.Managers;
using System.IO;
using Exiled.Loader;
namespace Subclass
{
public class Subclass : Plugin<Config>
{
public static Subclass Instance;
public override PluginPriority Priority { get; } = PluginPriority.Last;
public override string Name { get; } = "Subclass";
public override string Author { get; } = "Steven4547466";
public override Version Version { get; } = new Version(1, 4, 0);
public override Version RequiredExiledVersion { get; } = new Version(2, 1, 28);
public override string Prefix { get; } = "Subclass";
public Handlers.Player player { get; set; }
public Handlers.Server server { get; set; }
public Handlers.Map map { get; set; }
public Dictionary<string, SubClass> Classes { get; set; }
public Dictionary<RoleType, Dictionary<SubClass, float>> ClassesAdditive = null;
public Dictionary<RoleType, Dictionary<SubClass, float>> ClassesWeighted = null;
public bool Scp035Enabled = Loader.Plugins.Any(p => p.Name == "scp035" && p.Config.IsEnabled);
public bool CommonUtilsEnabled = Loader.Plugins.Any(p => p.Name == "Common Utilities" && p.Config.IsEnabled);
public bool RealisticSizesEnabled = Loader.Plugins.Any(p => p.Name == "RealisticSizes" && p.Config.IsEnabled);
public bool Scp008XEnabled = Loader.Plugins.Any(p => p.Name == "Scp008X" && p.Config.IsEnabled);
int harmonyPatches = 0;
private Harmony HarmonyInstance { get; set; }
public override void OnEnabled()
{
if (Config.IsEnabled == false)
{
Log.Info("Subclass was disabled, why did this run?");
return;
}
Instance = this;
base.OnEnabled();
Log.Info("Subclass enabled.");
RegisterEvents();
Classes = GetClasses();
HarmonyInstance = new Harmony($"steven4547466.subclass-{++harmonyPatches}");
HarmonyInstance.PatchAll();
}
public override void OnDisabled()
{
base.OnDisabled();
Log.Info("Subclass disabled.");
UnregisterEvents();
HarmonyInstance.UnpatchAll();
foreach (Exiled.API.Features.Player player in Exiled.API.Features.Player.List)
{
TrackingAndMethods.RemoveAndAddRoles(player, true);
}
Instance = null;
}
public override void OnReloaded()
{
base.OnReloaded();
//Log.Info("Subclass reloading.");
}
public void RegisterEvents()
{
player = new Handlers.Player();
Player.InteractingDoor += player.OnInteractingDoor;
Player.Died += player.OnDied;
Player.Dying += player.OnDying;
Player.Shooting += player.OnShooting;
Player.InteractingLocker += player.OnInteractingLocker;
Player.UnlockingGenerator += player.OnUnlockingGenerator;
Player.TriggeringTesla += player.OnTriggeringTesla;
Player.ChangingRole += player.OnChangingRole;
Player.Spawning += player.OnSpawning;
Player.Hurting += player.OnHurting;
Player.EnteringFemurBreaker += player.OnEnteringFemurBreaker;
Player.Escaping += player.OnEscaping;
Player.FailingEscapePocketDimension += player.OnFailingEscapePocketDimension;
Player.Interacted += player.OnInteracted;
Player.UsingMedicalItem += player.OnUsingMedicalItem;
Player.EnteringPocketDimension += player.OnEnteringPocketDimension;
Player.SpawningRagdoll += player.OnSpawningRagdoll;
server = new Handlers.Server();
Server.RoundStarted += server.OnRoundStarted;
Server.RoundEnded += server.OnRoundEnded;
Server.RespawningTeam += server.OnRespawningTeam;
map = new Handlers.Map();
Map.ExplodingGrenade += map.OnExplodingGrenade;
}
public void UnregisterEvents()
{
Log.Info("Events unregistered");
Player.InteractingDoor -= player.OnInteractingDoor;
Player.Died -= player.OnDied;
Player.Dying -= player.OnDying;
Player.Shooting -= player.OnShooting;
Player.InteractingLocker -= player.OnInteractingLocker;
Player.UnlockingGenerator -= player.OnUnlockingGenerator;
Player.TriggeringTesla -= player.OnTriggeringTesla;
Player.ChangingRole -= player.OnChangingRole;
Player.Spawning -= player.OnSpawning;
Player.Hurting -= player.OnHurting;
Player.EnteringFemurBreaker -= player.OnEnteringFemurBreaker;
Player.Escaping -= player.OnEscaping;
Player.FailingEscapePocketDimension -= player.OnFailingEscapePocketDimension;
Player.Interacted -= player.OnInteracted;
Player.UsingMedicalItem -= player.OnUsingMedicalItem;
Player.EnteringPocketDimension -= player.OnEnteringPocketDimension;
Player.SpawningRagdoll -= player.OnSpawningRagdoll;
player = null;
Server.RoundStarted -= server.OnRoundStarted;
Server.RoundEnded -= server.OnRoundEnded;
Server.RespawningTeam -= server.OnRespawningTeam;
server = null;
Map.ExplodingGrenade -= map.OnExplodingGrenade;
map = null;
}
public Dictionary<string, SubClass> GetClasses()
{
Dictionary<string, SubClass> classes = SubclassManager.LoadClasses();
Config config = Instance.Config;
if (config.AdditiveChance)
{
ClassesAdditive = new Dictionary<RoleType, Dictionary<SubClass, float>>();
foreach (var item in classes)
{
foreach (RoleType role in item.Value.AffectsRoles)
{
if (!ClassesAdditive.ContainsKey(role)) ClassesAdditive.Add(role, new Dictionary<SubClass, float>() { { item.Value, item.Value.FloatOptions["ChanceToGet"] } });
else ClassesAdditive[role].Add(item.Value, item.Value.FloatOptions["ChanceToGet"]);
}
}
//var additiveClasses = ClassesAdditive.ToList();
Dictionary<RoleType, Dictionary<SubClass, float>> classesAdditiveCopy = new Dictionary<RoleType, Dictionary<SubClass, float>>();
foreach (RoleType role in ClassesAdditive.Keys)
{
var additiveClasses = ClassesAdditive[role].ToList();
additiveClasses.Sort((x, y) => y.Value.CompareTo(x.Value));
if (!classesAdditiveCopy.ContainsKey(role)) classesAdditiveCopy.Add(role, new Dictionary<SubClass, float>());
classesAdditiveCopy[role] = additiveClasses.ToDictionary(x => x.Key, x => x.Value);
}
ClassesAdditive.Clear();
Dictionary<RoleType, float> sums = new Dictionary<RoleType, float>();
foreach (var roles in classesAdditiveCopy)
{
foreach (SubClass sclass in classesAdditiveCopy[roles.Key].Keys)
{
if (!sums.ContainsKey(roles.Key)) sums.Add(roles.Key, 0);
sums[roles.Key] += sclass.FloatOptions["ChanceToGet"];
if (!ClassesAdditive.ContainsKey(roles.Key)) ClassesAdditive.Add(roles.Key, new Dictionary<SubClass, float>() { { sclass, sclass.FloatOptions["ChanceToGet"] } });
else ClassesAdditive[roles.Key].Add(sclass, sums[roles.Key]);
}
}
}
else if (config.WeightedChance)
{
ClassesWeighted = new Dictionary<RoleType, Dictionary<SubClass, float>>();
foreach (var item in classes)
{
foreach (RoleType role in item.Value.AffectsRoles)
{
if (!ClassesWeighted.ContainsKey(role)) ClassesWeighted.Add(role, new Dictionary<SubClass, float> { { item.Value, item.Value.FloatOptions["ChanceToGet"] } });
else ClassesWeighted[role].Add(item.Value, item.Value.FloatOptions["ChanceToGet"]);
}
}
Dictionary<RoleType, Dictionary<SubClass, float>> classesWeightedCopy = new Dictionary<RoleType, Dictionary<SubClass, float>>();
foreach (RoleType role in ClassesWeighted.Keys)
{
var weightedClasses = ClassesWeighted[role].ToList();
weightedClasses.Sort((x, y) => y.Value.CompareTo(x.Value));
if (!classesWeightedCopy.ContainsKey(role)) classesWeightedCopy.Add(role, new Dictionary<SubClass, float>());
classesWeightedCopy[role] = weightedClasses.ToDictionary(x => x.Key, x => x.Value);
}
ClassesWeighted.Clear();
Dictionary<RoleType, float> totals = new Dictionary<RoleType, float>();
foreach (var weight in config.BaseWeights)
{
if (!totals.ContainsKey(weight.Key)) totals.Add(weight.Key, 0f);
totals[weight.Key] += weight.Value;
}
foreach (var item in classesWeightedCopy)
{
foreach (SubClass subClass in classesWeightedCopy[item.Key].Keys)
{
if (!totals.ContainsKey(item.Key)) totals.Add(item.Key, 0f);
totals[item.Key] += subClass.FloatOptions["ChanceToGet"];
}
}
Dictionary<RoleType, float> sums = new Dictionary<RoleType, float>();
foreach (var item in classesWeightedCopy)
{
foreach (SubClass sclass in classesWeightedCopy[item.Key].Keys)
{
if (!sums.ContainsKey(item.Key)) sums.Add(item.Key, 0f);
sums[item.Key] += sclass.FloatOptions["ChanceToGet"];
if (!ClassesWeighted.ContainsKey(item.Key))
{
ClassesWeighted.Add(item.Key, new Dictionary<SubClass, float>
{
{ sclass, 100 * (sclass.FloatOptions["ChanceToGet"] / totals[item.Key]) }
});
}
else
{
ClassesWeighted[item.Key].Add(sclass, 100 * (sums[item.Key] / totals[item.Key]));
}
}
}
}
else
{
ClassesAdditive = null;
ClassesWeighted = null;
}
return classes;
}
}
public class SubClass
{
public string Name = "";
public List<RoleType> AffectsRoles = new List<RoleType>() { RoleType.None };
public Dictionary<string, float> AffectsUsers = new Dictionary<string, float>();
public Dictionary<string, float> Permissions = new Dictionary<string, float>();
public Dictionary<string, int> SpawnParameters = new Dictionary<string, int>();
public Dictionary<string, string> StringOptions = new Dictionary<string, string>();
public Dictionary<string, bool> BoolOptions = new Dictionary<string, bool>();
public Dictionary<string, int> IntOptions = new Dictionary<string, int>();
public Dictionary<string, float> FloatOptions = new Dictionary<string, float>();
public List<string> SpawnLocations = new List<string>();
public Dictionary<int, Dictionary<string, float>> SpawnItems = new Dictionary<int, Dictionary<string, float>>();
public Dictionary<AmmoType, int> SpawnAmmo = new Dictionary<AmmoType, int>();
public List<AbilityType> Abilities = new List<AbilityType>();
public Dictionary<AbilityType, float> AbilityCooldowns = new Dictionary<AbilityType, float>();
public Dictionary<AbilityType, float> InitialAbilityCooldowns = new Dictionary<AbilityType, float>();
public List<string> AdvancedFFRules = new List<string>();
public List<string> OnHitEffects = new List<string>();
public List<string> OnSpawnEffects = new List<string>();
public Dictionary<string, List<string>> OnDamagedEffects = new Dictionary<string, List<string>>();
public List<RoleType> RolesThatCantDamage = new List<RoleType>();
public List<RoleType> CantDamageRoles = new List<RoleType>();
public List<Team> CantDamageTeams = new List<Team>();
public List<Team> TeamsThatCantDamage = new List<Team>();
public List<string> CantDamageSubclasses = new List<string>();
public List<string> SubclassesThatCantDamage = new List<string>();
public string EndsRoundWith = "RIP";
public RoleType SpawnsAs = RoleType.None;
public RoleType[] EscapesAs = { RoleType.None, RoleType.None };
public SubClass(string name, List<RoleType> roles, Dictionary<string, string> strings, Dictionary<string, bool> bools,
Dictionary<string, int> ints, Dictionary<string, float> floats, List<string> spawns, Dictionary<int, Dictionary<string, float>> items,
Dictionary<AmmoType, int> ammo, List<AbilityType> abilities, Dictionary<AbilityType, float> cooldowns,
List<string> ffRules = null, List<string> onHitEffects = null, List<string> spawnEffects = null, List<RoleType> cantDamage = null,
string endsRoundWith = "RIP", RoleType spawnsAs = RoleType.None, RoleType[] escapesAs = null, Dictionary<string, List<string>> onTakeDamage = null,
List<RoleType> cantDamageRoles = null, List<Team> cantDamageTeams = null, List<Team> teamsThatCantDamage = null, List<string> cantDamageSubclasses = null,
List<string> subclassesThatCantDamage = null,
Dictionary<string, float> affectsUsers = null, Dictionary<string, float> permissions = null, Dictionary<AbilityType, float> initialAbilityCooldowns = null,
Dictionary<string, int> spawnParameters = null)
{
Name = name;
AffectsRoles = roles;
StringOptions = strings;
BoolOptions = bools;
IntOptions = ints;
FloatOptions = floats;
SpawnLocations = spawns;
SpawnItems = items;
SpawnAmmo = ammo;
Abilities = abilities;
AbilityCooldowns = cooldowns;
if (ffRules != null) AdvancedFFRules = ffRules;
if (onHitEffects != null) OnHitEffects = onHitEffects;
if (spawnEffects != null) OnSpawnEffects = spawnEffects;
if (cantDamage != null) RolesThatCantDamage = cantDamage;
if (cantDamageTeams != null) CantDamageTeams = cantDamageTeams;
if (teamsThatCantDamage != null) TeamsThatCantDamage = teamsThatCantDamage;
if (cantDamageSubclasses != null) CantDamageSubclasses = cantDamageSubclasses;
if (subclassesThatCantDamage != null) SubclassesThatCantDamage = subclassesThatCantDamage;
if (endsRoundWith != "RIP") EndsRoundWith = endsRoundWith;
if (spawnsAs != RoleType.None) SpawnsAs = spawnsAs;
if (escapesAs != null) EscapesAs = escapesAs;
if (onTakeDamage != null) OnDamagedEffects = onTakeDamage;
if (cantDamageRoles != null) CantDamageRoles = cantDamageRoles;
if (affectsUsers != null) AffectsUsers = affectsUsers;
if (permissions != null) Permissions = permissions;
if (initialAbilityCooldowns != null) InitialAbilityCooldowns = initialAbilityCooldowns;
if (spawnParameters != null) SpawnParameters = spawnParameters;
}
public SubClass(SubClass subClass)
{
Name = subClass.Name;
AffectsRoles = new List<RoleType>(subClass.AffectsRoles);
StringOptions = new Dictionary<string, string>(subClass.StringOptions);
BoolOptions = new Dictionary<string, bool>(subClass.BoolOptions);
IntOptions = new Dictionary<string, int>(subClass.IntOptions);
FloatOptions = new Dictionary<string, float>(subClass.FloatOptions);
SpawnLocations = new List<string>(subClass.SpawnLocations);
SpawnItems = new Dictionary<int, Dictionary<string, float>>(subClass.SpawnItems);
SpawnAmmo = new Dictionary<AmmoType, int>(subClass.SpawnAmmo);
Abilities = new List<AbilityType>(subClass.Abilities);
AbilityCooldowns = new Dictionary<AbilityType, float>(subClass.AbilityCooldowns);
AdvancedFFRules = new List<string>(subClass.AdvancedFFRules);
OnHitEffects = new List<string>(subClass.OnHitEffects);
OnSpawnEffects = new List<string>(subClass.OnSpawnEffects);
RolesThatCantDamage = new List<RoleType>(subClass.RolesThatCantDamage);
EndsRoundWith = subClass.EndsRoundWith;
SpawnsAs = subClass.SpawnsAs;
EscapesAs = subClass.EscapesAs;
OnDamagedEffects = subClass.OnDamagedEffects;
CantDamageRoles = subClass.CantDamageRoles;
AffectsUsers = subClass.AffectsUsers;
InitialAbilityCooldowns = subClass.InitialAbilityCooldowns;
Permissions = subClass.Permissions;
SpawnParameters = subClass.SpawnParameters;
}
}
public enum AbilityType
{
PryGates,
GodMode,
InvisibleUntilInteract,
BypassKeycardReaders,
HealGrenadeFrag,
HealGrenadeFlash,
BypassTeslaGates,
InfiniteSprint,
Disable096Trigger,
Disable173Stop,
Revive,
Echolocate,
Scp939Vision,
NoArmorDecay,
NoClip,
NoSCP207Damage,
NoSCPDamage,
NoHumanDamage,
InfiniteAmmo,
Nimble,
Necromancy,
FlashImmune,
GrenadeImmune,
CantBeSacraficed,
CantActivateFemurBreaker,
LifeSteal,
Zombie106,
FlashOnCommand,
GrenadeOnCommand,
ExplodeOnDeath,
InvisibleOnCommand,
Disguise,
CantHeal,
HealAura,
DamageAura,
Regeneration,
Infect,
BackupCommand,
Vent,
PowerSurge,
Summon,
CantBeInfected,
Punch,
Stun,
Bloodlust,
Disarm,
Fake,
Corrupt,
Multiply,
CantEscape
}
}