Search in sources :

Example 1 with TurnFaceUpAbility

use of mage.abilities.common.TurnFaceUpAbility in project mage by magefree.

the class BecomesFaceDownCreatureAllEffect method init.

@Override
public void init(Ability source, Game game) {
    super.init(source, game);
    for (Permanent perm : game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game)) {
        if (!perm.isFaceDown(game) && !perm.isTransformable()) {
            affectedObjectList.add(new MageObjectReference(perm, game));
            perm.setFaceDown(true, game);
            // check for Morph
            Card card = game.getCard(perm.getId());
            if (card != null) {
                for (Ability ability : card.getAbilities(game)) {
                    if (ability instanceof MorphAbility) {
                        this.turnFaceUpAbilityMap.put(card.getId(), new TurnFaceUpAbility(((MorphAbility) ability).getMorphCosts()));
                    }
                }
            }
        }
    }
}
Also used : TurnFaceUpAbility(mage.abilities.common.TurnFaceUpAbility) MorphAbility(mage.abilities.keyword.MorphAbility) Ability(mage.abilities.Ability) MorphAbility(mage.abilities.keyword.MorphAbility) Permanent(mage.game.permanent.Permanent) FilterPermanent(mage.filter.FilterPermanent) TurnFaceUpAbility(mage.abilities.common.TurnFaceUpAbility) MageObjectReference(mage.MageObjectReference) Card(mage.cards.Card)

Example 2 with TurnFaceUpAbility

use of mage.abilities.common.TurnFaceUpAbility in project mage by magefree.

the class BecomesFaceDownCreatureEffect method apply.

@Override
public boolean apply(Layer layer, SubLayer sublayer, Ability source, Game game) {
    Permanent permanent;
    if (objectReference != null) {
        permanent = objectReference.getPermanent(game);
    } else {
        permanent = game.getPermanent(source.getSourceId());
    }
    if (permanent != null && permanent.isFaceDown(game)) {
        if (!foundPermanent) {
            foundPermanent = true;
            switch(faceDownType) {
                case MANIFESTED:
                case // sets manifested image
                MANUAL:
                    permanent.setManifested(true);
                    break;
                case MORPHED:
                case MEGAMORPHED:
                    permanent.setMorphed(true);
                    break;
            }
        }
        switch(layer) {
            case TypeChangingEffects_4:
                permanent.setName("");
                permanent.getSuperType().clear();
                permanent.removeAllCardTypes(game);
                permanent.addCardType(game, CardType.CREATURE);
                permanent.removeAllSubTypes(game);
                break;
            case ColorChangingEffects_5:
                permanent.getColor(game).setColor(new ObjectColor());
                break;
            case AbilityAddingRemovingEffects_6:
                // 
                Card card = game.getCard(permanent.getId());
                List<Ability> abilitiesToRemove = new ArrayList<>();
                for (Ability ability : permanent.getAbilities()) {
                    // keep gained abilities from other sources, removes only own (card text)
                    if (card != null && !card.getAbilities().contains(ability)) {
                        continue;
                    }
                    // so keep all tune face up abilities and other face down compatible
                    if (ability.getWorksFaceDown()) {
                        ability.setRuleVisible(false);
                        continue;
                    }
                    if (!ability.getRuleVisible() && !ability.getEffects().isEmpty()) {
                        if (ability.getEffects().get(0) instanceof BecomesFaceDownCreatureEffect) {
                            continue;
                        }
                    }
                    abilitiesToRemove.add(ability);
                }
                permanent.removeAbilities(abilitiesToRemove, source.getSourceId(), game);
                if (turnFaceUpAbility != null) {
                    permanent.addAbility(turnFaceUpAbility, source.getSourceId(), game);
                }
                break;
            case PTChangingEffects_7:
                if (sublayer == SubLayer.SetPT_7b) {
                    permanent.getPower().setValue(2);
                    permanent.getToughness().setValue(2);
                }
        }
    } else if (duration == Duration.Custom && foundPermanent == true) {
        discard();
    }
    return true;
}
Also used : TurnFaceUpAbility(mage.abilities.common.TurnFaceUpAbility) Ability(mage.abilities.Ability) Permanent(mage.game.permanent.Permanent) ObjectColor(mage.ObjectColor) ArrayList(java.util.ArrayList) Card(mage.cards.Card)

Aggregations

Ability (mage.abilities.Ability)2 TurnFaceUpAbility (mage.abilities.common.TurnFaceUpAbility)2 Card (mage.cards.Card)2 Permanent (mage.game.permanent.Permanent)2 ArrayList (java.util.ArrayList)1 MageObjectReference (mage.MageObjectReference)1 ObjectColor (mage.ObjectColor)1 MorphAbility (mage.abilities.keyword.MorphAbility)1 FilterPermanent (mage.filter.FilterPermanent)1