Search in sources :

Example 1 with ObjectColor

use of mage.ObjectColor in project mage by magefree.

the class ProtectionChosenColorTargetEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Permanent target = game.getPermanent(getTargetPointer().getFirst(game, source));
        if (target != null) {
            ChoiceColor colorChoice = new ChoiceColor();
            if (!controller.choose(Outcome.Benefit, colorChoice, game)) {
                return false;
            }
            game.informPlayers(target.getName() + ": " + controller.getLogName() + " has chosen " + colorChoice.getChoice());
            game.getState().setValue(target.getId() + "_color", colorChoice.getColor());
            ObjectColor protectColor = (ObjectColor) game.getState().getValue(target.getId() + "_color");
            if (protectColor != null) {
                ContinuousEffect effect = new ProtectionChosenColorTargetEffect();
                game.addEffect(effect, source);
                ObjectColor color = target.getColor(game);
                for (Permanent permanent : game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, source.getControllerId(), source.getSourceId(), game)) {
                    if (!permanent.getId().equals(target.getId()) && permanent.getColor(game).shares(color)) {
                        game.getState().setValue(permanent.getId() + "_color", colorChoice.getColor());
                        effect.setTargetPointer(new FixedTarget(permanent, game));
                        game.addEffect(effect, source);
                    }
                }
            }
            return true;
        }
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) ObjectColor(mage.ObjectColor) ContinuousEffect(mage.abilities.effects.ContinuousEffect) ChoiceColor(mage.choices.ChoiceColor)

Example 2 with ObjectColor

use of mage.ObjectColor in project mage by magefree.

the class ManaCanBeSpentAsAnyColorEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        ObjectColor colorless = new ObjectColor();
        // permaments
        for (Permanent perm : game.getBattlefield().getActivePermanents(source.getControllerId(), game)) {
            perm.getColor(game).setColor(colorless);
        }
        List<Card> affectedCards = new ArrayList<>();
        // spells
        for (MageObject object : game.getStack()) {
            if (object instanceof Spell) {
                game.getState().getCreateMageObjectAttribute(object, game).getColor().setColor(colorless);
                Card card = ((Spell) object).getCard();
                affectedCards.add(card);
            }
        }
        // exile
        affectedCards.addAll(game.getExile().getAllCardsByRange(game, controller.getId()));
        for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
            Player player = game.getPlayer(playerId);
            if (player == null) {
                continue;
            }
            // command
            affectedCards.addAll(game.getCommanderCardsFromCommandZone(player, CommanderCardType.ANY));
            // hand
            affectedCards.addAll(player.getHand().getCards(game));
            // library
            affectedCards.addAll(player.getLibrary().getCards(game));
            // graveyard
            affectedCards.addAll(player.getGraveyard().getCards(game));
        }
        // apply colors to all cards
        affectedCards.forEach(card -> {
            game.getState().getCreateMageObjectAttribute(card, game).getColor().setColor(colorless);
            // mdf cards
            if (card instanceof ModalDoubleFacesCard) {
                ModalDoubleFacesCardHalf leftHalfCard = ((ModalDoubleFacesCard) card).getLeftHalfCard();
                ModalDoubleFacesCardHalf rightHalfCard = ((ModalDoubleFacesCard) card).getRightHalfCard();
                game.getState().getCreateMageObjectAttribute(leftHalfCard, game).getColor().setColor(colorless);
                game.getState().getCreateMageObjectAttribute(rightHalfCard, game).getColor().setColor(colorless);
            }
            // split cards
            if (card instanceof SplitCard) {
                SplitCardHalf leftHalfCard = ((SplitCard) card).getLeftHalfCard();
                SplitCardHalf rightHalfCard = ((SplitCard) card).getRightHalfCard();
                game.getState().getCreateMageObjectAttribute(leftHalfCard, game).getColor().setColor(colorless);
                game.getState().getCreateMageObjectAttribute(rightHalfCard, game).getColor().setColor(colorless);
            }
            // double faces cards
            if (card.getSecondCardFace() != null) {
                game.getState().getCreateMageObjectAttribute(card, game).getColor().setColor(colorless);
            }
        });
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) ArrayList(java.util.ArrayList) MageObject(mage.MageObject) Spell(mage.game.stack.Spell) ObjectColor(mage.ObjectColor) UUID(java.util.UUID)

Example 3 with ObjectColor

use of mage.ObjectColor in project mage by magefree.

the class MostCommonColorCondition method apply.

@Override
public boolean apply(Game game, Ability source) {
    FilterPermanent[] colorFilters = new FilterPermanent[6];
    int i = 0;
    for (ObjectColor color : ObjectColor.getAllColors()) {
        colorFilters[i] = new FilterPermanent();
        colorFilters[i].add(new ColorPredicate(color));
        if (predicate != null) {
            colorFilters[i].add(predicate);
        }
        i++;
    }
    int[] colorCounts = new int[6];
    i = 0;
    for (ObjectColor color : ObjectColor.getAllColors()) {
        colorFilters[i].add(new ColorPredicate(color));
        colorCounts[i] = game.getBattlefield().count(colorFilters[i], source.getId(), source.getControllerId(), game);
        i++;
    }
    int max = 0;
    for (i = 0; i < 5; i++) {
        if (colorCounts[i] > max) {
            max = colorCounts[i] * 1;
        }
    }
    i = 0;
    ObjectColor commonest = new ObjectColor();
    for (ObjectColor color : ObjectColor.getAllColors()) {
        if (colorCounts[i] == max) {
            commonest.addColor(color);
        }
        i++;
    }
    if (compareColor.shares(commonest)) {
        if (isMono) {
            return !commonest.isMulticolored();
        } else {
            return true;
        }
    }
    return false;
}
Also used : ColorPredicate(mage.filter.predicate.mageobject.ColorPredicate) FilterPermanent(mage.filter.FilterPermanent) ObjectColor(mage.ObjectColor)

Example 4 with ObjectColor

use of mage.ObjectColor in project mage by magefree.

the class MorphAbility method setPermanentToFaceDownCreature.

public static void setPermanentToFaceDownCreature(MageObject mageObject, Game game) {
    mageObject.getPower().modifyBaseValue(2);
    mageObject.getToughness().modifyBaseValue(2);
    mageObject.getAbilities().clear();
    mageObject.getColor(game).setColor(new ObjectColor());
    mageObject.setName("");
    mageObject.removeAllCardTypes(game);
    mageObject.addCardType(game, CardType.CREATURE);
    mageObject.removeAllSubTypes(game);
    mageObject.getSuperType().clear();
    mageObject.getManaCost().clear();
    if (mageObject instanceof Permanent) {
        ((Permanent) mageObject).setExpansionSetCode("");
        ((Permanent) mageObject).setRarity(Rarity.SPECIAL);
    }
}
Also used : Permanent(mage.game.permanent.Permanent) ObjectColor(mage.ObjectColor)

Example 5 with ObjectColor

use of mage.ObjectColor in project mage by magefree.

the class CommandersPlateEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    Permanent permanent = null;
    if (affectedObjectsSet) {
        permanent = game.getPermanent(targetPointer.getFirst(game, source));
        if (permanent == null) {
            discard();
            return true;
        }
    } else {
        Permanent equipment = game.getPermanent(source.getSourceId());
        if (equipment != null && equipment.getAttachedTo() != null) {
            permanent = game.getPermanentOrLKIBattlefield(equipment.getAttachedTo());
        }
    }
    Set<UUID> commanders = game.getCommandersIds(player, CommanderCardType.COMMANDER_OR_OATHBREAKER, false);
    if (commanders.isEmpty()) {
        return false;
    }
    ObjectColor color = new ObjectColor("WUBRG");
    for (UUID commanderId : commanders) {
        Card card = game.getCard(commanderId);
        if (card == null) {
            continue;
        }
        FilterMana identity = card.getColorIdentity();
        if (identity.isWhite()) {
            color.setWhite(false);
        }
        if (identity.isBlue()) {
            color.setBlue(false);
        }
        if (identity.isBlack()) {
            color.setBlack(false);
        }
        if (identity.isRed()) {
            color.setRed(false);
        }
        if (identity.isGreen()) {
            color.setGreen(false);
        }
    }
    if (permanent != null) {
        permanent.addAbility(ProtectionAbility.from(color), source.getSourceId(), game);
    }
    return true;
}
Also used : Player(mage.players.Player) FilterMana(mage.filter.FilterMana) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) ObjectColor(mage.ObjectColor) UUID(java.util.UUID) Card(mage.cards.Card)

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