- [KHM] Added Cosmos Charger and Dream Devourer. Refactored ForetellAbility to work with Dream Devourer. Text fixes are required in some cases. Ignored a test for foretell.

This commit is contained in:
jeffwadsworth 2021-01-29 20:35:35 -06:00
parent d5822a7246
commit bc25c3d60a
7 changed files with 387 additions and 66 deletions

View file

@ -0,0 +1,70 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package mage.abilities.common;
import mage.abilities.Ability;
import mage.abilities.SpecialAction;
import mage.abilities.TriggeredAbilityImpl;
import mage.abilities.effects.Effect;
import mage.cards.Card;
import mage.constants.Zone;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.players.Player;
/**
*
* @author jeffwadsworth
*/
public class ForetellSourceControllerTriggeredAbility extends TriggeredAbilityImpl {
public ForetellSourceControllerTriggeredAbility(Effect effect) {
super(Zone.BATTLEFIELD, effect, false);
}
public ForetellSourceControllerTriggeredAbility(final ForetellSourceControllerTriggeredAbility ability) {
super(ability);
}
@Override
public boolean checkEventType(GameEvent event, Game game) {
return event.getType() == GameEvent.EventType.TAKEN_SPECIAL_ACTION;
}
@Override
public boolean checkTrigger(GameEvent event, Game game) {
//UUID specialAction = event.getTargetId();
Card card = game.getCard(event.getSourceId());
Player player = game.getPlayer(event.getPlayerId());
for (Ability a : card.getAbilities()) {
if (player.getId() == controllerId
&& (a instanceof SpecialAction)
&& a.getRule().endsWith("and exile this card from your hand face down. Cast it on a later turn for its foretell cost.)</i>")) {
return true;
}
}
// if the ability is added to cards via effect
for (Ability a : game.getState().getAllOtherAbilities(card.getId())) {
if (player.getId() == controllerId
&& (a instanceof SpecialAction)
&& a.getRule().endsWith("and exile this card from your hand face down. Cast it on a later turn for its foretell cost.)</i>")) {
return true;
}
}
return false;
}
@Override
public String getRule() {
return "Whenever you foretell a card, " + super.getRule();
}
@Override
public ForetellSourceControllerTriggeredAbility copy() {
return new ForetellSourceControllerTriggeredAbility(this);
}
}

View file

@ -2,6 +2,7 @@ package mage.abilities.keyword;
import java.util.UUID;
import mage.MageObject;
import mage.MageObjectReference;
import mage.abilities.Ability;
import mage.abilities.SpecialAction;
import mage.abilities.SpellAbility;
@ -11,6 +12,7 @@ import mage.abilities.costs.Costs;
import mage.abilities.costs.mana.GenericManaCost;
import mage.abilities.costs.mana.ManaCostsImpl;
import mage.abilities.effects.AsThoughEffectImpl;
import mage.abilities.effects.ContinuousEffectImpl;
import mage.abilities.effects.Effect;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.ExileTargetEffect;
@ -19,9 +21,11 @@ import mage.cards.ModalDoubleFacesCard;
import mage.cards.SplitCard;
import mage.constants.AsThoughEffectType;
import mage.constants.Duration;
import mage.constants.Layer;
import mage.constants.Outcome;
import mage.constants.SpellAbilityCastMode;
import mage.constants.SpellAbilityType;
import mage.constants.SubLayer;
import mage.constants.Zone;
import mage.game.ExileZone;
import mage.game.Game;
@ -44,13 +48,11 @@ public class ForetellAbility extends SpecialAction {
this.card = card;
this.usesStack = Boolean.FALSE;
this.addCost(new GenericManaCost(2));
// exile the card
this.addEffect(new ForetellExileEffect(card));
// foretell cost from exile : it can't be any other cost
addSubAbility(new ForetellCostAbility(foretellCost));
// exile the card and it can't be cast the turn it was foretold
this.addEffect(new ForetellExileEffect(card, foretellCost));
// look at face-down card anytime
addSubAbility(new SimpleStaticAbility(Zone.ALL, new ForetellLookAtCardEffect()));
this.setRuleVisible(false);
this.setRuleVisible(true);
this.addWatcher(new ForetoldWatcher());
}
@ -68,13 +70,69 @@ public class ForetellAbility extends SpecialAction {
@Override
public ActivationStatus canActivate(UUID playerId, Game game) {
// activate only during the controller's turn
if (!game.isActivePlayer(this.getControllerId())) {
if (game.getState().getContinuousEffects().getApplicableAsThoughEffects(AsThoughEffectType.ALLOW_FORETELL_ANYTIME, game).isEmpty()
&& !game.isActivePlayer(this.getControllerId())) {
return ActivationStatus.getFalse();
}
return super.canActivate(playerId, game);
}
}
class ForetellExileEffect extends OneShotEffect {
private Card card;
String foretellCost;
public ForetellExileEffect(Card card, String foretellCost) {
super(Outcome.Neutral);
this.card = card;
this.foretellCost = foretellCost;
StringBuilder sbRule = new StringBuilder("Foretell");
sbRule.append("&mdash;");
sbRule.append(foretellCost);
sbRule.append(" <i>(During your turn, you may pay {2} and exile this card from your hand face down. Cast it on a later turn for its foretell cost.)</i>");
staticText = sbRule.toString();
}
public ForetellExileEffect(final ForetellExileEffect effect) {
super(effect);
this.card = effect.card;
this.foretellCost = effect.foretellCost;
}
@Override
public ForetellExileEffect copy() {
return new ForetellExileEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null
&& card != null) {
// retrieve the exileId of the foretold card
UUID exileId = CardUtil.getExileZoneId(card.getId().toString() + "foretellAbility", game);
// foretell turn number shows up on exile window
Effect effect = new ExileTargetEffect(exileId, " Foretell Turn Number: " + game.getTurnNum());
// remember turn number it was cast
game.getState().setValue(card.getId().toString() + "Foretell Turn Number", game.getTurnNum());
// remember the foretell cost
game.getState().setValue(card.getId().toString() + "Foretell Cost", foretellCost);
// exile the card face-down
effect.setTargetPointer(new FixedTarget(card.getId()));
effect.apply(game, source);
card.setFaceDown(true, game);
game.addEffect(new ForetellAddCostEffect(new MageObjectReference(card, game)), source);
return true;
}
return false;
}
}
class ForetellLookAtCardEffect extends AsThoughEffectImpl {
public ForetellLookAtCardEffect() {
@ -115,42 +173,41 @@ class ForetellLookAtCardEffect extends AsThoughEffectImpl {
}
}
class ForetellExileEffect extends OneShotEffect {
// this needed to be a continuousEffect for a card like Dream Devourer...unless someone has a better idea
class ForetellAddCostEffect extends ContinuousEffectImpl {
private Card card;
private final MageObjectReference mor;
public ForetellExileEffect(Card card) {
super(Outcome.Neutral);
this.card = card;
staticText = "Foretold this card";
public ForetellAddCostEffect(MageObjectReference mor) {
super(Duration.EndOfGame, Layer.AbilityAddingRemovingEffects_6, SubLayer.NA, Outcome.AddAbility);
this.mor = mor;
staticText = "Foretold card";
}
public ForetellExileEffect(final ForetellExileEffect effect) {
public ForetellAddCostEffect(final ForetellAddCostEffect effect) {
super(effect);
this.card = effect.card;
}
@Override
public ForetellExileEffect copy() {
return new ForetellExileEffect(this);
this.mor = effect.mor;
}
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null
&& card != null) {
UUID exileId = CardUtil.getExileZoneId(card.getId().toString() + "foretellAbility", game);
// foretell turn number shows up on exile window
Effect effect = new ExileTargetEffect(exileId, " Foretell Turn Number: " + game.getTurnNum());
// remember turn number it was cast
game.getState().setValue(card.getId().toString() + "Foretell Turn Number", game.getTurnNum());
effect.setTargetPointer(new FixedTarget(card.getId()));
effect.apply(game, source);
card.setFaceDown(true, game);
return true;
Card card = mor.getCard(game);
if (card != null
&& game.getState().getZone(card.getId()) == Zone.EXILED) {
String foretellCost = (String) game.getState().getValue(card.getId().toString() + "Foretell Cost");
Ability ability = new ForetellCostAbility(foretellCost);
ability.setSourceId(card.getId());
ability.setControllerId(source.getControllerId());
game.getState().addOtherAbility(card, ability);
} else {
discard();
}
return false;
return true;
}
@Override
public ForetellAddCostEffect copy() {
return new ForetellAddCostEffect(this);
}
}
@ -160,7 +217,7 @@ class ForetellCostAbility extends SpellAbility {
private SpellAbility spellAbilityToResolve;
public ForetellCostAbility(String foretellCost) {
super(null, "Foretell", Zone.EXILED, SpellAbilityType.BASE_ALTERNATE, SpellAbilityCastMode.NORMAL);
super(null, "Testing", Zone.EXILED, SpellAbilityType.BASE_ALTERNATE, SpellAbilityCastMode.NORMAL);
this.setAdditionalCostsRuleVisible(false);
this.name = "Foretell " + foretellCost;
this.addCost(new ManaCostsImpl(foretellCost));
@ -268,33 +325,7 @@ class ForetellCostAbility extends SpellAbility {
@Override
public String getRule(boolean all) {
return this.getRule();
}
@Override
public String getRule() {
StringBuilder sbRule = new StringBuilder("Foretell");
if (!costs.isEmpty()) {
sbRule.append("&mdash;");
} else {
sbRule.append(' ');
}
if (!manaCosts.isEmpty()) {
sbRule.append(manaCosts.getText());
}
if (!costs.isEmpty()) {
if (!manaCosts.isEmpty()) {
sbRule.append(", ");
}
sbRule.append(costs.getText());
sbRule.append('.');
}
if (abilityName != null) {
sbRule.append(' ');
sbRule.append(abilityName);
}
sbRule.append(" <i>(During your turn, you may pay {2} and exile this card from your hand face down. Cast it on a later turn for its foretell cost.)</i>");
return sbRule.toString();
return "";
}
/**

View file

@ -18,7 +18,6 @@ public enum AsThoughEffectType {
BLOCK_FORESTWALK,
DAMAGE_NOT_BLOCKED,
BE_BLOCKED,
// PLAY_FROM_NOT_OWN_HAND_ZONE + CAST_AS_INSTANT:
// 1. Do not use dialogs in "applies" method for that type of effect (it calls multiple times and will freeze the game)
// 2. All effects in "applies" must checks affectedControllerId.equals(source.getControllerId()) (if not then all players will be able to play it)
@ -26,23 +25,22 @@ public enum AsThoughEffectType {
// TODO: search all PLAY_FROM_NOT_OWN_HAND_ZONE and CAST_AS_INSTANT effects and add support of mainCard and objectId
PLAY_FROM_NOT_OWN_HAND_ZONE(true),
CAST_AS_INSTANT(true),
ACTIVATE_AS_INSTANT,
DAMAGE,
SHROUD,
HEXPROOF,
PAY_0_ECHO,
LOOK_AT_FACE_DOWN,
// SPEND_OTHER_MANA:
// 1. It's uses for mana calcs at any zone, not stack only
// 2. Compare zone change counter as "objectZCC <= targetZCC + 1"
// 3. Compare zone with original (like exiled) and stack, not stack only
// TODO: search all SPEND_ONLY_MANA effects and improve counters compare as SPEND_OTHER_MANA
SPEND_OTHER_MANA,
SPEND_ONLY_MANA,
TARGET;
TARGET,
// Cosmos Charger effect
ALLOW_FORETELL_ANYTIME;
private final boolean needPlayCardAbility; // mark effect type as compatible with play/cast abilities