mirror of
https://github.com/magefree/mage.git
synced 2025-12-27 22:12:03 -08:00
[OTJ] Implement Tinybones, the Pickpocket + refactor MayCastTargetThenExileEffect (#12040)
This commit is contained in:
parent
3e75f93c20
commit
d1de8b8cd3
26 changed files with 412 additions and 150 deletions
|
|
@ -0,0 +1,158 @@
|
|||
package mage.abilities.effects.common;
|
||||
|
||||
import mage.ApprovingObject;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.Mode;
|
||||
import mage.abilities.effects.ContinuousEffect;
|
||||
import mage.abilities.effects.OneShotEffect;
|
||||
import mage.abilities.effects.common.asthought.YouMaySpendManaAsAnyColorToCastTargetEffect;
|
||||
import mage.abilities.effects.common.replacement.ThatSpellGraveyardExileReplacementEffect;
|
||||
import mage.cards.Card;
|
||||
import mage.constants.CastManaAdjustment;
|
||||
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;
|
||||
|
||||
/**
|
||||
* @author xenohedron, Susucr
|
||||
*/
|
||||
public class MayCastTargetCardEffect extends OneShotEffect {
|
||||
|
||||
private final Duration duration;
|
||||
|
||||
private final CastManaAdjustment manaAdjustment;
|
||||
|
||||
private final boolean thenExile; // Should the spell be exiled by a replacement effect if cast and it resolves?
|
||||
|
||||
/**
|
||||
* Allows to cast the target card immediately, for its manacost.
|
||||
*/
|
||||
public MayCastTargetCardEffect(boolean exileOnResolve) {
|
||||
this(CastManaAdjustment.NONE, exileOnResolve);
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows to cast the target card immediately, either for its cost or with a modifier (like for free, or mana as any type).
|
||||
*/
|
||||
public MayCastTargetCardEffect(CastManaAdjustment manaAdjustment, boolean exileOnResolve) {
|
||||
this(Duration.OneUse, manaAdjustment, exileOnResolve);
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes the target card playable for the specified duration as long as it remains in that zone.
|
||||
*/
|
||||
public MayCastTargetCardEffect(Duration duration, boolean exileOnResolve) {
|
||||
this(duration, CastManaAdjustment.NONE, exileOnResolve);
|
||||
}
|
||||
|
||||
protected MayCastTargetCardEffect(Duration duration, CastManaAdjustment manaAdjustment, boolean thenExile) {
|
||||
super(Outcome.Benefit);
|
||||
this.duration = duration;
|
||||
this.manaAdjustment = manaAdjustment;
|
||||
this.thenExile = thenExile;
|
||||
|
||||
// TODO: support the non-yet-supported combinations.
|
||||
// for now the constructor chains won't allow those.
|
||||
if (duration != Duration.OneUse && manaAdjustment != CastManaAdjustment.NONE) {
|
||||
throw new IllegalStateException(
|
||||
"Wrong code usage, not yet supported "
|
||||
+ "duration={" + duration.name() + "}, "
|
||||
+ "manaAdjustment={" + manaAdjustment.name() + "}"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
protected MayCastTargetCardEffect(final MayCastTargetCardEffect effect) {
|
||||
super(effect);
|
||||
this.duration = effect.duration;
|
||||
this.manaAdjustment = effect.manaAdjustment;
|
||||
this.thenExile = effect.thenExile;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MayCastTargetCardEffect copy() {
|
||||
return new MayCastTargetCardEffect(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Card card = game.getCard(getTargetPointer().getFirst(game, source));
|
||||
if (card == null) {
|
||||
return false;
|
||||
}
|
||||
if (duration == Duration.OneUse) {
|
||||
Player controller = game.getPlayer(source.getControllerId());
|
||||
if (controller == null || !controller.chooseUse(outcome, "Cast " + card.getLogName() + '?', source, game)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (manaAdjustment) {
|
||||
case NONE:
|
||||
case WITHOUT_PAYING_MANA_COST:
|
||||
break;
|
||||
case AS_THOUGH_ANY_MANA_COLOR:
|
||||
case AS_THOUGH_ANY_MANA_TYPE:
|
||||
// TODO: untangle why there is a confusion between the two.
|
||||
ContinuousEffect effect =
|
||||
new YouMaySpendManaAsAnyColorToCastTargetEffect(Duration.Custom, controller.getId(), null);
|
||||
effect.setTargetPointer(new FixedTarget(card, game));
|
||||
game.addEffect(effect, source);
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException("Wrong code usage, manaAdjustment is not yet supported: " + manaAdjustment);
|
||||
}
|
||||
|
||||
game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), Boolean.TRUE);
|
||||
boolean noMana = manaAdjustment == CastManaAdjustment.WITHOUT_PAYING_MANA_COST;
|
||||
controller.cast(controller.chooseAbilityForCast(card, game, noMana),
|
||||
game, noMana, new ApprovingObject(source, game));
|
||||
game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), null);
|
||||
} else {
|
||||
// TODO: support (and add tests!) for the non-NONE manaAdjustment
|
||||
CardUtil.makeCardPlayable(game, source, card, duration, false);
|
||||
}
|
||||
if (thenExile) {
|
||||
ContinuousEffect effect = new ThatSpellGraveyardExileReplacementEffect(true);
|
||||
effect.setTargetPointer(new FixedTarget(card, game));
|
||||
game.addEffect(effect, source);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getText(Mode mode) {
|
||||
if (staticText != null && !staticText.isEmpty()) {
|
||||
return staticText;
|
||||
}
|
||||
String text = "you may cast " + getTargetPointer().describeTargets(mode.getTargets(), "it");
|
||||
if (duration == Duration.EndOfTurn) {
|
||||
text += " this turn";
|
||||
} else if (!duration.toString().isEmpty()) {
|
||||
text += duration.toString();
|
||||
}
|
||||
switch (manaAdjustment) {
|
||||
case NONE:
|
||||
break;
|
||||
case WITHOUT_PAYING_MANA_COST:
|
||||
text += " without paying its mana cost";
|
||||
break;
|
||||
case AS_THOUGH_ANY_MANA_COLOR:
|
||||
text += ", and mana of any color can be spent to cast that spell";
|
||||
break;
|
||||
case AS_THOUGH_ANY_MANA_TYPE:
|
||||
text += ", and mana of any type can be spent to cast that spell";
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException("Wrong code usage, manaAdjustment is not yet supported: " + manaAdjustment);
|
||||
}
|
||||
text += ".";
|
||||
if (thenExile) {
|
||||
text += " " + ThatSpellGraveyardExileReplacementEffect.RULE_YOUR;
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,98 +0,0 @@
|
|||
package mage.abilities.effects.common;
|
||||
|
||||
import mage.ApprovingObject;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.Mode;
|
||||
import mage.abilities.effects.ContinuousEffect;
|
||||
import mage.abilities.effects.OneShotEffect;
|
||||
import mage.abilities.effects.common.replacement.ThatSpellGraveyardExileReplacementEffect;
|
||||
import mage.cards.Card;
|
||||
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;
|
||||
|
||||
/**
|
||||
* @author xenohedron
|
||||
*/
|
||||
public class MayCastTargetThenExileEffect extends OneShotEffect {
|
||||
|
||||
private final Duration duration;
|
||||
private final boolean noMana;
|
||||
|
||||
/**
|
||||
* Allows to cast the target card immediately, either for its cost or for free.
|
||||
* If resulting spell would be put into graveyard, exiles it instead.
|
||||
*/
|
||||
public MayCastTargetThenExileEffect(boolean noMana) {
|
||||
super(Outcome.Benefit);
|
||||
this.duration = Duration.OneUse;
|
||||
this.noMana = noMana;
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes the target card playable for the specified duration as long as it remains in that zone.
|
||||
* If resulting spell would be put into graveyard, exiles it instead.
|
||||
*/
|
||||
public MayCastTargetThenExileEffect(Duration duration) {
|
||||
super(Outcome.Benefit);
|
||||
this.duration = duration;
|
||||
this.noMana = false;
|
||||
}
|
||||
|
||||
protected MayCastTargetThenExileEffect(final MayCastTargetThenExileEffect effect) {
|
||||
super(effect);
|
||||
this.duration = effect.duration;
|
||||
this.noMana = effect.noMana;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MayCastTargetThenExileEffect copy() {
|
||||
return new MayCastTargetThenExileEffect(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Card card = game.getCard(getTargetPointer().getFirst(game, source));
|
||||
if (card == null) {
|
||||
return false;
|
||||
}
|
||||
FixedTarget fixedTarget = new FixedTarget(card, game);
|
||||
if (duration == Duration.OneUse) {
|
||||
Player controller = game.getPlayer(source.getControllerId());
|
||||
if (controller == null || !controller.chooseUse(outcome, "Cast " + card.getLogName() + '?', source, game)) {
|
||||
return false;
|
||||
}
|
||||
game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), Boolean.TRUE);
|
||||
controller.cast(controller.chooseAbilityForCast(card, game, noMana),
|
||||
game, noMana, new ApprovingObject(source, game));
|
||||
game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), null);
|
||||
} else {
|
||||
CardUtil.makeCardPlayable(game, source, card, duration, false);
|
||||
}
|
||||
ContinuousEffect effect = new ThatSpellGraveyardExileReplacementEffect(true);
|
||||
effect.setTargetPointer(fixedTarget);
|
||||
game.addEffect(effect, source);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getText(Mode mode) {
|
||||
if (staticText != null && !staticText.isEmpty()) {
|
||||
return staticText;
|
||||
}
|
||||
String text = "you may cast " + getTargetPointer().describeTargets(mode.getTargets(), "it");
|
||||
if (duration == Duration.EndOfTurn) {
|
||||
text += " this turn";
|
||||
} else if (!duration.toString().isEmpty()) {
|
||||
text += duration.toString();
|
||||
}
|
||||
if (noMana) {
|
||||
text += " without paying its mana cost";
|
||||
}
|
||||
return text + ". " + ThatSpellGraveyardExileReplacementEffect.RULE_YOUR;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -16,6 +16,7 @@ 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
|
||||
* TODO: AnyType and AnyColor are confused there.
|
||||
*
|
||||
* @author JayDi85
|
||||
*/
|
||||
|
|
|
|||
29
Mage/src/main/java/mage/constants/CastManaAdjustment.java
Normal file
29
Mage/src/main/java/mage/constants/CastManaAdjustment.java
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
package mage.constants;
|
||||
|
||||
/**
|
||||
* Groups together the most usual ways a card's payment is adjusted
|
||||
* by card effects that allow play or cast.
|
||||
* <p>
|
||||
* Effects should attempt to support those for all the various ways
|
||||
* to play/cast cards/spells in Effects
|
||||
*
|
||||
* @author Susucr
|
||||
*/
|
||||
public enum CastManaAdjustment {
|
||||
/**
|
||||
* No adjustment to play/cast
|
||||
*/
|
||||
NONE,
|
||||
/**
|
||||
* Mana can be used as any mana type to pay for the mana cost
|
||||
*/
|
||||
AS_THOUGH_ANY_MANA_TYPE,
|
||||
/**
|
||||
* Mana can be used as any mana color to pay for the mana cost
|
||||
*/
|
||||
AS_THOUGH_ANY_MANA_COLOR,
|
||||
/**
|
||||
* The card is play/cast without paying for its mana cost
|
||||
*/
|
||||
WITHOUT_PAYING_MANA_COST,
|
||||
}
|
||||
|
|
@ -1280,6 +1280,7 @@ public final class CardUtil {
|
|||
}
|
||||
}
|
||||
|
||||
// TODO: use CastManaAdjustment instead of boolean anyColor
|
||||
public static void makeCardPlayable(Game game, Ability source, Card card, Duration duration, boolean anyColor) {
|
||||
makeCardPlayable(game, source, card, duration, anyColor, null, null);
|
||||
}
|
||||
|
|
@ -1296,6 +1297,7 @@ public final class CardUtil {
|
|||
* @param anyColor
|
||||
* @param condition can be null
|
||||
*/
|
||||
// TODO: use CastManaAdjustment instead of boolean anyColor
|
||||
public static void makeCardPlayable(Game game, Ability source, Card card, Duration duration, boolean anyColor, UUID playerId, Condition condition) {
|
||||
// Effect can be used for cards in zones and permanents on battlefield
|
||||
// PermanentCard's ZCC is static, but we need updated ZCC from the card (after moved to another zone)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue