[KHM] foretell improves (related to bc25c3d60a):

* reverted code format of AsThoughEffectType;
 * fixed disabled test;
 * added test for Dream Devourer;
 * simplified some code;
This commit is contained in:
Oleg Agafonov 2021-01-30 11:21:51 +04:00
parent bc25c3d60a
commit df98cc3e62
5 changed files with 88 additions and 39 deletions

View file

@ -1,14 +1,8 @@
/*
* 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.abilities.keyword.ForetellAbility;
import mage.cards.Card;
import mage.constants.Zone;
import mage.game.Game;
@ -16,7 +10,6 @@ import mage.game.events.GameEvent;
import mage.players.Player;
/**
*
* @author jeffwadsworth
*/
public class ForetellSourceControllerTriggeredAbility extends TriggeredAbilityImpl {
@ -39,22 +32,15 @@ public class ForetellSourceControllerTriggeredAbility extends TriggeredAbilityIm
//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 (card == null || player == null) {
return false;
}
// 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;
}
if (!isControlledBy(player.getId())) {
return false;
}
return false;
return card.getAbilities(game).containsClass(ForetellAbility.class);
}
@Override

View file

@ -1,6 +1,5 @@
package mage.abilities.keyword;
import java.util.UUID;
import mage.MageObject;
import mage.MageObjectReference;
import mage.abilities.Ability;
@ -19,14 +18,7 @@ import mage.abilities.effects.common.ExileTargetEffect;
import mage.cards.Card;
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.constants.*;
import mage.game.ExileZone;
import mage.game.Game;
import mage.players.Player;
@ -34,13 +26,15 @@ import mage.target.targetpointer.FixedTarget;
import mage.util.CardUtil;
import mage.watchers.common.ForetoldWatcher;
import java.util.UUID;
/**
* @author jeffwadsworth
*/
public class ForetellAbility extends SpecialAction {
private String foretellCost;
private Card card;
private final String foretellCost;
private final Card card;
public ForetellAbility(Card card, String foretellCost) {
super(Zone.HAND);
@ -72,6 +66,7 @@ public class ForetellAbility extends SpecialAction {
// activate only during the controller's turn
if (game.getState().getContinuousEffects().getApplicableAsThoughEffects(AsThoughEffectType.ALLOW_FORETELL_ANYTIME, game).isEmpty()
&& !game.isActivePlayer(this.getControllerId())) {
// TODO: must be fixed to call super.canActivate here for additional checks someday
return ActivationStatus.getFalse();
}
return super.canActivate(playerId, game);
@ -80,7 +75,7 @@ public class ForetellAbility extends SpecialAction {
class ForetellExileEffect extends OneShotEffect {
private Card card;
private final Card card;
String foretellCost;
public ForetellExileEffect(Card card, String foretellCost) {

View file

@ -18,6 +18,7 @@ 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)
@ -25,21 +26,26 @@ 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,
// Cosmos Charger effect
// ALLOW_FORETELL_ANYTIME:
// For Cosmos Charger effect
ALLOW_FORETELL_ANYTIME;
private final boolean needPlayCardAbility; // mark effect type as compatible with play/cast abilities