diff --git a/Mage.Server.Plugins/Mage.Player.AI/src/main/java/mage/player/ai/ComputerPlayer.java b/Mage.Server.Plugins/Mage.Player.AI/src/main/java/mage/player/ai/ComputerPlayer.java index bc58b023ba3..4e35a867f9e 100644 --- a/Mage.Server.Plugins/Mage.Player.AI/src/main/java/mage/player/ai/ComputerPlayer.java +++ b/Mage.Server.Plugins/Mage.Player.AI/src/main/java/mage/player/ai/ComputerPlayer.java @@ -375,6 +375,9 @@ public class ComputerPlayer> extends PlayerImpl i else { targets = threats(opponentId, ((TargetPermanent)target).getFilter(), game, target.getTargets()); } + if (targets.isEmpty() && target.isRequired()) { + targets = game.getBattlefield().getActivePermanents(((TargetPermanent)target).getFilter(), playerId, game); + } for (Permanent permanent: targets) { if (((TargetPermanent)target).canTarget(playerId, permanent.getId(), source, game)) { target.addTarget(permanent.getId(), source, game); @@ -392,6 +395,9 @@ public class ComputerPlayer> extends PlayerImpl i else { targets = threats(opponentId, ((FilterCreatureOrPlayer)t.getFilter()).getCreatureFilter(), game, target.getTargets()); } + if (targets.isEmpty() && target.isRequired()) { + targets = game.getBattlefield().getActivePermanents(((FilterCreatureOrPlayer)t.getFilter()).getCreatureFilter(), playerId, game); + } for (Permanent permanent : targets) { List alreadyTargetted = target.getTargets(); if (t.canTarget(playerId, permanent.getId(), source, game)) { diff --git a/Mage.Server/plugins/mage-player-ai.jar b/Mage.Server/plugins/mage-player-ai.jar index edd676fe8ec..3dbe4404426 100644 Binary files a/Mage.Server/plugins/mage-player-ai.jar and b/Mage.Server/plugins/mage-player-ai.jar differ diff --git a/Mage.Sets/src/mage/sets/darkascension/HollowhengeSpirit.java b/Mage.Sets/src/mage/sets/darkascension/HollowhengeSpirit.java new file mode 100644 index 00000000000..69f8e811e94 --- /dev/null +++ b/Mage.Sets/src/mage/sets/darkascension/HollowhengeSpirit.java @@ -0,0 +1,77 @@ +/* + * 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.darkascension; + +import java.util.UUID; +import mage.Constants.CardType; +import mage.Constants.Rarity; +import mage.MageInt; +import mage.abilities.Ability; +import mage.abilities.common.EntersBattlefieldTriggeredAbility; +import mage.abilities.effects.common.RemoveFromCombatTargetEffect; +import mage.abilities.keyword.FlashAbility; +import mage.abilities.keyword.FlyingAbility; +import mage.cards.CardImpl; +import mage.target.Target; +import mage.target.common.TargetAttackingOrBlockingCreature; + +/** + * + * @author BetaSteward + */ +public class HollowhengeSpirit extends CardImpl { + + public HollowhengeSpirit(UUID ownerId) { + super(ownerId, 10, "Hollowhenge Spirit", Rarity.UNCOMMON, new CardType[]{CardType.CREATURE}, "{3}{W}"); + this.expansionSetCode = "DKA"; + this.subtype.add("Spirit"); + + this.color.setWhite(true); + this.power = new MageInt(2); + this.toughness = new MageInt(2); + + this.addAbility(FlashAbility.getInstance()); + this.addAbility(FlyingAbility.getInstance()); + // When Hollowhenge Spirit enters the battlefield, remove target attacking or blocking creature from combat. + Ability ability = new EntersBattlefieldTriggeredAbility(new RemoveFromCombatTargetEffect()); + Target target = new TargetAttackingOrBlockingCreature(); + target.setRequired(true); + ability.addTarget(target); + this.addAbility(ability); + + } + + public HollowhengeSpirit(final HollowhengeSpirit card) { + super(card); + } + + @Override + public HollowhengeSpirit copy() { + return new HollowhengeSpirit(this); + } +} diff --git a/Mage.Sets/src/mage/sets/darkascension/LostInTheWoods.java b/Mage.Sets/src/mage/sets/darkascension/LostInTheWoods.java new file mode 100644 index 00000000000..4abe214c082 --- /dev/null +++ b/Mage.Sets/src/mage/sets/darkascension/LostInTheWoods.java @@ -0,0 +1,157 @@ +/* + * 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.darkascension; + +import java.util.UUID; +import mage.Constants; +import mage.Constants.CardType; +import mage.Constants.Outcome; +import mage.Constants.Rarity; +import mage.abilities.Ability; +import mage.abilities.TriggeredAbilityImpl; +import mage.abilities.common.EntersBattlefieldTriggeredAbility; +import mage.abilities.effects.Effect; +import mage.cards.CardImpl; +import mage.abilities.effects.OneShotEffect; +import mage.abilities.effects.common.DiscardTargetEffect; +import mage.cards.Card; +import mage.cards.Cards; +import mage.cards.CardsImpl; +import mage.game.Game; +import mage.game.events.GameEvent; +import mage.game.permanent.Permanent; +import mage.players.Player; +import mage.target.TargetPlayer; +import mage.target.targetpointer.FixedTarget; + +/** + * + * @author BetaSteward + */ +public class LostInTheWoods extends CardImpl { + + public LostInTheWoods(UUID ownerId) { + super(ownerId, 123, "Lost in the Woods", Rarity.RARE, new CardType[]{CardType.ENCHANTMENT}, "{3}{G}{G}"); + this.expansionSetCode = "DKA"; + + this.color.setGreen(true); + + // Whenever a creature attacks you or a planeswalker you control, reveal the top card of your library. If it's a Forest card, remove that creature from combat. Then put the revealed card on the bottom of your library. + this.addAbility(new LostInTheWoodsTriggeredAbility()); + } + + public LostInTheWoods(final LostInTheWoods card) { + super(card); + } + + @Override + public LostInTheWoods copy() { + return new LostInTheWoods(this); + } +} + +class LostInTheWoodsEffect extends OneShotEffect { + + public LostInTheWoodsEffect() { + super(Outcome.PreventDamage); + } + + public LostInTheWoodsEffect(final LostInTheWoodsEffect effect) { + super(effect); + } + + @Override + public boolean apply(Game game, Ability source) { + Player player = game.getPlayer(source.getControllerId()); + if (player == null) { + return false; + } + + if (player.getLibrary().size() > 0) { + Card card = player.getLibrary().getFromTop(game); + Cards cards = new CardsImpl(); + cards.add(card); + player.revealCards("Lost in the Woods", cards, game); + + if (card != null) { + if (card.getName().equals("Forest")) { + Permanent permanent = game.getPermanent(targetPointer.getFirst(source)); + if (permanent != null) { + permanent.removeFromCombat(game); + } + } + card.moveToZone(Constants.Zone.LIBRARY, source.getId(), game, false); + return true; + } + } + return false; + } + + @Override + public LostInTheWoodsEffect copy() { + return new LostInTheWoodsEffect(this); + } + +} + +class LostInTheWoodsTriggeredAbility extends TriggeredAbilityImpl { + + public LostInTheWoodsTriggeredAbility() { + super(Constants.Zone.BATTLEFIELD, new LostInTheWoodsEffect(), false); + } + + public LostInTheWoodsTriggeredAbility(final LostInTheWoodsTriggeredAbility ability) { + super(ability); + } + + @Override + public LostInTheWoodsTriggeredAbility copy() { + return new LostInTheWoodsTriggeredAbility(this); + } + + @Override + public boolean checkTrigger(GameEvent event, Game game) { + if (event.getType() == GameEvent.EventType.ATTACKER_DECLARED) { + if (event.getTargetId().equals(controllerId)) { + this.getEffects().get(0).setTargetPointer(new FixedTarget(event.getSourceId())); + return true; + } + Permanent permanent = game.getPermanent(event.getTargetId()); + if (permanent != null && permanent.getCardType().contains(CardType.PLANESWALKER) && permanent.getControllerId().equals(controllerId)) { + this.getEffects().get(0).setTargetPointer(new FixedTarget(event.getSourceId())); + return true; + } + } + return false; + } + + @Override + public String getRule() { + return "Whenever a creature attacks you or a planeswalker you control, reveal the top card of your library. If it's a Forest card, remove that creature from combat. Then put the revealed card on the bottom of your library."; + } +} diff --git a/Mage.Tests/plugins/mage-player-ai.jar b/Mage.Tests/plugins/mage-player-ai.jar index edd676fe8ec..3dbe4404426 100644 Binary files a/Mage.Tests/plugins/mage-player-ai.jar and b/Mage.Tests/plugins/mage-player-ai.jar differ diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/TestHollowhengeSpirit.java b/Mage.Tests/src/test/java/org/mage/test/cards/TestHollowhengeSpirit.java new file mode 100644 index 00000000000..9be11323008 --- /dev/null +++ b/Mage.Tests/src/test/java/org/mage/test/cards/TestHollowhengeSpirit.java @@ -0,0 +1,71 @@ +package org.mage.test.cards; + +import mage.Constants; +import org.junit.Ignore; +import org.junit.Test; +import org.mage.test.serverside.base.CardTestPlayerBase; + +/** + * + * also tests required targets + * + * @author BetaSteward + */ +public class TestHollowhengeSpirit extends CardTestPlayerBase { + + @Test + public void testCard() { + addCard(Constants.Zone.BATTLEFIELD, playerA, "Plains", 4); + addCard(Constants.Zone.HAND, playerA, "Hollowhenge Spirit"); + addCard(Constants.Zone.BATTLEFIELD, playerB, "Craw Wurm"); + + castSpell(2, Constants.PhaseStep.DECLARE_BLOCKERS, playerA, "Hollowhenge Spirit"); + attack(2, playerB, "Craw Wurm"); + setStopAt(2, Constants.PhaseStep.END_TURN); + execute(); + + assertLife(playerA, 20); + assertLife(playerB, 20); + assertPermanentCount(playerA, "Hollowhenge Spirit", 1); + assertPermanentCount(playerB, "Craw Wurm", 1); + assertTapped("Hollowhenge Spirit", false); + assertTapped("Craw Wurm", true); + } + + @Test + public void testCard1() { + addCard(Constants.Zone.BATTLEFIELD, playerA, "Plains", 4); + addCard(Constants.Zone.HAND, playerA, "Hollowhenge Spirit"); + addCard(Constants.Zone.BATTLEFIELD, playerA, "Craw Wurm"); + + castSpell(1, Constants.PhaseStep.DECLARE_BLOCKERS, playerA, "Hollowhenge Spirit"); + attack(1, playerA, "Craw Wurm"); + setStopAt(1, Constants.PhaseStep.END_TURN); + execute(); + + assertLife(playerA, 20); + assertLife(playerB, 20); + assertPermanentCount(playerA, "Hollowhenge Spirit", 1); + assertPermanentCount(playerA, "Craw Wurm", 1); + assertTapped("Hollowhenge Spirit", false); + assertTapped("Craw Wurm", true); + } + + @Test + public void testCard2() { + addCard(Constants.Zone.BATTLEFIELD, playerA, "Plains", 4); + addCard(Constants.Zone.HAND, playerA, "Hollowhenge Spirit"); + addCard(Constants.Zone.BATTLEFIELD, playerA, "Craw Wurm"); + + castSpell(1, Constants.PhaseStep.PRECOMBAT_MAIN, playerA, "Hollowhenge Spirit"); + setStopAt(1, Constants.PhaseStep.END_TURN); + execute(); + + assertLife(playerA, 20); + assertLife(playerB, 20); + assertPermanentCount(playerA, "Hollowhenge Spirit", 1); + assertPermanentCount(playerA, "Craw Wurm", 1); + assertTapped("Craw Wurm", false); + } + +} diff --git a/Mage/src/mage/abilities/effects/common/RemoveFromCombatTargetEffect.java b/Mage/src/mage/abilities/effects/common/RemoveFromCombatTargetEffect.java new file mode 100644 index 00000000000..bd6acc26f13 --- /dev/null +++ b/Mage/src/mage/abilities/effects/common/RemoveFromCombatTargetEffect.java @@ -0,0 +1,72 @@ +/* +* Copyright 2012 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.effects.common; + +import mage.Constants; +import mage.Constants.Outcome; +import mage.abilities.Ability; +import mage.abilities.Mode; +import mage.abilities.effects.OneShotEffect; +import mage.game.Game; +import mage.game.permanent.Permanent; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class RemoveFromCombatTargetEffect extends OneShotEffect { + + public RemoveFromCombatTargetEffect() { + super(Outcome.Detriment); + } + + public RemoveFromCombatTargetEffect(final RemoveFromCombatTargetEffect effect) { + super(effect); + } + + @Override + public boolean apply(Game game, Ability source) { + Permanent permanent = game.getPermanent(targetPointer.getFirst(source)); + if (permanent != null) { + permanent.removeFromCombat(game); + } + return false; + } + + @Override + public RemoveFromCombatTargetEffect copy() { + return new RemoveFromCombatTargetEffect(this); + } + + @Override + public String getText(Mode mode) { + return "Remove target " + mode.getTargets().get(0).getTargetName() + " from combat"; + } + +}