Search in sources :

Example 61 with TargetCreaturePermanent

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

the class TigerTribeHunterEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    TargetPermanent target = new TargetPermanent(0, 1, StaticFilters.FILTER_CONTROLLED_ANOTHER_CREATURE, true);
    player.choose(outcome, target, source.getSourceId(), game);
    Permanent permanent = game.getPermanent(target.getFirstTarget());
    if (permanent == null) {
        return false;
    }
    int power = Math.max(permanent.getPower().getValue(), 0);
    if (!permanent.sacrifice(source, game)) {
        return false;
    }
    ReflexiveTriggeredAbility ability = new ReflexiveTriggeredAbility(new DamageTargetEffect(power), false, "{this} deals damage equal to the sacrificed creature's power to target creature.");
    ability.addTarget(new TargetCreaturePermanent());
    game.fireReflexiveTriggeredAbility(ability, source);
    return true;
}
Also used : TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) ReflexiveTriggeredAbility(mage.abilities.common.delayed.ReflexiveTriggeredAbility) TargetPermanent(mage.target.TargetPermanent) DamageTargetEffect(mage.abilities.effects.common.DamageTargetEffect)

Example 62 with TargetCreaturePermanent

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

the class GodsendRuleModifyingEffect method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    Permanent equipment = game.getPermanentOrLKIBattlefield((this.getSourceId()));
    if (equipment != null && equipment.getAttachedTo() != null) {
        Permanent equippedPermanent = game.getPermanentOrLKIBattlefield((equipment.getAttachedTo()));
        if (equippedPermanent != null) {
            possibleTargets.clear();
            String targetName = "";
            if (equippedPermanent.isAttacking()) {
                for (CombatGroup group : game.getCombat().getGroups()) {
                    if (group.getAttackers().contains(equippedPermanent.getId())) {
                        possibleTargets.addAll(group.getBlockers());
                    }
                }
                targetName = "a creature blocking attacker ";
            } else if (equippedPermanent.getBlocking() > 0) {
                for (CombatGroup group : game.getCombat().getGroups()) {
                    if (group.getBlockers().contains(equippedPermanent.getId())) {
                        possibleTargets.addAll(group.getAttackers());
                    }
                }
                targetName = "a creature blocked by creature ";
            }
            if (!possibleTargets.isEmpty()) {
                this.getTargets().clear();
                if (possibleTargets.size() == 1) {
                    this.getEffects().get(0).setTargetPointer(new FixedTarget(possibleTargets.iterator().next(), game));
                } else {
                    this.getEffects().get(0).setTargetPointer(new FirstTargetPointer());
                    targetName = targetName + " equipped by " + equipment.getName();
                    FilterCreaturePermanent filter = new FilterCreaturePermanent(targetName);
                    List<PermanentIdPredicate> uuidPredicates = new ArrayList<>();
                    for (UUID creatureId : possibleTargets) {
                        uuidPredicates.add(new PermanentIdPredicate(creatureId));
                    }
                    filter.add(Predicates.or(uuidPredicates));
                    this.getTargets().add(new TargetCreaturePermanent(filter));
                }
                return true;
            }
        }
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) PermanentIdPredicate(mage.filter.predicate.permanent.PermanentIdPredicate) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) FirstTargetPointer(mage.target.targetpointer.FirstTargetPointer) CombatGroup(mage.game.combat.CombatGroup)

Example 63 with TargetCreaturePermanent

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

the class ImpetuousDevilsAbility method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    if (event.getSourceId().equals(this.getSourceId())) {
        FilterCreaturePermanent filter = new FilterCreaturePermanent("creature defending player controls");
        UUID defenderId = game.getCombat().getDefendingPlayerId(sourceId, game);
        filter.add(new ControllerIdPredicate(defenderId));
        this.getTargets().clear();
        TargetCreaturePermanent target = new TargetCreaturePermanent(0, 1, filter, false);
        this.addTarget(target);
        return true;
    }
    return false;
}
Also used : TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) UUID(java.util.UUID)

Example 64 with TargetCreaturePermanent

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

the class SiegeStrikerEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    int tappedAmount = 0;
    TargetCreaturePermanent target = new TargetCreaturePermanent(0, Integer.MAX_VALUE, filter, true);
    if (target.canChoose(source.getSourceId(), source.getControllerId(), game) && target.choose(Outcome.Tap, source.getControllerId(), source.getSourceId(), game)) {
        for (UUID creatureId : target.getTargets()) {
            Permanent creature = game.getPermanent(creatureId);
            if (creature != null) {
                creature.tap(source, game);
                tappedAmount++;
            }
        }
    }
    if (tappedAmount > 0) {
        game.addEffect(new BoostSourceEffect(tappedAmount, tappedAmount, Duration.EndOfTurn), source);
        return true;
    }
    return false;
}
Also used : BoostSourceEffect(mage.abilities.effects.common.continuous.BoostSourceEffect) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) UUID(java.util.UUID)

Example 65 with TargetCreaturePermanent

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

the class ProvokeRequirementEffect method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    if (super.checkTrigger(event, game)) {
        FilterCreaturePermanent filter = new FilterCreaturePermanent("creature defending player controls");
        UUID defendingPlayerId = game.getCombat().getDefendingPlayerId(sourceId, game);
        filter.add(new ControllerIdPredicate(defendingPlayerId));
        this.getTargets().clear();
        TargetCreaturePermanent target = new TargetCreaturePermanent(filter);
        this.addTarget(target);
        return true;
    }
    return false;
}
Also used : TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) UUID(java.util.UUID)

Aggregations

TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)71 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)59 Player (mage.players.Player)49 ControllerIdPredicate (mage.filter.predicate.permanent.ControllerIdPredicate)37 Permanent (mage.game.permanent.Permanent)35 UUID (java.util.UUID)25 Target (mage.target.Target)18 FixedTarget (mage.target.targetpointer.FixedTarget)18 Effect (mage.abilities.effects.Effect)8 ContinuousEffect (mage.abilities.effects.ContinuousEffect)7 OneShotEffect (mage.abilities.effects.OneShotEffect)7 GainControlTargetEffect (mage.abilities.effects.common.continuous.GainControlTargetEffect)6 Card (mage.cards.Card)6 DamagedPlayerEvent (mage.game.events.DamagedPlayerEvent)6 ArrayList (java.util.ArrayList)5 Ability (mage.abilities.Ability)5 MageObject (mage.MageObject)4 GainAbilityTargetEffect (mage.abilities.effects.common.continuous.GainAbilityTargetEffect)4 PermanentIdPredicate (mage.filter.predicate.permanent.PermanentIdPredicate)4 RestrictionEffect (mage.abilities.effects.RestrictionEffect)3