Search in sources :

Example 6 with FilterControlledCreaturePermanent

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

the class NomadMythmakerEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Card aura = game.getCard(source.getFirstTarget());
    if (controller == null || aura == null) {
        return false;
    }
    FilterControlledCreaturePermanent FILTER = new FilterControlledCreaturePermanent("Choose a creature you control");
    TargetControlledPermanent target = new TargetControlledPermanent(FILTER);
    target.setNotTarget(true);
    if (controller.choose(Outcome.PutCardInPlay, target, source.getSourceId(), game)) {
        Permanent permanent = game.getPermanent(target.getFirstTarget());
        if (permanent != null && !permanent.cantBeAttachedBy(aura, source, game, false)) {
            game.getState().setValue("attachTo:" + aura.getId(), permanent);
            controller.moveCards(aura, Zone.BATTLEFIELD, source, game);
            return permanent.addAttachment(aura.getId(), source, game);
        }
    }
    return false;
}
Also used : TargetControlledPermanent(mage.target.common.TargetControlledPermanent) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) FilterCard(mage.filter.FilterCard) Card(mage.cards.Card)

Example 7 with FilterControlledCreaturePermanent

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

the class NobleStandAbility method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    FilterControlledCreaturePermanent filter = new FilterControlledCreaturePermanent();
    filter.add(TokenPredicate.FALSE);
    Permanent permanent = game.getPermanent(event.getSourceId());
    return permanent != null && filter.match(permanent, sourceId, controllerId, game);
}
Also used : Permanent(mage.game.permanent.Permanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent)

Example 8 with FilterControlledCreaturePermanent

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

the class SlaughterTheStrongEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    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) {
                boolean selectionDone = false;
                Set<UUID> selectedCreatures = new HashSet<>();
                while (player.canRespond() && selectionDone == false) {
                    int powerSum = 0;
                    for (UUID creatureId : selectedCreatures) {
                        Permanent creature = game.getPermanent(creatureId);
                        if (creature != null) {
                            powerSum += creature.getPower().getValue();
                        }
                    }
                    FilterControlledCreaturePermanent currentFilter = new FilterControlledCreaturePermanent("any number of creatures you control with total power 4 or less (already selected total power " + powerSum + ")");
                    Set<PermanentIdPredicate> alreadySelectedCreatures = new HashSet<>();
                    if (!selectedCreatures.isEmpty()) {
                        for (UUID creatureId : selectedCreatures) {
                            alreadySelectedCreatures.add(new PermanentIdPredicate(creatureId));
                        }
                        currentFilter.add(Predicates.or(new PowerPredicate(ComparisonType.FEWER_THAN, 5 - powerSum), Predicates.or(alreadySelectedCreatures)));
                    } else {
                        currentFilter.add(new PowerPredicate(ComparisonType.FEWER_THAN, 5 - powerSum));
                    }
                    // human can de-select targets, but AI must choose only one time
                    Target target;
                    if (player.isComputer()) {
                        // AI settings
                        FilterControlledCreaturePermanent strictFilter = currentFilter.copy();
                        selectedCreatures.stream().forEach(id -> {
                            strictFilter.add(Predicates.not(new PermanentIdPredicate(id)));
                        });
                        target = new TargetPermanent(0, 1, strictFilter, true);
                    } else {
                        // Human settings
                        target = new TargetPermanent(0, 1, currentFilter, true);
                    }
                    player.chooseTarget(Outcome.BoostCreature, target, source, game);
                    if (target.getFirstTarget() != null) {
                        if (selectedCreatures.contains(target.getFirstTarget())) {
                            selectedCreatures.remove(target.getFirstTarget());
                        } else {
                            selectedCreatures.add(target.getFirstTarget());
                        }
                    } else {
                        if (player.isComputer()) {
                            // AI stops
                            selectionDone = true;
                        } else {
                            // Human can continue
                            String selected = "Selected: ";
                            for (UUID creatureId : selectedCreatures) {
                                Permanent creature = game.getPermanent(creatureId);
                                if (creature != null) {
                                    selected += creature.getLogName() + " ";
                                }
                            }
                            selectionDone = player.chooseUse(Outcome.Detriment, "Creature selection", selected, "End the selection", "Continue the selection", source, game);
                        }
                    }
                }
                for (Permanent creature : game.getBattlefield().getAllActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, playerId, game)) {
                    if (!selectedCreatures.contains(creature.getId())) {
                        creature.sacrifice(source, game);
                    }
                }
            }
        }
        return true;
    }
    return false;
}
Also used : PermanentIdPredicate(mage.filter.predicate.permanent.PermanentIdPredicate) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) PowerPredicate(mage.filter.predicate.mageobject.PowerPredicate) Target(mage.target.Target) TargetPermanent(mage.target.TargetPermanent) UUID(java.util.UUID) HashSet(java.util.HashSet)

Example 9 with FilterControlledCreaturePermanent

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

the class MeldCondition method apply.

@Override
public boolean apply(Game game, Ability source) {
    MageObject sourceMageObject = source.getSourceObjectIfItStillExists(game);
    if (sourceMageObject instanceof Permanent) {
        Permanent sourcePermanent = (Permanent) sourceMageObject;
        if (sourcePermanent.isControlledBy(source.getControllerId()) && sourcePermanent.isOwnedBy(source.getControllerId())) {
            FilterControlledCreaturePermanent filter = new FilterControlledCreaturePermanent();
            filter.add(new NamePredicate(this.meldWithName));
            filter.add(new OwnerIdPredicate(source.getControllerId()));
            return game.getBattlefield().count(filter, source.getSourceId(), source.getControllerId(), game) > 0;
        }
    }
    return false;
}
Also used : NamePredicate(mage.filter.predicate.mageobject.NamePredicate) OwnerIdPredicate(mage.filter.predicate.card.OwnerIdPredicate) Permanent(mage.game.permanent.Permanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) MageObject(mage.MageObject) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent)

Example 10 with FilterControlledCreaturePermanent

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

the class MeldEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        // Find the two permanents to meld.
        UUID sourceId = source.getSourceId();
        FilterControlledCreaturePermanent filter = new FilterControlledCreaturePermanent("creature named " + meldWithName);
        filter.add(new NamePredicate(meldWithName));
        TargetPermanent target = new TargetControlledCreaturePermanent(filter);
        Set<UUID> meldWithList = target.possibleTargets(sourceId, source.getControllerId(), game);
        if (meldWithList.isEmpty()) {
            // possible permanent has left the battlefield meanwhile
            return false;
        }
        UUID meldWithId = null;
        if (meldWithList.size() == 1) {
            meldWithId = meldWithList.iterator().next();
        } else {
            if (controller.choose(Outcome.BoostCreature, target, sourceId, game)) {
                meldWithId = target.getFirstTarget();
            }
        }
        // Exile the two permanents to meld.
        Permanent sourcePermanent = game.getPermanent(sourceId);
        Permanent meldWithPermanent = game.getPermanent(meldWithId);
        if (sourcePermanent != null && meldWithPermanent != null) {
            Set<Card> toExile = new HashSet<>();
            toExile.add(sourcePermanent);
            toExile.add(meldWithPermanent);
            controller.moveCards(toExile, Zone.EXILED, source, game);
            // Create the meld card and move it to the battlefield.
            Card sourceCard = game.getExile().getCard(sourceId, game);
            Card meldWithCard = game.getExile().getCard(meldWithId, game);
            if (sourceCard != null && !sourceCard.isCopy() && meldWithCard != null && !meldWithCard.isCopy()) {
                meldCard.setOwnerId(controller.getId());
                meldCard.setTopHalfCard(meldWithCard, game);
                meldCard.setBottomHalfCard(sourceCard, game);
                meldCard.setMelded(true, game);
                game.addMeldCard(meldCard.getId(), meldCard);
                game.getState().addCard(meldCard);
                meldCard.setZone(Zone.EXILED, game);
                controller.moveCards(meldCard, Zone.BATTLEFIELD, source, game);
            }
            return true;
        }
    }
    return false;
}
Also used : Player(mage.players.Player) NamePredicate(mage.filter.predicate.mageobject.NamePredicate) Permanent(mage.game.permanent.Permanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) UUID(java.util.UUID) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) MeldCard(mage.cards.MeldCard) Card(mage.cards.Card) HashSet(java.util.HashSet)

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