Search in sources :

Example 71 with ObjectColor

use of mage.ObjectColor in project mage by magefree.

the class BecomesFaceDownCreatureAllEffect method apply.

@Override
public boolean apply(Layer layer, SubLayer sublayer, Ability source, Game game) {
    boolean targetExists = false;
    for (MageObjectReference mor : affectedObjectList) {
        Permanent permanent = mor.getPermanent(game);
        if (permanent != null && permanent.isFaceDown(game)) {
            targetExists = true;
            switch(layer) {
                case TypeChangingEffects_4:
                    permanent.setName("");
                    permanent.getSuperType().clear();
                    permanent.removeAllCardTypes(game);
                    permanent.addCardType(game, CardType.CREATURE);
                    permanent.removeAllSubTypes(game);
                    permanent.getManaCost().clear();
                    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 BecomesFaceDownCreatureAllEffect) {
                                continue;
                            }
                        }
                        abilitiesToRemove.add(ability);
                    }
                    permanent.removeAbilities(abilitiesToRemove, source.getSourceId(), game);
                    if (turnFaceUpAbilityMap.containsKey(permanent.getId())) {
                        permanent.addAbility(turnFaceUpAbilityMap.get(permanent.getId()), source.getSourceId(), game);
                    }
                    break;
                case PTChangingEffects_7:
                    if (sublayer == SubLayer.SetPT_7b) {
                        permanent.getPower().setValue(2);
                        permanent.getToughness().setValue(2);
                    }
            }
        }
    }
    if (!targetExists) {
        discard();
    }
    return true;
}
Also used : TurnFaceUpAbility(mage.abilities.common.TurnFaceUpAbility) MorphAbility(mage.abilities.keyword.MorphAbility) Ability(mage.abilities.Ability) Permanent(mage.game.permanent.Permanent) FilterPermanent(mage.filter.FilterPermanent) ObjectColor(mage.ObjectColor) MageObjectReference(mage.MageObjectReference) Card(mage.cards.Card)

Example 72 with ObjectColor

use of mage.ObjectColor 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)

Example 73 with ObjectColor

use of mage.ObjectColor in project mage by magefree.

the class MorphAbility method askToActivateAlternativeCosts.

@Override
public boolean askToActivateAlternativeCosts(Ability ability, Game game) {
    if (ability.getAbilityType() == AbilityType.SPELL) {
        Player player = game.getPlayer(ability.getControllerId());
        Spell spell = game.getStack().getSpell(ability.getId());
        if (player != null && spell != null) {
            this.resetMorph();
            // so only the back is visible
            spell.setFaceDown(true, game);
            if (alternateCosts.canPay(ability, this, ability.getControllerId(), game)) {
                if (player.chooseUse(Outcome.Benefit, "Cast this card as a 2/2 " + "face-down creature for " + getCosts().getText() + " ?", ability, game)) {
                    game.getState().setValue("MorphAbility" + ability.getSourceId(), // Gift of Doom
                    "activated");
                    activateMorph(game);
                    // change mana costs
                    ability.getManaCostsToPay().clear();
                    ability.getCosts().clear();
                    for (Iterator it = this.alternateCosts.iterator(); it.hasNext(); ) {
                        Cost cost = (Cost) it.next();
                        if (cost instanceof ManaCost) {
                            ability.getManaCostsToPay().add((ManaCost) cost.copy());
                        } else {
                            ability.getCosts().add(cost.copy());
                        }
                    }
                    // change spell colors and subtype *TODO probably this needs to be done by continuous effect (while on the stack)
                    ObjectColor spellColor = spell.getColor(game);
                    spellColor.setBlack(false);
                    spellColor.setRed(false);
                    spellColor.setGreen(false);
                    spellColor.setWhite(false);
                    spellColor.setBlue(false);
                    game.getState().getCreateMageObjectAttribute(spell.getCard(), game).getSubtype().clear();
                } else {
                    spell.setFaceDown(false, game);
                }
            }
        }
    }
    if (ability.getAbilityType() == AbilityType.PLAY_LAND) {
        Player player = game.getPlayer(ability.getControllerId());
        if (player != null) {
            this.resetMorph();
            if (alternateCosts.canPay(ability, this, ability.getControllerId(), game)) {
                if (player.chooseUse(Outcome.Benefit, "Cast this card as a 2/2 " + "face-down creature for " + getCosts().getText() + " ?", ability, game)) {
                    activateMorph(game);
                    // change mana costs
                    ability.getManaCostsToPay().clear();
                    ability.getCosts().clear();
                    for (Iterator it = this.alternateCosts.iterator(); it.hasNext(); ) {
                        Cost cost = (Cost) it.next();
                        if (cost instanceof ManaCost) {
                            ability.getManaCostsToPay().add((ManaCost) cost.copy());
                        } else {
                            ability.getCosts().add(cost.copy());
                        }
                    }
                }
            }
        }
    }
    return isActivated(ability, game);
}
Also used : Player(mage.players.Player) GenericManaCost(mage.abilities.costs.mana.GenericManaCost) ManaCost(mage.abilities.costs.mana.ManaCost) Iterator(java.util.Iterator) ObjectColor(mage.ObjectColor) Cost(mage.abilities.costs.Cost) GenericManaCost(mage.abilities.costs.mana.GenericManaCost) ManaCost(mage.abilities.costs.mana.ManaCost) Spell(mage.game.stack.Spell)

Example 74 with ObjectColor

use of mage.ObjectColor in project mage by magefree.

the class TargetControlledCreatureEachColor method makeFilter.

private static final FilterControlledPermanent makeFilter(String colors) {
    List<ObjectColor> objectColors = Arrays.stream(colors.split("")).map(ObjectColor::new).collect(Collectors.toList());
    FilterControlledPermanent filter = new FilterControlledCreaturePermanent(CardUtil.concatWithAnd(objectColors.stream().map(ObjectColor::getDescription).map(s -> CardUtil.addArticle(s) + " creature").collect(Collectors.toList())));
    filter.add(Predicates.or(objectColors.stream().map(ColorPredicate::new).collect(Collectors.toList())));
    return filter;
}
Also used : Arrays(java.util.Arrays) Cards(mage.cards.Cards) Predicates(mage.filter.predicate.Predicates) CardUtil(mage.util.CardUtil) UUID(java.util.UUID) CardsImpl(mage.cards.CardsImpl) Collectors(java.util.stream.Collectors) ColorAssignment(mage.abilities.dynamicvalue.common.ColorAssignment) Game(mage.game.Game) List(java.util.List) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Permanent(mage.game.permanent.Permanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) ColorPredicate(mage.filter.predicate.mageobject.ColorPredicate) ObjectColor(mage.ObjectColor) Ability(mage.abilities.Ability) ObjectColor(mage.ObjectColor) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent)

Example 75 with ObjectColor

use of mage.ObjectColor in project mage by magefree.

the class CardView method fillEmpty.

private void fillEmpty(Card card, boolean controlled) {
    this.name = "Face Down";
    this.displayName = name;
    this.displayFullName = name;
    this.rules = new ArrayList<>();
    this.power = "";
    this.toughness = "";
    this.loyalty = "";
    this.startingLoyalty = "";
    this.cardTypes = new ArrayList<>();
    this.subTypes = new SubTypes();
    this.superTypes = EnumSet.noneOf(SuperType.class);
    this.color = new ObjectColor();
    this.frameColor = new ObjectColor();
    this.frameStyle = FrameStyle.M15_NORMAL;
    this.manaCostLeftStr = "";
    this.manaCostRightStr = "";
    this.manaValue = 0;
    // the controller can see more information (e.g. enlarged image) than other players for face down cards (e.g. Morph played face down)
    if (!controlled) {
        this.rarity = Rarity.COMMON;
        this.expansionSetCode = "";
        this.cardNumber = "0";
    } else {
        this.rarity = card.getRarity();
    }
    if (card != null) {
        if (card instanceof Permanent) {
            this.mageObjectType = MageObjectType.PERMANENT;
        } else if (card.isCopy()) {
            this.mageObjectType = MageObjectType.COPY_CARD;
        } else {
            this.mageObjectType = MageObjectType.CARD;
        }
        if (card instanceof PermanentToken) {
            this.mageObjectType = MageObjectType.TOKEN;
        }
        if (card instanceof Spell) {
            this.mageObjectType = MageObjectType.SPELL;
        }
    }
}
Also used : SubTypes(mage.util.SubTypes) Permanent(mage.game.permanent.Permanent) ObjectColor(mage.ObjectColor) PermanentToken(mage.game.permanent.PermanentToken) Spell(mage.game.stack.Spell)

Aggregations

ObjectColor (mage.ObjectColor)82 Permanent (mage.game.permanent.Permanent)50 Player (mage.players.Player)27 ColorPredicate (mage.filter.predicate.mageobject.ColorPredicate)19 UUID (java.util.UUID)14 TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)14 Card (mage.cards.Card)13 FilterPermanent (mage.filter.FilterPermanent)13 Spell (mage.game.stack.Spell)12 Ability (mage.abilities.Ability)10 FixedTarget (mage.target.targetpointer.FixedTarget)10 ChoiceColor (mage.choices.ChoiceColor)9 Mana (mage.Mana)8 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)8 ArrayList (java.util.ArrayList)7 ContinuousEffect (mage.abilities.effects.ContinuousEffect)7 ProtectionAbility (mage.abilities.keyword.ProtectionAbility)7 FilterCard (mage.filter.FilterCard)7 FilterControlledCreaturePermanent (mage.filter.common.FilterControlledCreaturePermanent)6 MageObject (mage.MageObject)5