Skip to content

Commit

Permalink
Merge pull request #5 from Pokachi/development
Browse files Browse the repository at this point in the history
split energy gain multiplier to 3 settings
  • Loading branch information
Pokachi authored Jun 1, 2021
2 parents 67b42fc + 6404680 commit 8b951aa
Show file tree
Hide file tree
Showing 4 changed files with 206 additions and 12 deletions.
115 changes: 111 additions & 4 deletions DifficultyMod/Core/DifficultyPatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,121 @@ static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> 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<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> 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<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> 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<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> 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<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> 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;
}
}
}
Expand Down
76 changes: 73 additions & 3 deletions DifficultyMod/Core/DifficultySettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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;
Expand All @@ -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");
Expand Down Expand Up @@ -111,6 +115,32 @@ public static float EnergyGainMultiplier

}

public static float AttackEnergyGainMultiplier
{
get
{
return MelonPreferences.GetEntryValue<float>(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<float>(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
Expand Down Expand Up @@ -275,6 +305,46 @@ public static void IncreaseEnergyGainMultiplier(Action<float> callBack)
callBack(EnergyGainMultiplier);
}

public static void DecreaseAttackEnergyGainMultiplier(Action<float> callBack)
{
if (AttackEnergyGainMultiplier > ENERGY_GAIN_MULTIPLIER_MIN)
{
AttackEnergyGainMultiplier = (float)Math.Round(AttackEnergyGainMultiplier - 0.1f, 2);
}

callBack(AttackEnergyGainMultiplier);
}

public static void IncreaseAttackEnergyGainMultiplier(Action<float> callBack)
{
if (AttackEnergyGainMultiplier < ENERGY_GAIN_MULTIPLIER_MAX)
{
AttackEnergyGainMultiplier = (float)Math.Round(AttackEnergyGainMultiplier + 0.1f, 2);
}

callBack(AttackEnergyGainMultiplier);
}

public static void DecreaseKillEnergyGainMultiplier(Action<float> callBack)
{
if (KillEnergyGainMultiplier > ENERGY_GAIN_MULTIPLIER_MIN)
{
KillEnergyGainMultiplier = (float)Math.Round(KillEnergyGainMultiplier - 0.1f, 2);
}

callBack(KillEnergyGainMultiplier);
}

public static void IncreaseKillEnergyGainMultiplier(Action<float> callBack)
{
if (KillEnergyGainMultiplier < ENERGY_GAIN_MULTIPLIER_MAX)
{
KillEnergyGainMultiplier = (float)Math.Round(KillEnergyGainMultiplier + 0.1f, 2);
}

callBack(KillEnergyGainMultiplier);
}

public static void DecreaseGoldPileGainMultiplier(Action<float> callBack)
{
if (GoldPileGainMultiplier > GOLD_PILE_GAIN_MULTIPLIER_MIN)
Expand Down
23 changes: 19 additions & 4 deletions DifficultyMod/UI/DifficultyMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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); }); });
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8b951aa

Please sign in to comment.