From dbc7fec97792737343536ce0b208508440d06b26 Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Fri, 23 Aug 2013 15:01:52 +0200 Subject: [PATCH] Added SpellCastAllTriggeredAbility, some minor formatting. --- .../HikariTwilightGuardian.java | 7 +- .../mage/sets/fifthdawn/FoldIntoAEther.java | 2 +- .../sets/zendikar/QuestForTheHolyRelic.java | 4 +- .../common/SpellCastAllTriggeredAbility.java | 110 ++++++++++++++++++ .../CreateDelayedTriggeredAbilityEffect.java | 4 + .../abilities/keyword/LevelerCardBuilder.java | 6 +- 6 files changed, 126 insertions(+), 7 deletions(-) create mode 100644 Mage/src/mage/abilities/common/SpellCastAllTriggeredAbility.java diff --git a/Mage.Sets/src/mage/sets/championsofkamigawa/HikariTwilightGuardian.java b/Mage.Sets/src/mage/sets/championsofkamigawa/HikariTwilightGuardian.java index 76b29a1f6a2..822a8e89660 100644 --- a/Mage.Sets/src/mage/sets/championsofkamigawa/HikariTwilightGuardian.java +++ b/Mage.Sets/src/mage/sets/championsofkamigawa/HikariTwilightGuardian.java @@ -34,7 +34,7 @@ import mage.constants.CardType; import mage.constants.Rarity; import mage.MageInt; import mage.abilities.Ability; -import mage.abilities.common.SpellCastTriggeredAbility; +import mage.abilities.common.SpellCastControllerTriggeredAbility; import mage.abilities.common.delayed.AtEndOfTurnDelayedTriggeredAbility; import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.common.ReturnFromExileEffect; @@ -62,8 +62,11 @@ public class HikariTwilightGuardian extends CardImpl { this.color.setWhite(true); this.power = new MageInt(4); this.toughness = new MageInt(4); + // Flying this.addAbility(FlyingAbility.getInstance()); - this.addAbility(new SpellCastTriggeredAbility(new HikariTwilightGuardianEffect(), filter, true)); + + // Whenever you cast a Spirit or Arcane spell, you may exile Hikari, Twilight Guardian. If you do, return it to the battlefield under its owner's control at the beginning of the next end step. + this.addAbility(new SpellCastControllerTriggeredAbility(new HikariTwilightGuardianEffect(), filter, true)); } public HikariTwilightGuardian (final HikariTwilightGuardian card) { diff --git a/Mage.Sets/src/mage/sets/fifthdawn/FoldIntoAEther.java b/Mage.Sets/src/mage/sets/fifthdawn/FoldIntoAEther.java index 6c46311baeb..d2380c3b104 100644 --- a/Mage.Sets/src/mage/sets/fifthdawn/FoldIntoAEther.java +++ b/Mage.Sets/src/mage/sets/fifthdawn/FoldIntoAEther.java @@ -100,7 +100,7 @@ class FoldIntoAEtherEffect extends OneShotEffect { && player.choose(Outcome.PutCreatureInPlay, target, source.getSourceId(), game)) { Card card = game.getCard(target.getFirstTarget()); if (card != null) { - card.putOntoBattlefield(game, Zone.HAND, source.getId(), source.getControllerId()); + card.putOntoBattlefield(game, Zone.HAND, source.getId(), player.getId()); } } return true; diff --git a/Mage.Sets/src/mage/sets/zendikar/QuestForTheHolyRelic.java b/Mage.Sets/src/mage/sets/zendikar/QuestForTheHolyRelic.java index 560c9634d54..3867011b130 100644 --- a/Mage.Sets/src/mage/sets/zendikar/QuestForTheHolyRelic.java +++ b/Mage.Sets/src/mage/sets/zendikar/QuestForTheHolyRelic.java @@ -35,7 +35,7 @@ import mage.constants.Rarity; import mage.constants.Zone; import mage.abilities.Ability; import mage.abilities.common.SimpleActivatedAbility; -import mage.abilities.common.SpellCastTriggeredAbility; +import mage.abilities.common.SpellCastControllerTriggeredAbility; import mage.abilities.costs.common.RemoveCountersSourceCost; import mage.abilities.costs.common.SacrificeSourceCost; import mage.abilities.effects.OneShotEffect; @@ -72,7 +72,7 @@ public class QuestForTheHolyRelic extends CardImpl { this.color.setWhite(true); // Whenever you cast a creature spell, you may put a quest counter on Quest for the Holy Relic. - this.addAbility(new SpellCastTriggeredAbility(new AddCountersSourceEffect(CounterType.QUEST.createInstance()), filter, true)); + this.addAbility(new SpellCastControllerTriggeredAbility(new AddCountersSourceEffect(CounterType.QUEST.createInstance()), filter, true)); // Remove five quest counters from Quest for the Holy Relic and sacrifice it: Search your library for an Equipment card, put it onto the battlefield, and attach it to a creature you control. Then shuffle your library. Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, new QuestForTheHolyRelicEffect(), new RemoveCountersSourceCost(CounterType.QUEST.createInstance(5))); ability.addCost(new SacrificeSourceCost()); diff --git a/Mage/src/mage/abilities/common/SpellCastAllTriggeredAbility.java b/Mage/src/mage/abilities/common/SpellCastAllTriggeredAbility.java new file mode 100644 index 00000000000..5bed241791e --- /dev/null +++ b/Mage/src/mage/abilities/common/SpellCastAllTriggeredAbility.java @@ -0,0 +1,110 @@ +/* + * Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of BetaSteward_at_googlemail.com. + */ +package mage.abilities.common; + +import mage.abilities.TriggeredAbilityImpl; +import mage.abilities.effects.Effect; +import mage.constants.Zone; +import mage.filter.FilterSpell; +import mage.game.Game; +import mage.game.events.GameEvent; +import mage.game.stack.Spell; +import mage.target.targetpointer.FixedTarget; + +/** + * + * @author LevelX2 + */ +public class SpellCastAllTriggeredAbility extends TriggeredAbilityImpl { + + private static final FilterSpell spellCard = new FilterSpell("a spell"); + protected FilterSpell filter; + protected String rule; + + /** + * If true, the source that triggered the ability will be set as target to effect. + */ + protected boolean rememberSource = false; + + public SpellCastAllTriggeredAbility(Effect effect, boolean optional) { + this(Zone.BATTLEFIELD, effect, spellCard, optional, false); + } + + public SpellCastAllTriggeredAbility(Effect effect, FilterSpell filter, boolean optional) { + this(effect, filter, optional, false); + } + + public SpellCastAllTriggeredAbility(Effect effect, FilterSpell filter, boolean optional, String rule) { + this(effect, filter, optional, false); + this.rule = rule; + } + + public SpellCastAllTriggeredAbility(Effect effect, FilterSpell filter, boolean optional, boolean rememberSource) { + this(Zone.BATTLEFIELD, effect, filter, optional, rememberSource); + } + + public SpellCastAllTriggeredAbility(Zone zone, Effect effect, FilterSpell filter, boolean optional, boolean rememberSource) { + super(zone, effect, optional); + this.filter = filter; + this.rememberSource = rememberSource; + } + + public SpellCastAllTriggeredAbility(final SpellCastAllTriggeredAbility ability) { + super(ability); + filter = ability.filter; + this.rememberSource = ability.rememberSource; + this.rule = ability.rule; + } + + @Override + public boolean checkTrigger(GameEvent event, Game game) { + if (event.getType() == GameEvent.EventType.SPELL_CAST) { + Spell spell = game.getStack().getSpell(event.getTargetId()); + if (spell != null && filter.match(spell, game)) { + if (rememberSource) { + this.getEffects().get(0).setTargetPointer(new FixedTarget(spell.getId())); + } + return true; + } + } + return false; + } + + @Override + public String getRule() { + if (rule != null && !rule.isEmpty()) { + return rule; + } + return "Whenever a player casts " + filter.getMessage() + ", " + super.getRule(); + } + + @Override + public SpellCastAllTriggeredAbility copy() { + return new SpellCastAllTriggeredAbility(this); + } +} diff --git a/Mage/src/mage/abilities/effects/common/CreateDelayedTriggeredAbilityEffect.java b/Mage/src/mage/abilities/effects/common/CreateDelayedTriggeredAbilityEffect.java index 923bc445381..8b8e17f4820 100644 --- a/Mage/src/mage/abilities/effects/common/CreateDelayedTriggeredAbilityEffect.java +++ b/Mage/src/mage/abilities/effects/common/CreateDelayedTriggeredAbilityEffect.java @@ -31,6 +31,7 @@ package mage.abilities.effects.common; import mage.abilities.Ability; import mage.abilities.DelayedTriggeredAbility; import mage.abilities.Mode; +import mage.abilities.effects.Effect; import mage.abilities.effects.OneShotEffect; import mage.game.Game; @@ -71,6 +72,9 @@ public class CreateDelayedTriggeredAbilityEffect extends OneShotEffect