* Simic Guildmage - Fixed that the aura moving ability eas not working (fixes #3319).

This commit is contained in:
LevelX2 2017-05-16 12:16:52 +02:00
parent 7dcfbd5be5
commit 7b61ad7455

View file

@ -30,7 +30,6 @@ package mage.cards.s;
import java.util.UUID; import java.util.UUID;
import mage.MageInt; import mage.MageInt;
import mage.MageItem; import mage.MageItem;
import mage.MageObject;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.common.SimpleActivatedAbility; import mage.abilities.common.SimpleActivatedAbility;
import mage.abilities.costs.mana.ManaCostsImpl; import mage.abilities.costs.mana.ManaCostsImpl;
@ -41,7 +40,7 @@ import mage.constants.CardType;
import mage.constants.Outcome; import mage.constants.Outcome;
import mage.constants.Zone; import mage.constants.Zone;
import mage.counters.CounterType; import mage.counters.CounterType;
import mage.filter.FilterPermanent; import mage.filter.Filter;
import mage.filter.common.FilterCreaturePermanent; import mage.filter.common.FilterCreaturePermanent;
import mage.filter.common.FilterEnchantmentPermanent; import mage.filter.common.FilterEnchantmentPermanent;
import mage.filter.predicate.ObjectSourcePlayer; import mage.filter.predicate.ObjectSourcePlayer;
@ -64,15 +63,15 @@ import mage.target.common.TargetCreaturePermanent;
* @author anonymous * @author anonymous
*/ */
public class SimicGuildmage extends CardImpl { public class SimicGuildmage extends CardImpl {
private static final FilterEnchantmentPermanent filter = new FilterEnchantmentPermanent("Aura"); private static final FilterEnchantmentPermanent auraFilter = new FilterEnchantmentPermanent("Aura");
static { static {
filter.add(new SubtypePredicate("Aura")); auraFilter.add(new SubtypePredicate("Aura"));
} }
public SimicGuildmage(UUID ownerId, CardSetInfo setInfo) { public SimicGuildmage(UUID ownerId, CardSetInfo setInfo) {
super(ownerId,setInfo,new CardType[]{CardType.CREATURE},"{G/U}{G/U}"); super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{G/U}{G/U}");
this.subtype.add("Elf"); this.subtype.add("Elf");
this.subtype.add("Wizard"); this.subtype.add("Wizard");
this.power = new MageInt(2); this.power = new MageInt(2);
@ -84,7 +83,7 @@ public class SimicGuildmage extends CardImpl {
new FilterCreaturePermanent("creature (you take counter from)")); new FilterCreaturePermanent("creature (you take counter from)"));
target.setTargetTag(1); target.setTargetTag(1);
countersAbility.addTarget(target); countersAbility.addTarget(target);
FilterCreaturePermanent filter = new FilterCreaturePermanent( FilterCreaturePermanent filter = new FilterCreaturePermanent(
"another target creature with the same controller (counter goes to)"); "another target creature with the same controller (counter goes to)");
filter.add(new AnotherTargetPredicate(2)); filter.add(new AnotherTargetPredicate(2));
@ -93,12 +92,12 @@ public class SimicGuildmage extends CardImpl {
target2.setTargetTag(2); target2.setTargetTag(2);
countersAbility.addTarget(target2); countersAbility.addTarget(target2);
this.addAbility(countersAbility); this.addAbility(countersAbility);
// {1}{U}: Attach target Aura enchanting a permanent to another permanent with the same controller. // {1}{U}: Attach target Aura enchanting a permanent to another permanent with the same controller.
Ability auraAbility = new SimpleActivatedAbility(Zone.BATTLEFIELD, new MoveAuraEffect(), new ManaCostsImpl("{1}{U}")); Ability auraAbility = new SimpleActivatedAbility(Zone.BATTLEFIELD, new MoveAuraEffect(), new ManaCostsImpl("{1}{U}"));
auraAbility.addTarget(new TargetPermanent(filter)); auraAbility.addTarget(new TargetPermanent(auraFilter));
this.addAbility(auraAbility); this.addAbility(auraAbility);
} }
public SimicGuildmage(final SimicGuildmage card) { public SimicGuildmage(final SimicGuildmage card) {
@ -155,7 +154,7 @@ class SameControllerPredicate implements ObjectSourcePlayerPredicate<ObjectSourc
StackObject source = game.getStack().getStackObject(input.getSourceId()); StackObject source = game.getStack().getStackObject(input.getSourceId());
if (source != null) { if (source != null) {
if (source.getStackAbility().getTargets().isEmpty() if (source.getStackAbility().getTargets().isEmpty()
|| source.getStackAbility().getTargets().get(0).getTargets().isEmpty()) { || source.getStackAbility().getTargets().get(0).getTargets().isEmpty()) {
return true; return true;
} }
Permanent firstTarget = game.getPermanent( Permanent firstTarget = game.getPermanent(
@ -172,7 +171,7 @@ class SameControllerPredicate implements ObjectSourcePlayerPredicate<ObjectSourc
public String toString() { public String toString() {
return "Target with the same controller"; return "Target with the same controller";
} }
} }
class MoveAuraEffect extends OneShotEffect { class MoveAuraEffect extends OneShotEffect {
@ -194,47 +193,42 @@ class MoveAuraEffect extends OneShotEffect {
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
/* /*
5/1/2006 5/1/2006
For the second ability, only the Aura is targeted. For the second ability, only the Aura is targeted.
When the ability resolves, you choose a permanent to move the Aura onto. When the ability resolves, you choose a permanent to move the Aura onto.
It cant be the permanent the Aura is already attached to, it must be controlled by the player who controls the permanent the Aura is attached to, and it must be able to be enchanted by the Aura. It cant be the permanent the Aura is already attached to, it must be controlled by the player who controls the permanent the Aura is attached to, and it must be able to be enchanted by the Aura.
(It doesnt matter who controls the Aura or who controls Simic Guildmage.) (It doesnt matter who controls the Aura or who controls Simic Guildmage.)
If no such permanent exists, the Aura doesnt move. If no such permanent exists, the Aura doesnt move.
*/ */
UUID auraId = getTargetPointer().getFirst(game, source);
Permanent aura = game.getPermanent(auraId);
Permanent fromPermanent = game.getPermanent(aura.getAttachedTo());
Player controller = game.getPlayer(source.getControllerId()); Player controller = game.getPlayer(source.getControllerId());
if (fromPermanent != null && controller != null) { if (controller != null) {
Permanent aura = game.getPermanent(getTargetPointer().getFirst(game, source));
if (aura == null) {
return true;
}
Permanent fromPermanent = game.getPermanent(aura.getAttachedTo());
if (fromPermanent == null) {
return false;
}
boolean passed = true; boolean passed = true;
FilterPermanent filterChoice = new FilterPermanent("a different permanent with the same controller as the target to attach the enchantments to"); Target chosenPermanentToAttachAuras = aura.getSpellAbility().getTargets().get(0).copy();
chosenPermanentToAttachAuras.setNotTarget(true);
Filter filterChoice = chosenPermanentToAttachAuras.getFilter();
filterChoice.add(new ControllerIdPredicate(fromPermanent.getControllerId())); filterChoice.add(new ControllerIdPredicate(fromPermanent.getControllerId()));
filterChoice.add(Predicates.not(new PermanentIdPredicate(fromPermanent.getId()))); filterChoice.add(Predicates.not(new PermanentIdPredicate(fromPermanent.getId())));
chosenPermanentToAttachAuras.setTargetName("a different " + filterChoice.getMessage() + " with the same controller as the " + filterChoice.getMessage() + " the target aura is attached to");
Target chosenPermanentToAttachAuras = new TargetPermanent(filterChoice);
chosenPermanentToAttachAuras.setNotTarget(true);
if (chosenPermanentToAttachAuras.canChoose(source.getSourceId(), source.getControllerId(), game) if (chosenPermanentToAttachAuras.canChoose(source.getSourceId(), source.getControllerId(), game)
&& controller.choose(Outcome.Neutral, chosenPermanentToAttachAuras, source.getSourceId(), game)) { && controller.choose(Outcome.Neutral, chosenPermanentToAttachAuras, source.getSourceId(), game)) {
Permanent permanentToAttachAuras = game.getPermanent(chosenPermanentToAttachAuras.getFirstTarget()); Permanent permanentToAttachAura = game.getPermanent(chosenPermanentToAttachAuras.getFirstTarget());
if (permanentToAttachAuras != null) { if (permanentToAttachAura != null) {
if (aura != null && passed) { // Check for protection
// Check the target filter if (permanentToAttachAura.cantBeAttachedBy(aura, game)) {
Target target = aura.getSpellAbility().getTargets().get(0); passed = false;
if (target instanceof TargetPermanent) {
if (!target.getFilter().match(permanentToAttachAuras, game)) {
passed = false;
}
}
// Check for protection
MageObject auraObject = game.getObject(auraId);
if (permanentToAttachAuras.cantBeAttachedBy(auraObject, game)) {
passed = false;
}
} }
if (passed) { if (passed) {
fromPermanent.removeAttachment(aura.getId(), game); fromPermanent.removeAttachment(aura.getId(), game);
permanentToAttachAuras.addAttachment(aura.getId(), game); permanentToAttachAura.addAttachment(aura.getId(), game);
return true; return true;
} }
} }
@ -244,4 +238,4 @@ class MoveAuraEffect extends OneShotEffect {
return false; return false;
} }
} }