mirror of
https://github.com/magefree/mage.git
synced 2025-12-20 02:30:08 -08:00
fix #4207 (Indomitable Creativity)
rework to follow game rules for effect order
This commit is contained in:
parent
842fa90e7e
commit
0668a9aebc
1 changed files with 43 additions and 35 deletions
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
package mage.cards.i;
|
||||
|
||||
import mage.abilities.Ability;
|
||||
|
|
@ -15,9 +14,7 @@ import mage.players.Player;
|
|||
import mage.target.TargetPermanent;
|
||||
import mage.target.targetadjustment.XTargetsCountAdjuster;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author LevelX2
|
||||
|
|
@ -67,37 +64,48 @@ class IndomitableCreativityEffect extends OneShotEffect {
|
|||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Player controller = game.getPlayer(source.getControllerId());
|
||||
if (controller != null) {
|
||||
if (controller == null) {
|
||||
return false;
|
||||
}
|
||||
List<Permanent> destroyedPermanents = new ArrayList<>();
|
||||
for (UUID targetId : getTargetPointer().getTargets(game, source)) {
|
||||
Permanent target = game.getPermanent(targetId);
|
||||
if (target != null) {
|
||||
if (target.destroy(source, game, false)) {
|
||||
if (target != null && target.destroy(source, game, false)) {
|
||||
destroyedPermanents.add(target);
|
||||
}
|
||||
}
|
||||
if (destroyedPermanents.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
game.processAction();
|
||||
Map<UUID, Set<Card>> playerToBattlefield = new HashMap<>();
|
||||
for (Permanent permanent : destroyedPermanents) {
|
||||
Player controllerOfDestroyedCreature = game.getPlayer(permanent.getControllerId());
|
||||
if (controllerOfDestroyedCreature != null) {
|
||||
Library library = controllerOfDestroyedCreature.getLibrary();
|
||||
if (library.hasCards()) {
|
||||
Cards cardsToReaveal = new CardsImpl();
|
||||
playerToBattlefield.computeIfAbsent(controllerOfDestroyedCreature.getId(), x -> new HashSet<>());
|
||||
Cards cardsToReveal = new CardsImpl();
|
||||
for (Card card : library.getCards(game)) {
|
||||
cardsToReaveal.add(card);
|
||||
cardsToReveal.add(card);
|
||||
if (card.isCreature(game) || card.isArtifact(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;
|
||||
}
|
||||
}
|
||||
controllerOfDestroyedCreature.revealCards(source, " for destroyed " + permanent.getIdName(), cardsToReaveal, game);
|
||||
controllerOfDestroyedCreature.shuffleLibrary(source, game);
|
||||
controllerOfDestroyedCreature.revealCards(source, " for destroyed " + permanent.getIdName(), cardsToReveal, 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 false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue