From b9257fffaec182937833db7966b99f69edceb969 Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Thu, 14 Mar 2013 23:58:51 +0100 Subject: [PATCH] Changes to some X spells because adjustTargets works now for X spells of AI. By the way cost reduction of X spells for the AI should work now also. --- .../src/mage/sets/gatecrash/Gridlock.java | 64 ++++---------- .../src/mage/sets/gatecrash/KillingGlare.java | 57 ++----------- .../src/mage/sets/magic2010/Fireball.java | 84 ++++++++++++++++++- 3 files changed, 108 insertions(+), 97 deletions(-) diff --git a/Mage.Sets/src/mage/sets/gatecrash/Gridlock.java b/Mage.Sets/src/mage/sets/gatecrash/Gridlock.java index 66c5e5824c..32ba34deb9 100644 --- a/Mage.Sets/src/mage/sets/gatecrash/Gridlock.java +++ b/Mage.Sets/src/mage/sets/gatecrash/Gridlock.java @@ -27,18 +27,15 @@ */ package mage.sets.gatecrash; -import java.util.List; import java.util.UUID; import mage.Constants.CardType; -import mage.Constants.Outcome; import mage.Constants.Rarity; import mage.abilities.Ability; -import mage.abilities.effects.OneShotEffect; +import mage.abilities.SpellAbility; +import mage.abilities.effects.common.TapTargetEffect; import mage.cards.CardImpl; -import mage.filter.FilterPermanent; import mage.filter.common.FilterNonlandPermanent; import mage.game.Game; -import mage.game.permanent.Permanent; import mage.target.TargetPermanent; /** @@ -46,6 +43,7 @@ import mage.target.TargetPermanent; * @author LevelX2 */ public class Gridlock extends CardImpl { + private static final FilterNonlandPermanent filter = new FilterNonlandPermanent("nonland permanents"); public Gridlock(UUID ownerId) { super(ownerId, 36, "Gridlock", Rarity.UNCOMMON, new CardType[]{CardType.INSTANT}, "{X}{U}"); @@ -54,56 +52,28 @@ public class Gridlock extends CardImpl { this.color.setBlue(true); // Tap X target nonland permanents. - this.getSpellAbility().addEffect(new GridlockTapEffect()); - // Target handling has to be changes once handling of X costs is improved, so that the targets are shown when the spell is on the stack. + this.getSpellAbility().addEffect(new TapTargetEffect()); + // Correct number of targets will be set in adjustTargets + this.getSpellAbility().addTarget(new TargetPermanent(0, 1,filter, false)); + } public Gridlock(final Gridlock card) { super(card); } + @Override + public void adjustTargets(Ability ability, Game game) { + if (ability instanceof SpellAbility) { + ability.getTargets().clear(); + int numberToTap = ability.getManaCostsToPay().getX(); + numberToTap = Math.min(game.getBattlefield().count(filter, ability.getSourceId(), ability.getControllerId(), game), numberToTap); + ability.addTarget(new TargetPermanent(numberToTap, filter)); + } + } + @Override public Gridlock copy() { return new Gridlock(this); } } - -class GridlockTapEffect extends OneShotEffect { - - private static final FilterPermanent filter = new FilterNonlandPermanent(); - - public GridlockTapEffect() { - super(Outcome.Tap); - staticText = "Tap X target nonland permanents"; - } - - public GridlockTapEffect(final GridlockTapEffect effect) { - super(effect); - } - - @Override - public boolean apply(Game game, Ability source) { - int numberToTap = source.getManaCostsToPay().getX(); - numberToTap = Math.min(game.getBattlefield().getAllActivePermanents(filter,game).size(), numberToTap); - TargetPermanent target = new TargetPermanent(numberToTap, filter); - if (target.canChoose(source.getControllerId(), game) && target.choose(Outcome.Tap, source.getControllerId(), source.getId(), game)) { - if (!target.getTargets().isEmpty()) { - List targets = target.getTargets(); - for (UUID targetId : targets) { - Permanent permanent = game.getPermanent(targetId); - if (permanent != null) { - permanent.tap(game); - } - } - } - return true; - } - return false; - } - - @Override - public GridlockTapEffect copy() { - return new GridlockTapEffect(this); - } - -} \ No newline at end of file diff --git a/Mage.Sets/src/mage/sets/gatecrash/KillingGlare.java b/Mage.Sets/src/mage/sets/gatecrash/KillingGlare.java index 662c088975..93b77f8481 100644 --- a/Mage.Sets/src/mage/sets/gatecrash/KillingGlare.java +++ b/Mage.Sets/src/mage/sets/gatecrash/KillingGlare.java @@ -34,6 +34,7 @@ import mage.Constants.Rarity; import mage.abilities.Ability; import mage.abilities.SpellAbility; import mage.abilities.effects.OneShotEffect; +import mage.abilities.effects.common.DestroyTargetEffect; import mage.cards.CardImpl; import mage.filter.Filter; import mage.filter.common.FilterCreaturePermanent; @@ -57,7 +58,8 @@ public class KillingGlare extends CardImpl { this.color.setBlack(true); // Destroy target creature with power X or less. - this.getSpellAbility().addEffect(new KillingGlareDestroyEffect()); + this.getSpellAbility().addEffect(new DestroyTargetEffect()); + this.getSpellAbility().addTarget(new TargetCreaturePermanent(new FilterCreaturePermanent("creature with power X or less"))); } @@ -68,13 +70,11 @@ public class KillingGlare extends CardImpl { @Override public void adjustTargets(Ability ability, Game game) { if (ability instanceof SpellAbility) { - Player controller = game.getPlayer(ability.getControllerId()); - if (controller.isHuman()) { - ability.getTargets().clear(); - FilterCreaturePermanent filter = new FilterCreaturePermanent(); - filter.add(new PowerPredicate(Filter.ComparisonType.LessThan, ability.getManaCostsToPay().getX() + 1)); - ability.addTarget(new TargetCreaturePermanent(filter)); - } + int xValue = ability.getManaCostsToPay().getX(); + ability.getTargets().clear(); + FilterCreaturePermanent filter = new FilterCreaturePermanent(new StringBuilder("creature with power ").append(xValue).append(" or less").toString()); + filter.add(new PowerPredicate(Filter.ComparisonType.LessThan, xValue + 1)); + ability.addTarget(new TargetCreaturePermanent(filter)); } } @@ -84,44 +84,3 @@ public class KillingGlare extends CardImpl { return new KillingGlare(this); } } - -class KillingGlareDestroyEffect extends OneShotEffect { - - public KillingGlareDestroyEffect() { - super(Outcome.DestroyPermanent); - this.staticText = "Destroy target creature with power X or less"; - } - - public KillingGlareDestroyEffect(final KillingGlareDestroyEffect effect) { - super(effect); - } - - @Override - public KillingGlareDestroyEffect copy() { - return new KillingGlareDestroyEffect(this); - } - - @Override - public boolean apply(Game game, Ability source) { - Player controller = game.getPlayer(source.getControllerId()); - if (controller.isHuman()) { - Permanent creature = game.getPermanent(getTargetPointer().getFirst(game, source)); - if (creature == null) { - return false; - } - return creature.destroy(source.getSourceId(), game, false); - } else { - FilterCreaturePermanent filter = new FilterCreaturePermanent(); - filter.add(new PowerPredicate(Filter.ComparisonType.LessThan, source.getManaCostsToPay().getX() + 1)); - Target target = new TargetCreaturePermanent(filter); - if (controller.chooseTarget(outcome, target, source, game)) { - Permanent creature = game.getPermanent(target.getFirstTarget()); - if (creature == null) { - return false; - } - return creature.destroy(source.getSourceId(), game, false); - } - } - return false; - } -} diff --git a/Mage.Sets/src/mage/sets/magic2010/Fireball.java b/Mage.Sets/src/mage/sets/magic2010/Fireball.java index 68e5200eeb..828c194050 100644 --- a/Mage.Sets/src/mage/sets/magic2010/Fireball.java +++ b/Mage.Sets/src/mage/sets/magic2010/Fireball.java @@ -28,6 +28,10 @@ package mage.sets.magic2010; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Set; import java.util.UUID; import mage.Constants.CardType; import mage.Constants.Outcome; @@ -51,7 +55,7 @@ public class Fireball extends CardImpl { super(ownerId, 136, "Fireball", Rarity.UNCOMMON, new CardType[]{CardType.SORCERY}, "{X}{R}"); this.expansionSetCode = "M10"; this.color.setRed(true); - this.getSpellAbility().addTarget(new TargetCreatureOrPlayer(0, Integer.MAX_VALUE)); + this.getSpellAbility().addTarget(new FireballTargetCreatureOrPlayer(0, Integer.MAX_VALUE)); this.getSpellAbility().addEffect(new FireballEffect()); } @@ -114,4 +118,82 @@ class FireballEffect extends OneShotEffect { return new FireballEffect(this); } +} + +class FireballTargetCreatureOrPlayer extends TargetCreatureOrPlayer { + + public FireballTargetCreatureOrPlayer(int minNumTargets, int maxNumTargets) { + super(minNumTargets, maxNumTargets); + } + + public FireballTargetCreatureOrPlayer(final FireballTargetCreatureOrPlayer target) { + super(target); + } + + + /** + * This is only used by AI players + * + * @param source + * @param game + * @return + */ + @Override + public List getTargetOptions(Ability source, Game game) { + + List options = new ArrayList(); + int xVal = source.getManaCostsToPay().getX(); + + if (xVal < 1) { + return options; + } + + for (int numberTargets = 1; numberTargets == 1 || xVal / (numberTargets - 1) > 1 ; numberTargets++) { + Set possibleTargets = possibleTargets(source.getSourceId(), source.getControllerId(), game); + // less possible targets than we're trying to set + if (possibleTargets.size() < numberTargets) { + return options; + } + // less than 1 damage per target = 0, add no such options + if ((xVal -(numberTargets -1))/numberTargets < 1) { + continue; + } + + possibleTargets.removeAll(getTargets()); + Iterator it = possibleTargets.iterator(); + while (it.hasNext()) { + UUID targetId = it.next(); + TargetCreatureOrPlayer target = this.copy(); + target.clearChosen(); + target.addTarget(targetId, source, game, true); + + if (target.getTargets().size() == numberTargets) { + chosen = true; + } + + if (!target.isChosen()) { + Iterator it2 = possibleTargets.iterator(); + while (it2.hasNext()&& !target.isChosen()) { + UUID nextTargetId = it2.next(); + target.addTarget(nextTargetId, source, game, true); + + if (target.getTargets().size() == numberTargets) { + chosen = true; + } + + } + } + if (target.isChosen()) { + options.add(target); + } + } + } + return options; + } + + + @Override + public FireballTargetCreatureOrPlayer copy() { + return new FireballTargetCreatureOrPlayer(this); + } } \ No newline at end of file