mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-18 11:48:02 +00:00
- Introduce PhaseIn and PhaseOut triggers
- Added Teferi's Imp (as an example of both)
This commit is contained in:
@@ -4879,7 +4879,7 @@ public class Card extends GameEntity implements Comparable<Card> {
|
||||
final boolean phasingIn = this.isPhasedOut();
|
||||
|
||||
if (!this.switchPhaseState()) {
|
||||
// Switch Phase State returns False if the Permanent can't Phase Out
|
||||
// Switch Phase State bails early if the Permanent can't Phase Out
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -4913,6 +4913,15 @@ public class Card extends GameEntity implements Comparable<Card> {
|
||||
return false;
|
||||
}
|
||||
|
||||
final Map<String, Object> runParams = new TreeMap<String, Object>();
|
||||
runParams.put("Card", this);
|
||||
|
||||
if (!this.isPhasedOut()) {
|
||||
// If this is currently PhasedIn, it's about to phase out.
|
||||
// Run trigger before it does because triggers don't work with phased out objects
|
||||
getGame().getTriggerHandler().runTrigger(TriggerType.PhaseOut, runParams, false);
|
||||
}
|
||||
|
||||
this.phasedOut = !this.phasedOut;
|
||||
final Combat combat = this.getGame().getPhaseHandler().getCombat();
|
||||
if (combat != null && this.phasedOut) {
|
||||
@@ -4934,6 +4943,12 @@ public class Card extends GameEntity implements Comparable<Card> {
|
||||
getGame().getAction().exile(this);
|
||||
getGame().getTriggerHandler().clearSuppression(TriggerType.ChangesZone);
|
||||
}
|
||||
|
||||
if (!this.phasedOut) {
|
||||
// Just phased in, time to run the phased in trigger
|
||||
getGame().getTriggerHandler().runTrigger(TriggerType.PhaseIn, runParams, false);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
package forge.game.trigger;
|
||||
|
||||
import forge.game.card.Card;
|
||||
import forge.game.spellability.SpellAbility;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class TriggerPhaseIn extends Trigger {
|
||||
|
||||
public TriggerPhaseIn(final Map<String, String> params, final Card host, final boolean intrinsic) {
|
||||
super(params, host, intrinsic);
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public final boolean performTest(final java.util.Map<String, Object> runParams2) {
|
||||
final Card phaser = (Card) runParams2.get("Card");
|
||||
|
||||
if (this.mapParams.containsKey("ValidCard")) {
|
||||
if (!phaser.isValid(this.mapParams.get("ValidCard").split(","), this.getHostCard().getController(),
|
||||
this.getHostCard())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public final void setTriggeringObjects(final SpellAbility sa) {
|
||||
sa.setTriggeringObject("Card", this.getRunParams().get("Card"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package forge.game.trigger;
|
||||
|
||||
import forge.game.card.Card;
|
||||
import forge.game.spellability.SpellAbility;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class TriggerPhaseOut extends Trigger {
|
||||
|
||||
public TriggerPhaseOut(final Map<String, String> params, final Card host, final boolean intrinsic) {
|
||||
super(params, host, intrinsic);
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public final boolean performTest(final java.util.Map<String, Object> runParams2) {
|
||||
final Card phaser = (Card) runParams2.get("Card");
|
||||
|
||||
if (this.mapParams.containsKey("ValidCard")) {
|
||||
if (this.mapParams.get("ValidCard").equals("Card.Self")) {
|
||||
// Since Phased out cards aren't visible in .isValid, use a special check here.
|
||||
// NOTE: All Phase Out Triggers should use ValidCard$ Card.Self
|
||||
if (phaser != this.getHostCard()) {
|
||||
return false;
|
||||
}
|
||||
} else if (!phaser.isValid(this.mapParams.get("ValidCard").split(","), this.getHostCard().getController(),
|
||||
this.getHostCard())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public final void setTriggeringObjects(final SpellAbility sa) {
|
||||
sa.setTriggeringObject("Card", this.getRunParams().get("Card"));
|
||||
}
|
||||
}
|
||||
@@ -46,6 +46,8 @@ public enum TriggerType {
|
||||
NewGame(TriggerNewGame.class),
|
||||
PayCumulativeUpkeep(TriggerPayCumulativeUpkeep.class),
|
||||
Phase(TriggerPhase.class),
|
||||
PhaseIn(TriggerPhaseIn.class),
|
||||
PhaseOut(TriggerPhaseOut.class),
|
||||
PlanarDice(TriggerPlanarDice.class),
|
||||
PlaneswalkedFrom(TriggerPlaneswalkedFrom.class),
|
||||
PlaneswalkedTo(TriggerPlaneswalkedTo.class),
|
||||
|
||||
Reference in New Issue
Block a user