* Invoke Prejudice - Some changes.

This commit is contained in:
LevelX2 2016-05-19 12:52:57 +02:00
parent 9c821f59da
commit eea532b2a5

View file

@ -28,12 +28,12 @@
package mage.sets.legends; package mage.sets.legends;
import java.util.UUID; import java.util.UUID;
import mage.ObjectColor;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.TriggeredAbilityImpl; import mage.abilities.TriggeredAbilityImpl;
import mage.abilities.costs.mana.GenericManaCost; import mage.abilities.costs.mana.GenericManaCost;
import mage.abilities.effects.Effect; import mage.abilities.effects.Effect;
import mage.abilities.effects.common.CounterUnlessPaysEffect; import mage.abilities.effects.common.CounterUnlessPaysEffect;
import mage.cards.Card;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.constants.CardType; import mage.constants.CardType;
import mage.constants.Rarity; import mage.constants.Rarity;
@ -92,54 +92,31 @@ class InvokePrejudiceTriggeredAbility extends TriggeredAbilityImpl {
@Override @Override
public boolean checkTrigger(GameEvent event, Game game) { public boolean checkTrigger(GameEvent event, Game game) {
Card card = game.getCard(event.getSourceId()); if (game.getOpponents(getControllerId()).contains(event.getPlayerId())) {
Spell spell = (Spell) game.getObject(event.getTargetId());
if (card == null || !(card.getCardType().contains(CardType.CREATURE))) { if (spell != null && spell.getCardType().contains(CardType.CREATURE)) {
return false; boolean creatureSharesAColor = false;
} ObjectColor spellColor = spell.getColor(game);
for (Permanent permanent : game.getBattlefield().getAllActivePermanents(new FilterControlledCreaturePermanent(), getControllerId(), game)) {
// Get colors of the card if (spellColor.shares(permanent.getColor(game))) {
boolean castCreatureIsWhite = card.getColor(game).isWhite(); creatureSharesAColor = true;
boolean castCreatureIsBlue = card.getColor(game).isBlue(); break;
boolean castCreatureIsBlack = card.getColor(game).isBlack(); }
boolean castCreatureIsRed = card.getColor(game).isRed(); }
boolean castCreatureIsGreen = card.getColor(game).isGreen(); if (!creatureSharesAColor) {
for (Effect effect : getEffects()) {
// Compare to colours of creatures of controller on bf effect.setTargetPointer(new FixedTarget(event.getTargetId()));
boolean hasToPay = true; }
boolean gotACreature = false; return true;
}
for (Permanent permanent : game.getBattlefield().getActivePermanents(new FilterControlledCreaturePermanent(), getControllerId(), game)) {
gotACreature = true;
if (castCreatureIsWhite && permanent.getColor(game).isWhite()) {
hasToPay = false;
}
if (castCreatureIsBlue && permanent.getColor(game).isBlue()) {
hasToPay = false;
}
if (castCreatureIsBlack && permanent.getColor(game).isBlack()) {
hasToPay = false;
}
if (castCreatureIsRed && permanent.getColor(game).isRed()) {
hasToPay = false;
}
if (castCreatureIsGreen && permanent.getColor(game).isGreen()) {
hasToPay = false;
} }
} }
return false;
if (hasToPay || !gotACreature) {
for (Effect effect : getEffects()) {
effect.setTargetPointer(new FixedTarget(card.getId()));
}
}
return hasToPay || !gotACreature;
} }
@Override @Override
public String getRule() { public String getRule() {
return "Whenever an opponent casts a creature spell that doesn't share a color with a creature you control, counter that spell unless that player pays {X}, where X is its converted mana cost."; return "Whenever an opponent casts a creature spell that doesn't share a color with a creature you control, " + super.getRule();
} }
} }
@ -163,14 +140,10 @@ class InvokePrejudiceEffect extends CounterUnlessPaysEffect {
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
boolean result = true; boolean result = true;
Spell spell = game.getStack().getSpell(getTargetPointer().getFirst(game, source)); Spell spell = game.getStack().getSpell(getTargetPointer().getFirst(game, source));
if (spell != null) { if (spell != null) {
Card card = spell.getCard(); CounterUnlessPaysEffect effect = new CounterUnlessPaysEffect(new GenericManaCost(spell.getConvertedManaCost()));
if (card != null) { effect.setTargetPointer(getTargetPointer());
CounterUnlessPaysEffect effect = new CounterUnlessPaysEffect(new GenericManaCost(card.getConvertedManaCost())); result = effect.apply(game, source);
effect.setTargetPointer(new FixedTarget(spell.getId()));
result = effect.apply(game, source);
}
} }
return result; return result;
} }