Search in sources :

Example 41 with Target

use of mage.target.Target 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 42 with Target

use of mage.target.Target in project mage by magefree.

the class AllSunsDawnEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Cards cardsToHand = new CardsImpl();
        for (Target target : source.getTargets()) {
            UUID targetId = target.getFirstTarget();
            Card card = game.getCard(targetId);
            if (card != null) {
                cardsToHand.add(card);
            }
        }
        return controller.moveCards(cardsToHand, Zone.HAND, source, game);
    }
    return false;
}
Also used : Player(mage.players.Player) Target(mage.target.Target) UUID(java.util.UUID) FilterCard(mage.filter.FilterCard)

Example 43 with Target

use of mage.target.Target in project mage by magefree.

the class CephalidConstableTriggeredAbility method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    if (event.getSourceId().equals(this.sourceId) && ((DamagedPlayerEvent) event).isCombatDamage()) {
        FilterPermanent filter = new FilterPermanent("permanent" + (event.getAmount() > 1 ? "s" : "") + " damaged player control");
        filter.add(new ControllerIdPredicate(event.getPlayerId()));
        Target target = new TargetPermanent(0, event.getAmount(), filter, false);
        this.getTargets().clear();
        this.getTargets().add(target);
        return true;
    }
    return false;
}
Also used : Target(mage.target.Target) FilterPermanent(mage.filter.FilterPermanent) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) TargetPermanent(mage.target.TargetPermanent)

Example 44 with Target

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

Example 45 with Target

use of mage.target.Target in project mage by magefree.

the class DracoplasmEffect method replaceEvent.

@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
    Permanent creature = ((EntersTheBattlefieldEvent) event).getTarget();
    Player controller = game.getPlayer(source.getControllerId());
    if (creature != null && controller != null) {
        Target target = new TargetControlledPermanent(0, Integer.MAX_VALUE, filter, true);
        if (!target.canChoose(source.getSourceId(), source.getControllerId(), game)) {
            return false;
        }
        controller.chooseTarget(Outcome.Detriment, target, source, game);
        if (!target.getTargets().isEmpty()) {
            int power = 0;
            int toughness = 0;
            for (UUID targetId : target.getTargets()) {
                Permanent targetCreature = game.getPermanent(targetId);
                if (targetCreature != null && targetCreature.sacrifice(source, game)) {
                    power = CardUtil.overflowInc(power, targetCreature.getPower().getValue());
                    toughness = CardUtil.overflowInc(toughness, targetCreature.getToughness().getValue());
                }
            }
            ContinuousEffect effect = new SetPowerToughnessSourceEffect(power, toughness, Duration.Custom, SubLayer.SetPT_7b);
            game.addEffect(effect, source);
        }
    }
    return false;
}
Also used : TargetControlledPermanent(mage.target.common.TargetControlledPermanent) SetPowerToughnessSourceEffect(mage.abilities.effects.common.continuous.SetPowerToughnessSourceEffect) Player(mage.players.Player) Target(mage.target.Target) Permanent(mage.game.permanent.Permanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) EntersTheBattlefieldEvent(mage.game.events.EntersTheBattlefieldEvent) ContinuousEffect(mage.abilities.effects.ContinuousEffect) UUID(java.util.UUID)

Aggregations

Target (mage.target.Target)385 Player (mage.players.Player)291 Permanent (mage.game.permanent.Permanent)223 UUID (java.util.UUID)155 Card (mage.cards.Card)86 TargetPermanent (mage.target.TargetPermanent)80 FilterCard (mage.filter.FilterCard)62 FilterPermanent (mage.filter.FilterPermanent)56 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)54 FixedTarget (mage.target.targetpointer.FixedTarget)49 TargetControlledCreaturePermanent (mage.target.common.TargetControlledCreaturePermanent)45 TargetControlledPermanent (mage.target.common.TargetControlledPermanent)45 MageObject (mage.MageObject)43 FilterControlledCreaturePermanent (mage.filter.common.FilterControlledCreaturePermanent)42 TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)38 TargetOpponent (mage.target.common.TargetOpponent)35 CardsImpl (mage.cards.CardsImpl)32 ArrayList (java.util.ArrayList)31 ContinuousEffect (mage.abilities.effects.ContinuousEffect)31 FilterControlledPermanent (mage.filter.common.FilterControlledPermanent)30