Search in sources :

Example 26 with ObjectColor

use of mage.ObjectColor in project mage by magefree.

the class CallToArmsStateTriggeredAbility method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent permanent = game.getPermanent(source.getSourceId());
    UUID playerId = (UUID) game.getState().getValue(source.getSourceId() + ChooseOpponentEffect.VALUE_KEY);
    if (permanent != null) {
        Player opponent = game.getPlayer(playerId);
        if (opponent != null) {
            ObjectColor color = (ObjectColor) game.getState().getValue(permanent.getId() + "_color");
            Condition condition = new MostCommonColorCondition(color, true, new ControllerIdPredicate(playerId));
            if (condition.apply(game, source)) {
                Effect effect = new BoostAllEffect(1, 1, Duration.WhileOnBattlefield, filter, false);
                return effect.apply(game, source);
            }
        }
    }
    return false;
}
Also used : MostCommonColorCondition(mage.abilities.condition.common.MostCommonColorCondition) Condition(mage.abilities.condition.Condition) Player(mage.players.Player) MostCommonColorCondition(mage.abilities.condition.common.MostCommonColorCondition) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Permanent(mage.game.permanent.Permanent) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) ObjectColor(mage.ObjectColor) ChooseColorEffect(mage.abilities.effects.common.ChooseColorEffect) Effect(mage.abilities.effects.Effect) ChooseOpponentEffect(mage.abilities.effects.common.ChooseOpponentEffect) SacrificeSourceEffect(mage.abilities.effects.common.SacrificeSourceEffect) BoostAllEffect(mage.abilities.effects.common.continuous.BoostAllEffect) UUID(java.util.UUID) BoostAllEffect(mage.abilities.effects.common.continuous.BoostAllEffect)

Example 27 with ObjectColor

use of mage.ObjectColor in project mage by magefree.

the class CallToArmsStateTriggeredAbility method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    Permanent permanent = game.getPermanent(getSourceId());
    UUID playerId = (UUID) game.getState().getValue(getSourceId() + ChooseOpponentEffect.VALUE_KEY);
    if (permanent != null) {
        Player opponent = game.getPlayer(playerId);
        if (opponent != null) {
            ObjectColor color = (ObjectColor) game.getState().getValue(permanent.getId() + "_color");
            Condition condition = new MostCommonColorCondition(color, true, new ControllerIdPredicate(playerId));
            return !condition.apply(game, this);
        }
    }
    return false;
}
Also used : MostCommonColorCondition(mage.abilities.condition.common.MostCommonColorCondition) Condition(mage.abilities.condition.Condition) Player(mage.players.Player) MostCommonColorCondition(mage.abilities.condition.common.MostCommonColorCondition) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Permanent(mage.game.permanent.Permanent) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) ObjectColor(mage.ObjectColor) UUID(java.util.UUID)

Example 28 with ObjectColor

use of mage.ObjectColor in project mage by magefree.

the class ChromeMoxManaEffect method produceMana.

@Override
public Mana produceMana(Game game, Ability source) {
    Mana mana = new Mana();
    if (game == null) {
        return mana;
    }
    Permanent permanent = game.getPermanent(source.getSourceId());
    Player player = game.getPlayer(source.getControllerId());
    if (permanent != null && player != null) {
        List<UUID> imprinted = permanent.getImprinted();
        if (imprinted != null && !imprinted.isEmpty()) {
            Card imprintedCard = game.getCard(imprinted.get(0));
            if (imprintedCard != null) {
                Choice choice = new ChoiceColor(true);
                choice.getChoices().clear();
                choice.setMessage("Pick a mana color");
                ObjectColor color = imprintedCard.getColor(game);
                if (color.isBlack()) {
                    choice.getChoices().add("Black");
                }
                if (color.isRed()) {
                    choice.getChoices().add("Red");
                }
                if (color.isBlue()) {
                    choice.getChoices().add("Blue");
                }
                if (color.isGreen()) {
                    choice.getChoices().add("Green");
                }
                if (color.isWhite()) {
                    choice.getChoices().add("White");
                }
                if (!choice.getChoices().isEmpty()) {
                    if (choice.getChoices().size() == 1) {
                        choice.setChoice(choice.getChoices().iterator().next());
                    } else {
                        if (!player.choose(outcome, choice, game)) {
                            return mana;
                        }
                    }
                    switch(choice.getChoice()) {
                        case "Black":
                            // player.getManaPool().addMana(Mana.BlackMana(1), game, source);
                            mana.add(Mana.BlackMana(1));
                            break;
                        case "Blue":
                            // player.getManaPool().addMana(Mana.BlueMana(1), game, source);
                            mana.add(Mana.BlueMana(1));
                            break;
                        case "Red":
                            // player.getManaPool().addMana(Mana.RedMana(1), game, source);
                            mana.add(Mana.RedMana(1));
                            break;
                        case "Green":
                            // player.getManaPool().addMana(Mana.GreenMana(1), game, source);
                            mana.add(Mana.GreenMana(1));
                            break;
                        case "White":
                            // player.getManaPool().addMana(Mana.WhiteMana(1), game, source);
                            mana.add(Mana.WhiteMana(1));
                            break;
                        default:
                            break;
                    }
                }
            }
        }
    }
    return mana;
}
Also used : Player(mage.players.Player) Mana(mage.Mana) Choice(mage.choices.Choice) Permanent(mage.game.permanent.Permanent) ObjectColor(mage.ObjectColor) UUID(java.util.UUID) ChoiceColor(mage.choices.ChoiceColor) TargetCard(mage.target.TargetCard) Card(mage.cards.Card) FilterCard(mage.filter.FilterCard)

Example 29 with ObjectColor

use of mage.ObjectColor in project mage by magefree.

the class GrindstoneEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player targetPlayer = game.getPlayer(this.getTargetPointer().getFirst(game, source));
    if (targetPlayer != null) {
        int possibleIterations = targetPlayer.getLibrary().size() / 2;
        int iteration = 0;
        boolean colorShared;
        do {
            iteration++;
            if (iteration > possibleIterations + 20) {
                // 801.16. If the game somehow enters a "loop" of mandatory actions, repeating a sequence of events
                // with no way to stop, the game is a draw for each player who controls an object that's involved in
                // that loop, as well as for each player within the range of influence of any of those players. They
                // leave the game. All remaining players continue to play the game.
                game.setDraw(source.getControllerId());
                return true;
            }
            colorShared = false;
            List<Card> cards = targetPlayer.millCards(2, source, game).getCards(game).stream().collect(Collectors.toList());
            if (cards.size() < 2) {
                break;
            }
            for (int i = 0; i < cards.size(); i++) {
                if (colorShared) {
                    break;
                }
                ObjectColor color1 = cards.get(i).getColor(game);
                if (color1.isColorless()) {
                    continue;
                }
                for (int j = 0; j < cards.size(); j++) {
                    if (i >= j) {
                        continue;
                    }
                    ObjectColor color2 = cards.get(j).getColor(game);
                    if (color1.shares(color2)) {
                        colorShared = true;
                        break;
                    }
                }
            }
        } while (colorShared);
        return true;
    }
    return false;
}
Also used : TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) ObjectColor(mage.ObjectColor) Card(mage.cards.Card)

Example 30 with ObjectColor

use of mage.ObjectColor in project mage by magefree.

the class HeraldicBannerEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent permanent = game.getPermanent(source.getSourceId());
    if (permanent == null) {
        return false;
    }
    ObjectColor color = (ObjectColor) game.getState().getValue(permanent.getId() + "_color");
    if (color == null) {
        return false;
    }
    for (Permanent perm : game.getBattlefield().getActivePermanents(StaticFilters.FILTER_CONTROLLED_CREATURE, source.getControllerId(), source.getSourceId(), game)) {
        if (perm.getColor(game).contains(color)) {
            perm.addPower(1);
        }
    }
    return true;
}
Also used : Permanent(mage.game.permanent.Permanent) ObjectColor(mage.ObjectColor)

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