Search in sources :

Example 46 with FilterControlledCreaturePermanent

use of mage.filter.common.FilterControlledCreaturePermanent in project mage by magefree.

the class ExploitEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Target target = new TargetPermanent(1, 1, new FilterControlledCreaturePermanent("creature to exploit"), true);
        if (target.canChoose(source.getSourceId(), controller.getId(), game)) {
            controller.chooseTarget(Outcome.Sacrifice, target, source, game);
            Permanent permanent = game.getPermanent(target.getFirstTarget());
            if (permanent != null) {
                if (permanent.sacrifice(source, game)) {
                    game.fireEvent(GameEvent.getEvent(GameEvent.EventType.EXPLOITED_CREATURE, permanent.getId(), source, controller.getId()));
                }
            }
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) Target(mage.target.Target) Permanent(mage.game.permanent.Permanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) TargetPermanent(mage.target.TargetPermanent)

Example 47 with FilterControlledCreaturePermanent

use of mage.filter.common.FilterControlledCreaturePermanent in project mage by magefree.

the class EntrapmentManeuverSacrificeEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(targetPointer.getFirst(game, source));
    if (player == null) {
        return false;
    }
    FilterControlledCreaturePermanent filter = new FilterControlledCreaturePermanent();
    filter.add(AttackingPredicate.instance);
    int realCount = game.getBattlefield().countAll(filter, player.getId(), game);
    if (realCount > 0) {
        Target target = new TargetControlledPermanent(1, 1, filter, true);
        while (player.canRespond() && !target.isChosen() && target.canChoose(source.getSourceId(), player.getId(), game)) {
            player.chooseTarget(Outcome.Sacrifice, target, source, game);
        }
        Permanent permanent = game.getPermanent(target.getFirstTarget());
        if (permanent != null) {
            int amount = permanent.getToughness().getValue();
            permanent.sacrifice(source, game);
            new CreateTokenEffect(new SoldierToken(), amount).apply(game, source);
        } else {
            return false;
        }
    }
    return true;
}
Also used : TargetControlledPermanent(mage.target.common.TargetControlledPermanent) SoldierToken(mage.game.permanent.token.SoldierToken) TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) Target(mage.target.Target) Permanent(mage.game.permanent.Permanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) CreateTokenEffect(mage.abilities.effects.common.CreateTokenEffect)

Example 48 with FilterControlledCreaturePermanent

use of mage.filter.common.FilterControlledCreaturePermanent in project mage by magefree.

the class GarrukPrimalHunterEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player != null) {
        int amount = 0;
        for (Permanent p : game.getBattlefield().getActivePermanents(new FilterControlledCreaturePermanent(), source.getControllerId(), game)) {
            if (p.getPower().getValue() > amount) {
                amount = p.getPower().getValue();
            }
        }
        player.drawCards(amount, source, game);
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Permanent(mage.game.permanent.Permanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) FilterControlledLandPermanent(mage.filter.common.FilterControlledLandPermanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent)

Example 49 with FilterControlledCreaturePermanent

use of mage.filter.common.FilterControlledCreaturePermanent in project mage by magefree.

the class ChromaLightFromWithinCount method apply.

@Override
public boolean apply(Game game, Ability source) {
    for (Permanent creature : game.getBattlefield().getAllActivePermanents(new FilterControlledCreaturePermanent(), source.getControllerId(), game)) {
        if (creature != null) {
            Player controller = game.getPlayer(source.getControllerId());
            if (controller != null) {
                creature.addPower(new ChromaLightFromWithinCount(creature).calculate(game, source, this));
                creature.addToughness(new ChromaLightFromWithinCount(creature).calculate(game, source, this));
                boosted = true;
            }
        }
    }
    return boosted;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent)

Example 50 with FilterControlledCreaturePermanent

use of mage.filter.common.FilterControlledCreaturePermanent in project mage by magefree.

the class MaskwoodNexusEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    // in graveyard
    for (UUID cardId : controller.getGraveyard()) {
        Card card = game.getCard(cardId);
        if (card != null && card.isCreature(game)) {
            game.getState().getCreateMageObjectAttribute(card, game).getSubtype().setIsAllCreatureTypes(true);
        }
    }
    // on Hand
    for (UUID cardId : controller.getHand()) {
        Card card = game.getCard(cardId);
        if (card != null && card.isCreature(game)) {
            game.getState().getCreateMageObjectAttribute(card, game).getSubtype().setIsAllCreatureTypes(true);
        }
    }
    // in Exile
    for (Card card : game.getState().getExile().getAllCards(game)) {
        if (card.isCreature(game) && card.isOwnedBy(controller.getId())) {
            game.getState().getCreateMageObjectAttribute(card, game).getSubtype().setIsAllCreatureTypes(true);
        }
    }
    // in Library (e.g. for Mystical Teachings)
    for (Card card : controller.getLibrary().getCards(game)) {
        if (card.isOwnedBy(controller.getId()) && card.isCreature(game)) {
            game.getState().getCreateMageObjectAttribute(card, game).getSubtype().setIsAllCreatureTypes(true);
        }
    }
    // commander in command zone
    for (CommandObject commandObject : game.getState().getCommand()) {
        if (!(commandObject instanceof Commander)) {
            continue;
        }
        Card card = game.getCard(((Commander) commandObject).getId());
        if (card != null && card.isOwnedBy(controller.getId()) && card.isCreature(game)) {
            game.getState().getCreateMageObjectAttribute(card, game).getSubtype().setIsAllCreatureTypes(true);
        }
    }
    // creature spells you control
    for (Iterator<StackObject> iterator = game.getStack().iterator(); iterator.hasNext(); ) {
        StackObject stackObject = iterator.next();
        if (stackObject instanceof Spell && stackObject.isControlledBy(source.getControllerId()) && stackObject.isCreature(game)) {
            Card card = ((Spell) stackObject).getCard();
            game.getState().getCreateMageObjectAttribute(card, game).getSubtype().setIsAllCreatureTypes(true);
        }
    }
    // creatures you control
    List<Permanent> creatures = game.getBattlefield().getAllActivePermanents(new FilterControlledCreaturePermanent(), source.getControllerId(), game);
    for (Permanent creature : creatures) {
        if (creature != null) {
            creature.setIsAllCreatureTypes(game, true);
        }
    }
    return true;
}
Also used : CommandObject(mage.game.command.CommandObject) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) Commander(mage.game.command.Commander) StackObject(mage.game.stack.StackObject) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) UUID(java.util.UUID) Spell(mage.game.stack.Spell) Card(mage.cards.Card)

Aggregations

FilterControlledCreaturePermanent (mage.filter.common.FilterControlledCreaturePermanent)75 Permanent (mage.game.permanent.Permanent)62 Player (mage.players.Player)60 UUID (java.util.UUID)29 Target (mage.target.Target)27 TargetControlledCreaturePermanent (mage.target.common.TargetControlledCreaturePermanent)21 TargetControlledPermanent (mage.target.common.TargetControlledPermanent)16 ArrayList (java.util.ArrayList)13 Card (mage.cards.Card)11 TargetPermanent (mage.target.TargetPermanent)11 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)10 FixedTarget (mage.target.targetpointer.FixedTarget)9 MageObject (mage.MageObject)7 OneShotEffect (mage.abilities.effects.OneShotEffect)7 Effect (mage.abilities.effects.Effect)6 Ability (mage.abilities.Ability)5 PermanentsOnBattlefieldCount (mage.abilities.dynamicvalue.common.PermanentsOnBattlefieldCount)5 FilterPermanent (mage.filter.FilterPermanent)5 ControllerIdPredicate (mage.filter.predicate.permanent.ControllerIdPredicate)5 Spell (mage.game.stack.Spell)5