From 32dff5ae723947d3a763775f8161a469f77fcc97 Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Sat, 23 Mar 2013 16:40:15 +0100 Subject: [PATCH] Added replacement of {this} and{source} for selection of replacement effect order. --- .../java/mage/player/ai/ComputerPlayer.java | 2 +- .../src/mage/player/ai/SimulatedPlayerMCTS.java | 2 +- .../src/mage/player/human/HumanPlayer.java | 8 ++++---- .../abilities/effects/ContinuousEffects.java | 17 ++++++++++++++++- Mage/src/mage/players/Player.java | 2 +- 5 files changed, 23 insertions(+), 8 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 3609687e0d..ae21ed49ac 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 @@ -1244,7 +1244,7 @@ public class ComputerPlayer> extends PlayerImpl i } @Override - public int chooseEffect(List rEffects, Game game) { + public int chooseEffect(List rEffects, Game game) { log.debug("chooseEffect"); //TODO: implement this return 0; diff --git a/Mage.Server.Plugins/Mage.Player.AIMCTS/src/mage/player/ai/SimulatedPlayerMCTS.java b/Mage.Server.Plugins/Mage.Player.AIMCTS/src/mage/player/ai/SimulatedPlayerMCTS.java index 64f0401fcf..bc63811200 100644 --- a/Mage.Server.Plugins/Mage.Player.AIMCTS/src/mage/player/ai/SimulatedPlayerMCTS.java +++ b/Mage.Server.Plugins/Mage.Player.AIMCTS/src/mage/player/ai/SimulatedPlayerMCTS.java @@ -374,7 +374,7 @@ public class SimulatedPlayerMCTS extends MCTSPlayer { } @Override - public int chooseEffect(List rEffects, Game game) { + public int chooseEffect(List rEffects, Game game) { if (this.isHuman()) return rnd.nextInt(rEffects.size()); return super.chooseEffect(rEffects, game); 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 6a5d52f81f..70820a49fa 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 @@ -155,12 +155,12 @@ public class HumanPlayer extends PlayerImpl { } @Override - public int chooseEffect(List rEffects, Game game) { + public int chooseEffect(List rEffects, Game game) { updateGameStatePriority("chooseEffect", game); replacementEffectChoice.getChoices().clear(); int count = 1; - for (ReplacementEffect effect: rEffects) { - replacementEffectChoice.getChoices().add(count + ". " + effect.getText(null)); + for (String effectText: rEffects) { + replacementEffectChoice.getChoices().add(count + ". " + effectText); count++; } if (replacementEffectChoice.getChoices().size() == 1) @@ -173,7 +173,7 @@ public class HumanPlayer extends PlayerImpl { replacementEffectChoice.setChoice(response.getString()); count = 1; for (int i = 0; i < rEffects.size(); i++) { - if (replacementEffectChoice.getChoice().equals(count + ". " + rEffects.get(i).getText(null))) + if (replacementEffectChoice.getChoice().equals(count + ". " + rEffects.get(i))) return i; count++; } diff --git a/Mage/src/mage/abilities/effects/ContinuousEffects.java b/Mage/src/mage/abilities/effects/ContinuousEffects.java index 3d537405f2..8fc330de1b 100644 --- a/Mage/src/mage/abilities/effects/ContinuousEffects.java +++ b/Mage/src/mage/abilities/effects/ContinuousEffects.java @@ -34,6 +34,7 @@ import mage.Constants.AsThoughEffectType; import mage.Constants.Duration; import mage.Constants.Layer; import mage.Constants.SubLayer; +import mage.MageObject; import mage.abilities.Ability; import mage.abilities.StaticAbility; import mage.game.Game; @@ -376,7 +377,7 @@ public class ContinuousEffects implements Serializable { else { //20100716 - 616.1c Player player = game.getPlayer(event.getPlayerId()); - index = player.chooseEffect(rEffects, game); + index = player.chooseEffect(getReplacementEffectsTexts(rEffects, game), game); } ReplacementEffect rEffect = rEffects.get(index); caught = rEffect.replaceEvent(event, this.getAbility(rEffect.getId()), game); @@ -541,6 +542,20 @@ public class ContinuousEffects implements Serializable { return effects; } + public List getReplacementEffectsTexts(List rEffects, Game game) { + List texts = new ArrayList(); + for (ReplacementEffect effect: rEffects) { + Ability ability = replacementEffects.getAbility(effect.getId()); + MageObject object = game.getObject(ability.getSourceId()); + if (object != null) { + texts.add(ability.getRule(object.getName())); + } else { + texts.add(effect.getText(null)); + } + } + return texts; + } + } class TimestampSorter implements Comparator { @Override diff --git a/Mage/src/mage/players/Player.java b/Mage/src/mage/players/Player.java index 41aaf02c74..c3ee7c572e 100644 --- a/Mage/src/mage/players/Player.java +++ b/Mage/src/mage/players/Player.java @@ -231,7 +231,7 @@ public interface Player extends MageItem, Copyable { // set the value for X spells and abilities int announceXMana(int min, int max, String message, Game game, Ability ability); - int chooseEffect(List rEffects, Game game); + int chooseEffect(List rEffects, Game game); TriggeredAbility chooseTriggeredAbility(List abilities, Game game); Mode chooseMode(Modes modes, Ability source, Game game); void selectAttackers(Game game, UUID attackingPlayerId);