Skip to content

Commit

Permalink
Merge 02a42e3 into a75d870
Browse files Browse the repository at this point in the history
  • Loading branch information
Pokachi authored May 31, 2021
2 parents a75d870 + 02a42e3 commit 0fa8d9e
Show file tree
Hide file tree
Showing 5 changed files with 182 additions and 32 deletions.
57 changes: 54 additions & 3 deletions DifficultyMod/Core/DifficultyPatcher.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Boardgame;
using Boardgame.BoardEntities;
using Boardgame.Cards;
using Boardgame.Data;
using Boardgame.Networking;
using Boardgame.SerializableEvents;
Expand Down Expand Up @@ -30,7 +31,7 @@ public static int ModifyEnemyHPMultiplier(int defaultHP, PieceConfig pieceConfig

if (pieceConfig.HasPieceType(DataKeys.PieceType.Enemy))
{
return (int)(defaultHP * DifficultySettings.EnemyHPMultiplier);
return (int) (defaultHP * DifficultySettings.EnemyHPMultiplier);
}

return defaultHP;
Expand All @@ -47,15 +48,15 @@ public static int ModifyEnemyAttackMultiplier(int defaultAttack, PieceConfig pie

if (pieceConfig.HasPieceType(DataKeys.PieceType.Enemy))
{
return (int)(defaultAttack * DifficultySettings.EnemyAttackMultiplier);
return (int) (defaultAttack * DifficultySettings.EnemyAttackMultiplier);
}

return defaultAttack;
}

private static bool IsPrivateGame()
{
CreateGameMode gameMode = (CreateGameMode)(typeof(GameStateMachine).GetField("createGameMode", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(StateMachine));
CreateGameMode gameMode = (CreateGameMode) typeof(GameStateMachine).GetField("createGameMode", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(StateMachine);
return gameMode == CreateGameMode.Private;
}

Expand Down Expand Up @@ -137,5 +138,55 @@ static void Postfix(SerializableEventPickup __instance)
}
}
}

[HarmonyPatch(typeof(CardHandController), "GetCardSellValue")]
class CardSaleMultiplierPatcher
{
static void Postfix(ref int __result)
{
if (IsPrivateGame())
{
__result = (int) (__result * DifficultySettings.CardSaleMultiplier);
}
}
}


public static int ModifyCardCostInShop(int defaultCardCost)
{

// Do not modify the Attack if the game is public (i.e. anyone can join without room code)
if (!IsPrivateGame())
{
return defaultCardCost;
}

return (int) (defaultCardCost * DifficultySettings.CardCostMultiplier);
}

[HarmonyPatch(typeof(CardShopView), "Show", typeof(CardShopEntry[]), typeof(ICardCategoryProvider))]
class CardCosMultiplierPatcher
{
static MethodInfo m_MyExtraMethod = AccessTools.Method(typeof(DifficultyPatcher), nameof(ModifyCardCostInShop), new[] { typeof(int) });

static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
{
foreach (CodeInstruction instruction in instructions)
{
if (instruction.opcode == OpCodes.Ldfld)
{
string strOperand = instruction.operand.ToString();
if (strOperand.Contains("System.Int32 cost"))
{
yield return instruction;
yield return new CodeInstruction(OpCodes.Call, m_MyExtraMethod);

continue;
}
}
yield return instruction;
}
}
}
}
}
88 changes: 83 additions & 5 deletions DifficultyMod/Core/DifficultySettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ public static class DifficultySettings
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_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";

private const float ENEMY_HP_MULTIPLIER_MIN = 0.25f;
private const float ENEMY_HP_MULTIPLIER_MAX = 5f;
Expand All @@ -19,16 +21,23 @@ public static class DifficultySettings
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;
private const float CARD_SALE_MULTIPLIER_MIN = 0.1f;
private const float CARD_SALE_MULTIPLIER_MAX = 5f;
private const float CARD_COST_MULTIPLIER_MIN = 0.1f;
private const float CARD_COST_MULTIPLIER_MAX = 5f;

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 Multiplier");
MelonPreferences.CreateEntry(MELON_PREF_NAME, MELON_PREF_ENEMY_ATTACK_MULTIPLIER_NAME, 1f, "Enemy Attack Multiplier");
MelonPreferences.CreateEntry(MELON_PREF_NAME, MELON_PREF_ENERGY_GAIN_MULTIPLIER_NAME, 1f, "Energy Gain Multiplier");
MelonPreferences.CreateEntry(MELON_PREF_NAME, MELON_PREF_GOLD_PILE_GAIN_MULTIPLIER_NAME, 1f, "Gold Pile Gain Multiplier");
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_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");
}

#region Properties
public static float EnemyHPMultiplier
{
get
Expand Down Expand Up @@ -79,6 +88,34 @@ public static float GoldPileGainMultiplier

}

public static float CardSaleMultiplier
{
get
{
return MelonPreferences.GetEntryValue<float>(MELON_PREF_NAME, MELON_PREF_CARD_SALE_MULTIPLIER_NAME);
}
set
{
MelonPreferences.SetEntryValue(MELON_PREF_NAME, MELON_PREF_CARD_SALE_MULTIPLIER_NAME, value);
}

}

public static float CardCostMultiplier
{
get
{
return MelonPreferences.GetEntryValue<float>(MELON_PREF_NAME, MELON_PREF_CARD_COST_MULTIPLIER_NAME);
}
set
{
MelonPreferences.SetEntryValue(MELON_PREF_NAME, MELON_PREF_CARD_COST_MULTIPLIER_NAME, value);
}

}
#endregion Properties

#region Property_Modifier
public static void DecreaseEnemyHPMultiplier(Action<float> callBack)
{
if (EnemyHPMultiplier > ENEMY_HP_MULTIPLIER_MIN)
Expand Down Expand Up @@ -146,7 +183,7 @@ public static void DecreaseGoldPileGainMultiplier(Action<float> callBack)
GoldPileGainMultiplier = (float)Math.Round(GoldPileGainMultiplier - 0.1f, 2);
}

callBack(EnergyGainMultiplier);
callBack(GoldPileGainMultiplier);
}

public static void IncreaseGoldPileGainMultiplier(Action<float> callBack)
Expand All @@ -158,5 +195,46 @@ public static void IncreaseGoldPileGainMultiplier(Action<float> callBack)

callBack(GoldPileGainMultiplier);
}

public static void DecreaseCardSaleMultiplier(Action<float> callBack)
{
if (CardSaleMultiplier > CARD_SALE_MULTIPLIER_MIN)
{
CardSaleMultiplier = (float)Math.Round(CardSaleMultiplier - 0.1f, 2);
}

callBack(CardSaleMultiplier);
}

public static void IncreaseCardSaleMultiplier(Action<float> callBack)
{
if (CardSaleMultiplier < CARD_SALE_MULTIPLIER_MAX)
{
CardSaleMultiplier = (float)Math.Round(CardSaleMultiplier + 0.1f, 2);
}

callBack(CardSaleMultiplier);
}

public static void DecreaseCardCostMultiplier(Action<float> callBack)
{
if (CardCostMultiplier > CARD_COST_MULTIPLIER_MIN)
{
CardCostMultiplier = (float)Math.Round(CardCostMultiplier - 0.1f, 2);
}

callBack(CardCostMultiplier);
}

public static void IncreaseCardCostMultiplier(Action<float> callBack)
{
if (CardCostMultiplier < CARD_COST_MULTIPLIER_MAX)
{
CardCostMultiplier = (float)Math.Round(CardCostMultiplier + 0.1f, 2);
}

callBack(CardCostMultiplier);
}
#endregion Property_Modifier
}
}
2 changes: 1 addition & 1 deletion DifficultyMod/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@


// Melon Loader
[assembly: MelonInfo(typeof(DifficultyMod), "Difficulty Mod", "0.1.1", "Reena")]
[assembly: MelonInfo(typeof(DifficultyMod), "Difficulty Mod", "0.2", "Reena")]
[assembly: MelonGame("Resolution Games", "Demeo")]

// Setting ComVisible to false makes the types in this assembly not visible
Expand Down
Loading

0 comments on commit 0fa8d9e

Please sign in to comment.