* Harbor Serpent - Fixed that the attack restriction did not work correctly.

This commit is contained in:
LevelX2 2015-06-18 11:29:42 +02:00
parent e717ad038b
commit 7ee6e13913
2 changed files with 32 additions and 8 deletions

View file

@ -39,7 +39,6 @@ import mage.abilities.effects.RestrictionEffect;
import mage.abilities.keyword.IslandwalkAbility;
import mage.cards.CardImpl;
import mage.filter.common.FilterLandPermanent;
import mage.filter.predicate.mageobject.SubtypePredicate;
import mage.game.Game;
import mage.game.permanent.Permanent;
@ -58,7 +57,10 @@ public class HarborSerpent extends CardImpl {
this.power = new MageInt(5);
this.toughness = new MageInt(5);
// Islandwalk (This creature is unblockable as long as defending player controls an Island.)
this.addAbility(new IslandwalkAbility());
// Harbor Serpent can't attack unless there are five or more Islands on the battlefield.
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new HarborSerpentEffect()));
}
@ -74,11 +76,10 @@ public class HarborSerpent extends CardImpl {
class HarborSerpentEffect extends RestrictionEffect {
private final FilterLandPermanent filter = new FilterLandPermanent("Island");
private static final FilterLandPermanent filter = new FilterLandPermanent("Island", "Island");
public HarborSerpentEffect() {
super(Duration.WhileOnBattlefield);
filter.add(new SubtypePredicate("Island"));
staticText = "{this} can't attack unless there are five or more Islands on the battlefield";
}
@ -97,10 +98,8 @@ class HarborSerpentEffect extends RestrictionEffect {
}
@Override
public boolean applies(Permanent permanent, Ability source, Game game) {
if (game.getBattlefield().count(filter, source.getSourceId(), source.getControllerId(), game) < 5) {
return true;
}
return false;
public boolean applies(Permanent permanent, Ability source, Game game) {
return permanent.getId().equals(source.getSourceId()) &&
game.getBattlefield().count(filter, source.getSourceId(), source.getControllerId(), game) < 5;
}
}

View file

@ -66,6 +66,31 @@ public class CantAttackTest extends CardTestPlayerBase {
assertLife(playerB, 14); // 4 + 2
}
@Test
public void testAttackHarborSerpent() {
addCard(Zone.BATTLEFIELD, playerA, "Island", 2);
addCard(Zone.BATTLEFIELD, playerA, "Silvercoat Lion"); // 2/2
addCard(Zone.BATTLEFIELD, playerA, "Harbor Serpent"); // 5/5
addCard(Zone.HAND, playerA, "Island");
addCard(Zone.BATTLEFIELD, playerB, "Island", 2);
addCard(Zone.BATTLEFIELD, playerB, "Silvercoat Lion"); // 2/2
addCard(Zone.BATTLEFIELD, playerB, "Harbor Serpent"); // 5/5
attack(2, playerB, "Harbor Serpent");
attack(2, playerB, "Silvercoat Lion");
playLand(3, PhaseStep.PRECOMBAT_MAIN, playerA, "Island");
attack(3, playerA, "Harbor Serpent");
attack(3, playerA, "Silvercoat Lion");
setStopAt(3, PhaseStep.POSTCOMBAT_MAIN);
execute();
assertLife(playerB, 13);
assertLife(playerA, 18);
}
}