Fixed some handling problems of triggered abilities.

This commit is contained in:
LevelX2 2014-05-24 21:10:56 +02:00
parent e02b3377b3
commit 0443311f0e
8 changed files with 30 additions and 28 deletions

View file

@ -28,10 +28,6 @@
package mage.sets.gatecrash; package mage.sets.gatecrash;
import java.util.UUID; import java.util.UUID;
import mage.constants.CardType;
import mage.constants.Outcome;
import mage.constants.Rarity;
import mage.constants.Zone;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.common.DiesAttachedTriggeredAbility; import mage.abilities.common.DiesAttachedTriggeredAbility;
import mage.abilities.dynamicvalue.DynamicValue; import mage.abilities.dynamicvalue.DynamicValue;
@ -39,9 +35,12 @@ import mage.abilities.effects.common.AttachEffect;
import mage.abilities.effects.common.CreateTokenEffect; import mage.abilities.effects.common.CreateTokenEffect;
import mage.abilities.keyword.EnchantAbility; import mage.abilities.keyword.EnchantAbility;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.constants.CardType;
import mage.constants.Outcome;
import mage.constants.Rarity;
import mage.constants.Zone;
import mage.game.Game; import mage.game.Game;
import mage.game.permanent.Permanent; import mage.game.permanent.Permanent;
import mage.game.permanent.token.SoldierToken;
import mage.target.TargetPermanent; import mage.target.TargetPermanent;
import mage.target.common.TargetControlledCreaturePermanent; import mage.target.common.TargetControlledCreaturePermanent;
@ -65,7 +64,6 @@ public class MurderInvestigation extends CardImpl<MurderInvestigation> {
Ability ability = new EnchantAbility(auraTarget.getTargetName()); Ability ability = new EnchantAbility(auraTarget.getTargetName());
this.addAbility(ability); this.addAbility(ability);
// When enchanted creature dies, put X 1/1 white Soldier creature tokens onto the battlefield, where X is its power. // When enchanted creature dies, put X 1/1 white Soldier creature tokens onto the battlefield, where X is its power.
this.addAbility(new DiesAttachedTriggeredAbility(new CreateTokenEffect(new SoldierToken(), new AttachedPermanentPowerCount()), "enchanted creature")); this.addAbility(new DiesAttachedTriggeredAbility(new CreateTokenEffect(new SoldierToken(), new AttachedPermanentPowerCount()), "enchanted creature"));
} }

View file

@ -43,12 +43,12 @@ public abstract class MageTestPlayerBase {
protected Pattern pattern = Pattern.compile("([a-zA-Z]*):([\\w]*):([a-zA-Z ,\\-.!'\\d]*):([\\d]*)(:\\{tapped\\})?"); protected Pattern pattern = Pattern.compile("([a-zA-Z]*):([\\w]*):([a-zA-Z ,\\-.!'\\d]*):([\\d]*)(:\\{tapped\\})?");
protected Map<TestPlayer, List<Card>> handCards = new HashMap<TestPlayer, List<Card>>(); protected Map<TestPlayer, List<Card>> handCards = new HashMap<>();
protected Map<TestPlayer, List<PermanentCard>> battlefieldCards = new HashMap<TestPlayer, List<PermanentCard>>(); protected Map<TestPlayer, List<PermanentCard>> battlefieldCards = new HashMap<>();
protected Map<TestPlayer, List<Card>> graveyardCards = new HashMap<TestPlayer, List<Card>>(); protected Map<TestPlayer, List<Card>> graveyardCards = new HashMap<>();
protected Map<TestPlayer, List<Card>> libraryCards = new HashMap<TestPlayer, List<Card>>(); protected Map<TestPlayer, List<Card>> libraryCards = new HashMap<>();
protected Map<TestPlayer, Map<Zone, String>> commands = new HashMap<TestPlayer, Map<Zone, String>>(); protected Map<TestPlayer, Map<Zone, String>> commands = new HashMap<>();
protected TestPlayer playerA; protected TestPlayer playerA;
protected TestPlayer playerB; protected TestPlayer playerB;
@ -90,7 +90,7 @@ public abstract class MageTestPlayerBase {
* battlefield:ComputerB:Tine Shrike:0 * battlefield:ComputerB:Tine Shrike:0
* graveyard:ComputerB:Tine Shrike:1 * graveyard:ComputerB:Tine Shrike:1
*/ */
protected List<String> expectedResults = new ArrayList<String>(); protected List<String> expectedResults = new ArrayList<>();
protected static final String TESTS_PATH = "tests" + File.separator; protected static final String TESTS_PATH = "tests" + File.separator;
@ -148,8 +148,9 @@ public abstract class MageTestPlayerBase {
private static void deleteSavedGames() { private static void deleteSavedGames() {
File directory = new File("saved/"); File directory = new File("saved/");
if (!directory.exists()) if (!directory.exists()) {
directory.mkdirs(); directory.mkdirs();
}
File[] files = directory.listFiles( File[] files = directory.listFiles(
new FilenameFilter() { new FilenameFilter() {
@Override @Override
@ -170,7 +171,9 @@ public abstract class MageTestPlayerBase {
try { try {
while (scanner.hasNextLine()) { while (scanner.hasNextLine()) {
String line = scanner.nextLine().trim(); String line = scanner.nextLine().trim();
if (line == null || line.isEmpty() || line.startsWith("#")) continue; if (line == null || line.isEmpty() || line.startsWith("#")) {
continue;
}
if (line.startsWith("$include")) { if (line.startsWith("$include")) {
includeFrom(line); includeFrom(line);
continue; continue;
@ -273,7 +276,7 @@ public abstract class MageTestPlayerBase {
if (handCards.containsKey(player)) { if (handCards.containsKey(player)) {
return handCards.get(player); return handCards.get(player);
} }
List<Card> hand = new ArrayList<Card>(); List<Card> hand = new ArrayList<>();
handCards.put(player, hand); handCards.put(player, hand);
return hand; return hand;
} }
@ -282,7 +285,7 @@ public abstract class MageTestPlayerBase {
if (graveyardCards.containsKey(player)) { if (graveyardCards.containsKey(player)) {
return graveyardCards.get(player); return graveyardCards.get(player);
} }
List<Card> grave = new ArrayList<Card>(); List<Card> grave = new ArrayList<>();
graveyardCards.put(player, grave); graveyardCards.put(player, grave);
return grave; return grave;
} }
@ -291,7 +294,7 @@ public abstract class MageTestPlayerBase {
if (libraryCards.containsKey(player)) { if (libraryCards.containsKey(player)) {
return libraryCards.get(player); return libraryCards.get(player);
} }
List<Card> library = new ArrayList<Card>(); List<Card> library = new ArrayList<>();
libraryCards.put(player, library); libraryCards.put(player, library);
return library; return library;
} }
@ -300,7 +303,7 @@ public abstract class MageTestPlayerBase {
if (battlefieldCards.containsKey(player)) { if (battlefieldCards.containsKey(player)) {
return battlefieldCards.get(player); return battlefieldCards.get(player);
} }
List<PermanentCard> battlefield = new ArrayList<PermanentCard>(); List<PermanentCard> battlefield = new ArrayList<>();
battlefieldCards.put(player, battlefield); battlefieldCards.put(player, battlefield);
return battlefield; return battlefield;
} }
@ -309,7 +312,7 @@ public abstract class MageTestPlayerBase {
if (commands.containsKey(player)) { if (commands.containsKey(player)) {
return commands.get(player); return commands.get(player);
} }
Map<Zone, String> command = new HashMap<Zone, String>(); Map<Zone, String> command = new HashMap<>();
commands.put(player, command); commands.put(player, command);
return command; return command;
} }

View file

@ -228,6 +228,7 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement
/** /**
* Define turn number and step to stop the game on. * Define turn number and step to stop the game on.
* The game stops after executing the step
* @param turn * @param turn
* @param step * @param step
*/ */

View file

@ -1100,7 +1100,9 @@ public abstract class GameImpl<T extends GameImpl<T>> implements Game, Serializa
} finally { } finally {
if (top != null) { if (top != null) {
state.getStack().remove(top); state.getStack().remove(top);
state.handleSimultaneousEvent(this); while (state.hasSimultaneousEvents()) {
state.handleSimultaneousEvent(this);
}
} }
} }
} }

View file

@ -11,7 +11,7 @@ import mage.constants.PhaseStep;
*/ */
public class GameOptions implements Serializable { public class GameOptions implements Serializable {
private static GameOptions defInstance = new GameOptions(); private static final GameOptions defInstance = new GameOptions();
public static GameOptions getDefault() { public static GameOptions getDefault() {
return defInstance; return defInstance;

View file

@ -235,7 +235,6 @@ public class Spell<T extends Spell<T>> implements StackObject, Card {
if (this.getSpellAbility() instanceof BestowAbility) { if (this.getSpellAbility() instanceof BestowAbility) {
updateOptionalCosts(0); updateOptionalCosts(0);
result = card.putOntoBattlefield(game, fromZone, ability.getId(), controllerId); result = card.putOntoBattlefield(game, fromZone, ability.getId(), controllerId);
game.getState().handleSimultaneousEvent(game);
return result; return result;
} else { } else {
//20091005 - 608.2b //20091005 - 608.2b
@ -246,7 +245,6 @@ public class Spell<T extends Spell<T>> implements StackObject, Card {
} else { } else {
updateOptionalCosts(0); updateOptionalCosts(0);
result = card.putOntoBattlefield(game, fromZone, ability.getId(), controllerId); result = card.putOntoBattlefield(game, fromZone, ability.getId(), controllerId);
game.getState().handleSimultaneousEvent(game);
return result; return result;
} }
} }

View file

@ -28,13 +28,12 @@
package mage.game.stack; package mage.game.stack;
import java.util.UUID;
import mage.MageObject; import mage.MageObject;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.game.Controllable; import mage.game.Controllable;
import mage.game.Game; import mage.game.Game;
import java.util.UUID;
public interface StackObject extends MageObject, Controllable { public interface StackObject extends MageObject, Controllable {
boolean resolve(Game game); boolean resolve(Game game);

View file

@ -108,12 +108,13 @@ public abstract class Phase<T extends Phase<T>> implements Serializable {
return false; return false;
} }
currentStep = step; currentStep = step;
if (!game.isSimulation() && checkStopOnStepOption(game)) {
return false;
}
if (!game.getState().getTurnMods().skipStep(activePlayerId, getStep().getType())) { if (!game.getState().getTurnMods().skipStep(activePlayerId, getStep().getType())) {
playStep(game); playStep(game);
} }
if (!game.isSimulation() && checkStopOnStepOption(game)) {
return false;
}
} }
if (game.isPaused() || game.gameOver(null)) { if (game.isPaused() || game.gameOver(null)) {
return false; return false;