Search in sources :

Example 56 with ObjectColor

use of mage.ObjectColor in project mage by magefree.

the class ExpansionSet method validateCommonColors.

protected boolean validateCommonColors(List<Card> booster) {
    List<ObjectColor> commonColors = booster.stream().filter(card -> card.getRarity() == Rarity.COMMON).map(ExpansionSet::getColorForValidate).collect(Collectors.toList());
    // for multicolor sets, count not just the colors present at common,
    // but also the number of color combinations (guilds/shards/wedges)
    // e.g. a booster with three UB commons, three RW commons and four G commons
    // has all five colors but isn't "balanced"
    ObjectColor colorsRepresented = new ObjectColor();
    Set<ObjectColor> colorCombinations = new HashSet<>();
    int colorlessCountPlusOne = 1;
    for (ObjectColor color : commonColors) {
        colorCombinations.add(color);
        int colorCount = color.getColorCount();
        if (colorCount == 0) {
            ++colorlessCountPlusOne;
        } else if (colorCount > 1 && !hasOnlyMulticolorCards) {
            // to prevent biasing toward multicolor over monocolor cards,
            // count them as one of their colors chosen at random
            List<ObjectColor> multiColor = color.getColors();
            colorsRepresented.addColor(multiColor.get(RandomUtil.nextInt(multiColor.size())));
        } else {
            colorsRepresented.addColor(color);
        }
    }
    int colors = Math.min(colorsRepresented.getColorCount(), colorCombinations.size());
    // ("all but one" adds some leeway for sets with small boosters)
    if (colors >= Math.min(5, commonColors.size() - colorlessCountPlusOne))
        return true;
    // otherwise, if booster is missing more than one color, reject it
    if (colors < 4)
        return false;
    // for Torment and Judgment, always accept boosters with four out of five colors
    if (hasUnbalancedColors)
        return true;
    // if a common was replaced by a special card, increase the chance to accept four colors
    if (commonColors.size() < numBoosterCommon)
        ++colorlessCountPlusOne;
    // otherwise, stochiastically treat each colorless card as 1/5 of a card of the missing color
    return (RandomUtil.nextDouble() > Math.pow(0.8, colorlessCountPlusOne));
}
Also used : ObjectColor(mage.ObjectColor)

Example 57 with ObjectColor

use of mage.ObjectColor in project mage by magefree.

the class AnyColorPermanentTypesManaEffect method getManaTypes.

private Mana getManaTypes(Game game, Ability source) {
    Mana types = new Mana();
    if (game == null || game.getPhase() == null) {
        return types;
    }
    if (inManaTypeCalculation) {
        return types;
    }
    inManaTypeCalculation = true;
    ObjectColor permanentColor;
    List<Permanent> permanents = game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game);
    for (Permanent permanent : permanents) {
        permanentColor = permanent.getColor(game);
        if (permanentColor.isColorless()) {
            types.add(Mana.ColorlessMana(1));
        } else {
            List<ObjectColor> permanentColors = permanent.getColor(game).getColors();
            for (ObjectColor color : permanentColors) {
                types.add(new Mana(color.getOneColoredManaSymbol()));
            }
        }
    }
    inManaTypeCalculation = false;
    return types;
}
Also used : Mana(mage.Mana) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) ObjectColor(mage.ObjectColor)

Example 58 with ObjectColor

use of mage.ObjectColor in project mage by magefree.

the class GeneralTazriColorCount method calculate.

@Override
public int calculate(Game game, Ability sourceAbility, Effect effect) {
    int count = 0;
    boolean black = false;
    boolean red = false;
    boolean white = false;
    boolean green = false;
    boolean blue = false;
    for (Permanent creature : game.getBattlefield().getAllActivePermanents(filter, sourceAbility.getControllerId(), game)) {
        ObjectColor color = creature.getColor(game);
        black |= color.isBlack();
        red |= color.isRed();
        white |= color.isWhite();
        green |= color.isGreen();
        blue |= color.isBlue();
    }
    count += black ? 1 : 0;
    count += red ? 1 : 0;
    count += white ? 1 : 0;
    count += green ? 1 : 0;
    count += blue ? 1 : 0;
    return count;
}
Also used : Permanent(mage.game.permanent.Permanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) ObjectColor(mage.ObjectColor)

Example 59 with ObjectColor

use of mage.ObjectColor in project mage by magefree.

the class MindExtractionEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Player player = game.getPlayer(source.getFirstTarget());
    if (controller == null || player == null) {
        return false;
    }
    Permanent sacrificedCreature = null;
    for (Cost cost : source.getCosts()) {
        if (!(cost instanceof SacrificeTargetCost)) {
            continue;
        }
        SacrificeTargetCost sacCost = (SacrificeTargetCost) cost;
        for (Permanent permanent : sacCost.getPermanents()) {
            sacrificedCreature = permanent;
            break;
        }
    }
    if (sacrificedCreature == null) {
        return false;
    }
    ObjectColor color = sacrificedCreature.getColor(game);
    Cards cards = new CardsImpl(player.getHand());
    if (cards.isEmpty()) {
        return true;
    }
    player.revealCards(source, cards, game);
    if (color.isColorless()) {
        return true;
    }
    Cards toDiscard = new CardsImpl();
    cards.getCards(game).stream().filter(card -> card.getColor(game).shares(color)).forEach(toDiscard::add);
    player.discard(toDiscard, false, source, game);
    return true;
}
Also used : StaticFilters(mage.filter.StaticFilters) Cards(mage.cards.Cards) Outcome(mage.constants.Outcome) OneShotEffect(mage.abilities.effects.OneShotEffect) TargetPlayer(mage.target.TargetPlayer) UUID(java.util.UUID) CardsImpl(mage.cards.CardsImpl) Player(mage.players.Player) Cost(mage.abilities.costs.Cost) SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost) CardSetInfo(mage.cards.CardSetInfo) Game(mage.game.Game) CardImpl(mage.cards.CardImpl) Permanent(mage.game.permanent.Permanent) CardType(mage.constants.CardType) ObjectColor(mage.ObjectColor) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) Ability(mage.abilities.Ability) TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost) Permanent(mage.game.permanent.Permanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) ObjectColor(mage.ObjectColor) Cost(mage.abilities.costs.Cost) SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl)

Example 60 with ObjectColor

use of mage.ObjectColor in project mage by magefree.

the class PaintersServantEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        ObjectColor color = (ObjectColor) game.getState().getValue(source.getSourceId() + "_color");
        if (color == null) {
            return false;
        }
        // permanents
        for (Permanent perm : game.getBattlefield().getActivePermanents(source.getControllerId(), game)) {
            perm.getColor(game).addColor(color);
        }
        List<Card> affectedCards = new ArrayList<>();
        // stack
        for (MageObject object : game.getStack()) {
            if (object instanceof Spell) {
                game.getState().getCreateMageObjectAttribute(object, game).getColor().addColor(color);
                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().addColor(color);
            // mdf cards
            if (card instanceof ModalDoubleFacesCard) {
                ModalDoubleFacesCardHalf leftHalfCard = ((ModalDoubleFacesCard) card).getLeftHalfCard();
                ModalDoubleFacesCardHalf rightHalfCard = ((ModalDoubleFacesCard) card).getRightHalfCard();
                game.getState().getCreateMageObjectAttribute(leftHalfCard, game).getColor().addColor(color);
                game.getState().getCreateMageObjectAttribute(rightHalfCard, game).getColor().addColor(color);
            }
            // split cards
            if (card instanceof SplitCard) {
                SplitCardHalf leftHalfCard = ((SplitCard) card).getLeftHalfCard();
                SplitCardHalf rightHalfCard = ((SplitCard) card).getRightHalfCard();
                game.getState().getCreateMageObjectAttribute(leftHalfCard, game).getColor().addColor(color);
                game.getState().getCreateMageObjectAttribute(rightHalfCard, game).getColor().addColor(color);
            }
            // double faces cards
            if (card.getSecondCardFace() != null) {
                game.getState().getCreateMageObjectAttribute(card.getSecondCardFace(), game).getColor().addColor(color);
            }
        });
        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)

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