- small Refactor

This commit is contained in:
jeffwadsworth 2020-07-14 08:20:31 -05:00
parent 335acd4375
commit 2e0be17494
2 changed files with 47 additions and 1 deletions

View file

@ -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());
}
}

View file

@ -52,7 +52,7 @@ public class GoadTargetEffect extends OneShotEffect {
ContinuousEffect effect = new AttacksIfAbleTargetEffect(Duration.UntilYourNextTurn); ContinuousEffect effect = new AttacksIfAbleTargetEffect(Duration.UntilYourNextTurn);
effect.setTargetPointer(new FixedTarget(getTargetPointer().getFirst(game, source))); effect.setTargetPointer(new FixedTarget(getTargetPointer().getFirst(game, source)));
game.addEffect(effect, 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))); effect.setTargetPointer(new FixedTarget(getTargetPointer().getFirst(game, source)));
game.addEffect(effect, source); game.addEffect(effect, source);
game.informPlayers(controller.getLogName() + " is goading " + targetCreature.getLogName()); game.informPlayers(controller.getLogName() + " is goading " + targetCreature.getLogName());