Skip to content

Commit

Permalink
Fixed #12874. A code simplification is warranted if someone has the t…
Browse files Browse the repository at this point in the history
…ime. Fix is inline with the rest of it.
  • Loading branch information
jeffwadsworth committed Sep 19, 2024
1 parent b40e722 commit fb63fe0
Showing 1 changed file with 36 additions and 13 deletions.
49 changes: 36 additions & 13 deletions Mage.Sets/src/mage/cards/b/BrunaLightOfAlabaster.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

package mage.cards.b;

import java.util.ArrayList;
Expand Down Expand Up @@ -100,38 +99,54 @@ public boolean apply(Game game, Ability source) {
List<Permanent> fromBattlefield = new ArrayList<>();
List<Card> fromHandGraveyard = new ArrayList<>();

int countBattlefield = game.getBattlefield().getActivePermanents(filterAura, source.getControllerId(), source, game).size() - sourcePermanent.getAttachments().size();
int countBattlefield = (int) (game.getBattlefield().getActivePermanents(filterAura, source.getControllerId(), source, game).size()
- sourcePermanent.getAttachments().stream().map(game::getPermanent).filter(permanent -> permanent != null
&& permanent.hasSubtype(SubType.AURA, game)).count());
while (controller.canRespond()
&& countBattlefield > 0
&& controller.chooseUse(Outcome.Benefit, "Attach an Aura from the battlefield?", source, game)) {
Target targetAura = new TargetPermanent(filterAura);
targetAura.withNotTarget(true);
if (!controller.choose(Outcome.Benefit, targetAura, source, game)) { continue; }
if (!controller.choose(Outcome.Benefit, targetAura, source, game)) {
continue;
}

Permanent aura = game.getPermanent(targetAura.getFirstTarget());
if (aura == null) { continue; }
if (aura == null) {
continue;
}

Target target = aura.getSpellAbility().getTargets().get(0);
if (target == null) { continue; }
if (target == null) {
continue;
}

fromBattlefield.add(aura);
filterAura.add(Predicates.not(new CardIdPredicate(aura.getId())));

countBattlefield = game.getBattlefield().getActivePermanents(filterAura, source.getControllerId(), source, game).size() - sourcePermanent.getAttachments().size();
countBattlefield = (int) (game.getBattlefield().getActivePermanents(filterAura, source.getControllerId(), source, game).size()
- sourcePermanent.getAttachments().stream().map(game::getPermanent).filter(permanent -> permanent != null
&& permanent.hasSubtype(SubType.AURA, game)).count());
}

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, source, game)) { continue; }
if (!controller.choose(Outcome.Benefit, controller.getHand(), targetAura, source, game)) {
continue;
}

Card aura = game.getCard(targetAura.getFirstTarget());
if (aura == null) { continue; }
if (aura == null) {
continue;
}

Target target = aura.getSpellAbility().getTargets().get(0);
if (target == null) { continue; }
if (target == null) {
continue;
}
fromHandGraveyard.add(aura);
filterAuraCard.add(Predicates.not(new CardIdPredicate(aura.getId())));

Expand All @@ -143,13 +158,19 @@ public boolean apply(Game game, Ability source) {
&& 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, source, game)) { continue; }
if (!controller.choose(Outcome.Benefit, controller.getGraveyard(), targetAura, source, game)) {
continue;
}

Card aura = game.getCard(targetAura.getFirstTarget());
if (aura == null) { continue; }
if (aura == null) {
continue;
}

Target target = aura.getSpellAbility().getTargets().get(0);
if (target == null) { continue; }
if (target == null) {
continue;
}

fromHandGraveyard.add(aura);
filterAuraCard.add(Predicates.not(new CardIdPredicate(aura.getId())));
Expand All @@ -168,7 +189,9 @@ public boolean apply(Game game, Ability source) {

// Move cards
for (Card aura : fromHandGraveyard) {
if (aura == null) { continue; }
if (aura == null) {
continue;
}

game.getState().setValue("attachTo:" + aura.getId(), sourcePermanent);
controller.moveCards(aura, Zone.BATTLEFIELD, source, game);
Expand Down

0 comments on commit fb63fe0

Please sign in to comment.