Search in sources :

Example 6 with TargetPermanent

use of mage.target.TargetPermanent in project mage by magefree.

the class HazduhrTheAbbotRedirectDamageEffect 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) {
                    TargetPermanent target = new TargetPermanent();
                    target.add(source.getSourceId(), game);
                    redirectTarget = target;
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : Permanent(mage.game.permanent.Permanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) TargetPermanent(mage.target.TargetPermanent)

Example 7 with TargetPermanent

use of mage.target.TargetPermanent in project mage by magefree.

the class LucilleEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent equipment = game.getPermanent(source.getSourceId());
    if (equipment == null) {
        return false;
    }
    Player player = game.getPlayer(game.getCombat().getDefendingPlayerId(equipment.getAttachedTo(), game));
    if (player == null) {
        return false;
    }
    TargetPermanent target = new TargetControlledCreaturePermanent();
    target.setNotTarget(true);
    if (!target.canChoose(source.getSourceId(), player.getId(), game)) {
        return false;
    }
    player.choose(outcome, target, source.getSourceId(), game);
    Permanent permanent = game.getPermanent(target.getFirstTarget());
    return permanent.sacrifice(source, game) && new WalkerToken().putOntoBattlefield(1, game, source, source.getControllerId());
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) WalkerToken(mage.game.permanent.token.WalkerToken) TargetPermanent(mage.target.TargetPermanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent)

Example 8 with TargetPermanent

use of mage.target.TargetPermanent in project mage by magefree.

the class MyrBattlesphereEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Permanent myr = game.getPermanentOrLKIBattlefield(source.getSourceId());
        int tappedAmount = 0;
        TargetPermanent target = new TargetPermanent(0, 1, filter, true);
        while (controller.canRespond()) {
            target.clearChosen();
            if (target.canChoose(source.getSourceId(), source.getControllerId(), game)) {
                Map<String, Serializable> options = new HashMap<>();
                options.put("UI.right.btn.text", "Myr tapping complete");
                controller.choose(outcome, target, source.getControllerId(), game, options);
                if (!target.getTargets().isEmpty()) {
                    UUID creature = target.getFirstTarget();
                    if (creature != null) {
                        game.getPermanent(creature).tap(source, game);
                        tappedAmount++;
                    }
                } else {
                    break;
                }
            } else {
                break;
            }
        }
        if (tappedAmount > 0) {
            game.informPlayers(controller.getLogName() + " taps " + tappedAmount + " Myrs");
            // boost effect
            game.addEffect(new BoostSourceEffect(tappedAmount, 0, Duration.EndOfTurn), source);
            // damage to defender
            return game.damagePlayerOrPlaneswalker(targetPointer.getFirst(game, source), tappedAmount, myr.getId(), source, game, false, true) > 0;
        }
        return true;
    }
    return false;
}
Also used : BoostSourceEffect(mage.abilities.effects.common.continuous.BoostSourceEffect) Player(mage.players.Player) Serializable(java.io.Serializable) Permanent(mage.game.permanent.Permanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) HashMap(java.util.HashMap) TargetPermanent(mage.target.TargetPermanent) UUID(java.util.UUID)

Example 9 with TargetPermanent

use of mage.target.TargetPermanent in project mage by magefree.

the class PurgingScytheEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent sourcePermanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
    if (controller != null && sourcePermanent != null) {
        int leastToughness = Integer.MAX_VALUE;
        boolean multipleExist = false;
        Permanent permanentToDamage = null;
        for (Permanent permanent : game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURES, source.getControllerId(), game)) {
            if (permanent.getToughness().getValue() < leastToughness) {
                permanentToDamage = permanent;
                leastToughness = permanent.getToughness().getValue();
                multipleExist = false;
            } else {
                if (permanent.getToughness().getValue() == leastToughness) {
                    multipleExist = true;
                }
            }
        }
        if (multipleExist) {
            FilterCreaturePermanent filter = new FilterCreaturePermanent("one of the creatures with the least toughness");
            filter.add(new ToughnessPredicate(ComparisonType.EQUAL_TO, leastToughness));
            Target target = new TargetPermanent(filter);
            target.setNotTarget(true);
            if (target.canChoose(source.getSourceId(), source.getControllerId(), game)) {
                if (controller.choose(outcome, target, source.getSourceId(), game)) {
                    permanentToDamage = game.getPermanent(target.getFirstTarget());
                }
            }
        }
        if (permanentToDamage != null) {
            game.informPlayers(sourcePermanent.getName() + " chosen creature: " + permanentToDamage.getName());
            return permanentToDamage.damage(2, source.getSourceId(), source, game, false, true) > 0;
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) ToughnessPredicate(mage.filter.predicate.mageobject.ToughnessPredicate) Target(mage.target.Target) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Permanent(mage.game.permanent.Permanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) TargetPermanent(mage.target.TargetPermanent)

Example 10 with TargetPermanent

use of mage.target.TargetPermanent in project mage by magefree.

the class RescuerSphinxEffect 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, "Return a nonland permanent you control to your hand?", source, game)) {
        return false;
    }
    Target target = new TargetPermanent(0, 1, filter, true);
    if (!player.choose(outcome, target, source.getSourceId(), game)) {
        return false;
    }
    Permanent permanent = game.getPermanent(target.getFirstTarget());
    if (permanent == null || !player.moveCards(permanent, Zone.HAND, source, game)) {
        return false;
    }
    return new AddCountersSourceEffect(CounterType.P1P1.createInstance()).apply(game, source);
}
Also used : AddCountersSourceEffect(mage.abilities.effects.common.counter.AddCountersSourceEffect) Player(mage.players.Player) Target(mage.target.Target) FilterPermanent(mage.filter.FilterPermanent) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) TargetPermanent(mage.target.TargetPermanent)

Aggregations

TargetPermanent (mage.target.TargetPermanent)222 Player (mage.players.Player)173 Permanent (mage.game.permanent.Permanent)167 FilterPermanent (mage.filter.FilterPermanent)108 UUID (java.util.UUID)65 Target (mage.target.Target)58 ControllerIdPredicate (mage.filter.predicate.permanent.ControllerIdPredicate)47 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)36 FilterControlledPermanent (mage.filter.common.FilterControlledPermanent)32 FilterControlledCreaturePermanent (mage.filter.common.FilterControlledCreaturePermanent)24 TargetControlledCreaturePermanent (mage.target.common.TargetControlledCreaturePermanent)19 TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)19 FixedTarget (mage.target.targetpointer.FixedTarget)19 MageObject (mage.MageObject)18 Ability (mage.abilities.Ability)18 Card (mage.cards.Card)17 ArrayList (java.util.ArrayList)15 ReflexiveTriggeredAbility (mage.abilities.common.delayed.ReflexiveTriggeredAbility)14 PermanentIdPredicate (mage.filter.predicate.permanent.PermanentIdPredicate)14 OneShotEffect (mage.abilities.effects.OneShotEffect)13