Search in sources :

Example 11 with FilterControlledCreaturePermanent

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

the class OfferingCostReductionEffect method applies.

@Override
public boolean applies(UUID sourceId, Ability affectedAbility, Ability source, Game game, UUID playerId) {
    if (sourceId.equals(source.getSourceId())) {
        Card card = game.getCard(sourceId);
        if (card == null || !card.isOwnedBy(source.getControllerId())) {
            return false;
        }
        // because can activate is always called twice, result from first call will be used
        Object object = game.getState().getValue("offering_" + card.getId());
        if (object != null && object.equals(true)) {
            Object alreadyConfirmed = game.getState().getValue("offering_ok_" + card.getId());
            game.getState().setValue("offering_" + card.getId(), null);
            game.getState().setValue("offering_ok_" + card.getId(), null);
            return alreadyConfirmed != null;
        } else {
            // first call -> remove previous Ids
            game.getState().setValue("offering_Id_" + card.getId(), null);
        }
        if (game.getBattlefield().count(((OfferingAbility) source).getFilter(), source.getSourceId(), source.getControllerId(), game) > 0) {
            if (game.inCheckPlayableState()) {
                return true;
            }
            FilterControlledCreaturePermanent filter = ((OfferingAbility) source).getFilter();
            Card spellToCast = game.getCard(source.getSourceId());
            if (spellToCast == null) {
                return false;
            }
            Player player = game.getPlayer(source.getControllerId());
            if (player != null && player.chooseUse(Outcome.Benefit, "Offer a " + filter.getMessage() + " to cast " + spellToCast.getName() + '?', source, game)) {
                Target target = new TargetControlledCreaturePermanent(1, 1, filter, true);
                player.chooseTarget(Outcome.Sacrifice, target, source, game);
                if (!target.isChosen()) {
                    return false;
                }
                game.getState().setValue("offering_" + card.getId(), true);
                Permanent offer = game.getPermanent(target.getFirstTarget());
                if (offer != null) {
                    UUID activationId = UUID.randomUUID();
                    OfferingCostReductionEffect effect = new OfferingCostReductionEffect(activationId);
                    effect.setTargetPointer(new FixedTarget(offer, game));
                    game.addEffect(effect, source);
                    game.getState().setValue("offering_ok_" + card.getId(), true);
                    game.getState().setValue("offering_Id_" + card.getId(), activationId);
                    game.informPlayers(player.getLogName() + " announces to offer " + offer.getLogName() + " to cast " + // No id name to prevent to offer hand card knowledge after cancel casting
                    GameLog.getColoredObjectName(spellToCast));
                    return true;
                }
            } else {
                game.getState().setValue("offering_" + card.getId(), true);
            }
        }
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) Target(mage.target.Target) FixedTarget(mage.target.targetpointer.FixedTarget) 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) Card(mage.cards.Card)

Example 12 with FilterControlledCreaturePermanent

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

the class HeartmenderEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    boolean applied = false;
    FilterControlledCreaturePermanent filter = new FilterControlledCreaturePermanent();
    if (game.getBattlefield().getActivePermanents(filter, source.getControllerId(), game).isEmpty()) {
        return true;
    }
    for (Permanent creature : game.getBattlefield().getActivePermanents(filter, source.getControllerId(), game)) {
        if (creature != null && creature.getCounters(game).getCount(counter.getName()) >= counter.getCount()) {
            creature.removeCounters(counter.getName(), counter.getCount(), source, game);
            game.informPlayers("Removed " + counter.getCount() + ' ' + counter.getName() + " counter from " + creature.getName());
            applied = true;
        }
    }
    return applied;
}
Also used : Permanent(mage.game.permanent.Permanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent)

Example 13 with FilterControlledCreaturePermanent

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

the class InvokePrejudiceEffect method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    if (game.getOpponents(getControllerId()).contains(event.getPlayerId())) {
        Spell spell = (Spell) game.getObject(event.getTargetId());
        if (spell != null && spell.isCreature(game)) {
            boolean creatureSharesAColor = false;
            ObjectColor spellColor = spell.getColor(game);
            for (Permanent permanent : game.getBattlefield().getAllActivePermanents(new FilterControlledCreaturePermanent(), getControllerId(), game)) {
                if (spellColor.shares(permanent.getColor(game))) {
                    creatureSharesAColor = true;
                    break;
                }
            }
            if (!creatureSharesAColor) {
                for (Effect effect : getEffects()) {
                    effect.setTargetPointer(new FixedTarget(event.getTargetId()));
                }
                return true;
            }
        }
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Permanent(mage.game.permanent.Permanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) ObjectColor(mage.ObjectColor) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) Effect(mage.abilities.effects.Effect) CounterUnlessPaysEffect(mage.abilities.effects.common.CounterUnlessPaysEffect) Spell(mage.game.stack.Spell)

Example 14 with FilterControlledCreaturePermanent

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

the class DescendantsPathEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourceObject = source.getSourceObject(game);
    if (controller != null && sourceObject != null) {
        if (controller.getLibrary().hasCards()) {
            Card card = controller.getLibrary().getFromTop(game);
            if (card == null) {
                return false;
            }
            controller.revealCards(sourceObject.getIdName(), new CardsImpl(card), game);
            if (card.isCreature(game)) {
                FilterControlledCreaturePermanent filter = new FilterControlledCreaturePermanent();
                boolean found = false;
                for (Permanent permanent : game.getBattlefield().getAllActivePermanents(filter, controller.getId(), game)) {
                    if (card.shareCreatureTypes(game, permanent)) {
                        found = true;
                        break;
                    }
                }
                if (found) {
                    game.informPlayers(sourceObject.getLogName() + ": Found a creature that shares a creature type with the revealed card.");
                    if (controller.chooseUse(Outcome.Benefit, "Cast the card?", source, game)) {
                        game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), Boolean.TRUE);
                        controller.cast(controller.chooseAbilityForCast(card, game, true), game, true, new ApprovingObject(source, game));
                        game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), null);
                    } else {
                        game.informPlayers(sourceObject.getLogName() + ": " + controller.getLogName() + " canceled casting the card.");
                        controller.getLibrary().putOnBottom(card, game);
                    }
                } else {
                    game.informPlayers(sourceObject.getLogName() + ": No creature that shares a creature type with the revealed card.");
                    controller.getLibrary().putOnBottom(card, game);
                }
            } else {
                game.informPlayers(sourceObject.getLogName() + ": Put " + card.getLogName() + " on the bottom.");
                controller.getLibrary().putOnBottom(card, game);
            }
            return true;
        }
    }
    return false;
}
Also used : Player(mage.players.Player) ApprovingObject(mage.ApprovingObject) Permanent(mage.game.permanent.Permanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) MageObject(mage.MageObject) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) CardsImpl(mage.cards.CardsImpl) Card(mage.cards.Card)

Example 15 with FilterControlledCreaturePermanent

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

the class GoblinGoonCantBlockEffect method canAttack.

@Override
public boolean canAttack(Permanent attacker, UUID defenderId, Ability source, Game game, boolean canUseChooseDialogs) {
    if (defenderId == null) {
        return true;
    }
    UUID defendingPlayerId;
    Player defender = game.getPlayer(defenderId);
    if (defender == null) {
        Permanent permanent = game.getPermanent(defenderId);
        if (permanent != null) {
            defendingPlayerId = permanent.getControllerId();
        } else {
            return false;
        }
    } else {
        defendingPlayerId = defenderId;
    }
    if (defendingPlayerId != null) {
        return game.getBattlefield().countAll(new FilterControlledCreaturePermanent(), source.getControllerId(), game) > game.getBattlefield().countAll(new FilterControlledCreaturePermanent(), defendingPlayerId, game);
    } else {
        return true;
    }
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) UUID(java.util.UUID)

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