mirror of
https://github.com/correl/mage.git
synced 2024-12-26 03:00:11 +00:00
Fixed Swere, Misdirection and Ricochet Trap to target only spells with exactly one target and allowing to replace it with exactly one different valid target.
This commit is contained in:
parent
5d13559ef1
commit
8d4ec3f0ed
6 changed files with 70 additions and 75 deletions
|
@ -32,22 +32,18 @@ import java.util.UUID;
|
|||
import mage.constants.CardType;
|
||||
import mage.constants.Rarity;
|
||||
import mage.ObjectColor;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.costs.AlternativeCostImpl;
|
||||
import mage.abilities.costs.Cost;
|
||||
import mage.abilities.costs.CostsImpl;
|
||||
import mage.abilities.costs.common.ExileFromHandCost;
|
||||
import mage.abilities.effects.OneShotEffect;
|
||||
import mage.abilities.effects.common.ChooseNewTargetsTargetEffect;
|
||||
import mage.cards.CardImpl;
|
||||
import mage.constants.Outcome;
|
||||
import mage.filter.FilterSpell;
|
||||
import mage.filter.common.FilterOwnedCard;
|
||||
import mage.filter.predicate.Predicates;
|
||||
import mage.filter.predicate.mageobject.CardIdPredicate;
|
||||
import mage.filter.predicate.mageobject.ColorPredicate;
|
||||
import mage.filter.predicate.mageobject.NumberOfTargetsPredicate;
|
||||
import mage.game.Game;
|
||||
import mage.game.stack.Spell;
|
||||
import mage.target.TargetSpell;
|
||||
import mage.target.common.TargetCardInHand;
|
||||
|
||||
|
@ -57,8 +53,7 @@ import mage.target.common.TargetCardInHand;
|
|||
*/
|
||||
public class Misdirection extends CardImpl<Misdirection> {
|
||||
|
||||
private static final FilterSpell filter2 = new FilterSpell();
|
||||
|
||||
private static final FilterSpell filter2 = new FilterSpell("spell with a single target");
|
||||
static {
|
||||
filter2.add(new NumberOfTargetsPredicate(1));
|
||||
}
|
||||
|
@ -78,7 +73,7 @@ public class Misdirection extends CardImpl<Misdirection> {
|
|||
costs.add(new ExileFromHandCost(new TargetCardInHand(filterCardInHand)));
|
||||
this.getSpellAbility().addAlternativeCost(new AlternativeCostImpl("You may exile a blue card from your hand rather than pay Misdirection's mana cost", costs));
|
||||
// Change the target of target spell with a single target.
|
||||
this.getSpellAbility().addEffect(new MisdirectionEffect());
|
||||
this.getSpellAbility().addEffect(new ChooseNewTargetsTargetEffect(true, true));
|
||||
this.getSpellAbility().addTarget(new TargetSpell(filter2));
|
||||
}
|
||||
|
||||
|
@ -92,28 +87,3 @@ public class Misdirection extends CardImpl<Misdirection> {
|
|||
}
|
||||
}
|
||||
|
||||
class MisdirectionEffect extends OneShotEffect<MisdirectionEffect> {
|
||||
|
||||
public MisdirectionEffect() {
|
||||
super(Outcome.Neutral);
|
||||
staticText = "Change the target of target spell with a single target";
|
||||
}
|
||||
|
||||
public MisdirectionEffect(final MisdirectionEffect effect) {
|
||||
super(effect);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Spell spell = game.getStack().getSpell(source.getFirstTarget());
|
||||
if (spell != null && source.getControllerId() != null) {
|
||||
return spell.chooseNewTargets(game, source.getControllerId());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MisdirectionEffect copy() {
|
||||
return new MisdirectionEffect(this);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,7 +42,7 @@ import mage.target.TargetSpell;
|
|||
*/
|
||||
public class Swerve extends CardImpl<Swerve> {
|
||||
|
||||
private static final FilterSpell filter = new FilterSpell();
|
||||
private static final FilterSpell filter = new FilterSpell("spell with a single target");
|
||||
|
||||
static {
|
||||
filter.add(new NumberOfTargetsPredicate(1));
|
||||
|
@ -56,7 +56,7 @@ public class Swerve extends CardImpl<Swerve> {
|
|||
this.color.setBlue(true);
|
||||
|
||||
// Change the target of target spell with a single target.
|
||||
this.getSpellAbility().addEffect(new ChooseNewTargetsTargetEffect());
|
||||
this.getSpellAbility().addEffect(new ChooseNewTargetsTargetEffect(true, true));
|
||||
this.getSpellAbility().addTarget(new TargetSpell(filter));
|
||||
|
||||
}
|
||||
|
|
|
@ -31,12 +31,11 @@ import java.util.UUID;
|
|||
|
||||
import mage.constants.CardType;
|
||||
import mage.constants.Rarity;
|
||||
import mage.constants.Outcome;
|
||||
import mage.constants.WatcherScope;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.costs.AlternativeCostImpl;
|
||||
import mage.abilities.costs.mana.ColoredManaCost;
|
||||
import mage.abilities.effects.OneShotEffect;
|
||||
import mage.abilities.effects.common.ChooseNewTargetsTargetEffect;
|
||||
import mage.cards.CardImpl;
|
||||
import mage.constants.ColoredManaSymbol;
|
||||
import mage.filter.FilterSpell;
|
||||
|
@ -54,7 +53,7 @@ import mage.watchers.WatcherImpl;
|
|||
*/
|
||||
public class RicochetTrap extends CardImpl<RicochetTrap> {
|
||||
|
||||
private static final FilterSpell filter = new FilterSpell();
|
||||
private static final FilterSpell filter = new FilterSpell("spell with a single target");
|
||||
|
||||
static {
|
||||
filter.add(new NumberOfTargetsPredicate(1));
|
||||
|
@ -71,7 +70,7 @@ public class RicochetTrap extends CardImpl<RicochetTrap> {
|
|||
this.getSpellAbility().addAlternativeCost(new RicochetTrapAlternativeCost());
|
||||
|
||||
// Change the target of target spell with a single target.
|
||||
this.getSpellAbility().addEffect(new RicochetTrapEffect());
|
||||
this.getSpellAbility().addEffect(new ChooseNewTargetsTargetEffect(true, true));
|
||||
this.getSpellAbility().addTarget(new TargetSpell(filter));
|
||||
|
||||
this.addWatcher(new RicochetTrapWatcher());
|
||||
|
@ -154,29 +153,3 @@ class RicochetTrapAlternativeCost extends AlternativeCostImpl<RicochetTrapAltern
|
|||
return "If an opponent cast a blue spell this turn, you may pay {R} rather than pay {this} mana cost";
|
||||
}
|
||||
}
|
||||
|
||||
class RicochetTrapEffect extends OneShotEffect<RicochetTrapEffect> {
|
||||
|
||||
public RicochetTrapEffect() {
|
||||
super(Outcome.Neutral);
|
||||
staticText = "Change the target of target spell with a single target";
|
||||
}
|
||||
|
||||
public RicochetTrapEffect(final RicochetTrapEffect effect) {
|
||||
super(effect);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Spell spell = game.getStack().getSpell(source.getFirstTarget());
|
||||
if (spell != null && source.getControllerId() != null) {
|
||||
return spell.chooseNewTargets(game, source.getControllerId());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RicochetTrapEffect copy() {
|
||||
return new RicochetTrapEffect(this);
|
||||
}
|
||||
}
|
|
@ -41,19 +41,35 @@ import mage.game.stack.Spell;
|
|||
*/
|
||||
public class ChooseNewTargetsTargetEffect extends OneShotEffect<ChooseNewTargetsTargetEffect> {
|
||||
|
||||
private boolean forceChange;
|
||||
private boolean onlyOneTarget;
|
||||
|
||||
public ChooseNewTargetsTargetEffect() {
|
||||
this(false, false);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param forceChange - forces the user to choose another target (only targets with maxtargets = 1 supported)
|
||||
*/
|
||||
|
||||
public ChooseNewTargetsTargetEffect(boolean forceChange, boolean onlyOneTarget) {
|
||||
super(Outcome.Benefit);
|
||||
this.forceChange = forceChange;
|
||||
this.onlyOneTarget = onlyOneTarget;
|
||||
}
|
||||
|
||||
public ChooseNewTargetsTargetEffect(final ChooseNewTargetsTargetEffect effect) {
|
||||
super(effect);
|
||||
this.forceChange = effect.forceChange;
|
||||
this.onlyOneTarget = effect.onlyOneTarget;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Spell spell = game.getStack().getSpell(source.getFirstTarget());
|
||||
if (spell != null) {
|
||||
return spell.chooseNewTargets(game, source.getControllerId());
|
||||
return spell.chooseNewTargets(game, source.getControllerId(), forceChange, onlyOneTarget);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -65,6 +81,13 @@ public class ChooseNewTargetsTargetEffect extends OneShotEffect<ChooseNewTargets
|
|||
|
||||
@Override
|
||||
public String getText(Mode mode) {
|
||||
return "You may choose new targets for target " + mode.getTargets().get(0).getTargetName();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if (forceChange) {
|
||||
sb.append("Change the target of target ");
|
||||
} else {
|
||||
sb.append("You may choose new targets for target ");
|
||||
}
|
||||
sb.append(mode.getTargets().get(0).getTargetName());
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,6 +31,7 @@ import mage.MageObject;
|
|||
import mage.filter.predicate.Predicate;
|
||||
import mage.game.Game;
|
||||
import mage.game.stack.Spell;
|
||||
import mage.target.Target;
|
||||
import mage.target.Targets;
|
||||
|
||||
/**
|
||||
|
@ -49,11 +50,13 @@ public class NumberOfTargetsPredicate implements Predicate<MageObject> {
|
|||
public boolean apply(MageObject input, Game game) {
|
||||
Spell spell = game.getStack().getSpell(input.getId());
|
||||
if (spell != null) {
|
||||
Targets target = spell.getSpellAbility().getTargets();
|
||||
if (target != null) {
|
||||
if (target.size() == targets) {
|
||||
return true;
|
||||
Targets spellTargets = spell.getSpellAbility().getTargets();
|
||||
int numberOfTargets = 0;
|
||||
for (Target target : spellTargets) {
|
||||
numberOfTargets += target.getTargets().size();
|
||||
}
|
||||
if (numberOfTargets == targets) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -239,6 +239,19 @@ public class Spell<T extends Spell<T>> implements StackObject, Card {
|
|||
* @return
|
||||
*/
|
||||
public boolean chooseNewTargets(Game game, UUID playerId) {
|
||||
return chooseNewTargets(game, playerId, false, false);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param game
|
||||
* @param playerId
|
||||
* @param forceChange - does only work for targets with maximal one targetId
|
||||
* @param onlyOneTarget - 114.6b one target must be changed to another target
|
||||
* @return
|
||||
*/
|
||||
public boolean chooseNewTargets(Game game, UUID playerId, boolean forceChange, boolean onlyOneTarget) {
|
||||
Player player = game.getPlayer(playerId);
|
||||
if (player != null) {
|
||||
for(SpellAbility spellAbility: spellAbilities) {
|
||||
|
@ -256,11 +269,24 @@ public class Spell<T extends Spell<T>> implements StackObject, Card {
|
|||
} else {
|
||||
name = object.getName();
|
||||
}
|
||||
if (name != null && player.chooseUse(spellAbility.getEffects().get(0).getOutcome(), "Change target from " + name + "?", game)) {
|
||||
if (name != null && (forceChange || player.chooseUse(spellAbility.getEffects().get(0).getOutcome(), "Change target from " + name + "?", game))) {
|
||||
if (forceChange && target.possibleTargets(this.getSourceId(), playerId, game).size() > 1 ) {
|
||||
int iteration = 0;
|
||||
do {
|
||||
if (iteration > 0) {
|
||||
game.informPlayer(player, "You may only select exactly one target that must be different from the origin target!");
|
||||
}
|
||||
iteration++;
|
||||
newTarget.clearChosen();
|
||||
player.chooseTarget(spellAbility.getEffects().get(0).getOutcome(), newTarget, spellAbility, game);
|
||||
} while (targetId.equals(newTarget.getFirstTarget()) || newTarget.getTargets().size() != 1);
|
||||
|
||||
} else {
|
||||
if (!player.chooseTarget(spellAbility.getEffects().get(0).getOutcome(), newTarget, spellAbility, game)) {
|
||||
newTarget.addTarget(targetId, spellAbility, game, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
newTarget.addTarget(targetId, spellAbility, game, false);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue