Updated how spell triggers get information about the spell that triggered them.

This prevents countering the spell from removing the effect of the trigger.
This commit is contained in:
Evan Kranzler 2017-09-18 17:02:55 -04:00
parent e3245c496c
commit 7bb7754bb3
26 changed files with 69 additions and 61 deletions

View file

@ -85,7 +85,7 @@ public class BloodbondMarch extends CardImpl {
return false;
}
Spell spell = (Spell) game.getStack().getStackObject(targetPointer.getFirst(game, source));
Spell spell = game.getSpellOrLKIStack(this.getTargetPointer().getFirst(game, source));
if (spell == null) {
return false;

View file

@ -48,7 +48,7 @@ import mage.players.Player;
public class BounteousKirin extends CardImpl {
public BounteousKirin(UUID ownerId, CardSetInfo setInfo) {
super(ownerId,setInfo,new CardType[]{CardType.CREATURE},"{5}{G}{G}");
super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{5}{G}{G}");
addSuperType(SuperType.LEGENDARY);
this.subtype.add(SubType.KIRIN, SubType.SPIRIT);
@ -89,7 +89,7 @@ class BounteousKirinEffect extends OneShotEffect {
@Override
public boolean apply(Game game, Ability source) {
Spell spell = game.getState().getStack().getSpell(getTargetPointer().getFirst(game, source));
Spell spell = game.getSpellOrLKIStack(this.getTargetPointer().getFirst(game, source));
if (spell != null) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {

View file

@ -50,7 +50,7 @@ import mage.game.stack.Spell;
public class CelestialKirin extends CardImpl {
public CelestialKirin(UUID ownerId, CardSetInfo setInfo) {
super(ownerId,setInfo,new CardType[]{CardType.CREATURE},"{2}{W}{W}");
super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{2}{W}{W}");
addSuperType(SuperType.LEGENDARY);
this.subtype.add(SubType.KIRIN);
this.subtype.add(SubType.SPIRIT);
@ -92,7 +92,7 @@ class CelestialKirinEffect extends OneShotEffect {
@Override
public boolean apply(Game game, Ability source) {
Spell spell = game.getState().getStack().getSpell(getTargetPointer().getFirst(game, source));
Spell spell = game.getSpellOrLKIStack(this.getTargetPointer().getFirst(game, source));
if (spell != null) {
int cmc = spell.getConvertedManaCost();
FilterPermanent filter = new FilterPermanent();

View file

@ -91,7 +91,7 @@ public class ChandraTheFirebrand extends CardImpl {
class ChandraTheFirebrandAbility extends DelayedTriggeredAbility {
ChandraTheFirebrandAbility() {
super(new CopyTargetSpellEffect(), Duration.EndOfTurn);
super(new CopyTargetSpellEffect(true), Duration.EndOfTurn);
}
ChandraTheFirebrandAbility(final ChandraTheFirebrandAbility ability) {

View file

@ -54,7 +54,7 @@ import mage.target.TargetPlayer;
public class CloudhoofKirin extends CardImpl {
public CloudhoofKirin(UUID ownerId, CardSetInfo setInfo) {
super(ownerId,setInfo,new CardType[]{CardType.CREATURE},"{3}{U}{U}");
super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{3}{U}{U}");
addSuperType(SuperType.LEGENDARY);
this.subtype.add(SubType.KIRIN);
this.subtype.add(SubType.SPIRIT);
@ -98,10 +98,10 @@ class CloudhoofKirinEffect extends OneShotEffect {
@Override
public boolean apply(Game game, Ability source) {
Spell spell = game.getStack().getSpell(targetPointer.getFirst(game, source));
Spell spell = game.getSpellOrLKIStack(this.getTargetPointer().getFirst(game, source));
if (spell != null) {
Player targetPlayer = null;
for(Target target: source.getTargets()) {
for (Target target : source.getTargets()) {
if (target instanceof TargetPlayer) {
targetPlayer = game.getPlayer(target.getFirstTarget());
}

View file

@ -60,7 +60,7 @@ public class ClovenCasting extends CardImpl {
super(ownerId,setInfo,new CardType[]{CardType.ENCHANTMENT},"{5}{U}{R}");
// Whenever you cast a multicolored instant or sorcery spell, you may pay {1}. If you do, copy that spell. You may choose new targets for the copy.
Effect effect = new CopyTargetSpellEffect();
Effect effect = new CopyTargetSpellEffect(true);
effect.setText("copy that spell. You may choose new targets for the copy");
this.addAbility(new SpellCastControllerTriggeredAbility(new DoIfCostPaid(effect, new GenericManaCost(1)), filter, true, true));
}

View file

@ -58,7 +58,7 @@ import mage.target.targetpointer.FixedTarget;
public class CurseOfEchoes extends CardImpl {
public CurseOfEchoes(UUID ownerId, CardSetInfo setInfo) {
super(ownerId,setInfo,new CardType[]{CardType.ENCHANTMENT},"{4}{U}");
super(ownerId, setInfo, new CardType[]{CardType.ENCHANTMENT}, "{4}{U}");
this.subtype.add(SubType.AURA, SubType.CURSE);
// Enchant player
@ -143,7 +143,7 @@ class CurseOfEchoesEffect extends OneShotEffect {
@Override
public boolean apply(Game game, Ability source) {
Spell spell = game.getStack().getSpell(targetPointer.getFirst(game, source));
Spell spell = game.getSpellOrLKIStack(this.getTargetPointer().getFirst(game, source));
if (spell != null) {
String chooseMessage = "Copy target spell? You may choose new targets for the copy.";
for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {

View file

@ -36,7 +36,6 @@ import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.Outcome;
import mage.constants.SetTargetPointer;
import mage.constants.Zone;
import mage.filter.FilterSpell;
import mage.filter.predicate.Predicates;
import mage.filter.predicate.mageobject.CardTypePredicate;
@ -92,12 +91,9 @@ class DovescapeEffect extends OneShotEffect {
@Override
public boolean apply(Game game, Ability source) {
Spell spell = game.getStack().getSpell(this.getTargetPointer().getFirst(game, source));
Spell spell = game.getSpellOrLKIStack(this.getTargetPointer().getFirst(game, source));
int spellCMC = 0;
UUID spellControllerID = null;
if (spell == null) {
spell = (Spell) game.getLastKnownInformation(this.getTargetPointer().getFirst(game, source), Zone.STACK);
}
if (spell != null) {
spellCMC = spell.getConvertedManaCost();
spellControllerID = spell.getControllerId();

View file

@ -43,7 +43,6 @@ import mage.filter.common.FilterCreaturePermanent;
import mage.game.Game;
import mage.game.permanent.token.ThrullToken;
import mage.game.stack.Spell;
import mage.target.targetpointer.FixedTarget;
/**
* @author LevelX2
@ -95,10 +94,7 @@ class EndrekSahrMasterBreederEffect extends OneShotEffect {
@Override
public boolean apply(Game game, Ability source) {
Spell spell = game.getStack().getSpell(targetPointer.getFirst(game, source));
if (spell == null) {
spell = (Spell) game.getLastKnownInformation(((FixedTarget) getTargetPointer()).getTarget(), Zone.STACK);
}
Spell spell = game.getSpellOrLKIStack(this.getTargetPointer().getFirst(game, source));
if (spell != null) {
int cmc = spell.getConvertedManaCost();
if (cmc > 0) {

View file

@ -50,7 +50,7 @@ import mage.target.targetpointer.FixedTarget;
public class HiveMind extends CardImpl {
public HiveMind(UUID ownerId, CardSetInfo setInfo) {
super(ownerId,setInfo,new CardType[]{CardType.ENCHANTMENT},"{5}{U}");
super(ownerId, setInfo, new CardType[]{CardType.ENCHANTMENT}, "{5}{U}");
// Whenever a player casts an instant or sorcery spell, each other player copies that spell. Each of those players may choose new targets for his or her copy.
this.addAbility(new HiveMindTriggeredAbility());
@ -125,11 +125,7 @@ class HiveMindEffect extends OneShotEffect {
@Override
public boolean apply(Game game, Ability source) {
Spell spell;
spell = game.getStack().getSpell(((FixedTarget) getTargetPointer()).getTarget());
if (spell == null) { // if spell e.g. was countered
spell = (Spell) game.getLastKnownInformation(((FixedTarget) getTargetPointer()).getTarget(), Zone.STACK);
}
Spell spell = game.getSpellOrLKIStack(this.getTargetPointer().getFirst(game, source));
Player player = game.getPlayer(source.getControllerId());
if (spell != null && player != null) {
for (UUID playerId : game.getState().getPlayersInRange(player.getId(), game)) {

View file

@ -77,7 +77,7 @@ public class HowlOfTheHorde extends CardImpl {
class HowlOfTheHordeDelayedTriggeredAbility extends DelayedTriggeredAbility {
HowlOfTheHordeDelayedTriggeredAbility() {
super(new CopyTargetSpellEffect(), Duration.EndOfTurn);
super(new CopyTargetSpellEffect(true), Duration.EndOfTurn);
}
HowlOfTheHordeDelayedTriggeredAbility(final HowlOfTheHordeDelayedTriggeredAbility ability) {

View file

@ -55,7 +55,7 @@ import mage.target.TargetPlayer;
public class InfernalKirin extends CardImpl {
public InfernalKirin(UUID ownerId, CardSetInfo setInfo) {
super(ownerId,setInfo,new CardType[]{CardType.CREATURE},"{2}{B}{B}");
super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{2}{B}{B}");
addSuperType(SuperType.LEGENDARY);
this.subtype.add(SubType.KIRIN);
this.subtype.add(SubType.SPIRIT);
@ -100,11 +100,11 @@ class InfernalKirinEffect extends OneShotEffect {
@Override
public boolean apply(Game game, Ability source) {
Spell spell = game.getStack().getSpell(targetPointer.getFirst(game, source));
Spell spell = game.getSpellOrLKIStack(this.getTargetPointer().getFirst(game, source));
if (spell != null) {
int cmc = spell.getConvertedManaCost();
Player targetPlayer = null;
for(Target target: source.getTargets()) {
for (Target target : source.getTargets()) {
if (target instanceof TargetPlayer) {
targetPlayer = game.getPlayer(target.getFirstTarget());
}
@ -112,7 +112,7 @@ class InfernalKirinEffect extends OneShotEffect {
if (targetPlayer != null) {
if (!targetPlayer.getHand().isEmpty()) {
targetPlayer.revealCards("Infernal Kirin", targetPlayer.getHand(), game);
for (UUID uuid: targetPlayer.getHand().copy()) {
for (UUID uuid : targetPlayer.getHand().copy()) {
Card card = game.getCard(uuid);
if (card != null && card.getConvertedManaCost() == cmc) {
targetPlayer.discard(card, source, game);

View file

@ -29,7 +29,6 @@ package mage.cards.k;
import java.util.UUID;
import mage.MageInt;
import mage.MageObject;
import mage.abilities.Ability;
import mage.abilities.common.SpellCastOpponentTriggeredAbility;
import mage.abilities.effects.OneShotEffect;
@ -51,7 +50,7 @@ import mage.target.common.TargetCreatureOrPlayer;
public class KaervekTheMerciless extends CardImpl {
public KaervekTheMerciless(UUID ownerId, CardSetInfo setInfo) {
super(ownerId,setInfo,new CardType[]{CardType.CREATURE},"{5}{B}{R}");
super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{5}{B}{R}");
addSuperType(SuperType.LEGENDARY);
this.subtype.add(SubType.HUMAN);
this.subtype.add(SubType.SHAMAN);
@ -94,9 +93,9 @@ class KaervekTheMercilessEffect extends OneShotEffect {
@Override
public boolean apply(Game game, Ability source) {
MageObject spellCast = game.getObject(getTargetPointer().getFirst(game, source));
if (spellCast instanceof Spell) {
int cost = ((Spell) spellCast).getConvertedManaCost();
Spell spell = game.getSpellOrLKIStack(this.getTargetPointer().getFirst(game, source));
if (spell != null) {
int cost = spell.getConvertedManaCost();
Player target = game.getPlayer(source.getFirstTarget());
if (target != null) {
target.damage(cost, source.getSourceId(), game, false, true);

View file

@ -51,7 +51,6 @@ import mage.game.Game;
import mage.game.permanent.token.MetallurgicSummoningsConstructToken;
import mage.game.stack.Spell;
import mage.players.Player;
import mage.target.targetpointer.FixedTarget;
/**
*
@ -106,10 +105,7 @@ class MetallurgicSummoningsTokenEffect extends OneShotEffect {
@Override
public boolean apply(Game game, Ability source) {
Spell spell = game.getStack().getSpell(targetPointer.getFirst(game, source));
if (spell == null) {
spell = (Spell) game.getLastKnownInformation(((FixedTarget) getTargetPointer()).getTarget(), Zone.STACK);
}
Spell spell = game.getSpellOrLKIStack(this.getTargetPointer().getFirst(game, source));
if (spell != null) {
int cmc = spell.getConvertedManaCost();
if (cmc > 0) {

View file

@ -84,7 +84,7 @@ class MirariTriggeredAbility extends TriggeredAbilityImpl {
}
MirariTriggeredAbility() {
super(Zone.BATTLEFIELD, new DoIfCostPaid(new CopyTargetSpellEffect(), new GenericManaCost(3)), false);
super(Zone.BATTLEFIELD, new DoIfCostPaid(new CopyTargetSpellEffect(true), new GenericManaCost(3)), false);
this.addTarget(new TargetSpell(filter));
}

View file

@ -59,7 +59,7 @@ public class PrimalWellspring extends CardImpl {
this.addAbility(ability);
// When that mana is spent to cast an instant or sorcery spell, copy that spell and you may choose new targets for the copy.
Effect effect = new CopyTargetSpellEffect();
Effect effect = new CopyTargetSpellEffect(true);
effect.setText("copy that spell and you may choose new targets for the copy");
this.addAbility(new PyrimalWellspringTriggeredAbility(ability.getOriginalId(), effect));
}

View file

@ -127,7 +127,7 @@ class PyromancerAscensionQuestTriggeredAbility extends TriggeredAbilityImpl {
class PyromancerAscensionCopyTriggeredAbility extends TriggeredAbilityImpl {
PyromancerAscensionCopyTriggeredAbility() {
super(Zone.BATTLEFIELD, new CopyTargetSpellEffect(), true);
super(Zone.BATTLEFIELD, new CopyTargetSpellEffect(true), true);
}
PyromancerAscensionCopyTriggeredAbility(final PyromancerAscensionCopyTriggeredAbility ability) {

View file

@ -62,7 +62,7 @@ public class PyromancersGoggles extends CardImpl {
this.addAbility(ability);
// When that mana is used to cast a red instant or sorcery spell, copy that spell and you may choose new targets for the copy.
Effect effect = new CopyTargetSpellEffect();
Effect effect = new CopyTargetSpellEffect(true);
effect.setText("copy that spell and you may choose new targets for the copy");
this.addAbility(new PyromancersGogglesTriggeredAbility(ability.getOriginalId(), effect));

View file

@ -101,7 +101,7 @@ class RamosDragonEngineAddCountersEffect extends OneShotEffect {
Player you = game.getPlayer(source.getControllerId());
Permanent permanent = game.getPermanent(source.getSourceId());
if (you != null && permanent != null) {
Spell spell = game.getStack().getSpell(this.getTargetPointer().getFirst(game, source));
Spell spell = game.getSpellOrLKIStack(this.getTargetPointer().getFirst(game, source));
if (spell != null) {
int amount = 0;
if (spell.getColor(game).isWhite()) {

View file

@ -78,7 +78,7 @@ public class RikuOfTwoReflections extends CardImpl {
this.toughness = new MageInt(2);
// Whenever you cast an instant or sorcery spell, you may pay {U}{R}. If you do, copy that spell. You may choose new targets for the copy.
Effect effect = new CopyTargetSpellEffect();
Effect effect = new CopyTargetSpellEffect(true);
effect.setText("copy that spell. You may choose new targets for the copy");
this.addAbility(new SpellCastControllerTriggeredAbility(new DoIfCostPaid(effect, new ManaCostsImpl("{U}{R}")), filter, false, true));

View file

@ -125,15 +125,11 @@ class SunbirdsInvocationEffect extends OneShotEffect {
if (controller == null || sourceObject == null) {
return false;
}
Spell spell = game.getStack().getSpell(this.getTargetPointer().getFirst(game, source));
int xValue = 0;
if (spell == null) {
spell = (Spell) game.getLastKnownInformation(this.getTargetPointer().getFirst(game, source), Zone.STACK);
}
Spell spell = game.getSpellOrLKIStack(this.getTargetPointer().getFirst(game, source));
if (spell == null) {
return false;
}
xValue = spell.getConvertedManaCost();
int xValue = spell.getConvertedManaCost();
Cards cards = new CardsImpl();
cards.addAll(controller.getLibrary().getTopCards(game, xValue));
if (!cards.isEmpty()) {

View file

@ -46,7 +46,7 @@ public class SwarmIntelligence extends CardImpl {
// Whenever you cast an instant or sorcery spell, you may copy that spell. You may choose new targets for the copy.
this.addAbility(new SpellCastControllerTriggeredAbility(
new CopyTargetSpellEffect().setText("you may copy that spell. You may choose new targets for the copy"), new FilterInstantOrSorcerySpell("an instant or sorcery spell"), true, true));
new CopyTargetSpellEffect(true).setText("you may copy that spell. You may choose new targets for the copy"), new FilterInstantOrSorcerySpell("an instant or sorcery spell"), true, true));
}
public SwarmIntelligence(final SwarmIntelligence card) {

View file

@ -154,10 +154,7 @@ class ZadaHedronGrinderEffect extends OneShotEffect {
@Override
public boolean apply(Game game, Ability source) {
Spell spell = game.getStack().getSpell(targetPointer.getFirst(game, source));
if (spell == null) {
spell = (Spell) game.getLastKnownInformation(targetPointer.getFirst(game, source), Zone.STACK);
}
Spell spell = game.getSpellOrLKIStack(this.getTargetPointer().getFirst(game, source));
Player controller = game.getPlayer(source.getControllerId());
if (spell != null && controller != null) {
// search the target that targets source

View file

@ -43,17 +43,30 @@ import mage.players.Player;
*/
public class CopyTargetSpellEffect extends OneShotEffect {
private boolean useLKI = false;
public CopyTargetSpellEffect() {
super(Outcome.Copy);
}
public CopyTargetSpellEffect(boolean useLKI) {
super(Outcome.Copy);
this.useLKI = useLKI;
}
public CopyTargetSpellEffect(final CopyTargetSpellEffect effect) {
super(effect);
this.useLKI = effect.useLKI;
}
@Override
public boolean apply(Game game, Ability source) {
Spell spell = game.getStack().getSpell(targetPointer.getFirst(game, source));
Spell spell;
if (useLKI) {
spell = game.getSpellOrLKIStack(targetPointer.getFirst(game, source));
} else {
spell = game.getStack().getSpell(targetPointer.getFirst(game, source));
}
if (spell == null) {
spell = (Spell) game.getLastKnownInformation(targetPointer.getFirst(game, source), Zone.STACK);
}

View file

@ -57,6 +57,7 @@ import mage.game.match.MatchType;
import mage.game.permanent.Battlefield;
import mage.game.permanent.Permanent;
import mage.game.permanent.PermanentCard;
import mage.game.stack.Spell;
import mage.game.stack.SpellStack;
import mage.game.turn.Phase;
import mage.game.turn.Step;
@ -106,6 +107,10 @@ public interface Game extends MageItem, Serializable {
UUID getOwnerId(MageObject object);
Spell getSpell(UUID spellId);
Spell getSpellOrLKIStack(UUID spellId);
Permanent getPermanent(UUID permanentId);
Permanent getPermanentOrLKIBattlefield(UUID permanentId);

View file

@ -445,6 +445,20 @@ public abstract class GameImpl implements Game, Serializable {
return null;
}
@Override
public Spell getSpell(UUID spellId) {
return state.getStack().getSpell(spellId);
}
@Override
public Spell getSpellOrLKIStack(UUID spellId) {
Spell spell = state.getStack().getSpell(spellId);
if (spell == null) {
spell = (Spell) this.getLastKnownInformation(spellId, Zone.STACK);
}
return spell;
}
@Override
public Permanent getPermanent(UUID permanentId) {
return state.getPermanent(permanentId);