* Fixed some bugs of cards with destroy effects where the second effect was not applied if the target was not destroyed (e.g. because of indestructibility)

This commit is contained in:
LevelX2 2014-02-16 01:53:48 +01:00
parent 4cad29f50a
commit 489518c1e0
6 changed files with 92 additions and 98 deletions

View file

@ -25,24 +25,22 @@
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.sets.betrayersofkamigawa;
import java.util.UUID;
import mage.constants.CardType;
import mage.constants.Rarity;
import mage.MageObject;
import mage.abilities.Ability;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.DestroyTargetEffect;
import mage.cards.CardImpl;
import mage.constants.Outcome;
import mage.constants.Zone;
import mage.filter.FilterPermanent;
import mage.filter.predicate.Predicates;
import mage.filter.predicate.mageobject.CardTypePredicate;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.players.Player;
import mage.target.TargetPermanent;
@ -60,12 +58,12 @@ public class TerashisGrasp extends CardImpl<TerashisGrasp> {
new CardTypePredicate(CardType.ENCHANTMENT)));
}
public TerashisGrasp (UUID ownerId) {
public TerashisGrasp(UUID ownerId) {
super(ownerId, 26, "Terashi's Grasp", Rarity.COMMON, new CardType[]{CardType.SORCERY}, "{2}{W}");
this.expansionSetCode = "BOK";
this.subtype.add("Arcane");
this.color.setWhite(true);
// Destroy target artifact or enchantment.
this.getSpellAbility().addTarget(new TargetPermanent(filter));
this.getSpellAbility().addEffect(new DestroyTargetEffect());
@ -73,7 +71,7 @@ public class TerashisGrasp extends CardImpl<TerashisGrasp> {
this.getSpellAbility().addEffect(new TerashisGraspEffect());
}
public TerashisGrasp (final TerashisGrasp card) {
public TerashisGrasp(final TerashisGrasp card) {
super(card);
}
@ -84,31 +82,31 @@ public class TerashisGrasp extends CardImpl<TerashisGrasp> {
private class TerashisGraspEffect extends OneShotEffect<TerashisGraspEffect> {
public TerashisGraspEffect() {
super(Outcome.DestroyPermanent);
staticText = "You gain life equal to its converted mana cost";
}
public TerashisGraspEffect(TerashisGraspEffect effect) {
super(effect);
}
@Override
public boolean apply(Game game, Ability source) {
MageObject card = game.getLastKnownInformation(source.getFirstTarget(), Zone.BATTLEFIELD);
if (card != null) {
int cost = card.getManaCost().get(0).convertedManaCost();
Player player = game.getPlayer(source.getControllerId());
if (player != null) {
player.gainLife(cost, game);
}
}
return true;
}
@Override
public TerashisGraspEffect copy() {
return new TerashisGraspEffect(this);
}
public TerashisGraspEffect() {
super(Outcome.DestroyPermanent);
staticText = "You gain life equal to its converted mana cost";
}
public TerashisGraspEffect(TerashisGraspEffect effect) {
super(effect);
}
@Override
public boolean apply(Game game, Ability source) {
Permanent targetPermanent = game.getPermanentOrLKIBattlefield(getTargetPointer().getFirst(game, source));
if (targetPermanent != null) {
int cost = targetPermanent.getManaCost().convertedManaCost();
Player player = game.getPlayer(source.getControllerId());
if (player != null) {
player.gainLife(cost, game);
}
}
return true;
}
@Override
public TerashisGraspEffect copy() {
return new TerashisGraspEffect(this);
}
}
}

View file

@ -28,14 +28,15 @@
package mage.sets.gatecrash;
import java.util.UUID;
import mage.constants.CardType;
import mage.constants.Outcome;
import mage.constants.Rarity;
import mage.abilities.Ability;
import mage.abilities.effects.Effect;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.DestroyTargetEffect;
import mage.abilities.effects.common.PutLibraryIntoGraveTargetEffect;
import mage.cards.CardImpl;
import mage.constants.CardType;
import mage.constants.Outcome;
import mage.constants.Rarity;
import mage.filter.common.FilterCreaturePermanent;
import mage.filter.predicate.Predicates;
import mage.filter.predicate.mageobject.CardTypePredicate;
@ -63,6 +64,7 @@ public class GrislySpectacle extends CardImpl<GrislySpectacle> {
this.color.setBlack(true);
// Destroy target nonartifact creature. Its controller puts a number of cards equal to that creature's power from the top of his or her library into his or her graveyard.
this.getSpellAbility().addEffect(new DestroyTargetEffect());
this.getSpellAbility().addEffect(new GrislySpectacleEffect());
this.getSpellAbility().addTarget(new TargetPermanent(filter));
}
@ -81,7 +83,7 @@ class GrislySpectacleEffect extends OneShotEffect<GrislySpectacleEffect> {
public GrislySpectacleEffect() {
super(Outcome.DestroyPermanent);
this.staticText = "Destroy target nonartifact creature. Its controller puts a number of cards equal to that creature's power from the top of his or her library into his or her graveyard";
this.staticText = "Its controller puts a number of cards equal to that creature's power from the top of his or her library into his or her graveyard";
}
public GrislySpectacleEffect(final GrislySpectacleEffect effect) {
@ -95,13 +97,12 @@ class GrislySpectacleEffect extends OneShotEffect<GrislySpectacleEffect> {
@Override
public boolean apply(Game game, Ability source) {
Permanent creature = game.getPermanent(getTargetPointer().getFirst(game, source));
// the mill effect works also if creature is indestructible or regenerated
Permanent creature = game.getPermanentOrLKIBattlefield(this.getTargetPointer().getFirst(game, source));
if (creature != null) {
Player controller = game.getPlayer(creature.getControllerId());
if (controller != null) {
int power = creature.getPower().getValue();
creature.destroy(source.getSourceId(), game, false);
// the mill effect works also if creature is indestructible or regenerated
Effect effect = new PutLibraryIntoGraveTargetEffect(power);
effect.setTargetPointer(new FixedTarget(controller.getId()));
return effect.apply(game, source);

View file

@ -25,23 +25,21 @@
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.sets.mirrodinbesieged;
import java.util.UUID;
import mage.constants.CardType;
import mage.constants.Rarity;
import mage.MageObject;
import mage.abilities.Ability;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.DestroyTargetEffect;
import mage.cards.CardImpl;
import mage.constants.Outcome;
import mage.constants.Zone;
import mage.filter.FilterPermanent;
import mage.filter.predicate.mageobject.CardTypePredicate;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.players.Player;
import mage.target.TargetPermanent;
@ -51,22 +49,24 @@ import mage.target.TargetPermanent;
*/
public class DivineOffering extends CardImpl<DivineOffering> {
private static FilterPermanent filter = new FilterPermanent("artifact");
private final static FilterPermanent filter = new FilterPermanent("artifact");
static {
filter.add(new CardTypePredicate(CardType.ARTIFACT));
}
public DivineOffering (UUID ownerId) {
public DivineOffering(UUID ownerId) {
super(ownerId, 5, "Divine Offering", Rarity.COMMON, new CardType[]{CardType.INSTANT}, "{1}{W}");
this.expansionSetCode = "MBS";
this.color.setWhite(true);
this.getSpellAbility().addTarget(new TargetPermanent(filter));
this.getSpellAbility().addEffect(new DestroyTargetEffect());
this.getSpellAbility().addEffect(new DivineOfferingEffect());
// Destroy target artifact. You gain life equal to its converted mana cost.
this.getSpellAbility().addTarget(new TargetPermanent(filter, true));
this.getSpellAbility().addEffect(new DestroyTargetEffect());
this.getSpellAbility().addEffect(new DivineOfferingEffect());
}
public DivineOffering (final DivineOffering card) {
public DivineOffering(final DivineOffering card) {
super(card);
}
@ -75,34 +75,34 @@ public class DivineOffering extends CardImpl<DivineOffering> {
return new DivineOffering(this);
}
private class DivineOfferingEffect extends OneShotEffect<DivineOfferingEffect> {
public DivineOfferingEffect() {
super(Outcome.DestroyPermanent);
staticText = "You gain life equal to its converted mana cost";
}
public DivineOfferingEffect(DivineOfferingEffect effect) {
super(effect);
}
@Override
public boolean apply(Game game, Ability source) {
MageObject card = game.getLastKnownInformation(source.getFirstTarget(), Zone.BATTLEFIELD);
if (card != null) {
int cost = card.getManaCost().get(0).convertedManaCost();
Player player = game.getPlayer(source.getControllerId());
if (player != null) {
player.gainLife(cost, game);
}
}
return true;
}
@Override
public DivineOfferingEffect copy() {
return new DivineOfferingEffect(this);
}
private class DivineOfferingEffect extends OneShotEffect<DivineOfferingEffect> {
public DivineOfferingEffect() {
super(Outcome.DestroyPermanent);
staticText = "You gain life equal to its converted mana cost";
}
public DivineOfferingEffect(DivineOfferingEffect effect) {
super(effect);
}
@Override
public boolean apply(Game game, Ability source) {
Permanent artefact = game.getPermanentOrLKIBattlefield(getTargetPointer().getFirst(game, source));
if (artefact != null) {
int cost = artefact.getManaCost().convertedManaCost();
Player player = game.getPlayer(source.getControllerId());
if (player != null) {
player.gainLife(cost, game);
}
}
return true;
}
@Override
public DivineOfferingEffect copy() {
return new DivineOfferingEffect(this);
}
}
}

View file

@ -28,14 +28,14 @@
package mage.sets.ninthedition;
import java.util.UUID;
import mage.constants.CardType;
import mage.constants.Rarity;
import mage.abilities.Ability;
import mage.abilities.Mode;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.DestroyTargetEffect;
import mage.cards.CardImpl;
import mage.constants.CardType;
import mage.constants.Outcome;
import mage.constants.Rarity;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.players.Player;
@ -55,6 +55,7 @@ public class Chastise extends CardImpl<Chastise> {
// Destroy target attacking creature. You gain life equal to its power.
this.getSpellAbility().addTarget(new TargetAttackingCreature());
this.getSpellAbility().addEffect(new DestroyTargetEffect());
this.getSpellAbility().addEffect(new ChastiseEffect());
}
@ -70,13 +71,10 @@ public class Chastise extends CardImpl<Chastise> {
class ChastiseEffect extends OneShotEffect<ChastiseEffect> {
public ChastiseEffect() {
super(Outcome.DestroyPermanent);
super(Outcome.GainLife);
}
public ChastiseEffect(final ChastiseEffect effect) {
super(effect);
}
@ -88,10 +86,9 @@ class ChastiseEffect extends OneShotEffect<ChastiseEffect> {
@Override
public boolean apply(Game game, Ability source) {
Permanent permanent = game.getPermanent(source.getFirstTarget());
Permanent permanent = game.getPermanentOrLKIBattlefield(this.getTargetPointer().getFirst(game, source));
if (permanent != null) {
int power = permanent.getPower().getValue();
permanent.destroy(source.getId(), game, true);
Player player = game.getPlayer(source.getControllerId());
if (player != null) {
player.gainLife(power, game);
@ -103,7 +100,6 @@ class ChastiseEffect extends OneShotEffect<ChastiseEffect> {
@Override
public String getText(Mode mode) {
return "Destroy target attacking creature. You gain life equal to its power";
return "You gain life equal to its power";
}
}
}

View file

@ -64,6 +64,7 @@ public class Vendetta extends CardImpl<Vendetta> {
this.color.setBlack(true);
// Destroy target nonblack creature. It can't be regenerated. You lose life equal to that creature's toughness.
this.getSpellAbility().addTarget(new TargetCreaturePermanent(filter));
this.getSpellAbility().addEffect(new DestroyTargetEffect(true));
this.getSpellAbility().addEffect(new VendettaEffect());
@ -98,7 +99,7 @@ class VendettaEffect extends OneShotEffect<VendettaEffect> {
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
Permanent target = (Permanent) game.getLastKnownInformation(source.getFirstTarget(), Zone.BATTLEFIELD);
Permanent target = game.getPermanentOrLKIBattlefield(this.getTargetPointer().getFirst(game, source));
if (player != null && target != null) {
player.loseLife(target.getToughness().getValue(), game);
return true;
@ -106,4 +107,4 @@ class VendettaEffect extends OneShotEffect<VendettaEffect> {
return false;
}
}
}

View file

@ -29,19 +29,17 @@
package mage.sets.scarsofmirrodin;
import java.util.UUID;
import mage.constants.CardType;
import mage.constants.Rarity;
import mage.MageInt;
import mage.MageObject;
import mage.abilities.Ability;
import mage.abilities.common.BlocksOrBecomesBlockedByCreatureTriggeredAbility;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.DestroyTargetEffect;
import mage.cards.CardImpl;
import mage.constants.CardType;
import mage.constants.Outcome;
import mage.constants.Zone;
import mage.constants.Rarity;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.players.Player;
/**
@ -88,9 +86,9 @@ class EngulfingSlagwurmEffect extends OneShotEffect<EngulfingSlagwurmEffect> {
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
MageObject c = game.getLastKnownInformation(targetPointer.getFirst(game, source), Zone.BATTLEFIELD);
if (c != null && controller != null) {
controller.gainLife(c.getPower().getValue(), game);
Permanent creature = game.getPermanentOrLKIBattlefield(this.getTargetPointer().getFirst(game, source));
if (creature != null && controller != null) {
controller.gainLife(creature.getPower().getValue(), game);
}
return false;
}