-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLCPeeper.cs
1681 lines (1408 loc) · 54.1 KB
/
LCPeeper.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
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using BepInEx;
using GameNetcodeStuff;
using HarmonyLib;
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.Animations;
using UnityEngine.Events;
using UnityEngine.Audio;
using BepInEx.Configuration;
using System.Linq;
using Unity.Netcode.Components;
using Unity.Netcode.Samples;
using UnityEngine.AI;
using System.Reflection.Emit;
namespace LCPeeper
{
[BepInPlugin(modGUID, modName, modVersion)]
public class Peeper : BaseUnityPlugin
{
private const string modGUID = "x753.Peepers";
private const string modName = "Peepers";
private const string modVersion = "0.9.6";
private readonly Harmony harmony = new Harmony(modGUID);
private static Peeper Instance;
public static GameObject PeeperPrefab;
public static EnemyType PeeperType;
public static TerminalNode PeeperFile;
public static int PeeperCreatureID = 0;
public static List<PeeperAI> PeeperList = new List<PeeperAI>();
public static List<string> ignoreEnemies = new List<string> { "Peeper", "Manticoil", "Docile Locust Bees", "Girl" };
public static float PeeperSpawnChance;
public static int PeeperMinGroupSize;
public static int PeeperMaxGroupSize;
public static float PeeperWeight;
private void Awake()
{
AssetBundle peeperAssetBundle = AssetBundle.LoadFromMemory(LCPeeper.Properties.Resources.peeper);
PeeperPrefab = peeperAssetBundle.LoadAsset<GameObject>("Assets/PeeperPrefab.prefab");
PeeperType = peeperAssetBundle.LoadAsset<EnemyType>("Assets/PeeperType.asset");
PeeperFile = peeperAssetBundle.LoadAsset<TerminalNode>("Assets/PeeperFile.asset");
if (Instance == null)
{
Instance = this;
}
harmony.PatchAll();
Logger.LogInfo($"Plugin {modName} is loaded!");
// Handle configs
{
PeeperSpawnChance = Config.Bind("Spawn Rate", "Hourly Spawn Chance (%)", 10f, "Chance of a group of peepers spawning each hour").Value;
PeeperMinGroupSize = Config.Bind("Spawn Rate", "Minimum Peeper Group Size", 2, "The minimum number of peepers in a single group").Value;
PeeperMaxGroupSize = Config.Bind("Spawn Rate", "Maximum Peeper Group Size", 4, "The maximum number of peepers in a single group").Value;
PeeperWeight = Config.Bind("Peeper Settings", "Peeper Weight (lb)", 10f, "The weight of a single peeper in pounds.").Value / 105f;
}
// UnityNetcodeWeaver patch requires this
var types = Assembly.GetExecutingAssembly().GetTypes();
foreach (var type in types)
{
var methods = type.GetMethods(BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static);
foreach (var method in methods)
{
var attributes = method.GetCustomAttributes(typeof(RuntimeInitializeOnLoadMethodAttribute), false);
if (attributes.Length > 0)
{
method.Invoke(null, null);
}
}
}
}
[HarmonyPatch(typeof(GameNetworkManager))]
internal class GameNetworkManagerPatch
{
[HarmonyPatch("Start")]
[HarmonyPostfix]
static void StartPatch()
{
GameNetworkManager.Instance.GetComponent<NetworkManager>().AddNetworkPrefab(PeeperPrefab); // Register the network prefab
}
}
}
[HarmonyPatch(typeof(Terminal))]
internal class TerminalPatch
{
[HarmonyPatch("Start")]
[HarmonyPostfix]
static void StartPatch(Terminal __instance)
{
Terminal terminal = UnityEngine.Object.FindObjectOfType<Terminal>();
if (!terminal.enemyFiles.Find(node => node.creatureName == "Peepers"))
{
// Add peepers to the bestiary
Peeper.PeeperCreatureID = terminal.enemyFiles.Count;
Peeper.PeeperFile.creatureFileID = Peeper.PeeperCreatureID;
terminal.enemyFiles.Add(Peeper.PeeperFile);
TerminalKeyword infoKeyword = terminal.terminalNodes.allKeywords.First(keyword => keyword.word == "info");
TerminalKeyword peeperKeyword = ScriptableObject.CreateInstance<TerminalKeyword>();
peeperKeyword.word = "peepers";
peeperKeyword.isVerb = false;
peeperKeyword.defaultVerb = infoKeyword;
List<CompatibleNoun> itemInfoNouns = infoKeyword.compatibleNouns.ToList();
itemInfoNouns.Add(new CompatibleNoun()
{
noun = peeperKeyword,
result = Peeper.PeeperFile
});
infoKeyword.compatibleNouns = itemInfoNouns.ToArray();
List<TerminalKeyword> allKeywords = terminal.terminalNodes.allKeywords.ToList();
allKeywords.Add(peeperKeyword);
terminal.terminalNodes.allKeywords = allKeywords.ToArray();
}
}
}
[HarmonyPatch(typeof(RoundManager))]
internal class RoundManagerPatch
{
// The base game's spawning system doesn't really work well for something like this, so we'll do it our own way
[HarmonyPatch("AdvanceHourAndSpawnNewBatchOfEnemies")]
[HarmonyPrefix]
static void AdvanceHourAndSpawnNewBatchOfEnemiesPatch(RoundManager __instance)
{
float spawnRoll = UnityEngine.Random.Range(0f, 100f);
if (spawnRoll > Peeper.PeeperSpawnChance) { return; }
GameObject[] spawnPoints = GameObject.FindGameObjectsWithTag("OutsideAINode");
Vector3 spawnPoint = spawnPoints[__instance.AnomalyRandom.Next(0, spawnPoints.Length)].transform.position;
spawnPoint = __instance.GetRandomNavMeshPositionInRadius(spawnPoint, 4f, default(NavMeshHit));
int spawnIndex = 0;
bool flag = false;
for (int j = 0; j < spawnPoints.Length - 1; j++)
{
for (int k = 0; k < __instance.spawnDenialPoints.Length; k++)
{
flag = true;
if (Vector3.Distance(spawnPoint, __instance.spawnDenialPoints[k].transform.position) < 8f)
{
spawnIndex = (spawnIndex + 1) % spawnPoints.Length;
spawnPoint = spawnPoints[spawnIndex].transform.position;
spawnPoint = __instance.GetRandomNavMeshPositionInRadius(spawnPoint, 4f, default(NavMeshHit));
flag = false;
break;
}
}
if (flag)
{
break;
}
}
int peeperGroupSize = UnityEngine.Random.Range(Peeper.PeeperMinGroupSize, Peeper.PeeperMaxGroupSize);
for (int i = 0; i <= peeperGroupSize; i++)
{
RoundManager.Instance.SpawnEnemyGameObject(spawnPoint, 0f, -1, Peeper.PeeperType);
Peeper.PeeperType.numberSpawned++;
RoundManager.Instance.currentDaytimeEnemyPower += 1;
}
}
}
[HarmonyPatch(typeof(StartOfRound))]
internal class StartOfRoundPatch
{
[HarmonyPatch("Awake")]
[HarmonyPostfix]
static void AwakePatch(ref StartOfRound __instance)
{
foreach (SelectableLevel level in __instance.levels)
{
if (!level.DaytimeEnemies.Any(e => e.enemyType == Peeper.PeeperType))
{
int rarity = 0;
level.DaytimeEnemies.Add(new SpawnableEnemyWithRarity()
{
enemyType = Peeper.PeeperType,
rarity = rarity,
});
return; // We're only adding peepers to this list for other mods that use this list
}
}
}
[HarmonyPatch("EndOfGame")]
[HarmonyPrefix]
static void EndOfGamePatch(StartOfRound __instance, int bodiesInsured = 0, int connectedPlayersOnServer = 0, int scrapCollected = 0)
{
foreach (PeeperAI peeper in Peeper.PeeperList)
{
if (peeper.isAttached && peeper.attachedPlayer != null)
{
if (!peeper.attachedPlayer.isPlayerDead)
{
peeper.IsWeighted = false;
}
}
}
Peeper.PeeperList = new List<PeeperAI>();
PeeperAI.UsedAttachTargets = new List<Transform>();
}
}
[HarmonyPatch(typeof(StunGrenadeItem))]
internal class StunGrenadeItemPatch
{
[HarmonyPatch("StunExplosion")]
[HarmonyPostfix]
static void StunExplosion(StunGrenadeItem __instance, Vector3 explosionPosition, bool affectAudio, float flashSeverityMultiplier, float enemyStunTime, float flashSeverityDistanceRolloff = 1f, bool isHeldItem = false, PlayerControllerB playerHeldBy = null, PlayerControllerB playerThrownBy = null, float addToFlashSeverity = 0f)
{
PlayerControllerB playerControllerB = GameNetworkManager.Instance.localPlayerController;
if (Vector3.Distance(playerControllerB.transform.position, explosionPosition) < 16f)
{
if (Vector3.Distance(playerControllerB.transform.position, explosionPosition) > 5f)
{
if (!(isHeldItem && playerHeldBy == GameNetworkManager.Instance.localPlayerController))
{
if (Physics.Linecast(explosionPosition + Vector3.up * 0.5f, playerControllerB.gameplayCamera.transform.position, StartOfRound.Instance.collidersAndRoomMaskAndDefault, QueryTriggerInteraction.Ignore))
{
return;
}
}
}
// Make every peeper die if the player gets flashed
List<PeeperAI> allPeepers = new List<PeeperAI>(Peeper.PeeperList);
foreach (PeeperAI peeper in allPeepers)
{
if (peeper.attachedPlayer == playerControllerB)
{
if (peeper.IsOwner)
{
peeper.KillEnemyOnOwnerClient();
}
}
}
}
}
}
// https://github.com/Malcolm-Q/LC-LateGameUpgrades/blob/d1c0c42c8e35294626466aa11773a877bcaa7ea6/MoreShipUpgrades/Patches/Enemies/SpringManAIPatcher.cs
[HarmonyPatch(typeof(SpringManAI))]
internal class SpringManAIPatcher
{
[HarmonyPrefix]
[HarmonyPatch(nameof(SpringManAI.DoAIInterval))]
private static void DoAllIntervalPrefix(ref SpringManAI __instance)
{
if (PeeperAI.HasLineOfSightToPeeper(__instance.transform.position))
{
__instance.currentBehaviourStateIndex = 1;
}
}
[HarmonyTranspiler]
[HarmonyPatch(nameof(SpringManAI.Update))]
private static IEnumerable<CodeInstruction> Update_Transpiler(IEnumerable<CodeInstruction> instructions)
{
MethodInfo peeperMethod = typeof(PeeperAI).GetMethod("HasLineOfSightToPeeper", BindingFlags.Public | BindingFlags.Static);
MethodInfo transformMethod = typeof(SpringManAI).GetMethod("get_transform");
MethodInfo positionMethod = typeof(UnityEngine.Transform).GetMethod("get_position");
List<CodeInstruction> codes = new List<CodeInstruction>(instructions);
for (int i = 1; i < codes.Count; i++)
{
if (codes[i - 1].opcode != OpCodes.Ldc_I4_0) continue;
if (codes[i].opcode != OpCodes.Stloc_1) continue;
codes.Insert(i, new CodeInstruction(OpCodes.Or));
codes.Insert(i, new CodeInstruction(OpCodes.Call, peeperMethod));
codes.Insert(i, new CodeInstruction(OpCodes.Callvirt, positionMethod));
codes.Insert(i, new CodeInstruction(OpCodes.Call, transformMethod));
codes.Insert(i, new CodeInstruction(OpCodes.Ldarg_0));
break;
}
return codes;
}
}
[HarmonyPatch(typeof(SprayPaintItem))]
internal class SprayPaintItemPatch
{
static FieldInfo SprayMatIndex = typeof(SprayPaintItem).GetField("sprayCanMatsIndex", BindingFlags.NonPublic | BindingFlags.Instance);
[HarmonyPatch("SprayPaintClientRpc")]
[HarmonyPrefix]
static void SprayPaintClientRpcPatch(SprayPaintItem __instance, Vector3 sprayPos, Vector3 sprayRot)
{
try
{
RaycastHit raycastHit;
Ray ray = new Ray(sprayPos, sprayRot);
if (Physics.Raycast(ray, out raycastHit, 4f, (1 << 19), QueryTriggerInteraction.Collide))
{
if (raycastHit.collider != null && raycastHit.collider.name == "PeeperSprayCollider")
{
PeeperAI peeper = raycastHit.collider.transform.parent.parent.parent.parent.parent.parent.parent.GetComponent<PeeperAI>();
if (__instance.playerHeldBy == peeper.attachedPlayer) { return; }
//if (peeper.peeperMesh.materials.Length < 2)
//{
// if (peeper.isEnemyDead)
// {
// peeper.peeperMesh.materials = new Material[] { peeper.paintedMat, peeper.deadMat };
// }
// else
// {
// peeper.peeperMesh.materials = new Material[] { peeper.paintedMat, peeper.baseMat };
// }
//}
peeper.peeperMesh.materials[0].color = __instance.sprayCanMats[(int)SprayMatIndex.GetValue(__instance)].color;
if (peeper.isAttached)
{
peeper.EjectFromPlayerServerRpc(peeper.attachedPlayer.actualClientId);
}
}
}
}
catch (Exception e)
{
}
}
}
// Make the laser pointer kill a peeper when you shine it in its eye
[HarmonyPatch(typeof(FlashlightItem))]
internal class FlashlightItemPatch
{
[HarmonyPatch("Update")]
[HarmonyPostfix]
static void UpdatePatch(FlashlightItem __instance)
{
if (__instance.IsOwner && __instance.flashlightTypeID == 2 && __instance.isBeingUsed)
{
Transform laser = __instance.flashlightBulb.transform;
Ray ray = new Ray(laser.position, laser.forward);
RaycastHit[] hits = Physics.RaycastAll(ray, 32f, 1 << LayerMask.NameToLayer("ScanNode"));
foreach (RaycastHit hit in hits)
{
if (hit.collider.name == "PeeperScanNode")
{
float angle = Vector3.Angle(-ray.direction, hit.transform.forward);
if (angle < 55f)
{
PeeperAI peeper = hit.transform.parent.parent.parent.parent.parent.parent.parent.GetComponent<PeeperAI>();
if (peeper.attachedPlayer == GameNetworkManager.Instance.localPlayerController)
{
return;
}
if (peeper.IsOwner)
{
peeper.KillEnemyOnOwnerClient();
}
else
{
peeper.KillEnemyNetworked();
}
}
}
}
}
}
}
[HarmonyPatch(typeof(PlayerControllerB))]
internal class PlayerControllerBPatch
{
[HarmonyPatch("KillPlayer")]
[HarmonyPrefix]
static void KillPlayerPatch(PlayerControllerB __instance, Vector3 bodyVelocity, bool spawnBody = true, CauseOfDeath causeOfDeath = CauseOfDeath.Unknown, int deathAnimation = 0)
{
// Make every peeper fly off the player if the player dies
List<PeeperAI> allPeepers = new List<PeeperAI>(Peeper.PeeperList);
foreach (PeeperAI peeper in allPeepers)
{
if (peeper.attachedPlayer == __instance)
{
if (peeper.IsOwner)
{
if (causeOfDeath == CauseOfDeath.Electrocution || causeOfDeath == CauseOfDeath.Blast)
{
peeper.KillEnemyOnOwnerClient();
}
else
{
peeper.EjectFromPlayerServerRpc(__instance.playerClientId);
}
}
}
}
}
[HarmonyPatch("DamagePlayer")]
[HarmonyPrefix]
static void DamagePlayerPatch(PlayerControllerB __instance, int damageNumber, bool hasDamageSFX = true, bool callRPC = true, CauseOfDeath causeOfDeath = CauseOfDeath.Unknown, int deathAnimation = 0, bool fallDamage = false, Vector3 force = default(Vector3))
{
// Make every peeper fly off the player if the player gets injured
List<PeeperAI> allPeepers = new List<PeeperAI>(Peeper.PeeperList);
foreach (PeeperAI peeper in allPeepers)
{
if (peeper.attachedPlayer == __instance)
{
peeper.EjectFromPlayerServerRpc(__instance.playerClientId);
}
}
}
[HarmonyPatch("IShockableWithGun.ShockWithGun")]
[HarmonyPrefix]
static void DamagePlayerPatch(PlayerControllerB __instance, PlayerControllerB shockedByPlayer)
{
// Make every peeper die if the player gets shocked
List<PeeperAI> allPeepers = new List<PeeperAI>(Peeper.PeeperList);
foreach (PeeperAI peeper in allPeepers)
{
if (peeper.attachedPlayer == __instance)
{
if (peeper.IsOwner)
{
peeper.KillEnemyOnOwnerClient();
}
}
}
}
[HarmonyPatch("DropAllHeldItems")]
[HarmonyPostfix]
static void DamagePlayeDropAllHeldItemsPatch(PlayerControllerB __instance, bool itemsFall = true, bool disconnecting = false)
{
// Weight is set to 1f by the teleporter, add the Peeper weights back on!
if (__instance.carryWeight == 1f)
{
List<PeeperAI> allPeepers = new List<PeeperAI>(Peeper.PeeperList);
foreach (PeeperAI peeper in allPeepers)
{
if (peeper.attachedPlayer == __instance && peeper.isAttached && !peeper.isEnemyDead)
{
__instance.carryWeight += Peeper.PeeperWeight;
}
}
}
}
}
public class PeeperAI : EnemyAI
{
[Header("General")]
public GameObject creatureModel; // The root of the creature model
public SkinnedMeshRenderer peeperMesh;
public ScanNodeProperties scanNode;
[Header("AI and Pathfinding")]
public AISearchRoutine searchForPlayers;
public float maxSearchAndRoamRadius = 100f;
public float searchPrecisionValue = 5f;
private int sightRange = 30;
[Header("Constraints and Transforms")]
public Transform attachTargetTransform; // Current target transform for the attachConstraint
public static List<Transform> UsedAttachTargets = new List<Transform>();
public Vector3 attachTargetTranslationOffset;
public Vector3 attachTargetRotationOffset;
public Transform eyeTransform;
public Transform eyeOriginalTransform;
public bool isAttached;
public PlayerControllerB attachedPlayer;
[Header("Colliders and Physics")]
public SphereCollider attachCollider; // Collider with a PeeperAttachHitbox script
public SphereCollider physicsCollider; // Collider when the peeper turns into a ball and obeys the laws of physics
public SphereCollider hitboxCollider; // Collider that is used for damaging / shocking / killing the peeper
public Rigidbody physicsRigidbody; // Rigidbody that obeys the laws of physics
[Header("State Handling and Sync")]
public float stateTimer = 0f;
public float stateTimer2 = 0f;
public int stateCounter = 0;
[Header("Audio")]
public AudioSource AttachSFXSource;
public AudioClip walkSFX;
public AudioClip runSFX;
public AudioClip[] spotSFX;
public AudioClip[] jumpSFX;
public AudioClip[] attachSFX;
public AudioClip[] deathSFX;
public AudioClip[] ejectSFX;
public AudioClip[] zapSFX;
public AudioClip[] whisperSFX;
public static float NextWhisperTime;
[Header("Materials")]
public Material baseMat;
public Material paintedMat;
public Material deadMat;
public ParticleSystem deathParticles;
[Header("Ragdoll")]
private bool ragdollFrozen = false;
public Rigidbody[] ragdollRigidbodies;
public Collider[] ragdollColliders;
public override void Start()
{
base.Start();
this.searchForPlayers.searchWidth = this.maxSearchAndRoamRadius;
this.searchForPlayers.searchPrecision = this.searchPrecisionValue;
Peeper.PeeperList.Add(this);
AudioMixer audioMixer = SoundManager.Instance.diageticMixer;
base.creatureVoice.outputAudioMixerGroup = audioMixer.FindMatchingGroups("SFX")[0];
base.creatureSFX.outputAudioMixerGroup = audioMixer.FindMatchingGroups("SFX")[0];
this.AttachSFXSource.outputAudioMixerGroup = audioMixer.FindMatchingGroups("SFX")[0];
this.scanNode.creatureScanID = Peeper.PeeperCreatureID;
SwitchBehaviourState(2); // spawn state
}
public override void DoAIInterval()
{
if (base.inSpecialAnimation) { return; }
base.DoAIInterval();
if (StartOfRound.Instance.livingPlayers == 0 || this.isEnemyDead)
{
return;
}
int currentBehaviourStateIndex = this.currentBehaviourStateIndex;
if (currentBehaviourStateIndex != 0)
{
if (this.searchForPlayers.inProgress)
{
base.StopSearch(this.searchForPlayers, true);
this.movingTowardsTargetPlayer = true;
}
}
else if (!this.searchForPlayers.inProgress)
{
base.StartSearch(base.transform.position, this.searchForPlayers);
return;
}
}
public override void FinishedCurrentSearchRoutine()
{
base.FinishedCurrentSearchRoutine();
this.searchForPlayers.searchWidth = Mathf.Clamp(this.searchForPlayers.searchWidth + 20f, 1f, this.maxSearchAndRoamRadius);
}
private Vector3 agentLocalVelocity;
private Vector3 previousPosition;
private float velX;
private float velZ;
private float velXZ;
private float footstepTimer = 0f;
private void CalculateAnimationDirection()
{
this.agentLocalVelocity = this.transform.InverseTransformDirection(Vector3.ClampMagnitude(base.transform.position - this.previousPosition, 1f) / (Time.deltaTime * 2f));
this.velX = Mathf.Lerp(this.velX, this.agentLocalVelocity.x, 5f * Time.deltaTime);
this.velZ = Mathf.Lerp(this.velZ, -this.agentLocalVelocity.z, 5f * Time.deltaTime);
this.previousPosition = base.transform.position;
this.velXZ = Mathf.Sqrt(this.velX * this.velX + this.velZ * this.velZ);
creatureAnimator.SetFloat("Speed", this.velXZ);
float footstepInterval;
if (base.currentBehaviourStateIndex == 1 || base.currentBehaviourStateIndex == 5)
{
footstepInterval = 0.3f;
}
else
{
footstepInterval = 0.3335f;
}
this.footstepTimer += Time.deltaTime;
if (this.footstepTimer < footstepInterval) { return; }
this.footstepTimer = 0f;
if (this.velXZ > 0.15)
{
if (base.currentBehaviourStateIndex == 1)
{
PlayCreatureSFX(2);
}
else
{
PlayCreatureSFX(1);
}
}
}
private void PutCreatureOnGround()
{
if (base.agent.velocity.y > 5f) { return; }
creatureAnimator.SetBool("Grounded", true);
creatureAnimator.SetBool("Jump", false);
Ray ray = new Ray(this.transform.position + Vector3.up, Vector3.down);
RaycastHit hit;
if (Physics.Raycast(ray, out hit, 2f, LayerMask.GetMask("Room", "Colliders"), QueryTriggerInteraction.Ignore))
{
this.creatureModel.transform.localPosition = new Vector3(0f, -hit.distance + 1f, 0f);
}
}
private Vector3 deathDirection = Vector3.zero;
public override void HitEnemy(int force = 1, PlayerControllerB playerWhoHit = null, bool playHitSFX = false)
{
base.HitEnemy(force, playerWhoHit, false);
this.enemyHP -= force;
if (playerWhoHit != null)
{
deathDirection = (this.transform.position - playerWhoHit.transform.position).normalized;
}
if (this.enemyHP <= 0 && base.IsOwner)
{
base.KillEnemyOnOwnerClient(false);
}
}
public override void SetEnemyStunned(bool setToStunned, float setToStunTime = 1, PlayerControllerB setStunnedByPlayer = null)
{
this.enemyHP -= 1;
if (this.enemyHP <= 0 && base.IsOwner)
{
base.KillEnemyOnOwnerClient(false);
}
}
public void KillEnemyNetworked()
{
if (this.IsServer)
{
KillEnemyClientRpc();
}
else
{
KillEnemyServerRpc();
}
}
[ServerRpc(RequireOwnership = false)]
public void KillEnemyServerRpc()
{
KillEnemyClientRpc();
}
[ClientRpc]
public void KillEnemyClientRpc()
{
KillEnemy();
}
public override void KillEnemy(bool destroy = false)
{
base.KillEnemy(false);
base.creatureVoice.Stop();
base.creatureSFX.Stop();
PlayCreatureSFX(5);
SwitchBehaviourState(7);
base.isEnemyDead = true;
Peeper.PeeperList.Remove(this);
// Remove offset so the corpse doesn't fall through the floor
this.creatureModel.transform.localPosition = Vector3.zero;
if (this.isAttached && this.attachedPlayer != null)
{
EjectFromPlayer(this.attachedPlayer);
}
Color paintedColor = this.peeperMesh.material.color;
this.peeperMesh.materials = new Material[] { this.deadMat };
this.peeperMesh.materials[0].color = paintedColor;
deathParticles.Play();
base.creatureAnimator.enabled = false;
this.physicsRigidbody.isKinematic = true;
foreach (Rigidbody rb in this.ragdollRigidbodies)
{
rb.isKinematic = false;
if (deathDirection != Vector3.zero)
{
rb.AddForce(15f * deathDirection, ForceMode.Impulse);
}
}
foreach (Collider c in this.ragdollColliders)
{
c.enabled = true;
}
this.peeperMesh.SetBlendShapeWeight(0, 0);
this.peeperMesh.SetBlendShapeWeight(1, 350);
}
public void SwitchBehaviourState(int state)
{
SwitchBehaviourStateLocally(state);
SwitchBehaviourStateServerRpc(state);
}
[ServerRpc(RequireOwnership = false)]
public void SwitchBehaviourStateServerRpc(int state)
{
SwitchBehaviourStateClientRpc(state);
}
[ClientRpc]
public void SwitchBehaviourStateClientRpc(int state)
{
SwitchBehaviourStateLocally(state);
}
public void SwitchBehaviourStateLocally(int state)
{
this.stateTimer = 0f;
this.stateTimer2 = 0f;
this.stateCounter = 0;
switch (state)
{
case 0: // Neutral State
base.targetPlayer = null;
base.movingTowardsTargetPlayer = false;
base.agent.speed = 2f;
base.creatureAnimator.SetBool("Jump", false);
base.creatureAnimator.SetBool("Attached", false);
base.creatureAnimator.SetBool("Dead", false);
this.inSpecialAnimation = false;
this.agent.enabled = true;
this.enemyType.canBeStunned = true;
this.attachCollider.enabled = true;
this.physicsCollider.enabled = false;
this.physicsRigidbody.isKinematic = true;
this.hitboxCollider.enabled = true;
this.hitboxCollider.radius = 0.5f;
this.hitboxCollider.center = new Vector3(0f, 0.5f, 0f);
break;
case 1: // Chasing State
base.agent.speed = 6f;
base.creatureAnimator.SetBool("Jump", false);
base.creatureAnimator.SetBool("Attached", false);
base.creatureAnimator.SetBool("Dead", false);
this.inSpecialAnimation = false;
this.agent.enabled = true;
this.enemyType.canBeStunned = true;
this.attachCollider.enabled = true;
this.physicsCollider.enabled = false;
this.physicsRigidbody.isKinematic = true;
this.hitboxCollider.enabled = true;
this.hitboxCollider.radius = 0.5f;
this.hitboxCollider.center = new Vector3(0f, 0.5f, 0f);
break;
case 2: // Spawning State
base.targetPlayer = null;
base.movingTowardsTargetPlayer = false;
base.agent.speed = 0f;
base.creatureAnimator.SetBool("Jump", false);
base.creatureAnimator.SetBool("Attached", false);
base.creatureAnimator.SetBool("Dead", false);
base.creatureAnimator.SetBool("Grounded", true);
this.inSpecialAnimation = false;
this.agent.enabled = true;
this.enemyType.canBeStunned = true;
this.attachCollider.enabled = true;
this.physicsCollider.enabled = false;
this.physicsRigidbody.isKinematic = true;
this.hitboxCollider.enabled = true;
this.hitboxCollider.radius = 0.5f;
this.hitboxCollider.center = new Vector3(0f, 0.5f, 0f);
break;
case 3: // Jumping State
base.agent.speed = 0f;
this.creatureModel.transform.localPosition = Vector3.zero;
base.creatureAnimator.SetBool("Jump", true);
base.creatureAnimator.SetBool("Attached", false);
base.creatureAnimator.SetBool("Dead", false);
base.creatureAnimator.SetBool("Grounded", false);
this.inSpecialAnimation = true;
this.agent.enabled = false;
this.enemyType.canBeStunned = true;
this.attachCollider.enabled = true;
this.physicsCollider.enabled = true;
this.physicsRigidbody.isKinematic = false;
this.hitboxCollider.enabled = true;
this.hitboxCollider.radius = 2f;
this.hitboxCollider.center = Vector3.zero;
this.physicsCollider.includeLayers &= ~(1 << 19); // remove Enemies layer from inclusions
this.physicsCollider.excludeLayers |= 1 << 19; // add Enemies layer to exclusions
break;
case 4: // Attached State
base.targetPlayer = null;
base.movingTowardsTargetPlayer = false;
this.creatureModel.transform.localPosition = Vector3.zero;
base.agent.speed = 0f;
base.creatureAnimator.SetBool("Jump", true);
base.creatureAnimator.SetBool("Attached", true);
base.creatureAnimator.SetBool("Dead", false);
base.creatureAnimator.SetBool("Grounded", false);
this.inSpecialAnimation = true;
this.agent.enabled = false;
this.enemyType.canBeStunned = false;
this.attachCollider.enabled = false;
this.physicsCollider.enabled = false;
this.physicsRigidbody.isKinematic = true;
this.hitboxCollider.enabled = false;
this.hitboxCollider.radius = 0.5f;
this.hitboxCollider.center = Vector3.zero;
NextWhisperTime = Time.time + 10f;
break;
case 5: // Recovery State
base.targetPlayer = null;
base.movingTowardsTargetPlayer = false;
base.agent.speed = 0f;
base.creatureAnimator.SetBool("Jump", false);
base.creatureAnimator.SetBool("Attached", false);
base.creatureAnimator.SetBool("Dead", false);
base.creatureAnimator.SetBool("Grounded", true);
this.inSpecialAnimation = false;
this.agent.enabled = true;
this.enemyType.canBeStunned = true;
this.attachCollider.enabled = true;
this.physicsCollider.enabled = false;
this.physicsRigidbody.isKinematic = true;
this.hitboxCollider.enabled = true;
this.hitboxCollider.radius = 0.5f;
this.hitboxCollider.center = new Vector3(0f, 0.5f, 0f);
break;
case 6: // Fall Off State
this.stateTimer = UnityEngine.Random.Range(0f, 1f); // make them all get up at slightly different times
base.targetPlayer = null;
base.movingTowardsTargetPlayer = false;
base.agent.speed = 0f;
this.creatureModel.transform.localPosition = Vector3.zero;
base.creatureAnimator.SetBool("Jump", true);
base.creatureAnimator.SetBool("Attached", false);
base.creatureAnimator.SetBool("Dead", false);
base.creatureAnimator.SetBool("Grounded", false);
this.inSpecialAnimation = true;
this.agent.enabled = false;
this.enemyType.canBeStunned = true;
this.attachCollider.enabled = false;
this.physicsCollider.enabled = true;
this.physicsRigidbody.isKinematic = false;
this.hitboxCollider.enabled = true;
this.hitboxCollider.radius = 0.5f;
this.hitboxCollider.center = Vector3.zero;
this.physicsCollider.includeLayers |= 1 << 19; // add Enemies layer to inclusions
this.physicsCollider.excludeLayers &= ~(1 << 19); // remove Enemies layer from exclusions
break;
case 7: // Dead State
base.targetPlayer = null;
base.movingTowardsTargetPlayer = false;
base.agent.speed = 0f;
this.creatureModel.transform.localPosition = Vector3.zero;
base.creatureAnimator.SetBool("Jump", false);
base.creatureAnimator.SetBool("Attached", false);
base.creatureAnimator.SetBool("Dead", true);
base.creatureAnimator.SetBool("Grounded", false);
this.inSpecialAnimation = true;
this.agent.enabled = false;
this.enemyType.canBeStunned = false;
this.attachCollider.enabled = false;
this.physicsCollider.enabled = false;
this.physicsRigidbody.isKinematic = true;
this.hitboxCollider.enabled = false;
this.hitboxCollider.radius = 0.5f;
this.hitboxCollider.center = Vector3.zero;
break;
default:
break;
}
base.SwitchToBehaviourStateOnLocalClient(state);
}
private float blinkTimer = 0f;
private float blinkInterval = 0f;
private void LateUpdate()
{
if (this.isEnemyDead)
{
return;