diff --git a/DifficultyMod/Core/DifficultyPatcher.cs b/DifficultyMod/Core/DifficultyPatcher.cs index f28c122..7f72935 100644 --- a/DifficultyMod/Core/DifficultyPatcher.cs +++ b/DifficultyMod/Core/DifficultyPatcher.cs @@ -128,14 +128,121 @@ static IEnumerable Transpiler(IEnumerable inst } } - [HarmonyPatch(typeof(CardPowder), "GetPowderScale")] + + public static float ModifyEnergyOnTrashCard(float defaultEnergy) + { + // Do not modify the Attack if the game is public (i.e. anyone can join without room code) + if (!IsPrivateGame()) + { + return defaultEnergy; + } + + return defaultEnergy * DifficultySettings.EnergyGainMultiplier; + } + + public static float ModifyEnergyOnAttack(float defaultEnergy) + { + // Do not modify the Attack if the game is public (i.e. anyone can join without room code) + if (!IsPrivateGame()) + { + return defaultEnergy; + } + + return defaultEnergy * DifficultySettings.AttackEnergyGainMultiplier; + } + + public static float ModifyEnergyOnKill(float defaultEnergy) + { + // Do not modify the Attack if the game is public (i.e. anyone can join without room code) + if (!IsPrivateGame()) + { + return defaultEnergy; + } + + MelonLoader.MelonLogger.Msg(defaultEnergy + " MULT " + DifficultySettings.KillEnergyGainMultiplier); + return defaultEnergy * DifficultySettings.KillEnergyGainMultiplier; + } + + [HarmonyPatch(typeof(CardPowder), "OnTrashedCard")] class EnergyGainMultiplierPatcher { - static void Postfix(ref float __result) + static MethodInfo m_MyExtraMethod = AccessTools.Method(typeof(DifficultyPatcher), nameof(ModifyEnergyOnTrashCard), new[] { typeof(int) }); + + static IEnumerable Transpiler(IEnumerable instructions) { - if (IsPrivateGame()) + foreach (CodeInstruction instruction in instructions) { - __result *= DifficultySettings.EnergyGainMultiplier; + if (instruction.opcode == OpCodes.Mul) + { + yield return instruction; + yield return new CodeInstruction(OpCodes.Call, m_MyExtraMethod); + + continue; + } + yield return instruction; + } + } + } + + [HarmonyPatch(typeof(CardPowder), "GetPowderIncreaseValueFromTrashedCard")] + class EnergyGainDisplayedMultiplierPatcher + { + static MethodInfo m_MyExtraMethod = AccessTools.Method(typeof(DifficultyPatcher), nameof(ModifyEnergyOnTrashCard), new[] { typeof(float) }); + + static IEnumerable Transpiler(IEnumerable instructions) + { + foreach (CodeInstruction instruction in instructions) + { + if (instruction.opcode == OpCodes.Mul) + { + yield return instruction; + yield return new CodeInstruction(OpCodes.Call, m_MyExtraMethod); + + continue; + } + yield return instruction; + } + } + } + + [HarmonyPatch(typeof(CardPowder), "OnPlayerDealtDamage")] + class AttackEnergyGainMultiplierPatcher + { + static MethodInfo m_MyExtraMethod = AccessTools.Method(typeof(DifficultyPatcher), nameof(ModifyEnergyOnAttack), new[] { typeof(float) }); + + static IEnumerable Transpiler(IEnumerable instructions) + { + foreach (CodeInstruction instruction in instructions) + { + if (instruction.opcode == OpCodes.Mul) + { + yield return instruction; + yield return new CodeInstruction(OpCodes.Call, m_MyExtraMethod); + + continue; + } + yield return instruction; + } + } + } + + [HarmonyPatch(typeof(CardPowder), "OnEnemyKilled")] + class KillEnergyGainMultiplierPatcher + { + static MethodInfo m_MyExtraMethod = AccessTools.Method(typeof(DifficultyPatcher), nameof(ModifyEnergyOnKill), new[] { typeof(float) }); + + static IEnumerable Transpiler(IEnumerable instructions) + { + foreach (CodeInstruction instruction in instructions) + { + if (instruction.opcode == OpCodes.Mul) + { + yield return instruction; + yield return new CodeInstruction(OpCodes.Call, m_MyExtraMethod); + + continue; + } + yield return instruction; } } } diff --git a/DifficultyMod/Core/DifficultySettings.cs b/DifficultyMod/Core/DifficultySettings.cs index 0440f46..7e1ad0b 100644 --- a/DifficultyMod/Core/DifficultySettings.cs +++ b/DifficultyMod/Core/DifficultySettings.cs @@ -8,7 +8,9 @@ public static class DifficultySettings private const string MELON_PREF_NAME = "DemeoDifficultyMod"; private const string MELON_PREF_ENEMY_HP_MULTIPLIER_NAME = "EnemyHpMultiplier"; private const string MELON_PREF_ENEMY_ATTACK_MULTIPLIER_NAME = "EnemyAttackMultiplier"; - private const string MELON_PREF_ENERGY_GAIN_MULTIPLIER_NAME = "EnergyGainMultiplier"; + private const string MELON_PREF_ENERGY_GAIN_MULTIPLIER_NAME = "EnergyGainMultiplier"; // Trash Card + private const string MELON_PREF_ATTACK_ENERGY_GAIN_MULTIPLIER_NAME = "AttackEnergyGainMultiplier"; + private const string MELON_PREF_KILL_ENERGY_GAIN_MULTIPLIER_NAME = "KillEnergyGainMultiplier"; private const string MELON_PREF_GOLD_PILE_GAIN_MULTIPLIER_NAME = "GoldGainMultiplier"; private const string MELON_PREF_CARD_SALE_MULTIPLIER_NAME = "CardSaleMultiplier"; private const string MELON_PREF_CARD_COST_MULTIPLIER_NAME = "CardCostMultiplier"; @@ -21,7 +23,7 @@ public static class DifficultySettings private const float ENEMY_HP_MULTIPLIER_MAX = 5f; private const float ENEMY_ATTACK_MULTIPLIER_MIN = 0.25f; private const float ENEMY_ATTACK_MULTIPLIER_MAX = 5f; - private const float ENERGY_GAIN_MULTIPLIER_MIN = 0.1f; + private const float ENERGY_GAIN_MULTIPLIER_MIN = 0f; private const float ENERGY_GAIN_MULTIPLIER_MAX = 5f; private const float GOLD_PILE_GAIN_MULTIPLIER_MIN = 0.1f; private const float GOLD_PILE_GAIN_MULTIPLIER_MAX = 5f; @@ -39,7 +41,9 @@ public static void RegisterSettings() MelonPreferences.CreateCategory(MELON_PREF_NAME, "Demeo Difficulty Settings"); MelonPreferences.CreateEntry(MELON_PREF_NAME, MELON_PREF_ENEMY_HP_MULTIPLIER_NAME, 1f, "Enemy HP"); MelonPreferences.CreateEntry(MELON_PREF_NAME, MELON_PREF_ENEMY_ATTACK_MULTIPLIER_NAME, 1f, "Enemy Attack"); - MelonPreferences.CreateEntry(MELON_PREF_NAME, MELON_PREF_ENERGY_GAIN_MULTIPLIER_NAME, 1f, "Energy Gain"); + MelonPreferences.CreateEntry(MELON_PREF_NAME, MELON_PREF_ENERGY_GAIN_MULTIPLIER_NAME, 1f, "Trash Card Energy Gain"); + MelonPreferences.CreateEntry(MELON_PREF_NAME, MELON_PREF_ATTACK_ENERGY_GAIN_MULTIPLIER_NAME, 1f, "Attack Enemy Energy Gain"); + MelonPreferences.CreateEntry(MELON_PREF_NAME, MELON_PREF_KILL_ENERGY_GAIN_MULTIPLIER_NAME, 1f, "Kill Enemy Energy Gain"); MelonPreferences.CreateEntry(MELON_PREF_NAME, MELON_PREF_GOLD_PILE_GAIN_MULTIPLIER_NAME, 1f, "Gold Gained From Gold Pile"); MelonPreferences.CreateEntry(MELON_PREF_NAME, MELON_PREF_CARD_SALE_MULTIPLIER_NAME, 1f, "Gold Gained From Selling Cards"); MelonPreferences.CreateEntry(MELON_PREF_NAME, MELON_PREF_CARD_COST_MULTIPLIER_NAME, 1f, "Gold Cost When Buying Cards"); @@ -111,6 +115,32 @@ public static float EnergyGainMultiplier } + public static float AttackEnergyGainMultiplier + { + get + { + return MelonPreferences.GetEntryValue(MELON_PREF_NAME, MELON_PREF_ATTACK_ENERGY_GAIN_MULTIPLIER_NAME); + } + set + { + MelonPreferences.SetEntryValue(MELON_PREF_NAME, MELON_PREF_ATTACK_ENERGY_GAIN_MULTIPLIER_NAME, value); + } + + } + + public static float KillEnergyGainMultiplier + { + get + { + return MelonPreferences.GetEntryValue(MELON_PREF_NAME, MELON_PREF_KILL_ENERGY_GAIN_MULTIPLIER_NAME); + } + set + { + MelonPreferences.SetEntryValue(MELON_PREF_NAME, MELON_PREF_KILL_ENERGY_GAIN_MULTIPLIER_NAME, value); + } + + } + public static float GoldPileGainMultiplier { get @@ -275,6 +305,46 @@ public static void IncreaseEnergyGainMultiplier(Action callBack) callBack(EnergyGainMultiplier); } + public static void DecreaseAttackEnergyGainMultiplier(Action callBack) + { + if (AttackEnergyGainMultiplier > ENERGY_GAIN_MULTIPLIER_MIN) + { + AttackEnergyGainMultiplier = (float)Math.Round(AttackEnergyGainMultiplier - 0.1f, 2); + } + + callBack(AttackEnergyGainMultiplier); + } + + public static void IncreaseAttackEnergyGainMultiplier(Action callBack) + { + if (AttackEnergyGainMultiplier < ENERGY_GAIN_MULTIPLIER_MAX) + { + AttackEnergyGainMultiplier = (float)Math.Round(AttackEnergyGainMultiplier + 0.1f, 2); + } + + callBack(AttackEnergyGainMultiplier); + } + + public static void DecreaseKillEnergyGainMultiplier(Action callBack) + { + if (KillEnergyGainMultiplier > ENERGY_GAIN_MULTIPLIER_MIN) + { + KillEnergyGainMultiplier = (float)Math.Round(KillEnergyGainMultiplier - 0.1f, 2); + } + + callBack(KillEnergyGainMultiplier); + } + + public static void IncreaseKillEnergyGainMultiplier(Action callBack) + { + if (KillEnergyGainMultiplier < ENERGY_GAIN_MULTIPLIER_MAX) + { + KillEnergyGainMultiplier = (float)Math.Round(KillEnergyGainMultiplier + 0.1f, 2); + } + + callBack(KillEnergyGainMultiplier); + } + public static void DecreaseGoldPileGainMultiplier(Action callBack) { if (GoldPileGainMultiplier > GOLD_PILE_GAIN_MULTIPLIER_MIN) diff --git a/DifficultyMod/UI/DifficultyMenu.cs b/DifficultyMod/UI/DifficultyMenu.cs index c7d5e16..d2ea439 100644 --- a/DifficultyMod/UI/DifficultyMenu.cs +++ b/DifficultyMod/UI/DifficultyMenu.cs @@ -118,7 +118,7 @@ public void Initialize() CreateButton(pageTwoNavigationButtons.transform, new Vector3(1.6f, 0.15f, -5.6f), "Next Page", "DreadArrowUp", () => { ChangePage((currentPage + 1) % TOTAL_PAGES); }, new Vector3(0.7f, 0.7f, 0.7f)); #endregion Second_Page - #region Third_Page + #region Third_Page (Gold and Shop) difficultySettingsPageThree = CreateContainer(transform, "Difficulty Settings 3"); difficultySettingsPageThree.SetActive(false); @@ -153,16 +153,31 @@ public void Initialize() CreateButton(pageThreeNavigationButtons.transform, new Vector3(1.6f, 0.15f, -5.6f), "Next Page", "DreadArrowUp", () => { ChangePage((currentPage + 1) % TOTAL_PAGES); }, new Vector3(0.7f, 0.7f, 0.7f)); #endregion Third_Page - #region Fourth_Page + #region Fourth_Page (Energy) difficultySettingsPageFour = CreateContainer(transform, "Difficulty Settings 3"); difficultySettingsPageFour.SetActive(false); // Header CreateText(difficultySettingsPageFour.transform, new Vector3(0.036f, 0.15f, 2.4f), 3f, new Color(0.878f, 0.752f, 0.384f, 1), "Difficulty Menu", TextAlignmentOptions.Center, FontStyles.UpperCase); - // Energy Gain Multiplier + // Attack Energy Gain Multiplier + GameObject attackEnergyGainMultiplier = CreateContainer(difficultySettingsPageFour.transform, "Attack Energy Gain Multiplier"); + CreateText(attackEnergyGainMultiplier.transform, new Vector3(0.036f, 0.15f, 1.4f), 4.4f, new Color(0.0392f, 0.0157f, 0, 1), "Attack Energy Gain", TextAlignmentOptions.Center, FontStyles.Normal); + TextMeshPro attackEnergyGainMultiplierValue = CreateText(attackEnergyGainMultiplier.transform, new Vector3(0.036f, 0.15f, 0.4f), 7f, new Color(0.0392f, 0.0157f, 0, 1), "Attack Energy Gain Multiplier Text", floatToPercentStr(DifficultySettings.AttackEnergyGainMultiplier), TextAlignmentOptions.Center, FontStyles.Normal); + CreateButton(attackEnergyGainMultiplier.transform, new Vector3(-1.3f, 0.15f, 0.4f), "Attack Energy Gain Multiplier Down", "DreadArrowDown", () => { DifficultySettings.DecreaseAttackEnergyGainMultiplier(text => { UpdateText(attackEnergyGainMultiplierValue, text); }); }); + CreateButton(attackEnergyGainMultiplier.transform, new Vector3(1.4f, 0.15f, 0.4f), "Attack Energy Gain Multiplier Up", "DreadArrowUp", () => { DifficultySettings.IncreaseAttackEnergyGainMultiplier(text => { UpdateText(attackEnergyGainMultiplierValue, text); }); }); + + // Kill Energy Gain Multiplier + GameObject killEnergyGainMultiplier = CreateContainer(difficultySettingsPageFour.transform, "Kill Energy Gain Multiplier"); + CreateText(killEnergyGainMultiplier.transform, new Vector3(0.036f, 0.15f, -.6f), 4.4f, new Color(0.0392f, 0.0157f, 0, 1), "Kill Energy Gain", TextAlignmentOptions.Center, FontStyles.Normal); + CreateText(killEnergyGainMultiplier.transform, new Vector3(0.036f, 0.15f, -1f), 2f, new Color(0.0392f, 0.0157f, 0, 1), "(Only when non trivial enemies die)", TextAlignmentOptions.Center, FontStyles.Normal); + TextMeshPro killEnergyGainMultiplierValue = CreateText(killEnergyGainMultiplier.transform, new Vector3(0.036f, 0.15f, -1.6f), 7f, new Color(0.0392f, 0.0157f, 0, 1), "Kill Energy Gain Multiplier Text", floatToPercentStr(DifficultySettings.KillEnergyGainMultiplier), TextAlignmentOptions.Center, FontStyles.Normal); + CreateButton(killEnergyGainMultiplier.transform, new Vector3(-1.3f, 0.15f, -1.6f), "Kill Energy Gain Multiplier Down", "DreadArrowDown", () => { DifficultySettings.DecreaseKillEnergyGainMultiplier(text => { UpdateText(killEnergyGainMultiplierValue, text); }); }); + CreateButton(killEnergyGainMultiplier.transform, new Vector3(1.4f, 0.15f, -1.6f), "Kill Energy Gain Multiplier Up", "DreadArrowUp", () => { DifficultySettings.IncreaseKillEnergyGainMultiplier(text => { UpdateText(killEnergyGainMultiplierValue, text); }); }); + + // Discard Energy Gain Multiplier GameObject energyGainMultiplier = CreateContainer(difficultySettingsPageFour.transform, "Energy Gain Multiplier"); - CreateText(energyGainMultiplier.transform, new Vector3(0.036f, 0.15f, -2.6f), 4.4f, new Color(0.0392f, 0.0157f, 0, 1), "Energy Gain", TextAlignmentOptions.Center, FontStyles.Normal); + CreateText(energyGainMultiplier.transform, new Vector3(0.036f, 0.15f, -2.6f), 4.4f, new Color(0.0392f, 0.0157f, 0, 1), "Discard Energy Gain", TextAlignmentOptions.Center, FontStyles.Normal); TextMeshPro energyGainMultiplierValue = CreateText(energyGainMultiplier.transform, new Vector3(0.036f, 0.15f, -3.6f), 7f, new Color(0.0392f, 0.0157f, 0, 1), "Energy Gain Multiplier Text", floatToPercentStr(DifficultySettings.EnergyGainMultiplier), TextAlignmentOptions.Center, FontStyles.Normal); CreateButton(energyGainMultiplier.transform, new Vector3(-1.3f, 0.15f, -3.6f), "Energy Gain Multiplier Down", "DreadArrowDown", () => { DifficultySettings.DecreaseEnergyGainMultiplier(text => { UpdateText(energyGainMultiplierValue, text); }); }); CreateButton(energyGainMultiplier.transform, new Vector3(1.4f, 0.15f, -3.6f), "Energy Gain Multiplier Up", "DreadArrowUp", () => { DifficultySettings.IncreaseEnergyGainMultiplier(text => { UpdateText(energyGainMultiplierValue, text); }); }); diff --git a/README.md b/README.md index ff018fc..264ecc4 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,9 @@ Difficulty Mods is currently working in progress. This mod aims to adjust variou 1. Adjust gold gained from gold piles 1. Adjust card selling price in the shop in between levels. 1. Adjust card costs in the shops in between levels. -1. Adjust energy gained from discard, killing enemy, and attacking (might separate this into 3 separating settings, not sure) +1. Adjust energy gained from discard +1. Adjust energy gained from attacking +1. Adjust energy gained from killing high valued enemies ### Planned Features 1. Enable Coin Flip Toggle