From 1e7f82bb3c05c0b2a889f28fccb406ea3189ff46 Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Sat, 25 Apr 2015 19:13:02 +0200 Subject: [PATCH] * Fixed a bug that attach effects were not stopped during resolution if the object to attach doe sno longer exist. --- .../abilities/equipped/HeavyArbalestTest.java | 2 +- .../abilities/equipped/LeoninShikariTest.java | 61 +++++++++++++++++++ .../effects/common/AttachEffect.java | 20 +++--- 3 files changed, 74 insertions(+), 9 deletions(-) create mode 100644 Mage.Tests/src/test/java/org/mage/test/cards/abilities/equipped/LeoninShikariTest.java diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/abilities/equipped/HeavyArbalestTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/abilities/equipped/HeavyArbalestTest.java index fc742561e9..d86589240d 100644 --- a/Mage.Tests/src/test/java/org/mage/test/cards/abilities/equipped/HeavyArbalestTest.java +++ b/Mage.Tests/src/test/java/org/mage/test/cards/abilities/equipped/HeavyArbalestTest.java @@ -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()); } diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/abilities/equipped/LeoninShikariTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/abilities/equipped/LeoninShikariTest.java new file mode 100644 index 0000000000..74809428fd --- /dev/null +++ b/Mage.Tests/src/test/java/org/mage/test/cards/abilities/equipped/LeoninShikariTest.java @@ -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); + } + +} diff --git a/Mage/src/mage/abilities/effects/common/AttachEffect.java b/Mage/src/mage/abilities/effects/common/AttachEffect.java index 3241b3d35a..a94d9edead 100644 --- a/Mage/src/mage/abilities/effects/common/AttachEffect.java +++ b/Mage/src/mage/abilities/effects/common/AttachEffect.java @@ -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;