diff --git a/forge-game/src/main/java/forge/game/trigger/TriggerAbilityResolves.java b/forge-game/src/main/java/forge/game/trigger/TriggerAbilityResolves.java new file mode 100644 index 00000000000..93b65aeb89b --- /dev/null +++ b/forge-game/src/main/java/forge/game/trigger/TriggerAbilityResolves.java @@ -0,0 +1,73 @@ +/* + * 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.ability.AbilityKey; +import forge.game.card.Card; +import forge.game.spellability.SpellAbility; +import forge.util.Localizer; + +import java.util.Map; + +public class TriggerAbilityResolves extends Trigger { + + public TriggerAbilityResolves(final Map params, final Card host, final boolean intrinsic) { + super(params, host, intrinsic); + } + + /** {@inheritDoc} + * @param runParams*/ + @Override + public final boolean performTest(final Map runParams) { + final SpellAbility spellAbility = (SpellAbility) runParams.get(AbilityKey.SpellAbility); + if (spellAbility == null) { + System.out.println("TriggerAbilityResolves performTest encountered spellAbility == null. runParams2 = " + runParams); + return false; + } + final Card source = spellAbility.getHostCard(); + + if (!matchesValidParam("ValidSpellAbility", spellAbility)) { + return false; + } + + if (!matchesValidParam("ValidSource", source)) { + return false; + } + + return true; + } + + /** {@inheritDoc} */ + @Override + public final void setTriggeringObjects(final SpellAbility sa, Map runParams) { + final SpellAbility triggeredSA = (SpellAbility) runParams.get(AbilityKey.SpellAbility); + sa.setTriggeringObject(AbilityKey.Source, triggeredSA.getHostCard()); + sa.setTriggeringObjectsFrom( + runParams, + AbilityKey.SpellAbility, + AbilityKey.Cause); + } + + @Override + public String getImportantStackObjects(SpellAbility sa) { + StringBuilder sb = new StringBuilder(); + sb.append(Localizer.getInstance().getMessage("lblSpellAbility")).append(": ").append(sa.getTriggeringObject(AbilityKey.SpellAbility)); + 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 7faf2776c9e..c0ef1b69bff 100644 --- a/forge-game/src/main/java/forge/game/trigger/TriggerType.java +++ b/forge-game/src/main/java/forge/game/trigger/TriggerType.java @@ -14,6 +14,7 @@ import forge.game.card.Card; public enum TriggerType { Abandoned(TriggerAbandoned.class), AbilityCast(TriggerSpellAbilityCastOrCopy.class), + AbilityResolves(TriggerAbilityResolves.class), AbilityTriggered(TriggerAbilityTriggered.class), Adapt(TriggerAdapt.class), Always(TriggerAlways.class), diff --git a/forge-game/src/main/java/forge/game/zone/MagicStack.java b/forge-game/src/main/java/forge/game/zone/MagicStack.java index 2dd330f274f..b400e07c62f 100644 --- a/forge-game/src/main/java/forge/game/zone/MagicStack.java +++ b/forge-game/src/main/java/forge/game/zone/MagicStack.java @@ -526,6 +526,9 @@ public class MagicStack /* extends MyObservable */ implements Iterable runParams = AbilityKey.mapFromCard(source); + runParams.put(AbilityKey.SpellAbility, sa); + game.getTriggerHandler().runTrigger(TriggerType.AbilityResolves, runParams, false); AbilityUtils.resolve(sa); } else { sa.resolve(); diff --git a/forge-gui/res/cardsfolder/upcoming/tom_bombadil.txt b/forge-gui/res/cardsfolder/upcoming/tom_bombadil.txt new file mode 100644 index 00000000000..66492f29e0a --- /dev/null +++ b/forge-gui/res/cardsfolder/upcoming/tom_bombadil.txt @@ -0,0 +1,10 @@ +Name:Tom Bombadil +ManaCost:W U B R G +Types:Legendary Creature God Bard +PT:4/4 +S:Mode$ Continuous | Affected$ Card.Self | AddKeyword$ Hexproof & Indestructible | CheckSVar$ X | SVarCompare$ GE4 | Description$ As long as there are four or more lore counters among Sagas you control, CARDNAME has hexproof and indestructible. +SVar:X:Count$Valid Saga.YouCtrl$CardCounters.LORE +T:Mode$ AbilityResolves | ValidSource$ Saga.YouCtrl | ValidSpellAbility$ Ability.LastChapter | TriggerZones$ Battlefield | ActivationLimit$ 1 | Execute$ TrigDigUntil | TriggerDescription$ Whenever the final chapter ability of a Saga you control resolves, reveal cards from the top of your library until you reveal a Saga card. Put that onto the battlefield and the rest on the bottom of your library in a random order. This ability triggers only once each turn. +SVar:TrigDigUntil:DB$ DigUntil | Valid$ Saga | FoundDestination$ Battlefield | RevealedDestination$ Library | RevealedLibraryPosition$ -1 | RevealRandomOrder$ True +DeckNeeds:Type$Saga +Oracle:As long as there are four or more lore counters among Sagas you control, Tom Bombadil has hexproof and indestructible.\nWhenever the final chapter ability of a Saga you control resolves, reveal cards from the top of your library until you reveal a Saga card. Put that onto the battlefield and the rest on the bottom of your library in a random order. This ability triggers only once each turn.