mirror of
https://github.com/correl/mage.git
synced 2024-11-15 19:19:33 +00:00
Some changes to restrained event handling (simultaneous events) (fixes #897).
This commit is contained in:
parent
a5967d9b2a
commit
568f62c66f
8 changed files with 1023 additions and 935 deletions
|
@ -72,6 +72,7 @@ public class SiftThroughSands extends CardImpl {
|
||||||
Effect effect = new DiscardControllerEffect(1);
|
Effect effect = new DiscardControllerEffect(1);
|
||||||
effect.setText(", then discard a card");
|
effect.setText(", then discard a card");
|
||||||
this.getSpellAbility().addEffect(effect);
|
this.getSpellAbility().addEffect(effect);
|
||||||
|
|
||||||
// If you've cast a spell named Peer Through Depths and a spell named Reach Through Mists this turn, you may search your library for a card named The Unspeakable, put it onto the battlefield, then shuffle your library.
|
// If you've cast a spell named Peer Through Depths and a spell named Reach Through Mists this turn, you may search your library for a card named The Unspeakable, put it onto the battlefield, then shuffle your library.
|
||||||
this.getSpellAbility().addEffect(new ConditionalOneShotEffect(new SearchLibraryPutInPlayEffect(new TargetCardInLibrary(filter), false, true), new SiftThroughSandsCondition(), rule));
|
this.getSpellAbility().addEffect(new ConditionalOneShotEffect(new SearchLibraryPutInPlayEffect(new TargetCardInLibrary(filter), false, true), new SiftThroughSandsCondition(), rule));
|
||||||
this.getSpellAbility().addWatcher(new SiftThroughSandsWatcher());
|
this.getSpellAbility().addWatcher(new SiftThroughSandsWatcher());
|
||||||
|
|
|
@ -70,7 +70,6 @@ public class DungeonGeists extends CardImpl {
|
||||||
this.expansionSetCode = "DKA";
|
this.expansionSetCode = "DKA";
|
||||||
this.subtype.add("Spirit");
|
this.subtype.add("Spirit");
|
||||||
|
|
||||||
this.color.setBlue(true);
|
|
||||||
this.power = new MageInt(3);
|
this.power = new MageInt(3);
|
||||||
this.toughness = new MageInt(3);
|
this.toughness = new MageInt(3);
|
||||||
|
|
||||||
|
@ -112,40 +111,52 @@ class DungeonGeistsEffect extends ContinuousRuleModifyingEffectImpl {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean apply(Game game, Ability source) {
|
public boolean checksEventType(GameEvent event, Game game) {
|
||||||
return false;
|
return event.getType() == GameEvent.EventType.UNTAP || event.getType() == GameEvent.EventType.ZONE_CHANGE || event.getType() == GameEvent.EventType.LOST_CONTROL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean applies(GameEvent event, Ability source, Game game) {
|
public boolean applies(GameEvent event, Ability source, Game game) {
|
||||||
// Source must be on the battlefield (it's neccessary to check here because if as response to the enter
|
// Source must be on the battlefield (it's neccessary to check here because if as response to the enter
|
||||||
// the battlefield triggered ability the source dies (or will be exiled), then the ZONE_CHANGE or LOST_CONTROL
|
// the battlefield triggered ability the source dies (or will be exiled), then the ZONE_CHANGE or LOST_CONTROL
|
||||||
// event will happen before this effect is applied ever)
|
// event will happen before this effect is applied ever)
|
||||||
Permanent sourcePermanent = game.getPermanent(source.getSourceId());
|
Permanent sourcePermanent = (Permanent) source.getSourceObjectIfItStillExists(game);
|
||||||
if (sourcePermanent == null || !sourcePermanent.getControllerId().equals(source.getControllerId())) {
|
if (sourcePermanent == null || !sourcePermanent.getControllerId().equals(source.getControllerId())) {
|
||||||
this.used = true;
|
discard();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (event.getType() == GameEvent.EventType.LOST_CONTROL) {
|
switch(event.getType()) {
|
||||||
if (event.getTargetId().equals(source.getSourceId())) {
|
case ZONE_CHANGE:
|
||||||
discard();
|
// end effect if source does a zone move
|
||||||
return false;
|
if (event.getTargetId().equals(source.getSourceId())) {
|
||||||
}
|
ZoneChangeEvent zEvent = (ZoneChangeEvent)event;
|
||||||
|
if (zEvent.getFromZone() == Zone.BATTLEFIELD) {
|
||||||
|
discard();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case UNTAP:
|
||||||
|
// prevent to untap the target creature
|
||||||
|
if (game.getTurn().getStepType() == PhaseStep.UNTAP && event.getTargetId().equals(targetPointer.getFirst(game, source))) {
|
||||||
|
Permanent targetCreature = game.getPermanent(targetPointer.getFirst(game, source));
|
||||||
|
if (targetCreature != null) {
|
||||||
|
return targetCreature.getControllerId().equals(game.getActivePlayerId());
|
||||||
|
} else {
|
||||||
|
discard();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case LOST_CONTROL:
|
||||||
|
// end effect if source control is changed
|
||||||
|
if (event.getTargetId().equals(source.getSourceId())) {
|
||||||
|
discard();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
if (event.getType() == GameEvent.EventType.ZONE_CHANGE && event.getTargetId().equals(source.getSourceId())) {
|
|
||||||
ZoneChangeEvent zEvent = (ZoneChangeEvent)event;
|
|
||||||
if (zEvent.getFromZone() == Zone.BATTLEFIELD) {
|
|
||||||
discard();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (game.getTurn().getStepType() == PhaseStep.UNTAP && event.getType() == GameEvent.EventType.UNTAP) {
|
|
||||||
if (event.getTargetId().equals(targetPointer.getFirst(game, source))) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,16 +74,20 @@ public class DungeonGeistsTest extends CardTestPlayerBase {
|
||||||
public void testWithBlink() {
|
public void testWithBlink() {
|
||||||
addCard(Zone.BATTLEFIELD, playerA, "Island", 4);
|
addCard(Zone.BATTLEFIELD, playerA, "Island", 4);
|
||||||
addCard(Zone.BATTLEFIELD, playerA, "Plains", 4);
|
addCard(Zone.BATTLEFIELD, playerA, "Plains", 4);
|
||||||
|
// When Dungeon Geists enters the battlefield, tap target creature an opponent controls.
|
||||||
|
// That creature doesn't untap during its controller's untap step for as long as you control Dungeon Geists.
|
||||||
addCard(Zone.HAND, playerA, "Dungeon Geists");
|
addCard(Zone.HAND, playerA, "Dungeon Geists");
|
||||||
addCard(Zone.HAND, playerA, "Cloudshift");
|
addCard(Zone.HAND, playerA, "Cloudshift");
|
||||||
addCard(Zone.BATTLEFIELD, playerB, "Craw Wurm");
|
addCard(Zone.BATTLEFIELD, playerB, "Craw Wurm");
|
||||||
addCard(Zone.BATTLEFIELD, playerB, "Elite Vanguard");
|
addCard(Zone.BATTLEFIELD, playerB, "Elite Vanguard");
|
||||||
|
|
||||||
addTarget(playerA, "Craw Wurm"); // first target Craw Wurm
|
|
||||||
addTarget(playerA, "Elite Vanguard"); // after Cloudshift effect (return back to battlefield) target Elite Vanguard
|
|
||||||
|
|
||||||
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Dungeon Geists");
|
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Dungeon Geists");
|
||||||
|
addTarget(playerA, "Craw Wurm"); // first target Craw Wurm
|
||||||
|
|
||||||
castSpell(1, PhaseStep.POSTCOMBAT_MAIN, playerA, "Cloudshift", "Dungeon Geists");
|
castSpell(1, PhaseStep.POSTCOMBAT_MAIN, playerA, "Cloudshift", "Dungeon Geists");
|
||||||
|
addTarget(playerA, "Elite Vanguard"); // after Cloudshift effect (return back to battlefield) target Elite Vanguard
|
||||||
|
|
||||||
setStopAt(2, PhaseStep.DRAW);
|
setStopAt(2, PhaseStep.DRAW);
|
||||||
execute();
|
execute();
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,66 @@
|
||||||
|
/*
|
||||||
|
* To change this license header, choose License Headers in Project Properties.
|
||||||
|
* To change this template file, choose Tools | Templates
|
||||||
|
* and open the template in the editor.
|
||||||
|
*/
|
||||||
|
package org.mage.test.cards.triggers.state;
|
||||||
|
|
||||||
|
import mage.constants.PhaseStep;
|
||||||
|
import mage.constants.Zone;
|
||||||
|
import mage.counters.CounterType;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.mage.test.serverside.base.CardTestPlayerBase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author LevelX2
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class SynodCenturionTest extends CardTestPlayerBase {
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check that Synod Centurion gets sacrificed if no other artifacts are on the battlefield
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testAlone() {
|
||||||
|
addCard(Zone.BATTLEFIELD, playerA, "Mountain", 6);
|
||||||
|
addCard(Zone.BATTLEFIELD, playerA, "Demon's Horn");
|
||||||
|
addCard(Zone.HAND, playerA, "Shatter");
|
||||||
|
addCard(Zone.HAND, playerA, "Synod Centurion");
|
||||||
|
|
||||||
|
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Synod Centurion");
|
||||||
|
castSpell(1, PhaseStep.POSTCOMBAT_MAIN, playerA, "Shatter", "Demon's Horn");
|
||||||
|
|
||||||
|
setStopAt(1, PhaseStep.END_TURN);
|
||||||
|
execute();
|
||||||
|
|
||||||
|
assertGraveyardCount(playerA, "Demon's Horn", 1);
|
||||||
|
assertGraveyardCount(playerA, "Shatter", 1);
|
||||||
|
assertGraveyardCount(playerA, "Synod Centurion", 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check that Synod Centurion gets sacrificed if the only other
|
||||||
|
* artifact left the battlefiled for a short time
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testWithFlicker() {
|
||||||
|
addCard(Zone.BATTLEFIELD, playerA, "Plains", 6);
|
||||||
|
addCard(Zone.BATTLEFIELD, playerA, "Bottle Gnomes");
|
||||||
|
addCard(Zone.HAND, playerA, "Cloudshift");
|
||||||
|
addCard(Zone.HAND, playerA, "Synod Centurion");
|
||||||
|
|
||||||
|
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Synod Centurion");
|
||||||
|
castSpell(1, PhaseStep.POSTCOMBAT_MAIN, playerA, "Cloudshift", "Bottle Gnomes");
|
||||||
|
|
||||||
|
setStopAt(1, PhaseStep.END_TURN);
|
||||||
|
execute();
|
||||||
|
|
||||||
|
assertPermanentCount(playerA, "Bottle Gnomes", 1);
|
||||||
|
assertGraveyardCount(playerA, "Cloudshift", 1);
|
||||||
|
assertGraveyardCount(playerA, "Synod Centurion", 1);
|
||||||
|
}
|
||||||
|
}
|
|
@ -215,14 +215,20 @@ public abstract class AbilityImpl implements Ability {
|
||||||
else {
|
else {
|
||||||
game.addEffect((ContinuousEffect) effect, this);
|
game.addEffect((ContinuousEffect) effect, this);
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* All restrained trigger events are fired now.
|
||||||
|
* To restrain the events is mainly neccessary because of the movement of multiple object at once.
|
||||||
|
* If the event is fired directly as one object moved, other objects are not already in the correct zone
|
||||||
|
* to check for their effects. (e.g. Valakut, the Molten Pinnacle)
|
||||||
|
*/
|
||||||
|
game.getState().handleSimultaneousEvent(game);
|
||||||
|
game.resetShortLivingLKI();
|
||||||
/**
|
/**
|
||||||
* game.applyEffects() has to be done at least for every effect that moves cards/permanent between zones,
|
* game.applyEffects() has to be done at least for every effect that moves cards/permanent between zones,
|
||||||
* so Static effects work as intened if dependant from the moved objects zone it is in
|
* so Static effects work as intened if dependant from the moved objects zone it is in
|
||||||
* Otherwise for example were static abilities with replacement effects deactivated to late
|
* Otherwise for example were static abilities with replacement effects deactivated to late
|
||||||
* Example: {@link org.mage.test.cards.replacement.DryadMilitantTest#testDiesByDestroy testDiesByDestroy}
|
* Example: {@link org.mage.test.cards.replacement.DryadMilitantTest#testDiesByDestroy testDiesByDestroy}
|
||||||
*/
|
*/
|
||||||
// game.applyEffects();
|
|
||||||
// some effects must be applied before next effect is resolved, because effect is dependend.
|
|
||||||
if (effect.applyEffectsAfter()) {
|
if (effect.applyEffectsAfter()) {
|
||||||
game.applyEffects();
|
game.applyEffects();
|
||||||
}
|
}
|
||||||
|
|
|
@ -584,7 +584,7 @@ public abstract class CardImpl extends MageObjectImpl implements Card {
|
||||||
permanent.entersBattlefield(sourceId, game, event.getFromZone(), true);
|
permanent.entersBattlefield(sourceId, game, event.getFromZone(), true);
|
||||||
game.setScopeRelevant(false);
|
game.setScopeRelevant(false);
|
||||||
game.applyEffects();
|
game.applyEffects();
|
||||||
game.fireEvent(new ZoneChangeEvent(permanent, event.getPlayerId(), fromZone, Zone.BATTLEFIELD));
|
game.addSimultaneousEvent(new ZoneChangeEvent(permanent, event.getPlayerId(), fromZone, Zone.BATTLEFIELD));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (facedown) {
|
if (facedown) {
|
||||||
|
|
|
@ -108,7 +108,7 @@ public class PermanentToken extends PermanentImpl {
|
||||||
if (!game.replaceEvent(new ZoneChangeEvent(this, sourceId, this.getControllerId(), Zone.BATTLEFIELD, Zone.EXILED))) {
|
if (!game.replaceEvent(new ZoneChangeEvent(this, sourceId, this.getControllerId(), Zone.BATTLEFIELD, Zone.EXILED))) {
|
||||||
game.rememberLKI(objectId, Zone.BATTLEFIELD, this);
|
game.rememberLKI(objectId, Zone.BATTLEFIELD, this);
|
||||||
if (game.getPlayer(controllerId).removeFromBattlefield(this, game)) {
|
if (game.getPlayer(controllerId).removeFromBattlefield(this, game)) {
|
||||||
game.fireEvent(new ZoneChangeEvent(this, sourceId, this.getControllerId(), Zone.BATTLEFIELD, Zone.EXILED));
|
game.addSimultaneousEvent(new ZoneChangeEvent(this, sourceId, this.getControllerId(), Zone.BATTLEFIELD, Zone.EXILED));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -201,8 +201,8 @@ public class Spell implements StackObject, Card {
|
||||||
result |= spellAbility.resolve(game);
|
result |= spellAbility.resolve(game);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
game.getState().handleSimultaneousEvent(game);
|
// game.getState().handleSimultaneousEvent(game);
|
||||||
game.resetShortLivingLKI();
|
// game.resetShortLivingLKI();
|
||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue