mirror of
https://github.com/correl/mage.git
synced 2025-03-07 20:53:18 -10:00
* Brain Maggot - Fixed that the exiled cards were not returned to opponents hand.
This commit is contained in:
parent
ad012ebd02
commit
1342af5349
5 changed files with 146 additions and 26 deletions
|
@ -138,11 +138,11 @@ class BaneAlleyBrokerDrawExileEffect extends OneShotEffect {
|
|||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Player player = game.getPlayer(source.getControllerId());
|
||||
if (player != null) {
|
||||
player.drawCards(1, game);
|
||||
Player controller = game.getPlayer(source.getControllerId());
|
||||
if (controller != null) {
|
||||
controller.drawCards(1, game);
|
||||
Target target = new TargetCardInHand(new FilterCard("card to exile"));
|
||||
if (player.chooseTarget(outcome, target, source, game)) {
|
||||
if (controller.chooseTarget(outcome, target, source, game)) {
|
||||
Card card = game.getCard(target.getFirstTarget());
|
||||
MageObject sourceObject = game.getObject(source.getSourceId());
|
||||
if (card != null && sourceObject != null) {
|
||||
|
|
|
@ -117,7 +117,7 @@ class BrainMaggotExileEffect extends OneShotEffect {
|
|||
Card card = opponent.getHand().get(target.getFirstTarget(), game);
|
||||
// If source permanent leaves the battlefield before its triggered ability resolves, the target card won't be exiled.
|
||||
if (card != null && game.getState().getZone(source.getSourceId()) == Zone.BATTLEFIELD) {
|
||||
controller.moveCardToExileWithInfo(card, CardUtil.getCardExileZoneId(game, source), sourcePermanent.getName(), source.getSourceId(), game, Zone.HAND);
|
||||
controller.moveCardToExileWithInfo(card, CardUtil.getObjectExileZoneId(game, sourcePermanent), sourcePermanent.getName(), source.getSourceId(), game, Zone.HAND);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -183,7 +183,7 @@ class BrainMaggotReturnExiledCreatureEffect extends OneShotEffect {
|
|||
public boolean apply(Game game, Ability source) {
|
||||
Player controller = game.getPlayer(source.getControllerId());
|
||||
if (controller != null) {
|
||||
ExileZone exile = game.getExile().getExileZone(CardUtil.getCardExileZoneId(game, source));
|
||||
ExileZone exile = game.getExile().getExileZone(CardUtil.getObjectExileZoneId(game, source.getSourceObject(game)));
|
||||
Permanent sourcePermanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
|
||||
if (exile != null && sourcePermanent != null) {
|
||||
LinkedList<UUID> cards = new LinkedList<>(exile);
|
||||
|
|
|
@ -119,18 +119,20 @@ class AshiokNightmareWeaverExileEffect extends OneShotEffect {
|
|||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
UUID exileId = CardUtil.getCardExileZoneId(game, source);
|
||||
Player opponent = game.getPlayer(this.getTargetPointer().getFirst(game, source));
|
||||
Player controller = game.getPlayer(source.getControllerId());
|
||||
MageObject sourceObject = game.getObject(source.getSourceId());
|
||||
MageObject sourceObject = source.getSourceObject(game);
|
||||
if (sourceObject != null && opponent != null && controller != null) {
|
||||
for (int i = 0; i < 3; i++) {
|
||||
Card card = opponent.getLibrary().getFromTop(game);
|
||||
if (card != null) {
|
||||
controller.moveCardToExileWithInfo(card, exileId, sourceObject.getLogName(), source.getSourceId(), game, Zone.LIBRARY);
|
||||
UUID exileZone = CardUtil.getObjectExileZoneId(game, sourceObject);
|
||||
if (exileZone != null) {
|
||||
for (int i = 0; i < 3; i++) {
|
||||
Card card = opponent.getLibrary().getFromTop(game);
|
||||
if (card != null) {
|
||||
controller.moveCardToExileWithInfo(card, exileZone, sourceObject.getLogName(), source.getSourceId(), game, Zone.LIBRARY);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -154,8 +156,9 @@ class AshiokNightmareWeaverPutIntoPlayEffect extends OneShotEffect {
|
|||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Player player = game.getPlayer(source.getControllerId());
|
||||
if (player == null) {
|
||||
Player controller = game.getPlayer(source.getControllerId());
|
||||
MageObject sourceObject = source.getSourceObject(game);
|
||||
if (sourceObject == null || controller == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -169,12 +172,13 @@ class AshiokNightmareWeaverPutIntoPlayEffect extends OneShotEffect {
|
|||
FilterCard filter = new FilterCreatureCard(new StringBuilder("creature card with converted mana cost {").append(cmc).append("} exiled with Ashiok, Nightmare Weaver").toString());
|
||||
filter.add(new ConvertedManaCostPredicate(Filter.ComparisonType.Equal, cmc));
|
||||
|
||||
Target target = new TargetCardInExile(filter, CardUtil.getCardExileZoneId(game, source.getSourceId(), game.getPermanent(source.getSourceId()) == null));
|
||||
Target target = new TargetCardInExile(filter, CardUtil.getObjectExileZoneId(game, sourceObject));
|
||||
|
||||
if (target.canChoose(source.getSourceId(), player.getId(), game)) {
|
||||
if (player.chooseTarget(Outcome.PutCreatureInPlay, target, source, game)) {
|
||||
|
||||
if (target.canChoose(source.getSourceId(), controller.getId(), game)) {
|
||||
if (controller.chooseTarget(Outcome.PutCreatureInPlay, target, source, game)) {
|
||||
Card card = game.getCard(target.getFirstTarget());
|
||||
if (card != null && player.putOntoBattlefieldWithInfo(card, game, Zone.EXILED, source.getSourceId())) {
|
||||
if (card != null && controller.putOntoBattlefieldWithInfo(card, game, Zone.EXILED, source.getSourceId())) {
|
||||
// why is this change of controller neccessary?
|
||||
Permanent permanent = game.getPermanent(card.getId());
|
||||
if (permanent != null) {
|
||||
|
@ -256,7 +260,15 @@ class AshiokNightmareWeaverExileAllEffect extends OneShotEffect {
|
|||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
UUID exileId = CardUtil.getCardExileZoneId(game, source);
|
||||
Player controller = game.getPlayer(source.getControllerId());
|
||||
MageObject sourceObject = source.getSourceObject(game);
|
||||
if (sourceObject == null || controller == null) {
|
||||
return false;
|
||||
}
|
||||
UUID exileId = CardUtil.getObjectExileZoneId(game, sourceObject);
|
||||
if (exileId == null) {
|
||||
return false;
|
||||
}
|
||||
for (UUID opponentId: game.getOpponents(source.getControllerId())) {
|
||||
Player opponent = game.getPlayer(opponentId);
|
||||
if (opponent != null) {
|
||||
|
@ -265,7 +277,7 @@ class AshiokNightmareWeaverExileAllEffect extends OneShotEffect {
|
|||
for (UUID cardId : cards) {
|
||||
Card card = game.getCard(cardId);
|
||||
if (card != null) {
|
||||
card.moveToExile(exileId, "Ashiok, Nightmare Weaver", source.getSourceId(), game);
|
||||
controller.moveCardToExileWithInfo(card, exileId, sourceObject.getLogName(), source.getSourceId(), game, Zone.HAND);
|
||||
}
|
||||
}
|
||||
cards.clear();
|
||||
|
@ -273,7 +285,7 @@ class AshiokNightmareWeaverExileAllEffect extends OneShotEffect {
|
|||
for (UUID cardId :cards) {
|
||||
Card card = game.getCard(cardId);
|
||||
if (card != null) {
|
||||
card.moveToExile(exileId, "Ashiok, Nightmare Weaver", source.getSourceId(), game);
|
||||
controller.moveCardToExileWithInfo(card, exileId, sourceObject.getLogName(), source.getSourceId(), game, Zone.GRAVEYARD);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -102,15 +102,15 @@ class MesmericFiendExileEffect extends OneShotEffect {
|
|||
public boolean apply(Game game, Ability source) {
|
||||
Player controller = game.getPlayer(source.getControllerId());
|
||||
Player opponent = game.getPlayer(source.getFirstTarget());
|
||||
Permanent sourcePermanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
|
||||
Permanent sourcePermanent = (Permanent) source.getSourceObject(game);
|
||||
if (controller != null && opponent != null && sourcePermanent != null) {
|
||||
opponent.revealCards(sourcePermanent.getName(), opponent.getHand(), game);
|
||||
|
||||
TargetCard target = new TargetCard(Zone.PICK, new FilterNonlandCard("nonland card to exile"));
|
||||
TargetCard target = new TargetCard(Zone.HAND, new FilterNonlandCard("nonland card to exile"));
|
||||
if (controller.choose(Outcome.Exile, opponent.getHand(), target, game)) {
|
||||
Card card = opponent.getHand().get(target.getFirstTarget(), game);
|
||||
if (card != null) {
|
||||
controller.moveCardToExileWithInfo(card, CardUtil.getCardExileZoneId(game, source), sourcePermanent.getName(), source.getSourceId(), game, Zone.HAND);
|
||||
controller.moveCardToExileWithInfo(card, CardUtil.getObjectExileZoneId(game, sourcePermanent), sourcePermanent.getName(), source.getSourceId(), game, Zone.HAND);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -142,7 +142,7 @@ class MesmericFiendLeaveEffect extends OneShotEffect {
|
|||
public boolean apply(Game game, Ability source) {
|
||||
Player controller = game.getPlayer(source.getControllerId());
|
||||
if (controller != null) {
|
||||
ExileZone exZone = game.getExile().getExileZone(CardUtil.getCardExileZoneId(game, source.getSourceId(), true));
|
||||
ExileZone exZone = game.getExile().getExileZone(CardUtil.getObjectExileZoneId(game, source.getSourceObject(game)));
|
||||
if (exZone != null) {
|
||||
for (Card card : exZone.getCards(game)) {
|
||||
if (card != null) {
|
||||
|
|
|
@ -0,0 +1,108 @@
|
|||
/*
|
||||
* 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 org.mage.test.cards.triggers.dies;
|
||||
|
||||
import mage.constants.PhaseStep;
|
||||
import mage.constants.Zone;
|
||||
import org.junit.Test;
|
||||
import org.mage.test.serverside.base.CardTestPlayerBase;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author LevelX2
|
||||
*/
|
||||
|
||||
public class BrainMaggotTest extends CardTestPlayerBase {
|
||||
|
||||
/**
|
||||
* When Brain Maggot enters the battlefield, target opponent reveals his or her hand and
|
||||
* you choose a nonland card from it. Exile that card until Brain Maggot leaves the battlefield.
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testCardFromHandWillBeExiled() {
|
||||
addCard(Zone.BATTLEFIELD, playerA, "Swamp", 2);
|
||||
addCard(Zone.HAND, playerA, "Brain Maggot", 2);
|
||||
|
||||
addCard(Zone.HAND, playerB, "Bloodflow Connoisseur", 1);
|
||||
|
||||
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Brain Maggot");
|
||||
addTarget(playerA, "Bloodflow Connoisseur");
|
||||
|
||||
setStopAt(1, PhaseStep.BEGIN_COMBAT);
|
||||
execute();
|
||||
|
||||
assertPermanentCount(playerA, "Brain Maggot", 1);
|
||||
assertExileCount("Bloodflow Connoisseur", 1);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testCardFromHandWillBeExiledAndReturn() {
|
||||
addCard(Zone.BATTLEFIELD, playerA, "Swamp", 2);
|
||||
addCard(Zone.HAND, playerA, "Brain Maggot", 2);
|
||||
|
||||
addCard(Zone.HAND, playerB, "Bloodflow Connoisseur", 1);
|
||||
addCard(Zone.HAND, playerB, "Lightning Bolt", 1);
|
||||
addCard(Zone.BATTLEFIELD, playerB, "Mountain", 2);
|
||||
|
||||
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Brain Maggot");
|
||||
addTarget(playerA, "Bloodflow Connoisseur");
|
||||
castSpell(1, PhaseStep.BEGIN_COMBAT, playerB, "Lightning Bolt", "Brain Maggot");
|
||||
|
||||
setStopAt(1, PhaseStep.DECLARE_ATTACKERS);
|
||||
execute();
|
||||
|
||||
assertGraveyardCount(playerA, "Brain Maggot", 1);
|
||||
assertGraveyardCount(playerB, "Lightning Bolt", 1);
|
||||
assertHandCount(playerB, "Bloodflow Connoisseur", 1);
|
||||
assertExileCount("Bloodflow Connoisseur", 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCardFromHandWillBeExiledAndReturnMesmericFiend() {
|
||||
addCard(Zone.BATTLEFIELD, playerA, "Swamp", 2);
|
||||
addCard(Zone.HAND, playerA, "Mesmeric Fiend", 2);
|
||||
|
||||
addCard(Zone.HAND, playerB, "Bloodflow Connoisseur", 1);
|
||||
addCard(Zone.HAND, playerB, "Lightning Bolt", 1);
|
||||
addCard(Zone.BATTLEFIELD, playerB, "Mountain", 2);
|
||||
|
||||
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Mesmeric Fiend");
|
||||
addTarget(playerA, "Bloodflow Connoisseur");
|
||||
castSpell(1, PhaseStep.BEGIN_COMBAT, playerB, "Lightning Bolt", "Mesmeric Fiend");
|
||||
|
||||
setStopAt(1, PhaseStep.DECLARE_ATTACKERS);
|
||||
execute();
|
||||
|
||||
assertGraveyardCount(playerA, "Mesmeric Fiend", 1);
|
||||
assertGraveyardCount(playerB, "Lightning Bolt", 1);
|
||||
assertHandCount(playerB, "Bloodflow Connoisseur", 1);
|
||||
assertExileCount("Bloodflow Connoisseur", 0);
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue