Search in sources :

Example 6 with TargetControlledCreaturePermanent

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

the class LucilleEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent equipment = game.getPermanent(source.getSourceId());
    if (equipment == null) {
        return false;
    }
    Player player = game.getPlayer(game.getCombat().getDefendingPlayerId(equipment.getAttachedTo(), game));
    if (player == null) {
        return false;
    }
    TargetPermanent target = new TargetControlledCreaturePermanent();
    target.setNotTarget(true);
    if (!target.canChoose(source.getSourceId(), player.getId(), game)) {
        return false;
    }
    player.choose(outcome, target, source.getSourceId(), game);
    Permanent permanent = game.getPermanent(target.getFirstTarget());
    return permanent.sacrifice(source, game) && new WalkerToken().putOntoBattlefield(1, game, source, source.getControllerId());
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) WalkerToken(mage.game.permanent.token.WalkerToken) TargetPermanent(mage.target.TargetPermanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent)

Example 7 with TargetControlledCreaturePermanent

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

Example 8 with TargetControlledCreaturePermanent

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

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

the class BronzehideLionContinuousEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null || !(game.getState().getZone(source.getSourceId()) == Zone.GRAVEYARD)) {
        return false;
    }
    Card card = game.getCard(source.getSourceId());
    if (card == null) {
        return false;
    }
    TargetPermanent target = new TargetControlledCreaturePermanent();
    target.setNotTarget(true);
    if (controller.choose(outcome, target, source.getSourceId(), game) && game.getPermanent(target.getFirstTarget()) != null) {
        game.getState().setValue("attachTo:" + source.getSourceId(), target.getFirstTarget());
    }
    game.addEffect(new BronzehideLionContinuousEffect(game.getState().getZoneChangeCounter(source.getSourceId()) + 1), source);
    controller.moveCards(card, Zone.BATTLEFIELD, source, game);
    Permanent aura = game.getPermanent(card.getId());
    Permanent creature = game.getPermanent(target.getFirstTarget());
    if (aura == null || creature == null) {
        return true;
    }
    creature.addAttachment(aura.getId(), source, game);
    return true;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) TargetPermanent(mage.target.TargetPermanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) Card(mage.cards.Card)

Example 10 with TargetControlledCreaturePermanent

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

the class DoomfallEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player targetPlayer = game.getPlayer(getTargetPointer().getFirst(game, source));
    if (targetPlayer != null) {
        Target target = new TargetControlledCreaturePermanent();
        target.setNotTarget(true);
        if (targetPlayer.choose(outcome, target, source.getSourceId(), game)) {
            targetPlayer.moveCards(game.getPermanent(target.getFirstTarget()), Zone.EXILED, source, game);
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) Target(mage.target.Target) 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