Search in sources :

Example 1 with UginTheIneffableToken

use of mage.game.permanent.token.UginTheIneffableToken in project mage by magefree.

the class UginTheIneffableLookAtFaceDownEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    MageObject sourceObject = source.getSourceObject(game);
    if (player == null || sourceObject == null) {
        return false;
    }
    Card card = player.getLibrary().getFromTop(game);
    if (card == null) {
        return false;
    }
    // exile and look
    UUID exileZoneId = CardUtil.getExileZoneId(game, source.getSourceId(), source.getSourceObjectZoneChangeCounter());
    if (player.moveCardsToExile(card, source, game, false, exileZoneId, sourceObject.getIdName() + " (" + player.getName() + ")")) {
        card.turnFaceDown(source, game, source.getControllerId());
        player.lookAtCards(player.getName() + " - " + card.getIdName() + " - " + CardUtil.sdf.format(System.currentTimeMillis()), card, game);
    }
    // create token
    Set<MageObjectReference> tokenObjs = new HashSet<>();
    CreateTokenEffect effect = new CreateTokenEffect(new UginTheIneffableToken());
    effect.apply(game, source);
    // with return ability
    for (UUID addedTokenId : effect.getLastAddedTokenIds()) {
        // display referenced exiled face-down card on token
        SimpleStaticAbility sa = new SimpleStaticAbility(Zone.BATTLEFIELD, new InfoEffect("Referenced object: " + card.getId().toString().substring(0, 3)));
        GainAbilityTargetEffect gainAbilityEffect = new GainAbilityTargetEffect(sa, Duration.WhileOnBattlefield);
        gainAbilityEffect.setTargetPointer(new FixedTarget(addedTokenId));
        game.addEffect(gainAbilityEffect, source);
        // look at face-down card in exile
        UginTheIneffableLookAtFaceDownEffect lookAtEffect = new UginTheIneffableLookAtFaceDownEffect();
        lookAtEffect.setTargetPointer(new FixedTarget(card.getId(), game));
        game.addEffect(lookAtEffect, source);
        tokenObjs.add(new MageObjectReference(addedTokenId, game));
        game.addDelayedTriggeredAbility(new UginTheIneffableDelayedTriggeredAbility(tokenObjs, new MageObjectReference(card, game)), source);
    }
    return true;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) UginTheIneffableToken(mage.game.permanent.token.UginTheIneffableToken) MageObject(mage.MageObject) CreateTokenEffect(mage.abilities.effects.common.CreateTokenEffect) SimpleStaticAbility(mage.abilities.common.SimpleStaticAbility) Card(mage.cards.Card) FilterCard(mage.filter.FilterCard) InfoEffect(mage.abilities.effects.common.InfoEffect) GainAbilityTargetEffect(mage.abilities.effects.common.continuous.GainAbilityTargetEffect) UUID(java.util.UUID) MageObjectReference(mage.MageObjectReference) HashSet(java.util.HashSet)

Aggregations

HashSet (java.util.HashSet)1 UUID (java.util.UUID)1 MageObject (mage.MageObject)1 MageObjectReference (mage.MageObjectReference)1 SimpleStaticAbility (mage.abilities.common.SimpleStaticAbility)1 CreateTokenEffect (mage.abilities.effects.common.CreateTokenEffect)1 InfoEffect (mage.abilities.effects.common.InfoEffect)1 GainAbilityTargetEffect (mage.abilities.effects.common.continuous.GainAbilityTargetEffect)1 Card (mage.cards.Card)1 FilterCard (mage.filter.FilterCard)1 UginTheIneffableToken (mage.game.permanent.token.UginTheIneffableToken)1 Player (mage.players.Player)1 FixedTarget (mage.target.targetpointer.FixedTarget)1