* Polis Crusher - Fixed that it can't be the target of enchantments.

* Polis Crusher - Fixed that the targeted enchantment of it's second ability was chosen too late during resolution.
This commit is contained in:
LevelX2 2014-02-27 16:42:44 +01:00
parent 5a454cfad2
commit 8fa23501ee
5 changed files with 52 additions and 56 deletions

View file

@ -33,22 +33,24 @@ import mage.abilities.Ability;
import mage.abilities.common.DealsCombatDamageToAPlayerTriggeredAbility; import mage.abilities.common.DealsCombatDamageToAPlayerTriggeredAbility;
import mage.abilities.condition.common.MonstrousCondition; import mage.abilities.condition.common.MonstrousCondition;
import mage.abilities.decorator.ConditionalTriggeredAbility; import mage.abilities.decorator.ConditionalTriggeredAbility;
import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.Effect;
import mage.abilities.effects.common.DestroyTargetEffect;
import mage.abilities.keyword.MonstrosityAbility; import mage.abilities.keyword.MonstrosityAbility;
import mage.abilities.keyword.ProtectionAbility; import mage.abilities.keyword.ProtectionAbility;
import mage.abilities.keyword.TrampleAbility; import mage.abilities.keyword.TrampleAbility;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.constants.CardType; import mage.constants.CardType;
import mage.constants.Outcome;
import mage.constants.Rarity; import mage.constants.Rarity;
import mage.filter.FilterCard;
import mage.filter.FilterPermanent; import mage.filter.FilterPermanent;
import mage.filter.common.FilterEnchantmentPermanent; import mage.filter.common.FilterEnchantmentPermanent;
import mage.filter.predicate.mageobject.CardTypePredicate;
import mage.filter.predicate.permanent.ControllerIdPredicate; import mage.filter.predicate.permanent.ControllerIdPredicate;
import mage.game.Game; import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.players.Player; import mage.players.Player;
import mage.target.Target; import mage.target.Target;
import mage.target.TargetPermanent; import mage.target.TargetPermanent;
import mage.target.targetpointer.FirstTargetPointer;
/** /**
* *
@ -56,6 +58,12 @@ import mage.target.TargetPermanent;
*/ */
public class PolisCrusher extends CardImpl<PolisCrusher> { public class PolisCrusher extends CardImpl<PolisCrusher> {
private static final FilterCard filter = new FilterCard("enchantments");
static {
filter.add(new CardTypePredicate(CardType.ENCHANTMENT));
}
public PolisCrusher(UUID ownerId) { public PolisCrusher(UUID ownerId) {
super(ownerId, 198, "Polis Crusher", Rarity.RARE, new CardType[]{CardType.CREATURE}, "{2}{R}{G}"); super(ownerId, 198, "Polis Crusher", Rarity.RARE, new CardType[]{CardType.CREATURE}, "{2}{R}{G}");
this.expansionSetCode = "THS"; this.expansionSetCode = "THS";
@ -69,12 +77,12 @@ public class PolisCrusher extends CardImpl<PolisCrusher> {
// Trample // Trample
this.addAbility(TrampleAbility.getInstance()); this.addAbility(TrampleAbility.getInstance());
// protection from enchantments // protection from enchantments
this.addAbility(new ProtectionAbility(new FilterEnchantmentPermanent())); this.addAbility(new ProtectionAbility(filter));
// {4}{R}{G}: Monstrosity 3. // {4}{R}{G}: Monstrosity 3.
this.addAbility(new MonstrosityAbility("{4}{R}{G}", 3)); this.addAbility(new MonstrosityAbility("{4}{R}{G}", 3));
// Whenever Polis Crusher deals combat damage to a player, if Polis Crusher is monstrous, destroy target enchantment that player controls. // Whenever Polis Crusher deals combat damage to a player, if Polis Crusher is monstrous, destroy target enchantment that player controls.
Ability ability = new ConditionalTriggeredAbility( Ability ability = new ConditionalTriggeredAbility(
new DealsCombatDamageToAPlayerTriggeredAbility(new PolisCrusherDestroyEffect(), false, true), new DealsCombatDamageToAPlayerTriggeredAbility(new DestroyTargetEffect(), false, true),
MonstrousCondition.getInstance(), MonstrousCondition.getInstance(),
"Whenever {this} deals combat damage to a player, if {this} is monstrous, destroy target enchantment that player controls."); "Whenever {this} deals combat damage to a player, if {this} is monstrous, destroy target enchantment that player controls.");
this.addAbility(ability); this.addAbility(ability);
@ -84,45 +92,29 @@ public class PolisCrusher extends CardImpl<PolisCrusher> {
super(card); super(card);
} }
@Override
public void adjustTargets(Ability ability, Game game) {
if (ability instanceof ConditionalTriggeredAbility) {
for (Effect effect : ability.getEffects()) {
if (effect instanceof DestroyTargetEffect) {
Player attackedPlayer = game.getPlayer(effect.getTargetPointer().getFirst(game, ability));
if (attackedPlayer != null) {
ability.getTargets().clear();
FilterPermanent filterEnchantment = new FilterEnchantmentPermanent("enchantment attacked player controls");
filter.add(new ControllerIdPredicate(attackedPlayer.getId()));
Target target = new TargetPermanent(filterEnchantment);
target.setRequired(true);
ability.addTarget(target);
effect.setTargetPointer(new FirstTargetPointer());
break;
}
}
}
}
}
@Override @Override
public PolisCrusher copy() { public PolisCrusher copy() {
return new PolisCrusher(this); return new PolisCrusher(this);
} }
} }
class PolisCrusherDestroyEffect extends OneShotEffect<PolisCrusherDestroyEffect> {
public PolisCrusherDestroyEffect() {
super(Outcome.DestroyPermanent);
this.staticText = "destroy target enchantment that player controls";
}
public PolisCrusherDestroyEffect(final PolisCrusherDestroyEffect effect) {
super(effect);
}
@Override
public PolisCrusherDestroyEffect copy() {
return new PolisCrusherDestroyEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
Player attackedPlayer = game.getPlayer(this.getTargetPointer().getFirst(game, source));
Player controller = game.getPlayer(source.getControllerId());
if (controller != null && attackedPlayer != null) {
FilterPermanent filter = new FilterEnchantmentPermanent("enchantment attacked player controls");
filter.add(new ControllerIdPredicate(attackedPlayer.getId()));
Target target = new TargetPermanent(filter);
target.setRequired(true);
if (target.canChoose(source.getSourceId(), source.getControllerId(), game)
&& controller.chooseTarget(outcome, target, source, game)) {
Permanent enchantment = game.getPermanent(target.getFirstTarget());
if (enchantment != null) {
return enchantment.destroy(source.getSourceId(), game, false);
}
}
}
return false;
}
}

View file

@ -3,6 +3,7 @@ package mage.abilities.decorator;
import mage.abilities.TriggeredAbility; import mage.abilities.TriggeredAbility;
import mage.abilities.TriggeredAbilityImpl; import mage.abilities.TriggeredAbilityImpl;
import mage.abilities.condition.Condition; import mage.abilities.condition.Condition;
import mage.abilities.effects.Effects;
import mage.game.Game; import mage.game.Game;
import mage.game.events.GameEvent; import mage.game.events.GameEvent;
@ -51,10 +52,7 @@ public class ConditionalTriggeredAbility extends TriggeredAbilityImpl<Conditiona
public boolean checkTrigger(GameEvent event, Game game) { public boolean checkTrigger(GameEvent event, Game game) {
ability.setSourceId(this.getSourceId()); ability.setSourceId(this.getSourceId());
ability.setControllerId(this.getControllerId()); ability.setControllerId(this.getControllerId());
if (ability.checkTrigger(event, game)) { return ability.checkTrigger(event, game);
return true;
}
return false;
} }
@Override @Override
@ -64,4 +62,10 @@ public class ConditionalTriggeredAbility extends TriggeredAbilityImpl<Conditiona
} }
return text; return text;
} }
@Override
public Effects getEffects() {
return ability.getEffects();
}
} }

View file

@ -121,7 +121,7 @@ public class GainAbilityTargetEffect extends ContinuousEffectImpl<GainAbilityTar
} }
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
Target target = mode.getTargets().get(0); Target target = mode.getTargets().get(0);
if(target.getNumberOfTargets() > 1){ if(target.getMaxNumberOfTargets() > 1){
if (target.getNumberOfTargets() < target.getMaxNumberOfTargets()) { if (target.getNumberOfTargets() < target.getMaxNumberOfTargets()) {
sb.append("Up to"); sb.append("Up to");
} }

View file

@ -39,12 +39,12 @@ import mage.cards.Card;
import mage.constants.CardType; import mage.constants.CardType;
import mage.constants.Duration; import mage.constants.Duration;
import mage.constants.Layer; import mage.constants.Layer;
import static mage.constants.Layer.TypeChangingEffects_4;
import mage.constants.Outcome; import mage.constants.Outcome;
import mage.constants.SubLayer; import mage.constants.SubLayer;
import mage.constants.Zone; import mage.constants.Zone;
import mage.game.Game; import mage.game.Game;
import mage.game.permanent.Permanent; import mage.game.permanent.Permanent;
import mage.game.stack.Spell;
import mage.target.TargetPermanent; import mage.target.TargetPermanent;
import mage.target.common.TargetCreaturePermanent; import mage.target.common.TargetCreaturePermanent;

View file

@ -97,8 +97,8 @@ public abstract class PermanentImpl<T extends PermanentImpl<T>> extends CardImpl
protected int maxBlockedBy = 0; protected int maxBlockedBy = 0;
protected boolean loyaltyUsed; protected boolean loyaltyUsed;
protected boolean deathtouched; protected boolean deathtouched;
protected List<UUID> attachments = new ArrayList<UUID>(); protected List<UUID> attachments = new ArrayList<>();
protected Map<String, List<UUID>> connectedCards = new HashMap<String, List<UUID>>(); protected Map<String, List<UUID>> connectedCards = new HashMap<>();
protected List<UUID> dealtDamageByThisTurn; protected List<UUID> dealtDamageByThisTurn;
protected UUID attachedTo; protected UUID attachedTo;
protected UUID pairedCard; protected UUID pairedCard;
@ -139,9 +139,9 @@ public abstract class PermanentImpl<T extends PermanentImpl<T>> extends CardImpl
this.connectedCards.put(entry.getKey(), entry.getValue()); this.connectedCards.put(entry.getKey(), entry.getValue());
} }
if (permanent.dealtDamageByThisTurn != null) { if (permanent.dealtDamageByThisTurn != null) {
dealtDamageByThisTurn = new ArrayList<UUID>(permanent.dealtDamageByThisTurn); dealtDamageByThisTurn = new ArrayList<>(permanent.dealtDamageByThisTurn);
if (permanent.markedDamage != null) { if (permanent.markedDamage != null) {
markedDamage = new ArrayList<Counter>(); markedDamage = new ArrayList<>();
for (Counter counter : permanent.markedDamage) { for (Counter counter : permanent.markedDamage) {
markedDamage.add(counter.copy()); markedDamage.add(counter.copy());
} }
@ -552,7 +552,7 @@ public abstract class PermanentImpl<T extends PermanentImpl<T>> extends CardImpl
if (this.connectedCards.containsKey(key)) { if (this.connectedCards.containsKey(key)) {
this.connectedCards.get(key).add(connectedCard); this.connectedCards.get(key).add(connectedCard);
} else { } else {
List<UUID> list = new ArrayList<UUID>(); List<UUID> list = new ArrayList<>();
list.add(connectedCard); list.add(connectedCard);
this.connectedCards.put(key, list); this.connectedCards.put(key, list);
} }
@ -643,7 +643,7 @@ public abstract class PermanentImpl<T extends PermanentImpl<T>> extends CardImpl
deathtouched = true; deathtouched = true;
} }
if (dealtDamageByThisTurn == null) { if (dealtDamageByThisTurn == null) {
dealtDamageByThisTurn = new ArrayList<UUID>(); dealtDamageByThisTurn = new ArrayList<>();
} }
dealtDamageByThisTurn.add(sourceId); dealtDamageByThisTurn.add(sourceId);
} }
@ -736,7 +736,7 @@ public abstract class PermanentImpl<T extends PermanentImpl<T>> extends CardImpl
private void markDamage(Counter counter) { private void markDamage(Counter counter) {
if (markedDamage == null) { if (markedDamage == null) {
markedDamage = new ArrayList<Counter>(); markedDamage = new ArrayList<>();
} }
markedDamage.add(counter); markedDamage.add(counter);
} }
@ -1001,7 +1001,7 @@ public abstract class PermanentImpl<T extends PermanentImpl<T>> extends CardImpl
if (connectedCards.containsKey("imprint")) { if (connectedCards.containsKey("imprint")) {
this.connectedCards.get("imprint").add(imprintedCard); this.connectedCards.get("imprint").add(imprintedCard);
} else { } else {
List<UUID> imprinted = new ArrayList<UUID>(); List<UUID> imprinted = new ArrayList<>();
imprinted.add(imprintedCard); imprinted.add(imprintedCard);
this.connectedCards.put("imprint", imprinted); this.connectedCards.put("imprint", imprinted);
} }