Fix Intellect Devourer. Closes #11205

This commit is contained in:
PurpleCrowbar 2023-10-15 18:20:11 +01:00
parent 6e6ecfb339
commit 9645eced8b

View file

@ -6,10 +6,9 @@ import mage.abilities.Ability;
import mage.abilities.DelayedTriggeredAbility;
import mage.abilities.common.EntersBattlefieldTriggeredAbility;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.effects.AsThoughEffectImpl;
import mage.abilities.effects.AsThoughManaEffect;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.CreateDelayedTriggeredAbilityEffect;
import mage.abilities.effects.common.InfoEffect;
import mage.cards.*;
import mage.constants.*;
import mage.filter.FilterCard;
@ -18,7 +17,6 @@ import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.events.ZoneChangeEvent;
import mage.game.permanent.Permanent;
import mage.players.ManaPoolItem;
import mage.players.Player;
import mage.target.Target;
import mage.target.common.TargetCardInHand;
@ -45,12 +43,12 @@ public final class IntellectDevourer extends CardImpl {
ability.addEffect(new CreateDelayedTriggeredAbilityEffect(new IntellectDevourerReturnCardsAbility()));
this.addAbility(ability.withFlavorWord("Devour Intellect"));
// Body Thief You may play lands and cast spells from among cards exiled with Intellect Devourer.
// If you cast a spell this way, you may spend mana as though it were mana of any color to cast it.
ability = new SimpleStaticAbility(new IntellectDevourerPlayFromExileEffect());
ability.addEffect(new IntellectDevourerManaEffect());
this.addAbility(ability.withFlavorWord("Body Thief"));
this.addAbility(new SimpleStaticAbility(Zone.ALL, new InfoEffect(
"You may play lands and cast spells from among cards exiled with {this}. If you cast " +
"a spell this way, you may spend mana as though it were mana of any color to cast it"
)).withFlavorWord("Body Thief"));
}
private IntellectDevourer(final IntellectDevourer card) {
@ -82,7 +80,7 @@ class IntellectDevourerExileEffect extends OneShotEffect {
return false;
}
Boolean applied = false;
boolean applied = false;
// for storing each card to exile
Map<UUID, Cards> cardsToExile = new HashMap<>();
@ -92,7 +90,7 @@ class IntellectDevourerExileEffect extends OneShotEffect {
if (opponent == null) {
continue;
}
if (opponent.getHand().size() > 0) {
if (!opponent.getHand().isEmpty()) {
Target target = new TargetCardInHand(1, new FilterCard());
target.setRequired(true);
if (opponent.chooseTarget(Outcome.Exile, target, source, game)) {
@ -122,6 +120,7 @@ class IntellectDevourerExileEffect extends OneShotEffect {
opponent.moveCardsToExile(opponentCardsToExile.getCards(game), source, game, false, exileZoneId, sourceObject.getIdName());
Card thisCard = opponentCardsToExile.getCards(game).iterator().next();
game.getState().setValue(thisCard.getId().toString() + game.getState().getZoneChangeCounter(thisCard.getId()), exileZoneId);
CardUtil.makeCardPlayable(game, source, thisCard, Duration.Custom, true, source.getControllerId(), null);
applied = true;
}
@ -129,98 +128,6 @@ class IntellectDevourerExileEffect extends OneShotEffect {
}
}
class IntellectDevourerPlayFromExileEffect extends AsThoughEffectImpl {
IntellectDevourerPlayFromExileEffect() {
super(AsThoughEffectType.PLAY_FROM_NOT_OWN_HAND_ZONE, Duration.WhileOnBattlefield, Outcome.Benefit);
staticText = "You may play lands and cast spells from among cards exiled with {this}";
}
private IntellectDevourerPlayFromExileEffect(final IntellectDevourerPlayFromExileEffect effect) {super(effect);}
@Override
public boolean apply(Game game, Ability source) {return true;}
@Override
public IntellectDevourerPlayFromExileEffect copy() {return new IntellectDevourerPlayFromExileEffect(this);}
@Override
public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) {
MageObject sourceObject = source.getSourceObject(game);
Card theCard = game.getCard(objectId);
if (theCard == null) {
return false;
}
objectId = theCard.getMainCard().getId(); // for split cards
UUID exileZoneId = CardUtil.getExileZoneId(game, sourceObject.getId(), sourceObject.getZoneChangeCounter(game));
ExileZone exileZone = game.getExile().getExileZone(exileZoneId);
if (exileZone == null) {
return false;
}
// this check happens while the chosen card is in the exile zone
if (exileZone.contains(objectId) && affectedControllerId.equals(source.getControllerId())) {
Card card = game.getCard(objectId);
return card != null;
}
return false;
}
}
class IntellectDevourerManaEffect extends AsThoughEffectImpl implements AsThoughManaEffect {
IntellectDevourerManaEffect() {
super(AsThoughEffectType.SPEND_OTHER_MANA, Duration.WhileOnBattlefield, Outcome.Benefit);
this.staticText = "If you cast a spell this way, you may spend mana as though it were mana of any color to cast it";
}
private IntellectDevourerManaEffect(final IntellectDevourerManaEffect effect) {
super(effect);
}
@Override
public boolean apply(Game game, Ability source) {
return true;
}
@Override
public IntellectDevourerManaEffect copy() {
return new IntellectDevourerManaEffect(this);
}
@Override
public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) {
// this check occurs when the chosen card is outside of the exile zone, so the exileId must be retrieved from history
MageObject sourceObject = source.getSourceObject(game);
Card theCard = game.getCard(objectId);
if (theCard == null) {
return false;
}
objectId = theCard.getMainCard().getId(); // for split cards
// get the current zcc of the chosen exiled card
int zcc = game.getState().getZoneChangeCounter(theCard.getId());
// retrieve the exileId of this source card
UUID exileId = CardUtil.getExileZoneId(game, sourceObject.getId(), sourceObject.getZoneChangeCounter(game));
// retrieve the exileId stored on the chosen exiled card (note that we subtract 1 from it due to it being moved from the exile zone to the stack
UUID storedExileIdOfTheCard = (UUID) game.getState().getValue(theCard.getId().toString() + (zcc - 1));
if (objectId != null
&& game.getState().getZone(objectId) == Zone.STACK
&& exileId == storedExileIdOfTheCard
&& affectedControllerId.equals(source.getControllerId())) {
Card card = game.getCard(objectId);
return card != null;
}
return false;
}
@Override
public ManaType getAsThoughManaType(ManaType manaType, ManaPoolItem mana, UUID affectedControllerId, Ability source, Game game) {
return mana.getFirstAvailable();
}
}
class IntellectDevourerReturnCardsAbility extends DelayedTriggeredAbility {
public IntellectDevourerReturnCardsAbility() {