* War's Toll - Fixed the implementation of the restriction effect.

This commit is contained in:
LevelX2 2020-01-06 23:16:10 +01:00
parent 79f5d7a358
commit b2a8d4293a
4 changed files with 44 additions and 37 deletions

View file

@ -2,21 +2,23 @@ package mage.cards.w;
import java.util.UUID;
import mage.abilities.Ability;
import mage.abilities.common.AttacksAllTriggeredAbility;
import mage.abilities.common.SimpleEvasionAbility;
import mage.abilities.common.TapForManaAllTriggeredAbility;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.RestrictionEffect;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.Duration;
import mage.constants.Outcome;
import mage.constants.SetTargetPointer;
import mage.constants.TargetController;
import mage.filter.StaticFilters;
import mage.filter.common.FilterCreaturePermanent;
import mage.filter.common.FilterLandPermanent;
import mage.filter.predicate.permanent.ControllerIdPredicate;
import mage.filter.predicate.permanent.ControllerPredicate;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.players.Player;
/**
@ -40,7 +42,7 @@ public final class WarsToll extends CardImpl {
this.addAbility(new TapForManaAllTriggeredAbility(new WarsTollTapEffect(), filterOpponentLand, SetTargetPointer.PLAYER));
// If a creature an opponent controls attacks, all creatures that opponent controls attack if able.
this.addAbility(new AttacksAllTriggeredAbility(new WarsTollEffect(), false, filterOpponentCreature, SetTargetPointer.PERMANENT, true));
this.addAbility(new SimpleEvasionAbility(new WarsTollAttackRestrictionEffect()));
}
@ -82,37 +84,37 @@ class WarsTollTapEffect extends OneShotEffect {
}
}
class WarsTollEffect extends OneShotEffect {
class WarsTollAttackRestrictionEffect extends RestrictionEffect {
private static final FilterCreaturePermanent filterOpponentCreatures = new FilterCreaturePermanent();
public WarsTollEffect() {
super(Outcome.Neutral);
staticText = "all creatures that opponent controls attack if able";
public WarsTollAttackRestrictionEffect() {
super(Duration.WhileOnBattlefield);
staticText = "If a creature an opponent controls attacks, all creatures that opponent controls attack if able";
}
public WarsTollEffect(final WarsTollEffect effect) {
public WarsTollAttackRestrictionEffect(final WarsTollAttackRestrictionEffect effect) {
super(effect);
}
@Override
public boolean apply(Game game, Ability source) {
Player opponent = game.getPlayer(game.getPermanent(getTargetPointer().getFirst(game, source)).getControllerId());
if (opponent != null) {
filterOpponentCreatures.add(new ControllerIdPredicate(opponent.getId()));
game.getBattlefield().getAllActivePermanents(CardType.CREATURE).stream().filter((permanent) -> (filterOpponentCreatures.match(permanent, source.getSourceId(), source.getControllerId(), game))).forEachOrdered((permanent) -> {
//TODO: allow the player to choose between a planeswalker and player
if (permanent.canAttack(source.getControllerId(), game)) {
opponent.declareAttacker(permanent.getId(), source.getControllerId(), game, false);
}
});
return true;
}
return false;
public boolean applies(Permanent permanent, Ability source, Game game) {
Player controller = game.getPlayer(permanent.getControllerId());
return controller != null && controller.hasOpponent(source.getControllerId(), game);
}
@Override
public WarsTollEffect copy() {
return new WarsTollEffect(this);
public boolean canAttackCheckAfter(int numberOfAttackers, Ability source, Game game, boolean canUseChooseDialogs) {
int creaturesAbleToAttack = 0;
for (Permanent creaturePermanent : game.getBattlefield().getAllActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURES, game.getActivePlayerId(), game)) {
if (creaturePermanent.canAttackInPrinciple(null, game)) {
creaturesAbleToAttack++;
}
}
return numberOfAttackers == 0 || numberOfAttackers == creaturesAbleToAttack;
}
@Override
public WarsTollAttackRestrictionEffect copy() {
return new WarsTollAttackRestrictionEffect(this);
}
}

View file

@ -1,5 +1,3 @@
package mage.abilities;
import mage.constants.AbilityType;
@ -12,7 +10,11 @@ import mage.constants.Zone;
public abstract class EvasionAbility extends StaticAbility {
public EvasionAbility() {
super(AbilityType.EVASION, Zone.ALL);
this(Zone.ALL);
}
public EvasionAbility(Zone zone) {
super(AbilityType.EVASION, zone);
}
public EvasionAbility(final EvasionAbility ability) {

View file

@ -1,11 +1,8 @@
package mage.abilities.common;
import mage.abilities.EvasionAbility;
import mage.abilities.effects.Effect;
import mage.constants.Zone;
/**
*
@ -14,7 +11,11 @@ import mage.abilities.effects.Effect;
public class SimpleEvasionAbility extends EvasionAbility {
public SimpleEvasionAbility(Effect effect) {
super();
this(effect, Zone.ALL);
}
public SimpleEvasionAbility(Effect effect, Zone zone) {
super(zone);
if (effect != null) {
this.addEffect(effect);
}

View file

@ -1,5 +1,6 @@
package mage.abilities.effects;
import java.util.UUID;
import mage.abilities.Ability;
import mage.constants.Duration;
import mage.constants.EffectType;
@ -7,8 +8,6 @@ import mage.constants.Outcome;
import mage.game.Game;
import mage.game.permanent.Permanent;
import java.util.UUID;
/**
* @author BetaSteward_at_googlemail.com
*/
@ -36,16 +35,17 @@ public abstract class RestrictionEffect extends ContinuousEffectImpl {
// canUseChooseDialogs -- restrict checks can be called by rules engine and by card info engine,
// last one uses for info only and can't use dialogs, e.g. canUseChooseDialogs = false
public boolean canAttack(Game game, boolean canUseChooseDialogs) {
return true;
}
/**
* @param attacker
* @param defenderId id of planeswalker or player to attack, can be empty for general checks
* @param defenderId id of planeswalker or player to attack, can be empty
* for general checks
* @param source
* @param game
* @param canUseChooseDialogs
* @return
*/
public boolean canAttack(Permanent attacker, UUID defenderId, Ability source, Game game, boolean canUseChooseDialogs) {
@ -61,6 +61,7 @@ public abstract class RestrictionEffect extends ContinuousEffectImpl {
* @param blocker
* @param source
* @param game
* @param canUseChooseDialogs
* @return
*/
public boolean canBlock(Permanent attacker, Permanent blocker, Ability source, Game game, boolean canUseChooseDialogs) {
@ -81,6 +82,7 @@ public abstract class RestrictionEffect extends ContinuousEffectImpl {
* @param attacker
* @param source
* @param game
* @param canUseChooseDialogs
* @return true = block is ok false = block is not valid (human: back to
* defining blockers, AI: remove blocker)
*/