Search in sources :

Example 61 with TargetControlledCreaturePermanent

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

the class RakdosRiteknifeEffect method makeAbility.

private static Ability makeAbility(Permanent permanent, Game game) {
    Ability ability = new SimpleActivatedAbility(new AddCountersTargetEffect(CounterType.BLOOD.createInstance()).setText("put a blood counter on " + permanent.getName()).setTargetPointer(new FixedTarget(permanent, game)), new TapSourceCost());
    ability.addCost(new SacrificeTargetCost(new TargetControlledCreaturePermanent(FILTER_CONTROLLED_CREATURE_SHORT_TEXT)));
    return ability;
}
Also used : SimpleStaticAbility(mage.abilities.common.SimpleStaticAbility) EquipAbility(mage.abilities.keyword.EquipAbility) SimpleActivatedAbility(mage.abilities.common.SimpleActivatedAbility) Ability(mage.abilities.Ability) FixedTarget(mage.target.targetpointer.FixedTarget) SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost) SimpleActivatedAbility(mage.abilities.common.SimpleActivatedAbility) AddCountersTargetEffect(mage.abilities.effects.common.counter.AddCountersTargetEffect) TapSourceCost(mage.abilities.costs.common.TapSourceCost) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent)

Example 62 with TargetControlledCreaturePermanent

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

the class RampageOfTheValkyriesEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    List<UUID> perms = new ArrayList<>();
    for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
        Player player = game.getPlayer(playerId);
        if (player == null || player.getId().equals(source.getControllerId())) {
            continue;
        }
        TargetPermanent target = new TargetControlledCreaturePermanent();
        target.setNotTarget(true);
        if (!target.canChoose(source.getSourceId(), playerId, game)) {
            continue;
        }
        player.choose(outcome, target, source.getSourceId(), game);
        perms.add(target.getFirstTarget());
    }
    for (UUID permID : perms) {
        Permanent permanent = game.getPermanent(permID);
        if (permanent != null) {
            permanent.sacrifice(source, game);
        }
    }
    return true;
}
Also used : Player(mage.players.Player) FilterPermanent(mage.filter.FilterPermanent) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Permanent(mage.game.permanent.Permanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) ArrayList(java.util.ArrayList) TargetPermanent(mage.target.TargetPermanent) UUID(java.util.UUID) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent)

Example 63 with TargetControlledCreaturePermanent

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

the class ReignOfThePitEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    int totalPowerSacrificed = 0;
    List<UUID> perms = new ArrayList<>();
    for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
        Player player = game.getPlayer(playerId);
        if (player != null) {
            TargetControlledCreaturePermanent target = new TargetControlledCreaturePermanent(1, 1, new FilterControlledCreaturePermanent(), true);
            if (target.canChoose(source.getSourceId(), player.getId(), game)) {
                while (!target.isChosen() && player.canRespond()) {
                    player.choose(Outcome.Sacrifice, target, source.getSourceId(), game);
                }
                perms.addAll(target.getTargets());
            }
        }
    }
    for (UUID permID : perms) {
        Permanent permanent = game.getPermanent(permID);
        if (permanent != null) {
            int power = permanent.getPower().getValue();
            if (permanent.sacrifice(source, game)) {
                totalPowerSacrificed += power;
            }
        }
    }
    new CreateTokenEffect(new DemonFlyingToken(totalPowerSacrificed)).apply(game, source);
    return true;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) ArrayList(java.util.ArrayList) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) CreateTokenEffect(mage.abilities.effects.common.CreateTokenEffect) UUID(java.util.UUID) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) DemonFlyingToken(mage.game.permanent.token.DemonFlyingToken)

Example 64 with TargetControlledCreaturePermanent

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

the class FinalityEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    Target target = new TargetControlledCreaturePermanent(0, 1);
    target.setNotTarget(true);
    if (player.choose(Outcome.BoostCreature, target, source.getSourceId(), game)) {
        Effect effect = new AddCountersTargetEffect(CounterType.P1P1.createInstance(2));
        effect.setTargetPointer(new FixedTarget(target.getFirstTarget(), game));
        effect.apply(game, source);
    }
    game.addEffect(new BoostAllEffect(-4, -4, Duration.EndOfTurn), source);
    return true;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) Target(mage.target.Target) FixedTarget(mage.target.targetpointer.FixedTarget) AddCountersTargetEffect(mage.abilities.effects.common.counter.AddCountersTargetEffect) OneShotEffect(mage.abilities.effects.OneShotEffect) ReturnFromGraveyardToHandTargetEffect(mage.abilities.effects.common.ReturnFromGraveyardToHandTargetEffect) Effect(mage.abilities.effects.Effect) BoostAllEffect(mage.abilities.effects.common.continuous.BoostAllEffect) BoostAllEffect(mage.abilities.effects.common.continuous.BoostAllEffect) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) AddCountersTargetEffect(mage.abilities.effects.common.counter.AddCountersTargetEffect)

Example 65 with TargetControlledCreaturePermanent

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

the class FrayingOmnipotenceEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    // Each player loses half of their life,
    for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
        Player player = game.getPlayer(playerId);
        if (player == null) {
            continue;
        }
        int lifeToLose = (int) Math.ceil(player.getLife() / 2.0);
        player.loseLife(lifeToLose, game, source, false);
    }
    // then discards half of the cards in their hand,
    for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
        Player player = game.getPlayer(playerId);
        if (player == null) {
            continue;
        }
        int cardsToDiscard = (int) Math.ceil(player.getHand().size() / 2.0);
        if (cardsToDiscard > 0) {
            player.discard(cardsToDiscard, false, false, source, game);
        }
    }
    // then sacrifices half of the creatures they control,
    for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
        Player player = game.getPlayer(playerId);
        if (player == null) {
            continue;
        }
        FilterControlledCreaturePermanent filter = new FilterControlledCreaturePermanent();
        int creaturesToSacrifice = (int) Math.ceil(game.getBattlefield().count(filter, source.getSourceId(), player.getId(), game) / 2.0);
        if (creaturesToSacrifice == 0) {
            continue;
        }
        Target target = new TargetControlledCreaturePermanent(creaturesToSacrifice, creaturesToSacrifice, filter, true);
        target.chooseTarget(Outcome.Sacrifice, playerId, source, game);
        for (UUID permanentId : target.getTargets()) {
            Permanent permanent = game.getPermanent(permanentId);
            if (permanent != null) {
                permanent.sacrifice(source, game);
            }
        }
    }
    return true;
}
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) UUID(java.util.UUID) 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