From d63b241d54f1e0607e2322e4aa600dd57c1025a1 Mon Sep 17 00:00:00 2001
From: igoudt <igoudt@bol.com>
Date: Mon, 19 Jun 2017 01:03:12 +0200
Subject: [PATCH] implemented Eternalize Ability + Steadfast Sentinel

---
 .../src/mage/cards/s/SteadfastSentinel.java   |  39 ++++++
 .../src/mage/sets/HourOfDevastation.java      |   9 +-
 .../abilities/keywords/EternalizeTest.java    |  25 ++++
 .../abilities/keyword/EternalizeAbility.java  | 128 ++++++++++++++++++
 4 files changed, 197 insertions(+), 4 deletions(-)
 create mode 100644 Mage.Sets/src/mage/cards/s/SteadfastSentinel.java
 create mode 100644 Mage.Tests/src/test/java/org/mage/test/cards/abilities/keywords/EternalizeTest.java
 create mode 100644 Mage/src/main/java/mage/abilities/keyword/EternalizeAbility.java

diff --git a/Mage.Sets/src/mage/cards/s/SteadfastSentinel.java b/Mage.Sets/src/mage/cards/s/SteadfastSentinel.java
new file mode 100644
index 0000000000..438bd54aac
--- /dev/null
+++ b/Mage.Sets/src/mage/cards/s/SteadfastSentinel.java
@@ -0,0 +1,39 @@
+package mage.cards.s;
+
+import mage.MageInt;
+import mage.abilities.costs.mana.ManaCostsImpl;
+import mage.abilities.keyword.EternalizeAbility;
+import mage.abilities.keyword.VigilanceAbility;
+import mage.cards.CardImpl;
+import mage.cards.CardSetInfo;
+import mage.constants.CardType;
+
+import java.util.UUID;
+
+public class SteadfastSentinel extends CardImpl {
+
+    public SteadfastSentinel(UUID ownerId, CardSetInfo setInfo) {
+        super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{3}{W}");
+
+        subtype.add("Human");
+        subtype.add("Cleric");
+        power = new MageInt(2);
+        toughness = new MageInt(3);
+
+        //Vigilance
+        addAbility(VigilanceAbility.getInstance());
+
+        //Eternalize {4}{W}{W}
+        addAbility(new EternalizeAbility(new ManaCostsImpl("{4}{W}{W}"), this));
+    }
+
+
+    public SteadfastSentinel(final SteadfastSentinel card) {
+        super(card);
+    }
+
+    @Override
+    public SteadfastSentinel copy() {
+        return new SteadfastSentinel(this);
+    }
+}
diff --git a/Mage.Sets/src/mage/sets/HourOfDevastation.java b/Mage.Sets/src/mage/sets/HourOfDevastation.java
index 3604e25247..a0e2177b07 100644
--- a/Mage.Sets/src/mage/sets/HourOfDevastation.java
+++ b/Mage.Sets/src/mage/sets/HourOfDevastation.java
@@ -27,17 +27,17 @@
  */
 package mage.sets;
 
-import java.util.ArrayList;
-import java.util.List;
 import mage.cards.ExpansionSet;
-import mage.constants.Rarity;
 import mage.cards.repository.CardCriteria;
 import mage.cards.repository.CardInfo;
 import mage.cards.repository.CardRepository;
+import mage.constants.Rarity;
 import mage.constants.SetType;
 
+import java.util.ArrayList;
+import java.util.List;
+
 /**
- *
  * @author fireshoes
  */
 public class HourOfDevastation extends ExpansionSet {
@@ -81,6 +81,7 @@ public class HourOfDevastation extends ExpansionSet {
         cards.add(new SetCardInfo("Open Fire", 105, Rarity.COMMON, mage.cards.o.OpenFire.class));
         cards.add(new SetCardInfo("Ramunap Excavator", 129, Rarity.RARE, mage.cards.r.RamunapExcavator.class));
         cards.add(new SetCardInfo("Samut, the Tested", 144, Rarity.MYTHIC, mage.cards.s.SamutTheTested.class));
+        cards.add(new SetCardInfo("Steadfast Sentinel", 24, Rarity.COMMON, mage.cards.s.SteadfastSentinel.class));
         cards.add(new SetCardInfo("Supreme Will", 49, Rarity.UNCOMMON, mage.cards.s.SupremeWill.class));
 
     }
diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/abilities/keywords/EternalizeTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/abilities/keywords/EternalizeTest.java
new file mode 100644
index 0000000000..ff35998728
--- /dev/null
+++ b/Mage.Tests/src/test/java/org/mage/test/cards/abilities/keywords/EternalizeTest.java
@@ -0,0 +1,25 @@
+package org.mage.test.cards.abilities.keywords;
+
+import mage.abilities.keyword.VigilanceAbility;
+import mage.constants.PhaseStep;
+import mage.constants.Zone;
+import org.junit.Test;
+import org.mage.test.serverside.base.CardTestPlayerBase;
+
+public class EternalizeTest extends CardTestPlayerBase {
+
+    private String sentinel = "Steadfast Sentinel";
+
+    @Test
+    public void testEternalize() {
+        addCard(Zone.GRAVEYARD, playerA, sentinel, 1);
+        addCard(Zone.BATTLEFIELD, playerA, "Plains", 10);
+
+        activateAbility(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Eternalize");
+        setStopAt(1, PhaseStep.POSTCOMBAT_MAIN);
+        execute();
+        assertPermanentCount(playerA, sentinel, 1);
+        assertPowerToughness(playerA, sentinel, 4, 4);
+        assertAbility(playerA, sentinel, VigilanceAbility.getInstance(), true);
+    }
+}
diff --git a/Mage/src/main/java/mage/abilities/keyword/EternalizeAbility.java b/Mage/src/main/java/mage/abilities/keyword/EternalizeAbility.java
new file mode 100644
index 0000000000..a5fb3f57c8
--- /dev/null
+++ b/Mage/src/main/java/mage/abilities/keyword/EternalizeAbility.java
@@ -0,0 +1,128 @@
+/*
+ *  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.keyword;
+
+import mage.ObjectColor;
+import mage.abilities.Ability;
+import mage.abilities.ActivatedAbilityImpl;
+import mage.abilities.costs.Cost;
+import mage.abilities.costs.common.ExileSourceFromGraveCost;
+import mage.abilities.effects.OneShotEffect;
+import mage.cards.Card;
+import mage.constants.Outcome;
+import mage.constants.TimingRule;
+import mage.constants.Zone;
+import mage.game.Game;
+import mage.game.events.GameEvent;
+import mage.game.permanent.token.EmptyToken;
+import mage.players.Player;
+import mage.util.CardUtil;
+
+/**
+ *
+ * @author igoudt
+ */
+public class EternalizeAbility extends ActivatedAbilityImpl {
+
+    private String rule;
+
+    public EternalizeAbility(Cost cost, Card card) {
+        super(Zone.GRAVEYARD, new EternalizeEffect(), cost);
+        addCost(new ExileSourceFromGraveCost());
+        this.rule = setRule(cost, card);
+        this.timing = TimingRule.SORCERY;
+        setRule(cost, card);
+    }
+
+    public EternalizeAbility(final EternalizeAbility ability) {
+        super(ability);
+        this.rule = ability.rule;
+    }
+
+    @Override
+    public EternalizeAbility copy() {
+        return new EternalizeAbility(this);
+    }
+
+    @Override
+    public String getRule() {
+        return rule;
+    }
+
+    private String setRule(Cost cost, Card card) {
+        StringBuilder sb = new StringBuilder("Eternalize ").append(cost.getText());
+        sb.append(" <i>(").append(cost.getText());
+        sb.append(", Exile this card from your graveyard: Create a token that's a copy of it, except it's a 4/4 black Zombie ");
+        for (String subtype : card.getSubtype(null)) {
+            sb.append(subtype).append(" ");
+        }
+        sb.append(" with no mana cost. Eternalize only as a sorcery.)</i>");
+        return sb.toString();
+    }
+}
+
+class EternalizeEffect extends OneShotEffect {
+
+    public EternalizeEffect() {
+        super(Outcome.PutCreatureInPlay);
+    }
+
+    public EternalizeEffect(final EternalizeEffect effect) {
+        super(effect);
+    }
+
+    @Override
+    public EternalizeEffect copy() {
+        return new EternalizeEffect(this);
+    }
+
+    @Override
+    public boolean apply(Game game, Ability source) {
+        Card card = game.getCard(source.getSourceId());
+        Player controller = game.getPlayer(source.getControllerId());
+        if (controller != null && card != null) {
+            EmptyToken token = new EmptyToken();
+            CardUtil.copyTo(token).from(card); // needed so that entersBattlefied triggered abilities see the attributes (e.g. Master Biomancer)
+            token.getColor(game).setColor(ObjectColor.BLACK);
+            if (!token.getSubtype(game).contains("Zombie")) {
+                token.getSubtype(game).add(0, "Zombie");
+            }
+            token.getManaCost().clear();
+            token.getPower().modifyBaseValue(4);
+            token.getToughness().modifyBaseValue(4);
+            game.fireEvent(GameEvent.getEvent(GameEvent.EventType.EMBALMED_CREATURE, token.getId(), source.getSourceId(), controller.getId()));
+            token.putOntoBattlefield(1, game, source.getSourceId(), source.getControllerId(), false, false, null);
+            // Probably it makes sense to remove also the Embalm ability (it's not shown on the token cards).
+            // Also it can never get active or? But it's not mentioned in the reminder text.
+            return true;
+        }
+
+        return false;
+    }
+
+}