From 3d0b72587a2990342e389db0c5b576972e9588dc Mon Sep 17 00:00:00 2001 From: The Gray Alien <103865052+TheGrayAlien@users.noreply.github.com> Date: Thu, 10 Jul 2025 17:58:32 -0400 Subject: [PATCH] Update rule Prevent effects from party electrical attacks without giving free invulnerability buff. Now includes charmed and 'hearted' pets. --- .../Rules/PartyDamageOverriddenRule.cs | 34 ++++++++++++++++--- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/HouseRules.Essentials/Rules/PartyDamageOverriddenRule.cs b/HouseRules.Essentials/Rules/PartyDamageOverriddenRule.cs index afcc509e..6c609d77 100644 --- a/HouseRules.Essentials/Rules/PartyDamageOverriddenRule.cs +++ b/HouseRules.Essentials/Rules/PartyDamageOverriddenRule.cs @@ -12,9 +12,10 @@ public sealed class PartyDamageOverriddenRule : Rule, IConfigWritable, IPatchable, IMultiplayerSafe { - public override string Description => "Some player attacks and stuns/effects won't affect other players or pets"; + public override string Description => "Electrical attacks won't affect other players, pets, or player made constructs"; private static bool _isActivated; + private static Piece? _targetPiece; public PartyDamageOverriddenRule(bool value) { @@ -33,6 +34,31 @@ private static void Patch(Harmony harmony) prefix: new HarmonyMethod( typeof(PartyDamageOverriddenRule), nameof(Damage_DealDamage_Prefix))); + + harmony.Patch( + original: AccessTools.Method(typeof(Piece), "EnableEffectState"), + postfix: new HarmonyMethod( + typeof(PartyDamageOverriddenRule), + nameof(Piece_EnableEffectState_Postfix))); + } + + private static void Piece_EnableEffectState_Postfix() + { + if (!_isActivated) + { + return; + } + + if (_targetPiece != null) + { + if (!_targetPiece.IsImmuneToStatusEffect(EffectStateType.Stunned)) + { + _targetPiece.DisableEffectState(EffectStateType.Stunned); + _targetPiece.effectSink.SubtractHealth(0); + } + } + + _targetPiece = null; } private static bool Damage_DealDamage_Prefix(Target target, Damage damage, Target attacker) @@ -51,12 +77,12 @@ private static bool Damage_DealDamage_Prefix(Target target, Damage damage, Targe Piece attackerPiece = attacker.piece; if (attackerPiece != null) { - if (attackerPiece.IsPlayer() && (targetPiece.IsPlayer() || targetPiece.IsBot()) && damage.HasTag(DamageTag.Electricity)) + if (attackerPiece.IsPlayer() && (targetPiece.IsPlayer() || targetPiece.IsBot() || targetPiece.HasEffectState(EffectStateType.ConfusedPermanentVisualOnly)) && damage.HasTag(DamageTag.Electricity)) { targetPiece.effectSink.SubtractHealth(0); - if (!targetPiece.HasEffectState(EffectStateType.Invulnerable3) && !targetPiece.HasEffectState(EffectStateType.Stunned) && !targetPiece.HasEffectState(EffectStateType.Frozen) && damage.AbilityKey == AbilityKey.Zap) + if (!targetPiece.HasEffectState(EffectStateType.Stunned)) { - targetPiece.EnableEffectState(EffectStateType.Invulnerable1); + _targetPiece = targetPiece; } return false;