use of mage.abilities.effects.common.asthought.YouMaySpendManaAsAnyColorToCastTargetEffect in project mage by magefree.
the class RobberOfTheRichEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Player damagedPlayer = game.getPlayer(this.getTargetPointer().getFirst(game, source));
if (controller == null || damagedPlayer == null) {
return false;
}
Card card = damagedPlayer.getLibrary().getFromTop(game);
if (card == null) {
return false;
}
// move card to exile
controller.moveCardsToExile(card, source, game, true, CardUtil.getExileZoneId(game, source), CardUtil.getSourceName(game, source));
// don't worry about land
if (card.getSpellAbility() != null) {
// the exiled card is independent and requires a new ability in case the Robber leaves the battlefield
// the exiled card can be cast throughout the entire game as long as the controller attacked with a rogue that turn
Ability copiedAbility = source.copy();
copiedAbility.newId();
copiedAbility.setSourceId(card.getId());
copiedAbility.setControllerId(source.getControllerId());
PlayFromNotOwnHandZoneTargetEffect playFromExile = new PlayFromNotOwnHandZoneTargetEffect(Zone.EXILED, Duration.EndOfGame);
YouMaySpendManaAsAnyColorToCastTargetEffect spendAnyMana = new YouMaySpendManaAsAnyColorToCastTargetEffect(Duration.EndOfGame);
ConditionalAsThoughEffect castOnlyIfARogueAttackedThisTurn = new ConditionalAsThoughEffect(playFromExile, new RogueAttackedThisTurnCondition(copiedAbility));
playFromExile.setTargetPointer(new FixedTarget(card, game));
spendAnyMana.setTargetPointer(new FixedTarget(card, game));
castOnlyIfARogueAttackedThisTurn.setTargetPointer(new FixedTarget(card, game));
game.addEffect(castOnlyIfARogueAttackedThisTurn, copiedAbility);
game.addEffect(spendAnyMana, copiedAbility);
return true;
}
return false;
}
use of mage.abilities.effects.common.asthought.YouMaySpendManaAsAnyColorToCastTargetEffect in project mage by magefree.
the class CardUtil method makeCardPlayable.
/**
* Add effects to game that allows to play/cast card from current zone and spend mana as any type for it.
* Effects will be discarded/ignored on any card movements or blinks (after ZCC change)
* <p>
* Affected to all card's parts
*
* @param game
* @param card
* @param duration
* @param anyColor
* @param condition can be null
*/
public static void makeCardPlayable(Game game, Ability source, Card card, Duration duration, boolean anyColor, UUID playerId, Condition condition) {
// Effect can be used for cards in zones and permanents on battlefield
// PermanentCard's ZCC is static, but we need updated ZCC from the card (after moved to another zone)
// So there is a workaround to get actual card's ZCC
// Example: Hostage Taker
UUID objectId = card.getMainCard().getId();
int zcc = game.getState().getZoneChangeCounter(objectId);
game.addEffect(new CanPlayCardControllerEffect(game, objectId, zcc, duration, playerId, condition), source);
if (anyColor) {
game.addEffect(new YouMaySpendManaAsAnyColorToCastTargetEffect(duration, playerId, condition).setTargetPointer(new FixedTarget(objectId, zcc)), source);
}
}
Aggregations