diff --git a/Mage.Common/src/mage/view/AbilityPickerView.java b/Mage.Common/src/mage/view/AbilityPickerView.java index 49b998b5f4..d84365a59a 100644 --- a/Mage.Common/src/mage/view/AbilityPickerView.java +++ b/Mage.Common/src/mage/view/AbilityPickerView.java @@ -44,9 +44,13 @@ public class AbilityPickerView implements Serializable { private Map choices = new LinkedHashMap(); - public AbilityPickerView(List abilities) { + public AbilityPickerView(String objectName, List abilities) { for (Ability ability: abilities) { - choices.put(ability.getId(), ability.getRule(true)); + if (objectName == null) { + choices.put(ability.getId(), ability.getRule(true)); + } else { + choices.put(ability.getId(), ability.getRule(objectName)); + } } } 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 b174517f96..9993502bb2 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 @@ -1243,7 +1243,7 @@ public class ComputerPlayer> extends PlayerImpl i if (object != null) { LinkedHashMap useableAbilities = getSpellAbilities(object, game.getState().getZone(object.getId()), game); if (useableAbilities != null && useableAbilities.size() > 0) { - game.fireGetChoiceEvent(playerId, name, new ArrayList(useableAbilities.values())); + game.fireGetChoiceEvent(playerId, name, object, new ArrayList(useableAbilities.values())); // TODO: Improve this return (SpellAbility) useableAbilities.values().iterator().next(); } 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 6adfaaf85a..a62fc22642 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 @@ -452,7 +452,7 @@ public class HumanPlayer extends PlayerImpl { } LinkedHashMap useableAbilities = getUseableActivatedAbilities(object, zone, game); if (useableAbilities != null && useableAbilities.size() > 0) { - activateAbility(useableAbilities, game); + activateAbility(useableAbilities, object, game); } } } @@ -539,7 +539,7 @@ public class HumanPlayer extends PlayerImpl { LinkedHashMap useableAbilities = getUseableManaAbilities(object, zone, game); if (useableAbilities != null && useableAbilities.size() > 0) { useableAbilities = ManaUtil.tryToAutoPay(unpaid, useableAbilities); - activateAbility(useableAbilities, game); + activateAbility(useableAbilities, object, game); } } } @@ -741,7 +741,7 @@ public class HumanPlayer extends PlayerImpl { protected void specialAction(Game game) { updateGameStatePriority("specialAction", game); LinkedHashMap specialActions = game.getState().getSpecialActions().getControlledBy(playerId); - game.fireGetChoiceEvent(playerId, name, new ArrayList(specialActions.values())); + game.fireGetChoiceEvent(playerId, name, null, new ArrayList(specialActions.values())); waitForResponse(game); if (response.getUUID() != null) { if (specialActions.containsKey(response.getUUID())) { @@ -750,7 +750,7 @@ public class HumanPlayer extends PlayerImpl { } } - protected void activateAbility(LinkedHashMap abilities, Game game) { + protected void activateAbility(LinkedHashMap abilities, MageObject object, Game game) { updateGameStatePriority("activateAbility", game); if (abilities.size() == 1) { ActivatedAbility ability = abilities.values().iterator().next(); @@ -759,7 +759,7 @@ public class HumanPlayer extends PlayerImpl { return; } } - game.fireGetChoiceEvent(playerId, name, new ArrayList(abilities.values())); + game.fireGetChoiceEvent(playerId, name, object, new ArrayList(abilities.values())); waitForResponse(game); if (response.getUUID() != null) { if (abilities.containsKey(response.getUUID())) { @@ -779,7 +779,7 @@ public class HumanPlayer extends PlayerImpl { if (useableAbilities != null && useableAbilities.size() == 1) { return (SpellAbility) useableAbilities.values().iterator().next(); } else if (useableAbilities != null && useableAbilities.size() > 0) { - game.fireGetChoiceEvent(playerId, name, new ArrayList(useableAbilities.values())); + game.fireGetChoiceEvent(playerId, name, object, new ArrayList(useableAbilities.values())); waitForResponse(game); if (response.getUUID() != null) { if (useableAbilities.containsKey(response.getUUID())) { diff --git a/Mage.Server/src/main/java/mage/server/game/GameController.java b/Mage.Server/src/main/java/mage/server/game/GameController.java index 15d29a37a1..730518dcb2 100644 --- a/Mage.Server/src/main/java/mage/server/game/GameController.java +++ b/Mage.Server/src/main/java/mage/server/game/GameController.java @@ -213,7 +213,11 @@ public class GameController implements GameCallback { playXMana(event.getPlayerId(), event.getMessage()); break; case CHOOSE_ABILITY: - chooseAbility(event.getPlayerId(), event.getAbilities()); + String objectName = null; + if(event.getChoices() != null && event.getChoices().size() > 0) { + objectName = event.getChoices().iterator().next(); + } + chooseAbility(event.getPlayerId(), objectName, event.getAbilities()); break; case CHOOSE_PILE: choosePile(event.getPlayerId(), event.getMessage(), event.getPile1(), event.getPile2()); @@ -510,11 +514,11 @@ public class GameController implements GameCallback { } - private synchronized void chooseAbility(UUID playerId, final List choices) throws MageException { + private synchronized void chooseAbility(UUID playerId, final String objectName, final List choices) throws MageException { perform(playerId, new Command() { @Override public void execute(UUID playerId) { - getGameSession(playerId).chooseAbility(new AbilityPickerView(choices)); + getGameSession(playerId).chooseAbility(new AbilityPickerView(objectName, choices)); } }); } diff --git a/Mage/src/mage/game/Game.java b/Mage/src/mage/game/Game.java index 45bc2de77e..002cafc211 100644 --- a/Mage/src/mage/game/Game.java +++ b/Mage/src/mage/game/Game.java @@ -140,7 +140,7 @@ public interface Game extends MageItem, Serializable { void firePriorityEvent(UUID playerId); void firePlayManaEvent(UUID playerId, String message); void firePlayXManaEvent(UUID playerId, String message); - void fireGetChoiceEvent(UUID playerId, String message, List choices); + void fireGetChoiceEvent(UUID playerId, String message, MageObject object, List choices); void fireGetModeEvent(UUID playerId, String message, Map modes); void fireGetAmountEvent(UUID playerId, String message, int min, int max); void fireChoosePileEvent(UUID playerId, String message, List pile1, List pile2); diff --git a/Mage/src/mage/game/GameImpl.java b/Mage/src/mage/game/GameImpl.java index 2e9a74b8f1..b18b2f123d 100644 --- a/Mage/src/mage/game/GameImpl.java +++ b/Mage/src/mage/game/GameImpl.java @@ -1506,11 +1506,15 @@ public abstract class GameImpl> implements Game, Serializa } @Override - public void fireGetChoiceEvent(UUID playerId, String message, List choices) { + public void fireGetChoiceEvent(UUID playerId, String message, MageObject object, List choices) { if (simulation) { return; } - playerQueryEventSource.chooseAbility(playerId, message, choices); + String objectName = null; + if (object != null) { + objectName = object.getName(); + } + playerQueryEventSource.chooseAbility(playerId, message, objectName, choices); } @Override diff --git a/Mage/src/mage/game/events/PlayerQueryEvent.java b/Mage/src/mage/game/events/PlayerQueryEvent.java index bb6afd44ba..25e26b67b7 100644 --- a/Mage/src/mage/game/events/PlayerQueryEvent.java +++ b/Mage/src/mage/game/events/PlayerQueryEvent.java @@ -30,6 +30,7 @@ package mage.game.events; import java.io.Serializable; import java.util.EventObject; +import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; @@ -142,8 +143,13 @@ public class PlayerQueryEvent extends EventObject implements ExternalEvent, Seri return new PlayerQueryEvent(playerId, message, null, null, null, null, QueryType.ASK, 0, 0, false); } - public static PlayerQueryEvent chooseAbilityEvent(UUID playerId, String message, List choices) { - return new PlayerQueryEvent(playerId, message, choices, null, null, null, QueryType.CHOOSE_ABILITY, 0, 0, false); + public static PlayerQueryEvent chooseAbilityEvent(UUID playerId, String message, String objectName, List choices) { + Set nameAsSet = null; + if (objectName != null) { + nameAsSet = new HashSet(); + nameAsSet.add(objectName); + } + return new PlayerQueryEvent(playerId, message, choices, nameAsSet, null, null, QueryType.CHOOSE_ABILITY, 0, 0, false); } public static PlayerQueryEvent choosePileEvent(UUID playerId, String message, List pile1, List pile2) { diff --git a/Mage/src/mage/game/events/PlayerQueryEventSource.java b/Mage/src/mage/game/events/PlayerQueryEventSource.java index bfebc0d6f1..c52ad84344 100644 --- a/Mage/src/mage/game/events/PlayerQueryEventSource.java +++ b/Mage/src/mage/game/events/PlayerQueryEventSource.java @@ -58,8 +58,8 @@ public class PlayerQueryEventSource implements EventSource, Se dispatcher.fireEvent(PlayerQueryEvent.selectEvent(playerId, message)); } - public void chooseAbility(UUID playerId, String message, List choices) { - dispatcher.fireEvent(PlayerQueryEvent.chooseAbilityEvent(playerId, message, choices)); + public void chooseAbility(UUID playerId, String message, String objectName, List choices) { + dispatcher.fireEvent(PlayerQueryEvent.chooseAbilityEvent(playerId, message, objectName, choices)); } public void choosePile(UUID playerId, String message, List pile1, List pile2) { diff --git a/Mage/src/mage/players/PlayerImpl.java b/Mage/src/mage/players/PlayerImpl.java index 8ac44ae828..d045cb2ef7 100644 --- a/Mage/src/mage/players/PlayerImpl.java +++ b/Mage/src/mage/players/PlayerImpl.java @@ -914,7 +914,6 @@ public abstract class PlayerImpl> implements Player, Ser LinkedHashMap useable = new LinkedHashMap(); if (!(object instanceof Permanent) || ((Permanent)object).canUseActivatedAbilities(game)) { for (ActivatedAbility ability: object.getAbilities().getActivatedAbilities(zone)) { - if (ability.canActivate(playerId, game)) { useable.put(ability.getId(), ability); }