From 299e66419145829add0ad1a6a1c6fdeb7aaaec2d Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Fri, 3 Jul 2020 13:17:04 +0200 Subject: [PATCH] * Kestia, the Cultivator - Fixed bestow from the Command Zone doesn't attach her to the creature you target (fixes #6763). --- .../commander/duel/CastCommanderTest.java | 38 +++++++++++++++++++ .../common/CastCommanderAbility.java | 2 +- .../mage/abilities/keyword/BestowAbility.java | 2 + .../mage/constants/SpellAbilityCastMode.java | 3 +- Mage/src/main/java/mage/game/GameImpl.java | 2 - Mage/src/main/java/mage/game/stack/Spell.java | 10 ++--- 6 files changed, 48 insertions(+), 9 deletions(-) diff --git a/Mage.Tests/src/test/java/org/mage/test/commander/duel/CastCommanderTest.java b/Mage.Tests/src/test/java/org/mage/test/commander/duel/CastCommanderTest.java index 0b49817680..e61a86eaa6 100644 --- a/Mage.Tests/src/test/java/org/mage/test/commander/duel/CastCommanderTest.java +++ b/Mage.Tests/src/test/java/org/mage/test/commander/duel/CastCommanderTest.java @@ -3,6 +3,8 @@ package org.mage.test.commander.duel; 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.CardTestCommanderDuelBase; @@ -11,6 +13,7 @@ import org.mage.test.serverside.base.CardTestCommanderDuelBase; * @author LevelX2 */ public class CastCommanderTest extends CardTestCommanderDuelBase { + @Test public void testCastCommander() { addCard(Zone.BATTLEFIELD, playerA, "Swamp", 5); @@ -25,4 +28,39 @@ public class CastCommanderTest extends CardTestCommanderDuelBase { assertPermanentCount(playerA, "Ob Nixilis of the Black Oath", 1); } + + @Test + public void testCastKestiaCommander() { + // Bestow {3}{G}{W}{U} + // Enchanted creature gets +4/+4. + // Whenever an enchanted creature or enchantment creature you control attacks, draw a card. + addCard(Zone.COMMAND, playerA, "Kestia, the Cultivator", 1); // Creature {1}{G}{W}{U} 4/4 + + addCard(Zone.BATTLEFIELD, playerA, "Forest", 5); + addCard(Zone.BATTLEFIELD, playerA, "Plains", 5); + addCard(Zone.BATTLEFIELD, playerA, "Island", 5); + + addCard(Zone.BATTLEFIELD, playerA, "Silvercoat Lion", 1); + + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Kestia, the Cultivator using bestow", "Silvercoat Lion"); + + setStrictChooseMode(true); + + setStopAt(1, PhaseStep.BEGIN_COMBAT); + execute(); + + assertAllCommandsUsed(); + assertLife(playerA, 40); + assertLife(playerB, 40); + + + assertPermanentCount(playerA, "Kestia, the Cultivator", 1); + + Permanent kestia = getPermanent("Kestia, the Cultivator", playerA); + Assert.assertNotEquals("Kestia may not be an creature", true, kestia.isCreature()); + Assert.assertEquals("Kestia has to be an enchantment", true, kestia.isEnchantment()); + + assertPowerToughness(playerA, "Silvercoat Lion", 6, 6); + } + } diff --git a/Mage/src/main/java/mage/abilities/common/CastCommanderAbility.java b/Mage/src/main/java/mage/abilities/common/CastCommanderAbility.java index 68ceca8ea6..f2777d8b8b 100644 --- a/Mage/src/main/java/mage/abilities/common/CastCommanderAbility.java +++ b/Mage/src/main/java/mage/abilities/common/CastCommanderAbility.java @@ -9,7 +9,7 @@ import mage.constants.Zone; */ public class CastCommanderAbility extends SpellAbility { - private String ruleText; + private final String ruleText; public CastCommanderAbility(Card card, SpellAbility spellTemplate) { super(spellTemplate); diff --git a/Mage/src/main/java/mage/abilities/keyword/BestowAbility.java b/Mage/src/main/java/mage/abilities/keyword/BestowAbility.java index 757c5bbe2c..3682e85029 100644 --- a/Mage/src/main/java/mage/abilities/keyword/BestowAbility.java +++ b/Mage/src/main/java/mage/abilities/keyword/BestowAbility.java @@ -12,6 +12,7 @@ import mage.cards.Card; import mage.constants.CardType; import mage.constants.Duration; import mage.constants.Outcome; +import mage.constants.SpellAbilityCastMode; import mage.constants.SpellAbilityType; import mage.constants.SubType; import mage.constants.TimingRule; @@ -92,6 +93,7 @@ public class BestowAbility extends SpellAbility { public BestowAbility(Card card, String manaString) { super(new ManaCostsImpl(manaString), card.getName() + " using bestow"); this.spellAbilityType = SpellAbilityType.BASE_ALTERNATE; + this.spellAbilityCastMode = SpellAbilityCastMode.BESTOW; this.timing = TimingRule.SORCERY; TargetPermanent auraTarget = new TargetCreaturePermanent(); this.addTarget(auraTarget); diff --git a/Mage/src/main/java/mage/constants/SpellAbilityCastMode.java b/Mage/src/main/java/mage/constants/SpellAbilityCastMode.java index cc3484d9a1..19bf79cc6b 100644 --- a/Mage/src/main/java/mage/constants/SpellAbilityCastMode.java +++ b/Mage/src/main/java/mage/constants/SpellAbilityCastMode.java @@ -8,7 +8,8 @@ package mage.constants; public enum SpellAbilityCastMode { NORMAL("Normal"), MADNESS("Madness"), - FLASHBACK("Flashback"); + FLASHBACK("Flashback"), + BESTOW("Bestow"); private final String text; diff --git a/Mage/src/main/java/mage/game/GameImpl.java b/Mage/src/main/java/mage/game/GameImpl.java index b1ba34e30a..990499c74f 100644 --- a/Mage/src/main/java/mage/game/GameImpl.java +++ b/Mage/src/main/java/mage/game/GameImpl.java @@ -2059,8 +2059,6 @@ public abstract class GameImpl implements Game, Serializable { if (card != null && card.isCreature()) { UUID wasAttachedTo = perm.getAttachedTo(); perm.attachTo(null, this); - //moved to mage.game.permanent.PermanentImpl::detachAllAttachments - //BestowAbility.becomeCreature(perm, this); fireEvent(new GameEvent(GameEvent.EventType.UNATTACHED, wasAttachedTo, perm.getId(), perm.getControllerId())); } else if (movePermanentToGraveyardWithInfo(perm)) { somethingHappened = true; diff --git a/Mage/src/main/java/mage/game/stack/Spell.java b/Mage/src/main/java/mage/game/stack/Spell.java index c87120b51c..05fbffbfa3 100644 --- a/Mage/src/main/java/mage/game/stack/Spell.java +++ b/Mage/src/main/java/mage/game/stack/Spell.java @@ -244,7 +244,7 @@ public class Spell extends StackObjImpl implements Card { } else if (this.isEnchantment() && this.hasSubtype(SubType.AURA, game)) { if (ability.getTargets().stillLegal(ability, game)) { updateOptionalCosts(0); - boolean bestow = ability instanceof BestowAbility; + boolean bestow = SpellAbilityCastMode.BESTOW.equals(ability.getSpellAbilityCastMode()); if (bestow) { // Must be removed first time, after that will be removed by continous effect // Otherwise effects like evolve trigger from creature comes into play event @@ -274,7 +274,7 @@ public class Spell extends StackObjImpl implements Card { return false; } // Aura has no legal target and its a bestow enchantment -> Add it to battlefield as creature - if (this.getSpellAbility() instanceof BestowAbility) { + if (SpellAbilityCastMode.BESTOW.equals(this.getSpellAbility().getSpellAbilityCastMode())) { updateOptionalCosts(0); if (controller.moveCards(card, Zone.BATTLEFIELD, ability, game, false, faceDown, false, null)) { Permanent permanent = game.getPermanent(card.getId()); @@ -500,7 +500,7 @@ public class Spell extends StackObjImpl implements Card { cardTypes.add(CardType.CREATURE); return cardTypes; } - if (this.getSpellAbility() instanceof BestowAbility) { + if (SpellAbilityCastMode.BESTOW.equals(this.getSpellAbility().getSpellAbilityCastMode())) { ArrayList cardTypes = new ArrayList<>(); cardTypes.addAll(card.getCardType()); cardTypes.remove(CardType.CREATURE); @@ -511,7 +511,7 @@ public class Spell extends StackObjImpl implements Card { @Override public SubTypeList getSubtype(Game game) { - if (this.getSpellAbility() instanceof BestowAbility) { + if (SpellAbilityCastMode.BESTOW.equals(this.getSpellAbility().getSpellAbilityCastMode())) { SubTypeList subtypes = card.getSubtype(game); if (!subtypes.contains(SubType.AURA)) { // do it only once subtypes.add(SubType.AURA); @@ -523,7 +523,7 @@ public class Spell extends StackObjImpl implements Card { @Override public boolean hasSubtype(SubType subtype, Game game) { - if (this.getSpellAbility() instanceof BestowAbility) { // workaround for Bestow (don't like it) + if (SpellAbilityCastMode.BESTOW.equals(this.getSpellAbility().getSpellAbilityCastMode())) { // workaround for Bestow (don't like it) SubTypeList subtypes = card.getSubtype(game); if (!subtypes.contains(SubType.AURA)) { // do it only once subtypes.add(SubType.AURA);