* 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 mage.MageInt;
import mage.MageItem;
import mage.MageObject;
import mage.abilities.Ability;
import mage.abilities.common.SimpleActivatedAbility;
import mage.abilities.costs.mana.ManaCostsImpl;
@ -41,7 +40,7 @@ import mage.constants.CardType;
import mage.constants.Outcome;
import mage.constants.Zone;
import mage.counters.CounterType;
import mage.filter.FilterPermanent;
import mage.filter.Filter;
import mage.filter.common.FilterCreaturePermanent;
import mage.filter.common.FilterEnchantmentPermanent;
import mage.filter.predicate.ObjectSourcePlayer;
@ -64,15 +63,15 @@ import mage.target.common.TargetCreaturePermanent;
* @author anonymous
*/
public class SimicGuildmage extends CardImpl {
private static final FilterEnchantmentPermanent filter = new FilterEnchantmentPermanent("Aura");
private static final FilterEnchantmentPermanent auraFilter = new FilterEnchantmentPermanent("Aura");
static {
filter.add(new SubtypePredicate("Aura"));
auraFilter.add(new SubtypePredicate("Aura"));
}
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("Wizard");
this.power = new MageInt(2);
@ -84,7 +83,7 @@ public class SimicGuildmage extends CardImpl {
new FilterCreaturePermanent("creature (you take counter from)"));
target.setTargetTag(1);
countersAbility.addTarget(target);
FilterCreaturePermanent filter = new FilterCreaturePermanent(
"another target creature with the same controller (counter goes to)");
filter.add(new AnotherTargetPredicate(2));
@ -93,12 +92,12 @@ public class SimicGuildmage extends CardImpl {
target2.setTargetTag(2);
countersAbility.addTarget(target2);
this.addAbility(countersAbility);
// {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}"));
auraAbility.addTarget(new TargetPermanent(filter));
auraAbility.addTarget(new TargetPermanent(auraFilter));
this.addAbility(auraAbility);
}
public SimicGuildmage(final SimicGuildmage card) {
@ -155,7 +154,7 @@ class SameControllerPredicate implements ObjectSourcePlayerPredicate<ObjectSourc
StackObject source = game.getStack().getStackObject(input.getSourceId());
if (source != null) {
if (source.getStackAbility().getTargets().isEmpty()
|| source.getStackAbility().getTargets().get(0).getTargets().isEmpty()) {
|| source.getStackAbility().getTargets().get(0).getTargets().isEmpty()) {
return true;
}
Permanent firstTarget = game.getPermanent(
@ -172,7 +171,7 @@ class SameControllerPredicate implements ObjectSourcePlayerPredicate<ObjectSourc
public String toString() {
return "Target with the same controller";
}
}
class MoveAuraEffect extends OneShotEffect {
@ -194,47 +193,42 @@ class MoveAuraEffect extends OneShotEffect {
@Override
public boolean apply(Game game, Ability source) {
/*
5/1/2006
For the second ability, only the Aura is targeted.
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 doesnt matter who controls the Aura or who controls Simic Guildmage.)
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());
5/1/2006
For the second ability, only the Aura is targeted.
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 doesnt matter who controls the Aura or who controls Simic Guildmage.)
If no such permanent exists, the Aura doesnt move.
*/
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;
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(Predicates.not(new PermanentIdPredicate(fromPermanent.getId())));
Target chosenPermanentToAttachAuras = new TargetPermanent(filterChoice);
chosenPermanentToAttachAuras.setNotTarget(true);
chosenPermanentToAttachAuras.setTargetName("a different " + filterChoice.getMessage() + " with the same controller as the " + filterChoice.getMessage() + " the target aura is attached to");
if (chosenPermanentToAttachAuras.canChoose(source.getSourceId(), source.getControllerId(), game)
&& controller.choose(Outcome.Neutral, chosenPermanentToAttachAuras, source.getSourceId(), game)) {
Permanent permanentToAttachAuras = game.getPermanent(chosenPermanentToAttachAuras.getFirstTarget());
if (permanentToAttachAuras != null) {
if (aura != null && passed) {
// Check the target filter
Target target = aura.getSpellAbility().getTargets().get(0);
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;
}
Permanent permanentToAttachAura = game.getPermanent(chosenPermanentToAttachAuras.getFirstTarget());
if (permanentToAttachAura != null) {
// Check for protection
if (permanentToAttachAura.cantBeAttachedBy(aura, game)) {
passed = false;
}
if (passed) {
fromPermanent.removeAttachment(aura.getId(), game);
permanentToAttachAuras.addAttachment(aura.getId(), game);
permanentToAttachAura.addAttachment(aura.getId(), game);
return true;
}
}
@ -244,4 +238,4 @@ class MoveAuraEffect extends OneShotEffect {
return false;
}
}
}