1
0
Fork 0
mirror of https://github.com/correl/mage.git synced 2025-04-10 01:01:05 -09:00

* Meld - Fixed a bug that produced an exception if while the meld ability was on the stack, one of the permanents to meld left the battlefield meanwhile.

This commit is contained in:
LevelX2 2016-08-12 12:12:10 +02:00
parent 6f89a67f68
commit aa58c76ba9
2 changed files with 63 additions and 16 deletions
Mage.Tests/src/test/java/org/mage/test/cards/abilities/keywords
Mage/src/main/java/mage/abilities/effects/common

View file

@ -163,4 +163,47 @@ public class MeldTest extends CardTestPlayerBase {
assertHandCount(playerB, 0); assertHandCount(playerB, 0);
} }
/**
* With Hanweir Garrison and Hanweir Battlements in your control put Hanweir
* Battlements' ability in the stack to transform(i.e. meld). In answer to
* that, return to hand Hanweir Garrison. Resolve Hanweir Battlements
* ability.
*
* Expected result: The ability fizzles.
*
* Actual results: A NPE error is lauched.
*/
@Test
public void testReturnToHand() {
addCard(Zone.BATTLEFIELD, playerA, "Mountain", 5);
// Whenever Hanweir Garrison attacks, put two 1/1 red Human creature tokens onto the battlefield tapped and attacking.
// <i>(Melds with Hanweir Battlements.)</i>
addCard(Zone.BATTLEFIELD, playerA, "Hanweir Garrison"); // Creature 2/3 {2}{R}
// {T}: Add {C} to your mana pool.
// {R},{T}: Target creature gains haste until end of turn.
// {3}{R}{R},{T}: If you both own and control Hanweir Battlements and a creature named Hanweir Garrison, exile them, then meld them into Hanweir, the Writhing Township.
addCard(Zone.BATTLEFIELD, playerA, "Hanweir Battlements"); // Land
// Brisela, Voice of Nightmares 9/10
// Flying, First strike, Vigilance, Lifelink
// Your opponents can't cast spells with converted mana cost 3 or less.
addCard(Zone.BATTLEFIELD, playerB, "Island", 1);
// Return target creature to its owner's hand.
addCard(Zone.HAND, playerB, "Unsummon", 1); // Instant {U}
activateAbility(1, PhaseStep.PRECOMBAT_MAIN, playerA, "{3}{R}{R}");
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerB, "Unsummon", "Hanweir Garrison", "{3}{R}{R}");
setStopAt(1, PhaseStep.BEGIN_COMBAT);
execute();
assertGraveyardCount(playerB, "Unsummon", 1);
assertPermanentCount(playerA, "Hanweir Battlements", 1);
assertHandCount(playerA, "Hanweir Garrison", 1);
}
} }

View file

@ -79,32 +79,36 @@ public class MeldEffect extends OneShotEffect {
filter.add(new NamePredicate(meldWithName)); filter.add(new NamePredicate(meldWithName));
TargetPermanent target = new TargetControlledCreaturePermanent(filter); TargetPermanent target = new TargetControlledCreaturePermanent(filter);
Set<UUID> meldWithList = target.possibleTargets(sourceId, source.getControllerId(), game); Set<UUID> meldWithList = target.possibleTargets(sourceId, source.getControllerId(), game);
if (meldWithList.isEmpty()) {
return false; // possible permanent has left the battlefield meanwhile
}
UUID meldWithId; UUID meldWithId;
if (meldWithList.size() == 1) { if (meldWithList.size() == 1) {
meldWithId = meldWithList.iterator().next(); meldWithId = meldWithList.iterator().next();
} } else {
else {
controller.choose(Outcome.BoostCreature, target, sourceId, game); controller.choose(Outcome.BoostCreature, target, sourceId, game);
meldWithId = target.getFirstTarget(); meldWithId = target.getFirstTarget();
} }
// Exile the two permanents to meld. // Exile the two permanents to meld.
Permanent sourcePermanent = game.getPermanent(sourceId); Permanent sourcePermanent = game.getPermanent(sourceId);
Permanent meldWithPermanent = game.getPermanent(meldWithId); Permanent meldWithPermanent = game.getPermanent(meldWithId);
sourcePermanent.moveToExile(null, "", sourceId, game); if (sourcePermanent != null && meldWithPermanent != null) {
meldWithPermanent.moveToExile(null, "", sourceId, game); sourcePermanent.moveToExile(null, "", sourceId, game);
// Create the meld card and move it to the battlefield. meldWithPermanent.moveToExile(null, "", sourceId, game);
Card sourceCard = game.getExile().getCard(sourceId, game); // Create the meld card and move it to the battlefield.
Card meldWithCard = game.getExile().getCard(meldWithId, game); Card sourceCard = game.getExile().getCard(sourceId, game);
if (!sourceCard.isCopy() && !meldWithCard.isCopy()) { Card meldWithCard = game.getExile().getCard(meldWithId, game);
meldCard.setOwnerId(controller.getId()); if (!sourceCard.isCopy() && !meldWithCard.isCopy()) {
meldCard.setTopHalfCard(meldWithCard, game); meldCard.setOwnerId(controller.getId());
meldCard.setbottomHalfCard(sourceCard, game); meldCard.setTopHalfCard(meldWithCard, game);
meldCard.setMelded(true); meldCard.setbottomHalfCard(sourceCard, game);
game.addMeldCard(meldCard.getId(), meldCard); meldCard.setMelded(true);
game.getState().addCard(meldCard); game.addMeldCard(meldCard.getId(), meldCard);
meldCard.moveToZone(Zone.BATTLEFIELD, sourceId, game, false); game.getState().addCard(meldCard);
meldCard.moveToZone(Zone.BATTLEFIELD, sourceId, game, false);
}
return true;
} }
return true;
} }
return false; return false;
} }