From 4a5140d0abc02a145f21e793c886d712db6dfb2c Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Thu, 26 Feb 2015 13:52:02 +0100 Subject: [PATCH] Fixed a bug of cost paying handling not showing only the left over unpaid part of mana cost (fixes #185). Added the name of the object the cost is paid for to the feedback panel. --- .../java/mage/player/ai/ComputerPlayer.java | 2 +- .../src/mage/player/human/HumanPlayer.java | 8 +++--- .../abilities/costs/mana/ManaCostImpl.java | 6 +++- .../abilities/costs/mana/ManaCostsImpl.java | 26 +++-------------- Mage/src/mage/players/Player.java | 2 +- Mage/src/mage/util/ManaUtil.java | 28 +++++++++++++++++++ 6 files changed, 43 insertions(+), 29 deletions(-) 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 11d8d71fae..83df4dce0e 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 @@ -1011,7 +1011,7 @@ public class ComputerPlayer extends PlayerImpl implements Player { } @Override - public boolean playMana(ManaCost unpaid, Game game) { + public boolean playMana(ManaCost unpaid, String promptText, Game game) { payManaMode = true; boolean result = playManaHandling(unpaid, game); payManaMode = false; 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 9c863bc9f3..bef521c8db 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 @@ -606,17 +606,17 @@ public class HumanPlayer extends PlayerImpl { @Override - public boolean playMana(ManaCost unpaid, Game game) { + public boolean playMana(ManaCost unpaid, String promptText, Game game) { payManaMode = true; - boolean result = playManaHandling(unpaid, game); + boolean result = playManaHandling(unpaid, promptText, game); payManaMode = false; return result; } - protected boolean playManaHandling(ManaCost unpaid, Game game) { + protected boolean playManaHandling(ManaCost unpaid, String promptText, Game game) { updateGameStatePriority("playMana", game); - game.firePlayManaEvent(playerId, "Pay " + unpaid.getText()); + game.firePlayManaEvent(playerId, "Pay " + promptText); waitForResponse(game); if (!this.isInGame()) { return false; diff --git a/Mage/src/mage/abilities/costs/mana/ManaCostImpl.java b/Mage/src/mage/abilities/costs/mana/ManaCostImpl.java index 465a60b4fd..55407b2415 100644 --- a/Mage/src/mage/abilities/costs/mana/ManaCostImpl.java +++ b/Mage/src/mage/abilities/costs/mana/ManaCostImpl.java @@ -39,6 +39,7 @@ import mage.filter.Filter; import mage.game.Game; import mage.players.ManaPool; import mage.players.Player; +import mage.util.ManaUtil; public abstract class ManaCostImpl extends CostImpl implements ManaCost { @@ -218,12 +219,15 @@ public abstract class ManaCostImpl extends CostImpl implements ManaCost { Player player = game.getPlayer(controllerId); assignPayment(game, ability, player.getManaPool()); while (!isPaid()) { - if (player.playMana(this, game)) { + ManaCost unpaid = this.getUnpaid(); + String promptText = ManaUtil.addSpecialManaPayAbilities(ability, game, unpaid); + if (player.playMana(unpaid, promptText, game)) { assignPayment(game, ability, player.getManaPool()); } else { return false; } + game.getState().getSpecialActions().removeManaActions(); } return true; } diff --git a/Mage/src/mage/abilities/costs/mana/ManaCostsImpl.java b/Mage/src/mage/abilities/costs/mana/ManaCostsImpl.java index 7b34a9701c..77f84f7eae 100644 --- a/Mage/src/mage/abilities/costs/mana/ManaCostsImpl.java +++ b/Mage/src/mage/abilities/costs/mana/ManaCostsImpl.java @@ -37,7 +37,6 @@ import mage.MageObject; import mage.Mana; import mage.abilities.Ability; import mage.abilities.costs.VariableCost; -import mage.abilities.keyword.DelveAbility; import mage.abilities.mana.ManaOptions; import mage.constants.ColoredManaSymbol; import mage.filter.Filter; @@ -45,6 +44,7 @@ import mage.game.Game; import mage.players.ManaPool; import mage.players.Player; import mage.target.Targets; +import mage.util.ManaUtil; /** * @author BetaSteward_at_googlemail.com @@ -121,8 +121,9 @@ public class ManaCostsImpl extends ArrayList implements M Player player = game.getPlayer(controllerId); assignPayment(game, ability, player.getManaPool()); while (!isPaid()) { - addSpecialManaPayAbilities(ability, game); - if (player.playMana(this.getUnpaid(), game)) { + ManaCost unpaid = this.getUnpaid(); + String promptText = ManaUtil.addSpecialManaPayAbilities(ability, game, unpaid); + if (player.playMana(unpaid, promptText, game)) { assignPayment(game, ability, player.getManaPool()); } else { return false; @@ -132,25 +133,6 @@ public class ManaCostsImpl extends ArrayList implements M return true; } - /** - * This activates the special button if there exists special ways to pay the mana (Delve, Convoke) - * - * @param ability - * @param game - */ - private void addSpecialManaPayAbilities(Ability source, Game game) { - // check for special mana payment possibilities - MageObject mageObject = source.getSourceObject(game); - if (mageObject != null) { - for (Ability ability :mageObject.getAbilities()) { - if (ability instanceof AlternateManaPaymentAbility) { - ((AlternateManaPaymentAbility) ability).addSpecialAction(source, game, getUnpaid()); - } - } - } - } - - /** * bookmarks the current state and restores it if player doesn't pay the mana cost * diff --git a/Mage/src/mage/players/Player.java b/Mage/src/mage/players/Player.java index b22e86a7fd..a9d847a803 100644 --- a/Mage/src/mage/players/Player.java +++ b/Mage/src/mage/players/Player.java @@ -299,7 +299,7 @@ public interface Player extends MageItem, Copyable { boolean chooseUse(Outcome outcome, String message, Game game); boolean choose(Outcome outcome, Choice choice, Game game); boolean choosePile(Outcome outcome, String message, List pile1, List pile2, Game game); - boolean playMana(ManaCost unpaid, Game game); + boolean playMana(ManaCost unpaid, String promptText, Game game); /** * Moves the cards from cards to the bottom of the players library. diff --git a/Mage/src/mage/util/ManaUtil.java b/Mage/src/mage/util/ManaUtil.java index 160a483d45..080efef553 100644 --- a/Mage/src/mage/util/ManaUtil.java +++ b/Mage/src/mage/util/ManaUtil.java @@ -10,6 +10,10 @@ import java.util.HashSet; import java.util.LinkedHashMap; import java.util.Set; import java.util.UUID; +import mage.MageObject; +import mage.abilities.Ability; +import mage.abilities.costs.mana.AlternateManaPaymentAbility; +import mage.game.Game; /** * @author noxx @@ -334,4 +338,28 @@ public class ManaUtil { return useableAbilities; } + + /** + * This activates the special button inthe feedback panel of the client + * if there exists special ways to pay the mana (e.g. Delve, Convoke) + * + * @param source ability the mana costs have to be paid for + * @param game + * @param unpaid mana that has still to be paid + * @return message to be shown in human players feedback area + */ + public static String addSpecialManaPayAbilities(Ability source, Game game, ManaCost unpaid) { + // check for special mana payment possibilities + MageObject mageObject = source.getSourceObject(game); + if (mageObject != null) { + for (Ability ability :mageObject.getAbilities()) { + if (ability instanceof AlternateManaPaymentAbility) { + ((AlternateManaPaymentAbility) ability).addSpecialAction(source, game, unpaid); + } + } + return unpaid.getText() + "
" + mageObject.getLogName() + "
"; + } else { + return unpaid.getText(); + } + } }