Skip to content
Open
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
56 changes: 56 additions & 0 deletions HouseRules.Essentials/AbilityTargetEffectsOverriddenRule.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
namespace HouseRules.Essentials.Rules
{
using System.Collections.Generic;
using System.Linq;
using DataKeys;
using HouseRules.Core.Types;

public sealed class AbilityTargetEffectsOverriddenRule : Rule, IConfigWritable<Dictionary<AbilityKey, List<EffectStateType>>>, IMultiplayerSafe
{
public override string Description => "Some abilities have added secondary effects.";

private readonly Dictionary<AbilityKey, List<EffectStateType>> _adjustments;
private Dictionary<AbilityKey, List<EffectStateType>> _originals;

/// <summary>
/// Initializes a new instance of the <see cref="AbilityTargetEffectsOverriddenRule"/> class.
/// </summary>
/// <param name="adjustments">Key-value pairs of abilityKey and List<EffectStateType>.</param>
public AbilityTargetEffectsOverriddenRule(Dictionary<AbilityKey, List<EffectStateType>> adjustments)
{
_adjustments = adjustments;
_originals = new Dictionary<AbilityKey, List<EffectStateType>>();
}

public Dictionary<AbilityKey, List<EffectStateType>> GetConfigObject() => _adjustments;

protected override void OnPreGameCreated(Context context)
{
_originals = ReplaceAbilities(context, _adjustments);
}

protected override void OnDeactivate(Context context)
{
ReplaceAbilities(context, _originals);
}

private static Dictionary<AbilityKey, List<EffectStateType>> ReplaceAbilities(Context context, Dictionary<AbilityKey, List<EffectStateType>> replacements)
{
var originals = new Dictionary<AbilityKey, List<EffectStateType>>();
foreach (var replacement in replacements)
{
var abilityPromise = context.AbilityFactory.LoadAbility(replacement.Key);
abilityPromise.OnLoaded(ability =>
{
originals[replacement.Key] = ability.targetEffects.ToList();
ability.targetEffects = replacement.Value.ToArray();
});
}

// Theoretically, there can be a race condition as there's no guarantee the promise above is fulfilled by
// the return value is used. Realistically, there's no concern since the value isn't used until after the
// promise has long been fulfilled.
return originals;
}
}
}
1 change: 1 addition & 0 deletions HouseRules.Essentials/HouseRulesEssentialsBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ private static void RegisterRuleTypes()
HR.Rulebook.Register(typeof(AbilityActionCostAdjustedRule));
HR.Rulebook.Register(typeof(AbilityRandomPieceListRule));
HR.Rulebook.Register(typeof(AbilityStealthDamageOverriddenRule));
HR.Rulebook.Register(typeof(AbilityTargetEffectsOverriddenRule));
HR.Rulebook.Register(typeof(ApplyEffectOnHitAdjustedRule));
HR.Rulebook.Register(typeof(BackstabConfigOverriddenRule));
HR.Rulebook.Register(typeof(CourageShantyAddsHpRule));
Expand Down
17 changes: 17 additions & 0 deletions HouseRules.Essentials/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,23 @@ The [Settings Reference](../docs/SettingsReference.md) contains lists of all dif
},
```

#### __AbilityTargetEffectsAdjusted__: Replaces the list of addition effects to the selected abilities
- REPLACES the list of addition effects for the selected abilities. You may manually include the original effect if desired.
- To configure:
- Specify the [AbilityKey](../docs/SettingsReference.md#abilitykeys) of the ability to modify.
- Specify the list of [EffectStates](../docs/SettingsReference.md#effectstatetypes) that the ability should apply.

###### _Example JSON config for AbilityTargetEffectsAdjusted_

```json
{
"Rule": "AbilityTargetEffectsAdjusted",
"Config": {
"Javelin": [ "Weaken1Turn" ],
"WarCry": [ "Panic", "Blinded" ]
}
```

#### __ApplyEffectOnHitAdjusted__: Adjusts the effect that a ♟️BoardPiece has on attackers.
- For example, you can make Barricades inspire Panic on enemies that hit it.
- To be useful the effect has to last at least 2 rounds.
Expand Down