Search in sources :

Example 91 with Ability

use of mage.abilities.Ability in project mage by magefree.

the class HandOfVecnaEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null || player.getHand().size() < 1) {
        return false;
    }
    Permanent sourcePermanent = source.getSourcePermanentIfItStillExists(game);
    Permanent equipped = game.getPermanent(sourcePermanent != null ? sourcePermanent.getAttachedTo() : null);
    List<Permanent> chooseable = game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game);
    if (equipped != null) {
        chooseable.add(equipped);
    }
    Permanent toBoost;
    switch(chooseable.size()) {
        case 0:
            return false;
        case 1:
            toBoost = chooseable.get(0);
            break;
        default:
            FilterPermanent filter = new FilterPermanent("a creature to give +X/+X to");
            filter.add(Predicates.or(chooseable.stream().map(permanent -> new MageObjectReferencePredicate(permanent, game)).collect(Collectors.toList())));
            TargetPermanent target = new TargetPermanent(filter);
            target.setNotTarget(true);
            player.choose(outcome, target, source.getSourceId(), game);
            toBoost = game.getPermanent(target.getFirstTarget());
    }
    int xValue = player.getHand().size();
    game.addEffect(new BoostTargetEffect(xValue, xValue, Duration.EndOfTurn).setTargetPointer(new FixedTarget(toBoost, game)), source);
    return true;
}
Also used : BeginningOfCombatTriggeredAbility(mage.abilities.common.BeginningOfCombatTriggeredAbility) BoostTargetEffect(mage.abilities.effects.common.continuous.BoostTargetEffect) CardsInControllerHandCount(mage.abilities.dynamicvalue.common.CardsInControllerHandCount) PayLifeCost(mage.abilities.costs.common.PayLifeCost) EquipAbility(mage.abilities.keyword.EquipAbility) OneShotEffect(mage.abilities.effects.OneShotEffect) Predicates(mage.filter.predicate.Predicates) MageObjectReferencePredicate(mage.filter.predicate.mageobject.MageObjectReferencePredicate) UUID(java.util.UUID) FilterPermanent(mage.filter.FilterPermanent) Collectors(java.util.stream.Collectors) Player(mage.players.Player) FixedTarget(mage.target.targetpointer.FixedTarget) CardSetInfo(mage.cards.CardSetInfo) Game(mage.game.Game) List(java.util.List) CardImpl(mage.cards.CardImpl) Permanent(mage.game.permanent.Permanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) mage.constants(mage.constants) NamePredicate(mage.filter.predicate.mageobject.NamePredicate) TargetPermanent(mage.target.TargetPermanent) Ability(mage.abilities.Ability) FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) FilterPermanent(mage.filter.FilterPermanent) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) MageObjectReferencePredicate(mage.filter.predicate.mageobject.MageObjectReferencePredicate) BoostTargetEffect(mage.abilities.effects.common.continuous.BoostTargetEffect) TargetPermanent(mage.target.TargetPermanent)

Example 92 with Ability

use of mage.abilities.Ability in project mage by magefree.

the class HankyuCost method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent permanent = source.getSourcePermanentIfItStillExists(game);
    if (permanent == null) {
        return false;
    }
    Permanent creature = game.getPermanent(permanent.getAttachedTo());
    if (creature == null) {
        return false;
    }
    creature.addAbility(new SimpleActivatedAbility(new AddCountersTargetEffect(CounterType.AIM.createInstance()).setTargetPointer(new FixedTarget(permanent, game)).setText("put an aim counter on " + permanent.getName()), new TapSourceCost()), source.getSourceId(), game);
    Ability ability = new SimpleActivatedAbility(new DamageTargetEffect(HankyuValue.instance).setText("this creature deals damage to any target equal " + "to the number of aim counters removed this way"), new TapSourceCost());
    ability.addCost(new HankyuCost().setMageObjectReference(source, game));
    ability.addTarget(new TargetAnyTarget());
    creature.addAbility(ability, source.getSourceId(), game);
    return true;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) SimpleActivatedAbility(mage.abilities.common.SimpleActivatedAbility) SimpleStaticAbility(mage.abilities.common.SimpleStaticAbility) EquipAbility(mage.abilities.keyword.EquipAbility) Ability(mage.abilities.Ability) Permanent(mage.game.permanent.Permanent) SimpleActivatedAbility(mage.abilities.common.SimpleActivatedAbility) DamageTargetEffect(mage.abilities.effects.common.DamageTargetEffect) AddCountersTargetEffect(mage.abilities.effects.common.counter.AddCountersTargetEffect) TapSourceCost(mage.abilities.costs.common.TapSourceCost) TargetAnyTarget(mage.target.common.TargetAnyTarget)

Example 93 with Ability

use of mage.abilities.Ability in project mage by magefree.

the class HushwingGryffEffect method getInfoMessage.

@Override
public String getInfoMessage(Ability source, GameEvent event, Game game) {
    MageObject enteringObject = game.getObject(event.getSourceId());
    MageObject sourceObject = game.getObject(source.getSourceId());
    Ability ability = (Ability) getValue("targetAbility");
    if (enteringObject != null && sourceObject != null && ability != null) {
        MageObject abilitObject = game.getObject(ability.getSourceId());
        if (abilitObject != null) {
            return sourceObject.getLogName() + " prevented ability of " + abilitObject.getLogName() + " to trigger for " + enteringObject.getLogName() + " entering the battlefield.";
        }
    }
    return null;
}
Also used : SimpleStaticAbility(mage.abilities.common.SimpleStaticAbility) FlashAbility(mage.abilities.keyword.FlashAbility) TriggeredAbility(mage.abilities.TriggeredAbility) FlyingAbility(mage.abilities.keyword.FlyingAbility) Ability(mage.abilities.Ability) MageObject(mage.MageObject)

Example 94 with Ability

use of mage.abilities.Ability in project mage by magefree.

the class KethisTheHiddenHandGraveyardEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    controller.getGraveyard().getCards(game).stream().filter(card -> affectedObjectList.stream().anyMatch(mor -> mor.refersTo(card, game))).forEach(card -> {
        Ability ability = new SimpleStaticAbility(Zone.GRAVEYARD, new KethisTheHiddenHandGraveyardEffect());
        ability.setSourceId(card.getId());
        ability.setControllerId(card.getOwnerId());
        game.getState().addOtherAbility(card, ability);
    });
    return true;
}
Also used : FilterCard(mage.filter.FilterCard) SimpleActivatedAbility(mage.abilities.common.SimpleActivatedAbility) SimpleStaticAbility(mage.abilities.common.SimpleStaticAbility) TargetCardInYourGraveyard(mage.target.common.TargetCardInYourGraveyard) MageObjectReference(mage.MageObjectReference) UUID(java.util.UUID) MageInt(mage.MageInt) Player(mage.players.Player) CardSetInfo(mage.cards.CardSetInfo) Objects(java.util.Objects) ContinuousEffectImpl(mage.abilities.effects.ContinuousEffectImpl) Game(mage.game.Game) AsThoughEffectImpl(mage.abilities.effects.AsThoughEffectImpl) CardImpl(mage.cards.CardImpl) SpellsCostReductionControllerEffect(mage.abilities.effects.common.cost.SpellsCostReductionControllerEffect) Card(mage.cards.Card) mage.constants(mage.constants) ExileFromGraveCost(mage.abilities.costs.common.ExileFromGraveCost) Ability(mage.abilities.Ability) SimpleActivatedAbility(mage.abilities.common.SimpleActivatedAbility) SimpleStaticAbility(mage.abilities.common.SimpleStaticAbility) Ability(mage.abilities.Ability) Player(mage.players.Player) SimpleStaticAbility(mage.abilities.common.SimpleStaticAbility)

Example 95 with Ability

use of mage.abilities.Ability in project mage by magefree.

the class MindreaverExileEffect method canTarget.

@Override
public boolean canTarget(UUID id, Ability source, Game game) {
    Spell spell = game.getSpell(id);
    ExileZone exileZone = game.getExile().getExileZone(CardUtil.getExileZoneId(game, source));
    return super.canTarget(id, source, game) && spell != null && exileZone != null && !exileZone.isEmpty() && exileZone.getCards(game).stream().filter(Objects::nonNull).anyMatch(card -> CardUtil.haveSameNames(spell, card));
}
Also used : CounterTargetEffect(mage.abilities.effects.common.CounterTargetEffect) SubType(mage.constants.SubType) Player(mage.players.Player) CardType(mage.constants.CardType) Spell(mage.game.stack.Spell) TargetSpell(mage.target.TargetSpell) HeroicAbility(mage.abilities.keyword.HeroicAbility) SimpleActivatedAbility(mage.abilities.common.SimpleActivatedAbility) SacrificeSourceCost(mage.abilities.costs.common.SacrificeSourceCost) Cards(mage.cards.Cards) Outcome(mage.constants.Outcome) OneShotEffect(mage.abilities.effects.OneShotEffect) CardUtil(mage.util.CardUtil) TargetPlayer(mage.target.TargetPlayer) UUID(java.util.UUID) MageInt(mage.MageInt) CardsImpl(mage.cards.CardsImpl) CardSetInfo(mage.cards.CardSetInfo) FilterSpell(mage.filter.FilterSpell) Objects(java.util.Objects) ManaCostsImpl(mage.abilities.costs.mana.ManaCostsImpl) Game(mage.game.Game) ExileZone(mage.game.ExileZone) CardImpl(mage.cards.CardImpl) Ability(mage.abilities.Ability) Objects(java.util.Objects) ExileZone(mage.game.ExileZone) Spell(mage.game.stack.Spell) TargetSpell(mage.target.TargetSpell) FilterSpell(mage.filter.FilterSpell)

Aggregations

Ability (mage.abilities.Ability)359 Player (mage.players.Player)173 Permanent (mage.game.permanent.Permanent)134 UUID (java.util.UUID)126 Game (mage.game.Game)123 OneShotEffect (mage.abilities.effects.OneShotEffect)98 SimpleStaticAbility (mage.abilities.common.SimpleStaticAbility)87 CardSetInfo (mage.cards.CardSetInfo)87 CardImpl (mage.cards.CardImpl)85 CardType (mage.constants.CardType)78 Outcome (mage.constants.Outcome)76 Card (mage.cards.Card)72 SimpleActivatedAbility (mage.abilities.common.SimpleActivatedAbility)64 MageObject (mage.MageObject)57 MageInt (mage.MageInt)47 SpellAbility (mage.abilities.SpellAbility)43 Objects (java.util.Objects)38 Zone (mage.constants.Zone)38 mage.constants (mage.constants)37 FilterCard (mage.filter.FilterCard)35