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.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);
}
}