mirror of
https://github.com/magefree/mage.git
synced 2025-12-20 02:30:08 -08:00
fix #12245 (Fight or Flight)
This commit is contained in:
parent
5d19fe7583
commit
a0c3c7a7de
1 changed files with 42 additions and 40 deletions
|
|
@ -1,10 +1,5 @@
|
|||
|
||||
package mage.cards.f;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.common.BeginningOfCombatTriggeredAbility;
|
||||
import mage.abilities.effects.OneShotEffect;
|
||||
|
|
@ -18,12 +13,18 @@ import mage.constants.Outcome;
|
|||
import mage.constants.TargetController;
|
||||
import mage.filter.StaticFilters;
|
||||
import mage.filter.common.FilterCreaturePermanent;
|
||||
import mage.filter.predicate.permanent.ControllerIdPredicate;
|
||||
import mage.game.Game;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.players.Player;
|
||||
import mage.target.common.TargetCreaturePermanent;
|
||||
import mage.target.targetpointer.FixedTarget;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author LevelX2 & L_J
|
||||
|
|
@ -67,41 +68,42 @@ class FightOrFlightEffect extends OneShotEffect {
|
|||
public boolean apply(Game game, Ability source) {
|
||||
Player player = game.getPlayer(source.getControllerId());
|
||||
Player targetPlayer = game.getPlayer(game.getCombat().getAttackingPlayerId());
|
||||
if (player != null && targetPlayer != null) {
|
||||
int count = game.getBattlefield().countAll(StaticFilters.FILTER_PERMANENT_CREATURES, targetPlayer.getId(), game);
|
||||
TargetCreaturePermanent creatures = new TargetCreaturePermanent(0, count, new FilterCreaturePermanent("creatures to put in the first pile"), true);
|
||||
List<Permanent> pile1 = new ArrayList<>();
|
||||
creatures.setRequired(false);
|
||||
if (player.choose(Outcome.Neutral, creatures, source, game)) {
|
||||
List<UUID> targets = creatures.getTargets();
|
||||
for (UUID targetId : targets) {
|
||||
Permanent p = game.getPermanent(targetId);
|
||||
if (p != null) {
|
||||
pile1.add(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
List<Permanent> pile2 = new ArrayList<>();
|
||||
for (Permanent p : game.getBattlefield().getAllActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, targetPlayer.getId(), game)) {
|
||||
if (!pile1.contains(p)) {
|
||||
pile2.add(p);
|
||||
}
|
||||
}
|
||||
|
||||
boolean choice = targetPlayer.choosePile(outcome, "Choose which pile can attack this turn.", pile1, pile2, game);
|
||||
List<Permanent> chosenPile = choice ? pile2 : pile1;
|
||||
List<Permanent> otherPile = choice ? pile1 : pile2;
|
||||
for (Permanent permanent : chosenPile) {
|
||||
if (permanent != null) {
|
||||
RestrictionEffect effect = new CantAttackTargetEffect(Duration.EndOfTurn);
|
||||
effect.setText("");
|
||||
effect.setTargetPointer(new FixedTarget(permanent, game));
|
||||
game.addEffect(effect, source);
|
||||
}
|
||||
}
|
||||
game.informPlayers("Creatures that can attack this turn: " + otherPile.stream().map(Permanent::getLogName).collect(Collectors.joining(", ")));
|
||||
return true;
|
||||
if (player == null || targetPlayer == null) {
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
FilterCreaturePermanent filter = new FilterCreaturePermanent("creatures to put in the first pile");
|
||||
filter.add(new ControllerIdPredicate(targetPlayer.getId()));
|
||||
TargetCreaturePermanent creatures = new TargetCreaturePermanent(0, Integer.MAX_VALUE, filter, true);
|
||||
List<Permanent> pile1 = new ArrayList<>();
|
||||
creatures.setRequired(false);
|
||||
if (player.choose(Outcome.Neutral, creatures, source, game)) {
|
||||
List<UUID> targets = creatures.getTargets();
|
||||
for (UUID targetId : targets) {
|
||||
Permanent p = game.getPermanent(targetId);
|
||||
if (p != null) {
|
||||
pile1.add(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
List<Permanent> pile2 = new ArrayList<>();
|
||||
for (Permanent p : game.getBattlefield().getAllActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, targetPlayer.getId(), game)) {
|
||||
if (!pile1.contains(p)) {
|
||||
pile2.add(p);
|
||||
}
|
||||
}
|
||||
|
||||
boolean choice = targetPlayer.choosePile(outcome, "Choose which pile can attack this turn.", pile1, pile2, game);
|
||||
List<Permanent> chosenPile = choice ? pile2 : pile1;
|
||||
List<Permanent> otherPile = choice ? pile1 : pile2;
|
||||
for (Permanent permanent : chosenPile) {
|
||||
if (permanent != null) {
|
||||
RestrictionEffect effect = new CantAttackTargetEffect(Duration.EndOfTurn);
|
||||
effect.setText("");
|
||||
effect.setTargetPointer(new FixedTarget(permanent, game));
|
||||
game.addEffect(effect, source);
|
||||
}
|
||||
}
|
||||
game.informPlayers("Creatures that can attack this turn: " + otherPile.stream().map(Permanent::getLogName).collect(Collectors.joining(", ")));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue