Search in sources :

Example 1 with CustomIllusionToken

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

the class SkyclaveApparitionEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent permanentLeftBattlefield = (Permanent) getValue("permanentLeftBattlefield");
    ExileZone exile = game.getExile().getExileZone(CardUtil.getExileZoneId(game, source.getSourceId(), permanentLeftBattlefield.getZoneChangeCounter(game)));
    if (exile == null || exile.isEmpty()) {
        return false;
    }
    // From ZNR Release Notes:
    // https://magic.wizards.com/en/articles/archive/feature/zendikar-rising-release-notes-2020-09-10
    // If Skyclave Apparition's first ability exiled more than one card owned by a single player,
    // that player creates a token with power and toughness equal to the sum of those cards' converted mana costs.
    // If the first ability exiled cards owned by more than one player, each of those players creates a token
    // with power and toughness equal to the sum of the converted mana costs of all cards exiled by the first ability.
    Set<UUID> owners = new HashSet<>();
    int totalCMC = exile.getCards(game).stream().filter(Objects::nonNull).map(card -> owners.add(card.getOwnerId()) ? card : card).mapToInt(MageObject::getManaValue).sum();
    for (UUID playerId : owners) {
        new CustomIllusionToken(totalCMC).putOntoBattlefield(1, game, source, playerId);
    }
    return true;
}
Also used : FilterNonlandPermanent(mage.filter.common.FilterNonlandPermanent) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) ExileZone(mage.game.ExileZone) CustomIllusionToken(mage.game.permanent.token.CustomIllusionToken) UUID(java.util.UUID) HashSet(java.util.HashSet)

Aggregations

HashSet (java.util.HashSet)1 UUID (java.util.UUID)1 FilterPermanent (mage.filter.FilterPermanent)1 FilterNonlandPermanent (mage.filter.common.FilterNonlandPermanent)1 ExileZone (mage.game.ExileZone)1 Permanent (mage.game.permanent.Permanent)1 CustomIllusionToken (mage.game.permanent.token.CustomIllusionToken)1 TargetPermanent (mage.target.TargetPermanent)1