Added method to cast modal spells with specific modes for test player. Added condition for test player to cast a spell only if specific spell is on the stack.

This commit is contained in:
LevelX2 2014-03-19 16:41:43 +01:00
parent 1856df8987
commit 640a792653
3 changed files with 60 additions and 3 deletions

View file

@ -36,9 +36,9 @@ import mage.constants.PhaseStep;
*/
public class PlayerAction {
private int turnNum;
private PhaseStep step;
private String action;
private final int turnNum;
private final PhaseStep step;
private final String action;
public PlayerAction(int turnNum, PhaseStep step, String action) {
this.turnNum = turnNum;

View file

@ -54,7 +54,10 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import mage.abilities.Mode;
import mage.abilities.Modes;
import mage.filter.common.FilterCreatureForCombatBlock;
import mage.game.stack.StackObject;
/**
*
@ -66,6 +69,7 @@ public class TestPlayer extends ComputerPlayer<TestPlayer> {
private final List<PlayerAction> actions = new ArrayList<>();
private final List<String> choices = new ArrayList<>();
private final List<String> targets = new ArrayList<>();
private final List<String> modesSet = new ArrayList<>();
public TestPlayer(String name, RangeOfInfluence range) {
super(name, range);
@ -84,6 +88,10 @@ public class TestPlayer extends ComputerPlayer<TestPlayer> {
choices.add(choice);
}
public void addModeChoice(String mode) {
modesSet.add(mode);
}
public void addTarget(String target) {
targets.add(target);
}
@ -101,6 +109,9 @@ public class TestPlayer extends ComputerPlayer<TestPlayer> {
String command = action.getAction();
command = command.substring(command.indexOf("activate:") + 9);
String[] groups = command.split(";");
if (!checkSpellOnStackCondition(groups, game)) {
break;
}
for (Ability ability: this.getPlayable(game, true)) {
if (ability.toString().startsWith(groups[0])) {
Ability newAbility = ability.copy();
@ -174,6 +185,22 @@ public class TestPlayer extends ComputerPlayer<TestPlayer> {
}
}
@Override
public Mode chooseMode(Modes modes, Ability source, Game game) {
if (!modesSet.isEmpty() && modes.getMaxModes() > modes.getSelectedModes().size()) {
int selectedMode = Integer.parseInt(modesSet.get(0));
int i = 0;
for (Mode mode: modes.values()) {
if (i == selectedMode) {
modesSet.remove(0);
return mode;
}
i++;
}
}
return super.chooseMode(modes, source, game); //To change body of generated methods, choose Tools | Templates.
}
@Override
public boolean choose(Outcome outcome, Choice choice, Game game) {
if (!choices.isEmpty()) {
@ -265,6 +292,18 @@ public class TestPlayer extends ComputerPlayer<TestPlayer> {
return null;
}
private boolean checkSpellOnStackCondition(String[] groups, Game game) {
if (groups.length > 2 && groups[2].startsWith("spellOnStack=")) {
String spellOnStack = groups[2].substring(13);
for (StackObject stackObject: game.getStack()) {
if (stackObject.getName().equals(spellOnStack)) {
return true;
}
}
return false;
}
return true;
}
private boolean addTargets(Ability ability, String[] groups, Game game) {
boolean result = true;
for (int i = 1; i < groups.length; i++) {

View file

@ -634,6 +634,20 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement
player.addAction(turnNum, step, "activate:Cast " + cardName + ";target=" + targetName);
}
/**
* Spell will only be cast, if a spell with the given name is already on the stack
*
* @param turnNum
* @param step
* @param player
* @param cardName
* @param targetName
* @param spellOnStack
*/
public void castSpell(int turnNum, PhaseStep step, TestPlayer player, String cardName, String targetName, String spellOnStack) {
player.addAction(turnNum, step, "activate:Cast " + cardName + ";target=" + targetName + ";spellOnStack=" + spellOnStack);
}
public void activateAbility(int turnNum, PhaseStep step, TestPlayer player, String ability) {
player.addAction(turnNum, step, "activate:" + ability);
}
@ -662,6 +676,10 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement
player.addChoice(choice);
}
public void setModeChoice(TestPlayer player, String choice) {
player.addModeChoice(choice);
}
public void addTarget(TestPlayer player, String target) {
player.addTarget(target);
}