mirror of
https://github.com/correl/mage.git
synced 2024-11-15 03:00:16 +00:00
Fixed missing watchers from DelayedTriggeredAbility:
* Planeswalkers Mischief - fixed rollback error on play; * Psychic Theft - fixed rollback error on play;
This commit is contained in:
parent
32b7c592c8
commit
848c5b6052
6 changed files with 67 additions and 17 deletions
|
@ -120,7 +120,7 @@ class CyclopeanTombCreateTriggeredEffect extends OneShotEffect {
|
|||
DelayedTriggeredAbility ability = new AtTheBeginOfYourNextUpkeepDelayedTriggeredAbility(new CyclopeanTombEffect(), Duration.EndOfGame, false);
|
||||
ability.setControllerId(source.getControllerId());
|
||||
ability.setSourceId(source.getSourceId());
|
||||
game.addDelayedTriggeredAbility(ability);
|
||||
game.addDelayedTriggeredAbility(ability, source);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -22,7 +22,6 @@ import mage.watchers.common.SpellsCastWatcher;
|
|||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import mage.MageObject;
|
||||
|
||||
/**
|
||||
* @author jeffwadsworth
|
||||
|
@ -76,7 +75,7 @@ class PlaneswalkersMischiefEffect extends OneShotEffect {
|
|||
Cards cards = new CardsImpl(revealedCard);
|
||||
opponent.revealCards(source, cards, game);
|
||||
if (revealedCard.isInstant()
|
||||
|| revealedCard.isSorcery()) {
|
||||
|| revealedCard.isSorcery()) {
|
||||
opponent.moveCardToExileWithInfo(revealedCard, source.getSourceId(), "Planeswalker's Mischief", source.getSourceId(), game, Zone.HAND, true);
|
||||
AsThoughEffect effect = new PlaneswalkersMischiefCastFromExileEffect();
|
||||
effect.setTargetPointer(new FixedTarget(revealedCard.getId()));
|
||||
|
@ -145,7 +144,7 @@ class PlaneswalkersMischiefCondition implements Condition {
|
|||
if (!game.getExile().getExileZone(exileId).contains(cardId)) {
|
||||
return false;
|
||||
}
|
||||
SpellsCastWatcher watcher = game.getState().getWatcher(SpellsCastWatcher.class, source.getSourceId());
|
||||
SpellsCastWatcher watcher = game.getState().getWatcher(SpellsCastWatcher.class);
|
||||
if (watcher != null) {
|
||||
List<Spell> spells = watcher.getSpellsCastThisTurn(source.getControllerId());
|
||||
if (spells != null) {
|
||||
|
|
|
@ -80,7 +80,7 @@ class PsychicTheftEffect extends OneShotEffect {
|
|||
Card chosenCard = null;
|
||||
if (cardsHand > 0) {
|
||||
TargetCard target = new TargetCard(Zone.HAND, filter);
|
||||
if (controller.choose(Outcome.Benefit, opponent.getHand(), target, game)) {
|
||||
if (controller.choose(Outcome.Exile, opponent.getHand(), target, game)) {
|
||||
chosenCard = opponent.getHand().get(target.getFirstTarget(), game);
|
||||
}
|
||||
}
|
||||
|
@ -156,7 +156,7 @@ class PsychicTheftCondition implements Condition {
|
|||
if (!game.getExile().getExileZone(exileId).contains(cardId)) {
|
||||
return false;
|
||||
}
|
||||
SpellsCastWatcher watcher = game.getState().getWatcher(SpellsCastWatcher.class, source.getSourceId());
|
||||
SpellsCastWatcher watcher = game.getState().getWatcher(SpellsCastWatcher.class);
|
||||
if (watcher != null) {
|
||||
List<Spell> spells = watcher.getSpellsCastThisTurn(source.getControllerId());
|
||||
if (spells != null) {
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
package org.mage.test.cards.watchers;
|
||||
|
||||
import mage.constants.PhaseStep;
|
||||
import mage.constants.Zone;
|
||||
import org.junit.Test;
|
||||
import org.mage.test.serverside.base.CardTestPlayerBase;
|
||||
|
||||
/**
|
||||
* @author JayDi85
|
||||
*/
|
||||
public class WatchersFromDelayedTriggeredAbilitiesTest extends CardTestPlayerBase {
|
||||
|
||||
@Test
|
||||
public void test_PsychicTheft_WatcherFromDelayedAbility() {
|
||||
|
||||
// Target player reveals their hand. You choose an instant or sorcery card from it and exile that card.
|
||||
// You may cast that card for as long as it remains exiled. At the beginning of the next end step,
|
||||
// if you haven't cast the card, return it to its owner's hand.
|
||||
addCard(Zone.HAND, playerA, "Psychic Theft", 1); // {1}{U}
|
||||
addCard(Zone.BATTLEFIELD, playerA, "Island", 2);
|
||||
addCard(Zone.BATTLEFIELD, playerA, "Mountain", 1);
|
||||
//
|
||||
addCard(Zone.HAND, playerB, "Lightning Bolt");
|
||||
|
||||
// reveal
|
||||
activateManaAbility(1, PhaseStep.PRECOMBAT_MAIN, playerA, "{T}: Add {U}", 2);
|
||||
checkPlayableAbility("can't play bolt", 1, PhaseStep.PRECOMBAT_MAIN, playerA, "Cast Lightning Bolt", false);
|
||||
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Psychic Theft", playerB);
|
||||
setChoice(playerA, "Lightning Bolt");
|
||||
waitStackResolved(1, PhaseStep.PRECOMBAT_MAIN);
|
||||
|
||||
// can play until end step
|
||||
checkPlayableAbility("can play bolt on 1", 1, PhaseStep.PRECOMBAT_MAIN, playerA, "Cast Lightning Bolt", true);
|
||||
checkPlayableAbility("can play bolt on 2", 2, PhaseStep.PRECOMBAT_MAIN, playerA, "Cast Lightning Bolt", false);
|
||||
|
||||
setStrictChooseMode(true);
|
||||
setStopAt(2, PhaseStep.END_TURN);
|
||||
execute();
|
||||
assertAllCommandsUsed();
|
||||
|
||||
assertHandCount(playerB, "Lightning Bolt", 1);
|
||||
}
|
||||
}
|
|
@ -1,14 +1,5 @@
|
|||
package org.mage.test.serverside.base.impl;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
import mage.MageObject;
|
||||
import mage.Mana;
|
||||
import mage.ObjectColor;
|
||||
|
@ -44,6 +35,12 @@ import org.mage.test.player.TestPlayer;
|
|||
import org.mage.test.serverside.base.CardTestAPI;
|
||||
import org.mage.test.serverside.base.MageTestPlayerBase;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.util.*;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* API for test initialization and asserting the test results.
|
||||
*
|
||||
|
@ -202,7 +199,6 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement
|
|||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @throws GameException
|
||||
* @throws FileNotFoundException
|
||||
*/
|
||||
|
@ -291,7 +287,7 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement
|
|||
}
|
||||
}
|
||||
Assert.assertFalse("Wrong stop command on " + this.stopOnTurn + " / " + this.stopAtStep + " (" + this.stopAtStep.getIndex() + ")"
|
||||
+ " (found actions after stop on " + maxTurn + " / " + maxPhase + ")",
|
||||
+ " (found actions after stop on " + maxTurn + " / " + maxPhase + ")",
|
||||
(maxTurn > this.stopOnTurn) || (maxTurn == this.stopOnTurn && maxPhase > this.stopAtStep.getIndex()));
|
||||
|
||||
for (Player player : currentGame.getPlayers().values()) {
|
||||
|
@ -533,6 +529,9 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement
|
|||
* Removes all cards from player's library from the game. Usually this
|
||||
* should be used once before initialization to form the library in certain
|
||||
* order.
|
||||
* <p>
|
||||
* Warning, if you doesn't add cards to hand then player will lose the game on draw and test
|
||||
* return unused actions (game ended too early)
|
||||
*
|
||||
* @param player {@link Player} to remove all library cards from.
|
||||
*/
|
||||
|
|
|
@ -890,6 +890,7 @@ public class GameState implements Serializable, Copyable<GameState> {
|
|||
// TODO: add sources for triggers - the same way as in addEffect: sources
|
||||
this.triggers.add((TriggeredAbility) ability, sourceId, attachedTo);
|
||||
}
|
||||
|
||||
List<Watcher> watcherList = new ArrayList<>(ability.getWatchers()); // Workaround to prevent ConcurrentModificationException, not clear to me why this is happening now
|
||||
for (Watcher watcher : watcherList) {
|
||||
// TODO: Check that watcher for commanderAbility (where attachedTo = null) also work correctly
|
||||
|
@ -897,6 +898,7 @@ public class GameState implements Serializable, Copyable<GameState> {
|
|||
watcher.setSourceId(attachedTo == null ? ability.getSourceId() : attachedTo.getId());
|
||||
watchers.add(watcher);
|
||||
}
|
||||
|
||||
for (Ability sub : ability.getSubAbilities()) {
|
||||
addAbility(sub, sourceId, attachedTo);
|
||||
}
|
||||
|
@ -949,6 +951,13 @@ public class GameState implements Serializable, Copyable<GameState> {
|
|||
|
||||
public void addDelayedTriggeredAbility(DelayedTriggeredAbility ability) {
|
||||
this.delayed.add(ability);
|
||||
|
||||
List<Watcher> watcherList = new ArrayList<>(ability.getWatchers()); // Workaround to prevent ConcurrentModificationException, not clear to me why this is happening now
|
||||
for (Watcher watcher : watcherList) {
|
||||
watcher.setControllerId(ability.getControllerId());
|
||||
watcher.setSourceId(ability.getSourceId());
|
||||
this.watchers.add(watcher);
|
||||
}
|
||||
}
|
||||
|
||||
public void removeDelayedTriggeredAbility(UUID abilityId) {
|
||||
|
|
Loading…
Reference in a new issue