From 2e0be174942b5975dd60931cfc391202a512eb5b Mon Sep 17 00:00:00 2001 From: jeffwadsworth Date: Tue, 14 Jul 2020 08:20:31 -0500 Subject: [PATCH] - small Refactor --- .../CantAttackControllerDueToGoadEffect.java | 46 +++++++++++++++++++ .../common/combat/GoadTargetEffect.java | 2 +- 2 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 Mage/src/main/java/mage/abilities/effects/common/combat/CantAttackControllerDueToGoadEffect.java diff --git a/Mage/src/main/java/mage/abilities/effects/common/combat/CantAttackControllerDueToGoadEffect.java b/Mage/src/main/java/mage/abilities/effects/common/combat/CantAttackControllerDueToGoadEffect.java new file mode 100644 index 0000000000..964bcf9a59 --- /dev/null +++ b/Mage/src/main/java/mage/abilities/effects/common/combat/CantAttackControllerDueToGoadEffect.java @@ -0,0 +1,46 @@ +package mage.abilities.effects.common.combat; + +import java.util.UUID; +import mage.abilities.Ability; +import mage.abilities.effects.RestrictionEffect; +import mage.constants.Duration; +import mage.game.Game; +import mage.game.permanent.Permanent; + +/** + * @author TheElk801 + */ +public class CantAttackControllerDueToGoadEffect extends RestrictionEffect { + + public CantAttackControllerDueToGoadEffect(Duration duration) { + super(duration); + } + + public CantAttackControllerDueToGoadEffect(final CantAttackControllerDueToGoadEffect effect) { + super(effect); + } + + @Override + public CantAttackControllerDueToGoadEffect copy() { + return new CantAttackControllerDueToGoadEffect(this); + } + + @Override + public boolean applies(Permanent permanent, Ability source, Game game) { + return this.getTargetPointer().getTargets(game, source).contains(permanent.getId()); + } + + @Override + public boolean canAttack(Permanent attacker, UUID defenderId, Ability source, Game game, boolean canUseChooseDialogs) { + if (defenderId == null + || game.getState().getPlayersInRange(attacker.getControllerId(), game).size() == 2) { // just 2 players left, so it may attack you + return true; + } + // A planeswalker controlled by the controller is the defender + if (game.getPermanent(defenderId) != null) { + return !game.getPermanent(defenderId).getControllerId().equals(source.getControllerId()); + } + // The controller is the defender + return !defenderId.equals(source.getControllerId()); + } +} diff --git a/Mage/src/main/java/mage/abilities/effects/common/combat/GoadTargetEffect.java b/Mage/src/main/java/mage/abilities/effects/common/combat/GoadTargetEffect.java index ffb6e25cbe..578536f1d7 100644 --- a/Mage/src/main/java/mage/abilities/effects/common/combat/GoadTargetEffect.java +++ b/Mage/src/main/java/mage/abilities/effects/common/combat/GoadTargetEffect.java @@ -52,7 +52,7 @@ public class GoadTargetEffect extends OneShotEffect { ContinuousEffect effect = new AttacksIfAbleTargetEffect(Duration.UntilYourNextTurn); effect.setTargetPointer(new FixedTarget(getTargetPointer().getFirst(game, source))); game.addEffect(effect, source); - effect = new CantAttackYouEffect(Duration.UntilYourNextTurn); // remember current controller + effect = new CantAttackControllerDueToGoadEffect(Duration.UntilYourNextTurn); // remember current controller effect.setTargetPointer(new FixedTarget(getTargetPointer().getFirst(game, source))); game.addEffect(effect, source); game.informPlayers(controller.getLogName() + " is goading " + targetCreature.getLogName());