* Gain cost modification abilities - fixed that commanders can't be played without full mana (example: gained Affinity by Mycosynth Golem, gained Convoke by Chief Engineer, see #7249 #7171, #6698);

This commit is contained in:
Oleg Agafonov 2020-12-18 18:33:44 +04:00
parent 53c5abea14
commit 384ff2e7ac
8 changed files with 145 additions and 28 deletions

View file

@ -99,14 +99,11 @@ class TeferiMageOfZhalfirAddFlashEffect extends ContinuousEffectImpl {
}
}
// commander in command zone
for (UUID commanderId : game.getCommandersIds(controller)) {
if (game.getState().getZone(commanderId) == Zone.COMMAND) {
Card card = game.getCard(commanderId);
if (card != null && card.isCreature()) {
game.getCommanderCardsFromCommandZone(controller).stream()
.filter(MageObject::isCreature)
.forEach(card -> {
game.getState().addOtherAbility(card, FlashAbility.getInstance());
}
}
}
});
return true;
}
return false;

View file

@ -238,8 +238,6 @@ public class ConvokeTest extends CardTestPlayerBaseWithAIHelps {
}
@Test
@Ignore
// TODO: fix gain ability for spells to apply in all zones instead stack only or change getPlayable to look ahead and simulate spell on stack (wtf)
public void test_Other_ConvokeAsGains() {
// {1}{U}
// Artifact spells you cast have convoke.

View file

@ -1,4 +1,3 @@
package org.mage.test.cards.abilities.other;
import mage.constants.PhaseStep;
@ -6,23 +5,23 @@ import mage.constants.Zone;
import mage.game.permanent.Permanent;
import org.junit.Assert;
import org.junit.Test;
import org.mage.test.serverside.base.CardTestPlayerBase;
import org.mage.test.serverside.base.CardTestCommander4Players;
/**
*
* @author BetaSteward
*/
public class MycosynthGolemTest extends CardTestPlayerBase {
public class MycosynthGolemTest extends CardTestCommander4Players {
/**
* Mycosynth Golem Artifact Creature Golem 4/5, 11 (11) Affinity for
* artifacts (This spell costs {1} less to cast for each artifact you
* control.) Artifact creature spells you cast have affinity for artifacts.
* (They cost {1} less to cast for each artifact you control.)
*
*/
@Test
public void testSpellsAffinity() {
public void test_AffinityForNormalSpells() {
/*
bug:
Mycosynth Golem Artifact Creature Golem 4/5, 11 (11) Affinity for
artifacts (This spell costs {1} less to cast for each artifact you
control.) Artifact creature spells you cast have affinity for artifacts.
(They cost {1} less to cast for each artifact you control.)
*/
addCard(Zone.BATTLEFIELD, playerA, "Mountain", 1);
addCard(Zone.BATTLEFIELD, playerA, "Forest", 1);
// Affinity for artifacts
@ -32,8 +31,10 @@ public class MycosynthGolemTest extends CardTestPlayerBase {
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Alpha Myr");
setStrictChooseMode(true);
setStopAt(1, PhaseStep.BEGIN_COMBAT);
execute();
assertAllCommandsUsed();
assertPermanentCount(playerA, "Alpha Myr", 1);
assertHandCount(playerA, "Alpha Myr", 0);
@ -48,7 +49,5 @@ public class MycosynthGolemTest extends CardTestPlayerBase {
tappedLands++;
}
Assert.assertEquals("only one land may be tapped because the cost reduction", 1, tappedLands);
}
}

View file

@ -1,7 +1,12 @@
package org.mage.test.commander.duel;
import mage.abilities.Ability;
import mage.abilities.common.SimpleActivatedAbility;
import mage.abilities.costs.mana.ManaCostsImpl;
import mage.abilities.effects.common.CreateTokenEffect;
import mage.constants.PhaseStep;
import mage.constants.Zone;
import mage.game.permanent.token.ArtifactWallToken;
import org.junit.Test;
import org.mage.test.serverside.base.CardTestCommanderDuelBase;
@ -82,4 +87,81 @@ public class CommanderAffinityTest extends CardTestCommanderDuelBase {
assertAllCommandsUsed();
}
@Test
public void test_Gained_Affinity() {
// bug: Mycosynth Golem did not allow my commander, Karn, Silver Golem, to cost 0 even though I had 7+ artifacts on the board.
Ability ability = new SimpleActivatedAbility(Zone.ALL, new CreateTokenEffect(new ArtifactWallToken(), 7), new ManaCostsImpl("R"));
addCustomCardWithAbility("generate tokens", playerA, ability);
addCard(Zone.BATTLEFIELD, playerA, "Mountain", 1);
//
addCard(Zone.COMMAND, playerA, "Karn, Silver Golem", 1); // {5}
addCard(Zone.BATTLEFIELD, playerA, "Mountain", 5);
//
// Destroy target artifact.
addCard(Zone.HAND, playerA, "Ancient Grudge", 1); // {1}{R}
addCard(Zone.BATTLEFIELD, playerA, "Mountain", 2);
//
// Artifact creature spells you cast have affinity for artifacts. (They cost {1} less to cast for each artifact you control.)
addCard(Zone.BATTLEFIELD, playerA, "Mycosynth Golem", 1);
// Affinity for artifacts
// Artifact creature spells you cast have affinity for artifacts.
// addCard(Zone.BATTLEFIELD, playerA, "Mycosynth Golem");
// addCard(Zone.HAND, playerA, "Alpha Myr"); // Creature - Myr 2/1
checkCommandCardCount("before", 1, PhaseStep.PRECOMBAT_MAIN, playerA, "Karn, Silver Golem", 1);
checkPlayableAbility("before", 1, PhaseStep.PRECOMBAT_MAIN, playerA, "Cast Karn, Silver Golem", true);
// first cast for 5 and destroy (prepare commander with additional cost)
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Karn, Silver Golem");
waitStackResolved(1, PhaseStep.PRECOMBAT_MAIN);
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Ancient Grudge", "Karn, Silver Golem");
waitStackResolved(1, PhaseStep.PRECOMBAT_MAIN);
checkCommandCardCount("after destroy ", 1, PhaseStep.PRECOMBAT_MAIN, playerA, "Karn, Silver Golem", 1);
checkPlayableAbility("after destroy", 1, PhaseStep.PRECOMBAT_MAIN, playerA, "Cast Karn, Silver Golem", false);
setChoice(playerA, "Yes"); // move to command zone
waitStackResolved(1, PhaseStep.PRECOMBAT_MAIN);
// can't do the second cast with additional cost (must pay 2 + 5, but have only R)
checkPlayableAbility("after move", 1, PhaseStep.PRECOMBAT_MAIN, playerA, "Cast Karn, Silver Golem", false);
// generate artifact tokens
activateAbility(1, PhaseStep.PRECOMBAT_MAIN, playerA, "{R}: Create");
waitStackResolved(1, PhaseStep.PRECOMBAT_MAIN);
checkPermanentCount("after tokens", 1, PhaseStep.PRECOMBAT_MAIN, playerA, "Wall", 7);
checkPlayableAbility("after tokens", 1, PhaseStep.PRECOMBAT_MAIN, playerA, "Cast Karn, Silver Golem", true);
setStrictChooseMode(true);
setStopAt(1, PhaseStep.END_TURN);
execute();
assertAllCommandsUsed();
}
@Test
public void test_Gained_Convoke() {
// bug:
// https://github.com/magefree/mage/issues/7171
// Commander doesn't get 'convoke' when chief engineer is on the battlefield, so for instance I can't cast Breya by tapping other creatures.
// Artifact spells you cast have convoke.
addCard(Zone.BATTLEFIELD, playerA, "Chief Engineer", 1);
//
addCard(Zone.COMMAND, playerA, "Karn, Silver Golem", 1); // {5}
addCard(Zone.BATTLEFIELD, playerA, "Mountain", 5 - 2);
addCard(Zone.BATTLEFIELD, playerA, "Grizzly Bears", 2);
// 3 mana + 2 convoke
checkPlayableAbility("before", 1, PhaseStep.PRECOMBAT_MAIN, playerA, "Cast Karn, Silver Golem", true);
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Karn, Silver Golem");
addTarget(playerA, "Grizzly Bears"); // convoke cost
addTarget(playerA, "Grizzly Bears"); // convoke cost
setStrictChooseMode(true);
setStopAt(1, PhaseStep.END_TURN);
execute();
assertAllCommandsUsed();
assertPermanentCount(playerA, "Karn, Silver Golem", 1);
}
}

View file

@ -60,6 +60,14 @@ public class GainAbilitySpellsEffect extends ContinuousEffectImpl {
game.getState().addOtherAbility(card, ability);
}
}
// workaround to gain cost reduction abilities to commanders before cast (make it playable)
game.getCommanderCardsFromCommandZone(player).stream()
.filter(card -> filter.match(card, game))
.forEach(card -> {
game.getState().addOtherAbility(card, ability);
});
for (StackObject stackObject : game.getStack()) {
if (stackObject.isControlledBy(source.getControllerId())) {
Card card = game.getCard(stackObject.getSourceId());

View file

@ -44,8 +44,7 @@ public class GainAbilityControlledSpellsEffect extends ContinuousEffectImpl {
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
Permanent permanent = game.getPermanent(source.getSourceId());
if (player != null
&& permanent != null) {
if (player != null && permanent != null) {
for (Card card : game.getExile().getAllCards(game)) {
if (card.isOwnedBy(source.getControllerId())
&& filter.match(card, game)) {
@ -67,6 +66,14 @@ public class GainAbilityControlledSpellsEffect extends ContinuousEffectImpl {
game.getState().addOtherAbility(card, ability);
}
}
// workaround to gain cost reduction abilities to commanders before cast (make it playable)
game.getCommanderCardsFromCommandZone(player).stream()
.filter(card -> filter.match(card, game))
.forEach(card -> {
game.getState().addOtherAbility(card, ability);
});
for (StackObject stackObject : game.getStack()) {
// only spells cast, so no copies of spells
if ((stackObject instanceof Spell)

View file

@ -1,8 +1,5 @@
package mage.game;
import java.io.Serializable;
import java.util.*;
import java.util.stream.Collectors;
import mage.MageItem;
import mage.MageObject;
import mage.abilities.Ability;
@ -45,6 +42,10 @@ import mage.players.Players;
import mage.util.MessageToClient;
import mage.util.functions.ApplyToPermanent;
import java.io.Serializable;
import java.util.*;
import java.util.stream.Collectors;
public interface Game extends MageItem, Serializable {
MatchType getGameType();
@ -503,6 +504,21 @@ public interface Game extends MageItem, Serializable {
return getCommandersIds(player, CommanderCardType.ANY);
}
/**
* Return not played commander cards from command zone
*
* @param player
* @return
*/
default Set<Card> getCommanderCardsFromCommandZone(Player player) {
// commanders in command zone aren't cards so you must call getCard instead getObject
return getCommandersIds(player).stream()
.map(this::getCard)
.filter(Objects::nonNull)
.filter(card -> Zone.COMMAND.equals(this.getState().getZone(card.getId())))
.collect(Collectors.toSet());
}
void setGameStopped(boolean gameStopped);
boolean isGameStopped();

View file

@ -23,6 +23,7 @@ import mage.filter.Filter;
import mage.filter.predicate.mageobject.NamePredicate;
import mage.game.CardState;
import mage.game.Game;
import mage.game.command.Commander;
import mage.game.events.GameEvent;
import mage.game.permanent.Permanent;
import mage.game.permanent.PermanentCard;
@ -815,6 +816,15 @@ public final class CardUtil {
public static Abilities<Ability> getAbilities(MageObject object, Game game) {
if (object instanceof Card) {
return ((Card) object).getAbilities(game);
} else if (object instanceof Commander && Zone.COMMAND.equals(game.getState().getZone(object.getId()))) {
// Commanders in command zone must gain cost related abilities for playable
// calculation (affinity, convoke; example: Chief Engineer). So you must use card object here
Card card = game.getCard(object.getId());
if (card != null) {
return card.getAbilities(game);
} else {
return object.getAbilities();
}
} else {
return object.getAbilities();
}