* 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();
// Compare to colours of creatures of controller on bf
boolean hasToPay = true;
boolean gotACreature = false;
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;
} }
} }
if (!creatureSharesAColor) {
if (hasToPay || !gotACreature) {
for (Effect effect : getEffects()) { for (Effect effect : getEffects()) {
effect.setTargetPointer(new FixedTarget(card.getId())); effect.setTargetPointer(new FixedTarget(event.getTargetId()));
}
return true;
} }
} }
}
return hasToPay || !gotACreature; return false;
} }
@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,15 +140,11 @@ 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()));
effect.setTargetPointer(new FixedTarget(spell.getId()));
result = effect.apply(game, source); result = effect.apply(game, source);
} }
}
return result; return result;
} }
} }