From d36086acd2f46414e4ad1446ebaf942bcbca7d56 Mon Sep 17 00:00:00 2001 From: BetaSteward Date: Mon, 29 Aug 2011 22:48:55 -0400 Subject: [PATCH] MBS - Knowledge Pool --- .../sets/mirrodinbesieged/KnowledgePool.java | 184 ++++++++++++++++++ Mage/src/mage/game/stack/Spell.java | 20 +- Mage/src/mage/players/PlayerImpl.java | 8 +- .../mage/target/common/TargetCardInExile.java | 83 ++++++++ 4 files changed, 290 insertions(+), 5 deletions(-) create mode 100644 Mage.Sets/src/mage/sets/mirrodinbesieged/KnowledgePool.java create mode 100644 Mage/src/mage/target/common/TargetCardInExile.java diff --git a/Mage.Sets/src/mage/sets/mirrodinbesieged/KnowledgePool.java b/Mage.Sets/src/mage/sets/mirrodinbesieged/KnowledgePool.java new file mode 100644 index 00000000000..cdbbf09378a --- /dev/null +++ b/Mage.Sets/src/mage/sets/mirrodinbesieged/KnowledgePool.java @@ -0,0 +1,184 @@ +/* + * Copyright 2011 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.sets.mirrodinbesieged; + +import mage.target.common.TargetCardInExile; +import java.util.UUID; +import mage.Constants.CardType; +import mage.Constants.Outcome; +import mage.Constants.Rarity; +import mage.Constants.Zone; +import mage.abilities.Ability; +import mage.abilities.TriggeredAbilityImpl; +import mage.abilities.common.EntersBattlefieldTriggeredAbility; +import mage.abilities.common.SimpleStaticAbility; +import mage.abilities.effects.ContinuousEffectImpl; +import mage.abilities.effects.Effect; +import mage.abilities.effects.OneShotEffect; +import mage.cards.Card; +import mage.cards.CardImpl; +import mage.filter.common.FilterNonlandCard; +import mage.game.Game; +import mage.game.events.GameEvent; +import mage.game.events.GameEvent.EventType; +import mage.game.events.ZoneChangeEvent; +import mage.game.stack.Spell; +import mage.players.Player; +import mage.target.targetpointer.FixedTarget; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class KnowledgePool extends CardImpl { + + public KnowledgePool(UUID ownerId) { + super(ownerId, 111, "Knowledge Pool", Rarity.RARE, new CardType[]{CardType.ARTIFACT}, "{6}"); + this.expansionSetCode = "MBS"; + // Imprint - When Knowledge Pool enters the battlefield, each player exiles the top three cards of his or her library + this.addAbility(new EntersBattlefieldTriggeredAbility(new KnowledgePoolEffect1(), false)); + // Whenever a player casts a spell from his or her hand, that player exiles it. If the player does, he or she may cast another nonland card exiled with Knowledge Pool without paying that card's mana cost. + this.addAbility(new KnowledgePoolAbility()); + } + + public KnowledgePool(final KnowledgePool card) { + super(card); + } + + @Override + public KnowledgePool copy() { + return new KnowledgePool(this); + } + +} + +class KnowledgePoolEffect1 extends OneShotEffect { + + public KnowledgePoolEffect1() { + super(Outcome.Neutral); + staticText = "each player exiles the top three cards of his or her library"; + } + + public KnowledgePoolEffect1(final KnowledgePoolEffect1 effect) { + super(effect); + } + + @Override + public boolean apply(Game game, Ability source) { + Player sourcePlayer = game.getPlayer(source.getControllerId()); + for (UUID playerId: sourcePlayer.getInRange()) { + Player player = game.getPlayer(playerId); + if (player != null) { + for (int i = 0; i < 3; i++) { + player.getLibrary().removeFromTop(game).moveToExile(source.getSourceId(), "Knowledge Pool Exile", source.getId(), game); + } + } + } + return true; + } + + @Override + public KnowledgePoolEffect1 copy() { + return new KnowledgePoolEffect1(this); + } + +} + +class KnowledgePoolAbility extends TriggeredAbilityImpl { + + public KnowledgePoolAbility() { + super(Zone.BATTLEFIELD, new KnowledgePoolEffect2(), false); + } + + public KnowledgePoolAbility(final KnowledgePoolAbility ability) { + super(ability); + } + + @Override + public KnowledgePoolAbility copy() { + return new KnowledgePoolAbility(this); + } + + @Override + public boolean checkTrigger(GameEvent event, Game game) { + if (event.getType() == EventType.SPELL_CAST && event.getZone() == Zone.HAND) { + Spell spell = game.getStack().getSpell(event.getTargetId()); + if (spell != null) { + for (Effect effect : this.getEffects()) { + effect.setTargetPointer(new FixedTarget(event.getTargetId())); + } + return true; + } + } + return false; + } + +} + +class KnowledgePoolEffect2 extends OneShotEffect { + + private static FilterNonlandCard filter = new FilterNonlandCard("nonland card exiled with Knowledge Pool"); + + public KnowledgePoolEffect2() { + super(Outcome.Neutral); + staticText = "Whenever a player casts a spell from his or her hand, that player exiles it. If the player does, he or she may cast another nonland card exiled with {this} without paying that card's mana cost"; + } + + public KnowledgePoolEffect2(final KnowledgePoolEffect2 effect) { + super(effect); + } + + @Override + public boolean apply(Game game, Ability source) { + Spell spell = game.getStack().getSpell(targetPointer.getFirst(source)); + if (spell != null) { + if (spell.moveToExile(source.getSourceId(), "Knowledge Pool Exile", id, game)) { + Player player = game.getPlayer(spell.getControllerId()); + if (player != null && player.chooseUse(Outcome.PlayForFree, "Cast another nonland card exiled with Knowledge Pool without paying that card's mana cost?", game)) { + TargetCardInExile target = new TargetCardInExile(filter, source.getSourceId()); + while (player.choose(Outcome.PlayForFree, game.getExile().getExileZone(source.getSourceId()), target, game)) { + Card card = game.getCard(target.getFirstTarget()); + if (card != null && !card.getId().equals(spell.getSourceId())) { + game.getExile().removeCard(card, game); + return player.cast(card.getSpellAbility(), game, true); + } + target.clearChosen(); + } + } + return true; + } + } + return false; + } + + @Override + public KnowledgePoolEffect2 copy() { + return new KnowledgePoolEffect2(this); + } + +} \ No newline at end of file diff --git a/Mage/src/mage/game/stack/Spell.java b/Mage/src/mage/game/stack/Spell.java index a7ea498f0f6..b042077b508 100644 --- a/Mage/src/mage/game/stack/Spell.java +++ b/Mage/src/mage/game/stack/Spell.java @@ -52,6 +52,7 @@ import mage.watchers.Watchers; import java.util.List; import java.util.UUID; +import mage.game.events.ZoneChangeEvent; import mage.watchers.Watcher; /** @@ -338,8 +339,23 @@ public class Spell> implements StackObject, Card { @Override public boolean moveToExile(UUID exileId, String name, UUID sourceId, Game game) { - throw new UnsupportedOperationException("Unsupported operation"); - } + ZoneChangeEvent event = new ZoneChangeEvent(this.getId(), sourceId, this.getOwnerId(), Zone.STACK, Zone.EXILED); + if (!game.replaceEvent(event)) { + game.getStack().remove(this); + game.rememberLKI(this.getId(), event.getFromZone(), this); + + if (exileId == null) { + game.getExile().getPermanentExile().add(this.card); + } + else { + game.getExile().createZone(exileId, name).add(this.card); + } + game.setZone(this.card.getId(), event.getToZone()); + game.fireEvent(event); + return event.getToZone() == Zone.EXILED; + } + return false; + } @Override public boolean putOntoBattlefield(Game game, Zone fromZone, UUID sourceId, UUID controllerId) { diff --git a/Mage/src/mage/players/PlayerImpl.java b/Mage/src/mage/players/PlayerImpl.java index f284befe213..2d23895e1c5 100644 --- a/Mage/src/mage/players/PlayerImpl.java +++ b/Mage/src/mage/players/PlayerImpl.java @@ -440,15 +440,17 @@ public abstract class PlayerImpl> implements Player, Ser if (card != null) { if (!game.replaceEvent(GameEvent.getEvent(GameEvent.EventType.CAST_SPELL, ability.getId(), ability.getSourceId(), playerId))) { int bookmark = game.bookmarkState(); - - card.cast(game, game.getZone(card.getId()), ability, playerId); + Zone fromZone = game.getZone(card.getId()); + card.cast(game, fromZone, ability, playerId); Ability spellAbility = game.getStack().getSpell(ability.getId()).getSpellAbility(); if (spellAbility.activate(game, noMana)) { for (KickerAbility kicker: card.getAbilities().getKickerAbilities()) { kicker.activate(game, false); } - game.fireEvent(GameEvent.getEvent(GameEvent.EventType.SPELL_CAST, spellAbility.getId(), playerId)); + GameEvent event = GameEvent.getEvent(GameEvent.EventType.SPELL_CAST, spellAbility.getId(), playerId); + event.setZone(fromZone); + game.fireEvent(event); game.fireInformEvent(name + " casts " + card.getName()); game.removeBookmark(bookmark); return true; diff --git a/Mage/src/mage/target/common/TargetCardInExile.java b/Mage/src/mage/target/common/TargetCardInExile.java new file mode 100644 index 00000000000..e7bea3c5aaf --- /dev/null +++ b/Mage/src/mage/target/common/TargetCardInExile.java @@ -0,0 +1,83 @@ +/* + * Copyright 2011 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.target.common; + +import java.util.UUID; +import mage.Constants.Zone; +import mage.abilities.Ability; +import mage.cards.Card; +import mage.filter.FilterCard; +import mage.game.ExileZone; +import mage.game.Game; +import mage.target.TargetCard; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class TargetCardInExile extends TargetCard { + + private UUID zoneId; + + public TargetCardInExile(FilterCard filter, UUID zoneId) { + this(1, 1, filter, zoneId); + } + + public TargetCardInExile(int minNumTargets, int maxNumTargets, FilterCard filter, UUID zoneId) { + super(minNumTargets, maxNumTargets, Zone.EXILED, filter); + this.zoneId = zoneId; + this.targetName = filter.getMessage(); + } + + public TargetCardInExile(final TargetCardInExile target) { + super(target); + this.zoneId = target.zoneId; + } + + @Override + public boolean canTarget(UUID id, Ability source, Game game) { + Card card = game.getCard(id); + if (card != null && game.getZone(card.getId()) == Zone.EXILED) { + ExileZone exile; + if (zoneId != null) { + exile = game.getExile().getExileZone(zoneId); + } else { + exile = game.getExile().getPermanentExile(); + } + if (exile != null && exile.contains(id)) { + return filter.match(card); + } + } + return false; + } + + @Override + public TargetCardInExile copy() { + return new TargetCardInExile(this); + } +}