Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
BubkisLord committed Jun 10, 2022
1 parent 48e3f2d commit 53dafe4
Show file tree
Hide file tree
Showing 4 changed files with 292 additions and 29 deletions.
103 changes: 76 additions & 27 deletions CharmMod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,23 @@ public class CharmMod : Mod, ILocalSettings<SaveSettings>
HKBlessing.Instance,
HuntersMark.Instance,
PowerfulDash.Instance,
HealthyShell.Instance,
DoubleDash.Instance,
SoulSpeed.Instance,
SoulSpell.Instance,
SoulHunger.Instance,
RavenousSoul.Instance,
SoulSwitch.Instance,
GeoSwitch.Instance,
WealthyAmulet.Instance,
TripleJump.Instance
SoulSlow.Instance,
SlowTime.Instance,
SpeedTime.Instance
};

public int NewCharms = Charms.Count; //STARTS AT 0 (almost definately)
public int OldCharms = 40; //STARTS AT 1 (for some reason)

internal static CharmMod Instance;

private Dictionary<string, Func<bool, bool>> BoolGetters = new();
Expand Down Expand Up @@ -73,7 +86,9 @@ public override void Initialize()
On.PlayMakerFSM.OnEnable += EditFSMs;
On.PlayerData.CountCharms += CountOurCharms;
ModHooks.NewGameHook += GiveCharms;
ModHooks.HeroUpdateHook += SetDefaultNotchCosts;
ModHooks.HeroUpdateHook += OnUpdate;
ModHooks.SoulGainHook += GrantAllOurCharmsOnSoul;

StartTicking();
if (ModHooks.GetMod("DebugMod") != null)
{
Expand All @@ -84,7 +99,6 @@ public override void Initialize()
}
}
// breaks infinite loop when reading equippedCharm_X
private bool Equipped(Charm c) => c.Settings(Settings).Equipped;

private Dictionary<(string Key, string Sheet), Func<string>> TextEdits = new();

Expand All @@ -101,7 +115,8 @@ private void GiveCharms()
{
GrantAllOurCharms();
}
public override string GetVersion() => "6.3.2";

public override string GetVersion() => "8.30.3";

internal SaveSettings Settings = new();

Expand Down Expand Up @@ -149,9 +164,39 @@ private string GetCharmStrings(string key, string sheetName, string orig)
}
return orig;
}
private void SetDefaultNotchCosts()
private void OnUpdate()
{
GrantAllOurCharms();
//give charms when certain things are done.

if (PlayerData.instance.colosseumBronzeCompleted) Quickfall.Instance.Settings(Settings).Got = true;
if (PlayerData.instance.colosseumSilverCompleted) Slowfall.Instance.Settings(Settings).Got = true;
if (PlayerData.instance.hasShadowDash) PowerfulDash.Instance.Settings(Settings).Got = true;
if (PlayerData.instance.hasNailArt) SturdyNail.Instance.Settings(Settings).Got = true;
if (PlayerData.instance.hasHuntersMark) HuntersMark.Instance.Settings(Settings).Got = true;
if (PlayerData.instance.hasDreamGate) SoulHunger.Instance.Settings(Settings).Got = true;
if (PlayerData.instance.hasDreamNail) SoulSlow.Instance.Settings(Settings).Got = true;
if (PlayerData.instance.hasSuperDash && PlayerData.instance.gaveSlykey) BetterCDash.Instance.Settings(Settings).Got = true;
if (PlayerData.instance.killedHollowKnight) HKBlessing.Instance.Settings(Settings).Got = true;
if (PlayerData.instance.hasKingsBrand) HealthyShell.Instance.Settings(Settings).Got = true;
if (PlayerData.instance.killedHollowKnightPrime) GlassCannon.Instance.Settings(Settings).Got = true;
if (PlayerData.instance.bankerAccountPurchased) WealthyAmulet.Instance.Settings(Settings).Got = true;
if (PlayerData.instance.colosseumGoldCompleted) RavenousSoul.Instance.Settings(Settings).Got = true;
if (PlayerData.instance.canOvercharm) DoubleDash.Instance.Settings(Settings).Got = true;
if (PlayerData.instance.collectorDefeated) SoulSpell.Instance.Settings(Settings).Got = true;
if (PlayerData.instance.grubsCollected > 10) SlowTime.Instance.Settings(Settings).Got = true;
if (PlayerData.instance.fatGrubKing) SpeedTime.Instance.Settings(Settings).Got = true;
if (PlayerData.instance.mageLordDreamDefeated) GeoSwitch.Instance.Settings(Settings).Got = true;
if (PlayerData.instance.killedMageLord) SoulSwitch.Instance.Settings(Settings).Got = true;
if (PlayerData.instance.nailsmithConvoArt) SoulSpeed.Instance.Settings(Settings).Got = true;

//end
//ik it is messy, but what else is there to do. Also, if u are seeing this code and think that there is a more appropriate time to give the charm, DM me on discord. I am BubkisLord#5187


if (PlayerData.instance.maxHealth < 1)
{
HeroController.instance.AddToMaxHealth(1);
}
foreach (Charm charm in CharmMod.Charms)
{
charm.Settings(this.Settings).Cost = charm.DefaultCost;
Expand Down Expand Up @@ -216,25 +261,6 @@ private void CountOurCharms(On.PlayerData.orig_CountCharms orig, PlayerData self
self.SetInt("charmsOwned", self.GetInt("charmsOwned") + Charms.Count(c => c.Settings(Settings).Got));
}

private void RandomizeNotchCosts(int seed)
{
// This log statement is here to help diagnose a possible bug where charms cost more than
// they ever should.
Log("Randomizing notch costs");
var rng = new System.Random(seed);
var total = Charms.Select(x => x.DefaultCost).Sum();
for (var i = 0; i < total; i++)
{
var possiblePicks = Charms.Select(x => x.Settings(Settings)).Where(s => s.Cost < 6).ToList();
if (possiblePicks.Count == 0)
{
break;
}
var pick = rng.Next(possiblePicks.Count);
possiblePicks[pick].Cost++;
}
}

internal static void UpdateNailDamage()
{
IEnumerator WaitThenUpdate()
Expand All @@ -253,9 +279,27 @@ public void GrantAllOurCharms()
}
}

public void OnLoadLocal(SaveSettings s)
public int GrantAllOurCharmsOnSoul(int soulamount)
{
((ILocalSettings<SaveSettings>)Instance).OnLoadLocal(s);
foreach (var charm in Charms)
{
charm.Settings(Settings).Got = true;
}
return soulamount;
}

public int GiveSpecificCharm(int numberino)
{
Charms[numberino].Settings(Settings).Got = true;
return numberino;
}

public void TakeAllOurCharms()
{
foreach (var charm in Charms)
{
charm.Settings(Settings).Got = false;
}
}

SaveSettings ILocalSettings<SaveSettings>.OnSaveLocal()
Expand All @@ -267,5 +311,10 @@ public SaveSettings OnSaveLocal()
{
throw new NotImplementedException();
}

public void OnLoadLocal(SaveSettings s)
{
throw new NotImplementedException();
}
}
}
2 changes: 1 addition & 1 deletion CharmMod.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
<HintPath>$(HollowKnightRefs)/Mods/SFCore/SFCore.dll</HintPath>
</Reference>
<Reference Include="ItemChanger">
<HintPath>$(HollowKnightRefs)/Mods/ItemChanger/ItemChanger.dll</HintPath>
<HintPath>C:\Program Files (x86)\Hollow Knight\Hollow Knight_Data\Managed\Mods\ItemChanger\ItemChanger.dll</HintPath>
</Reference>
<Reference Include="MenuChanger">
<HintPath>$(HollowKnightRefs)/Mods/MenuChanger/MenuChanger.dll</HintPath>
Expand Down
204 changes: 204 additions & 0 deletions Menu.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
using Satchel.BetterMenus;

namespace CharmMod
{
public class ClassName : Mod, ICustomMenuMod, ITogglableMod, ILocalSettings<SaveSettings>, IMod
{
public ClassName() : base("Charm Mod") { }
public override string GetVersion() => CharmMod.Instance.GetVersion();
public override int LoadPriority() => 1;
public bool ToggleButtonInsideMenu => throw new NotImplementedException();

private int charmSelect = 0;
public override void Initialize()
{
ModHooks.LanguageGetHook += LanguageGet;
}

public string LanguageGet(string key, string sheetTitle, string orig)
{
//Check for the key and sheet for MainMenu "Yes" text
if (key == "HU_DEFEAT" && sheetTitle == "Ghosts")
{
return "My mind... it clears. Have we been sleeping? No, not you, little knight. ...I remember... ...those proud lords, were they truly monsters? Their eyes, bright and clear. Why, why did you tell me to fear them so? They were going to help... ...it was I who brought the madness... ...finally, you have stopped, you cruel voice... ...who are you?...";
}

if (key == "TOWN" && sheetTitle == "Map Zones")
{
return "Elderbug The Amazing's Domain";
}

if (key == "CLIFFS" && sheetTitle == "Map Zones")
{
return "The Forgotten Edge";
}

if (key == "DISTANT_VILLAGE" && sheetTitle == "Map Zones")
{
return "Herrah's Den";
}

if (key == "BONE_FOREST" && sheetTitle == "Map Zones")
{
return "Bone Forest";
}

if (key == "TEST_AREA" && sheetTitle == "Map Zones")
{
return "Test area, TELL ME WHERE U FOUND THIS. Ping me @BubkisLord#5187 (discord)";
}

if (key == "DREAM_WORLD" && sheetTitle == "Map Zones")
{
return "Dream World";
}

if (key == "ELDERBUG_FLOWER" && sheetTitle == "Prompts")
{
return "Give him the Delicate Flower like a giga-chad?";
}

if (key == "ELDERBUG_INTRO_VISITEDCROSSROAD" && sheetTitle == "Elderbug")
{
return "WHAT THE HELL WAS THAT? THE ONLY VISITOR FOR YEARS JUST WALKS PAST ME? HOW DARE YOU! Go away!";
}

if (key == "ELDERBUG_DREAM" && sheetTitle == "Elderbug")
{
return "Hello? Is someone there? Who is that? Aah! What was that? That feeling. ...Like the cold, terrifying embrace of death...";
}

if (orig.Contains("Hollow Knight"))
{
return orig.Replace("Hollow Knight", "Infected Vessel");
}

if (orig.Contains("Pure Vessel"))
{
return orig.Replace("Pure Vessel", "Hollow Vessel");
}

if (orig.Contains("Mantis"))
{
return orig.Replace("Mantis", "Bubkis");
}

if (orig.Contains("mantis"))
{
return orig.Replace("mantis", "bubkis");
}

if (orig.Contains("The Forgotten Town"))
{
return orig.Replace("The Forgotten Town", "The Realm of Elderbug");
}

if (ZoteBorn.Instance.Equipped() && key == "" && sheetTitle == "Prices")
{
return "Test area, TELL ME WHERE U FOUND THIS. Ping me @BubkisLord#5187 (discord)";
}

return orig;
}

private Menu MenuRef;
public MenuScreen GetMenuScreen(MenuScreen modListMenu, ModToggleDelegates? modtoggledelegates)
{
MenuRef ??= new Menu(
"CharmMod",
new Element[]
{
new MenuButton("Reset health", "Make health to max health.", (_) => HealthReset()),
new MenuButton("Add health", "Change health by 1.", (_) => AddHealth()),
new MenuButton("Take health", "Change health by -1.", (_) => TakeHealth()),
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 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 MenuButton("Give Specific Charm", "+1 to charm select", (_) => SelectCharm(1)),
new MenuButton("Give Specific Charm", "Pick the charm", (_) => GiveSpecificCharm(charmSelect)),
new MenuButton("Give Charms", "Get all CharmMod charms.", (_) => CharmMod.Instance.GrantAllOurCharms()),
new MenuButton("Take Charms", "Take all CharmMod charms.", (_) => CharmMod.Instance.TakeAllOurCharms())
}
);
return MenuRef.GetMenuScreen(modListMenu);
}

public int SelectCharm(int bubkis)
{
if (charmSelect > CharmMod.Instance.NewCharms)
{
charmSelect = 0;
}
charmSelect += bubkis;
return bubkis;
}

public int GiveSpecificCharm(int bubkis)
{
CharmMod.Instance.GiveSpecificCharm(bubkis);
return bubkis;
}

public void AddHealth()
{
HeroController.instance.AddHealth(1);
}
public void TakeHealth()
{
HeroController.instance.TakeHealth(1);
}
public void AddMaxHealth()
{
HeroController.instance.AddToMaxHealth(1);
PlayerData.instance.MaxHealth();
HeroController.instance.MaxHealth();
SoulSlow.Instance.Settings(CharmMod.Instance.Settings).Equipped = true;
SoulSlow.Instance.Settings(CharmMod.Instance.Settings).Equipped = false;
}

public void TakeMaxHealth()
{
HeroController.instance.AddToMaxHealth(-1);
PlayerData.instance.MaxHealth();
HeroController.instance.MaxHealth();
SoulSlow.Instance.Settings(CharmMod.Instance.Settings).Equipped = true;
SoulSlow.Instance.Settings(CharmMod.Instance.Settings).Equipped = false;
}
public void MaxHealthReset()
{
var CurrentMaxHp = PlayerData.instance.maxHealth;
var WantedMaxHp = 5;
var MaxHpChangeAmount = WantedMaxHp - CurrentMaxHp;
HeroController.instance.AddToMaxHealth(MaxHpChangeAmount);
PlayerData.instance.MaxHealth();
HeroController.instance.MaxHealth();
SoulSlow.Instance.Settings(CharmMod.Instance.Settings).Equipped = true;
SoulSlow.Instance.Settings(CharmMod.Instance.Settings).Equipped = false;
}

public void HealthReset()
{
var hp = PlayerData.instance.health;
var maxhp = PlayerData.instance.maxHealth;
var changeamount = maxhp - hp;
HeroController.instance.AddHealth(changeamount);
}
public void Unload()
{
throw new NotImplementedException();
}

public void OnLoadLocal(SaveSettings s)
{
throw new NotImplementedException();
}

public SaveSettings OnSaveLocal()
{
throw new NotImplementedException();
}
}
}
12 changes: 11 additions & 1 deletion SaveSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,17 @@ public class SaveSettings
public CharmSettings GlassCannon = new();
public CharmSettings WealthyAmulet = new();
public CharmSettings PowerfulDash = new();
public CharmSettings TripleJump = new();
public CharmSettings DoubleDash = new();
public CharmSettings SoulSpeed = new();
public CharmSettings SoulSpell = new();
public CharmSettings SoulHunger = new();
public CharmSettings RavenousSoul = new();
public CharmSettings SoulSwitch = new();
public CharmSettings HealthyShell = new();
public CharmSettings GeoSwitch = new();
public CharmSettings SoulSlow = new();
public CharmSettings SlowTime = new();
public CharmSettings SpeedTime = new();

public bool[] gotCharms = new[] { true, true, true, true };
public bool[] newCharms = new[] { false, false, false, false };
Expand Down

0 comments on commit 53dafe4

Please sign in to comment.