From f9bf394120f834b03bb4773b7ab38179d5760106 Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Thu, 28 Jan 2016 23:49:10 +0100 Subject: [PATCH] Added Moonring Mirror. --- .../championsofkamigawa/MoonringMirror.java | 162 ++++++++++++++++++ .../sets/championsofkamigawa/UbaMask.java | 3 +- 2 files changed, 164 insertions(+), 1 deletion(-) create mode 100644 Mage.Sets/src/mage/sets/championsofkamigawa/MoonringMirror.java diff --git a/Mage.Sets/src/mage/sets/championsofkamigawa/MoonringMirror.java b/Mage.Sets/src/mage/sets/championsofkamigawa/MoonringMirror.java new file mode 100644 index 0000000000..29f6df2e27 --- /dev/null +++ b/Mage.Sets/src/mage/sets/championsofkamigawa/MoonringMirror.java @@ -0,0 +1,162 @@ +/* + * 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.sets.championsofkamigawa; + +import java.util.HashSet; +import java.util.Set; +import java.util.UUID; +import mage.MageObject; +import mage.abilities.Ability; +import mage.abilities.common.BeginningOfUpkeepTriggeredAbility; +import mage.abilities.common.DrawCardControllerTriggeredAbility; +import mage.abilities.effects.OneShotEffect; +import mage.cards.Card; +import mage.cards.CardImpl; +import mage.cards.Cards; +import mage.cards.CardsImpl; +import mage.constants.CardType; +import mage.constants.Outcome; +import mage.constants.Rarity; +import mage.constants.TargetController; +import mage.constants.Zone; +import mage.game.Game; +import mage.players.Player; +import mage.util.CardUtil; + +/** + * + * @author LevelX2 + */ +public class MoonringMirror extends CardImpl { + + protected static final String VALUE_PREFIX = "ExileZones"; + + public MoonringMirror(UUID ownerId) { + super(ownerId, 262, "Moonring Mirror", Rarity.RARE, new CardType[]{CardType.ARTIFACT}, "{5}"); + this.expansionSetCode = "CHK"; + + // Whenever you draw a card, exile the top card of your library face down. + this.addAbility(new DrawCardControllerTriggeredAbility(new MoonringMirrorExileEffect(), false)); + + // At the beginning of your upkeep, you may exile all cards from your hand face down. If you do, put all other cards you own exiled with Moonring Mirror into your hand. + this.addAbility(new BeginningOfUpkeepTriggeredAbility(new MoonringMirrorEffect(), TargetController.YOU, true)); + } + + public MoonringMirror(final MoonringMirror card) { + super(card); + } + + @Override + public MoonringMirror copy() { + return new MoonringMirror(this); + } +} + +class MoonringMirrorExileEffect extends OneShotEffect { + + public MoonringMirrorExileEffect() { + super(Outcome.Discard); + staticText = "exile the top card of your library face down"; + } + + public MoonringMirrorExileEffect(final MoonringMirrorExileEffect effect) { + super(effect); + } + + @Override + public boolean apply(Game game, Ability source) { + Player controller = game.getPlayer(source.getControllerId()); + if (controller != null) { + Card card = controller.getLibrary().getFromTop(game); + MageObject sourceObject = source.getSourceObject(game); + if (card != null && sourceObject != null) { + UUID exileZoneId = CardUtil.getExileZoneId(game, source.getSourceId(), source.getSourceObjectZoneChangeCounter()); + card.setFaceDown(true, game); + controller.moveCardsToExile(card, source, game, false, exileZoneId, sourceObject.getIdName()); + card.setFaceDown(true, game); + Set exileZones = (Set) game.getState().getValue(MoonringMirror.VALUE_PREFIX + source.getSourceId().toString()); + if (exileZones == null) { + exileZones = new HashSet<>(); + game.getState().setValue(MoonringMirror.VALUE_PREFIX + source.getSourceId().toString(), exileZones); + } + exileZones.add(exileZoneId); + return true; + } + } + return false; + } + + @Override + public MoonringMirrorExileEffect copy() { + return new MoonringMirrorExileEffect(this); + } +} + +class MoonringMirrorEffect extends OneShotEffect { + + public MoonringMirrorEffect() { + super(Outcome.Benefit); + this.staticText = "you may exile all cards from your hand face down. If you do, put all other cards you own exiled with {this} into your hand"; + } + + public MoonringMirrorEffect(final MoonringMirrorEffect effect) { + super(effect); + } + + @Override + public MoonringMirrorEffect copy() { + return new MoonringMirrorEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + Player controller = game.getPlayer(source.getControllerId()); + MageObject sourceObject = source.getSourceObject(game); + if (controller != null && sourceObject != null) { + UUID exileZoneId = CardUtil.getExileZoneId(game, source.getSourceId(), source.getSourceObjectZoneChangeCounter()); + Cards cardsToHand = null; + if (game.getExile().getExileZone(exileZoneId) != null && game.getExile().getExileZone(exileZoneId).size() > 0) { + cardsToHand = new CardsImpl(game.getExile().getExileZone(exileZoneId)); + } + for (Card card : controller.getHand().getCards(game)) { + card.setFaceDown(true, game); + } + controller.moveCardsToExile(controller.getHand().getCards(game), source, game, false, exileZoneId, sourceObject.getIdName()); + if (cardsToHand != null) { + controller.moveCards(cardsToHand.getCards(game), Zone.HAND, source, game, false, true, false, null); + } + if (game.getExile().getExileZone(exileZoneId) != null) { + for (Card card : game.getExile().getExileZone(exileZoneId).getCards(game)) { + card.setFaceDown(true, game); + } + } + return true; + } + return false; + } +} diff --git a/Mage.Sets/src/mage/sets/championsofkamigawa/UbaMask.java b/Mage.Sets/src/mage/sets/championsofkamigawa/UbaMask.java index 7b2af01f8f..a994e4b3d1 100644 --- a/Mage.Sets/src/mage/sets/championsofkamigawa/UbaMask.java +++ b/Mage.Sets/src/mage/sets/championsofkamigawa/UbaMask.java @@ -112,9 +112,10 @@ class UbaMaskReplacementEffect extends ReplacementEffectImpl { exiledCards = new HashMap<>(); game.getState().setValue(UbaMask.UBA_MASK_VALUE_KEY, exiledCards); } - Set exiledCardsByPlayer = exiledCards.get(event.getPlayerId()); + HashSet exiledCardsByPlayer = exiledCards.get(event.getPlayerId()); if (exiledCardsByPlayer == null) { exiledCardsByPlayer = new HashSet<>(); + exiledCards.put(event.getPlayerId(), exiledCardsByPlayer); } exiledCardsByPlayer.add(new MageObjectReference(card.getId(), game)); }