diff --git a/Mage.Common/src/mage/view/CombatGroupView.java b/Mage.Common/src/mage/view/CombatGroupView.java index f6923e3610..90465ae4e1 100644 --- a/Mage.Common/src/mage/view/CombatGroupView.java +++ b/Mage.Common/src/mage/view/CombatGroupView.java @@ -61,7 +61,7 @@ public class CombatGroupView implements Serializable { if (attacker != null) attackers.put(id, new PermanentView(attacker, game.getCard(attacker.getId()))); } - for (UUID id: combatGroup.getBlockers()) { + for (UUID id: combatGroup.getBlockerOrder()) { Permanent blocker = game.getPermanent(id); if (blocker != null) blockers.put(id, new PermanentView(blocker, game.getCard(blocker.getId()))); diff --git a/Mage.Server.Plugins/Mage.Player.AI/src/main/java/mage/player/ai/ComputerPlayer.java b/Mage.Server.Plugins/Mage.Player.AI/src/main/java/mage/player/ai/ComputerPlayer.java index 8eb6816a40..50374941ea 100644 --- a/Mage.Server.Plugins/Mage.Player.AI/src/main/java/mage/player/ai/ComputerPlayer.java +++ b/Mage.Server.Plugins/Mage.Player.AI/src/main/java/mage/player/ai/ComputerPlayer.java @@ -880,6 +880,12 @@ public class ComputerPlayer<T extends ComputerPlayer<T>> extends PlayerImpl<T> i return min; } + @Override + public UUID chooseBlockerOrder(Cards blockers, Game game) { + //TODO: improve this + return blockers.iterator().next(); + } + @Override protected List<Permanent> getAvailableManaProducers(Game game) { // logger.debug("getAvailableManaProducers"); diff --git a/Mage.Server.Plugins/Mage.Player.Human/src/mage/player/human/HumanPlayer.java b/Mage.Server.Plugins/Mage.Player.Human/src/mage/player/human/HumanPlayer.java index 584aef5998..ef7d60621c 100644 --- a/Mage.Server.Plugins/Mage.Player.Human/src/mage/player/human/HumanPlayer.java +++ b/Mage.Server.Plugins/Mage.Player.Human/src/mage/player/human/HumanPlayer.java @@ -458,6 +458,21 @@ public class HumanPlayer extends PlayerImpl<HumanPlayer> { } } + @Override + public UUID chooseBlockerOrder(Cards blockers, Game game) { + while (!abort) { + game.fireSelectTargetEvent(playerId, "Pick blocker", blockers, true); + waitForResponse(); + if (response.getUUID() != null) { + for (Card card: blockers.getCards(game)) { + if (card.getId().equals(response.getUUID())) + return card.getId(); + } + } + } + return null; + } + protected void selectCombatGroup(UUID blockerId, Game game) { TargetAttackingCreature target = new TargetAttackingCreature(); game.fireSelectTargetEvent(playerId, "Select attacker to block", target.possibleTargets(null, playerId, game), target.isRequired(), null); diff --git a/Mage.Server/plugins/mage-player-ai.jar b/Mage.Server/plugins/mage-player-ai.jar index 6c7e92c2ca..1a451360d7 100644 Binary files a/Mage.Server/plugins/mage-player-ai.jar and b/Mage.Server/plugins/mage-player-ai.jar differ diff --git a/Mage.Server/plugins/mage-player-human.jar b/Mage.Server/plugins/mage-player-human.jar index 2746ea14c0..9dd67a8637 100644 Binary files a/Mage.Server/plugins/mage-player-human.jar and b/Mage.Server/plugins/mage-player-human.jar differ diff --git a/Mage/src/mage/game/combat/Combat.java b/Mage/src/mage/game/combat/Combat.java index 785e43dbde..9c986f50b4 100644 --- a/Mage/src/mage/game/combat/Combat.java +++ b/Mage/src/mage/game/combat/Combat.java @@ -61,7 +61,7 @@ public class Combat implements Serializable, Copyable<Combat> { protected List<CombatGroup> groups = new ArrayList<CombatGroup>(); protected Set<UUID> defenders = new HashSet<UUID>(); - protected UUID attackerId; + protected UUID attackerId; //the player that is attacking public Combat() {} @@ -346,7 +346,9 @@ public class Combat implements Serializable, Copyable<Combat> { } public void damageAssignmentOrder(Game game) { - //TODO: set damage assignment order + for (CombatGroup group: groups) { + group.pickBlockerOrder(attackerId, game); + } } @Override diff --git a/Mage/src/mage/game/combat/CombatGroup.java b/Mage/src/mage/game/combat/CombatGroup.java index f38b4e6dd1..8dabe4baae 100644 --- a/Mage/src/mage/game/combat/CombatGroup.java +++ b/Mage/src/mage/game/combat/CombatGroup.java @@ -34,6 +34,8 @@ import java.util.*; import mage.abilities.keyword.DoubleStrikeAbility; import mage.abilities.keyword.FirstStrikeAbility; import mage.abilities.keyword.TrampleAbility; +import mage.cards.Cards; +import mage.cards.CardsImpl; import mage.game.Game; import mage.game.events.GameEvent; import mage.game.permanent.Permanent; @@ -271,6 +273,29 @@ public class CombatGroup implements Serializable, Copyable<CombatGroup> { } } + public void pickBlockerOrder(UUID playerId, Game game) { + if (blockers.isEmpty()) + return; + Player player = game.getPlayer(playerId); + List<UUID> blockerList = new ArrayList<UUID>(blockers); + blockerOrder.clear(); + while (true) { + if (blockerList.size() == 1) { + blockerOrder.add(blockerList.get(0)); + break; + } + else { + Cards blockerCards = new CardsImpl(); + for (UUID blockerId: blockerList) { + blockerCards.add(game.getCard(blockerId)); + } + UUID blockerId = player.chooseBlockerOrder(blockerCards, game); + blockerOrder.add(blockerId); + blockerList.remove(blockerId); + } + } + } + public int totalAttackerDamage(Game game) { int total = 0; for (UUID attackerId: attackers) { diff --git a/Mage/src/mage/players/Player.java b/Mage/src/mage/players/Player.java index 9683e5fe58..160630a609 100644 --- a/Mage/src/mage/players/Player.java +++ b/Mage/src/mage/players/Player.java @@ -158,6 +158,7 @@ public interface Player extends MageItem, Copyable<Player> { public abstract TriggeredAbility chooseTriggeredAbility(TriggeredAbilities abilities, Game game); public abstract void selectAttackers(Game game); public abstract void selectBlockers(Game game); + public abstract UUID chooseBlockerOrder(Cards blockers, Game game); public abstract void assignDamage(int damage, List<UUID> targets, UUID sourceId, Game game); public abstract int getAmount(int min, int max, String message, Game game); public abstract void sideboard(Match match, Deck deck);