From 18b402f7399a9399467f4ff480059e31b8ab5b26 Mon Sep 17 00:00:00 2001 From: androosss Date: Tue, 15 Apr 2025 13:42:40 +0200 Subject: [PATCH] imporved effect --- .../sources/ScryfallImageSupportTokens.java | 4 +- .../src/mage/cards/g/GrenzosRebuttal.java | 132 +++++++----------- 2 files changed, 52 insertions(+), 84 deletions(-) diff --git a/Mage.Client/src/main/java/org/mage/plugins/card/dl/sources/ScryfallImageSupportTokens.java b/Mage.Client/src/main/java/org/mage/plugins/card/dl/sources/ScryfallImageSupportTokens.java index 0e4933480bf..a04ab8ba44f 100644 --- a/Mage.Client/src/main/java/org/mage/plugins/card/dl/sources/ScryfallImageSupportTokens.java +++ b/Mage.Client/src/main/java/org/mage/plugins/card/dl/sources/ScryfallImageSupportTokens.java @@ -1,10 +1,10 @@ package org.mage.plugins.card.dl.sources; +import mage.cards.repository.TokenRepository; + import java.util.HashMap; import java.util.Map; -import mage.cards.repository.TokenRepository; - /** * @author JayDi85 */ diff --git a/Mage.Sets/src/mage/cards/g/GrenzosRebuttal.java b/Mage.Sets/src/mage/cards/g/GrenzosRebuttal.java index fada8b2470c..bb5c5476710 100644 --- a/Mage.Sets/src/mage/cards/g/GrenzosRebuttal.java +++ b/Mage.Sets/src/mage/cards/g/GrenzosRebuttal.java @@ -1,9 +1,5 @@ package mage.cards.g; -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; - import mage.abilities.Ability; import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.common.CreateTokenEffect; @@ -12,9 +8,7 @@ import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; import mage.constants.Outcome; -import mage.filter.common.FilterArtifactPermanent; -import mage.filter.common.FilterCreaturePermanent; -import mage.filter.common.FilterLandPermanent; +import mage.filter.FilterPermanent; import mage.filter.predicate.permanent.ControllerIdPredicate; import mage.game.Game; import mage.game.permanent.Permanent; @@ -23,6 +17,12 @@ import mage.players.Player; import mage.players.PlayerList; import mage.target.Target; import mage.target.TargetPermanent; +import mage.util.CardUtil; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.UUID; /** * @@ -50,6 +50,10 @@ public final class GrenzosRebuttal extends CardImpl { class GrenzosRebuttalEffect extends OneShotEffect { + private static final List cardTypes = Arrays.asList( + CardType.ARTIFACT, CardType.CREATURE, CardType.LAND + ); + GrenzosRebuttalEffect() { super(Outcome.Benefit); this.staticText = "Starting with you, each player chooses an artifact, a creature, and a land from among the permanents controlled by the player to their left." + "Destroy each permanent chosen this way."; @@ -66,92 +70,56 @@ class GrenzosRebuttalEffect extends OneShotEffect { @Override public boolean apply(Game game, Ability source) { - Player controller = game.getPlayer(source.getControllerId()); - if (controller != null) { - List chosenPermanents = new ArrayList<>(); + UUID controllerId = source.getControllerId(); + Player controller = game.getPlayer(controllerId); + if (controller == null || !controller.canRespond()) { + return false; + } + List chosenPermanents = new ArrayList<>(); - PlayerList playerList = game.getState().getPlayerList().copy(); - // set playerlist to controller - while (!playerList.get().equals(source.getControllerId())) { - playerList.getNext(); + PlayerList playerList = game.getState().getPlayersInRange(controllerId, game, true); + + Player currentPlayer = game.getPlayer(playerList.get()); + Player nextPlayer = null; + + while (!playerList.get().equals(controllerId) || nextPlayer == null) { + nextPlayer = game.getPlayer(playerList.getNext()); + if (nextPlayer == null) { + return false; } - Player currentPlayer = game.getPlayer(playerList.get()); - Player nextPlayer; - UUID firstNextPlayer = null; - while (!playerList.getNext().equals(firstNextPlayer)) { - nextPlayer = game.getPlayer(playerList.get()); - if (nextPlayer == null) { - return false; - } - // save first next player to check for iteration stop - if (firstNextPlayer == null) { - firstNextPlayer = nextPlayer.getId(); - } - if (!nextPlayer.canRespond()) { - continue; - } - // if player is in range they choose a creature to control - if (currentPlayer != null && game.getState().getPlayersInRange(controller.getId(), game).contains(currentPlayer.getId())) { - FilterArtifactPermanent filterArtifact = new FilterArtifactPermanent( - "artifact controlled by " + nextPlayer.getLogName()); - filterArtifact.add(new ControllerIdPredicate(nextPlayer.getId())); - FilterCreaturePermanent filterCreature = new FilterCreaturePermanent( - "creature controlled by " + nextPlayer.getLogName()); - filterCreature.add(new ControllerIdPredicate(nextPlayer.getId())); - FilterLandPermanent filterLand = new FilterLandPermanent( - "land controlled by " + nextPlayer.getLogName()); - filterLand.add(new ControllerIdPredicate(nextPlayer.getId())); - Target targetArtifact = new TargetPermanent(1, 1, filterArtifact, true); - Target targetCreature = new TargetPermanent(1, 1, filterCreature, true); - Target targetLand = new TargetPermanent(1, 1, filterLand, true); - if (targetArtifact.canChoose(currentPlayer.getId(), source, game)) { - while (currentPlayer.canRespond() && !targetArtifact.isChosen(game) && targetArtifact.canChoose(currentPlayer.getId(), source, game)) { - currentPlayer.chooseTarget(Outcome.Benefit, targetArtifact, source, game); + if (currentPlayer != null) { + for (CardType cardType : cardTypes) { + String cardTypeText = CardUtil.addArticle(cardType.toString()); + FilterPermanent filter = new FilterPermanent( + cardTypeText + " controlled by " + nextPlayer.getLogName()); + filter.add(cardType.getPredicate()); + filter.add(new ControllerIdPredicate(nextPlayer.getId())); + + Target target = new TargetPermanent(1, 1, filter, true); + + if (target.canChoose(currentPlayer.getId(), source, game)) { + while (currentPlayer.canRespond() && !target.isChosen(game) && target.canChoose(currentPlayer.getId(), source, game)) { + currentPlayer.chooseTarget(Outcome.Benefit, target, source, game); } - Permanent artifact = game.getPermanent(targetArtifact.getFirstTarget()); + Permanent artifact = game.getPermanent(target.getFirstTarget()); if (artifact != null) { chosenPermanents.add(artifact); } - targetArtifact.clearChosen(); - } - - if (targetCreature.canChoose(currentPlayer.getId(), source, game)) { - while (currentPlayer.canRespond() && !targetCreature.isChosen(game) && targetCreature.canChoose(currentPlayer.getId(), source, game)) { - currentPlayer.chooseTarget(Outcome.Benefit, targetCreature, source, game); - } - - Permanent creature = game.getPermanent(targetCreature.getFirstTarget()); - if (creature != null) { - chosenPermanents.add(creature); - } - targetCreature.clearChosen(); - } - - if (targetLand.canChoose(currentPlayer.getId(), source, game)) { - while (currentPlayer.canRespond() && !targetLand.isChosen(game) && targetLand.canChoose(currentPlayer.getId(), source, game)) { - currentPlayer.chooseTarget(Outcome.Benefit, targetLand, source, game); - } - - Permanent land = game.getPermanent(targetLand.getFirstTarget()); - if (land != null) { - chosenPermanents.add(land); - } - targetLand.clearChosen(); + target.clearChosen(); } } - currentPlayer = nextPlayer; } - - for (Permanent permanent : game.getBattlefield().getAllActivePermanents()) { - if (!chosenPermanents.contains(permanent)) { - permanent.destroy(source, game); - } - } - - return true; + currentPlayer = nextPlayer; } - return false; + + for (Permanent permanent : game.getBattlefield().getAllActivePermanents()) { + if (!chosenPermanents.contains(permanent)) { + permanent.destroy(source, game); + } + } + + return true; } } \ No newline at end of file