Removed PostResolveEffect class.

This commit is contained in:
emerald000 2015-03-26 16:59:33 -04:00
parent 1cb3012c37
commit 966e8d1698
51 changed files with 305 additions and 735 deletions

View file

@ -35,7 +35,7 @@ import mage.constants.Rarity;
import mage.constants.Zone; import mage.constants.Zone;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.postresolve.ExileSpellEffect; import mage.abilities.effects.common.ExileSpellEffect;
import mage.cards.Card; import mage.cards.Card;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.game.Game; import mage.game.Game;

View file

@ -27,15 +27,14 @@
*/ */
package mage.sets.avacynrestored; package mage.sets.avacynrestored;
import mage.constants.CardType; import java.util.UUID;
import mage.constants.Rarity;
import mage.abilities.costs.mana.ManaCostsImpl; import mage.abilities.costs.mana.ManaCostsImpl;
import mage.abilities.effects.postresolve.ExileSpellEffect; import mage.abilities.effects.common.ExileSpellEffect;
import mage.abilities.effects.common.turn.AddExtraTurnControllerEffect; import mage.abilities.effects.common.turn.AddExtraTurnControllerEffect;
import mage.abilities.keyword.MiracleAbility; import mage.abilities.keyword.MiracleAbility;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.constants.CardType;
import java.util.UUID; import mage.constants.Rarity;
/** /**
* @author noxx * @author noxx

View file

@ -34,7 +34,7 @@ import mage.constants.CardType;
import mage.constants.Rarity; import mage.constants.Rarity;
import mage.abilities.effects.common.DamageTargetEffect; import mage.abilities.effects.common.DamageTargetEffect;
import mage.abilities.effects.common.discard.DiscardControllerEffect; import mage.abilities.effects.common.discard.DiscardControllerEffect;
import mage.abilities.effects.postresolve.ReturnToHandSpellEffect; import mage.abilities.effects.common.ReturnToHandSpellEffect;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.target.common.TargetCreatureOrPlayer; import mage.target.common.TargetCreatureOrPlayer;

View file

@ -32,7 +32,7 @@ import mage.MageObject;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.ReplacementEffectImpl; import mage.abilities.effects.ReplacementEffectImpl;
import mage.abilities.effects.postresolve.ReturnToLibrarySpellEffect; import mage.abilities.effects.common.ReturnToLibrarySpellEffect;
import mage.cards.Card; import mage.cards.Card;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.constants.CardType; import mage.constants.CardType;

View file

@ -34,7 +34,7 @@ import mage.abilities.Ability;
import mage.abilities.effects.ContinuousEffect; import mage.abilities.effects.ContinuousEffect;
import mage.abilities.effects.ContinuousEffectImpl; import mage.abilities.effects.ContinuousEffectImpl;
import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.postresolve.ExileSpellEffect; import mage.abilities.effects.common.ExileSpellEffect;
import mage.cards.Card; import mage.cards.Card;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.cards.Cards; import mage.cards.Cards;

View file

@ -27,30 +27,32 @@
*/ */
package mage.sets.conflux; package mage.sets.conflux;
import java.util.UUID;
import mage.ObjectColor;
import mage.abilities.condition.common.PermanentsOnTheBattlefieldCondition;
import mage.abilities.decorator.ConditionalOneShotEffect;
import mage.abilities.effects.common.continuous.GainAbilityTargetEffect;
import mage.abilities.effects.common.ReturnToHandSpellEffect;
import mage.abilities.keyword.FlyingAbility;
import mage.cards.CardImpl;
import mage.constants.CardType; import mage.constants.CardType;
import mage.constants.Duration; import mage.constants.Duration;
import mage.constants.Rarity; import mage.constants.Rarity;
import mage.constants.Zone; import mage.filter.common.FilterControlledPermanent;
import mage.ObjectColor;
import mage.abilities.Ability;
import mage.abilities.effects.PostResolveEffect;
import mage.abilities.effects.common.continuous.GainAbilityTargetEffect;
import mage.abilities.keyword.FlyingAbility;
import mage.cards.Card;
import mage.cards.CardImpl;
import mage.filter.FilterPermanent;
import mage.filter.predicate.mageobject.ColorPredicate; import mage.filter.predicate.mageobject.ColorPredicate;
import mage.game.Game;
import mage.target.common.TargetCreaturePermanent; import mage.target.common.TargetCreaturePermanent;
import java.util.UUID;
/** /**
* *
* @author North * @author North
*/ */
public class ViewFromAbove extends CardImpl { public class ViewFromAbove extends CardImpl {
private static final FilterControlledPermanent filter = new FilterControlledPermanent("white permanent you control");
static {
filter.add(new ColorPredicate(ObjectColor.WHITE));
}
public ViewFromAbove(UUID ownerId) { public ViewFromAbove(UUID ownerId) {
super(ownerId, 38, "View from Above", Rarity.UNCOMMON, new CardType[]{CardType.INSTANT}, "{1}{U}"); super(ownerId, 38, "View from Above", Rarity.UNCOMMON, new CardType[]{CardType.INSTANT}, "{1}{U}");
this.expansionSetCode = "CON"; this.expansionSetCode = "CON";
@ -61,7 +63,10 @@ public class ViewFromAbove extends CardImpl {
this.getSpellAbility().addEffect(new GainAbilityTargetEffect(FlyingAbility.getInstance(), Duration.EndOfTurn)); this.getSpellAbility().addEffect(new GainAbilityTargetEffect(FlyingAbility.getInstance(), Duration.EndOfTurn));
this.getSpellAbility().addTarget(new TargetCreaturePermanent()); this.getSpellAbility().addTarget(new TargetCreaturePermanent());
// If you control a white permanent, return View from Above to its owner's hand. // If you control a white permanent, return View from Above to its owner's hand.
this.getSpellAbility().addEffect(new ViewFromAboveEffect()); this.getSpellAbility().addEffect(new ConditionalOneShotEffect(
ReturnToHandSpellEffect.getInstance(),
new PermanentsOnTheBattlefieldCondition(filter),
"If you control a white permanent, return {this} to its owner's hand"));
} }
public ViewFromAbove(final ViewFromAbove card) { public ViewFromAbove(final ViewFromAbove card) {
@ -73,31 +78,3 @@ public class ViewFromAbove extends CardImpl {
return new ViewFromAbove(this); return new ViewFromAbove(this);
} }
} }
class ViewFromAboveEffect extends PostResolveEffect {
public ViewFromAboveEffect() {
this.staticText = "If you control a white permanent, return {this} to its owner's hand";
}
public ViewFromAboveEffect(final ViewFromAboveEffect effect) {
super(effect);
}
@Override
public ViewFromAboveEffect copy() {
return new ViewFromAboveEffect(this);
}
@Override
public void postResolve(Card card, Ability source, UUID controllerId, Game game) {
FilterPermanent filter = new FilterPermanent("white permanent");
filter.add(new ColorPredicate(ObjectColor.WHITE));
if (game.getBattlefield().countAll(filter, source.getControllerId(), game) > 0) {
card.moveToZone(Zone.HAND, source.getSourceId(), game, false);
} else {
card.moveToZone(Zone.GRAVEYARD, source.getSourceId(), game, false);
}
}
}

View file

@ -30,7 +30,7 @@ package mage.sets.dragonsoftarkir;
import java.util.UUID; import java.util.UUID;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.postresolve.ExileSpellEffect; import mage.abilities.effects.common.ExileSpellEffect;
import mage.cards.Card; import mage.cards.Card;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.constants.CardType; import mage.constants.CardType;

View file

@ -35,7 +35,7 @@ import mage.abilities.common.delayed.AtTheBeginOfYourNextUpkeepDelayedTriggeredA
import mage.abilities.effects.Effect; import mage.abilities.effects.Effect;
import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.ExileTargetEffect; import mage.abilities.effects.common.ExileTargetEffect;
import mage.abilities.effects.postresolve.ExileSpellEffect; import mage.abilities.effects.common.ExileSpellEffect;
import mage.cards.Card; import mage.cards.Card;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.constants.CardType; import mage.constants.CardType;

View file

@ -29,7 +29,7 @@ package mage.sets.fatereforged;
import java.util.UUID; import java.util.UUID;
import mage.abilities.effects.common.turn.AddExtraTurnControllerEffect; import mage.abilities.effects.common.turn.AddExtraTurnControllerEffect;
import mage.abilities.effects.postresolve.ExileSpellEffect; import mage.abilities.effects.common.ExileSpellEffect;
import mage.abilities.keyword.DelveAbility; import mage.abilities.keyword.DelveAbility;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.constants.CardType; import mage.constants.CardType;

View file

@ -28,12 +28,12 @@
package mage.sets.fifthdawn; package mage.sets.fifthdawn;
import java.util.UUID; import java.util.UUID;
import mage.constants.CardType;
import mage.constants.Rarity;
import mage.abilities.dynamicvalue.common.PermanentsOnBattlefieldCount; import mage.abilities.dynamicvalue.common.PermanentsOnBattlefieldCount;
import mage.abilities.effects.common.CreateTokenEffect; import mage.abilities.effects.common.CreateTokenEffect;
import mage.abilities.effects.postresolve.ShuffleSpellEffect; import mage.abilities.effects.common.ShuffleSpellEffect;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.constants.CardType;
import mage.constants.Rarity;
import mage.filter.common.FilterControlledPermanent; import mage.filter.common.FilterControlledPermanent;
import mage.filter.predicate.mageobject.SubtypePredicate; import mage.filter.predicate.mageobject.SubtypePredicate;
import mage.game.permanent.token.InsectToken; import mage.game.permanent.token.InsectToken;

View file

@ -33,7 +33,7 @@ import mage.constants.Outcome;
import mage.constants.Rarity; import mage.constants.Rarity;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.postresolve.ShuffleSpellEffect; import mage.abilities.effects.common.ShuffleSpellEffect;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.game.Game; import mage.game.Game;
import mage.game.turn.TurnMod; import mage.game.turn.TurnMod;

View file

@ -30,7 +30,7 @@ package mage.sets.fifthedition;
import java.util.UUID; import java.util.UUID;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.postresolve.ExileSpellEffect; import mage.abilities.effects.common.ExileSpellEffect;
import mage.cards.Card; import mage.cards.Card;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.constants.CardType; import mage.constants.CardType;

View file

@ -29,21 +29,12 @@ package mage.sets.guildpact;
import java.util.UUID; import java.util.UUID;
import mage.MageInt; import mage.MageInt;
import mage.MageObject;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.Mode;
import mage.abilities.common.SpellCastOpponentTriggeredAbility; import mage.abilities.common.SpellCastOpponentTriggeredAbility;
import mage.abilities.costs.Cost;
import mage.abilities.costs.mana.GenericManaCost; import mage.abilities.costs.mana.GenericManaCost;
import mage.abilities.effects.ContinuousEffect;
import mage.abilities.effects.Effect;
import mage.abilities.effects.Effects;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.PostResolveEffect;
import mage.abilities.effects.common.SacrificeEffect; import mage.abilities.effects.common.SacrificeEffect;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.constants.CardType; import mage.constants.CardType;
import mage.constants.Outcome;
import mage.constants.Rarity; import mage.constants.Rarity;
import mage.constants.SetTargetPointer; import mage.constants.SetTargetPointer;
import mage.constants.Zone; import mage.constants.Zone;
@ -51,7 +42,6 @@ import mage.filter.FilterPermanent;
import mage.filter.FilterSpell; import mage.filter.FilterSpell;
import mage.game.Game; import mage.game.Game;
import mage.players.Player; import mage.players.Player;
import mage.util.CardUtil;
/** /**
* *
@ -70,8 +60,7 @@ public class SpelltitheEnforcer extends CardImpl {
// Whenever an opponent casts a spell, that player sacrifices a permanent unless he or she pays {1}. // Whenever an opponent casts a spell, that player sacrifices a permanent unless he or she pays {1}.
this.addAbility(new SpellCastOpponentTriggeredAbility( this.addAbility(new SpellCastOpponentTriggeredAbility(
Zone.BATTLEFIELD, Zone.BATTLEFIELD,
new DoUnlessTargetPaysEffect(new SacrificeEffect(new FilterPermanent(), 1, "that player"), new GenericManaCost(1), new SpelltitheEnforcerEffect(),
"Pay {1}? (otherwise sacrifice a permanent)"),
new FilterSpell(), new FilterSpell(),
false, false,
SetTargetPointer.PLAYER SetTargetPointer.PLAYER
@ -88,87 +77,32 @@ public class SpelltitheEnforcer extends CardImpl {
} }
} }
class DoUnlessTargetPaysEffect extends OneShotEffect { class SpelltitheEnforcerEffect extends SacrificeEffect {
protected Effects executingEffects = new Effects();
private final Cost cost;
private String chooseUseText;
public DoUnlessTargetPaysEffect(Effect effect, Cost cost) { SpelltitheEnforcerEffect() {
this(effect, cost, null); super(new FilterPermanent("permanent to sacrifice"), 1, "that player");
this.staticText = "that player sacrifices a permanent unless he or she pays {1}";
} }
public DoUnlessTargetPaysEffect(Effect effect, Cost cost, String chooseUseText) { SpelltitheEnforcerEffect(final SpelltitheEnforcerEffect effect) {
super(Outcome.Benefit);
this.executingEffects.add(effect);
this.cost = cost;
this.chooseUseText = chooseUseText;
}
public DoUnlessTargetPaysEffect(final DoUnlessTargetPaysEffect effect) {
super(effect); super(effect);
this.executingEffects = effect.executingEffects.copy();
this.cost = effect.cost.copy();
this.chooseUseText = effect.chooseUseText;
} }
public void addEffect(Effect effect) { @Override
executingEffects.add(effect); public SpelltitheEnforcerEffect copy() {
return new SpelltitheEnforcerEffect(this);
} }
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId()); Player player = game.getPlayer(this.getTargetPointer().getFirst(game, source));
Player targetPlayer = game.getPlayer(getTargetPointer().getFirst(game, source)); if (player != null) {
MageObject sourceObject = game.getObject(source.getSourceId()); GenericManaCost cost = new GenericManaCost(1);
if (controller != null && sourceObject != null && targetPlayer != null) { if (!cost.pay(source, game, player.getId(), player.getId(), false)) {
String message; super.apply(game, source);
if (chooseUseText == null) {
String effectText = executingEffects.getText(source.getModes().getMode());
message = "Pay " + cost.getText() + " to prevent (" + effectText.substring(0, effectText.length() -1) + ")?";
} else {
message = chooseUseText;
} }
message = CardUtil.replaceSourceName(message, sourceObject.getLogName()); return true;
boolean result = true;
boolean doEffect = true;
// check if target player is willing to pay
if (cost.canPay(source, source.getSourceId(), targetPlayer.getId(), game) && targetPlayer.chooseUse(Outcome.Detriment, message, game)) {
cost.clearPaid();
if (cost.pay(source, game, source.getSourceId(), targetPlayer.getId(), false)) {
game.informPlayers(targetPlayer.getName() + " pays the cost to prevent the effect");
doEffect = false;
}
}
// do the effects player did not pay
if (doEffect) {
for(Effect effect: executingEffects) {
effect.setTargetPointer(this.targetPointer);
if (effect instanceof OneShotEffect) {
if (!(effect instanceof PostResolveEffect)) {
result &= effect.apply(game, source);
}
}
else {
game.addEffect((ContinuousEffect) effect, source);
}
}
}
return result;
} }
return false; return false;
} }
@Override
public String getText(Mode mode) {
if (!staticText.isEmpty()) {
return staticText;
}
String effectsText = executingEffects.getText(mode);
return effectsText.substring(0, effectsText.length() -1) + " unless he or she pays " + cost.getText();
}
@Override
public DoUnlessTargetPaysEffect copy() {
return new DoUnlessTargetPaysEffect(this);
}
} }

View file

@ -29,7 +29,7 @@ package mage.sets.invasion;
import java.util.UUID; import java.util.UUID;
import mage.abilities.effects.Effect; import mage.abilities.effects.Effect;
import mage.abilities.effects.postresolve.ExileSpellEffect; import mage.abilities.effects.common.ExileSpellEffect;
import mage.abilities.effects.common.ReturnFromGraveyardToHandTargetEffect; import mage.abilities.effects.common.ReturnFromGraveyardToHandTargetEffect;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.constants.CardType; import mage.constants.CardType;

View file

@ -29,7 +29,7 @@ package mage.sets.journeyintonyx;
import java.util.UUID; import java.util.UUID;
import mage.abilities.effects.Effect; import mage.abilities.effects.Effect;
import mage.abilities.effects.postresolve.ExileSpellEffect; import mage.abilities.effects.common.ExileSpellEffect;
import mage.abilities.effects.common.ReturnToHandTargetEffect; import mage.abilities.effects.common.ReturnToHandTargetEffect;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.constants.CardType; import mage.constants.CardType;

View file

@ -28,7 +28,7 @@
package mage.sets.journeyintonyx; package mage.sets.journeyintonyx;
import java.util.UUID; import java.util.UUID;
import mage.abilities.effects.postresolve.ExileSpellEffect; import mage.abilities.effects.common.ExileSpellEffect;
import mage.abilities.effects.common.turn.ControlTargetPlayerNextTurnEffect; import mage.abilities.effects.common.turn.ControlTargetPlayerNextTurnEffect;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.constants.CardType; import mage.constants.CardType;

View file

@ -34,7 +34,7 @@ import mage.constants.Outcome;
import mage.constants.Rarity; import mage.constants.Rarity;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.postresolve.ExileSpellEffect; import mage.abilities.effects.common.ExileSpellEffect;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.game.Game; import mage.game.Game;
import mage.players.Player; import mage.players.Player;

View file

@ -33,7 +33,7 @@ import mage.constants.Outcome;
import mage.constants.Rarity; import mage.constants.Rarity;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.postresolve.ExileSpellEffect; import mage.abilities.effects.common.ExileSpellEffect;
import mage.cards.Card; import mage.cards.Card;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.constants.Zone; import mage.constants.Zone;

View file

@ -34,7 +34,7 @@ import mage.constants.CardType;
import mage.constants.Rarity; import mage.constants.Rarity;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.postresolve.ShuffleSpellEffect; import mage.abilities.effects.common.ShuffleSpellEffect;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.constants.Outcome; import mage.constants.Outcome;
import mage.counters.CounterType; import mage.counters.CounterType;

View file

@ -33,7 +33,7 @@ import mage.constants.CardType;
import mage.constants.Rarity; import mage.constants.Rarity;
import mage.abilities.dynamicvalue.common.ManacostVariableValue; import mage.abilities.dynamicvalue.common.ManacostVariableValue;
import mage.abilities.effects.common.DrawCardTargetEffect; import mage.abilities.effects.common.DrawCardTargetEffect;
import mage.abilities.effects.postresolve.ShuffleSpellEffect; import mage.abilities.effects.common.ShuffleSpellEffect;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.target.TargetPlayer; import mage.target.TargetPlayer;

View file

@ -33,7 +33,7 @@ import mage.constants.Rarity;
import mage.ObjectColor; import mage.ObjectColor;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.postresolve.ShuffleSpellEffect; import mage.abilities.effects.common.ShuffleSpellEffect;
import mage.cards.Card; import mage.cards.Card;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.constants.Outcome; import mage.constants.Outcome;

View file

@ -34,7 +34,7 @@ import mage.constants.Outcome;
import mage.constants.Rarity; import mage.constants.Rarity;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.postresolve.ExileSpellEffect; import mage.abilities.effects.common.ExileSpellEffect;
import mage.abilities.effects.common.continuous.MaximumHandSizeControllerEffect; import mage.abilities.effects.common.continuous.MaximumHandSizeControllerEffect;
import mage.abilities.effects.common.continuous.MaximumHandSizeControllerEffect.HandSizeModification; import mage.abilities.effects.common.continuous.MaximumHandSizeControllerEffect.HandSizeModification;
import mage.cards.Card; import mage.cards.Card;

View file

@ -30,7 +30,7 @@ package mage.sets.mirrodinbesieged;
import java.util.UUID; import java.util.UUID;
import mage.abilities.dynamicvalue.common.ManacostVariableValue; import mage.abilities.dynamicvalue.common.ManacostVariableValue;
import mage.abilities.effects.common.DamageTargetEffect; import mage.abilities.effects.common.DamageTargetEffect;
import mage.abilities.effects.postresolve.ShuffleSpellEffect; import mage.abilities.effects.common.ShuffleSpellEffect;
import mage.abilities.effects.common.replacement.DealtDamageToCreatureBySourceDies; import mage.abilities.effects.common.replacement.DealtDamageToCreatureBySourceDies;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.constants.CardType; import mage.constants.CardType;

View file

@ -33,7 +33,7 @@ import mage.MageInt;
import mage.ObjectColor; import mage.ObjectColor;
import mage.abilities.dynamicvalue.common.ManacostVariableValue; import mage.abilities.dynamicvalue.common.ManacostVariableValue;
import mage.abilities.effects.common.CreateTokenEffect; import mage.abilities.effects.common.CreateTokenEffect;
import mage.abilities.effects.postresolve.ShuffleSpellEffect; import mage.abilities.effects.common.ShuffleSpellEffect;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.constants.CardType; import mage.constants.CardType;
import mage.constants.Rarity; import mage.constants.Rarity;

View file

@ -30,7 +30,6 @@ package mage.sets.modernmasters;
import java.util.UUID; import java.util.UUID;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.PostResolveEffect;
import mage.cards.Card; import mage.cards.Card;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.cards.Cards; import mage.cards.Cards;
@ -39,10 +38,8 @@ import mage.constants.CardType;
import mage.constants.Outcome; import mage.constants.Outcome;
import mage.constants.Rarity; import mage.constants.Rarity;
import mage.constants.Zone; import mage.constants.Zone;
import mage.filter.FilterCard;
import mage.game.Game; import mage.game.Game;
import mage.players.Player; import mage.players.Player;
import mage.target.TargetCard;
/** /**
* *
@ -59,7 +56,6 @@ public class PetalsOfInsight extends CardImpl {
// Look at the top three cards of your library. You may put those cards on the bottom of your library in any order. If you do, return Petals of Insight to its owner's hand. Otherwise, draw three cards. // Look at the top three cards of your library. You may put those cards on the bottom of your library in any order. If you do, return Petals of Insight to its owner's hand. Otherwise, draw three cards.
this.getSpellAbility().addEffect(new PetalsOfInsightEffect()); this.getSpellAbility().addEffect(new PetalsOfInsightEffect());
this.getSpellAbility().addEffect(new PetalsOfInsightReturnEffect());
} }
public PetalsOfInsight(final PetalsOfInsight card) { public PetalsOfInsight(final PetalsOfInsight card) {
@ -74,12 +70,12 @@ public class PetalsOfInsight extends CardImpl {
class PetalsOfInsightEffect extends OneShotEffect { class PetalsOfInsightEffect extends OneShotEffect {
public PetalsOfInsightEffect() { PetalsOfInsightEffect() {
super(Outcome.Benefit); super(Outcome.Benefit);
this.staticText = "Look at the top three cards of your library. You may put those cards on the bottom of your library in any order"; this.staticText = "Look at the top three cards of your library. You may put those cards on the bottom of your library in any order. If you do, return {this} to its owner's hand. Otherwise, draw three cards";
} }
public PetalsOfInsightEffect(final PetalsOfInsightEffect effect) { PetalsOfInsightEffect(final PetalsOfInsightEffect effect) {
super(effect); super(effect);
} }
@ -94,32 +90,21 @@ class PetalsOfInsightEffect extends OneShotEffect {
if (player == null) { if (player == null) {
return false; return false;
} }
Cards cards = new CardsImpl(Zone.PICK); Cards cards = new CardsImpl();
int count = Math.min(player.getLibrary().size(), 3); int count = Math.min(player.getLibrary().size(), 3);
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
Card card = player.getLibrary().removeFromTop(game); Card card = player.getLibrary().removeFromTop(game);
if (card != null) { if (card != null) {
cards.add(card); cards.add(card);
game.setZone(card.getId(), Zone.PICK);
} }
} }
player.lookAtCards("Petals of Insight", cards, game); player.lookAtCards("Petals of Insight", cards, game);
if (player.chooseUse(outcome, "Put the cards on the bottom of your library in any order?", game)) { if (player.chooseUse(outcome, "Put the cards on the bottom of your library in any order?", game)) {
TargetCard target = new TargetCard(Zone.PICK, new FilterCard("card to put on the bottom of your library")); player.putCardsOnBottomOfLibrary(cards, game, source, true);
while (player.isInGame() && cards.size() > 1) { Card spellCard = game.getStack().getSpell(source.getSourceId()).getCard();
player.choose(Outcome.Neutral, cards, target, game); if (spellCard != null) {
Card card = cards.get(target.getFirstTarget(), game); player.moveCardToHandWithInfo(spellCard, source.getSourceId(), game, Zone.STACK);
if (card != null) {
cards.remove(card);
card.moveToZone(Zone.LIBRARY, source.getSourceId(), game, false);
} }
target.clearChosen();
}
if (cards.size() == 1) {
Card card = cards.get(cards.iterator().next(), game);
card.moveToZone(Zone.LIBRARY, source.getSourceId(), game, false);
}
game.getState().setValue(source.getSourceId().toString(), Boolean.TRUE);
} else { } else {
for (UUID cardId: cards) { for (UUID cardId: cards) {
Card card = game.getCard(cardId); Card card = game.getCard(cardId);
@ -127,43 +112,8 @@ class PetalsOfInsightEffect extends OneShotEffect {
card.moveToZone(Zone.LIBRARY, source.getSourceId(), game, true); card.moveToZone(Zone.LIBRARY, source.getSourceId(), game, true);
} }
} }
game.getState().setValue(source.getSourceId().toString(), Boolean.FALSE); player.drawCards(3, game);
} }
return true; return true;
} }
} }
class PetalsOfInsightReturnEffect extends PostResolveEffect {
public PetalsOfInsightReturnEffect() {
staticText = "If you do, return Petals of Insight to its owner's hand. Otherwise, draw three cards";
}
public PetalsOfInsightReturnEffect(final PetalsOfInsightReturnEffect effect) {
super(effect);
}
@Override
public PetalsOfInsightReturnEffect copy() {
return new PetalsOfInsightReturnEffect(this);
}
@Override
public void postResolve(Card card, Ability source, UUID controllerId, Game game) {
Player controller = game.getPlayer(controllerId);
if (controller != null) {
Boolean returnToHand = (Boolean) game.getState().getValue(source.getSourceId().toString());
if (returnToHand == null) {
returnToHand = Boolean.FALSE;
}
if (returnToHand) {
card.moveToZone(Zone.HAND, source.getSourceId(), game, false);
}
else {
card.moveToZone(Zone.GRAVEYARD, source.getSourceId(), game, false);
controller.drawCards(3, game);
}
}
}
}

View file

@ -29,7 +29,7 @@ package mage.sets.morningtide;
import java.util.UUID; import java.util.UUID;
import mage.abilities.effects.common.DamageTargetEffect; import mage.abilities.effects.common.DamageTargetEffect;
import mage.abilities.effects.postresolve.ClashWinReturnToHandSpellEffect; import mage.abilities.effects.common.ClashWinReturnToHandSpellEffect;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.constants.CardType; import mage.constants.CardType;
import mage.constants.Rarity; import mage.constants.Rarity;

View file

@ -27,22 +27,13 @@
*/ */
package mage.sets.morningtide; package mage.sets.morningtide;
import java.io.ObjectStreamException;
import java.util.UUID; import java.util.UUID;
import mage.abilities.Ability;
import mage.abilities.MageSingleton;
import mage.abilities.dynamicvalue.common.ManacostVariableValue; import mage.abilities.dynamicvalue.common.ManacostVariableValue;
import mage.abilities.effects.PostResolveEffect; import mage.abilities.effects.common.ClashWinReturnToHandSpellEffect;
import mage.abilities.effects.common.ClashEffect;
import mage.abilities.effects.common.DamageTargetEffect; import mage.abilities.effects.common.DamageTargetEffect;
import mage.abilities.effects.postresolve.ClashWinReturnToHandSpellEffect;
import mage.cards.Card;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.constants.CardType; import mage.constants.CardType;
import mage.constants.Rarity; import mage.constants.Rarity;
import mage.constants.Zone;
import mage.game.Game;
import mage.players.Player;
import mage.target.common.TargetCreatureOrPlayer; import mage.target.common.TargetCreatureOrPlayer;
/** /**

View file

@ -29,17 +29,10 @@ package mage.sets.planarchaos;
import java.util.UUID; import java.util.UUID;
import mage.MageInt; import mage.MageInt;
import mage.MageObject;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.Mode;
import mage.abilities.common.EntersBattlefieldTriggeredAbility; import mage.abilities.common.EntersBattlefieldTriggeredAbility;
import mage.abilities.costs.Cost; import mage.abilities.costs.Cost;
import mage.abilities.costs.common.SacrificeTargetCost; import mage.abilities.costs.common.SacrificeTargetCost;
import mage.abilities.effects.ContinuousEffect;
import mage.abilities.effects.Effect;
import mage.abilities.effects.Effects;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.PostResolveEffect;
import mage.abilities.effects.common.PutOnLibrarySourceEffect; import mage.abilities.effects.common.PutOnLibrarySourceEffect;
import mage.abilities.keyword.TrampleAbility; import mage.abilities.keyword.TrampleAbility;
import mage.cards.CardImpl; import mage.cards.CardImpl;
@ -50,7 +43,6 @@ import mage.filter.common.FilterControlledLandPermanent;
import mage.game.Game; import mage.game.Game;
import mage.players.Player; import mage.players.Player;
import mage.target.common.TargetControlledPermanent; import mage.target.common.TargetControlledPermanent;
import mage.util.CardUtil;
/** /**
* *
@ -69,13 +61,7 @@ public class ShivanWumpus extends CardImpl {
this.addAbility(TrampleAbility.getInstance()); this.addAbility(TrampleAbility.getInstance());
// When Shivan Wumpus enters the battlefield, any player may sacrifice a land. If a player does, put Shivan Wumpus on top of its owner's library. // When Shivan Wumpus enters the battlefield, any player may sacrifice a land. If a player does, put Shivan Wumpus on top of its owner's library.
this.addAbility(new EntersBattlefieldTriggeredAbility( this.addAbility(new EntersBattlefieldTriggeredAbility(new ShivanWumpusEffect(), false));
new DoIfAnyPlayerPaysEffect(
new PutOnLibrarySourceEffect(true),
new SacrificeTargetCost(new TargetControlledPermanent(new FilterControlledLandPermanent("a land"))),
"Sacrifice a land to return {this} to top of its owners library?"),
false
));
} }
public ShivanWumpus(final ShivanWumpus card) { public ShivanWumpus(final ShivanWumpus card) {
@ -88,91 +74,42 @@ public class ShivanWumpus extends CardImpl {
} }
} }
class DoIfAnyPlayerPaysEffect extends OneShotEffect { class ShivanWumpusEffect extends PutOnLibrarySourceEffect {
protected Effects executingEffects = new Effects();
private final Cost cost;
private String chooseUseText;
public DoIfAnyPlayerPaysEffect(Effect effect, Cost cost) { ShivanWumpusEffect() {
this(effect, cost, null); super(true);
this.staticText = "any player may sacrifice a land. If a player does, put {this} on top of its owner's library";
} }
public DoIfAnyPlayerPaysEffect(Effect effect, Cost cost, String chooseUseText) { ShivanWumpusEffect(final ShivanWumpusEffect effect) {
super(Outcome.Benefit);
this.executingEffects.add(effect);
this.cost = cost;
this.chooseUseText = chooseUseText;
}
public DoIfAnyPlayerPaysEffect(final DoIfAnyPlayerPaysEffect effect) {
super(effect); super(effect);
this.executingEffects = effect.executingEffects.copy();
this.cost = effect.cost.copy();
this.chooseUseText = effect.chooseUseText;
} }
public void addEffect(Effect effect) { @Override
executingEffects.add(effect); public ShivanWumpusEffect copy() {
return new ShivanWumpusEffect(this);
} }
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId()); Player controller = game.getPlayer(source.getControllerId());
MageObject sourceObject = game.getObject(source.getSourceId()); if (controller != null) {
if (controller != null && sourceObject != null) { boolean costPaid = false;
String message;
if (chooseUseText == null) {
String effectText = executingEffects.getText(source.getModes().getMode());
message = "Pay " + cost.getText() + " to prevent (" + effectText.substring(0, effectText.length() -1) + ")?";
} else {
message = chooseUseText;
}
message = CardUtil.replaceSourceName(message, sourceObject.getLogName());
boolean result = true;
boolean doEffect = false;
// check if any player is willing to pay
for (UUID playerId : controller.getInRange()) { for (UUID playerId : controller.getInRange()) {
Cost cost = new SacrificeTargetCost(new TargetControlledPermanent(new FilterControlledLandPermanent()));
Player player = game.getPlayer(playerId); Player player = game.getPlayer(playerId);
if (player != null && cost.canPay(source, source.getSourceId(), player.getId(), game) && player.chooseUse(Outcome.Detriment, message, game)) { if (player != null
cost.clearPaid(); && cost.canPay(source, source.getSourceId(), playerId, game)
if (cost.pay(source, game, source.getSourceId(), player.getId(), false)) { && player.chooseUse(Outcome.Sacrifice, "Sacrifice a land?", game)
game.informPlayers(sourceObject.getLogName() + ": " + player.getName() + " pays the cost"); && cost.pay(source, game, source.getSourceId(), playerId, true)) {
doEffect = true; costPaid = true;
break;
} }
} }
if (costPaid) {
super.apply(game, source);
} }
// do the effects if nobody paid return true;
if (doEffect) {
for(Effect effect: executingEffects) {
effect.setTargetPointer(this.targetPointer);
if (effect instanceof OneShotEffect) {
if (!(effect instanceof PostResolveEffect)) {
result &= effect.apply(game, source);
}
}
else {
game.addEffect((ContinuousEffect) effect, source);
}
}
}
return result;
} }
return false; return false;
} }
@Override
public String getText(Mode mode) {
if (!staticText.isEmpty()) {
return staticText;
}
// any player may sacrifice a land. If a player does, put Shivan Wumpus on top of its owner's library.
String effectsText = executingEffects.getText(mode);
return "any player may " + cost.getText() + ". If a player does, " + effectsText.substring(0, effectsText.length() -1) ;
}
@Override
public DoIfAnyPlayerPaysEffect copy() {
return new DoIfAnyPlayerPaysEffect(this);
}
} }

View file

@ -29,7 +29,7 @@ package mage.sets.planechase;
import java.util.UUID; import java.util.UUID;
import mage.abilities.effects.common.ReturnFromGraveyardToBattlefieldTargetEffect; import mage.abilities.effects.common.ReturnFromGraveyardToBattlefieldTargetEffect;
import mage.abilities.effects.postresolve.ShuffleSpellEffect; import mage.abilities.effects.common.ShuffleSpellEffect;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.constants.CardType; import mage.constants.CardType;
import mage.constants.Rarity; import mage.constants.Rarity;

View file

@ -30,7 +30,7 @@ package mage.sets.returntoravnica;
import java.util.UUID; import java.util.UUID;
import mage.constants.CardType; import mage.constants.CardType;
import mage.constants.Rarity; import mage.constants.Rarity;
import mage.abilities.effects.postresolve.ExileSpellEffect; import mage.abilities.effects.common.ExileSpellEffect;
import mage.abilities.effects.common.ReturnFromGraveyardToHandTargetEffect; import mage.abilities.effects.common.ReturnFromGraveyardToHandTargetEffect;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.target.common.TargetCardInYourGraveyard; import mage.target.common.TargetCardInYourGraveyard;

View file

@ -27,17 +27,17 @@
*/ */
package mage.sets.scarsofmirrodin; package mage.sets.scarsofmirrodin;
import mage.constants.CardType; import java.util.UUID;
import mage.constants.Outcome;
import mage.constants.Rarity;
import mage.constants.Zone;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.PostResolveEffect;
import mage.cards.Card; import mage.cards.Card;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.cards.Cards; import mage.cards.Cards;
import mage.cards.CardsImpl; import mage.cards.CardsImpl;
import mage.constants.CardType;
import mage.constants.Outcome;
import mage.constants.Rarity;
import mage.constants.Zone;
import mage.filter.FilterPermanent; import mage.filter.FilterPermanent;
import mage.filter.common.FilterCreaturePermanent; import mage.filter.common.FilterCreaturePermanent;
import mage.game.Game; import mage.game.Game;
@ -45,8 +45,6 @@ import mage.game.permanent.Permanent;
import mage.players.Player; import mage.players.Player;
import mage.target.common.TargetOpponent; import mage.target.common.TargetOpponent;
import java.util.UUID;
/** /**
* *
* @author BetaSteward_at_googlemail.com * @author BetaSteward_at_googlemail.com
@ -57,9 +55,10 @@ public class CerebralEruption extends CardImpl {
super(ownerId, 86, "Cerebral Eruption", Rarity.RARE, new CardType[]{CardType.SORCERY}, "{2}{R}{R}"); super(ownerId, 86, "Cerebral Eruption", Rarity.RARE, new CardType[]{CardType.SORCERY}, "{2}{R}{R}");
this.expansionSetCode = "SOM"; this.expansionSetCode = "SOM";
this.color.setRed(true); this.color.setRed(true);
// Target opponent reveals the top card of his or her library. Cerebral Eruption deals damage equal to the revealed card's converted mana cost to that player and each creature he or she controls. If a land card is revealed this way, return Cerebral Eruption to its owner's hand.
this.getSpellAbility().addTarget(new TargetOpponent()); this.getSpellAbility().addTarget(new TargetOpponent());
this.getSpellAbility().addEffect(new CerebralEruptionEffect1()); this.getSpellAbility().addEffect(new CerebralEruptionEffect());
this.getSpellAbility().addEffect(new CerebralEruptionEffect2());
} }
public CerebralEruption(final CerebralEruption card) { public CerebralEruption(final CerebralEruption card) {
@ -70,19 +69,18 @@ public class CerebralEruption extends CardImpl {
public CerebralEruption copy() { public CerebralEruption copy() {
return new CerebralEruption(this); return new CerebralEruption(this);
} }
} }
class CerebralEruptionEffect1 extends OneShotEffect { class CerebralEruptionEffect extends OneShotEffect {
private static FilterPermanent filter = new FilterCreaturePermanent(); private static FilterPermanent filter = new FilterCreaturePermanent();
public CerebralEruptionEffect1() { CerebralEruptionEffect() {
super(Outcome.Damage); super(Outcome.Damage);
staticText = "Target opponent reveals the top card of his or her library. {this} deals damage equal to the revealed card's converted mana cost to that player and each creature he or she controls."; staticText = "Target opponent reveals the top card of his or her library. {this} deals damage equal to the revealed card's converted mana cost to that player and each creature he or she controls. If a land card is revealed this way, return {this} to its owner's hand";
} }
public CerebralEruptionEffect1(final CerebralEruptionEffect1 effect) { CerebralEruptionEffect(final CerebralEruptionEffect effect) {
super(effect); super(effect);
} }
@ -100,42 +98,19 @@ class CerebralEruptionEffect1 extends OneShotEffect {
for (Permanent perm: game.getBattlefield().getAllActivePermanents(filter, player.getId(), game)) { for (Permanent perm: game.getBattlefield().getAllActivePermanents(filter, player.getId(), game)) {
perm.damage(damage, source.getSourceId(), game, false, true); perm.damage(damage, source.getSourceId(), game, false, true);
} }
if (card.getCardType().contains(CardType.LAND)) {
Card spellCard = game.getStack().getSpell(source.getSourceId()).getCard();
if (spellCard != null) {
player.moveCardToHandWithInfo(spellCard, source.getSourceId(), game, Zone.STACK);
}
}
return true; return true;
} }
return false; return false;
} }
@Override @Override
public CerebralEruptionEffect1 copy() { public CerebralEruptionEffect copy() {
return new CerebralEruptionEffect1(this); return new CerebralEruptionEffect(this);
}
}
class CerebralEruptionEffect2 extends PostResolveEffect {
public CerebralEruptionEffect2() {
staticText = "If a land card is revealed this way, return {this} to its owner's hand";
}
public CerebralEruptionEffect2(final CerebralEruptionEffect2 effect) {
super(effect);
}
@Override
public void postResolve(Card card, Ability source, UUID controllerId, Game game) {
Card revealed = (Card) game.getState().getValue(source.getSourceId().toString());
if (revealed != null && revealed.getCardType().contains(CardType.LAND)) {
card.moveToZone(Zone.HAND, source.getSourceId(), game, false);
}
else {
card.moveToZone(Zone.GRAVEYARD, source.getSourceId(), game, false);
} }
} }
@Override
public CerebralEruptionEffect2 copy() {
return new CerebralEruptionEffect2(this);
}
}

View file

@ -28,19 +28,17 @@
package mage.sets.scarsofmirrodin; package mage.sets.scarsofmirrodin;
import java.util.UUID; import java.util.UUID;
import mage.abilities.Ability;
import mage.abilities.effects.OneShotEffect;
import mage.cards.Card;
import mage.cards.CardImpl;
import mage.constants.CardType; import mage.constants.CardType;
import mage.constants.Outcome; import mage.constants.Outcome;
import mage.constants.Rarity; import mage.constants.Rarity;
import mage.constants.Zone; import mage.constants.Zone;
import mage.abilities.Ability;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.PostResolveEffect;
import mage.cards.Card;
import mage.cards.CardImpl;
import mage.game.Game; import mage.game.Game;
import mage.players.Player; import mage.players.Player;
import mage.target.TargetPlayer; import mage.target.TargetPlayer;
import mage.target.common.TargetDiscard;
/** /**
* *
@ -52,10 +50,10 @@ public class PsychicMiasma extends CardImpl {
super(ownerId, 76, "Psychic Miasma", Rarity.COMMON, new CardType[]{CardType.SORCERY}, "{1}{B}"); super(ownerId, 76, "Psychic Miasma", Rarity.COMMON, new CardType[]{CardType.SORCERY}, "{1}{B}");
this.expansionSetCode = "SOM"; this.expansionSetCode = "SOM";
this.color.setBlack(true); this.color.setBlack(true);
// Target player discards a card. If a land card is discarded this way, return Psychic Miasma to its owner's hand.
this.getSpellAbility().addTarget(new TargetPlayer()); this.getSpellAbility().addTarget(new TargetPlayer());
PsychicMiasmaEffect1 effect1 = new PsychicMiasmaEffect1(); this.getSpellAbility().addEffect(new PsychicMiasmaEffect());
this.getSpellAbility().addEffect(effect1);
this.getSpellAbility().addEffect(new PsychicMiasmaEffect2());
} }
public PsychicMiasma(final PsychicMiasma card) { public PsychicMiasma(final PsychicMiasma card) {
@ -69,14 +67,14 @@ public class PsychicMiasma extends CardImpl {
} }
class PsychicMiasmaEffect1 extends OneShotEffect { class PsychicMiasmaEffect extends OneShotEffect {
public PsychicMiasmaEffect1() { PsychicMiasmaEffect() {
super(Outcome.Discard); super(Outcome.Discard);
staticText = "Target player discards a card"; staticText = "Target player discards a card. If a land card is discarded this way, return {this} to its owner's hand";
} }
public PsychicMiasmaEffect1(final PsychicMiasmaEffect1 effect) { PsychicMiasmaEffect(final PsychicMiasmaEffect effect) {
super(effect); super(effect);
} }
@ -84,49 +82,19 @@ class PsychicMiasmaEffect1 extends OneShotEffect {
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(targetPointer.getFirst(game, source)); Player player = game.getPlayer(targetPointer.getFirst(game, source));
if (player != null) { if (player != null) {
TargetDiscard target = new TargetDiscard(player.getId()); Card discardedCard = player.discardOne(false, source, game);
player.choose(Outcome.Discard, target, source.getSourceId(), game); if (discardedCard != null && discardedCard.getCardType().contains(CardType.LAND)) {
Card card = player.getHand().get(target.getFirstTarget(), game); Card spellCard = game.getStack().getSpell(source.getSourceId()).getCard();
if (card != null) { if (spellCard != null) {
player.discard(card, source, game); player.moveCardToHandWithInfo(spellCard, source.getSourceId(), game, Zone.STACK);
game.getState().setValue(source.getSourceId().toString(), card); }
return true;
} }
} }
return false; return false;
} }
@Override @Override
public PsychicMiasmaEffect1 copy() { public PsychicMiasmaEffect copy() {
return new PsychicMiasmaEffect1(this); return new PsychicMiasmaEffect(this);
}
}
class PsychicMiasmaEffect2 extends PostResolveEffect {
public PsychicMiasmaEffect2() {
staticText = "If a land card is discarded this way, return {this} to its owner's hand";
}
public PsychicMiasmaEffect2(final PsychicMiasmaEffect2 effect) {
super(effect);
}
@Override
public PsychicMiasmaEffect2 copy() {
return new PsychicMiasmaEffect2(this);
}
@Override
public void postResolve(Card card, Ability source, UUID controllerId, Game game) {
Card discard = (Card) game.getState().getValue(source.getSourceId().toString());
if (discard != null && discard.getCardType().contains(CardType.LAND)) {
card.moveToZone(Zone.HAND, source.getSourceId(), game, false);
}
else {
card.moveToZone(Zone.GRAVEYARD, source.getSourceId(), game, false);
} }
} }
}

View file

@ -28,17 +28,11 @@
package mage.sets.shadowmoor; package mage.sets.shadowmoor;
import java.util.UUID; import java.util.UUID;
import mage.MageObject;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.Mode;
import mage.abilities.costs.Cost; import mage.abilities.costs.Cost;
import mage.abilities.costs.common.PayLifeCost; import mage.abilities.costs.common.PayLifeCost;
import mage.abilities.effects.ContinuousEffect;
import mage.abilities.effects.Effect;
import mage.abilities.effects.Effects;
import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.PostResolveEffect; import mage.cards.Card;
import mage.abilities.effects.common.discard.DiscardHandTargetEffect;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.constants.CardType; import mage.constants.CardType;
import mage.constants.Outcome; import mage.constants.Outcome;
@ -46,7 +40,6 @@ import mage.constants.Rarity;
import mage.game.Game; import mage.game.Game;
import mage.players.Player; import mage.players.Player;
import mage.target.TargetPlayer; import mage.target.TargetPlayer;
import mage.util.CardUtil;
/** /**
* *
@ -62,7 +55,7 @@ public class Tyrannize extends CardImpl {
// Target player discards his or her hand unless he or she pays 7 life. // Target player discards his or her hand unless he or she pays 7 life.
this.getSpellAbility().addTarget(new TargetPlayer()); this.getSpellAbility().addTarget(new TargetPlayer());
this.getSpellAbility().addEffect(new DoUnlessTargetPaysEffect(new DiscardHandTargetEffect(), new PayLifeCost(7), rule)); this.getSpellAbility().addEffect(new TyrannizeEffect());
} }
@ -76,87 +69,36 @@ public class Tyrannize extends CardImpl {
} }
} }
class DoUnlessTargetPaysEffect extends OneShotEffect { class TyrannizeEffect extends OneShotEffect {
protected Effects executingEffects = new Effects();
private final Cost cost;
private String chooseUseText;
public DoUnlessTargetPaysEffect(Effect effect, Cost cost) { TyrannizeEffect() {
this(effect, cost, null); super(Outcome.Discard);
this.staticText = "Target player discards his or her hand unless he or she pays 7 life";
} }
public DoUnlessTargetPaysEffect(Effect effect, Cost cost, String chooseUseText) { TyrannizeEffect(final TyrannizeEffect effect) {
super(Outcome.Benefit);
this.executingEffects.add(effect);
this.cost = cost;
this.chooseUseText = chooseUseText;
}
public DoUnlessTargetPaysEffect(final DoUnlessTargetPaysEffect effect) {
super(effect); super(effect);
this.executingEffects = effect.executingEffects.copy();
this.cost = effect.cost.copy();
this.chooseUseText = effect.chooseUseText;
} }
public void addEffect(Effect effect) { @Override
executingEffects.add(effect); public TyrannizeEffect copy() {
return new TyrannizeEffect(this);
} }
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId()); Player player = game.getPlayer(this.getTargetPointer().getFirst(game, source));
Player targetPlayer = game.getPlayer(getTargetPointer().getFirst(game, source)); if (player != null) {
MageObject sourceObject = game.getObject(source.getSourceId()); Cost cost = new PayLifeCost(7);
if (controller != null && sourceObject != null && targetPlayer != null) { if (!cost.canPay(source, source.getSourceId(), player.getId(), game)
String message; || !player.chooseUse(Outcome.LoseLife, "Pay 7 life?", game)
if (chooseUseText == null) { || !cost.pay(source, game, source.getSourceId(), player.getId(), true)) {
String effectText = executingEffects.getText(source.getModes().getMode()); for (Card card : player.getHand().getCards(game)) {
message = "Pay " + cost.getText() + " to prevent (" + effectText.substring(0, effectText.length() -1) + ")?"; player.discard(card, source, game);
} else {
message = chooseUseText;
}
message = CardUtil.replaceSourceName(message, sourceObject.getLogName());
boolean result = true;
boolean doEffect = true;
// check if target player is willing to pay
if (cost.canPay(source, source.getSourceId(), targetPlayer.getId(), game) && targetPlayer.chooseUse(Outcome.Detriment, message, game)) {
cost.clearPaid();
if (cost.pay(source, game, source.getSourceId(), targetPlayer.getId(), false)) {
game.informPlayers(targetPlayer.getName() + " pays the cost to prevent the effect");
doEffect = false;
} }
} }
// do the effects player did not pay return true;
if (doEffect) {
for(Effect effect: executingEffects) {
effect.setTargetPointer(this.targetPointer);
if (effect instanceof OneShotEffect) {
if (!(effect instanceof PostResolveEffect)) {
result &= effect.apply(game, source);
}
}
else {
game.addEffect((ContinuousEffect) effect, source);
}
}
}
return result;
} }
return false; return false;
} }
@Override
public String getText(Mode mode) {
if (!staticText.isEmpty()) {
return staticText;
}
String effectsText = executingEffects.getText(mode);
return effectsText.substring(0, effectsText.length() -1) + " unless he or she pays " + cost.getText();
}
@Override
public DoUnlessTargetPaysEffect copy() {
return new DoUnlessTargetPaysEffect(this);
}
} }

View file

@ -31,7 +31,7 @@ import java.util.UUID;
import mage.constants.CardType; import mage.constants.CardType;
import mage.constants.Rarity; import mage.constants.Rarity;
import mage.abilities.effects.common.DamageTargetEffect; import mage.abilities.effects.common.DamageTargetEffect;
import mage.abilities.effects.postresolve.ShuffleSpellEffect; import mage.abilities.effects.common.ShuffleSpellEffect;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.target.common.TargetCreatureOrPlayer; import mage.target.common.TargetCreatureOrPlayer;

View file

@ -33,7 +33,7 @@ import mage.constants.Outcome;
import mage.constants.Rarity; import mage.constants.Rarity;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.postresolve.ShuffleSpellEffect; import mage.abilities.effects.common.ShuffleSpellEffect;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.game.Game; import mage.game.Game;
import mage.players.Player; import mage.players.Player;

View file

@ -34,7 +34,7 @@ import mage.abilities.costs.Cost;
import mage.abilities.costs.common.SacrificeTargetCost; import mage.abilities.costs.common.SacrificeTargetCost;
import mage.abilities.effects.Effect; import mage.abilities.effects.Effect;
import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.postresolve.ExileSpellEffect; import mage.abilities.effects.common.ExileSpellEffect;
import mage.cards.Card; import mage.cards.Card;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.constants.*; import mage.constants.*;

View file

@ -31,7 +31,7 @@ import mage.abilities.Ability;
import mage.abilities.costs.common.DiscardXTargetCost; import mage.abilities.costs.common.DiscardXTargetCost;
import mage.abilities.dynamicvalue.common.GetXValue; import mage.abilities.dynamicvalue.common.GetXValue;
import mage.abilities.effects.Effect; import mage.abilities.effects.Effect;
import mage.abilities.effects.postresolve.ExileSpellEffect; import mage.abilities.effects.common.ExileSpellEffect;
import mage.abilities.effects.common.ReturnFromGraveyardToHandTargetEffect; import mage.abilities.effects.common.ReturnFromGraveyardToHandTargetEffect;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.constants.CardType; import mage.constants.CardType;

View file

@ -30,7 +30,7 @@ package mage.sets.urzassaga;
import java.util.UUID; import java.util.UUID;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.postresolve.ExileSpellEffect; import mage.abilities.effects.common.ExileSpellEffect;
import mage.abilities.effects.common.discard.DiscardHandAllEffect; import mage.abilities.effects.common.discard.DiscardHandAllEffect;
import mage.cards.Card; import mage.cards.Card;
import mage.cards.CardImpl; import mage.cards.CardImpl;

View file

@ -33,7 +33,7 @@ import mage.constants.Outcome;
import mage.constants.Rarity; import mage.constants.Rarity;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.postresolve.ExileSpellEffect; import mage.abilities.effects.common.ExileSpellEffect;
import mage.abilities.effects.common.UntapLandsEffect; import mage.abilities.effects.common.UntapLandsEffect;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.game.Game; import mage.game.Game;

View file

@ -50,7 +50,6 @@ import mage.abilities.effects.ContinuousEffect;
import mage.abilities.effects.Effect; import mage.abilities.effects.Effect;
import mage.abilities.effects.Effects; import mage.abilities.effects.Effects;
import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.PostResolveEffect;
import mage.abilities.effects.common.BasicManaEffect; import mage.abilities.effects.common.BasicManaEffect;
import mage.abilities.effects.common.DynamicManaEffect; import mage.abilities.effects.common.DynamicManaEffect;
import mage.abilities.keyword.FlashbackAbility; import mage.abilities.keyword.FlashbackAbility;
@ -195,7 +194,6 @@ public abstract class AbilityImpl implements Ability {
if (checkIfClause(game)) { if (checkIfClause(game)) {
for (Effect effect: getEffects()) { for (Effect effect: getEffects()) {
if (effect instanceof OneShotEffect) { if (effect instanceof OneShotEffect) {
if (!(effect instanceof PostResolveEffect)) {
boolean effectResult = effect.apply(game, this); boolean effectResult = effect.apply(game, this);
result &= effectResult; result &= effectResult;
if (logger.isDebugEnabled()) { if (logger.isDebugEnabled()) {
@ -212,7 +210,6 @@ public abstract class AbilityImpl implements Ability {
} }
} }
} }
}
else { else {
game.addEffect((ContinuousEffect) effect, this); game.addEffect((ContinuousEffect) effect, this);
} }

View file

@ -1,61 +0,0 @@
/*
* Copyright 2011 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 mage.abilities.effects;
import java.util.UUID;
import mage.constants.Outcome;
import mage.abilities.Ability;
import mage.cards.Card;
import mage.game.Game;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public abstract class PostResolveEffect extends OneShotEffect {
public PostResolveEffect() {
super(Outcome.Neutral);
}
public PostResolveEffect(final PostResolveEffect effect) {
super(effect);
}
@Override
public boolean apply(Game game, Ability source) {
return true;
}
public boolean isActive(Ability source, Game game) {
return true;
}
public abstract void postResolve(Card card, Ability source, UUID controllerId, Game game);
}

View file

@ -25,15 +25,13 @@
* authors and should not be interpreted as representing official policies, either expressed * authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com. * or implied, of BetaSteward_at_googlemail.com.
*/ */
package mage.abilities.effects.postresolve; package mage.abilities.effects.common;
import java.io.ObjectStreamException;
import java.util.UUID;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.MageSingleton; import mage.abilities.MageSingleton;
import mage.abilities.effects.PostResolveEffect; import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.ClashEffect;
import mage.cards.Card; import mage.cards.Card;
import mage.constants.Outcome;
import mage.constants.Zone; import mage.constants.Zone;
import mage.game.Game; import mage.game.Game;
import mage.players.Player; import mage.players.Player;
@ -42,42 +40,36 @@ import mage.players.Player;
* *
* @author LevelX2 * @author LevelX2
*/ */
public class ClashWinReturnToHandSpellEffect extends PostResolveEffect implements MageSingleton { public class ClashWinReturnToHandSpellEffect extends OneShotEffect implements MageSingleton {
private static final ClashWinReturnToHandSpellEffect fINSTANCE = new ClashWinReturnToHandSpellEffect(); private static final ClashWinReturnToHandSpellEffect fINSTANCE = new ClashWinReturnToHandSpellEffect();
private Object readResolve() throws ObjectStreamException {
return fINSTANCE;
}
private ClashWinReturnToHandSpellEffect() {
staticText = "Clash with an opponent. If you win, return {this} to its owner's hand";
}
public static ClashWinReturnToHandSpellEffect getInstance() { public static ClashWinReturnToHandSpellEffect getInstance() {
return fINSTANCE; return fINSTANCE;
} }
private ClashWinReturnToHandSpellEffect() {
super(Outcome.ReturnToHand);
staticText = "Clash with an opponent. If you win, return {this} to its owner's hand";
}
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
if (ClashEffect.getInstance().apply(game, source)) {
Card spellCard = game.getStack().getSpell(source.getSourceId()).getCard();
if (spellCard != null) {
controller.moveCardToHandWithInfo(spellCard, source.getSourceId(), game, Zone.STACK);
}
}
return true; return true;
} }
return false;
}
@Override @Override
public ClashWinReturnToHandSpellEffect copy() { public ClashWinReturnToHandSpellEffect copy() {
return fINSTANCE; return fINSTANCE;
} }
@Override
public boolean isActive(Ability source, Game game) {
return ClashEffect.getInstance().apply(game, source);
}
@Override
public void postResolve(Card card, Ability source, UUID controllerId, Game game) {
Player controller = game.getPlayer(controllerId);
if (controller != null) {
controller.moveCardToHandWithInfo(card, source.getSourceId(), game, Zone.STACK);
}
}
} }

View file

@ -34,7 +34,6 @@ import mage.abilities.Mode;
import mage.abilities.effects.ContinuousEffect; import mage.abilities.effects.ContinuousEffect;
import mage.abilities.effects.Effect; import mage.abilities.effects.Effect;
import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.PostResolveEffect;
import mage.constants.Outcome; import mage.constants.Outcome;
import mage.game.Game; import mage.game.Game;
import mage.players.Player; import mage.players.Player;
@ -91,10 +90,8 @@ public class DoIfClashWonEffect extends OneShotEffect {
executingEffect.setTargetPointer(this.targetPointer); executingEffect.setTargetPointer(this.targetPointer);
} }
if (executingEffect instanceof OneShotEffect) { if (executingEffect instanceof OneShotEffect) {
if (!(executingEffect instanceof PostResolveEffect)) {
return executingEffect.apply(game, source); return executingEffect.apply(game, source);
} }
}
else { else {
game.addEffect((ContinuousEffect) executingEffect, source); game.addEffect((ContinuousEffect) executingEffect, source);
} }

View file

@ -8,7 +8,6 @@ import mage.abilities.effects.ContinuousEffect;
import mage.abilities.effects.Effect; import mage.abilities.effects.Effect;
import mage.abilities.effects.Effects; import mage.abilities.effects.Effects;
import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.PostResolveEffect;
import mage.constants.Outcome; import mage.constants.Outcome;
import mage.game.Game; import mage.game.Game;
import mage.players.Player; import mage.players.Player;
@ -61,10 +60,8 @@ public class DoIfCostPaid extends OneShotEffect {
for(Effect effect: executingEffects) { for(Effect effect: executingEffects) {
effect.setTargetPointer(this.targetPointer); effect.setTargetPointer(this.targetPointer);
if (effect instanceof OneShotEffect) { if (effect instanceof OneShotEffect) {
if (!(effect instanceof PostResolveEffect)) {
result &= effect.apply(game, source); result &= effect.apply(game, source);
} }
}
else { else {
game.addEffect((ContinuousEffect) effect, source); game.addEffect((ContinuousEffect) effect, source);
} }

View file

@ -36,7 +36,6 @@ import mage.abilities.effects.ContinuousEffect;
import mage.abilities.effects.Effect; import mage.abilities.effects.Effect;
import mage.abilities.effects.Effects; import mage.abilities.effects.Effects;
import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.PostResolveEffect;
import mage.constants.Outcome; import mage.constants.Outcome;
import mage.game.Game; import mage.game.Game;
import mage.players.Player; import mage.players.Player;
@ -106,10 +105,8 @@ public class DoUnlessAnyPlayerPaysEffect extends OneShotEffect {
for(Effect effect: executingEffects) { for(Effect effect: executingEffects) {
effect.setTargetPointer(this.targetPointer); effect.setTargetPointer(this.targetPointer);
if (effect instanceof OneShotEffect) { if (effect instanceof OneShotEffect) {
if (!(effect instanceof PostResolveEffect)) {
result &= effect.apply(game, source); result &= effect.apply(game, source);
} }
}
else { else {
game.addEffect((ContinuousEffect) effect, source); game.addEffect((ContinuousEffect) effect, source);
} }

View file

@ -26,49 +26,49 @@
* or implied, of BetaSteward_at_googlemail.com. * or implied, of BetaSteward_at_googlemail.com.
*/ */
package mage.abilities.effects.postresolve; package mage.abilities.effects.common;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.MageSingleton; import mage.abilities.MageSingleton;
import mage.abilities.effects.PostResolveEffect; import mage.abilities.effects.OneShotEffect;
import mage.cards.Card; import mage.cards.Card;
import mage.game.Game; import mage.constants.Outcome;
import java.io.ObjectStreamException;
import java.util.UUID;
import mage.constants.Zone; import mage.constants.Zone;
import mage.game.Game;
import mage.players.Player; import mage.players.Player;
/** /**
* *
* @author BetaSteward_at_googlemail.com * @author BetaSteward_at_googlemail.com
*/ */
public class ExileSpellEffect extends PostResolveEffect implements MageSingleton { public class ExileSpellEffect extends OneShotEffect implements MageSingleton {
private static final ExileSpellEffect fINSTANCE = new ExileSpellEffect(); private static final ExileSpellEffect fINSTANCE = new ExileSpellEffect();
private Object readResolve() throws ObjectStreamException { public static ExileSpellEffect getInstance() {
return fINSTANCE; return fINSTANCE;
} }
private ExileSpellEffect() { private ExileSpellEffect() {
super(Outcome.Exile);
staticText = "Exile {this}"; staticText = "Exile {this}";
} }
public static ExileSpellEffect getInstance() {
return fINSTANCE;
}
@Override @Override
public ExileSpellEffect copy() { public ExileSpellEffect copy() {
return fINSTANCE; return fINSTANCE;
} }
@Override @Override
public void postResolve(Card card, Ability source, UUID controllerId, Game game) { public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(controllerId); Player controller = game.getPlayer(source.getControllerId());
if (controller != null) { if (controller != null) {
controller.moveCardToExileWithInfo(card, null, "", controllerId, game, Zone.STACK); Card spellCard = game.getStack().getSpell(source.getSourceId()).getCard();
} if (spellCard != null) {
controller.moveCardToExileWithInfo(spellCard, null, "", source.getSourceId(), game, Zone.STACK);
}
return true;
}
return false;
} }
} }

View file

@ -0,0 +1,44 @@
package mage.abilities.effects.common;
import mage.abilities.Ability;
import mage.abilities.MageSingleton;
import mage.abilities.effects.OneShotEffect;
import mage.cards.Card;
import mage.constants.Outcome;
import mage.constants.Zone;
import mage.game.Game;
import mage.players.Player;
/**
*
* @author Loki
*/
public class ReturnToHandSpellEffect extends OneShotEffect implements MageSingleton {
private static final ReturnToHandSpellEffect fINSTANCE = new ReturnToHandSpellEffect();
public static ReturnToHandSpellEffect getInstance() {
return fINSTANCE;
}
private ReturnToHandSpellEffect() {
super(Outcome.Benefit);
staticText = "Return {this} to its owner's hand";
}
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Card spellCard = game.getStack().getSpell(source.getSourceId()).getCard();
controller.moveCardToHandWithInfo(spellCard, source.getSourceId(), game, Zone.STACK);
return true;
}
return false;
}
@Override
public ReturnToHandSpellEffect copy() {
return fINSTANCE;
}
}

View file

@ -25,12 +25,12 @@
* authors and should not be interpreted as representing official policies, either expressed * authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com. * or implied, of BetaSteward_at_googlemail.com.
*/ */
package mage.abilities.effects.postresolve; package mage.abilities.effects.common;
import java.util.UUID;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.effects.PostResolveEffect; import mage.abilities.effects.OneShotEffect;
import mage.cards.Card; import mage.cards.Card;
import mage.constants.Outcome;
import mage.constants.Zone; import mage.constants.Zone;
import mage.game.Game; import mage.game.Game;
import mage.players.Player; import mage.players.Player;
@ -39,11 +39,12 @@ import mage.players.Player;
* *
* @author LevelX2 * @author LevelX2
*/ */
public class ReturnToLibrarySpellEffect extends PostResolveEffect { public class ReturnToLibrarySpellEffect extends OneShotEffect {
private final boolean toTop; private final boolean toTop;
public ReturnToLibrarySpellEffect(boolean top) { public ReturnToLibrarySpellEffect(boolean top) {
super(Outcome.Neutral);
staticText = "Put {this} on "+ (top ? "top":"the bottom") + " of its owner's library"; staticText = "Put {this} on "+ (top ? "top":"the bottom") + " of its owner's library";
this.toTop = top; this.toTop = top;
} }
@ -55,19 +56,19 @@ public class ReturnToLibrarySpellEffect extends PostResolveEffect {
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Card spellCard = game.getStack().getSpell(source.getSourceId()).getCard();
if (spellCard != null) {
controller.moveCardToLibraryWithInfo(spellCard, source.getSourceId(), game, Zone.STACK, toTop, true);
}
return true; return true;
} }
return false;
}
@Override @Override
public ReturnToLibrarySpellEffect copy() { public ReturnToLibrarySpellEffect copy() {
return new ReturnToLibrarySpellEffect(this); return new ReturnToLibrarySpellEffect(this);
} }
@Override
public void postResolve(Card card, Ability source, UUID controllerId, Game game) {
Player controller = game.getPlayer(controllerId);
if (controller != null) {
controller.moveCardToLibraryWithInfo(card, source.getSourceId(), game, Zone.STACK, toTop, true);
}
}
} }

View file

@ -26,56 +26,53 @@
* or implied, of BetaSteward_at_googlemail.com. * or implied, of BetaSteward_at_googlemail.com.
*/ */
package mage.abilities.effects.postresolve; package mage.abilities.effects.common;
import mage.constants.Zone;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.MageSingleton; import mage.abilities.MageSingleton;
import mage.abilities.effects.PostResolveEffect; import mage.abilities.effects.OneShotEffect;
import mage.cards.Card; import mage.cards.Card;
import mage.constants.Outcome;
import mage.constants.Zone;
import mage.game.Game; import mage.game.Game;
import mage.players.Player; import mage.players.Player;
import java.io.ObjectStreamException;
import java.util.UUID;
/** /**
* *
* @author nantuko * @author nantuko
*/ */
public class ShuffleSpellEffect extends PostResolveEffect implements MageSingleton { public class ShuffleSpellEffect extends OneShotEffect implements MageSingleton {
private static final ShuffleSpellEffect fINSTANCE = new ShuffleSpellEffect(); private static final ShuffleSpellEffect fINSTANCE = new ShuffleSpellEffect();
private Object readResolve() throws ObjectStreamException {
return fINSTANCE;
}
private ShuffleSpellEffect() {
staticText = "Shuffle {this} into its owner's library";
}
public static ShuffleSpellEffect getInstance() { public static ShuffleSpellEffect getInstance() {
return fINSTANCE; return fINSTANCE;
} }
private ShuffleSpellEffect() {
super(Outcome.Neutral);
staticText = "Shuffle {this} into its owner's library";
}
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Card spellCard = game.getStack().getSpell(source.getSourceId()).getCard();
if (spellCard != null) {
Player owner = game.getPlayer(spellCard.getOwnerId());
if (owner != null) {
controller.moveCardToLibraryWithInfo(spellCard, source.getSourceId(), game, Zone.STACK, true, true);
owner.shuffleLibrary(game);
}
}
return true; return true;
} }
return false;
}
@Override @Override
public ShuffleSpellEffect copy() { public ShuffleSpellEffect copy() {
return fINSTANCE; return fINSTANCE;
} }
@Override
public void postResolve(Card card, Ability source, UUID controllerId, Game game) {
Player controller = game.getPlayer(source.getControllerId());
Player owner = game.getPlayer(card.getOwnerId());
if (controller != null && owner != null) {
controller.moveCardToLibraryWithInfo(card, source.getSourceId(), game, Zone.STACK, true, true);
owner.shuffleLibrary(game);
}
}
} }

View file

@ -1,51 +0,0 @@
package mage.abilities.effects.postresolve;
import mage.constants.Zone;
import mage.abilities.Ability;
import mage.abilities.MageSingleton;
import mage.abilities.effects.PostResolveEffect;
import mage.cards.Card;
import mage.game.Game;
import java.io.ObjectStreamException;
import java.util.UUID;
import mage.players.Player;
/**
*
* @author Loki
*/
public class ReturnToHandSpellEffect extends PostResolveEffect implements MageSingleton {
private static final ReturnToHandSpellEffect fINSTANCE = new ReturnToHandSpellEffect();
private Object readResolve() throws ObjectStreamException {
return fINSTANCE;
}
private ReturnToHandSpellEffect() {
staticText = "Return {this} to its owner's hand";
}
public static ReturnToHandSpellEffect getInstance() {
return fINSTANCE;
}
@Override
public boolean apply(Game game, Ability source) {
return true;
}
@Override
public ReturnToHandSpellEffect copy() {
return fINSTANCE;
}
@Override
public void postResolve(Card card, Ability source, UUID controllerId, Game game) {
Player controller = game.getPlayer(controllerId);
if (controller != null) {
controller.moveCardToHandWithInfo(card, source.getSourceId(), game, Zone.STACK);
}
}
}

View file

@ -44,8 +44,6 @@ import mage.abilities.costs.Cost;
import mage.abilities.costs.mana.ManaCost; import mage.abilities.costs.mana.ManaCost;
import mage.abilities.costs.mana.ManaCosts; import mage.abilities.costs.mana.ManaCosts;
import mage.abilities.dynamicvalue.common.StaticValue; import mage.abilities.dynamicvalue.common.StaticValue;
import mage.abilities.effects.Effect;
import mage.abilities.effects.PostResolveEffect;
import mage.abilities.keyword.BestowAbility; import mage.abilities.keyword.BestowAbility;
import mage.abilities.keyword.MorphAbility; import mage.abilities.keyword.MorphAbility;
import mage.cards.Card; import mage.cards.Card;
@ -64,7 +62,6 @@ import mage.game.permanent.PermanentCard;
import mage.players.Player; import mage.players.Player;
import mage.target.Target; import mage.target.Target;
import mage.target.TargetAmount; import mage.target.TargetAmount;
import mage.watchers.Watcher;
/** /**
* *
@ -204,19 +201,9 @@ public class Spell implements StackObject, Card {
index++; index++;
} }
} }
if (!isCopiedSpell()) {
for (Effect effect : ability.getEffects()) {
if (effect instanceof PostResolveEffect) {
if (((PostResolveEffect) effect).isActive(ability, game)) {
((PostResolveEffect) effect).postResolve(card, ability, controllerId, game);
return result;
}
}
}
if (game.getState().getZone(card.getMainCard().getId()) == Zone.STACK) { if (game.getState().getZone(card.getMainCard().getId()) == Zone.STACK) {
card.moveToZone(Zone.GRAVEYARD, ability.getSourceId(), game, false); card.moveToZone(Zone.GRAVEYARD, ability.getSourceId(), game, false);
} }
}
return result; return result;
} }
//20091005 - 608.2b //20091005 - 608.2b