fix #4207 (Indomitable Creativity)

rework to follow game rules for effect order
This commit is contained in:
xenohedron 2024-09-15 21:12:38 -04:00
parent 842fa90e7e
commit 0668a9aebc

View file

@ -1,4 +1,3 @@
package mage.cards.i; package mage.cards.i;
import mage.abilities.Ability; import mage.abilities.Ability;
@ -15,9 +14,7 @@ import mage.players.Player;
import mage.target.TargetPermanent; import mage.target.TargetPermanent;
import mage.target.targetadjustment.XTargetsCountAdjuster; import mage.target.targetadjustment.XTargetsCountAdjuster;
import java.util.ArrayList; import java.util.*;
import java.util.List;
import java.util.UUID;
/** /**
* @author LevelX2 * @author LevelX2
@ -67,37 +64,48 @@ class IndomitableCreativityEffect extends OneShotEffect {
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId()); Player controller = game.getPlayer(source.getControllerId());
if (controller != null) { if (controller == null) {
return false;
}
List<Permanent> destroyedPermanents = new ArrayList<>(); List<Permanent> destroyedPermanents = new ArrayList<>();
for (UUID targetId : getTargetPointer().getTargets(game, source)) { for (UUID targetId : getTargetPointer().getTargets(game, source)) {
Permanent target = game.getPermanent(targetId); Permanent target = game.getPermanent(targetId);
if (target != null) { if (target != null && target.destroy(source, game, false)) {
if (target.destroy(source, game, false)) {
destroyedPermanents.add(target); destroyedPermanents.add(target);
} }
} }
if (destroyedPermanents.isEmpty()) {
return false;
} }
game.processAction();
Map<UUID, Set<Card>> playerToBattlefield = new HashMap<>();
for (Permanent permanent : destroyedPermanents) { for (Permanent permanent : destroyedPermanents) {
Player controllerOfDestroyedCreature = game.getPlayer(permanent.getControllerId()); Player controllerOfDestroyedCreature = game.getPlayer(permanent.getControllerId());
if (controllerOfDestroyedCreature != null) { if (controllerOfDestroyedCreature != null) {
Library library = controllerOfDestroyedCreature.getLibrary(); Library library = controllerOfDestroyedCreature.getLibrary();
if (library.hasCards()) { if (library.hasCards()) {
Cards cardsToReaveal = new CardsImpl(); playerToBattlefield.computeIfAbsent(controllerOfDestroyedCreature.getId(), x -> new HashSet<>());
Cards cardsToReveal = new CardsImpl();
for (Card card : library.getCards(game)) { for (Card card : library.getCards(game)) {
cardsToReaveal.add(card); cardsToReveal.add(card);
if (card.isCreature(game) || card.isArtifact(game)) { if (card.isCreature(game) || card.isArtifact(game)) {
controllerOfDestroyedCreature.moveCards(card, Zone.EXILED, source, game); controllerOfDestroyedCreature.moveCards(card, Zone.EXILED, source, game);
controllerOfDestroyedCreature.moveCards(card, Zone.BATTLEFIELD, source, game); playerToBattlefield.computeIfAbsent(controllerOfDestroyedCreature.getId(), x -> new HashSet<>()).add(card);
break; break;
} }
} }
controllerOfDestroyedCreature.revealCards(source, " for destroyed " + permanent.getIdName(), cardsToReaveal, game); controllerOfDestroyedCreature.revealCards(source, " for destroyed " + permanent.getIdName(), cardsToReveal, game);
controllerOfDestroyedCreature.shuffleLibrary(source, game);
} }
} }
} }
game.processAction();
for (Map.Entry<UUID, Set<Card>> entry: playerToBattlefield.entrySet()) {
Player player = game.getPlayer(entry.getKey());
if (player != null) {
player.moveCards(entry.getValue(), Zone.BATTLEFIELD, source, game);
player.shuffleLibrary(source, game);
}
}
return true; return true;
} }
return false;
}
} }