Characteristics check for spell cast filters

This commit is contained in:
Steven Knipe 2023-09-26 21:05:55 -07:00
parent 2e539243eb
commit 967b4a7fb3
6 changed files with 58 additions and 28 deletions

View file

@ -3,6 +3,7 @@ package mage.cards.c;
import mage.MageInt;
import mage.MageObjectReference;
import mage.abilities.Ability;
import mage.abilities.SpellAbility;
import mage.abilities.common.EntersBattlefieldAllTriggeredAbility;
import mage.abilities.common.LimitedTimesPerTurnActivatedAbility;
import mage.abilities.costs.common.DiscardCardCost;
@ -92,18 +93,21 @@ class ChainerNightmareAdeptContinuousEffect extends AsThoughEffectImpl {
}
@Override
public boolean applies(UUID sourceId, Ability source, UUID affectedControllerId, Game game) {
public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) {
throw new IllegalArgumentException("ERROR, can't call applies method on empty affectedAbility");
}
@Override
public boolean applies(UUID objectId, Ability affectedAbility, Ability source, Game game, UUID playerId) {
ChainerNightmareAdeptWatcher watcher = game.getState().getWatcher(ChainerNightmareAdeptWatcher.class);
if (watcher == null || !watcher.checkPermission(
affectedControllerId, source, game
) || game.getState().getZone(sourceId) != Zone.GRAVEYARD) {
playerId, source, game
) || game.getState().getZone(objectId) != Zone.GRAVEYARD) {
return false;
}
Card card = game.getCard(sourceId);
return card != null
&& card.getOwnerId().equals(affectedControllerId)
&& card.isCreature(game)
&& !card.isLand(game);
Card card = game.getCard(objectId);
return card != null && affectedAbility instanceof SpellAbility
&& card.getOwnerId().equals(playerId)
&& ((SpellAbility) affectedAbility).getCharacteristics(game).isCreature();
}
}

View file

@ -7,6 +7,7 @@ import mage.MageObject;
import mage.Mana;
import mage.abilities.Ability;
import mage.abilities.LoyaltyAbility;
import mage.abilities.SpellAbility;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.DamageTargetEffect;
import mage.abilities.effects.common.GetEmblemEffect;
@ -165,10 +166,10 @@ class ChandraDressedToKillPlayEffect extends PlayFromNotOwnHandZoneTargetEffect
@Override
public boolean applies(UUID objectId, Ability affectedAbility, Ability source, Game game, UUID playerId) {
if (!super.applies(objectId, affectedAbility, source, game, playerId)) {
if (!(super.applies(objectId, affectedAbility, source, game, playerId) && affectedAbility instanceof SpellAbility)) {
return false;
}
Card card = game.getCard(objectId);
Card card = ((SpellAbility) affectedAbility).getCharacteristics(game);
return card != null && card.getColor(game).isRed();
}
}

View file

@ -4,6 +4,7 @@ import mage.MageIdentifier;
import mage.MageInt;
import mage.MageObjectReference;
import mage.abilities.Ability;
import mage.abilities.SpellAbility;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.effects.AsThoughEffectImpl;
import mage.abilities.keyword.LifelinkAbility;
@ -82,18 +83,22 @@ class DanithaNewBenaliasLightCastFromGraveyardEffect extends AsThoughEffectImpl
}
@Override
public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) {
if (!source.isControlledBy(affectedControllerId) || game.getState().getZone(objectId) != Zone.GRAVEYARD) {
public boolean applies(UUID objectId, Ability affectedAbility, Ability source, Game game, UUID playerId) {
if (!source.isControlledBy(playerId) || game.getState().getZone(objectId) != Zone.GRAVEYARD || !(affectedAbility instanceof SpellAbility)) {
return false;
}
Card objectCard = game.getCard(objectId);
Card objectCard = ((SpellAbility) affectedAbility).getCharacteristics(game);
return objectCard != null
&& objectCard.isOwnedBy(source.getControllerId())
&& (objectCard.hasSubtype(SubType.AURA, game) || objectCard.hasSubtype(SubType.EQUIPMENT, game))
&& objectCard.getSpellAbility() != null
&& objectCard.getSpellAbility().spellCanBeActivatedRegularlyNow(affectedControllerId, game)
&& objectCard.getSpellAbility().spellCanBeActivatedRegularlyNow(playerId, game)
&& !DanithaNewBenaliasLightWatcher.isAbilityUsed(source, game);
}
@Override
public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) {
throw new IllegalArgumentException("ERROR, can't call applies method on empty affectedAbility");
}
}
class DanithaNewBenaliasLightWatcher extends Watcher {

View file

@ -3,6 +3,7 @@ package mage.abilities.effects.common.asthought;
import java.util.UUID;
import mage.abilities.Ability;
import mage.abilities.SpellAbility;
import mage.abilities.effects.AsThoughEffectImpl;
import mage.cards.Card;
import mage.constants.AsThoughEffectType;
@ -51,16 +52,23 @@ public class PlayFromNotOwnHandZoneAllEffect extends AsThoughEffectImpl {
@Override
public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) {
throw new IllegalArgumentException("ERROR, can't call applies method on empty affectedAbility");
}
@Override
public boolean applies(UUID objectId, Ability affectedAbility, Ability source, Game game, UUID playerId) {
Card card = game.getCard(objectId);
if (card != null) {
if (affectedAbility instanceof SpellAbility) {
card = ((SpellAbility) affectedAbility).getCharacteristics(game);
}
switch (allowedCaster) {
case YOU:
if (affectedControllerId != source.getControllerId()) {
if (playerId != source.getControllerId()) {
return false;
}
break;
case OPPONENT:
if (!game.getOpponents(source.getControllerId()).contains(affectedControllerId)) {
if (!game.getOpponents(source.getControllerId()).contains(playerId)) {
return false;
}
break;

View file

@ -1,6 +1,7 @@
package mage.abilities.effects.common.continuous;
import mage.abilities.Ability;
import mage.abilities.SpellAbility;
import mage.abilities.effects.AsThoughEffectImpl;
import mage.cards.Card;
import mage.constants.AsThoughEffectType;
@ -87,6 +88,10 @@ public class PlayTheTopCardEffect extends AsThoughEffectImpl {
@Override
public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) {
throw new IllegalArgumentException("ERROR, can't call applies method on empty affectedAbility");
}
@Override
public boolean applies(UUID objectId, Ability affectedAbility, Ability source, Game game, UUID playerId) {
// main card and all parts are checks in different calls.
// two modes:
// * can play cards (must check main card and allows any parts)
@ -101,10 +106,15 @@ public class PlayTheTopCardEffect extends AsThoughEffectImpl {
if (this.canPlayCardOnly) {
// check whole card instead part
cardToCheck = cardToCheck.getMainCard();
} else if (affectedAbility instanceof SpellAbility) {
SpellAbility spell = (SpellAbility) affectedAbility;
cardToCheck = spell.getCharacteristics(game);
if (spell.getManaCosts().isEmpty()){
return false;
}
}
// must be you
if (!affectedControllerId.equals(source.getControllerId())) {
if (!playerId.equals(source.getControllerId())) {
return false;
}
@ -154,12 +164,7 @@ public class PlayTheTopCardEffect extends AsThoughEffectImpl {
}
}
// can't cast without mana cost
if (!cardToCheck.isLand(game) && cardToCheck.getManaCost().isEmpty()) {
return false;
}
// must be correct card
return filter.match(cardToCheck, affectedControllerId, source, game);
return filter.match(cardToCheck, playerId, source, game);
}
}

View file

@ -1,6 +1,7 @@
package mage.abilities.effects.common.ruleModifying;
import mage.abilities.Ability;
import mage.abilities.SpellAbility;
import mage.abilities.effects.AsThoughEffectImpl;
import mage.cards.Card;
import mage.constants.AsThoughEffectType;
@ -48,6 +49,10 @@ public class PlayLandsFromGraveyardControllerEffect extends AsThoughEffectImpl {
@Override
public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) {
throw new IllegalArgumentException("ERROR, can't call applies method on empty affectedAbility");
}
@Override
public boolean applies(UUID objectId, Ability affectedAbility, Ability source, Game game, UUID playerId) {
// current card's part
Card cardToCheck = game.getCard(objectId);
if (cardToCheck == null) {
@ -55,13 +60,13 @@ public class PlayLandsFromGraveyardControllerEffect extends AsThoughEffectImpl {
}
// must be you
if (!affectedControllerId.equals(source.getControllerId())) {
if (!playerId.equals(source.getControllerId())) {
return false;
}
// must be your card
Player player = game.getPlayer(cardToCheck.getOwnerId());
if (player == null || !player.getId().equals(affectedControllerId)) {
if (player == null || !player.getId().equals(playerId)) {
return false;
}
@ -75,8 +80,10 @@ public class PlayLandsFromGraveyardControllerEffect extends AsThoughEffectImpl {
if (!cardToCheck.isLand(game) && cardToCheck.getManaCost().isEmpty()) {
return false;
}
if (affectedAbility instanceof SpellAbility){
cardToCheck = ((SpellAbility) affectedAbility).getCharacteristics(game);
}
// must be correct card
return filter.match(cardToCheck, affectedControllerId, source, game);
return filter.match(cardToCheck, playerId, source, game);
}
}