diff --git a/Mage.Sets/src/mage/sets/magic2013/SerraAvenger.java b/Mage.Sets/src/mage/sets/magic2013/SerraAvenger.java new file mode 100644 index 00000000000..406fb6de92f --- /dev/null +++ b/Mage.Sets/src/mage/sets/magic2013/SerraAvenger.java @@ -0,0 +1,51 @@ +/* + * 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.magic2013; + +import java.util.UUID; + +/** + * @author noxx + */ +public class SerraAvenger extends mage.sets.timespiral.SerraAvenger { + + public SerraAvenger(UUID ownerId) { + super(ownerId); + this.cardNumber = 33; + this.expansionSetCode = "M13"; + } + + public SerraAvenger(final SerraAvenger card) { + super(card); + } + + @Override + public SerraAvenger copy() { + return new SerraAvenger(this); + } +} diff --git a/Mage.Sets/src/mage/sets/timespiral/SerraAvenger.java b/Mage.Sets/src/mage/sets/timespiral/SerraAvenger.java new file mode 100644 index 00000000000..cdb5ad83035 --- /dev/null +++ b/Mage.Sets/src/mage/sets/timespiral/SerraAvenger.java @@ -0,0 +1,118 @@ +/* + * 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.timespiral; + +import mage.Constants.CardType; +import mage.Constants.Rarity; +import mage.MageInt; +import mage.abilities.Ability; +import mage.abilities.costs.CostImpl; +import mage.abilities.keyword.FlyingAbility; +import mage.abilities.keyword.VigilanceAbility; +import mage.cards.CardImpl; +import mage.game.Game; +import mage.players.Player; + +import java.util.UUID; + +/** + * @author noxx + */ +public class SerraAvenger extends CardImpl { + + private static final String rule = "You can't cast Serra Avenger during your first, second, or third turns of the game"; + + public SerraAvenger(UUID ownerId) { + super(ownerId, 40, "Serra Avenger", Rarity.RARE, new CardType[]{CardType.CREATURE}, "{W}{W}"); + this.expansionSetCode = "TSP"; + this.subtype.add("Angel"); + + this.color.setWhite(true); + this.power = new MageInt(3); + this.toughness = new MageInt(3); + + // Flying + this.addAbility(FlyingAbility.getInstance()); + + // Vigilance + this.addAbility(VigilanceAbility.getInstance()); + + // You can't cast Serra Avenger during your first, second, or third turns of the game. + this.getSpellAbility().addCost(new SerraAvengerCost()); + this.addInfo("cost", rule); + } + + public SerraAvenger(final SerraAvenger card) { + super(card); + } + + @Override + public SerraAvenger copy() { + return new SerraAvenger(this); + } +} + +class SerraAvengerCost extends CostImpl { + + public SerraAvengerCost() { + text = "You can't cast Serra Avenger during your first, second, or third turns of the game"; + } + + public SerraAvengerCost(final SerraAvengerCost cost) { + super(cost); + } + + @Override + public SerraAvengerCost copy() { + return new SerraAvengerCost(this); + } + + @Override + public boolean canPay(UUID sourceId, UUID controllerId, Game game) { + if (game.getActivePlayerId().equals(controllerId)) { + Player controller = game.getPlayer(controllerId); + if (controller.getTurns() > 3) { + return true; + } else { + game.informPlayer(controller, "You can't cass Serra Avenger (your turns passed: " + controller.getTurns() + ")"); + return false; + } + } + + // Always return true for not controller's turn: + // 9/25/2006: You can cast Serra Avenger during another player's first, second, or third turns of the game + // if some other effect (such as Vedalken Orrery) enables that. + return true; + } + + @Override + public boolean pay(Ability ability, Game game, UUID sourceId, UUID controllerId, boolean noMana) { + this.paid = true; + return paid; + } +} \ No newline at end of file diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/cost/custom/SerraAvengerTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/cost/custom/SerraAvengerTest.java new file mode 100644 index 00000000000..940e8a71c5d --- /dev/null +++ b/Mage.Tests/src/test/java/org/mage/test/cards/cost/custom/SerraAvengerTest.java @@ -0,0 +1,55 @@ +package org.mage.test.cards.cost.custom; + +import mage.Constants; +import org.junit.Test; +import org.mage.test.serverside.base.CardTestPlayerBase; + +/** + * + * @author noxx + */ +public class SerraAvengerTest extends CardTestPlayerBase { + + /** + * Try to cast Serra Avenger on 1st, 2nd, 3rd and 4th turns. + * It should success only on 4th one. + */ + @Test + public void testCard() { + addCard(Constants.Zone.BATTLEFIELD, playerA, "Plains", 2); + addCard(Constants.Zone.HAND, playerA, "Serra Avenger", 4); + + castSpell(1, Constants.PhaseStep.PRECOMBAT_MAIN, playerA, "Serra Avenger"); + castSpell(3, Constants.PhaseStep.PRECOMBAT_MAIN, playerA, "Serra Avenger"); + castSpell(5, Constants.PhaseStep.PRECOMBAT_MAIN, playerA, "Serra Avenger"); + castSpell(7, Constants.PhaseStep.PRECOMBAT_MAIN, playerA, "Serra Avenger"); + + setStopAt(7, Constants.PhaseStep.BEGIN_COMBAT); + execute(); + + assertPermanentCount(playerA, "Serra Avenger", 1); // only the one that was cast on 4th turn + } + + /** + * Tests that we may cast Serra Avenger "earlier" if we use extra turns + */ + @Test + public void testWithExtraTurns() { + addCard(Constants.Zone.BATTLEFIELD, playerA, "Plains", 5); + addCard(Constants.Zone.BATTLEFIELD, playerA, "Island", 2); + addCard(Constants.Zone.HAND, playerA, "Time Warp", 3); + addCard(Constants.Zone.HAND, playerA, "Serra Avenger", 1); + + castSpell(1, Constants.PhaseStep.PRECOMBAT_MAIN, playerA, "Time Warp", playerA); + castSpell(2, Constants.PhaseStep.PRECOMBAT_MAIN, playerA, "Time Warp", playerA); + castSpell(3, Constants.PhaseStep.PRECOMBAT_MAIN, playerA, "Time Warp", playerA); + castSpell(4, Constants.PhaseStep.PRECOMBAT_MAIN, playerA, "Serra Avenger"); + + setStopAt(4, Constants.PhaseStep.BEGIN_COMBAT); + execute(); + + assertGraveyardCount(playerA, "Time Warp", 3); + assertPermanentCount(playerA, "Serra Avenger", 1); + } + +} diff --git a/Mage/src/mage/players/Player.java b/Mage/src/mage/players/Player.java index 5bd3e80ac2f..d1f39fcb814 100644 --- a/Mage/src/mage/players/Player.java +++ b/Mage/src/mage/players/Player.java @@ -261,4 +261,6 @@ public interface Player extends MageItem, Copyable { * Signals that the player becomes active player in this turn. */ public void becomesActivePlayer(); + + public int getTurns(); } diff --git a/Mage/src/mage/players/PlayerImpl.java b/Mage/src/mage/players/PlayerImpl.java index de1a17c61d2..7030aa7d234 100644 --- a/Mage/src/mage/players/PlayerImpl.java +++ b/Mage/src/mage/players/PlayerImpl.java @@ -97,6 +97,8 @@ public abstract class PlayerImpl> implements Player, Ser protected ManaPool manaPool; protected boolean passed; protected boolean passedTurn; + protected int turns; + /** * This indicates that player passed all turns until his own turn starts. * Note! This differs from passedTurn as it doesn't care about spells and abilities in the stack and will pass them as well. @@ -158,6 +160,7 @@ public abstract class PlayerImpl> implements Player, Ser this.passed = player.passed; this.passedTurn = player.passedTurn; this.passedAllTurns = player.passedAllTurns; + this.turns = player.turns; this.left = player.left; this.range = player.range; this.canGainLife = player.canGainLife; @@ -1456,5 +1459,12 @@ public abstract class PlayerImpl> implements Player, Ser @Override public void becomesActivePlayer() { this.passedAllTurns = false; + this.turns++; } + + @Override + public int getTurns() { + return turns; + } + }