Search in sources :

Example 1 with ProtectionAbility

use of mage.abilities.keyword.ProtectionAbility 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 2 with ProtectionAbility

use of mage.abilities.keyword.ProtectionAbility 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)

Example 3 with ProtectionAbility

use of mage.abilities.keyword.ProtectionAbility in project mage by magefree.

the class GiverOfRunesEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    if (player.chooseUse(outcome, "Give the targeted creature protection from colorless?", null, "Yes", "No (choose a color instead)", source, game)) {
        game.addEffect(new GainAbilityTargetEffect(new ProtectionAbility(filter), Duration.EndOfTurn), source);
        return true;
    }
    game.addEffect(new GainProtectionFromColorTargetEffect(Duration.EndOfTurn), source);
    return true;
}
Also used : Player(mage.players.Player) GainProtectionFromColorTargetEffect(mage.abilities.effects.common.continuous.GainProtectionFromColorTargetEffect) GainAbilityTargetEffect(mage.abilities.effects.common.continuous.GainAbilityTargetEffect) ProtectionAbility(mage.abilities.keyword.ProtectionAbility)

Example 4 with ProtectionAbility

use of mage.abilities.keyword.ProtectionAbility in project mage by magefree.

the class RidersOfGavonyGainAbilityControlledEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    if (protectionFilter == null) {
        Permanent permanent = game.getPermanent(source.getSourceId());
        if (permanent != null) {
            SubType subType = ChooseCreatureTypeEffect.getChosenCreatureType(permanent.getId(), game);
            if (subType != null) {
                protectionFilter = new FilterPermanent(subType.getDescription() + 's');
                protectionFilter.add(subType.getPredicate());
            } else {
                discard();
            }
        }
    }
    if (protectionFilter != null) {
        for (Permanent perm : game.getBattlefield().getAllActivePermanents(filter, source.getControllerId(), game)) {
            perm.addAbility(new ProtectionAbility(protectionFilter), source.getSourceId(), game);
        }
        return true;
    }
    return false;
}
Also used : FilterPermanent(mage.filter.FilterPermanent) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) ProtectionAbility(mage.abilities.keyword.ProtectionAbility)

Example 5 with ProtectionAbility

use of mage.abilities.keyword.ProtectionAbility in project mage by magefree.

the class GainProtectionFromColorTargetEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent creature = game.getPermanent(getTargetPointer().getFirst(game, source));
    if (creature != null) {
        FilterCard protectionFilter = (FilterCard) ((ProtectionAbility) ability).getFilter();
        protectionFilter.add(new ColorPredicate(choice.getColor()));
        protectionFilter.setMessage(choice.getChoice());
        ((ProtectionAbility) ability).setFilter(protectionFilter);
        creature.addAbility(ability, source.getSourceId(), game);
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) ColorPredicate(mage.filter.predicate.mageobject.ColorPredicate) Permanent(mage.game.permanent.Permanent) ProtectionAbility(mage.abilities.keyword.ProtectionAbility)

Aggregations

ProtectionAbility (mage.abilities.keyword.ProtectionAbility)24 ColorPredicate (mage.filter.predicate.mageobject.ColorPredicate)14 Permanent (mage.game.permanent.Permanent)13 FilterCard (mage.filter.FilterCard)12 Player (mage.players.Player)10 ObjectColor (mage.ObjectColor)7 Ability (mage.abilities.Ability)7 GainAbilityControllerEffect (mage.abilities.effects.common.continuous.GainAbilityControllerEffect)4 FilterObject (mage.filter.FilterObject)4 ContinuousEffect (mage.abilities.effects.ContinuousEffect)3 GainAbilityControlledEffect (mage.abilities.effects.common.continuous.GainAbilityControlledEffect)3 GainAbilityTargetEffect (mage.abilities.effects.common.continuous.GainAbilityTargetEffect)3 GainProtectionFromColorTargetEffect (mage.abilities.effects.common.continuous.GainProtectionFromColorTargetEffect)3 FlyingAbility (mage.abilities.keyword.FlyingAbility)3 ChoiceColor (mage.choices.ChoiceColor)3 FilterPermanent (mage.filter.FilterPermanent)3 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)3 ArrayList (java.util.ArrayList)2 MageObject (mage.MageObject)2 EntersBattlefieldTriggeredAbility (mage.abilities.common.EntersBattlefieldTriggeredAbility)2