mirror of
https://github.com/correl/mage.git
synced 2025-03-17 01:06:26 -09:00
Fixed DiscardEachPlayerEffect so that all players discard simultaneously (Fixes #286).
This commit is contained in:
parent
7c6666062e
commit
36d07416b9
1 changed files with 44 additions and 13 deletions
|
@ -1,19 +1,23 @@
|
||||||
package mage.abilities.effects.common;
|
package mage.abilities.effects.common;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import mage.abilities.Ability;
|
import mage.abilities.Ability;
|
||||||
import mage.abilities.Mode;
|
import mage.abilities.Mode;
|
||||||
import mage.abilities.dynamicvalue.DynamicValue;
|
import mage.abilities.dynamicvalue.DynamicValue;
|
||||||
import mage.abilities.dynamicvalue.common.StaticValue;
|
import mage.abilities.dynamicvalue.common.StaticValue;
|
||||||
import mage.abilities.effects.OneShotEffect;
|
import mage.abilities.effects.OneShotEffect;
|
||||||
import mage.cards.Card;
|
import mage.cards.Card;
|
||||||
|
import mage.cards.Cards;
|
||||||
|
import mage.cards.CardsImpl;
|
||||||
import mage.constants.Outcome;
|
import mage.constants.Outcome;
|
||||||
|
import mage.filter.FilterCard;
|
||||||
import mage.game.Game;
|
import mage.game.Game;
|
||||||
import mage.players.Player;
|
import mage.players.Player;
|
||||||
|
import mage.target.Target;
|
||||||
|
import mage.target.common.TargetDiscard;
|
||||||
import mage.util.CardUtil;
|
import mage.util.CardUtil;
|
||||||
|
|
||||||
|
|
||||||
public class DiscardEachPlayerEffect extends OneShotEffect<DiscardEachPlayerEffect> {
|
public class DiscardEachPlayerEffect extends OneShotEffect<DiscardEachPlayerEffect> {
|
||||||
|
|
||||||
protected DynamicValue amount;
|
protected DynamicValue amount;
|
||||||
|
@ -41,19 +45,46 @@ public class DiscardEachPlayerEffect extends OneShotEffect<DiscardEachPlayerEffe
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean apply(Game game, Ability source) {
|
public boolean apply(Game game, Ability source) {
|
||||||
for (UUID playerId : game.getPlayerList()) {
|
Player controller = game.getPlayer(source.getControllerId());
|
||||||
|
// Store for each player the cards to discard, that's important because all discard shall happen at the same time
|
||||||
|
HashMap<UUID, Cards> cardsToDiscard = new HashMap<UUID, Cards>();
|
||||||
|
if (controller != null) {
|
||||||
|
// choose cards to discard
|
||||||
|
for (UUID playerId : controller.getInRange()) {
|
||||||
Player player = game.getPlayer(playerId);
|
Player player = game.getPlayer(playerId);
|
||||||
if (player != null) {
|
if (player != null) {
|
||||||
|
int numberOfCardsToDiscard = Math.min(amount.calculate(game, source), player.getHand().size());
|
||||||
|
Cards cards = new CardsImpl();
|
||||||
if (randomDiscard) {
|
if (randomDiscard) {
|
||||||
int maxAmount = Math.min(amount.calculate(game, source), player.getHand().size());
|
while (cards.size() < numberOfCardsToDiscard) {
|
||||||
for (int i = 0; i < maxAmount; i++) {
|
|
||||||
Card card = player.getHand().getRandom(game);
|
Card card = player.getHand().getRandom(game);
|
||||||
|
if (!cards.contains(card.getId())) {
|
||||||
|
cards.add(card);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Target target = new TargetDiscard(numberOfCardsToDiscard, numberOfCardsToDiscard, new FilterCard(), playerId);
|
||||||
|
target.setRequired(true);
|
||||||
|
player.chooseTarget(outcome, target, source, game);
|
||||||
|
cards.addAll(target.getTargets());
|
||||||
|
}
|
||||||
|
cardsToDiscard.put(playerId, cards);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// discard all choosen cards
|
||||||
|
for (UUID playerId : controller.getInRange()) {
|
||||||
|
Player player = game.getPlayer(playerId);
|
||||||
|
if (player != null) {
|
||||||
|
Cards cardsPlayer = cardsToDiscard.get(playerId);
|
||||||
|
if (cardsPlayer != null) {
|
||||||
|
for (UUID cardId : cardsPlayer) {
|
||||||
|
Card card = game.getCard(cardId);
|
||||||
if (card != null) {
|
if (card != null) {
|
||||||
player.discard(card, source, game);
|
player.discard(card, source, game);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
game.informPlayers(new StringBuilder(player.getName()).append(" discards ").append(Integer.toString(cardsPlayer.size())).append(" card").append(cardsPlayer.size() > 1?"s":"").toString());
|
||||||
player.discard(amount.calculate(game, source), source, game);
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue