Search in sources :

Example 51 with ObjectColor

use of mage.ObjectColor in project mage by magefree.

the class ConvokeEffect method getManaOptions.

@Override
public ManaOptions getManaOptions(Ability source, Game game, ManaCost unpaid) {
    ManaOptions options = new ManaOptions();
    FilterControlledCreaturePermanent filterBasic = new FilterControlledCreaturePermanent();
    // each creature can give {1} or color mana
    game.getBattlefield().getActivePermanents(filterBasic, source.getControllerId(), source.getSourceId(), game).stream().filter(permanent -> !permanent.isTapped()).forEach(permanent -> {
        ManaOptions permMana = new ManaOptions();
        permMana.add(Mana.GenericMana(1));
        for (ObjectColor color : permanent.getColor(game).getColors()) {
            if (color.isBlack())
                permMana.add(Mana.BlackMana(1));
            if (color.isBlue())
                permMana.add(Mana.BlueMana(1));
            if (color.isGreen())
                permMana.add(Mana.GreenMana(1));
            if (color.isRed())
                permMana.add(Mana.RedMana(1));
            if (color.isWhite())
                permMana.add(Mana.WhiteMana(1));
        }
        options.addMana(permMana);
    });
    options.removeDuplicated();
    return options;
}
Also used : Target(mage.target.Target) SimpleStaticAbility(mage.abilities.common.SimpleStaticAbility) Zone(mage.constants.Zone) SpecialAction(mage.abilities.SpecialAction) TappedPredicate(mage.filter.predicate.permanent.TappedPredicate) Predicates(mage.filter.predicate.Predicates) Player(mage.players.Player) ArrayList(java.util.ArrayList) ManaOptions(mage.abilities.mana.ManaOptions) ValueHint(mage.abilities.hint.ValueHint) AbilityType(mage.constants.AbilityType) ManaPool(mage.players.ManaPool) ManaCost(mage.abilities.costs.mana.ManaCost) Locale(java.util.Locale) ManaType(mage.constants.ManaType) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) ColorPredicate(mage.filter.predicate.mageobject.ColorPredicate) Spell(mage.game.stack.Spell) ObjectColor(mage.ObjectColor) ChoiceColor(mage.choices.ChoiceColor) Choice(mage.choices.Choice) ActivationManaAbilityStep(mage.abilities.costs.mana.ActivationManaAbilityStep) AlternateManaPaymentAbility(mage.abilities.costs.mana.AlternateManaPaymentAbility) Outcome(mage.constants.Outcome) OneShotEffect(mage.abilities.effects.OneShotEffect) UUID(java.util.UUID) Game(mage.game.Game) List(java.util.List) GameEvent(mage.game.events.GameEvent) Permanent(mage.game.permanent.Permanent) PermanentsOnBattlefieldCount(mage.abilities.dynamicvalue.common.PermanentsOnBattlefieldCount) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) Mana(mage.Mana) Ability(mage.abilities.Ability) ManaOptions(mage.abilities.mana.ManaOptions) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) ObjectColor(mage.ObjectColor)

Example 52 with ObjectColor

use of mage.ObjectColor in project mage by magefree.

the class BecomesColorOrColorsEnchantedEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent enchantment = game.getPermanentOrLKIBattlefield(source.getSourceId());
    if (enchantment == null) {
        return false;
    }
    Permanent permanent = game.getPermanent(enchantment.getAttachedTo());
    StringBuilder sb = new StringBuilder();
    if (controller == null || permanent == null) {
        return false;
    }
    for (int i = 0; i < 5; i++) {
        if (i > 0) {
            if (!controller.chooseUse(Outcome.Neutral, "Choose another color?", source, game)) {
                break;
            }
        }
        ChoiceColor choiceColor = new ChoiceColor();
        if (!controller.choose(Outcome.Benefit, choiceColor, game)) {
            return false;
        }
        if (!game.isSimulation()) {
            game.informPlayers(permanent.getName() + ": " + controller.getLogName() + " has chosen " + choiceColor.getChoice());
        }
        if (choiceColor.getColor().isBlack()) {
            sb.append('B');
        } else if (choiceColor.getColor().isBlue()) {
            sb.append('U');
        } else if (choiceColor.getColor().isRed()) {
            sb.append('R');
        } else if (choiceColor.getColor().isGreen()) {
            sb.append('G');
        } else if (choiceColor.getColor().isWhite()) {
            sb.append('W');
        }
    }
    String colors = new String(sb);
    ObjectColor chosenColors = new ObjectColor(colors);
    ContinuousEffect effect = new BecomesColorTargetEffect(chosenColors, Duration.Custom);
    effect.setTargetPointer(new FixedTarget(permanent, game));
    game.addEffect(effect, source);
    return true;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) BecomesColorTargetEffect(mage.abilities.effects.common.continuous.BecomesColorTargetEffect) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) ObjectColor(mage.ObjectColor) ContinuousEffect(mage.abilities.effects.ContinuousEffect) ChoiceColor(mage.choices.ChoiceColor)

Example 53 with ObjectColor

use of mage.ObjectColor in project mage by magefree.

the class EmptyShrineKannushiProtectionAbility method canTarget.

@Override
public boolean canTarget(MageObject source, Game game) {
    ObjectColor color = new ObjectColor();
    for (Permanent permanent : game.getBattlefield().getAllActivePermanents(controllerId)) {
        ObjectColor permanentColor = permanent.getColor(game);
        if (permanentColor.isColorless()) {
            continue;
        }
        if (permanentColor.isBlack()) {
            color.setBlack(true);
        }
        if (permanentColor.isBlue()) {
            color.setBlue(true);
        }
        if (permanentColor.isGreen()) {
            color.setGreen(true);
        }
        if (permanentColor.isRed()) {
            color.setRed(true);
        }
        if (permanentColor.isWhite()) {
            color.setWhite(true);
        }
    }
    List<Predicate<MageObject>> colorPredicates = new ArrayList<>();
    if (color.isBlack()) {
        colorPredicates.add(new ColorPredicate(ObjectColor.BLACK));
    }
    if (color.isBlue()) {
        colorPredicates.add(new ColorPredicate(ObjectColor.BLUE));
    }
    if (color.isGreen()) {
        colorPredicates.add(new ColorPredicate(ObjectColor.GREEN));
    }
    if (color.isRed()) {
        colorPredicates.add(new ColorPredicate(ObjectColor.RED));
    }
    if (color.isWhite()) {
        colorPredicates.add(new ColorPredicate(ObjectColor.WHITE));
    }
    Filter protectionFilter = new FilterObject("the colors of permanents you control");
    protectionFilter.add(Predicates.or(colorPredicates));
    this.filter = protectionFilter;
    return super.canTarget(source, game);
}
Also used : ColorPredicate(mage.filter.predicate.mageobject.ColorPredicate) Permanent(mage.game.permanent.Permanent) Filter(mage.filter.Filter) FilterObject(mage.filter.FilterObject) ObjectColor(mage.ObjectColor) ArrayList(java.util.ArrayList) Predicate(mage.filter.predicate.Predicate) ColorPredicate(mage.filter.predicate.mageobject.ColorPredicate)

Example 54 with ObjectColor

use of mage.ObjectColor in project mage by magefree.

the class GauntletOfPowerManaEffect2 method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    TappedForManaEvent mEvent = (TappedForManaEvent) event;
    Permanent permanent = mEvent.getPermanent();
    if (permanent == null || !permanent.isLand() || !permanent.isBasic()) {
        return false;
    }
    ObjectColor color = (ObjectColor) game.getState().getValue(getSourceId() + "_color");
    if (color == null) {
        return false;
    }
    Mana mana = mEvent.getMana();
    if ((!color.isBlack() || mana.getBlack() < 1) && (!color.isBlue() || mana.getBlue() < 1) && (!color.isGreen() || mana.getGreen() < 1) && (!color.isWhite() || mana.getWhite() < 1) && (!color.isRed() || mana.getRed() < 1)) {
        return false;
    }
    getEffects().setValue("mana", mEvent.getMana());
    getEffects().setTargetPointer(new FixedTarget(permanent, game));
    return true;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Mana(mage.Mana) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Permanent(mage.game.permanent.Permanent) ObjectColor(mage.ObjectColor) TappedForManaEvent(mage.game.events.TappedForManaEvent)

Example 55 with ObjectColor

use of mage.ObjectColor in project mage by magefree.

the class TabletOfTheGuildsGainLifeEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player you = game.getPlayer(source.getControllerId());
    if (you != null) {
        Spell spell = game.getStack().getSpell(this.getTargetPointer().getFirst(game, source));
        if (spell != null) {
            ObjectColor color1 = new ObjectColor((String) game.getState().getValue(source.getSourceId() + "_color1"));
            ObjectColor color2 = new ObjectColor((String) game.getState().getValue(source.getSourceId() + "_color2"));
            int amount = 0;
            if (spell.getColor(game).contains(color1)) {
                ++amount;
            }
            if (spell.getColor(game).contains(color2)) {
                ++amount;
            }
            if (amount > 0) {
                you.gainLife(amount, game, source);
                return true;
            }
        }
    }
    return false;
}
Also used : Player(mage.players.Player) ObjectColor(mage.ObjectColor) FilterSpell(mage.filter.FilterSpell) 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