-
Notifications
You must be signed in to change notification settings - Fork 2
/
CharmMod.cs
1517 lines (1355 loc) · 73.4 KB
/
CharmMod.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
global using System;
global using System.IO;
global using System.Collections;
global using UnityEngine;
global using SFCore;
global using System.Collections.Generic;
global using System.Linq;
global using ItemChanger;
global using ItemChanger.Tags;
global using ItemChanger.UIDefs;
global using Satchel.BetterMenus;
global using GlobalEnums;
global using ItemChanger.Internal;
global using ItemChanger.Modules;
global using UnityEngine.SceneManagement;
global using System.Net;
global using HutongGames.PlayMaker;
global using ItemChanger.Locations;
global using ItemChanger.Placements;
global using UnityEngine.UIElements;
global using RandomizerMod.Extensions;
global using RandomizerMod.IC;
global using RandomizerMod.Menu;
global using RandomizerMod.Settings;
global using RandomizerMod;
global using RandomizerMod.RandomizerData;
global using RandomizerCore;
global using static Fyrenest.Fyrenest;
using RandomizerMod.RC;
using RandomizerMod.Logging;
using MenuChanger.MenuElements;
using MenuChanger;
using System.Configuration;
namespace Fyrenest
{
public class Fyrenest : Mod, IMod, ICustomMenuMod, ILocalSettings<CustomLocalSaveData>, ITogglableMod
{
/// <summary>
/// Gets the version of the mod
/// </summary>
public override string GetVersion() => "3.1 - Transition Update";
#region Variable Declarations
/// <summary>
/// The number of the selected charm (for the mod menu).
/// </summary>
public static int charmSelect = 0;
public static Fyrenest Loadedinstance { get; set; }
/// <summary>
/// The data for the loaded save
/// </summary>
public static CustomLocalSaveData LocalSaveData { get; set; } = new CustomLocalSaveData();
/// <summary>
/// Globally saved data - runs across all saves
/// </summary>
public static CustomGlobalSaveData GlobalSaveData { get; set; } = new CustomGlobalSaveData();
/// <summary>
/// Instances of all classes derived from Room
/// </summary>
readonly List<Room> rooms = new();
readonly PrefabManager PrefabMan = new();
/// <summary>
/// The room instance corresponding to the currently loaded scene.
/// </summary>
public Room ActiveRoom = null;
/// <summary>
/// The room that the player was previously in.
/// </summary>
public Room PreviousRoom = null;
public RoomMirrorer RoomMirrorer = new();
/// <summary>
/// If the mod is activated
/// </summary>
public bool Enabled = false;
public void OnLoadLocal(CustomLocalSaveData s) => LocalSaveData = s;
public void OnLoadGlobal(CustomGlobalSaveData gs) => GlobalSaveData = gs;
public CustomLocalSaveData OnSaveLocal() => LocalSaveData;
public CustomGlobalSaveData OnSaveGlobal() => GlobalSaveData;
public const int CurrentRevision = 3;
/// <summary>
/// Amount of new charms made by the mod.
/// </summary>
public int NewCharms = Charms.Count; //STARTS AT 1 FOR SOME REASON
/// <summary>
/// Amount of original charms.
/// </summary>
public int OldCharms = 40; //STARTS AT 1 FOR SOME REASON
internal static Fyrenest instance;
private readonly Dictionary<string, Func<bool, bool>> BoolGetters = new();
private readonly Dictionary<string, Action<bool>> BoolSetters = new();
private readonly Dictionary<string, Func<int, int>> IntGetters = new();
private readonly Dictionary<(string, string), Action<PlayMakerFSM>> FSMEdits = new();
private readonly List<(int Period, Action Func)> Tickers = new();
public static Dictionary<string, Dictionary<string, GameObject>> Preloads;
#endregion
/// <summary>
/// A list of all added charms.
/// </summary>
private readonly static List<Charm> Charms = new()
{
SturdyNail.instance,
BetterCDash.instance,
GlassCannon.instance,
HKBlessing.instance,
PowerfulDash.instance,
Fyrechild.instance,
OpportunisticDefeat.instance,
SoulSpeed.instance,
SoulHunger.instance,
RavenousSoul.instance,
SoulSpell.instance,
SoulSwitch.instance,
GeoSwitch.instance,
WealthyAmulet.instance,
SoulSlow.instance,
SlowTime.instance,
SpeedTime.instance,
ZoteBorn.instance,
GravityCharm.instance,
BulbousInfection.instance,
SlyDeal.instance,
ElderStone.instance,
GiantNail.instance,
MatosBlessing.instance,
HealthyShell.instance,
BlueBlood.instance,
ShellShield.instance,
WyrmForm.instance,
TripleJump.instance,
VoidSoul.instance
};
public Fyrenest() : base("Fyrenest")
{
//Make sure the main menu text is changed, but disable all other functionalitly
SetEnabled(true);
Enabled = true;
//Instantiate all Room subclasses
foreach (Type type in this.GetType().Assembly.GetTypes())
{
if (type.BaseType == typeof(Room))
{
rooms.Add((Room)Activator.CreateInstance(type));
}
}
}
/// <summary>
/// Called when the mod is loaded
/// </summary>
public override void Initialize(Dictionary<string, Dictionary<string, GameObject>> preloadedObjects)
{
Log("Initializing Mod.\nInitializing Part 1...");
Log("Adding Achievements...");
AchievementHelper.AddAchievement("voidSoulAchievement", EmbeddedSprite.Get("VoidSoulAchievement.png"), "Soul of Void", "Gain and wear the Void Soul charm.", false);
AchievementHelper.AddAchievement("allCharmsGained", EmbeddedSprite.Get("AllCharms.png"), "Charmed Vessel", "Gain all charms in Fyrenest", false);
AchievementHelper.AddAchievement("completedVessel", EmbeddedSprite.Get("CompletedVessel.png"), "Completed Vessel", "Gain all charms in the the whole game.", true);
if (GlobalSaveData.ALLCharmsGainedAchGot) GameManager.instance.AwardAchievement("completedVessel");
if (GlobalSaveData.allCharmsGainedAchGot) GameManager.instance.AwardAchievement("allCharmsGained");
if (GlobalSaveData.voidsoulachievementAchGot) GameManager.instance.AwardAchievement("voidSoulAchievement");
Log("Successfully Added Achievements.");
instance = this;
//set up hooks
On.GameManager.OnNextLevelReady += OnSceneLoad;
On.UIManager.StartNewGame += InitializeWorld;
On.HeroController.TakeDamage += OnDamage;
On.MenuStyleTitle.SetTitle += OnMainMenu;
On.HeroController.Start += OnGameStart;
On.GrimmEnemyRange.GetTarget += DisableGrimmchildShooting;
//Events.OnEnterGame += CorrectGrubfather;
Events.OnEnterGame += OnSaveLoad;
UnityEngine.SceneManagement.SceneManager.activeSceneChanged += OnBeforeSceneLoad;
ModHooks.CharmUpdateHook += OnCharmUpdate;
ModHooks.LanguageGetHook += GetCharmStrings;
ModHooks.GetPlayerBoolHook += ReadCharmBools;
ModHooks.SetPlayerBoolHook += WriteCharmBools;
ModHooks.GetPlayerIntHook += ReadCharmCosts;
// This will run after Rando has already set up its item placements.
On.PlayMakerFSM.OnEnable += EditFSMs;
On.PlayerData.CountCharms += CountOurCharms;
ModHooks.AfterSavegameLoadHook += OnLoadSave;
ModHooks.HeroUpdateHook += OnUpdate;
On.GameManager.SaveGame += OnSave;
ModHooks.SavegameLoadHook += ModHooks_SavegameLoadHook;
On.PlayerData.CountGameCompletion += SetGameCompletion;
Events.OnEnterGame += GiveStartingItemsAndSetEnabled;
//On.UIManager.StartNewGame += PlaceItems;
//intialize the Prefabs
PrefabMan.InitializePrefabs(preloadedObjects);
RoomMirrorer.Hook();
TextReplacements.instance.Hook();
FyrenestModeMenu.Register();
//Call OnInit for all Room subclasses
foreach (Room room in rooms)
{
room.OnInit();
Log("Initialized " + room.RoomName);
}
Log("Initialization Part 1 Complete.");
if (Fyrenest.Loadedinstance != null) return;
Fyrenest.Loadedinstance = this;
Preloads = preloadedObjects;
// Keep this for now, BUT DO NOT UNCOMMENT!!!
//On.HeroController.Awake += delegate (On.HeroController.orig_Awake orig, HeroController self) {
// orig.Invoke(self);
// foreach (IAbility ability in Abilities)
// {
// Log($"Loading ability {ability.Name}!");
// ability.Load();
// }
//};
Log("Initializing Part 2...");
if (ModHooks.GetMod("Randomizer 4") != null)
{
// The code that references rando needs to be in a separate method
// so that the mod will still load without it installed
// (trying to run a method whose code references an unavailable
// DLL will fail even if the code in question isn't actually run)
HookRando();
}
foreach (var charm in Charms)
{
var num = CharmHelper.AddSprites(EmbeddedSprite.Get(charm.Sprite))[0];
charm.Num = num;
var settings = charm.Settings;
IntGetters[$"charmCost_{num}"] = _ => settings(Settings).Cost;
AddTextEdit($"CHARM_NAME_{num}", "UI", charm.Name);
AddTextEdit($"CHARM_DESC_{num}", "UI", () => charm.Description);
BoolGetters[$"equippedCharm_{num}"] = _ => settings(Settings).Equipped;
BoolSetters[$"equippedCharm_{num}"] = value => settings(Settings).Equipped = value;
BoolGetters[$"gotCharm_{num}"] = _ => settings(Settings).Got;
BoolSetters[$"gotCharm_{num}"] = value => settings(Settings).Got = value;
BoolGetters[$"newCharm_{num}"] = _ => settings(Settings).New;
BoolSetters[$"newCharm_{num}"] = value => settings(Settings).New = value;
charm.Hook();
foreach (var edit in charm.FsmEdits)
{
AddFsmEdit(edit.obj, edit.fsm, edit.edit);
}
Tickers.AddRange(charm.Tickers);
var item = new ItemChanger.Items.CharmItem()
{
charmNum = charm.Num,
name = charm.Name.Replace(" ", "_"),
UIDef = new MsgUIDef()
{
name = new LanguageString("UI", $"CHARM_NAME_{charm.Num}"),
shopDesc = new LanguageString("UI", $"CHARM_DESC_{charm.Num}"),
}
};
// Tag the item for ConnectionMetadataInjector, so that MapModS and
// other mods recognize the items we're adding as charms.
var mapmodTag = item.AddTag<InteropTag>();
mapmodTag.Message = "RandoSupplementalMetadata";
mapmodTag.Properties["ModSource"] = GetName();
mapmodTag.Properties["PoolGroup"] = "Charms";
Finder.DefineCustomItem(item);
}
for (var i = 1; i <= 40; i++)
{
var num = i; // needed for closure to capture a different copy of the variable each time
BoolGetters[$"equippedCharm_{num}"] = value => value;
IntGetters[$"charmCost_{num}"] = value => value;
}
StartTicking();
if (ModHooks.GetMod("DebugMod") != null)
{
DebugModHook.GiveAllCharms(() =>
{
GrantAllOurCharms();
PlayerData.instance.CountCharms();
});
}
Log("Initializing Part 2 Complete.\n\nAll Initializing Complete.");
}
private void PlaceItems(On.UIManager.orig_StartNewGame orig, UIManager self, bool permaDeath, bool bossRush)
{
//if (ModHooks.GetMod("Randomizer 4") != null && IsRandoActive())
//{
// PlaceItemsRando();
//}
//else
//{
// ConfigureICModules();
// PlaceCharmsAtFixedPositions();
//}
}
private static void ConfigureICModules()
{
// The fix fury isnt really needed, but may make my life easier along the way.
ItemChangerMod.Modules.GetOrAdd<FixFury>();
// Everyone likes skips, am I right?
ItemChangerMod.Modules.GetOrAdd<LeftCityChandelier>();
//ItemChangerMod.Modules.GetOrAdd<PlayerDataEditModule>();
//ItemChangerMod.Modules.GetOrAdd<RespawnCollectorJars>();
//ItemChangerMod.Modules.GetOrAdd<TransitionFixes>();
//ItemChangerMod.Modules.GetOrAdd<FixWatcherKnightConditionalLoad>();
//ItemChangerMod.Modules.GetOrAdd<HorizontalTransitionQuakeCancel>();
//ItemChangerMod.Modules.GetOrAdd<ReusableBeastsDenEntrance>();
}
//private void PlaceItemsRando()
//{
// var gs = RandomizerMod.RandomizerMod.RS.GenerationSettings;
// if (!gs.PoolSettings.Charms)
// {
// PlaceCharmsAtFixedPositions();
// }
//}
//private static void DefineCharmsForRando(RequestBuilder rb)
//{
// if (!rb.gs.PoolSettings.Charms)
// {
// return;
// }
// var names = new HashSet<string>();
// foreach (var charm in Charms)
// {
// var name = charm.Name.Replace(" ", "_");
// names.Add(name);
// rb.EditItemRequest(name, info =>
// {
// info.getItemDef = () => new()
// {
// Name = name,
// Pool = "Charm",
// MajorItem = false,
// PriceCap = 666
// };
// });
// }
// rb.OnGetGroupFor.Subscribe(0f, (RequestBuilder rb, string item, RequestBuilder.ElementType type, out GroupBuilder gb) => {
// if (names.Contains(item) && (type == RequestBuilder.ElementType.Unknown || type == RequestBuilder.ElementType.Item))
// {
// gb = rb.GetGroupFor("Shaman_Stone");
// return true;
// }
// gb = default;
// return false;
// });
//}
private void HookRando()
{
//RequestBuilder.OnUpdate.Subscribe(-9999, SetRandoNotchCosts);
//RequestBuilder.OnUpdate.Subscribe(-498, DefineCharmsForRando);
//RequestBuilder.OnUpdate.Subscribe(-200, IncreaseMaxCharmCost);
//RequestBuilder.OnUpdate.Subscribe(50, AddCharmsToPool);
//SettingsLog.AfterLogSettings += LogRandoSettings;
}
private void IncreaseMaxCharmCost(RequestBuilder rb)
{
// This limitation could be lifted
if (rb.gs.PoolSettings.Charms && RandoSettings.Instance.AddCharms)
{
rb.gs.CostSettings.MaximumCharmCost += RandoSettings.Instance.IncreaseMaxCharmCostBy;
}
}
private void AddCharmsToPool(RequestBuilder rb)
{
if (!(rb.gs.PoolSettings.Charms && RandoSettings.Instance.AddCharms))
{
return;
}
foreach (var charm in Charms)
{
rb.AddItemByName(charm.Name.Replace(" ", "_"));
}
}
private void LogRandoSettings(LogArguments args, TextWriter w)
{
w.WriteLine("Logging Transcendence settings:");
w.WriteLine(JsonUtil.Serialize(RandoSettings.Instance));
}
//private Dictionary<int, int> DefaultNotchCosts()
//{
// var costs = Charms.ToDictionary(c => c.Num, c => c.DefaultCost);
// return costs;
//}
//private const int MinTotalCost = 25;
//private const int MaxTotalCost = 38;
//private Dictionary<int, int> RandomizeNotchCosts(int seed)
//{
// // This log statement is here to help diagnose a possible bug where charms cost more than
// // they ever should.
// var rng = new System.Random(seed);
// var total = rng.Next(MinTotalCost, MaxTotalCost + 1);
// Log($"Randomizing notch costs; total cost = {total}");
// var costs = Charms.ToDictionary(c => c.Num, c => 0);
// for (var i = 0; i < total; i++)
// {
// var possiblePicks = costs.Where(c => c.Value < 6).Select(c => c.Key).ToList();
// if (possiblePicks.Count == 0)
// {
// break;
// }
// var pick = rng.Next(possiblePicks.Count);
// costs[possiblePicks[pick]]++;
// }
// return costs;
//}
//private static void TestPlacements()
//{
// ItemChangerMod.AddPlacements(new List<AbstractPlacement>()
// {
// AddCharmPlacement(VoidSoul.instance),
// AddCharmPlacementExtended(TripleJump.instance, "GG_Atrium", 155.6f, 61.4f)
// }, conflictResolution: PlacementConflictResolution.Ignore);
//}
//private static MutablePlacement AddCharmPlacement(Charm charm)
//{
// var repairPlacement = new CoordinateLocation() { x = charm.X, y = charm.Y, elevation = 0, sceneName = charm.Scene, name = charm.Name }.Wrap() as MutablePlacement;
// for (int i = 0; i < Charms.Count; i++)
// {
// if (Charms[i].Name == charm.Name) repairPlacement.Add(Charms[i]);
// }
// return repairPlacement;
//}
//private static MutablePlacement AddCharmPlacementExtended(Charm charm, string Scene, float x, float y)
//{
// var repairPlacement = new CoordinateLocation() { x = x, y = y, elevation = 0, sceneName = Scene, name = charm.Name }.Wrap() as MutablePlacement;
// for (int i = 0; i < Charms.Count; i++)
// {
// if (Charms[i].Name == charm.Name) repairPlacement.Add(Charms[i]);
// }
// return repairPlacement;
//}
private void GiveStartingItemsAndSetEnabled()
{
if (LocalSaveData.FyrenestEnabled) Enabled = true;
if (Enabled) LocalSaveData.FyrenestEnabled = true;
}
private void SetGameCompletion(On.PlayerData.orig_CountGameCompletion orig, global::PlayerData self)
{
orig(self);
if (!Enabled) return;
float Completion = 0;
// 50% Max
int CharmMultiplier = 50/Charms.Count();
Completion += CharmMultiplier * Charms.Count(c => c.Settings(Settings).Got);
// 55% Max
if (PlayerData.instance.elderbugGaveFlower) Completion += 5;
// 57% Max
if (PlayerData.instance.dreamNailUpgraded) Completion += 2;
// 69% Max
Completion += Mathf.Clamp(PlayerData.instance.dreamOrbs, 0, 2400) / 200;
// 78% Max
if (PlayerData.instance.notchFogCanyon) Completion++;
if (PlayerData.instance.notchShroomOgres) Completion++;
if (PlayerData.instance.gotGrimmNotch) Completion++;
if (PlayerData.instance.salubraNotch1) Completion++;
if (PlayerData.instance.salubraNotch2) Completion++;
if (PlayerData.instance.salubraNotch3) Completion++;
if (PlayerData.instance.salubraNotch4) Completion++;
if (PlayerData.instance.slyNotch1) Completion++;
if (PlayerData.instance.slyNotch2) Completion++;
// 82% Max
Completion += Mathf.Clamp(PlayerData.instance.maxHealth, 5, 9) - 5;
// 85% Max
if (PlayerData.instance.metMoth) Completion += 3;
// 86% Max
if (PlayerData.instance.metGiraffe) Completion++;
// 100% Max
if (PlayerData.instance.dreamReward1) Completion++;
if (PlayerData.instance.dreamReward2) Completion++;
if (PlayerData.instance.dreamReward3) Completion++;
if (PlayerData.instance.dreamReward4) Completion++;
if (PlayerData.instance.dreamReward5) Completion += 2;
if (PlayerData.instance.dreamReward6) Completion += 2;
if (PlayerData.instance.dreamReward7) Completion += 2;
if (PlayerData.instance.dreamReward8) Completion += 2;
if (PlayerData.instance.dreamReward9) Completion += 2;
Completion = Mathf.Clamp(Completion, 0, 100);
self.completionPercentage = Completion;
}
private void ModHooks_SavegameLoadHook(int obj)
{
PlayerData.instance.CalculateNotchesUsed();
}
#region SaveData
public class CustomGlobalSaveData
{
public bool allCharmsGainedAchGot = false;
public bool voidsoulachievementAchGot = false;
public bool ALLCharmsGainedAchGot = false;
}
// The local data to store that is specific to saves.
public class CustomLocalSaveData
{
// What charms the player has in the specific save.
public bool SturdyNailGot = false;
public bool BetterCDashGot = false;
public bool GlassCannonGot = false;
public bool HKBlessingGot = false;
public bool PowerfulDashGot = false;
public bool HealthyShellGot = false;
public bool OpportunisticDefeatGot = false;
public bool SoulSpeedGot = false;
public bool SoulSpellGot = false;
public bool SoulHungerGot = false;
public bool RavenousSoulGot = false;
public bool SoulSwitchGot = false;
public bool GeoSwitchGot = false;
public bool WealthyAmuletGot = false;
public bool SoulSlowGot = false;
public bool SlowTimeGot = false;
public bool SpeedTimeGot = false;
public bool ZoteBornGot = false;
public bool SlyDealGot = false;
public bool ElderStoneGot = false;
public bool GiantNailGot = false;
public bool MatosBlessingGot = false;
public bool ShellShieldGot = false;
public bool VoidSoulGot = false;
public bool BlueBloodGot = false;
public bool SlowjumpGot = false;
public bool QuickjumpGot = false;
public bool TripleJumpGot = false;
public bool GravityCharmGot = false;
public bool BulbousInfectionGot = false;
public bool WyrmFormGot = false;
public bool FyreChildGot = false;
public bool QuickfallDonePopup = false;
public bool SlowfallDonePopup = false;
public bool SturdyNailDonePopup = false;
public bool BetterCDashDonePopup = false;
public bool GlassCannonDonePopup = false;
public bool HKBlessingDonePopup = false;
public bool PowerfulDashDonePopup = false;
public bool HealthyShellDonePopup = false;
public bool OpportunisticDefeatDonePopup = false;
public bool SoulSpeedDonePopup = false;
public bool SoulSpellDonePopup = false;
public bool SoulHungerDonePopup = false;
public bool RavenousSoulDonePopup = false;
public bool SoulSwitchDonePopup = false;
public bool GeoSwitchDonePopup = false;
public bool WealthyAmuletDonePopup = false;
public bool SoulSlowDonePopup = false;
public bool SlowTimeDonePopup = false;
public bool SpeedTimeDonePopup = false;
public bool ZoteBornDonePopup = false;
public bool SlyDealDonePopup = false;
public bool ElderStoneDonePopup = false;
public bool GiantNailDonePopup = false;
public bool MatosBlessingDonePopup = false;
public bool ShellShieldDonePopup = false;
public bool VoidSoulDonePopup = false;
public bool BlueBloodDonePopup = false;
public bool QuickjumpDonePopup = false;
public bool SlowjumpDonePopup = false;
public bool TripleJumpDonePopup = false;
public bool GravityCharmDonePopup = false;
public bool BulbousInfectionDonePopup = false;
public bool WyrmFormDonePopup = false;
public bool FyreChildDonePopup = false;
public int revision = 0;
public bool FyrenestEnabled = false;
public bool allCharmsGainedShown = false;
public bool ALLCharmsGainedShown = false;
public bool voidsoulachievementShown = false;
}
#endregion
private void OnLoadSave(SaveGameData obj)
{
PlayerData.instance.CalculateNotchesUsed();
PlayerData.instance.openedMapperShop = true;
PlayerData.instance.mapAllRooms = true;
PlayerData.instance.mapAbyss = true;
PlayerData.instance.mapCity = true;
PlayerData.instance.mapCliffs = true;
PlayerData.instance.mapCrossroads = true;
PlayerData.instance.mapDeepnest = true;
PlayerData.instance.mapDirtmouth = true;
PlayerData.instance.mapFogCanyon = true;
PlayerData.instance.mapFungalWastes = true;
PlayerData.instance.mapGreenpath = true;
PlayerData.instance.mapMines = true;
PlayerData.instance.mapOutskirts = true;
PlayerData.instance.mapRestingGrounds = true;
PlayerData.instance.mapRoyalGardens = true;
PlayerData.instance.mapWaterways = true;
PlayerData.instance.hasMap = true;
PlayerData.instance.UpdateGameMap();
}
private int ReadCharmCosts(string intName, int value)
{
bool flag = this.IntGetters.TryGetValue(intName, out Func<int, int> cost);
int result;
if (flag)
{
result = cost(value);
}
else
{
result = value;
}
return result;
}
private void OnUpdate()
{
//change dreamshield to cost 2 notches.
PlayerData.instance.charmCost_38 = 2;
foreach (Charm charm in Charms)
{
charm.Settings(Settings).Cost = charm.DefaultCost;
}
#region Ugly block of code (do not look at it, it is GROSS AS)
//give charms when certain things are done.
if (PlayerData.instance.hasShadowDash) PowerfulDash.instance.Settings(Settings).Got = true; LocalSaveData.PowerfulDashGot = true;
if (PlayerData.instance.hasNailArt) SturdyNail.instance.Settings(Settings).Got = true; LocalSaveData.SturdyNailGot = true;
if (PlayerData.instance.hasDreamGate) SoulHunger.instance.Settings(Settings).Got = true; LocalSaveData.SoulHungerGot = true;
if (PlayerData.instance.hasDreamNail) SoulSlow.instance.Settings(Settings).Got = true; LocalSaveData.SoulSlowGot = true;
if (PlayerData.instance.hasSuperDash && PlayerData.instance.gaveSlykey) BetterCDash.instance.Settings(Settings).Got = true; LocalSaveData.BetterCDashGot = true;
if (PlayerData.instance.killedHollowKnight) HKBlessing.instance.Settings(Settings).Got = true; LocalSaveData.HKBlessingGot = true;
if (PlayerData.instance.hasKingsBrand) HealthyShell.instance.Settings(Settings).Got = true; LocalSaveData.HealthyShellGot = true;
if (PlayerData.instance.killedHollowKnightPrime) GlassCannon.instance.Settings(Settings).Got = true; LocalSaveData.GlassCannonGot = true;
if (PlayerData.instance.bankerAccountPurchased) WealthyAmulet.instance.Settings(Settings).Got = true; LocalSaveData.WealthyAmuletGot = true;
if (PlayerData.instance.colosseumGoldCompleted) RavenousSoul.instance.Settings(Settings).Got = true; LocalSaveData.RavenousSoulGot = true;
if (PlayerData.instance.canOvercharm) OpportunisticDefeat.instance.Settings(Settings).Got = true; LocalSaveData.OpportunisticDefeatGot = true;
if (PlayerData.instance.collectorDefeated) SoulSpell.instance.Settings(Settings).Got = true; LocalSaveData.SoulSpellGot = true;
if (PlayerData.instance.grubsCollected > 10) SlowTime.instance.Settings(Settings).Got = true; LocalSaveData.SlowTimeGot = true;
if (PlayerData.instance.statueStateCollector.completedTier2) SpeedTime.instance.Settings(Settings).Got = true; LocalSaveData.SpeedTimeGot = true;
if (PlayerData.instance.mageLordDreamDefeated) GeoSwitch.instance.Settings(Settings).Got = true; LocalSaveData.GeoSwitchGot = true;
if (PlayerData.instance.killedMageLord) SoulSwitch.instance.Settings(Settings).Got = true; LocalSaveData.SoulSwitchGot = true;
if (PlayerData.instance.nailsmithConvoArt) SoulSpeed.instance.Settings(Settings).Got = true; LocalSaveData.SoulSpeedGot = true;
if (PlayerData.instance.zotePrecept > 56) ZoteBorn.instance.Settings(Settings).Got = true; LocalSaveData.ZoteBornGot = true;
if (PlayerData.instance.visitedWhitePalace) ElderStone.instance.Settings(Settings).Got = true; LocalSaveData.ElderStoneGot = true;
if (PlayerData.instance.gaveSlykey && PlayerData.instance.slyConvoNailHoned && PlayerData.instance.completionPercentage > 100) SlyDeal.instance.Settings(Settings).Got = true; LocalSaveData.SlyDealGot = true;
if (PlayerData.instance.honedNail) GiantNail.instance.Settings(Settings).Got = true; LocalSaveData.GiantNailGot = true;
if (PlayerData.instance.hasAllNailArts && PlayerData.instance.hasKingsBrand) MatosBlessing.instance.Settings(Settings).Got = true; LocalSaveData.MatosBlessingGot = true;
if (!LocalSaveData.SturdyNailGot && SturdyNail.instance.Settings(Settings).Got) LocalSaveData.SturdyNailGot = true;
if (!LocalSaveData.BetterCDashGot && BetterCDash.instance.Settings(Settings).Got) LocalSaveData.BetterCDashGot = true;
if (!LocalSaveData.GlassCannonGot && GlassCannon.instance.Settings(Settings).Got) LocalSaveData.GlassCannonGot = true;
if (!LocalSaveData.HKBlessingGot && HKBlessing.instance.Settings(Settings).Got) LocalSaveData.HKBlessingGot = true;
if (!LocalSaveData.PowerfulDashGot && PowerfulDash.instance.Settings(Settings).Got) LocalSaveData.PowerfulDashGot = true;
if (!LocalSaveData.HealthyShellGot && HealthyShell.instance.Settings(Settings).Got) LocalSaveData.HealthyShellGot = true;
if (!LocalSaveData.OpportunisticDefeatGot && OpportunisticDefeat.instance.Settings(Settings).Got) LocalSaveData.OpportunisticDefeatGot = true;
if (!LocalSaveData.SoulSpeedGot && SoulSpeed.instance.Settings(Settings).Got) LocalSaveData.SoulSpeedGot = true;
if (!LocalSaveData.SoulSpellGot && SoulSpell.instance.Settings(Settings).Got) LocalSaveData.SoulSpellGot = true;
if (!LocalSaveData.SoulHungerGot && SoulHunger.instance.Settings(Settings).Got) LocalSaveData.SoulHungerGot = true;
if (!LocalSaveData.RavenousSoulGot && RavenousSoul.instance.Settings(Settings).Got) LocalSaveData.RavenousSoulGot = true;
if (!LocalSaveData.SoulSwitchGot && SoulSwitch.instance.Settings(Settings).Got) LocalSaveData.SoulSwitchGot = true;
if (!LocalSaveData.GeoSwitchGot && GeoSwitch.instance.Settings(Settings).Got) LocalSaveData.GeoSwitchGot = true;
if (!LocalSaveData.WealthyAmuletGot && WealthyAmulet.instance.Settings(Settings).Got) LocalSaveData.WealthyAmuletGot = true;
if (!LocalSaveData.SoulSlowGot && SoulSlow.instance.Settings(Settings).Got) LocalSaveData.SoulSlowGot = true;
if (!LocalSaveData.SlowTimeGot && SlowTime.instance.Settings(Settings).Got) LocalSaveData.SlowTimeGot = true;
if (!LocalSaveData.SpeedTimeGot && SpeedTime.instance.Settings(Settings).Got) LocalSaveData.SpeedTimeGot = true;
if (!LocalSaveData.ZoteBornGot && ZoteBorn.instance.Settings(Settings).Got) LocalSaveData.ZoteBornGot = true;
if (!LocalSaveData.SlyDealGot && SlyDeal.instance.Settings(Settings).Got) LocalSaveData.SlyDealGot = true;
if (!LocalSaveData.ElderStoneGot && ElderStone.instance.Settings(Settings).Got) LocalSaveData.ElderStoneGot = true;
if (!LocalSaveData.GiantNailGot && GiantNail.instance.Settings(Settings).Got) LocalSaveData.GiantNailGot = true;
if (!LocalSaveData.MatosBlessingGot && MatosBlessing.instance.Settings(Settings).Got) LocalSaveData.MatosBlessingGot = true;
if (!LocalSaveData.ShellShieldGot && ShellShield.instance.Settings(Settings).Got) LocalSaveData.ShellShieldGot = true;
if (!LocalSaveData.GravityCharmGot && GravityCharm.instance.Settings(Settings).Got) LocalSaveData.GravityCharmGot = true;
if (!LocalSaveData.BulbousInfectionGot && BulbousInfection.instance.Settings(Settings).Got) LocalSaveData.BulbousInfectionGot = true;
if (!LocalSaveData.FyreChildGot && Fyrechild.instance.Settings(Settings).Got) LocalSaveData.FyreChildGot = true;
if (!LocalSaveData.WyrmFormGot && WyrmForm.instance.Settings(Settings).Got) LocalSaveData.WyrmFormGot = true;
if (!LocalSaveData.VoidSoulGot && VoidSoul.instance.Settings(Settings).Got) LocalSaveData.WyrmFormGot = true;
#endregion
#region More dumb code stuff
if (PlayerData.instance.maxHealth < 1)
{
HeroController.instance.AddToMaxHealth(1);
}
if (CheckIfGotAllCharms() && !LocalSaveData.allCharmsGainedShown) MessageController.Enqueue(EmbeddedSprite.Get("AllCharms.png"), "Unlocked Achievement"); GameManager.instance.AwardAchievement("allCharmsGained"); LocalSaveData.allCharmsGainedShown = true; GlobalSaveData.allCharmsGainedAchGot = true;
if (VoidSoul.instance.Equipped() && VoidSoul.instance.Settings(Settings).Got && !LocalSaveData.voidsoulachievementShown) MessageController.Enqueue(EmbeddedSprite.Get("VoidSoulAchievement.png"), "Unlocked Achievement"); GameManager.instance.AwardAchievement("voidSoulAchievement"); LocalSaveData.voidsoulachievementShown = true; GlobalSaveData.voidsoulachievementAchGot = true;
if (CheckIfObtainedALLCharms() && !LocalSaveData.ALLCharmsGainedShown) MessageController.Enqueue(EmbeddedSprite.Get("CompletedVessel.png"), "Hidden Achievement Unlocked: Completed Vessel"); GameManager.instance.AwardAchievement("completedVessel"); LocalSaveData.ALLCharmsGainedShown = true; GlobalSaveData.ALLCharmsGainedAchGot = true;
//GameObject map = GameObject.Find("");
//if (map != null)
//{
// var assembly = Assembly.GetExecutingAssembly();
// using (var stream = assembly.GetManifestResourceStream("Fyrenest.Resources.map.png"))
// {
// Sprite mapSprite = SpriteManager.Load(stream);
// map.GetComponent<SpriteRenderer>().sprite = mapSprite;
// }
//}
if (Input.GetKeyDown(KeyCode.Backspace))
{
Log("Initiating OnWorldInit()");
PlaceCharmsAtFixedPositions();
//Call OnWorldInit for all Room subclasses
foreach (Room room in rooms)
{
room.OnWorldInit();
Log("Initialized " + room.RoomName);
}
Log("Re-initialized all rooms.");
}
if (Input.GetKeyDown(KeyCode.Alpha0))
{
// Toggle if Fyrenest is enabled.
LocalSaveData.FyrenestEnabled = true;
Log("Initiating OnWorldInit()");
PlaceCharmsAtFixedPositions();
//Call OnWorldInit for all Room subclasses
foreach (Room room in rooms)
{
room.OnWorldInit();
Log("Initialized " + room.RoomName);
}
Log("Re-initialized all rooms.");
}
#endregion
}
public bool CheckIfGotAllCharms()
{
int counter = 0;
foreach (Charm charm in Charms)
{
if (charm.Settings(Settings).Got)
{
counter++;
}
}
if (counter == Charms.Count)
{
return true;
}
else
{
return false;
}
}
public bool CheckIfObtainedALLCharms()
{
int counter = 0;
foreach (Charm charm in Charms)
{
if (charm.Settings(Settings).Got)
{
counter++;
}
}
// sorry for that super long line...
if (counter == Charms.Count && PlayerData.instance.gotCharm_1 && PlayerData.instance.gotCharm_2 &&
PlayerData.instance.gotCharm_3 && PlayerData.instance.gotCharm_4 && PlayerData.instance.gotCharm_5 &&
PlayerData.instance.gotCharm_6 && PlayerData.instance.gotCharm_7 && PlayerData.instance.gotCharm_8 &&
PlayerData.instance.gotCharm_9 && PlayerData.instance.gotCharm_10 && PlayerData.instance.gotCharm_11 &&
PlayerData.instance.gotCharm_12 && PlayerData.instance.gotCharm_13 && PlayerData.instance.gotCharm_14 &&
PlayerData.instance.gotCharm_15 && PlayerData.instance.gotCharm_16 && PlayerData.instance.gotCharm_17 &&
PlayerData.instance.gotCharm_18 && PlayerData.instance.gotCharm_19 && PlayerData.instance.gotCharm_20 &&
PlayerData.instance.gotCharm_21 && PlayerData.instance.gotCharm_22 && PlayerData.instance.gotCharm_23 &&
PlayerData.instance.gotCharm_24 && PlayerData.instance.gotCharm_25 && PlayerData.instance.gotCharm_26 &&
PlayerData.instance.gotCharm_27 && PlayerData.instance.gotCharm_28 && PlayerData.instance.gotCharm_29 &&
PlayerData.instance.gotCharm_30 && PlayerData.instance.gotCharm_31 && PlayerData.instance.gotCharm_32 &&
PlayerData.instance.gotCharm_33 && PlayerData.instance.gotCharm_34 && PlayerData.instance.gotCharm_35 &&
PlayerData.instance.gotCharm_36 && PlayerData.instance.gotCharm_37 && PlayerData.instance.gotCharm_38 &&
PlayerData.instance.gotCharm_39 && PlayerData.instance.gotCharm_40)
{
return true;
}
else
{
return false;
}
}
public bool insanity = false;
private void OnSave(On.GameManager.orig_SaveGame orig, GameManager self)
{
CheckCharmPopup();
orig(self);
}
public bool ToggleButtonInsideMenu => true;
public string selectedCharm = Charms[charmSelect].ToString().Replace("Fyrenest.", "").Replace(".instance", "");
/// <summary>
/// UNUSED - YOU SHOULD NOT NEED THIS VARIABLE
/// </summary>
public static int ModToggle = 0;
private Menu MenuRef;
private Menu ExtraMenuRef;
public MenuScreen GetMenuScreen(MenuScreen modListMenu, ModToggleDelegates? toggleDelegates)
{
MenuRef ??= new Menu(
"Fyrenest",
new Element[]
{
new TextPanel("Fyrenest Settings", 1000, 70),
new MenuButton("Reset health", "Make health to max health.", (_) => HealthReset(), false, Id:"Test"),
new TextPanel("Health Settings", 1000, 70),
new MenuButton("Reset health", "Make health to max health.", (_) => HealthReset(), false, Id:"Reset Health"),
new MenuButton("Add health", "Change health by 1.", (_) => AddHealth(), false, Id:"Add Health"),
new MenuButton("Take health", "Change health by -1.", (_) => TakeHealth(), false, Id:"Take Health"),
new TextPanel("Max Health Settings", 1000, 70),
new MenuButton("Reset Max Health", "Sets max health to 5", (_) => MaxHealthReset()),
new MenuButton("Add Max Health", "Increase max health by one. (Equip and de-equip the slow soul charm to update)", (_) => AddMaxHealth()),
new MenuButton("Take Max Health", "Decrease max health by one. (Equip and de-equip the slow soul charm to update)", (_) => TakeMaxHealth()),
new TextPanel("Soul Settings", 1000, 70),
new MenuButton("Reset Soul", "Make soul the max soul amount.", (_) => HeroController.instance.AddMPCharge(PlayerData.instance.MPReserveMax)),
new MenuButton("Add Soul", "Add one charge of soul.", (_) => HeroController.instance.AddMPCharge(33)),
new MenuButton("Take Soul", "Take one charge of soul.", (_) => HeroController.instance.TakeMP(33)),
new TextPanel("Charm Settings", 1000, 70),
new MenuRow(new List<Element>() //first parameter is a list of elements you want to add to the row
{
new MenuButton("Select Specific Charm", "Current Charm Selected: Quickfall", (_) => {
//find element by Id
SelectCharm(1); //trigger normal function
Element elem = MenuRef.Find("SelectSpecificCharm");
MenuButton buttonElem = elem as MenuButton;
buttonElem.Name = "Select Specific Charm"; //change name
string SelectedCharm = Charms[charmSelect].Name.ToString();
string charmNameSelected = SelectedCharm.Replace("Fyrenest.", "").Replace(".instance", "");
string desc = "Current selected charm: "+SelectedCharm; //set desc to the new wanted description
buttonElem.Description = desc; //change description
buttonElem.Update();//Update button
MenuRef.Update(); // Update Menu
}, false, Id:"SelectSpecificCharm"),
new MenuButton("Give Specific Charm", "Add the charm to your inventory.", (_) => GiveSpecificCharm(1), false, Id:"GiveSpecCharm"),
}, "Specific Charm Selection"),
new MenuButton("Give Charms", "Get all CharmMod charms.", (_) => GrantAllOurCharms()),
new MenuButton("Take Charms", "Take all CharmMod charms.", (_) => TakeAllOurCharms()),
new MenuButton("Update Charms", "Reloads charm effects.", (_) => ReloadCharmEffects()),
new MenuButton("More Settings", "", (_) => UIManager.instance.UIGoToDynamicMenu(ExtraMenuRef.menuScreen)),
}
);
ExtraMenuRef ??= new Menu(
"Extra Fyrenest Settings",
new Element[]
{
new TextPanel("Extra Mod Settings",1000, 100, Id:"ModToggleTitle"),
new HorizontalOption( "Insanity Mode", "Toggle insanity mode.", new string[]{ "Normal", "INSANITY" }, (setting) => { ModToggle = setting; if(setting == 0) { insanity = false; } else { insanity = true; } }, () => ModToggle),
new MenuButton("Back button", "Go back to main page.", (_) => UIManager.instance.UIGoToDynamicMenu(MenuRef.menuScreen)),
new TextPanel("Do not press the default back button.", 500, 50, "BackButtonWarning")
}
);
MenuRef.GetMenuScreen(modListMenu);
ExtraMenuRef.GetMenuScreen(ExtraMenuRef.menuScreen);
return MenuRef.menuScreen;
}
private void ReloadCharmEffects()
{
GameManager.instance.UpdateBlueHealth();
GameManager.instance.SaveGame();
PlayerData.instance.equippedCharms.Clear();
foreach (var charm in Charms)
{
charm.Settings(Settings).Equipped = false;
}
HeroController.instance.CharmUpdate();
PlayerData.instance.CalculateNotchesUsed();
return;
}
public static MenuButton NavigateToMenu(string name, string description, Func<MenuScreen> getScreen)
{
return new MenuButton(
name,
description,
(mb) =>
{
UIManager.instance.UIGoToDynamicMenu(getScreen());
},
proceed: true
);
}
#region Charm Language Replacements
private string GetCharmStrings(string key, string sheetName, string orig)
{
if (TextEdits.TryGetValue((key, sheetName), out var text))
{
return text();
}
return orig;
}
#endregion
#region Random Useless Stuff
public float grav = 0f;
public float gravsaved = 0f;
public static void PlaceCharmsAtFixedPositions()
{
var placements = new List<AbstractPlacement>();
foreach (var charm in Charms)
{
// make it so only some charms get placed, not all of them
if (charm.Placeable)
{
var name = charm.Name.Replace(" ", "_");
placements.Add(
new CoordinateLocation() { x = charm.X, y = charm.Y, elevation = 0, sceneName = charm.Scene, name = name }
.Wrap()
.Add(Finder.GetItem(name)));
}
}
ItemChangerMod.AddPlacements(placements);
}
public int SelectCharm(int bubkis)
{
if (charmSelect > Charms.Count)
{
charmSelect = 0;
}
charmSelect += bubkis;
return bubkis;
}
public void AddHealth()
{
HeroController.instance.AddHealth(1);
}
public void TakeHealth()
{
HeroController.instance.TakeHealth(1);
}
public void AddMaxHealth()