Search in sources :

Example 21 with GainAbilitySourceEffect

use of mage.abilities.effects.common.continuous.GainAbilitySourceEffect in project mage by magefree.

the class VeteranWarleaderEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourceObject = game.getObject(source.getSourceId());
    if (sourceObject != null && controller != null) {
        Choice abilityChoice = new ChoiceImpl();
        abilityChoice.setMessage("Choose an ability to add");
        Set<String> abilities = new HashSet<>();
        abilities.add(FirstStrikeAbility.getInstance().getRule());
        abilities.add(VigilanceAbility.getInstance().getRule());
        abilities.add(TrampleAbility.getInstance().getRule());
        abilityChoice.setChoices(abilities);
        if (!controller.choose(Outcome.AddAbility, abilityChoice, game)) {
            return false;
        }
        String chosen = abilityChoice.getChoice();
        Ability ability = null;
        if (FirstStrikeAbility.getInstance().getRule().equals(chosen)) {
            ability = FirstStrikeAbility.getInstance();
        } else if (VigilanceAbility.getInstance().getRule().equals(chosen)) {
            ability = VigilanceAbility.getInstance();
        } else if (TrampleAbility.getInstance().getRule().equals(chosen)) {
            ability = TrampleAbility.getInstance();
        }
        if (ability != null) {
            game.informPlayers(sourceObject.getLogName() + ": " + controller.getLogName() + " has chosen: " + chosen);
            ContinuousEffect effect = new GainAbilitySourceEffect(ability, Duration.EndOfTurn);
            game.addEffect(effect, source);
            return true;
        }
    }
    return false;
}
Also used : SimpleStaticAbility(mage.abilities.common.SimpleStaticAbility) VigilanceAbility(mage.abilities.keyword.VigilanceAbility) FirstStrikeAbility(mage.abilities.keyword.FirstStrikeAbility) SimpleActivatedAbility(mage.abilities.common.SimpleActivatedAbility) TrampleAbility(mage.abilities.keyword.TrampleAbility) Ability(mage.abilities.Ability) Player(mage.players.Player) Choice(mage.choices.Choice) GainAbilitySourceEffect(mage.abilities.effects.common.continuous.GainAbilitySourceEffect) MageObject(mage.MageObject) ChoiceImpl(mage.choices.ChoiceImpl) ContinuousEffect(mage.abilities.effects.ContinuousEffect) HashSet(java.util.HashSet)

Example 22 with GainAbilitySourceEffect

use of mage.abilities.effects.common.continuous.GainAbilitySourceEffect in project mage by magefree.

the class JeweledSpiritEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    ChoiceColorOrArtifact choice = new ChoiceColorOrArtifact();
    if (controller != null && controller.choose(outcome, choice, game)) {
        FilterCard protectionFilter = new FilterCard();
        if (choice.isArtifactSelected()) {
            protectionFilter.add(CardType.ARTIFACT.getPredicate());
        } else {
            protectionFilter.add(new ColorPredicate(choice.getColor()));
        }
        protectionFilter.setMessage(choice.getChoice());
        ProtectionAbility protectionAbility = new ProtectionAbility(protectionFilter);
        ContinuousEffect effect = new GainAbilitySourceEffect(protectionAbility, Duration.EndOfTurn);
        game.addEffect(effect, source);
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) ColorPredicate(mage.filter.predicate.mageobject.ColorPredicate) ChoiceColorOrArtifact(mage.choices.ChoiceColorOrArtifact) Player(mage.players.Player) GainAbilitySourceEffect(mage.abilities.effects.common.continuous.GainAbilitySourceEffect) ProtectionAbility(mage.abilities.keyword.ProtectionAbility) ContinuousEffect(mage.abilities.effects.ContinuousEffect)

Example 23 with GainAbilitySourceEffect

use of mage.abilities.effects.common.continuous.GainAbilitySourceEffect in project mage by magefree.

the class SungoldSentinelEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    ChoiceColor choice = new ChoiceColor(true);
    player.choose(outcome, choice, game);
    Ability ability = HexproofBaseAbility.getFirstFromColor(choice.getColor());
    game.addEffect(new GainAbilitySourceEffect(ability, Duration.EndOfTurn), source);
    FilterCreaturePermanent filter = new FilterCreaturePermanent();
    filter.add(new ColorPredicate(choice.getColor()));
    game.addEffect(new CantBeBlockedByAllSourceEffect(filter, Duration.EndOfTurn), source);
    return true;
}
Also used : EntersBattlefieldOrAttacksSourceTriggeredAbility(mage.abilities.common.EntersBattlefieldOrAttacksSourceTriggeredAbility) ConditionalActivatedAbility(mage.abilities.decorator.ConditionalActivatedAbility) HexproofBaseAbility(mage.abilities.keyword.HexproofBaseAbility) Ability(mage.abilities.Ability) ColorPredicate(mage.filter.predicate.mageobject.ColorPredicate) Player(mage.players.Player) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) CantBeBlockedByAllSourceEffect(mage.abilities.effects.common.combat.CantBeBlockedByAllSourceEffect) GainAbilitySourceEffect(mage.abilities.effects.common.continuous.GainAbilitySourceEffect) ChoiceColor(mage.choices.ChoiceColor)

Example 24 with GainAbilitySourceEffect

use of mage.abilities.effects.common.continuous.GainAbilitySourceEffect in project mage by magefree.

the class TemurSabertoothEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Target target = new TargetPermanent(1, 1, filter, true);
        if (target.canChoose(source.getSourceId(), controller.getId(), game)) {
            if (controller.chooseUse(outcome, "Return another creature to hand?", source, game) && controller.chooseTarget(outcome, target, source, game)) {
                Permanent toHand = game.getPermanent(target.getFirstTarget());
                if (toHand != null) {
                    controller.moveCards(toHand, Zone.HAND, source, game);
                }
                game.addEffect(new GainAbilitySourceEffect(IndestructibleAbility.getInstance(), Duration.EndOfTurn), source);
            }
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) Target(mage.target.Target) Permanent(mage.game.permanent.Permanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) GainAbilitySourceEffect(mage.abilities.effects.common.continuous.GainAbilitySourceEffect) TargetPermanent(mage.target.TargetPermanent)

Example 25 with GainAbilitySourceEffect

use of mage.abilities.effects.common.continuous.GainAbilitySourceEffect in project mage by magefree.

the class ThunderousOratorEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    List<Ability> abilities = new ArrayList<>();
    if (game.getBattlefield().count(filter, source.getSourceId(), source.getControllerId(), game) > 0) {
        abilities.add(new MenaceAbility());
    }
    game.getBattlefield().getActivePermanents(StaticFilters.FILTER_CONTROLLED_CREATURE, source.getControllerId(), source.getSourceId(), game).stream().filter(Objects::nonNull).map(p -> p.getAbilities(game)).flatMap(Collection::stream).filter(keywords::contains).distinct().forEach(abilities::add);
    if (abilities.isEmpty()) {
        return false;
    }
    for (Ability ability : abilities) {
        game.addEffect(new GainAbilitySourceEffect(ability, Duration.EndOfTurn), source);
    }
    return true;
}
Also used : AttacksTriggeredAbility(mage.abilities.common.AttacksTriggeredAbility) Ability(mage.abilities.Ability) GainAbilitySourceEffect(mage.abilities.effects.common.continuous.GainAbilitySourceEffect)

Aggregations

GainAbilitySourceEffect (mage.abilities.effects.common.continuous.GainAbilitySourceEffect)33 Player (mage.players.Player)21 Permanent (mage.game.permanent.Permanent)11 Ability (mage.abilities.Ability)9 MageObject (mage.MageObject)7 SimpleActivatedAbility (mage.abilities.common.SimpleActivatedAbility)6 ChoiceImpl (mage.choices.ChoiceImpl)6 ContinuousEffect (mage.abilities.effects.ContinuousEffect)5 Choice (mage.choices.Choice)5 BoostSourceEffect (mage.abilities.effects.common.continuous.BoostSourceEffect)4 SimpleStaticAbility (mage.abilities.common.SimpleStaticAbility)3 FirstStrikeAbility (mage.abilities.keyword.FirstStrikeAbility)3 FlyingAbility (mage.abilities.keyword.FlyingAbility)3 HasteAbility (mage.abilities.keyword.HasteAbility)3 TrampleAbility (mage.abilities.keyword.TrampleAbility)3 HashSet (java.util.HashSet)2 AddCardSubTypeSourceEffect (mage.abilities.effects.common.continuous.AddCardSubTypeSourceEffect)2 SetPowerToughnessSourceEffect (mage.abilities.effects.common.continuous.SetPowerToughnessSourceEffect)2 ProtectionAbility (mage.abilities.keyword.ProtectionAbility)2 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)2