Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add rule for multiplying gold picked up. #39

Merged
merged 2 commits into from
Jan 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Rules/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ RulesAPI.
- **AbilityDamageAdjustedRule**: Ability damage is adjusted
- **ActionPointsAdjustedRule**: Action points are adjusted
- **EnemyRespawnDisabledRule**: Enemy respawns are disabled
- **GoldPickedUpMultipliedRule**: Gold picked up is multiplied
- **PieceConfigAdjustedRule**: Piece configuration is adjusted
- See [PieceConfig.md](../docs/PieceConfig.md) for information about modifiable fields.
- **RatNestsSpawnGoldRule**: Rat nests spawn gold
Expand Down
42 changes: 42 additions & 0 deletions Rules/Rule/GoldPickedUpMultipliedRule.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
namespace Rules.Rule
{
using Boardgame.Data;
using Boardgame.SerializableEvents;
using HarmonyLib;

public sealed class GoldPickedUpMultipliedRule : RulesAPI.Rule
{
public override string Description => "Gold picked up is multiplied";

private static double _multiplier;
private static bool _isActivated;

public GoldPickedUpMultipliedRule(double multiplier)
{
_multiplier = multiplier;
}

protected override void OnActivate() => _isActivated = true;

protected override void OnDeactivate() => _isActivated = false;

private static void OnPatch(Harmony harmony)
{
harmony.Patch(
original: AccessTools.Constructor(
typeof(SerializableEventPickup),
new[] { typeof(int), typeof(IntPoint2D), typeof(bool) }),
postfix: new HarmonyMethod(typeof(GoldPickedUpMultipliedRule), nameof(SerializableEventPickup_Constructor_Postfix)));
}

private static void SerializableEventPickup_Constructor_Postfix(ref SerializableEventPickup __instance)
{
if (!_isActivated)
{
return;
}

__instance.goldAmount = (int)(__instance.goldAmount * _multiplier);
}
}
}
1 change: 1 addition & 0 deletions Rules/Rules.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
<Compile Include="Rule\AbilityDamageAdjustedRule.cs" />
<Compile Include="Rule\ActionPointsAdjustedRule.cs" />
<Compile Include="Rule\EnemyRespawnDisabledRule.cs" />
<Compile Include="Rule\GoldPickedUpMultipliedRule.cs" />
<Compile Include="Rule\RatNestsSpawnGoldRule.cs" />
<Compile Include="Rule\SampleRule.cs" />
<Compile Include="Rule\PieceConfigAdjustedRule.cs" />
Expand Down
1 change: 1 addition & 0 deletions Rules/RulesMod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ private static void RegisterNewRuleTypes()
registrar.Register(typeof(Rule.AbilityDamageAdjustedRule));
registrar.Register(typeof(Rule.ActionPointsAdjustedRule));
registrar.Register(typeof(Rule.EnemyRespawnDisabledRule));
registrar.Register(typeof(Rule.GoldPickedUpMultipliedRule));
registrar.Register(typeof(Rule.PieceConfigAdjustedRule));
registrar.Register(typeof(Rule.RatNestsSpawnGoldRule));
registrar.Register(typeof(Rule.StartHealthAdjustedRule));
Expand Down