Added replacement of {this} and{source} for selection of replacement effect order.

This commit is contained in:
LevelX2 2013-03-23 16:40:15 +01:00
parent 27c96d7ea9
commit 32dff5ae72
5 changed files with 23 additions and 8 deletions

View file

@ -1244,7 +1244,7 @@ public class ComputerPlayer<T extends ComputerPlayer<T>> extends PlayerImpl<T> i
}
@Override
public int chooseEffect(List<ReplacementEffect> rEffects, Game game) {
public int chooseEffect(List<String> rEffects, Game game) {
log.debug("chooseEffect");
//TODO: implement this
return 0;

View file

@ -374,7 +374,7 @@ public class SimulatedPlayerMCTS extends MCTSPlayer {
}
@Override
public int chooseEffect(List<ReplacementEffect> rEffects, Game game) {
public int chooseEffect(List<String> rEffects, Game game) {
if (this.isHuman())
return rnd.nextInt(rEffects.size());
return super.chooseEffect(rEffects, game);

View file

@ -155,12 +155,12 @@ public class HumanPlayer extends PlayerImpl<HumanPlayer> {
}
@Override
public int chooseEffect(List<ReplacementEffect> rEffects, Game game) {
public int chooseEffect(List<String> 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<HumanPlayer> {
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++;
}

View file

@ -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<String> getReplacementEffectsTexts(List<ReplacementEffect> rEffects, Game game) {
List<String> texts = new ArrayList<String>();
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<ContinuousEffect> {
@Override

View file

@ -231,7 +231,7 @@ public interface Player extends MageItem, Copyable<Player> {
// set the value for X spells and abilities
int announceXMana(int min, int max, String message, Game game, Ability ability);
int chooseEffect(List<ReplacementEffect> rEffects, Game game);
int chooseEffect(List<String> rEffects, Game game);
TriggeredAbility chooseTriggeredAbility(List<TriggeredAbility> abilities, Game game);
Mode chooseMode(Modes modes, Ability source, Game game);
void selectAttackers(Game game, UUID attackingPlayerId);