* Bruna, Light of Alabaster - Fixed that the check what aura could be selected was not correct (e.g. Daybreak Coronet condition) fixes #3335.

This commit is contained in:
LevelX2 2017-05-21 00:49:59 +02:00
parent ca9f596e4a
commit c26968a096

View file

@ -27,6 +27,9 @@
*/
package mage.cards.b;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.common.AttacksOrBlocksTriggeredAbility;
@ -42,6 +45,8 @@ import mage.constants.SuperType;
import mage.constants.Zone;
import mage.filter.FilterCard;
import mage.filter.FilterPermanent;
import mage.filter.predicate.Predicates;
import mage.filter.predicate.mageobject.CardIdPredicate;
import mage.filter.predicate.mageobject.CardTypePredicate;
import mage.filter.predicate.mageobject.SubtypePredicate;
import mage.filter.predicate.other.AuraCardCanAttachToPermanentId;
@ -53,14 +58,13 @@ import mage.target.Target;
import mage.target.TargetCard;
import mage.target.TargetPermanent;
import java.util.UUID;
/**
* @author noxx
*/
public class BrunaLightOfAlabaster extends CardImpl {
public BrunaLightOfAlabaster(UUID ownerId, CardSetInfo setInfo) {
super(ownerId,setInfo,new CardType[]{CardType.CREATURE},"{3}{W}{W}{U}");
super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{3}{W}{W}{U}");
addSuperType(SuperType.LEGENDARY);
this.subtype.add("Angel");
@ -103,7 +107,7 @@ class BrunaLightOfAlabasterEffect extends OneShotEffect {
@Override
public boolean apply(Game game, Ability source) {
UUID bruna = source.getSourceId();
Player player = game.getPlayer(source.getControllerId());
Player controller = game.getPlayer(source.getControllerId());
FilterPermanent filterAura = new FilterPermanent("Aura");
FilterCard filterAuraCard = new FilterCard("Aura card");
@ -115,64 +119,85 @@ class BrunaLightOfAlabasterEffect extends OneShotEffect {
filterAuraCard.add(new SubtypePredicate("Aura"));
filterAuraCard.add(new AuraCardCanAttachToPermanentId(bruna));
if (player == null) {
if (controller == null) {
return false;
}
Permanent permanent = game.getPermanent(source.getSourceId());
if (permanent == null) {
Permanent sourcePermanent = game.getPermanent(source.getSourceId());
if (sourcePermanent == null) {
return false;
}
List<Permanent> fromBattlefield = new ArrayList<>();
List<Card> fromHandGraveyard = new ArrayList<>();
int countBattlefield = game.getBattlefield().getAllActivePermanents(filterAura, game).size() - permanent.getAttachments().size();
while (player.canRespond()
int countBattlefield = game.getBattlefield().getAllActivePermanents(filterAura, game).size() - sourcePermanent.getAttachments().size();
while (controller.canRespond()
&& countBattlefield > 0
&& player.chooseUse(Outcome.Benefit, "Attach an Aura from the battlefield?", source, game)) {
&& controller.chooseUse(Outcome.Benefit, "Attach an Aura from the battlefield?", source, game)) {
Target targetAura = new TargetPermanent(filterAura);
if (player.choose(Outcome.Benefit, targetAura, source.getSourceId(), game)) {
if (controller.choose(Outcome.Benefit, targetAura, source.getSourceId(), game)) {
Permanent aura = game.getPermanent(targetAura.getFirstTarget());
if (aura != null) {
Target target = aura.getSpellAbility().getTargets().get(0);
if (target != null && target.canTarget(source.getSourceId(), source, game)) {
fromBattlefield.add(aura);
filterAura.add(Predicates.not(new CardIdPredicate(aura.getId())));
}
}
}
countBattlefield = game.getBattlefield().getAllActivePermanents(filterAura, game).size() - sourcePermanent.getAttachments().size();
}
int countHand = controller.getHand().count(filterAuraCard, game);
while (controller.canRespond()
&& countHand > 0
&& controller.chooseUse(Outcome.Benefit, "Attach an Aura from your hand?", source, game)) {
TargetCard targetAura = new TargetCard(Zone.HAND, filterAuraCard);
if (controller.choose(Outcome.Benefit, controller.getHand(), targetAura, game)) {
Card aura = game.getCard(targetAura.getFirstTarget());
if (aura != null) {
Target target = aura.getSpellAbility().getTargets().get(0);
if (target != null && target.canTarget(source.getSourceId(), source, game)) {
fromHandGraveyard.add(aura);
filterAuraCard.add(Predicates.not(new CardIdPredicate(aura.getId())));
}
}
}
countHand = controller.getHand().count(filterAuraCard, game);
}
int countGraveyard = controller.getGraveyard().count(filterAuraCard, game);
while (controller.canRespond()
&& countGraveyard > 0
&& controller.chooseUse(Outcome.Benefit, "Attach an Aura from your graveyard?", source, game)) {
TargetCard targetAura = new TargetCard(Zone.GRAVEYARD, filterAuraCard);
if (controller.choose(Outcome.Benefit, controller.getGraveyard(), targetAura, game)) {
Card aura = game.getCard(targetAura.getFirstTarget());
if (aura != null) {
Target target = aura.getSpellAbility().getTargets().get(0);
if (target != null && target.canTarget(source.getSourceId(), source, game)) {
fromHandGraveyard.add(aura);
filterAuraCard.add(Predicates.not(new CardIdPredicate(aura.getId())));
}
}
}
countGraveyard = controller.getGraveyard().count(filterAuraCard, game);
}
// Move permanents
for (Permanent aura : fromBattlefield) {
Permanent attachedTo = game.getPermanent(aura.getAttachedTo());
if (attachedTo != null) {
attachedTo.removeAttachment(aura.getId(), game);
}
permanent.addAttachment(aura.getId(), game);
sourcePermanent.addAttachment(aura.getId(), game);
}
}
countBattlefield = game.getBattlefield().getAllActivePermanents(filterAura, game).size() - permanent.getAttachments().size();
}
int countHand = player.getHand().count(filterAuraCard, game);
while (player.canRespond()
&& countHand > 0
&& player.chooseUse(Outcome.Benefit, "Attach an Aura from your hand?", source, game)) {
TargetCard targetAura = new TargetCard(Zone.HAND, filterAuraCard);
if (player.choose(Outcome.Benefit, player.getHand(), targetAura, game)) {
Card aura = game.getCard(targetAura.getFirstTarget());
// Move cards
for (Card aura : fromHandGraveyard) {
if (aura != null) {
game.getState().setValue("attachTo:" + aura.getId(), permanent);
aura.putOntoBattlefield(game, Zone.HAND, source.getSourceId(), player.getId());
permanent.addAttachment(aura.getId(), game);
game.getState().setValue("attachTo:" + aura.getId(), sourcePermanent);
controller.moveCards(aura, Zone.BATTLEFIELD, source, game);
sourcePermanent.addAttachment(aura.getId(), game);
}
}
countHand = player.getHand().count(filterAuraCard, game);
}
int countGraveyard = player.getGraveyard().count(filterAuraCard, game);
while (player.canRespond()
&& countGraveyard > 0
&& player.chooseUse(Outcome.Benefit, "Attach an Aura from your graveyard?", source, game)) {
TargetCard targetAura = new TargetCard(Zone.GRAVEYARD, filterAuraCard);
if (player.choose(Outcome.Benefit, player.getGraveyard(), targetAura, game)) {
Card aura = game.getCard(targetAura.getFirstTarget());
if (aura != null) {
game.getState().setValue("attachTo:" + aura.getId(), permanent);
aura.putOntoBattlefield(game, Zone.GRAVEYARD, source.getSourceId(), player.getId());
permanent.addAttachment(aura.getId(), game);
}
}
countGraveyard = player.getGraveyard().count(filterAuraCard, game);
}
return true;
}
}