From 629b5fd589b63ce997abcd47399d1a55fc2b2684 Mon Sep 17 00:00:00 2001 From: magenoxx Date: Sat, 12 May 2012 15:23:38 +0400 Subject: [PATCH] [AVR] Hunted Ghoul with tests --- .../mage/sets/avacynrestored/HuntedGhoul.java | 127 ++++++++++++++++++ .../combat/AttackBlockRestrictionsTest.java | 42 ++++++ 2 files changed, 169 insertions(+) create mode 100644 Mage.Sets/src/mage/sets/avacynrestored/HuntedGhoul.java diff --git a/Mage.Sets/src/mage/sets/avacynrestored/HuntedGhoul.java b/Mage.Sets/src/mage/sets/avacynrestored/HuntedGhoul.java new file mode 100644 index 00000000000..4828429d7f1 --- /dev/null +++ b/Mage.Sets/src/mage/sets/avacynrestored/HuntedGhoul.java @@ -0,0 +1,127 @@ +/* + * 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.avacynrestored; + +import mage.Constants; +import mage.Constants.CardType; +import mage.Constants.Rarity; +import mage.MageInt; +import mage.abilities.Ability; +import mage.abilities.EvasionAbility; +import mage.abilities.effects.RestrictionEffect; +import mage.cards.CardImpl; +import mage.game.Game; +import mage.game.permanent.Permanent; + +import java.util.UUID; + +/** + * @author noxx + */ +public class HuntedGhoul extends CardImpl { + + public HuntedGhoul(UUID ownerId) { + super(ownerId, 110, "Hunted Ghoul", Rarity.COMMON, new CardType[]{CardType.CREATURE}, "{B}"); + this.expansionSetCode = "AVR"; + this.subtype.add("Zombie"); + + this.color.setBlack(true); + this.power = new MageInt(1); + this.toughness = new MageInt(2); + + // Hunted Ghoul can't block Humans. + this.addAbility(HuntedGhoulAbility.getInstance()); + } + + public HuntedGhoul(final HuntedGhoul card) { + super(card); + } + + @Override + public HuntedGhoul copy() { + return new HuntedGhoul(this); + } +} + +class HuntedGhoulAbility extends EvasionAbility { + + private static HuntedGhoulAbility instance; + + public static HuntedGhoulAbility getInstance() { + if (instance == null) { + instance = new HuntedGhoulAbility(); + } + return instance; + } + + private HuntedGhoulAbility() { + this.addEffect(new HuntedGhoulEffect()); + } + + @Override + public String getRule() { + return "{this} can't block Humans."; + } + + @Override + public HuntedGhoulAbility copy() { + return getInstance(); + } +} + +class HuntedGhoulEffect extends RestrictionEffect { + + public HuntedGhoulEffect() { + super(Constants.Duration.WhileOnBattlefield); + } + + public HuntedGhoulEffect(final HuntedGhoulEffect effect) { + super(effect); + } + + @Override + public boolean applies(Permanent permanent, Ability source, Game game) { + if (permanent.getAbilities().containsKey(HuntedGhoulAbility.getInstance().getId())) { + return true; + } + return false; + } + + @Override + public boolean canBlock(Permanent attacker, Permanent blocker, Ability source, Game game) { + if (attacker.getSubtype().contains("Human")) { + return false; + } + return true; + } + + @Override + public HuntedGhoulEffect copy() { + return new HuntedGhoulEffect(this); + } +} diff --git a/Mage.Tests/src/test/java/org/mage/test/combat/AttackBlockRestrictionsTest.java b/Mage.Tests/src/test/java/org/mage/test/combat/AttackBlockRestrictionsTest.java index 06af1be8496..0bae98c71cd 100644 --- a/Mage.Tests/src/test/java/org/mage/test/combat/AttackBlockRestrictionsTest.java +++ b/Mage.Tests/src/test/java/org/mage/test/combat/AttackBlockRestrictionsTest.java @@ -51,4 +51,46 @@ public class AttackBlockRestrictionsTest extends CardTestPlayerBase { Permanent crawWurm = getPermanent("Craw Wurm", playerB.getId()); Assert.assertTrue("Should be tapped because of being blocked by Wall of Frost", crawWurm.isTapped()); } + + /** + * Tests card that says that it can't block specific cards + * Hunted Ghoul: + * Hunted Ghoul can't block Humans. + */ + @Test + public void testFilteredBlocking() { + addCard(Constants.Zone.BATTLEFIELD, playerA, "Hunted Ghoul"); + addCard(Constants.Zone.BATTLEFIELD, playerB, "Elite Vanguard"); + + attack(2, playerB, "Elite Vanguard"); + block(2, playerA, "Hunted Ghoul", "Elite Vanguard"); + + setStopAt(4, Constants.PhaseStep.END_TURN); + execute(); + + assertLife(playerA, 18); + assertLife(playerB, 20); + } + + /** + * Tests card that says that it can't block specific cards still can block others + * Hunted Ghoul: + * Hunted Ghoul can't block Humans. + */ + @Test + public void testFilteredBlocking2() { + addCard(Constants.Zone.BATTLEFIELD, playerA, "Hunted Ghoul"); + addCard(Constants.Zone.BATTLEFIELD, playerB, "Craw Wurm"); + + attack(2, playerB, "Craw Wurm"); + block(2, playerA, "Hunted Ghoul", "Craw Wurm"); + + setStopAt(4, Constants.PhaseStep.END_TURN); + execute(); + + assertLife(playerA, 20); + assertLife(playerB, 20); + + assertPermanentCount(playerA, "Hunted Ghoul", 0); + } }