forked from External/mage
create common ExileTopCardPlayUntilExileAnotherEffect
This commit is contained in:
parent
2e70279485
commit
3ac86997b2
3 changed files with 152 additions and 213 deletions
|
|
@ -1,27 +1,13 @@
|
||||||
package mage.cards.f;
|
package mage.cards.f;
|
||||||
|
|
||||||
import mage.MageObject;
|
|
||||||
import mage.abilities.Ability;
|
|
||||||
import mage.abilities.condition.common.FerociousCondition;
|
import mage.abilities.condition.common.FerociousCondition;
|
||||||
import mage.abilities.effects.AsThoughEffect;
|
import mage.abilities.effects.common.ExileTopCardPlayUntilExileAnotherEffect;
|
||||||
import mage.abilities.effects.AsThoughEffectImpl;
|
|
||||||
import mage.abilities.effects.ContinuousEffect;
|
|
||||||
import mage.abilities.effects.OneShotEffect;
|
|
||||||
import mage.abilities.hint.common.FerociousHint;
|
import mage.abilities.hint.common.FerociousHint;
|
||||||
import mage.abilities.triggers.BeginningOfEndStepTriggeredAbility;
|
import mage.abilities.triggers.BeginningOfEndStepTriggeredAbility;
|
||||||
import mage.cards.Card;
|
|
||||||
import mage.cards.CardImpl;
|
import mage.cards.CardImpl;
|
||||||
import mage.cards.CardSetInfo;
|
import mage.cards.CardSetInfo;
|
||||||
import mage.constants.AsThoughEffectType;
|
|
||||||
import mage.constants.CardType;
|
import mage.constants.CardType;
|
||||||
import mage.constants.Duration;
|
|
||||||
import mage.constants.Outcome;
|
|
||||||
import mage.game.Game;
|
|
||||||
import mage.players.Player;
|
|
||||||
import mage.target.targetpointer.FixedTarget;
|
|
||||||
import mage.util.CardUtil;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -34,7 +20,7 @@ public final class FuriousRise extends CardImpl {
|
||||||
|
|
||||||
// At the beginning of your end step, if you control a creature with power 4 or greater, exile the top card of your library.
|
// At the beginning of your end step, if you control a creature with power 4 or greater, exile the top card of your library.
|
||||||
// You may play that card until you exile another card with Furious Rise.
|
// You may play that card until you exile another card with Furious Rise.
|
||||||
this.addAbility(new BeginningOfEndStepTriggeredAbility(new FuriousRiseEffect())
|
this.addAbility(new BeginningOfEndStepTriggeredAbility(new ExileTopCardPlayUntilExileAnotherEffect())
|
||||||
.withInterveningIf(FerociousCondition.instance).addHint(FerociousHint.instance));
|
.withInterveningIf(FerociousCondition.instance).addHint(FerociousHint.instance));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -47,88 +33,3 @@ public final class FuriousRise extends CardImpl {
|
||||||
return new FuriousRise(this);
|
return new FuriousRise(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class FuriousRiseEffect extends OneShotEffect {
|
|
||||||
|
|
||||||
FuriousRiseEffect() {
|
|
||||||
super(Outcome.Benefit);
|
|
||||||
this.staticText = "exile the top card of your library. You may play that card until you exile another card with {this}";
|
|
||||||
}
|
|
||||||
|
|
||||||
private FuriousRiseEffect(final FuriousRiseEffect effect) {
|
|
||||||
super(effect);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public FuriousRiseEffect copy() {
|
|
||||||
return new FuriousRiseEffect(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean apply(Game game, Ability source) {
|
|
||||||
Player controller = game.getPlayer(source.getControllerId());
|
|
||||||
MageObject mageObject = source.getSourceObject(game);
|
|
||||||
if (controller != null && mageObject != null) {
|
|
||||||
Card cardToExile = controller.getLibrary().getFromTop(game);
|
|
||||||
|
|
||||||
UUID exileId = CardUtil.getCardExileZoneId(game, source);
|
|
||||||
controller.moveCardsToExile(cardToExile, source, game, true, exileId, mageObject.getIdName() + " (" + source.getStackMomentSourceZCC() + ")");
|
|
||||||
Card cardToPlay = game.getCard(cardToExile.getId());
|
|
||||||
|
|
||||||
endPreviousEffect(game, source); // workaround for Furious Rise
|
|
||||||
|
|
||||||
ContinuousEffect effect = new FuriousRisePlayEffect();
|
|
||||||
effect.setTargetPointer(new FixedTarget(cardToPlay, game));
|
|
||||||
game.addEffect(effect, source);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static boolean endPreviousEffect(Game game, Ability source) {
|
|
||||||
for (AsThoughEffect effect : game.getContinuousEffects().getApplicableAsThoughEffects(AsThoughEffectType.PLAY_FROM_NOT_OWN_HAND_ZONE, game)) {
|
|
||||||
if (effect instanceof FuriousRisePlayEffect) {
|
|
||||||
for (Ability ability : game.getContinuousEffects().getAsThoughEffectsAbility(effect)) {
|
|
||||||
if (ability.getSourceId().equals(source.getSourceId())
|
|
||||||
&& source.getStackMomentSourceZCC() == ability.getStackMomentSourceZCC()) {
|
|
||||||
effect.discard();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class FuriousRisePlayEffect extends AsThoughEffectImpl {
|
|
||||||
|
|
||||||
FuriousRisePlayEffect() {
|
|
||||||
super(AsThoughEffectType.PLAY_FROM_NOT_OWN_HAND_ZONE, Duration.Custom, Outcome.Benefit);
|
|
||||||
}
|
|
||||||
|
|
||||||
private FuriousRisePlayEffect(final FuriousRisePlayEffect effect) {
|
|
||||||
super(effect);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean apply(Game game, Ability source) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public FuriousRisePlayEffect copy() {
|
|
||||||
return new FuriousRisePlayEffect(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) {
|
|
||||||
List<UUID> targets = getTargetPointer().getTargets(game, source);
|
|
||||||
if (targets.isEmpty()) {
|
|
||||||
this.discard();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return targets.contains(objectId)
|
|
||||||
&& affectedControllerId.equals(source.getControllerId());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -6,25 +6,16 @@ import mage.abilities.common.SimpleActivatedAbility;
|
||||||
import mage.abilities.common.SpellCastControllerTriggeredAbility;
|
import mage.abilities.common.SpellCastControllerTriggeredAbility;
|
||||||
import mage.abilities.costs.common.PayEnergyCost;
|
import mage.abilities.costs.common.PayEnergyCost;
|
||||||
import mage.abilities.costs.common.TapSourceCost;
|
import mage.abilities.costs.common.TapSourceCost;
|
||||||
import mage.abilities.effects.AsThoughEffectImpl;
|
|
||||||
import mage.abilities.effects.ContinuousEffect;
|
|
||||||
import mage.abilities.effects.OneShotEffect;
|
|
||||||
import mage.abilities.effects.common.DamagePlayersEffect;
|
import mage.abilities.effects.common.DamagePlayersEffect;
|
||||||
|
import mage.abilities.effects.common.ExileTopCardPlayUntilExileAnotherEffect;
|
||||||
import mage.abilities.effects.common.counter.GetEnergyCountersControllerEffect;
|
import mage.abilities.effects.common.counter.GetEnergyCountersControllerEffect;
|
||||||
import mage.cards.Card;
|
|
||||||
import mage.cards.CardImpl;
|
import mage.cards.CardImpl;
|
||||||
import mage.cards.CardSetInfo;
|
import mage.cards.CardSetInfo;
|
||||||
import mage.constants.*;
|
import mage.constants.*;
|
||||||
import mage.filter.FilterSpell;
|
import mage.filter.FilterSpell;
|
||||||
import mage.filter.predicate.Predicates;
|
import mage.filter.predicate.Predicates;
|
||||||
import mage.filter.predicate.card.CastFromZonePredicate;
|
import mage.filter.predicate.card.CastFromZonePredicate;
|
||||||
import mage.game.ExileZone;
|
|
||||||
import mage.game.Game;
|
|
||||||
import mage.players.Player;
|
|
||||||
import mage.target.targetpointer.FixedTarget;
|
|
||||||
import mage.util.CardUtil;
|
|
||||||
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -52,7 +43,7 @@ public final class UnstableAmulet extends CardImpl {
|
||||||
|
|
||||||
// {T}, Pay {E}{E}: Exile the top card of your library. You may play it until you exile another card with Unstable Amulet.
|
// {T}, Pay {E}{E}: Exile the top card of your library. You may play it until you exile another card with Unstable Amulet.
|
||||||
Ability ability = new SimpleActivatedAbility(
|
Ability ability = new SimpleActivatedAbility(
|
||||||
new UnstableAmuletEffect(),
|
new ExileTopCardPlayUntilExileAnotherEffect("it"),
|
||||||
new TapSourceCost()
|
new TapSourceCost()
|
||||||
);
|
);
|
||||||
ability.addCost(new PayEnergyCost(2));
|
ability.addCost(new PayEnergyCost(2));
|
||||||
|
|
@ -67,104 +58,4 @@ public final class UnstableAmulet extends CardImpl {
|
||||||
public UnstableAmulet copy() {
|
public UnstableAmulet copy() {
|
||||||
return new UnstableAmulet(this);
|
return new UnstableAmulet(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class UnstableAmuletEffect extends OneShotEffect {
|
|
||||||
|
|
||||||
UnstableAmuletEffect() {
|
|
||||||
super(Outcome.DrawCard);
|
|
||||||
staticText = "Exile the top card of your library. You may play it until you exile another card with {this}.";
|
|
||||||
}
|
|
||||||
|
|
||||||
private UnstableAmuletEffect(final UnstableAmuletEffect effect) {
|
|
||||||
super(effect);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public UnstableAmuletEffect copy() {
|
|
||||||
return new UnstableAmuletEffect(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean apply(Game game, Ability source) {
|
|
||||||
Player controller = game.getPlayer(source.getControllerId());
|
|
||||||
if (controller == null || !controller.getLibrary().hasCards()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
Card card = controller.getLibrary().getFromTop(game);
|
|
||||||
if (card == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
UUID exileId = CardUtil.getExileZoneId(game, source);
|
|
||||||
String exileName = CardUtil.getSourceIdName(game, source);
|
|
||||||
controller.moveCardsToExile(card, source, game, true, exileId, exileName);
|
|
||||||
game.processAction();
|
|
||||||
if (!Zone.EXILED.equals(game.getState().getZone(card.getId()))) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
// Allow the card to be played until it leaves that exile zone.
|
|
||||||
ContinuousEffect effect = new UnstableAmuletPlayEffect(exileId);
|
|
||||||
effect.setTargetPointer(new FixedTarget(card.getMainCard(), game));
|
|
||||||
game.addEffect(effect, source);
|
|
||||||
// Clean the exile Zone from other cards, that can no longer be played.
|
|
||||||
ExileZone exileZone = game.getExile().getExileZone(exileId);
|
|
||||||
if (exileZone == null) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
Set<Card> inExileZone = exileZone.getCards(game);
|
|
||||||
for (Card cardInExile : inExileZone) {
|
|
||||||
if (cardInExile.getMainCard().getId().equals(card.getMainCard().getId())) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
game.getExile().moveToMainExileZone(cardInExile, game);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class UnstableAmuletPlayEffect extends AsThoughEffectImpl {
|
|
||||||
|
|
||||||
// The exile zone the card should be in for the effect to work.
|
|
||||||
private final UUID exileId;
|
|
||||||
|
|
||||||
UnstableAmuletPlayEffect(UUID exileId) {
|
|
||||||
super(AsThoughEffectType.PLAY_FROM_NOT_OWN_HAND_ZONE, Duration.Custom, Outcome.Benefit);
|
|
||||||
this.exileId = exileId;
|
|
||||||
}
|
|
||||||
|
|
||||||
private UnstableAmuletPlayEffect(final UnstableAmuletPlayEffect effect) {
|
|
||||||
super(effect);
|
|
||||||
this.exileId = effect.exileId;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public UnstableAmuletPlayEffect copy() {
|
|
||||||
return new UnstableAmuletPlayEffect(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean apply(Game game, Ability source) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) {
|
|
||||||
Card mainTargetCard = game.getCard(getTargetPointer().getFirst(game, source));
|
|
||||||
if (mainTargetCard == null) {
|
|
||||||
this.discard();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
ExileZone exileZone = game.getExile().getExileZone(exileId);
|
|
||||||
if (exileZone == null || !exileZone.contains(mainTargetCard.getId())) {
|
|
||||||
// Clean the Continuous effect if the target card is no longer in the exile zone
|
|
||||||
this.discard();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
Card objectCard = game.getCard(objectId);
|
|
||||||
if (objectCard == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return mainTargetCard.getId().equals(objectCard.getMainCard().getId()) // using main card to work with split/mdfc/adventures
|
|
||||||
&& affectedControllerId.equals(source.getControllerId());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -0,0 +1,147 @@
|
||||||
|
package mage.abilities.effects.common;
|
||||||
|
|
||||||
|
import mage.abilities.Ability;
|
||||||
|
import mage.abilities.effects.AsThoughEffectImpl;
|
||||||
|
import mage.abilities.effects.ContinuousEffect;
|
||||||
|
import mage.abilities.effects.OneShotEffect;
|
||||||
|
import mage.cards.Card;
|
||||||
|
import mage.constants.AsThoughEffectType;
|
||||||
|
import mage.constants.Duration;
|
||||||
|
import mage.constants.Outcome;
|
||||||
|
import mage.constants.Zone;
|
||||||
|
import mage.game.ExileZone;
|
||||||
|
import mage.game.Game;
|
||||||
|
import mage.players.Player;
|
||||||
|
import mage.target.targetpointer.FixedTarget;
|
||||||
|
import mage.util.CardUtil;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Susucr
|
||||||
|
*/
|
||||||
|
public class ExileTopCardPlayUntilExileAnotherEffect extends OneShotEffect {
|
||||||
|
|
||||||
|
|
||||||
|
public ExileTopCardPlayUntilExileAnotherEffect() {
|
||||||
|
this(false, "that card");
|
||||||
|
}
|
||||||
|
|
||||||
|
public ExileTopCardPlayUntilExileAnotherEffect(boolean withInterveningIf) {
|
||||||
|
this(withInterveningIf, "that card");
|
||||||
|
}
|
||||||
|
|
||||||
|
public ExileTopCardPlayUntilExileAnotherEffect(String cardDescriptor) {
|
||||||
|
this(false, cardDescriptor);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ExileTopCardPlayUntilExileAnotherEffect(boolean withInterveningIf, String cardDescriptor) {
|
||||||
|
super(Outcome.DrawCard);
|
||||||
|
staticText = makeText(withInterveningIf, cardDescriptor);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private ExileTopCardPlayUntilExileAnotherEffect(final ExileTopCardPlayUntilExileAnotherEffect effect) {
|
||||||
|
super(effect);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public OneShotEffect copy() {
|
||||||
|
return new ExileTopCardPlayUntilExileAnotherEffect();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean apply(Game game, Ability source) {
|
||||||
|
Player controller = game.getPlayer(source.getControllerId());
|
||||||
|
if (controller == null || !controller.getLibrary().hasCards()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
Card card = controller.getLibrary().getFromTop(game);
|
||||||
|
if (card == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
UUID exileId = CardUtil.getExileZoneId(game, source);
|
||||||
|
String exileName = CardUtil.getSourceIdName(game, source);
|
||||||
|
controller.moveCardsToExile(card, source, game, true, exileId, exileName);
|
||||||
|
game.processAction();
|
||||||
|
if (!Zone.EXILED.equals(game.getState().getZone(card.getId()))) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// Allow the card to be played until it leaves that exile zone.
|
||||||
|
ContinuousEffect effect = new ExileTopCardPlayEffect(exileId);
|
||||||
|
effect.setTargetPointer(new FixedTarget(card.getMainCard(), game));
|
||||||
|
game.addEffect(effect, source);
|
||||||
|
// Clean the exile Zone from other cards, that can no longer be played.
|
||||||
|
ExileZone exileZone = game.getExile().getExileZone(exileId);
|
||||||
|
if (exileZone == null) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
Set<Card> inExileZone = exileZone.getCards(game);
|
||||||
|
for (Card cardInExile : inExileZone) {
|
||||||
|
if (cardInExile.getMainCard().getId().equals(card.getMainCard().getId())) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
game.getExile().moveToMainExileZone(cardInExile, game);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String makeText(boolean withInterveningIf, String cardDescriptor) {
|
||||||
|
StringBuilder sb = new StringBuilder("exile the top card of your library. ");
|
||||||
|
if (withInterveningIf) {
|
||||||
|
sb.append("If you do, you may play ");
|
||||||
|
} else {
|
||||||
|
sb.append("You may play ");
|
||||||
|
}
|
||||||
|
sb.append(cardDescriptor);
|
||||||
|
sb.append(" until you exile another card with {this}.");
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class ExileTopCardPlayEffect extends AsThoughEffectImpl {
|
||||||
|
|
||||||
|
private final UUID exileId;
|
||||||
|
|
||||||
|
ExileTopCardPlayEffect(UUID exileId) {
|
||||||
|
super(AsThoughEffectType.PLAY_FROM_NOT_OWN_HAND_ZONE, Duration.Custom, Outcome.Benefit);
|
||||||
|
this.exileId = exileId;
|
||||||
|
}
|
||||||
|
|
||||||
|
private ExileTopCardPlayEffect(final ExileTopCardPlayEffect effect) {
|
||||||
|
super(effect);
|
||||||
|
this.exileId = effect.exileId;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ExileTopCardPlayEffect copy() {
|
||||||
|
return new ExileTopCardPlayEffect(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean apply(Game game, Ability source) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean applies(UUID sourceId, Ability source, UUID affectedControllerId, Game game) {
|
||||||
|
Card mainTargetCard = game.getCard(getTargetPointer().getFirst(game, source));
|
||||||
|
if (mainTargetCard == null) {
|
||||||
|
this.discard();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
ExileZone exileZone = game.getExile().getExileZone(exileId);
|
||||||
|
if (exileZone == null || !exileZone.contains(mainTargetCard.getId())) {
|
||||||
|
// Clean the Continuous effect if the target card is no longer in the exile zone
|
||||||
|
this.discard();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
Card objectCard = game.getCard(sourceId);
|
||||||
|
if (objectCard == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return mainTargetCard.getId().equals(objectCard.getMainCard().getId()) // using main card to work with split/mdfc/adventures
|
||||||
|
&& affectedControllerId.equals(source.getControllerId());
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue