mirror of
https://github.com/magefree/mage.git
synced 2025-12-21 02:52:02 -08:00
* Fixed that cast conditions of legendary sorceries were checked correctly if you cast a card owned by another player e.g. from exile (fixes #4921).
This commit is contained in:
parent
a227bd9e1c
commit
74f05d438f
3 changed files with 203 additions and 51 deletions
|
|
@ -0,0 +1,146 @@
|
|||
/*
|
||||
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
package org.mage.test.cards.conditional;
|
||||
|
||||
import mage.constants.PhaseStep;
|
||||
import mage.constants.Zone;
|
||||
import org.junit.Test;
|
||||
import org.mage.test.serverside.base.CardTestPlayerBase;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author LevelX2
|
||||
*/
|
||||
public class LegendarySorceryTest extends CardTestPlayerBase {
|
||||
|
||||
@Test
|
||||
public void testCastSuccessful() {
|
||||
// (You may cast a legendary sorcery only if you control a legendary creature or planeswalker.)
|
||||
// Exile all nonland permanents that aren’t legendary.
|
||||
addCard(Zone.HAND, playerA, "Urza's Ruinous Blast"); // Sorcery Legendary {4}{W}
|
||||
addCard(Zone.BATTLEFIELD, playerA, "Plains", 5);
|
||||
addCard(Zone.BATTLEFIELD, playerA, "Silvercoat Lion", 1); // non Legendary
|
||||
// Flying, first strike, vigilance, trample, haste, protection from black and from red
|
||||
addCard(Zone.BATTLEFIELD, playerA, "Akroma, Angel of Wrath", 1); // Legendary
|
||||
|
||||
addCard(Zone.BATTLEFIELD, playerB, "Silvercoat Lion", 1); // non Legendary
|
||||
// Flying, first strike, vigilance, trample, haste, protection from black and from red
|
||||
addCard(Zone.BATTLEFIELD, playerB, "Akroma, Angel of Wrath", 1); // Legendary
|
||||
|
||||
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Urza's Ruinous Blast");
|
||||
|
||||
setStopAt(1, PhaseStep.BEGIN_COMBAT);
|
||||
execute();
|
||||
|
||||
assertGraveyardCount(playerA, "Urza's Ruinous Blast", 1);
|
||||
|
||||
assertPermanentCount(playerA, "Plains", 5);
|
||||
|
||||
assertPermanentCount(playerA, "Silvercoat Lion", 0);
|
||||
assertPermanentCount(playerB, "Silvercoat Lion", 0);
|
||||
|
||||
assertPermanentCount(playerA, "Akroma, Angel of Wrath", 1);
|
||||
assertPermanentCount(playerB, "Akroma, Angel of Wrath", 1);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCastNotSuccessful() {
|
||||
// (You may cast a legendary sorcery only if you control a legendary creature or planeswalker.)
|
||||
// Exile all nonland permanents that aren’t legendary.
|
||||
addCard(Zone.HAND, playerA, "Urza's Ruinous Blast"); // Sorcery Legendary {4}{W}
|
||||
addCard(Zone.BATTLEFIELD, playerA, "Plains", 5);
|
||||
addCard(Zone.BATTLEFIELD, playerA, "Silvercoat Lion", 1); // non Legendary
|
||||
|
||||
addCard(Zone.BATTLEFIELD, playerB, "Silvercoat Lion", 1); // non Legendary
|
||||
// Flying, first strike, vigilance, trample, haste, protection from black and from red
|
||||
addCard(Zone.BATTLEFIELD, playerB, "Akroma, Angel of Wrath", 1); // Legendary
|
||||
|
||||
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Urza's Ruinous Blast");
|
||||
|
||||
setStopAt(1, PhaseStep.BEGIN_COMBAT);
|
||||
execute();
|
||||
|
||||
assertGraveyardCount(playerA, "Urza's Ruinous Blast", 0);
|
||||
|
||||
assertPermanentCount(playerA, "Plains", 5);
|
||||
|
||||
assertPermanentCount(playerA, "Silvercoat Lion", 1);
|
||||
assertPermanentCount(playerB, "Silvercoat Lion", 1);
|
||||
|
||||
assertPermanentCount(playerA, "Akroma, Angel of Wrath", 0);
|
||||
assertPermanentCount(playerB, "Akroma, Angel of Wrath", 1);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCastSuccessfulFromExile() {
|
||||
// First strike
|
||||
// When this enters the battlefield, exile target instant or sorcery card from an opponent's graveyard.
|
||||
// You may cast that card this turn and you may spend mana as though it were mana of any color.
|
||||
// If that card would be put into a graveyard this turn, exile it instead.
|
||||
addCard(Zone.HAND, playerA, "Dire Fleet Daredevil"); // Creature {1}{R}
|
||||
addCard(Zone.BATTLEFIELD, playerA, "Mountain", 2);
|
||||
addCard(Zone.BATTLEFIELD, playerA, "Plains", 5);
|
||||
addCard(Zone.BATTLEFIELD, playerA, "Silvercoat Lion", 1); // non Legendary
|
||||
addCard(Zone.BATTLEFIELD, playerA, "Akroma, Angel of Wrath", 1); // Legendary
|
||||
|
||||
addCard(Zone.BATTLEFIELD, playerB, "Silvercoat Lion", 1); // non Legendary
|
||||
// Flying, first strike, vigilance, trample, haste, protection from black and from red
|
||||
addCard(Zone.BATTLEFIELD, playerB, "Akroma, Angel of Wrath", 1); // Legendary
|
||||
// (You may cast a legendary sorcery only if you control a legendary creature or planeswalker.)
|
||||
// Exile all nonland permanents that aren’t legendary.
|
||||
addCard(Zone.GRAVEYARD, playerB, "Urza's Ruinous Blast"); // Sorcery Legendary {4}{W}
|
||||
|
||||
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Dire Fleet Daredevil");
|
||||
addTarget(playerA, "Urza's Ruinous Blast");
|
||||
|
||||
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Urza's Ruinous Blast");
|
||||
|
||||
setStopAt(1, PhaseStep.BEGIN_COMBAT);
|
||||
execute();
|
||||
|
||||
assertExileCount(playerB, "Urza's Ruinous Blast", 1);
|
||||
|
||||
assertHandCount(playerA, "Dire Fleet Daredevil", 0);
|
||||
assertPermanentCount(playerA, "Dire Fleet Daredevil", 0);
|
||||
|
||||
assertExileCount(playerA, "Dire Fleet Daredevil", 1);
|
||||
assertExileCount(playerA, "Silvercoat Lion", 1);
|
||||
assertExileCount(playerB, "Silvercoat Lion", 1);
|
||||
|
||||
assertPermanentCount(playerA, "Plains", 5);
|
||||
|
||||
assertPermanentCount(playerA, "Silvercoat Lion", 0);
|
||||
assertPermanentCount(playerB, "Silvercoat Lion", 0);
|
||||
|
||||
assertPermanentCount(playerA, "Akroma, Angel of Wrath", 1);
|
||||
assertPermanentCount(playerB, "Akroma, Angel of Wrath", 1);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -1,18 +1,27 @@
|
|||
package mage.abilities.common;
|
||||
|
||||
import mage.abilities.condition.common.LegendaryCondition;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.effects.ContinuousRuleModifyingEffectImpl;
|
||||
import mage.constants.CardType;
|
||||
import mage.constants.Duration;
|
||||
import mage.constants.Outcome;
|
||||
import mage.constants.SuperType;
|
||||
import mage.constants.Zone;
|
||||
import mage.filter.FilterPermanent;
|
||||
import mage.filter.predicate.Predicates;
|
||||
import mage.filter.predicate.mageobject.CardTypePredicate;
|
||||
import mage.filter.predicate.mageobject.SupertypePredicate;
|
||||
import mage.game.Game;
|
||||
import mage.game.events.GameEvent;
|
||||
|
||||
/**
|
||||
* @author JRHerlehy
|
||||
* Created on 4/8/18.
|
||||
* @author JRHerlehy Created on 4/8/18.
|
||||
*/
|
||||
public class LegendarySpellAbility extends SimpleStaticAbility {
|
||||
|
||||
public LegendarySpellAbility() {
|
||||
super(Zone.ALL, new CastOnlyIfConditionIsTrueEffect(LegendaryCondition.instance));
|
||||
super(Zone.ALL, new LegendarySpellAbilityCheckEffect());
|
||||
this.setRuleAtTheTop(true);
|
||||
this.getEffects().get(0).setText("<i>(You may cast a legendary sorcery only if you control a legendary creature or planeswalker.)</i>");
|
||||
}
|
||||
|
||||
private LegendarySpellAbility(final LegendarySpellAbility ability) {
|
||||
|
|
@ -24,3 +33,46 @@ public class LegendarySpellAbility extends SimpleStaticAbility {
|
|||
return new LegendarySpellAbility(this);
|
||||
}
|
||||
}
|
||||
|
||||
class LegendarySpellAbilityCheckEffect extends ContinuousRuleModifyingEffectImpl {
|
||||
|
||||
private static final FilterPermanent filter = new FilterPermanent("legendary creature or planeswalker");
|
||||
|
||||
static {
|
||||
filter.add(
|
||||
Predicates.and(
|
||||
new SupertypePredicate(SuperType.LEGENDARY),
|
||||
Predicates.or(
|
||||
new CardTypePredicate(CardType.CREATURE),
|
||||
new CardTypePredicate(CardType.PLANESWALKER)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public LegendarySpellAbilityCheckEffect() {
|
||||
super(Duration.EndOfGame, Outcome.Detriment);
|
||||
staticText = "<i>(You may cast a legendary sorcery only if you control a legendary creature or planeswalker.)</i>";
|
||||
}
|
||||
|
||||
private LegendarySpellAbilityCheckEffect(final LegendarySpellAbilityCheckEffect effect) {
|
||||
super(effect);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checksEventType(GameEvent event, Game game) {
|
||||
return event.getType() == GameEvent.EventType.CAST_SPELL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean applies(GameEvent event, Ability source, Game game) {
|
||||
return event.getSourceId().equals(source.getSourceId())
|
||||
&& !game.getBattlefield().contains(filter, event.getPlayerId(), 1, game);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LegendarySpellAbilityCheckEffect copy() {
|
||||
return new LegendarySpellAbilityCheckEffect(this);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,46 +0,0 @@
|
|||
package mage.abilities.condition.common;
|
||||
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.condition.Condition;
|
||||
import mage.constants.CardType;
|
||||
import mage.constants.SuperType;
|
||||
import mage.filter.FilterPermanent;
|
||||
import mage.filter.predicate.Predicates;
|
||||
import mage.filter.predicate.mageobject.CardTypePredicate;
|
||||
import mage.filter.predicate.mageobject.SupertypePredicate;
|
||||
import mage.game.Game;
|
||||
|
||||
/**
|
||||
* @author JRHerlehy
|
||||
* Created on 4/7/18.
|
||||
*/
|
||||
public enum LegendaryCondition implements Condition {
|
||||
|
||||
instance;
|
||||
|
||||
private static final FilterPermanent filter = new FilterPermanent("legendary creature or planeswalker");
|
||||
|
||||
static {
|
||||
filter.add(
|
||||
Predicates.and(
|
||||
new SupertypePredicate(SuperType.LEGENDARY),
|
||||
Predicates.or(
|
||||
new CardTypePredicate(CardType.CREATURE),
|
||||
new CardTypePredicate(CardType.PLANESWALKER)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
return game.getBattlefield().contains(filter, source.getControllerId(), 1, game);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return super.toString();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue