Search in sources :

Example 1 with TargetAnyTarget

use of mage.target.common.TargetAnyTarget in project mage by magefree.

the class HeartPiercerManticoreSacrificeEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    Target target = new TargetControlledCreaturePermanent(1, 1, StaticFilters.FILTER_CONTROLLED_ANOTHER_CREATURE, true);
    if (!controller.choose(outcome, target, source.getSourceId(), game)) {
        return false;
    }
    Permanent toSacrifice = game.getPermanent(target.getFirstTarget());
    if (toSacrifice == null) {
        return false;
    }
    int power = toSacrifice.getPower().getValue();
    if (!toSacrifice.sacrifice(source, game)) {
        return false;
    }
    ReflexiveTriggeredAbility trigger = new ReflexiveTriggeredAbility(new DamageTargetEffect(power), false, "{this} deals damage equal to that creature's power to any target.");
    trigger.addTarget(new TargetAnyTarget());
    game.fireReflexiveTriggeredAbility(trigger, source);
    return true;
}
Also used : Player(mage.players.Player) Target(mage.target.Target) TargetAnyTarget(mage.target.common.TargetAnyTarget) Permanent(mage.game.permanent.Permanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) ReflexiveTriggeredAbility(mage.abilities.common.delayed.ReflexiveTriggeredAbility) DamageTargetEffect(mage.abilities.effects.common.DamageTargetEffect) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) TargetAnyTarget(mage.target.common.TargetAnyTarget)

Example 2 with TargetAnyTarget

use of mage.target.common.TargetAnyTarget in project mage by magefree.

the class SpareDaggerEffect method makeAbility.

@Override
protected Ability makeAbility(Game game, Ability source) {
    if (source == null || game == null) {
        return null;
    }
    String sourceName = source.getSourcePermanentIfItStillExists(game).getName();
    ReflexiveTriggeredAbility ability = new ReflexiveTriggeredAbility(new DamageTargetEffect(1), false, "This creature deals 1 damage to any target");
    ability.addTarget(new TargetAnyTarget());
    return new AttacksTriggeredAbility(new DoWhenCostPaid(ability, useAttachedCost.copy().setMageObjectReference(source, game), "Sacrifice " + sourceName + "?"), false, "Whenever this creature attacks, you may sacrifice " + sourceName + ". When you do, this creature deals 1 damage to any target.");
}
Also used : DoWhenCostPaid(mage.abilities.effects.common.DoWhenCostPaid) ReflexiveTriggeredAbility(mage.abilities.common.delayed.ReflexiveTriggeredAbility) AttacksTriggeredAbility(mage.abilities.common.AttacksTriggeredAbility) DamageTargetEffect(mage.abilities.effects.common.DamageTargetEffect) TargetAnyTarget(mage.target.common.TargetAnyTarget)

Example 3 with TargetAnyTarget

use of mage.target.common.TargetAnyTarget in project mage by magefree.

the class LeylineTyrantDamageEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    int costX = player.announceXMana(0, Integer.MAX_VALUE, "Announce the value for {X}", game, source);
    String manaString;
    if (costX == 0) {
        manaString = "{0}";
    } else {
        manaString = "";
        for (int i = 0; i < costX; i++) {
            manaString += "{R}";
        }
    }
    Cost cost = new ManaCostsImpl<>(manaString);
    cost.clearPaid();
    if (!cost.pay(source, game, source, source.getControllerId(), false)) {
        return false;
    }
    ReflexiveTriggeredAbility ability = new ReflexiveTriggeredAbility(new DamageTargetEffect(costX), false, "{this} deals " + costX + " damage to any target");
    ability.addTarget(new TargetAnyTarget());
    game.fireReflexiveTriggeredAbility(ability, source);
    return true;
}
Also used : Player(mage.players.Player) ReflexiveTriggeredAbility(mage.abilities.common.delayed.ReflexiveTriggeredAbility) DamageTargetEffect(mage.abilities.effects.common.DamageTargetEffect) Cost(mage.abilities.costs.Cost) ManaCostsImpl(mage.abilities.costs.mana.ManaCostsImpl) TargetAnyTarget(mage.target.common.TargetAnyTarget)

Example 4 with TargetAnyTarget

use of mage.target.common.TargetAnyTarget in project mage by magefree.

the class MartyrdomRedirectDamageTargetEffect method applies.

@Override
public boolean applies(GameEvent event, Ability source, Game game) {
    Permanent permanent = game.getBattlefield().getPermanent(source.getSourceId());
    if (permanent != null) {
        if (filter.match(permanent, permanent.getId(), permanent.getControllerId(), game)) {
            if (event.getTargetId().equals(getTargetPointer().getFirst(game, source))) {
                if (event.getTargetId() != null) {
                    TargetAnyTarget target = new TargetAnyTarget();
                    target.add(source.getSourceId(), game);
                    redirectTarget = target;
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : Permanent(mage.game.permanent.Permanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) TargetAnyTarget(mage.target.common.TargetAnyTarget)

Example 5 with TargetAnyTarget

use of mage.target.common.TargetAnyTarget in project mage by magefree.

the class ToralfsHammerEffect method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    DamagedEvent dEvent = (DamagedEvent) event;
    if (dEvent.getExcess() < 1 || dEvent.isCombatDamage() || !game.getOpponents(getControllerId()).contains(game.getControllerId(event.getTargetId()))) {
        return false;
    }
    this.getEffects().clear();
    this.getTargets().clear();
    this.addEffect(new DamageTargetEffect(dEvent.getExcess()));
    FilterCreaturePlayerOrPlaneswalker filter = new FilterCreaturePlayerOrPlaneswalker();
    filter.getPermanentFilter().add(Predicates.not(new MageObjectReferencePredicate(new MageObjectReference(event.getTargetId(), game))));
    this.addTarget(new TargetAnyTarget(filter));
    return true;
}
Also used : DamagedEvent(mage.game.events.DamagedEvent) FilterCreaturePlayerOrPlaneswalker(mage.filter.common.FilterCreaturePlayerOrPlaneswalker) MageObjectReferencePredicate(mage.filter.predicate.mageobject.MageObjectReferencePredicate) DamageTargetEffect(mage.abilities.effects.common.DamageTargetEffect) MageObjectReference(mage.MageObjectReference) TargetAnyTarget(mage.target.common.TargetAnyTarget)

Aggregations

TargetAnyTarget (mage.target.common.TargetAnyTarget)23 DamageTargetEffect (mage.abilities.effects.common.DamageTargetEffect)20 ReflexiveTriggeredAbility (mage.abilities.common.delayed.ReflexiveTriggeredAbility)11 Permanent (mage.game.permanent.Permanent)9 Player (mage.players.Player)8 Ability (mage.abilities.Ability)7 SimpleActivatedAbility (mage.abilities.common.SimpleActivatedAbility)7 ManaCostsImpl (mage.abilities.costs.mana.ManaCostsImpl)6 SimpleManaAbility (mage.abilities.mana.SimpleManaAbility)4 Test (org.junit.Test)4 SimpleStaticAbility (mage.abilities.common.SimpleStaticAbility)3 Card (mage.cards.Card)3 TapSourceCost (mage.abilities.costs.common.TapSourceCost)2 CounterUnlessPaysEffect (mage.abilities.effects.common.CounterUnlessPaysEffect)2 AddConditionalManaEffect (mage.abilities.effects.mana.AddConditionalManaEffect)2 SimpleActivatedAbilityManaBuilder (mage.abilities.mana.builder.common.SimpleActivatedAbilityManaBuilder)2 Target (mage.target.Target)2 TargetPermanent (mage.target.TargetPermanent)2 TargetSpell (mage.target.TargetSpell)2 TargetControlledCreaturePermanent (mage.target.common.TargetControlledCreaturePermanent)2