From 244fa1396176ba5b2a4faedcc8678411a2d7cda6 Mon Sep 17 00:00:00 2001 From: Hans Mackowiak Date: Wed, 12 Jun 2019 05:23:31 +0000 Subject: [PATCH] TriggerExiled: make new Trigger for exile keyword action for Soulherder --- .../src/main/java/forge/game/GameAction.java | 17 ++- .../forge/game/trigger/TriggerExiled.java | 109 ++++++++++++++++++ .../java/forge/game/trigger/TriggerType.java | 1 + .../res/cardsfolder/upcoming/soulherder.txt | 2 +- 4 files changed, 127 insertions(+), 2 deletions(-) create mode 100644 forge-game/src/main/java/forge/game/trigger/TriggerExiled.java diff --git a/forge-game/src/main/java/forge/game/GameAction.java b/forge-game/src/main/java/forge/game/GameAction.java index 77c4c009772..59b32063fb0 100644 --- a/forge-game/src/main/java/forge/game/GameAction.java +++ b/forge-game/src/main/java/forge/game/GameAction.java @@ -700,8 +700,23 @@ public class GameAction { if (game.isCardExiled(c)) { return c; } + + final Zone origin = c.getZone(); final PlayerZone removed = c.getOwner().getZone(ZoneType.Exile); - return moveTo(removed, c, cause, params); + final Card copied = moveTo(removed, c, cause, params); + + // Run triggers + final Map runParams = Maps.newHashMap(); + runParams.put("Card", c); + runParams.put("Cause", cause); + runParams.put("Origin", origin.getZoneType().name()); + if (params != null) { + runParams.putAll(params); + } + + game.getTriggerHandler().runTrigger(TriggerType.Exiled, runParams, false); + + return copied; } public final Card moveTo(final ZoneType name, final Card c, SpellAbility cause) { diff --git a/forge-game/src/main/java/forge/game/trigger/TriggerExiled.java b/forge-game/src/main/java/forge/game/trigger/TriggerExiled.java new file mode 100644 index 00000000000..3592a8d0adf --- /dev/null +++ b/forge-game/src/main/java/forge/game/trigger/TriggerExiled.java @@ -0,0 +1,109 @@ +/* + * Forge: Play Magic: the Gathering. + * Copyright (C) 2011 Forge Team + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package forge.game.trigger; + +import forge.game.card.Card; + +import forge.game.spellability.SpellAbility; + +import java.util.Map; + +import org.apache.commons.lang3.ArrayUtils; + +/** + *

+ * Trigger_ChangesZone class. + *

+ * + * @author Forge + * @version $Id$ + */ +public class TriggerExiled extends Trigger { + + /** + *

+ * Constructor for TriggerExiled. + *

+ * + * @param params + * a {@link java.util.Map} object. + * @param host + * a {@link forge.game.card.Card} object. + * @param intrinsic + * the intrinsic + */ + public TriggerExiled(final Map params, final Card host, final boolean intrinsic) { + super(params, host, intrinsic); + } + + /** {@inheritDoc} */ + @Override + public final boolean performTest(final Map runParams2) { + if (hasParam("Origin")) { + if (!getParam("Origin").equals("Any")) { + if (getParam("Origin") == null) { + return false; + } + if (!ArrayUtils.contains( + getParam("Origin").split(","), runParams2.get("Origin") + )) { + return false; + } + } + } + + if (hasParam("ValidCard")) { + Card moved = (Card) runParams2.get("Card"); + + if (!moved.isValid(getParam("ValidCard").split(","), getHostCard().getController(), + getHostCard(), null)) { + return false; + } + } + + if (hasParam("ValidCause")) { + if (!runParams2.containsKey("Cause") ) { + return false; + } + SpellAbility cause = (SpellAbility) runParams2.get("Cause"); + if (cause == null) { + return false; + } + if (!cause.getHostCard().isValid(getParam("ValidCause").split(","), getHostCard().getController(), + getHostCard(), null)) { + return false; + } + } + + return true; + } + + /** {@inheritDoc} */ + @Override + public final void setTriggeringObjects(final SpellAbility sa) { + sa.setTriggeringObject("Card", this.getRunParams().get("Card")); + } + + @Override + public String getImportantStackObjects(SpellAbility sa) { + StringBuilder sb = new StringBuilder(); + sb.append("Exiled: ").append(sa.getTriggeringObject("Card")); + return sb.toString(); + } + +} diff --git a/forge-game/src/main/java/forge/game/trigger/TriggerType.java b/forge-game/src/main/java/forge/game/trigger/TriggerType.java index 94a312db0c6..9061aa652d2 100644 --- a/forge-game/src/main/java/forge/game/trigger/TriggerType.java +++ b/forge-game/src/main/java/forge/game/trigger/TriggerType.java @@ -53,6 +53,7 @@ public enum TriggerType { Drawn(TriggerDrawn.class), Evolved(TriggerEvolved.class), Exerted(TriggerExerted.class), + Exiled(TriggerExiled.class), Exploited(TriggerExploited.class), Explores(TriggerExplores.class), Fight(TriggerFight.class), diff --git a/forge-gui/res/cardsfolder/upcoming/soulherder.txt b/forge-gui/res/cardsfolder/upcoming/soulherder.txt index 1904591dffe..205dba5bd3b 100644 --- a/forge-gui/res/cardsfolder/upcoming/soulherder.txt +++ b/forge-gui/res/cardsfolder/upcoming/soulherder.txt @@ -2,7 +2,7 @@ Name:Soulherder ManaCost:1 W U Types:Creature Spirit PT:1/1 -T:Mode$ ChangesZone | Origin$ Battlefield | Destination$ Exile | ValidCard$ Creature | TriggerZones$ Battlefield | Execute$ TrigPutCounter | TriggerDescription$ Whenever a creature is exiled from the battlefield, put a +1/+1 counter on CARDNAME. +T:Mode$ Exiled | Origin$ Battlefield | ValidCard$ Creature | TriggerZones$ Battlefield | Execute$ TrigPutCounter | TriggerDescription$ Whenever a creature is exiled from the battlefield, put a +1/+1 counter on CARDNAME. SVar:TrigPutCounter:DB$PutCounter | Defined$ Self | CounterType$ P1P1 | CounterNum$ 1 SVar:PlayMain1:TRUE T:Mode$ Phase | Phase$ End of Turn | ValidPlayer$ You | TriggerZones$ Battlefield | Execute$ ConjurerExile | OptionalDecider$ You | TriggerDescription$ At the beginning of your end step, you may exile another target creature you control, then return it to the battlefield under its owner's control.