mirror of
https://github.com/magefree/mage.git
synced 2025-12-26 21:42:07 -08:00
* Double faces and adventure cards: improved support with some "exile and cast" effects like Hostage Taker (#7446);
This commit is contained in:
parent
43014f7f5e
commit
e3db50f111
12 changed files with 201 additions and 190 deletions
|
|
@ -2,11 +2,13 @@ package mage.abilities.effects.common.asthought;
|
|||
|
||||
import mage.MageObjectReference;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.condition.Condition;
|
||||
import mage.abilities.effects.AsThoughEffectImpl;
|
||||
import mage.constants.AsThoughEffectType;
|
||||
import mage.constants.Duration;
|
||||
import mage.constants.Outcome;
|
||||
import mage.game.Game;
|
||||
import mage.util.CardUtil;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
|
|
@ -14,22 +16,31 @@ import java.util.UUID;
|
|||
* Play card from current zone. Will be discarded on any card movements or blinks.
|
||||
* <p>
|
||||
* Recommends to use combo effects from CardUtil.makeCardPlayableAndSpendManaAsAnyColor instead signle effect
|
||||
* <p>
|
||||
* Affected to all card's parts
|
||||
*
|
||||
* @author JayDi85
|
||||
*/
|
||||
public class CanPlayCardControllerEffect extends AsThoughEffectImpl {
|
||||
|
||||
protected final MageObjectReference mor;
|
||||
private final MageObjectReference mor;
|
||||
private final Condition condition;
|
||||
|
||||
public CanPlayCardControllerEffect(Game game, UUID cardId, int cardZCC, Duration duration) {
|
||||
this(game, cardId, cardZCC, duration, null);
|
||||
}
|
||||
|
||||
public CanPlayCardControllerEffect(Game game, UUID cardId, int cardZCC, Duration duration, Condition condition) {
|
||||
super(AsThoughEffectType.PLAY_FROM_NOT_OWN_HAND_ZONE, duration, Outcome.Benefit);
|
||||
this.staticText = "You may play those card";
|
||||
this.mor = new MageObjectReference(cardId, cardZCC, game);
|
||||
this.condition = condition;
|
||||
}
|
||||
|
||||
public CanPlayCardControllerEffect(final CanPlayCardControllerEffect effect) {
|
||||
super(effect);
|
||||
this.mor = effect.mor;
|
||||
this.condition = effect.condition;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -48,6 +59,12 @@ public class CanPlayCardControllerEffect extends AsThoughEffectImpl {
|
|||
discard();
|
||||
return false;
|
||||
}
|
||||
return mor.refersTo(sourceId, game) && source.isControlledBy(affectedControllerId);
|
||||
|
||||
if (condition != null && !condition.apply(game, source)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
UUID objectIdToCast = CardUtil.getMainCardId(game, sourceId); // affected to all card's parts
|
||||
return mor.refersTo(objectIdToCast, game) && source.isControlledBy(affectedControllerId);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
package mage.abilities.effects.common.asthought;
|
||||
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.condition.Condition;
|
||||
import mage.abilities.effects.AsThoughEffectImpl;
|
||||
import mage.abilities.effects.AsThoughManaEffect;
|
||||
import mage.constants.*;
|
||||
|
|
@ -15,17 +16,27 @@ import java.util.UUID;
|
|||
/**
|
||||
* Spend mana as any color to cast targeted card. Will not affected after any card movements or blinks.
|
||||
*
|
||||
* Affects to all card's parts
|
||||
*
|
||||
* @author JayDi85
|
||||
*/
|
||||
public class YouMaySpendManaAsAnyColorToCastTargetEffect extends AsThoughEffectImpl implements AsThoughManaEffect {
|
||||
|
||||
private final Condition condition;
|
||||
|
||||
public YouMaySpendManaAsAnyColorToCastTargetEffect(Duration duration) {
|
||||
this(duration, null);
|
||||
}
|
||||
|
||||
public YouMaySpendManaAsAnyColorToCastTargetEffect(Duration duration, Condition condition) {
|
||||
super(AsThoughEffectType.SPEND_OTHER_MANA, duration, Outcome.Benefit);
|
||||
this.staticText = "You may spend mana as though it were mana of any color to cast it";
|
||||
this.condition = condition;
|
||||
}
|
||||
|
||||
public YouMaySpendManaAsAnyColorToCastTargetEffect(final YouMaySpendManaAsAnyColorToCastTargetEffect effect) {
|
||||
super(effect);
|
||||
this.condition = effect.condition;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -40,10 +51,15 @@ public class YouMaySpendManaAsAnyColorToCastTargetEffect extends AsThoughEffectI
|
|||
|
||||
@Override
|
||||
public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) {
|
||||
if (condition != null && !condition.apply(game, source)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
objectId = CardUtil.getMainCardId(game, objectId); // for split cards
|
||||
FixedTarget fixedTarget = ((FixedTarget) getTargetPointer());
|
||||
UUID targetId = CardUtil.getMainCardId(game, fixedTarget.getTarget()); // Affects to all card's parts (example: Hostage Taker exile mdf card)
|
||||
return source.isControlledBy(affectedControllerId)
|
||||
&& Objects.equals(objectId, fixedTarget.getTarget())
|
||||
&& Objects.equals(objectId, targetId)
|
||||
&& game.getState().getZoneChangeCounter(objectId) <= fixedTarget.getZoneChangeCounter() + 1
|
||||
&& (game.getState().getZone(objectId) == Zone.STACK || game.getState().getZone(objectId) == Zone.EXILED);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import mage.cards.Card;
|
|||
import mage.cards.LevelerCard;
|
||||
import mage.game.Game;
|
||||
import mage.game.events.ZoneChangeEvent;
|
||||
import mage.util.CardUtil;
|
||||
|
||||
import javax.annotation.processing.SupportedSourceVersion;
|
||||
import javax.lang.model.SourceVersion;
|
||||
|
|
@ -22,10 +23,8 @@ import java.util.UUID;
|
|||
public class PermanentCard extends PermanentImpl {
|
||||
|
||||
protected int maxLevelCounters;
|
||||
// A copy of the origin card that was cast (this is not the original card, so it's possible to chnage some attribute to this blueprint to change attributes to the permanent if it enters the battlefield with e.g. a subtype)
|
||||
// A copy of the origin card that was cast (this is not the original card, so it's possible to change some attribute to this blueprint to change attributes to the permanent if it enters the battlefield with e.g. a subtype)
|
||||
protected Card card;
|
||||
// A copy of original card that was used for copy and create current permanent (used in copy effects and special commands like adjustTargets)
|
||||
protected Card copiedFromCard;
|
||||
// the number this permanent instance had
|
||||
protected int zoneChangeCounter;
|
||||
|
||||
|
|
@ -220,4 +219,8 @@ public class PermanentCard extends PermanentImpl {
|
|||
card.setZoneChangeCounter(value, game);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Card getMainCard() {
|
||||
return card.getMainCard();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package mage.game.permanent;
|
|||
import mage.MageObject;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.costs.mana.ManaCost;
|
||||
import mage.cards.Card;
|
||||
import mage.constants.EmptyNames;
|
||||
import mage.game.Game;
|
||||
import mage.game.permanent.token.Token;
|
||||
|
|
@ -118,4 +119,9 @@ public class PermanentToken extends PermanentImpl {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Card getMainCard() {
|
||||
// token don't have game card, so return itself
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ import mage.abilities.Abilities;
|
|||
import mage.abilities.Ability;
|
||||
import mage.abilities.Mode;
|
||||
import mage.abilities.SpellAbility;
|
||||
import mage.abilities.condition.Condition;
|
||||
import mage.abilities.costs.VariableCost;
|
||||
import mage.abilities.costs.mana.*;
|
||||
import mage.abilities.effects.ContinuousEffect;
|
||||
|
|
@ -1024,21 +1025,30 @@ public final class CardUtil {
|
|||
}
|
||||
}
|
||||
|
||||
public static void makeCardPlayableAndSpendManaAsAnyColor(Game game, Ability source, Card card, Duration duration) {
|
||||
makeCardPlayableAndSpendManaAsAnyColor(game, source, card, duration, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add effects to game that allows to play/cast card from current zone and spend mana as any type for it.
|
||||
* Effects will be discarded/ignored on any card movements or blinks (after ZCC change)
|
||||
*
|
||||
* Affected to all card's parts
|
||||
*
|
||||
* @param game
|
||||
* @param card
|
||||
* @param duration
|
||||
* @param condition can be null
|
||||
*/
|
||||
public static void makeCardPlayableAndSpendManaAsAnyColor(Game game, Ability source, Card card, Duration duration) {
|
||||
public static void makeCardPlayableAndSpendManaAsAnyColor(Game game, Ability source, Card card, Duration duration, Condition condition) {
|
||||
// Effect can be used for cards in zones and permanents on battlefield
|
||||
// So there is a workaround to get real ZCC (PermanentCard's ZCC is static, but it must be from Card's ZCC)
|
||||
// PermanentCard's ZCC is static, but we need updated ZCC from the card (after moved to another zone)
|
||||
// So there is a workaround to get actual card's ZCC
|
||||
// Example: Hostage Taker
|
||||
int zcc = game.getState().getZoneChangeCounter(card.getId());
|
||||
game.addEffect(new CanPlayCardControllerEffect(game, card.getId(), zcc, duration), source);
|
||||
game.addEffect(new YouMaySpendManaAsAnyColorToCastTargetEffect(duration).setTargetPointer(new FixedTarget(card.getId(), zcc)), source);
|
||||
UUID objectId = card.getMainCard().getId();
|
||||
int zcc = game.getState().getZoneChangeCounter(objectId);
|
||||
game.addEffect(new CanPlayCardControllerEffect(game, objectId, zcc, duration, condition), source);
|
||||
game.addEffect(new YouMaySpendManaAsAnyColorToCastTargetEffect(duration, condition).setTargetPointer(new FixedTarget(objectId, zcc)), source);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue