Search in sources :

Example 1 with TargetControlledCreaturePermanent

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

the class CracklingDoomEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        List<Permanent> toSacrifice = new ArrayList<>();
        for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
            if (controller.hasOpponent(playerId, game)) {
                Player opponent = game.getPlayer(playerId);
                if (opponent != null) {
                    int greatestPower = Integer.MIN_VALUE;
                    int numberOfCreatures = 0;
                    Permanent permanentToSacrifice = null;
                    for (Permanent permanent : game.getBattlefield().getAllActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, playerId, game)) {
                        if (permanent.getPower().getValue() > greatestPower) {
                            greatestPower = permanent.getPower().getValue();
                            numberOfCreatures = 1;
                            permanentToSacrifice = permanent;
                        } else if (permanent.getPower().getValue() == greatestPower) {
                            numberOfCreatures++;
                        }
                    }
                    if (numberOfCreatures == 1) {
                        if (permanentToSacrifice != null) {
                            toSacrifice.add(permanentToSacrifice);
                        }
                    } else if (greatestPower != Integer.MIN_VALUE) {
                        FilterControlledCreaturePermanent filter = new FilterControlledCreaturePermanent("creature to sacrifice with power equal to " + greatestPower);
                        filter.add(new PowerPredicate(ComparisonType.EQUAL_TO, greatestPower));
                        Target target = new TargetControlledCreaturePermanent(filter);
                        if (opponent.choose(outcome, target, playerId, game)) {
                            Permanent permanent = game.getPermanent(target.getFirstTarget());
                            if (permanent != null) {
                                toSacrifice.add(permanent);
                            }
                        }
                    }
                }
            }
        }
        for (Permanent permanent : toSacrifice) {
            permanent.sacrifice(source, game);
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) Target(mage.target.Target) Permanent(mage.game.permanent.Permanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) ArrayList(java.util.ArrayList) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) PowerPredicate(mage.filter.predicate.mageobject.PowerPredicate) UUID(java.util.UUID) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent)

Example 2 with TargetControlledCreaturePermanent

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

the class GoblinAssassinTriggeredEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    List<UUID> perms = new ArrayList<>();
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
            Player player = game.getPlayer(playerId);
            if (player != null && !player.flipCoin(source, game, false)) {
                TargetControlledCreaturePermanent target = new TargetControlledCreaturePermanent();
                target.setNotTarget(true);
                if (target.canChoose(source.getSourceId(), player.getId(), game)) {
                    player.chooseTarget(Outcome.Sacrifice, target, source, game);
                    perms.addAll(target.getTargets());
                }
            }
        }
        for (UUID permID : perms) {
            Permanent permanent = game.getPermanent(permID);
            if (permanent != null) {
                permanent.sacrifice(source, game);
            }
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) ArrayList(java.util.ArrayList) UUID(java.util.UUID) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent)

Example 3 with TargetControlledCreaturePermanent

use of mage.target.common.TargetControlledCreaturePermanent 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 4 with TargetControlledCreaturePermanent

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

the class HavengulSkaabAbility method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    if (event.getSourceId().equals(this.getSourceId())) {
        TargetControlledCreaturePermanent target = new TargetControlledCreaturePermanent(1, 1, filter, false);
        this.addTarget(target);
        return true;
    }
    return false;
}
Also used : TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent)

Example 5 with TargetControlledCreaturePermanent

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

the class LordOfThePitEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    Permanent sourcePermanent = game.getPermanent(source.getSourceId());
    if (sourcePermanent == null) {
        sourcePermanent = (Permanent) game.getLastKnownInformation(source.getSourceId(), Zone.BATTLEFIELD);
    }
    if (player == null || sourcePermanent == null) {
        return false;
    }
    FilterControlledCreaturePermanent filter = new FilterControlledCreaturePermanent("creature other than " + sourcePermanent.getName());
    filter.add(AnotherPredicate.instance);
    Target target = new TargetControlledCreaturePermanent(1, 1, filter, true);
    if (target.canChoose(source.getSourceId(), player.getId(), game)) {
        player.choose(Outcome.Sacrifice, target, source.getSourceId(), game);
        Permanent permanent = game.getPermanent(target.getFirstTarget());
        if (permanent != null) {
            permanent.sacrifice(source, game);
            return true;
        }
    } else {
        player.damage(7, source.getSourceId(), source, game);
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) Target(mage.target.Target) Permanent(mage.game.permanent.Permanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent)

Aggregations

TargetControlledCreaturePermanent (mage.target.common.TargetControlledCreaturePermanent)78 Player (mage.players.Player)73 Permanent (mage.game.permanent.Permanent)64 Target (mage.target.Target)41 UUID (java.util.UUID)29 FilterControlledCreaturePermanent (mage.filter.common.FilterControlledCreaturePermanent)27 TargetPermanent (mage.target.TargetPermanent)18 ArrayList (java.util.ArrayList)14 Cost (mage.abilities.costs.Cost)10 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)9 SacrificeTargetCost (mage.abilities.costs.common.SacrificeTargetCost)8 FixedTarget (mage.target.targetpointer.FixedTarget)8 Ability (mage.abilities.Ability)6 FilterPermanent (mage.filter.FilterPermanent)6 MageObject (mage.MageObject)5 TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)5 OneShotEffect (mage.abilities.effects.OneShotEffect)4 Card (mage.cards.Card)4 SimpleActivatedAbility (mage.abilities.common.SimpleActivatedAbility)3 SimpleStaticAbility (mage.abilities.common.SimpleStaticAbility)3