* Fixed a bug that attach effects were not stopped during resolution if the object to attach doe sno longer exist.

This commit is contained in:
LevelX2 2015-04-25 19:13:02 +02:00
parent 167bf8be3c
commit 1e7f82bb3c
3 changed files with 74 additions and 9 deletions

View file

@ -58,7 +58,7 @@ public class HeavyArbalestTest extends CardTestPlayerBase {
assertLife(playerB, 18);
Permanent eliteVanguard = getPermanent("Elite Vanguard", playerA.getId());
Assert.assertTrue(eliteVanguard.getAttachments().size() == 0);
Assert.assertTrue(eliteVanguard.getAttachments().isEmpty());
Assert.assertFalse(eliteVanguard.isTapped());
}

View file

@ -0,0 +1,61 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.mage.test.cards.abilities.equipped;
import mage.constants.PhaseStep;
import mage.constants.Zone;
import mage.game.permanent.Permanent;
import org.junit.Assert;
import org.junit.Test;
import org.mage.test.serverside.base.CardTestPlayerBase;
/**
*
* @author LevelX2
*/
public class LeoninShikariTest extends CardTestPlayerBase {
/**
* Test you can equip during combat
*/
@Test
public void testEquipInstant() {
addCard(Zone.BATTLEFIELD, playerA, "Plains", 2);
// You may activate equip abilities any time you could cast an instant.
addCard(Zone.BATTLEFIELD, playerA, "Leonin Shikari");
addCard(Zone.BATTLEFIELD, playerA, "Silvercoat Lion");
// Equipped creature gets +1/+1.
addCard(Zone.BATTLEFIELD, playerA, "Leonin Scimitar");
addCard(Zone.BATTLEFIELD, playerB, "Island", 2);
addCard(Zone.HAND, playerB, "Boomerang");
activateAbility(1, PhaseStep.BEGIN_COMBAT, playerA, "Equip {1}", "Silvercoat Lion");
castSpell(1, PhaseStep.BEGIN_COMBAT, playerB, "Boomerang", "Leonin Scimitar", "Equip");
castSpell(1, PhaseStep.POSTCOMBAT_MAIN, playerA, "Leonin Scimitar");
setStopAt(1, PhaseStep.END_TURN);
execute();
assertLife(playerA, 20);
assertLife(playerB, 20);
assertGraveyardCount(playerB, "Boomerang", 1);
assertPermanentCount(playerA, "Leonin Scimitar", 1);
assertPowerToughness(playerA, "Silvercoat Lion", 2, 2);
Permanent silvercoatLion = getPermanent("Silvercoat Lion", playerA.getId());
Assert.assertTrue("Silvercoat Lion may not have any attachments", silvercoatLion.getAttachments().isEmpty());
Permanent leoninScimitar = getPermanent("Leonin Scimitar", playerA.getId());
Assert.assertTrue(leoninScimitar.getAttachedTo() == null);
}
}

View file

@ -28,6 +28,7 @@
package mage.abilities.effects.common;
import mage.MageObject;
import mage.constants.Outcome;
import mage.abilities.Ability;
import mage.abilities.effects.OneShotEffect;
@ -61,14 +62,17 @@ public class AttachEffect extends OneShotEffect {
@Override
public boolean apply(Game game, Ability source) {
Permanent permanent = game.getPermanent(getTargetPointer().getFirst(game, source));
if (permanent != null) {
return permanent.addAttachment(source.getSourceId(), game);
}
else {
Player player = game.getPlayer(getTargetPointer().getFirst(game, source));
if (player != null) {
return player.addAttachment(source.getSourceId(), game);
Permanent sourcePermanent = (Permanent)source.getSourceObjectIfItStillExists(game);
if (sourcePermanent != null) {
Permanent permanent = game.getPermanent(getTargetPointer().getFirst(game, source));
if (permanent != null) {
return permanent.addAttachment(source.getSourceId(), game);
}
else {
Player player = game.getPlayer(getTargetPointer().getFirst(game, source));
if (player != null) {
return player.addAttachment(source.getSourceId(), game);
}
}
}
return false;