From ab5fe47ce752b90de14a79d8e285ca3005c8045e Mon Sep 17 00:00:00 2001
From: Jeff <jeff@delmarus.com>
Date: Mon, 19 Mar 2018 14:56:31 -0500
Subject: [PATCH] - Added Aven Shrine.

---
 Mage.Sets/src/mage/cards/a/AvenShrine.java | 147 +++++++++++++++++++++
 Mage.Sets/src/mage/sets/Odyssey.java       |   1 +
 2 files changed, 148 insertions(+)
 create mode 100644 Mage.Sets/src/mage/cards/a/AvenShrine.java

diff --git a/Mage.Sets/src/mage/cards/a/AvenShrine.java b/Mage.Sets/src/mage/cards/a/AvenShrine.java
new file mode 100644
index 0000000000..64b88e4c70
--- /dev/null
+++ b/Mage.Sets/src/mage/cards/a/AvenShrine.java
@@ -0,0 +1,147 @@
+/*
+ *  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.cards.a;
+
+import java.util.UUID;
+import mage.MageObject;
+import mage.abilities.Ability;
+import mage.abilities.TriggeredAbilityImpl;
+import mage.abilities.effects.OneShotEffect;
+import mage.cards.CardImpl;
+import mage.cards.CardSetInfo;
+import mage.constants.CardType;
+import mage.constants.Outcome;
+import mage.constants.Zone;
+import mage.filter.FilterCard;
+import mage.filter.predicate.mageobject.NamePredicate;
+import mage.game.Game;
+import mage.game.events.GameEvent;
+import mage.game.events.GameEvent.EventType;
+import mage.game.stack.Spell;
+import mage.players.Player;
+
+/**
+ *
+ * @author jeffwadsworth
+ */
+public class AvenShrine extends CardImpl {
+
+    public AvenShrine(UUID ownerId, CardSetInfo setInfo) {
+        super(ownerId, setInfo, new CardType[]{CardType.ENCHANTMENT}, "{1}{W}{W}");
+
+        // Whenever a player casts a spell, that player gains X life, where X is the number of cards in all graveyards with the same name as that spell.
+        this.addAbility(new AvenShrineTriggeredAbility());
+
+    }
+
+    public AvenShrine(final AvenShrine card) {
+        super(card);
+    }
+
+    @Override
+    public AvenShrine copy() {
+        return new AvenShrine(this);
+    }
+}
+
+class AvenShrineTriggeredAbility extends TriggeredAbilityImpl {
+
+    public AvenShrineTriggeredAbility() {
+        super(Zone.BATTLEFIELD, new AvenShrineEffect(), false);
+    }
+
+    public AvenShrineTriggeredAbility(final AvenShrineTriggeredAbility ability) {
+        super(ability);
+    }
+
+    @Override
+    public AvenShrineTriggeredAbility copy() {
+        return new AvenShrineTriggeredAbility(this);
+    }
+
+    @Override
+    public boolean checkEventType(GameEvent event, Game game) {
+        return event.getType() == EventType.SPELL_CAST;
+    }
+
+    @Override
+    public boolean checkTrigger(GameEvent event, Game game) {
+        Spell spell = game.getStack().getSpell(event.getTargetId());
+        MageObject mageObject = game.getObject(sourceId);
+        if (spell != null
+                && !spell.isCopy()
+                && spell.getCard() != null
+                && !spell.getCard().isCopy()) {
+            game.getState().setValue("avenShrine" + mageObject, spell);
+            return true;
+        }
+        return false;
+    }
+
+}
+
+class AvenShrineEffect extends OneShotEffect {
+
+    public AvenShrineEffect() {
+        super(Outcome.GainLife);
+        staticText = "Whenever a player casts a spell, that player gains X life, where X is the number of cards in all graveyards with the same name as that spell";
+    }
+
+    public AvenShrineEffect(final AvenShrineEffect effect) {
+        super(effect);
+    }
+
+    @Override
+    public boolean apply(Game game, Ability source) {
+        int count = 0;
+        MageObject mageObject = game.getObject(source.getSourceId());
+        Spell spell = (Spell) game.getState().getValue("avenShrine" + mageObject);
+        if (spell != null) {
+            Player controller = game.getPlayer(spell.getControllerId());
+            if (controller != null) {
+                String name = spell.getName();
+                FilterCard filterCardName = new FilterCard();
+                filterCardName.add(new NamePredicate(name));
+                for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
+                    Player player = game.getPlayer(playerId);
+                    if (player != null) {
+                        count += player.getGraveyard().count(filterCardName, game);
+                    }
+                }
+                controller.gainLife(count, game);
+                return true;
+            }
+        }
+        return false;
+    }
+
+    @Override
+    public AvenShrineEffect copy() {
+        return new AvenShrineEffect(this);
+    }
+}
diff --git a/Mage.Sets/src/mage/sets/Odyssey.java b/Mage.Sets/src/mage/sets/Odyssey.java
index 32cd0eef8a..203896bcf9 100644
--- a/Mage.Sets/src/mage/sets/Odyssey.java
+++ b/Mage.Sets/src/mage/sets/Odyssey.java
@@ -72,6 +72,7 @@ public class Odyssey extends ExpansionSet {
         cards.add(new SetCardInfo("Aven Cloudchaser", 7, Rarity.COMMON, mage.cards.a.AvenCloudchaser.class));
         cards.add(new SetCardInfo("Aven Fisher", 63, Rarity.COMMON, mage.cards.a.AvenFisher.class));
         cards.add(new SetCardInfo("Aven Flock", 8, Rarity.COMMON, mage.cards.a.AvenFlock.class));
+        cards.add(new SetCardInfo("Aven Shrine", 9, Rarity.RARE, mage.cards.a.AvenShrine.class));
         cards.add(new SetCardInfo("Aven Smokeweaver", 64, Rarity.UNCOMMON, mage.cards.a.AvenSmokeweaver.class));
         cards.add(new SetCardInfo("Aven Windreader", 65, Rarity.COMMON, mage.cards.a.AvenWindreader.class));
         cards.add(new SetCardInfo("Balancing Act", 10, Rarity.RARE, mage.cards.b.BalancingAct.class));