From 8718a1de8ef6ba131caf5ddddc373371aca59b83 Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Mon, 4 Mar 2013 22:54:27 +0100 Subject: [PATCH] Fixed Pit Fight (issue #151) and other fight cards that both targets must be valid when the effect resolves. Fixed also that the second target must be another target than the first. --- .../sets/avacynrestored/UlvenwaldTracker.java | 29 +++++++++++++++-- .../mage/sets/darkascension/BloodFeud.java | 32 +++++++++++++++++-- .../src/mage/sets/gatecrash/DomriRade.java | 7 ++-- .../mage/sets/gatecrash/GruulRagebeast.java | 1 + .../src/mage/sets/gatecrash/PitFight.java | 32 +++++++++++++++++-- .../src/mage/sets/innistrad/PreyUpon.java | 7 ++-- .../effects/common/FightTargetsEffect.java | 27 ++++++++++------ 7 files changed, 114 insertions(+), 21 deletions(-) diff --git a/Mage.Sets/src/mage/sets/avacynrestored/UlvenwaldTracker.java b/Mage.Sets/src/mage/sets/avacynrestored/UlvenwaldTracker.java index 550a973da3..7e04a9c95e 100644 --- a/Mage.Sets/src/mage/sets/avacynrestored/UlvenwaldTracker.java +++ b/Mage.Sets/src/mage/sets/avacynrestored/UlvenwaldTracker.java @@ -38,6 +38,7 @@ import mage.abilities.costs.common.TapSourceCost; import mage.abilities.costs.mana.ManaCostsImpl; import mage.abilities.effects.common.FightTargetsEffect; import mage.cards.CardImpl; +import mage.game.Game; import mage.target.common.TargetControlledCreaturePermanent; import mage.target.common.TargetCreaturePermanent; @@ -60,8 +61,8 @@ public class UlvenwaldTracker extends CardImpl { // {1}{G}, {tap}: Target creature you control fights another target creature. Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, new FightTargetsEffect(), new ManaCostsImpl("{1}{G}")); ability.addCost(new TapSourceCost()); - ability.addTarget(new TargetControlledCreaturePermanent()); - ability.addTarget(new TargetCreaturePermanent()); + ability.addTarget(new TargetControlledCreaturePermanent(true)); + ability.addTarget(new TargetOtherCreaturePermanent(true)); this.addAbility(ability); } @@ -74,3 +75,27 @@ public class UlvenwaldTracker extends CardImpl { return new UlvenwaldTracker(this); } } +class TargetOtherCreaturePermanent extends TargetCreaturePermanent { + + public TargetOtherCreaturePermanent(boolean required) { + super(true); + } + + public TargetOtherCreaturePermanent(final TargetOtherCreaturePermanent target) { + super(target); + } + + @Override + public boolean canTarget(UUID controllerId, UUID id, Ability source, Game game) { + if (source.getTargets().get(0).getTargets().contains(id)) { + return false; + } + return super.canTarget(controllerId, id, source, game); + } + + @Override + public TargetOtherCreaturePermanent copy() { + return new TargetOtherCreaturePermanent(this); + } + +} diff --git a/Mage.Sets/src/mage/sets/darkascension/BloodFeud.java b/Mage.Sets/src/mage/sets/darkascension/BloodFeud.java index e3140e14de..1d56a2d910 100644 --- a/Mage.Sets/src/mage/sets/darkascension/BloodFeud.java +++ b/Mage.Sets/src/mage/sets/darkascension/BloodFeud.java @@ -30,8 +30,11 @@ package mage.sets.darkascension; import java.util.UUID; import mage.Constants.CardType; import mage.Constants.Rarity; +import mage.abilities.Ability; import mage.abilities.effects.common.FightTargetsEffect; import mage.cards.CardImpl; +import mage.filter.common.FilterCreaturePermanent; +import mage.game.Game; import mage.target.common.TargetCreaturePermanent; /** @@ -48,8 +51,8 @@ public class BloodFeud extends CardImpl { // Target creature fights another target creature. this.getSpellAbility().addEffect(new FightTargetsEffect()); - this.getSpellAbility().addTarget(new TargetCreaturePermanent()); - this.getSpellAbility().addTarget(new TargetCreaturePermanent()); + this.getSpellAbility().addTarget(new TargetCreaturePermanent(true)); + this.getSpellAbility().addTarget(new TargetOtherCreaturePermanent(true)); } public BloodFeud(final BloodFeud card) { @@ -61,3 +64,28 @@ public class BloodFeud extends CardImpl { return new BloodFeud(this); } } + +class TargetOtherCreaturePermanent extends TargetCreaturePermanent { + + public TargetOtherCreaturePermanent(boolean required) { + super(true); + } + + public TargetOtherCreaturePermanent(final TargetOtherCreaturePermanent target) { + super(target); + } + + @Override + public boolean canTarget(UUID controllerId, UUID id, Ability source, Game game) { + if (source.getTargets().get(0).getTargets().contains(id)) { + return false; + } + return super.canTarget(controllerId, id, source, game); + } + + @Override + public TargetOtherCreaturePermanent copy() { + return new TargetOtherCreaturePermanent(this); + } + +} diff --git a/Mage.Sets/src/mage/sets/gatecrash/DomriRade.java b/Mage.Sets/src/mage/sets/gatecrash/DomriRade.java index 813bbaa3f7..c8362c9b2b 100644 --- a/Mage.Sets/src/mage/sets/gatecrash/DomriRade.java +++ b/Mage.Sets/src/mage/sets/gatecrash/DomriRade.java @@ -56,7 +56,6 @@ import mage.game.Game; import mage.game.command.Emblem; import mage.players.Player; import mage.target.common.TargetControlledCreaturePermanent; -import mage.target.common.TargetCreaturePermanent; /** * @@ -78,8 +77,8 @@ public class DomriRade extends CardImpl { // -2: Target creature you control fights another target creature. LoyaltyAbility ability2 = new LoyaltyAbility(new FightTargetsEffect(), -2); - ability2.addTarget(new TargetControlledCreaturePermanent()); - ability2.addTarget(new TargetCreaturePermanent()); + ability2.addTarget(new TargetControlledCreaturePermanent(true)); + ability2.addTarget(new TargetOtherCreaturePermanent(true)); this.addAbility(ability2); // -7: You get an emblem with "Creatures you control have double strike, trample, hexproof and haste." @@ -150,4 +149,4 @@ class DomriRadeEmblem extends Emblem { ability.addEffect(effect); this.getAbilities().add(ability); } -} \ No newline at end of file +} diff --git a/Mage.Sets/src/mage/sets/gatecrash/GruulRagebeast.java b/Mage.Sets/src/mage/sets/gatecrash/GruulRagebeast.java index c16b0f094e..cf464c81e0 100644 --- a/Mage.Sets/src/mage/sets/gatecrash/GruulRagebeast.java +++ b/Mage.Sets/src/mage/sets/gatecrash/GruulRagebeast.java @@ -74,6 +74,7 @@ public class GruulRagebeast extends CardImpl { // Whenever Gruul Ragebeast or another creature enters the battlefield under your control, that creature fights target creature an opponent controls. Ability ability = new GruulRagebeastTriggeredAbility(); + ability.addTarget(new TargetCreaturePermanent(filter2)); this.addAbility(ability); } diff --git a/Mage.Sets/src/mage/sets/gatecrash/PitFight.java b/Mage.Sets/src/mage/sets/gatecrash/PitFight.java index 5b6d10a023..a13761651e 100644 --- a/Mage.Sets/src/mage/sets/gatecrash/PitFight.java +++ b/Mage.Sets/src/mage/sets/gatecrash/PitFight.java @@ -30,8 +30,10 @@ package mage.sets.gatecrash; import java.util.UUID; import mage.Constants.CardType; import mage.Constants.Rarity; +import mage.abilities.Ability; import mage.abilities.effects.common.FightTargetsEffect; import mage.cards.CardImpl; +import mage.game.Game; import mage.target.common.TargetControlledCreaturePermanent; import mage.target.common.TargetCreaturePermanent; @@ -50,8 +52,8 @@ public class PitFight extends CardImpl { // Target creature you control fights another target creature. this.getSpellAbility().addEffect(new FightTargetsEffect()); - this.getSpellAbility().addTarget(new TargetControlledCreaturePermanent()); - this.getSpellAbility().addTarget(new TargetCreaturePermanent()); + this.getSpellAbility().addTarget(new TargetControlledCreaturePermanent(true)); + this.getSpellAbility().addTarget(new TargetOtherCreaturePermanent(true)); } public PitFight(final PitFight card) { @@ -63,3 +65,29 @@ public class PitFight extends CardImpl { return new PitFight(this); } } + + +class TargetOtherCreaturePermanent extends TargetCreaturePermanent { + + public TargetOtherCreaturePermanent(boolean required) { + super(required); + } + + public TargetOtherCreaturePermanent(final TargetOtherCreaturePermanent target) { + super(target); + } + + @Override + public boolean canTarget(UUID controllerId, UUID id, Ability source, Game game) { + if (source.getTargets().get(0).getTargets().contains(id)) { + return false; + } + return super.canTarget(controllerId, id, source, game); + } + + @Override + public TargetOtherCreaturePermanent copy() { + return new TargetOtherCreaturePermanent(this); + } + +} diff --git a/Mage.Sets/src/mage/sets/innistrad/PreyUpon.java b/Mage.Sets/src/mage/sets/innistrad/PreyUpon.java index 77efa2d733..9143e76823 100644 --- a/Mage.Sets/src/mage/sets/innistrad/PreyUpon.java +++ b/Mage.Sets/src/mage/sets/innistrad/PreyUpon.java @@ -35,6 +35,7 @@ import mage.abilities.effects.common.FightTargetsEffect; import mage.cards.CardImpl; import mage.filter.common.FilterCreaturePermanent; import mage.filter.predicate.permanent.ControllerPredicate; +import mage.target.Target; import mage.target.common.TargetControlledCreaturePermanent; import mage.target.common.TargetCreaturePermanent; @@ -58,8 +59,10 @@ public class PreyUpon extends CardImpl { // Target creature you control fights target creature you don't control. this.getSpellAbility().addEffect(new FightTargetsEffect()); - this.getSpellAbility().addTarget(new TargetControlledCreaturePermanent()); - this.getSpellAbility().addTarget(new TargetCreaturePermanent(filter)); + this.getSpellAbility().addTarget(new TargetControlledCreaturePermanent(true)); + Target target = new TargetCreaturePermanent(filter); + target.setRequired(true); + this.getSpellAbility().addTarget(target); } public PreyUpon(final PreyUpon card) { diff --git a/Mage/src/mage/abilities/effects/common/FightTargetsEffect.java b/Mage/src/mage/abilities/effects/common/FightTargetsEffect.java index 25c584ff9f..7fdbe13edc 100644 --- a/Mage/src/mage/abilities/effects/common/FightTargetsEffect.java +++ b/Mage/src/mage/abilities/effects/common/FightTargetsEffect.java @@ -32,6 +32,7 @@ import mage.Constants.Outcome; import mage.abilities.Ability; import mage.abilities.Mode; import mage.abilities.effects.OneShotEffect; +import mage.cards.Card; import mage.game.Game; import mage.game.permanent.Permanent; @@ -51,15 +52,22 @@ public class FightTargetsEffect extends OneShotEffect { @Override public boolean apply(Game game, Ability source) { - Permanent creature1 = game.getPermanent(source.getTargets().get(0).getFirstTarget()); - Permanent creature2 = game.getPermanent(source.getTargets().get(1).getFirstTarget()); - // 20110930 - 701.10 - if (creature1 != null && creature2 != null) { - if (creature1.getCardType().contains(CardType.CREATURE) && creature2.getCardType().contains(CardType.CREATURE)) { - creature1.damage(creature2.getPower().getValue(), creature2.getId(), game, true, false); - creature2.damage(creature1.getPower().getValue(), creature1.getId(), game, true, false); - return true; + Card card = game.getCard(source.getSourceId()); + if (card != null) { + // only if both targets are legal the effect will be applied + if (source.getTargets().get(0).isLegal(source, game) && source.getTargets().get(1).isLegal(source, game)) { + Permanent creature1 = game.getPermanent(source.getTargets().get(0).getFirstTarget()); + Permanent creature2 = game.getPermanent(source.getTargets().get(1).getFirstTarget()); + // 20110930 - 701.10 + if (creature1 != null && creature2 != null) { + if (creature1.getCardType().contains(CardType.CREATURE) && creature2.getCardType().contains(CardType.CREATURE)) { + creature1.damage(creature2.getPower().getValue(), creature2.getId(), game, true, false); + creature2.damage(creature1.getPower().getValue(), creature1.getId(), game, true, false); + return true; + } + } } + game.informPlayers(card.getName() + " has been fizzled."); } return false; } @@ -71,7 +79,8 @@ public class FightTargetsEffect extends OneShotEffect { @Override public String getText(Mode mode) { - return "Target " + mode.getTargets().get(0).getTargetName() + " fights target " + mode.getTargets().get(1).getTargetName(); + return "Target " + mode.getTargets().get(0).getTargetName() + " fights another target " + mode.getTargets().get(1).getTargetName(); } } +