-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathModAI.cs
996 lines (913 loc) · 41.4 KB
/
ModAI.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
using AIs;
using ModAI.Data.Enums;
using ModAI.Data.Interfaces;
using ModAI.Data.Modding;
using ModAI.Managers;
using ModManager;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Xml;
using UnityEngine;
using UnityEngine.UI;
namespace ModAI
{
/// <summary>
/// ModAI is a mod for Green Hell that enables a player to use cheats,
/// customize some AI behaviour
/// and spawn in enemy waves and other creatures.
/// Press Keypad8 (default) or the key configurable in ModAPI to open the main mod screen.
/// </summary>
public class ModAI : MonoBehaviour
{
private static ModAI Instance;
private static readonly string ModName = nameof(ModAI);
private static readonly string RuntimeConfiguration = Path.Combine(Application.dataPath.Replace("GH_Data", "Mods"), $"{nameof(RuntimeConfiguration)}.xml");
private static float ModAIScreenTotalWidth { get; set; } = 700f;
private static float ModAIScreenTotalHeight { get; set; } = 150f;
private static float ModAIScreenMinWidth { get; set; } = 700f;
private static float ModAIScreenMaxWidth { get; set; } = Screen.width;
private static float ModAIScreenMinHeight { get; set; } = 50f;
private static float ModAIScreenMaxHeight { get; set; } = Screen.height;
private static float ModAIScreenStartPositionX { get; set; } = Screen.width / 8f;
private static float ModAIScreenStartPositionY { get; set; } = 0f;
private bool IsModAIScreenMinimized { get; set; } = false;
private static int ModAIScreenId { get; set; }
private static Rect ModAIScreen = new Rect(ModAIScreenStartPositionX, ModAIScreenStartPositionY, ModAIScreenTotalWidth, ModAIScreenTotalHeight);
private bool ShowModAIScreen { get; set; } = false;
private bool ShowModInfo { get; set; } = false;
private bool ShowCheatOptions { get; set; } = false;
private static CursorManager LocalCursorManager;
private static HUDManager LocalHUDManager;
private static Player LocalPlayer;
private static EnemyAISpawnManager LocalEnemyAISpawnManager;
private static FirecampGroupsManager LocalFirecampGroupsManager;
private static AIManager LocalAIManager;
private static StylingManager LocalStylingManager;
public Vector2 ModInfoScrollViewPosition { get; set; }
public IConfigurableMod SelectedMod { get; set; }
public Vector2 AISelectionScrollViewPosition { get; set; }
public string TribalsInWaveCount { get; set; } = "3";
public string SelectedAiCount { get; set; } = "1";
public string SelectedAiName { get; set; } = string.Empty;
public int SelectedAiIndex { get; set; } = 0;
public string[] GetAINames()
{
var aiNames = Enum.GetNames(typeof(AI.AIID));
return aiNames;
}
public FirecampGroup PlayerFireCampGroup { get; set; }
public string WaveWest { get; set; } = string.Empty;
public string WaveSouth { get; set; } = string.Empty;
public bool IsHostile { get; set; } = true;
public bool CanSwim { get; set; } = false;
public bool IsHallucination { get; set; } = false;
public bool IsGodModeCheatEnabled { get; set; } = false;
public bool IsItemDecayCheatEnabled { get; set; } = false;
public bool IsGhostModeCheatEnabled { get; set; } = false;
public bool IsOneShotAICheatEnabled { get; set; } = false;
public bool IsOneShotDestroyCheatEnabled { get; set; } = false;
public bool IsModActiveForMultiplayer { get; private set; } = false;
public bool IsModActiveForSingleplayer => ReplTools.AmIMaster();
private string OnlyForSinglePlayerOrHostMessage()
=> "Only available for single player or when host. Host can activate using ModManager.";
private string PermissionChangedMessage(string permission, string reason)
=> $"Permission to use mods and cheats in multiplayer was {permission} because {reason}.";
private string HUDBigInfoMessage(string message, MessageType messageType, Color? headcolor = null)
=> $"<color=#{(headcolor != null ? ColorUtility.ToHtmlStringRGBA(headcolor.Value) : ColorUtility.ToHtmlStringRGBA(Color.red))}>{messageType}</color>\n{message}";
private void OnlyForSingleplayerOrWhenHostBox()
{
using (new GUILayout.HorizontalScope(GUI.skin.box))
{
GUILayout.Label(OnlyForSinglePlayerOrHostMessage(), LocalStylingManager.ColoredCommentLabel(Color.yellow));
}
}
private void ModManager_onPermissionValueChanged(bool optionValue)
{
string reason = optionValue ? "the game host allowed usage" : "the game host did not allow usage";
IsModActiveForMultiplayer = optionValue;
ShowHUDBigInfo(
(optionValue ?
HUDBigInfoMessage(PermissionChangedMessage($"granted", $"{reason}"), MessageType.Info, Color.green)
: HUDBigInfoMessage(PermissionChangedMessage($"revoked", $"{reason}"), MessageType.Info, Color.yellow))
);
}
public void ShowHUDBigInfo(string text, float duration = 3f)
{
string header = $"{ModName} Info";
string textureName = HUDInfoLogTextureType.Count.ToString();
HUDBigInfo obj = (HUDBigInfo)LocalHUDManager.GetHUD(typeof(HUDBigInfo));
HUDBigInfoData.s_Duration = duration;
HUDBigInfoData data = new HUDBigInfoData
{
m_Header = header,
m_Text = text,
m_TextureName = textureName,
m_ShowTime = Time.time
};
obj.AddInfo(data);
obj.Show(show: true);
}
public void ShowHUDInfoLog(string itemID, string localizedTextKey)
{
Localization localization = GreenHellGame.Instance.GetLocalization();
var messages = ((HUDMessages)LocalHUDManager.GetHUD(typeof(HUDMessages)));
messages.AddMessage($"{localization.Get(localizedTextKey)} {localization.Get(itemID)}");
}
protected virtual void Start()
{
ModManager.ModManager.onPermissionValueChanged += ModManager_onPermissionValueChanged;
ShortcutKey = GetShortcutKey(nameof(ShortcutKey));
}
public ModAI()
{
useGUILayout = true;
Instance = this;
}
public static ModAI Get()
{
return Instance;
}
private void InitSkinUI()
{
GUI.skin = ModAPI.Interface.Skin;
}
private void EnableCursor(bool blockPlayer = false)
{
LocalCursorManager.ShowCursor(blockPlayer, false);
if (blockPlayer)
{
LocalPlayer.BlockMoves();
LocalPlayer.BlockRotation();
LocalPlayer.BlockInspection();
}
else
{
LocalPlayer.UnblockMoves();
LocalPlayer.UnblockRotation();
LocalPlayer.UnblockInspection();
}
}
public KeyCode ShortcutKey { get; set; } = KeyCode.Keypad8;
public KeyCode GetShortcutKey(string buttonID)
{
var ConfigurableModList = GetModList();
if (ConfigurableModList != null && ConfigurableModList.Count > 0)
{
SelectedMod = ConfigurableModList.Find(cfgMod => cfgMod.ID == ModName);
return SelectedMod.ConfigurableModButtons.Find(cfgButton => cfgButton.ID == buttonID).ShortcutKey;
}
else
{
return KeyCode.Keypad8;
}
}
private List<IConfigurableMod> GetModList()
{
List<IConfigurableMod> modList = new List<IConfigurableMod>();
try
{
if (File.Exists(RuntimeConfiguration))
{
using (XmlReader configFileReader = XmlReader.Create(new StreamReader(RuntimeConfiguration)))
{
while (configFileReader.Read())
{
configFileReader.ReadToFollowing("Mod");
do
{
string gameID = GameID.GreenHell.ToString();
string modID = configFileReader.GetAttribute(nameof(IConfigurableMod.ID));
string uniqueID = configFileReader.GetAttribute(nameof(IConfigurableMod.UniqueID));
string version = configFileReader.GetAttribute(nameof(IConfigurableMod.Version));
var configurableMod = new ConfigurableMod(gameID, modID, uniqueID, version);
configFileReader.ReadToDescendant("Button");
do
{
string buttonID = configFileReader.GetAttribute(nameof(IConfigurableModButton.ID));
string buttonKeyBinding = configFileReader.ReadElementContentAsString();
configurableMod.AddConfigurableModButton(buttonID, buttonKeyBinding);
} while (configFileReader.ReadToNextSibling("Button"));
if (!modList.Contains(configurableMod))
{
modList.Add(configurableMod);
}
} while (configFileReader.ReadToNextSibling("Mod"));
}
}
}
return modList;
}
catch (Exception exc)
{
HandleException(exc, nameof(GetModList));
modList = new List<IConfigurableMod>();
return modList;
}
}
private void HandleException(Exception exc, string methodName)
{
string info = $"[{ModName}:{methodName}] throws exception - {exc.TargetSite?.Name}:\n{exc.Message}\n{exc.InnerException}\n{exc.Source}\n{exc.StackTrace}";
ModAPI.Log.Write(info);
Debug.Log(info);
}
protected virtual void Update()
{
if (Input.GetKeyDown(ShortcutKey))
{
if (!ShowModAIScreen)
{
InitData();
EnableCursor(true);
}
ToggleShowUI(0);
if (!ShowModAIScreen)
{
EnableCursor(false);
}
}
}
protected virtual void InitData()
{
LocalCursorManager = CursorManager.Get();
LocalHUDManager = HUDManager.Get();
LocalPlayer = Player.Get();
LocalEnemyAISpawnManager = EnemyAISpawnManager.Get();
LocalFirecampGroupsManager = FirecampGroupsManager.Get();
LocalAIManager = AIManager.Get();
LocalStylingManager = StylingManager.Get();
}
private void ToggleShowUI(int controlId)
{
switch (controlId)
{
case 0:
ShowModAIScreen = !ShowModAIScreen;
return;
case 3:
ShowModInfo = !ShowModInfo;
return;
case 4:
ShowCheatOptions = !ShowCheatOptions;
return;
default:
ShowModAIScreen = !ShowModAIScreen;
ShowModInfo = !ShowModInfo;
ShowCheatOptions = !ShowCheatOptions;
return;
}
}
private void OnGUI()
{
if (ShowModAIScreen)
{
InitData();
InitSkinUI();
ShowModAIWindow();
}
}
private void ShowModAIWindow()
{
if (ModAIScreenId <= 0)
{
ModAIScreenId = GetHashCode();
}
string modAIScreenTitle = $"{ModName} created by [Dragon Legion] Immaanuel#4300";
ModAIScreen = GUILayout.Window(ModAIScreenId, ModAIScreen, InitModAIScreen, modAIScreenTitle,
GUI.skin.window,
GUILayout.ExpandWidth(true),
GUILayout.MinWidth(ModAIScreenMinWidth),
GUILayout.MaxWidth(ModAIScreenMaxWidth),
GUILayout.ExpandHeight(true),
GUILayout.MinHeight(ModAIScreenMinHeight),
GUILayout.MaxHeight(ModAIScreenMaxHeight));
}
private void ScreenMenuBox()
{
string CollapseButtonText = IsModAIScreenMinimized ? "O" : "-";
if (GUI.Button(new Rect(ModAIScreen.width - 40f, 0f, 20f, 20f), CollapseButtonText, GUI.skin.button))
{
CollapseWindow();
}
if (GUI.Button(new Rect(ModAIScreen.width - 20f, 0f, 20f, 20f), "X", GUI.skin.button))
{
CloseWindow();
}
}
private void CollapseWindow()
{
if (!IsModAIScreenMinimized)
{
ModAIScreen = new Rect(ModAIScreenStartPositionX, ModAIScreenStartPositionY, ModAIScreenTotalWidth, ModAIScreenMinHeight);
IsModAIScreenMinimized = true;
}
else
{
ModAIScreen = new Rect(ModAIScreenStartPositionX, ModAIScreenStartPositionY, ModAIScreenTotalWidth, ModAIScreenTotalHeight);
IsModAIScreenMinimized = false;
}
ShowModAIWindow();
}
private void CloseWindow()
{
ShowModAIScreen = false;
EnableCursor(false);
}
private void InitModAIScreen(int windowId)
{
ModAIScreenStartPositionX = ModAIScreen.x;
ModAIScreenStartPositionY = ModAIScreen.y;
using (new GUILayout.VerticalScope(GUI.skin.box))
{
ScreenMenuBox();
if (!IsModAIScreenMinimized)
{
ModAIManagerBox();
CheatsManagerBox();
AIManagerBox();
}
}
GUI.DragWindow(new Rect(0f, 0f, 10000f, 10000f));
}
private void AIManagerBox()
{
try
{
if (IsModActiveForSingleplayer || IsModActiveForMultiplayer)
{
using (new GUILayout.VerticalScope(GUI.skin.box))
{
GUILayout.Label($"AI Manager", LocalStylingManager.ColoredHeaderLabel(Color.yellow));
GUILayout.Label($"AI Options", LocalStylingManager.ColoredSubHeaderLabel(Color.yellow));
AiOptionsBox();
SpawnWaveBox();
AISelectionScrollViewBox();
SpawnAIBox();
KillAiBox();
}
}
else
{
OnlyForSingleplayerOrWhenHostBox();
}
}
catch (Exception exc)
{
HandleException(exc, nameof(AIManagerBox));
}
}
private void ModAIManagerBox()
{
try
{
if (IsModActiveForSingleplayer || IsModActiveForMultiplayer)
{
using (new GUILayout.VerticalScope(GUI.skin.box))
{
GUILayout.Label($"{ModName} Manager", LocalStylingManager.ColoredHeaderLabel(Color.yellow));
GUILayout.Label($"{ModName} Options", LocalStylingManager.ColoredSubHeaderLabel(Color.yellow));
if (GUILayout.Button($"Mod Info", GUI.skin.button))
{
ToggleShowUI(3);
}
if (ShowModInfo)
{
ModInfoBox();
}
MultiplayerOptionBox();
}
}
else
{
OnlyForSingleplayerOrWhenHostBox();
}
}
catch (Exception exc)
{
HandleException(exc, nameof(ModAIManagerBox));
}
}
private void ModInfoBox()
{
using (new GUILayout.VerticalScope(GUI.skin.box))
{
ModInfoScrollViewPosition = GUILayout.BeginScrollView(ModInfoScrollViewPosition, GUI.skin.scrollView, GUILayout.MinHeight(150f));
GUILayout.Label("Mod Info", LocalStylingManager.ColoredSubHeaderLabel(Color.cyan));
using (new GUILayout.HorizontalScope(GUI.skin.box))
{
GUILayout.Label($"{nameof(IConfigurableMod.GameID)}:", LocalStylingManager.FormFieldNameLabel);
GUILayout.Label($"{SelectedMod.GameID}", LocalStylingManager.FormFieldValueLabel);
}
using (new GUILayout.HorizontalScope(GUI.skin.box))
{
GUILayout.Label($"{nameof(IConfigurableMod.ID)}:", LocalStylingManager.FormFieldNameLabel);
GUILayout.Label($"{SelectedMod.ID}", LocalStylingManager.FormFieldValueLabel);
}
using (var uidScope = new GUILayout.HorizontalScope(GUI.skin.box))
{
GUILayout.Label($"{nameof(IConfigurableMod.UniqueID)}:", LocalStylingManager.FormFieldNameLabel);
GUILayout.Label($"{SelectedMod.UniqueID}", LocalStylingManager.FormFieldValueLabel);
}
using (var versionScope = new GUILayout.HorizontalScope(GUI.skin.box))
{
GUILayout.Label($"{nameof(IConfigurableMod.Version)}:", LocalStylingManager.FormFieldNameLabel);
GUILayout.Label($"{SelectedMod.Version}", LocalStylingManager.FormFieldValueLabel);
}
GUILayout.Label("Buttons Info", LocalStylingManager.ColoredSubHeaderLabel(Color.cyan));
foreach (var configurableModButton in SelectedMod.ConfigurableModButtons)
{
using (var btnidScope = new GUILayout.HorizontalScope(GUI.skin.box))
{
GUILayout.Label($"{nameof(IConfigurableModButton.ID)}:", LocalStylingManager.FormFieldNameLabel);
GUILayout.Label($"{configurableModButton.ID}", LocalStylingManager.FormFieldValueLabel);
}
using (var btnbindScope = new GUILayout.HorizontalScope(GUI.skin.box))
{
GUILayout.Label($"{nameof(IConfigurableModButton.KeyBinding)}:", LocalStylingManager.FormFieldNameLabel);
GUILayout.Label($"{configurableModButton.KeyBinding}", LocalStylingManager.FormFieldValueLabel);
}
}
GUILayout.EndScrollView();
}
}
private void MultiplayerOptionBox()
{
try
{
using (new GUILayout.VerticalScope(GUI.skin.box))
{
GUILayout.Label("Multiplayer Options", LocalStylingManager.ColoredSubHeaderLabel(Color.yellow));
string multiplayerOptionMessage = string.Empty;
if (IsModActiveForSingleplayer || IsModActiveForMultiplayer)
{
if (IsModActiveForSingleplayer)
{
multiplayerOptionMessage = $"you are the game host";
}
if (IsModActiveForMultiplayer)
{
multiplayerOptionMessage = $"the game host allowed usage";
}
GUILayout.Label(PermissionChangedMessage($"granted", multiplayerOptionMessage), LocalStylingManager.ColoredFieldValueLabel(Color.green));
}
else
{
if (!IsModActiveForSingleplayer)
{
multiplayerOptionMessage = $"you are not the game host";
}
if (!IsModActiveForMultiplayer)
{
multiplayerOptionMessage = $"the game host did not allow usage";
}
GUILayout.Label(PermissionChangedMessage($"revoked", $"{multiplayerOptionMessage}"), LocalStylingManager.ColoredFieldValueLabel(Color.yellow));
}
}
}
catch (Exception exc)
{
HandleException(exc, nameof(MultiplayerOptionBox));
}
}
private void CheatsManagerBox()
{
try
{
using (new GUILayout.VerticalScope(GUI.skin.box))
{
GUILayout.Label($"Cheat manager", LocalStylingManager.ColoredHeaderLabel(Color.yellow));
GUILayout.Label($"Cheat Options", LocalStylingManager.ColoredSubHeaderLabel(Color.yellow));
if (GUILayout.Button($"Cheats", GUI.skin.button))
{
ToggleShowUI(4);
}
if (ShowCheatOptions)
{
CheatOptionsBox();
}
}
}
catch (Exception exc)
{
HandleException(exc, nameof(CheatsManagerBox));
}
}
private void CheatOptionsBox()
{
using (new GUILayout.VerticalScope(GUI.skin.box))
{
GUILayout.Label("These are all available cheats. You can switch any cheat on / off.", LocalStylingManager.TextLabel);
Cheats.m_OneShotAI = GUILayout.Toggle(Cheats.m_OneShotAI, "One shot AI cheat on / off", GUI.skin.toggle);
Cheats.m_OneShotConstructions = GUILayout.Toggle(Cheats.m_OneShotConstructions, "One shot constructions cheat on / off", GUI.skin.toggle);
Cheats.m_GhostMode = GUILayout.Toggle(Cheats.m_GhostMode, "Ghost mode cheat on / off", GUI.skin.toggle);
Cheats.m_GodMode = GUILayout.Toggle(Cheats.m_GodMode, "God mode cheat on / off", GUI.skin.toggle);
Cheats.m_ImmortalItems = GUILayout.Toggle(Cheats.m_ImmortalItems, "No item decay cheat on / off", GUI.skin.toggle);
Cheats.m_InstantBuild = GUILayout.Toggle(Cheats.m_InstantBuild, "Instant build cheat on / off", GUI.skin.toggle);
}
}
private void AiOptionsBox()
{
try
{
using (new GUILayout.VerticalScope(GUI.skin.box))
{
GUILayout.Label($"Switch to set for AI to be able to swim or not.", LocalStylingManager.FormFieldNameLabel);
CanSwimOption();
GUILayout.Label($"Switch to set for AI to become hostile or not", LocalStylingManager.FormFieldNameLabel);
IsHostileOption();
GUILayout.Label($"Switch to set for AI to be a hallucination or not", LocalStylingManager.FormFieldNameLabel);
IsHallucinationOption();
}
}
catch (Exception exc)
{
HandleException(exc, nameof(AiOptionsBox));
}
}
private void IsHallucinationOption()
{
try
{
using (new GUILayout.HorizontalScope(GUI.skin.box))
{
bool _isHallucinationValue = IsHallucination;
IsHallucination = GUILayout.Toggle(IsHallucination, $"AI is a hallucination?", LocalStylingManager.FormFieldNameLabel);
if (_isHallucinationValue != IsHallucination)
{
if (LocalAIManager.m_ActiveAIs != null)
{
foreach (var activeAi in LocalAIManager.m_ActiveAIs)
{
activeAi.m_Hallucination = IsHallucination;
if (IsHallucination)
{
activeAi.Disappear(true);
}
activeAi.InitializeModules();
}
}
string _optionText = $"AI is hallucination has been { (IsHallucination ? "enabled" : "disabled") }";
ShowHUDBigInfo(HUDBigInfoMessage(_optionText, MessageType.Info, Color.green));
}
if (IsHallucination)
{
GUILayout.Label($"enabled", LocalStylingManager.ColoredToggleFieldValueLabel(IsHallucination, Color.green, LocalStylingManager.DefaultColor));
}
else
{
GUILayout.Label($"disabled", LocalStylingManager.ColoredToggleFieldValueLabel(IsHallucination, Color.green, LocalStylingManager.DefaultColor));
}
}
}
catch (Exception exc)
{
HandleException(exc, nameof(IsHallucinationOption));
}
}
private void IsHostileOption()
{
try
{
using (new GUILayout.HorizontalScope(GUI.skin.box))
{
bool _isHostileValue = IsHostile;
IsHostile = GUILayout.Toggle(IsHostile, $"AI is hostile?", LocalStylingManager.FormFieldNameLabel);
if (_isHostileValue != IsHostile)
{
if (LocalAIManager.m_ActiveAIs != null)
{
foreach (var activeAi in LocalAIManager.m_ActiveAIs)
{
if (activeAi.m_HostileStateModule != null)
{
activeAi.m_HostileStateModule.m_State = IsHostile ? HostileStateModule.State.Aggressive : HostileStateModule.State.Calm;
activeAi.InitializeModules();
}
}
}
string _optionText = $"AI is hostile has been { (IsHostile ? "enabled" : "disabled") }";
ShowHUDBigInfo(HUDBigInfoMessage(_optionText, MessageType.Info, Color.green));
}
if (IsHostile)
{
GUILayout.Label($"enabled", LocalStylingManager.ColoredToggleFieldValueLabel(IsHostile, Color.green, LocalStylingManager.DefaultColor));
}
else
{
GUILayout.Label($"disabled", LocalStylingManager.ColoredToggleFieldValueLabel(IsHostile, Color.green, LocalStylingManager.DefaultColor));
}
}
}
catch (Exception exc)
{
HandleException(exc, nameof(IsHostileOption));
}
}
private void CanSwimOption()
{
try
{
using (new GUILayout.HorizontalScope(GUI.skin.box))
{
bool _canSwimValue = CanSwim;
CanSwim = GUILayout.Toggle(CanSwim, $"AI can swim?", LocalStylingManager.FormFieldNameLabel);
if (_canSwimValue != CanSwim)
{
if (LocalAIManager?.m_ActiveAIs != null)
{
foreach (var activeAi in LocalAIManager?.m_ActiveAIs)
{
if (activeAi.m_Params != null)
{
activeAi.m_Params.m_CanSwim = CanSwim;
activeAi.InitializeModules();
}
}
}
string _optionText = $"AI can swim has been { (CanSwim ? "enabled" : "disabled") }";
ShowHUDBigInfo(HUDBigInfoMessage(_optionText, MessageType.Info, Color.green));
}
if (CanSwim)
{
GUILayout.Label($"enabled", LocalStylingManager.ColoredToggleFieldValueLabel(CanSwim, Color.green, LocalStylingManager.DefaultColor));
}
else
{
GUILayout.Label($"disabled", LocalStylingManager.ColoredToggleFieldValueLabel(CanSwim, Color.green, LocalStylingManager.DefaultColor));
}
}
}
catch (Exception exc)
{
HandleException(exc, nameof(CanSwimOption));
}
}
private void SpawnWaveBox()
{
if (!IsGodModeCheatEnabled)
{
using (new GUILayout.VerticalScope(GUI.skin.box))
{
GUILayout.Label("Here you can spawn in waves of enemies. Set how many enemies you would like in the wave. Click [Spawn wave] to start the attack.", LocalStylingManager.TextLabel);
using (var actionScope = new GUILayout.HorizontalScope(GUI.skin.box))
{
GUILayout.Label("Enemy count in wave", LocalStylingManager.TextLabel);
TribalsInWaveCount = GUILayout.TextField(TribalsInWaveCount, LocalStylingManager.FormInputTextField);
if (GUILayout.Button("Spawn wave", GUI.skin.button, GUILayout.Width(150f)))
{
OnClickSpawnWaveButton();
}
}
}
}
else
{
using (var infoScope = new GUILayout.HorizontalScope(GUI.skin.box))
{
GUILayout.Label($"To enable, please switch player cheat god mode off", LocalStylingManager.ColoredCommentLabel(Color.yellow));
}
}
}
private void OnClickSpawnWaveButton()
{
try
{
int validatedTribalCount = ValidMinMax(TribalsInWaveCount);
if (validatedTribalCount > 0)
{
HumanAIWave humanAiWave = LocalEnemyAISpawnManager?.SpawnWave(validatedTribalCount, IsHallucination, PlayerFireCampGroup);
if (humanAiWave != null && humanAiWave.m_Members != null && humanAiWave.m_Members.Count > 0)
{
Vector3 spawnPosition = humanAiWave.transform.position;
LocalPlayer.GetGPSCoordinates(spawnPosition, out int gps_lat, out int gps_long);
WaveWest = gps_lat.ToString();
WaveSouth = gps_long.ToString();
LocalEnemyAISpawnManager?.BlockSpawn();
StringBuilder info = new StringBuilder($"Spawned a wave of {humanAiWave.m_Members.Count} enemies");
info.Append($" at GPS coordinates W {WaveWest} S {WaveSouth}");
info.AppendLine($"");
info.Append($" Each enemy {(CanSwim ? "can swim" : "cannot swim")}, ");
info.Append($" {(IsHostile ? "is hostile" : "is not hostile")} ");
info.Append($" and {(IsHallucination ? "is a hallucination." : "is real")}.");
info.AppendLine($"");
foreach (HumanAI humanAI in humanAiWave.m_Members)
{
info.Append($"{humanAI.GetName().Replace("Clone", "").Replace("(", "").Replace(")", "")} incoming!");
if (humanAI.m_HostileStateModule != null)
{
humanAI.m_HostileStateModule.m_State = IsHostile ? HostileStateModule.State.Aggressive : HostileStateModule.State.Calm;
}
if (humanAI.m_Params != null)
{
humanAI.m_Params.m_CanSwim = CanSwim;
}
humanAI.InitializeModules();
}
humanAiWave.Initialize();
LocalEnemyAISpawnManager?.UnblockSpawn();
ShowHUDBigInfo(HUDBigInfoMessage(info.ToString(), MessageType.Info, Color.green));
}
else
{
ShowHUDBigInfo(HUDBigInfoMessage($"Something went wrong. Cannot spawn a wave of {validatedTribalCount}!", MessageType.Warning, Color.yellow));
}
}
else
{
ShowHUDBigInfo(HUDBigInfoMessage($"Invalid input {validatedTribalCount}: please input numbers only - min. 1 and max. 5", MessageType.Warning, Color.yellow));
}
}
catch (Exception exc)
{
HandleException(exc, nameof(OnClickSpawnWaveButton));
}
}
private void SpawnAIBox()
{
using (new GUILayout.VerticalScope(GUI.skin.box))
{
GUILayout.Label($"Here you can spawn in any selected being. Set how many AI beings you would like to spawn in, then click [Spawn {SelectedAiName}].", LocalStylingManager.TextLabel);
GUILayout.Label($"Only a count between min. 1 and max. 5 beings is allowed!", LocalStylingManager.ColoredCommentLabel(Color.yellow) );
using (var actionScope = new GUILayout.HorizontalScope(GUI.skin.box))
{
GUILayout.Label($"AI count", LocalStylingManager.TextLabel);
SelectedAiCount = GUILayout.TextField(SelectedAiCount, LocalStylingManager.FormInputTextField);
if (GUILayout.Button($"Spawn {SelectedAiName}", GUI.skin.button, GUILayout.Width(150f)))
{
OnClickSpawnAIButton();
}
}
}
}
private void KillAiBox()
{
using (new GUILayout.VerticalScope(GUI.skin.box))
{
GUILayout.Label($"Here you can kill all occurrences in-game of a selected AI being type.", LocalStylingManager.TextLabel);
using (new GUILayout.HorizontalScope(GUI.skin.box))
{
GUILayout.Label($"To kill all {SelectedAiName}", LocalStylingManager.TextLabel);
if (GUILayout.Button($"Execute {SelectedAiName}", GUI.skin.button, GUILayout.Width(150f)))
{
OnClickKillButton();
}
}
}
}
private void OnClickKillButton()
{
try
{
if (!string.IsNullOrEmpty(SelectedAiName))
{
if (LocalAIManager.m_ActiveAIs != null)
{
var toKill = LocalAIManager.m_ActiveAIs?.Where(an => an.GetName().Contains(SelectedAiName));
if (toKill != null)
{
foreach (AI ai in toKill)
{
DamageInfo damageInfo = new DamageInfo
{
m_Damage = float.MaxValue,
m_Damager = LocalPlayer.gameObject,
m_Normal = Vector3.up,
m_Position = ai.transform.position
};
ai.TakeDamage(damageInfo);
}
}
}
StringBuilder info = new StringBuilder($"Killed all {SelectedAiName}!");
ShowHUDBigInfo(HUDBigInfoMessage(info.ToString(), MessageType.Info, Color.green));
}
else
{
ShowHUDBigInfo(HUDBigInfoMessage($"Please select AI to kill!", MessageType.Warning, Color.yellow));
}
}
catch (Exception exc)
{
HandleException(exc, nameof(OnClickKillButton));
}
}
private void AISelectionScrollViewBox()
{
try
{
using (new GUILayout.VerticalScope(GUI.skin.box))
{
GUILayout.Label("AI selection grid", LocalStylingManager.TextLabel);
AiSelectionScrollView();
}
}
catch (Exception exc)
{
HandleException(exc, nameof(AISelectionScrollViewBox));
}
}
private void AiSelectionScrollView()
{
try
{
AISelectionScrollViewPosition = GUILayout.BeginScrollView(AISelectionScrollViewPosition, GUI.skin.scrollView, GUILayout.MinHeight(300f));
string[] aiNames = GetAINames();
if (aiNames != null)
{
int _selectedAiIndex = SelectedAiIndex;
SelectedAiIndex = GUILayout.SelectionGrid(SelectedAiIndex, aiNames, 3, LocalStylingManager.ColoredSelectedGridButton(_selectedAiIndex!=SelectedAiIndex));
SelectedAiName = aiNames[SelectedAiIndex];
}
GUILayout.EndScrollView();
}
catch (Exception exc)
{
HandleException(exc, nameof(AiSelectionScrollView));
}
}
private void OnClickSpawnAIButton()
{
try
{
int validatedSelectedAiCount = ValidMinMax(SelectedAiCount);
if (validatedSelectedAiCount > 0)
{
string[] aiNames = GetAINames();
SelectedAiName = aiNames[SelectedAiIndex];
if (!string.IsNullOrEmpty(SelectedAiName))
{
for (int i = 0; i < validatedSelectedAiCount; i++)
{
SpawnAI(SelectedAiName);
}
StringBuilder info = new StringBuilder($"Spawned in {SelectedAiCount} x {SelectedAiName}");
ShowHUDBigInfo(HUDBigInfoMessage(info.ToString(), MessageType.Info, Color.green));
}
}
else
{
ShowHUDBigInfo(HUDBigInfoMessage($"Invalid input {validatedSelectedAiCount}: please input numbers only - min. 1 and max. 5", MessageType.Warning, Color.yellow));
}
}
catch (Exception exc)
{
HandleException(exc, nameof(OnClickSpawnAIButton));
}
}
private void SpawnAI(string aiName)
{
try
{
AI ai = default;
GameObject prefab = GreenHellGame.Instance.GetPrefab(aiName);
if (prefab != null)
{
Vector3 forward = Camera.main.transform.forward;
Vector3 position = LocalPlayer.GetHeadTransform().position + forward * 10f;
ai = Instantiate(prefab, position, Quaternion.LookRotation(-forward, Vector3.up)).GetComponent<AI>();
if (ai == null)
{
ShowHUDBigInfo(HUDBigInfoMessage($"Something went wrong. Could not instantiate game object {aiName}!", MessageType.Warning, Color.yellow));
}
}
else
{
ShowHUDBigInfo(HUDBigInfoMessage($"Something went wrong. Could not get prefab for {aiName}!", MessageType.Warning, Color.yellow));
}
}
catch (Exception exc)
{
HandleException(exc, nameof(SpawnAI));
}
}
private int ValidMinMax(string countToValidate)
{
try
{
if (int.TryParse(countToValidate, out int count))
{
if (count <= 0)
{
count = 1;
}
if (count > 5)
{
count = 5;
}
return count;
}
else
{
return -1;
}
}
catch (Exception exc)
{
HandleException(exc, nameof(ValidMinMax));
return 1;
}
}
}
}