Search in sources :

Example 1 with ChoiceColor

use of mage.choices.ChoiceColor 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 ChoiceColor

use of mage.choices.ChoiceColor in project mage by magefree.

the class CorruptedGrafstoneManaEffect method produceMana.

@Override
public Mana produceMana(Game game, Ability source) {
    Mana mana = new Mana();
    if (game == null) {
        return mana;
    }
    Mana types = getManaTypesInGraveyard(game, source);
    Choice choice = new ChoiceColor(true);
    choice.getChoices().clear();
    choice.setMessage("Pick a mana color");
    if (types.getBlack() > 0) {
        choice.getChoices().add("Black");
    }
    if (types.getRed() > 0) {
        choice.getChoices().add("Red");
    }
    if (types.getBlue() > 0) {
        choice.getChoices().add("Blue");
    }
    if (types.getGreen() > 0) {
        choice.getChoices().add("Green");
    }
    if (types.getWhite() > 0) {
        choice.getChoices().add("White");
    }
    if (!choice.getChoices().isEmpty()) {
        Player player = game.getPlayer(source.getControllerId());
        if (player != null) {
            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":
                    mana.setBlack(1);
                    break;
                case "Blue":
                    mana.setBlue(1);
                    break;
                case "Red":
                    mana.setRed(1);
                    break;
                case "Green":
                    mana.setGreen(1);
                    break;
                case "White":
                    mana.setWhite(1);
                    break;
            }
        }
    }
    return mana;
}
Also used : Player(mage.players.Player) Mana(mage.Mana) Choice(mage.choices.Choice) ChoiceColor(mage.choices.ChoiceColor)

Example 3 with ChoiceColor

use of mage.choices.ChoiceColor in project mage by magefree.

the class SehtsTigerEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject mageObject = game.getObject(source.getSourceId());
    ChoiceColor choice = new ChoiceColor();
    if (controller != null && mageObject != null && controller.choose(Outcome.Protect, choice, game)) {
        game.informPlayers(mageObject.getLogName() + ": " + controller.getLogName() + " has chosen " + choice.getChoice());
        FilterCard filter = new FilterCard();
        filter.add(new ColorPredicate(choice.getColor()));
        filter.setMessage(choice.getChoice());
        Ability ability = new ProtectionAbility(filter);
        game.addEffect(new GainAbilityControllerEffect(ability, Duration.EndOfTurn), source);
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) ColorPredicate(mage.filter.predicate.mageobject.ColorPredicate) EntersBattlefieldTriggeredAbility(mage.abilities.common.EntersBattlefieldTriggeredAbility) FlashAbility(mage.abilities.keyword.FlashAbility) ProtectionAbility(mage.abilities.keyword.ProtectionAbility) Ability(mage.abilities.Ability) Player(mage.players.Player) MageObject(mage.MageObject) ProtectionAbility(mage.abilities.keyword.ProtectionAbility) ChoiceColor(mage.choices.ChoiceColor) GainAbilityControllerEffect(mage.abilities.effects.common.continuous.GainAbilityControllerEffect)

Example 4 with ChoiceColor

use of mage.choices.ChoiceColor in project mage by magefree.

the class ConditionalManaEffect method produceMana.

@Override
public Mana produceMana(Game game, Ability source) {
    Mana mana = new Mana();
    if (game == null) {
        return mana;
    }
    if (condition.apply(game, source)) {
        mana = effect.getManaTemplate().copy();
    } else if (otherwiseEffect != null) {
        mana = otherwiseEffect.getManaTemplate().copy();
    }
    if (mana.getAny() > 0) {
        int amount = mana.getAny();
        Player controller = game.getPlayer(source.getControllerId());
        if (controller == null) {
            return mana;
        }
        ChoiceColor choice = new ChoiceColor(true);
        if (controller.choose(outcome, choice, game)) {
            mana.setAny(0);
            mana.add(choice.getMana(amount));
        }
    }
    return mana;
}
Also used : Player(mage.players.Player) Mana(mage.Mana) ChoiceColor(mage.choices.ChoiceColor)

Example 5 with ChoiceColor

use of mage.choices.ChoiceColor in project mage by magefree.

the class FaithsShieldEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject mageObject = game.getObject(source.getSourceId());
    if (controller != null && mageObject != null) {
        if (FatefulHourCondition.instance.apply(game, source)) {
            ChoiceColor choice = new ChoiceColor();
            if (!controller.choose(Outcome.Protect, choice, game)) {
                return false;
            }
            if (choice.getColor() != null) {
                game.informPlayers(mageObject.getLogName() + ": " + controller.getLogName() + " has chosen " + choice.getChoice());
                FilterCard filter = new FilterCard();
                filter.add(new ColorPredicate(choice.getColor()));
                filter.setMessage(choice.getChoice());
                Ability ability = new ProtectionAbility(filter);
                game.addEffect(new GainAbilityControlledEffect(ability, Duration.EndOfTurn), source);
                game.addEffect(new GainAbilityControllerEffect(ability, Duration.EndOfTurn), source);
                return true;
            }
        } else {
            game.addEffect(new GainProtectionFromColorTargetEffect(Duration.EndOfTurn), source);
            return true;
        }
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) ColorPredicate(mage.filter.predicate.mageobject.ColorPredicate) ProtectionAbility(mage.abilities.keyword.ProtectionAbility) Ability(mage.abilities.Ability) Player(mage.players.Player) GainProtectionFromColorTargetEffect(mage.abilities.effects.common.continuous.GainProtectionFromColorTargetEffect) GainAbilityControlledEffect(mage.abilities.effects.common.continuous.GainAbilityControlledEffect) MageObject(mage.MageObject) ProtectionAbility(mage.abilities.keyword.ProtectionAbility) ChoiceColor(mage.choices.ChoiceColor) GainAbilityControllerEffect(mage.abilities.effects.common.continuous.GainAbilityControllerEffect)

Aggregations

ChoiceColor (mage.choices.ChoiceColor)54 Player (mage.players.Player)52 Mana (mage.Mana)22 Permanent (mage.game.permanent.Permanent)17 ColorPredicate (mage.filter.predicate.mageobject.ColorPredicate)14 Choice (mage.choices.Choice)10 ObjectColor (mage.ObjectColor)8 FilterCard (mage.filter.FilterCard)7 MageObject (mage.MageObject)5 FilterPermanent (mage.filter.FilterPermanent)5 FixedTarget (mage.target.targetpointer.FixedTarget)5 ConditionalMana (mage.ConditionalMana)4 ContinuousEffect (mage.abilities.effects.ContinuousEffect)4 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)4 Ability (mage.abilities.Ability)3 ProtectionAbility (mage.abilities.keyword.ProtectionAbility)3 Card (mage.cards.Card)3 TargetPlayer (mage.target.TargetPlayer)3 TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)3 ArrayList (java.util.ArrayList)2