[AVR] Fixed Stolen Goods not working with dual face cards. Closes #9430.

This commit is contained in:
Alex Vasile 2022-08-29 21:04:49 -04:00
parent 461b011fb7
commit a29d5c70cb
2 changed files with 57 additions and 50 deletions

View file

@ -6,13 +6,11 @@ import mage.abilities.Ability;
import mage.abilities.effects.AsThoughEffectImpl; import mage.abilities.effects.AsThoughEffectImpl;
import mage.abilities.effects.ContinuousEffect; import mage.abilities.effects.ContinuousEffect;
import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.asthought.PlayFromNotOwnHandZoneTargetEffect;
import mage.cards.Card; import mage.cards.Card;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.cards.CardSetInfo; import mage.cards.CardSetInfo;
import mage.constants.AsThoughEffectType; import mage.constants.*;
import mage.constants.CardType;
import mage.constants.Duration;
import mage.constants.Outcome;
import mage.game.Game; import mage.game.Game;
import mage.players.Player; import mage.players.Player;
import mage.target.common.TargetOpponent; import mage.target.common.TargetOpponent;
@ -61,54 +59,23 @@ class StolenGoodsEffect extends OneShotEffect {
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
Player opponent = game.getPlayer(targetPointer.getFirst(game, source)); Player opponent = game.getPlayer(targetPointer.getFirst(game, source));
if (opponent != null) { if (opponent == null) {
return false;
}
Card card; Card card;
do { do {
card = opponent.getLibrary().getFromTop(game); card = opponent.getLibrary().getFromTop(game);
if (card != null) { if (card == null) {
continue;
}
if (card.isLand(game)) {
opponent.moveCardsToExile(card, source, game, true, source.getSourceId(), CardUtil.createObjectRealtedWindowTitle(source, game, null)); opponent.moveCardsToExile(card, source, game, true, source.getSourceId(), CardUtil.createObjectRealtedWindowTitle(source, game, null));
} else {
PlayFromNotOwnHandZoneTargetEffect.exileAndPlayFromExile(game, source, card, TargetController.YOU, Duration.EndOfTurn, true, false, true);
break;
} }
} while (card != null && card.isLand(game)); } while (card != null && card.isLand(game));
if (card != null) {
ContinuousEffect effect = new StolenGoodsCastFromExileEffect();
effect.setTargetPointer(new FixedTarget(card, game));
game.addEffect(effect, source);
}
return true; return true;
} }
return false;
}
}
class StolenGoodsCastFromExileEffect extends AsThoughEffectImpl {
public StolenGoodsCastFromExileEffect() {
super(AsThoughEffectType.PLAY_FROM_NOT_OWN_HAND_ZONE, Duration.EndOfTurn, Outcome.Benefit);
staticText = "You may cast card from exile";
}
public StolenGoodsCastFromExileEffect(final StolenGoodsCastFromExileEffect effect) {
super(effect);
}
@Override
public boolean apply(Game game, Ability source) {
return true;
}
@Override
public StolenGoodsCastFromExileEffect copy() {
return new StolenGoodsCastFromExileEffect(this);
}
@Override
public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) {
if (objectId != null && objectId.equals(getTargetPointer().getFirst(game, source))
&& affectedControllerId.equals(source.getControllerId())) {
allowCardToPlayWithoutMana(objectId, source, affectedControllerId, game);
return true;
}
return false;
}
} }

View file

@ -0,0 +1,40 @@
package org.mage.test.cards.single.avr;
import mage.constants.PhaseStep;
import mage.constants.Zone;
import org.junit.Test;
import org.mage.test.serverside.base.CardTestPlayerBase;
/**
* {@link mage.cards.s.StolenGoods Stolen Goods}
* {3}{U}
* Sorcery
* Target opponent exiles cards from the top of their library until they exile a nonland card.
* Until end of turn, you may cast that card without paying its mana cost.
*
@author Alex-Vasile
*/
public class StolenGoodsTest extends CardTestPlayerBase {
private static final String stolenGoods = "Stolen Goods";
/**
* Reported bug: https://github.com/magefree/mage/issues/9430
* "[[Stolen Goods]] will let you cast spells without paying their mana costs, but only if you have enough mana to cast them.
* In this example, I want to cast [[Kolvori, God of Kinship]], but can't because I have no green sources."
*/
@Test
public void castDualFaceCard() {
addCard(Zone.BATTLEFIELD, playerA, "Island", 4);
addCard(Zone.HAND, playerA, stolenGoods);
addCard(Zone.LIBRARY, playerB, "Kolvori, God of Kinship");
skipInitShuffling();
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, stolenGoods);
castSpell(1, PhaseStep.POSTCOMBAT_MAIN, playerA, "Kolvori, God of Kinship");
setStopAt(1, PhaseStep.END_TURN);
execute();
}
}