Search in sources :

Example 36 with FixedTarget

use of mage.target.targetpointer.FixedTarget in project mage by magefree.

the class PeerPressureEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Choice choice = new ChoiceCreatureType(game.getObject(source.getSourceId()));
    if (controller != null && controller.choose(Outcome.GainControl, choice, game)) {
        String chosenType = choice.getChoice();
        game.informPlayers(controller.getLogName() + " has chosen " + chosenType);
        UUID playerWithMost = null;
        int maxControlled = 0;
        for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
            FilterPermanent filter = new FilterCreaturePermanent(SubType.byDescription(chosenType), chosenType);
            filter.add(new ControllerIdPredicate(playerId));
            int controlled = new PermanentsOnBattlefieldCount(filter).calculate(game, source, this);
            if (controlled > maxControlled) {
                maxControlled = controlled;
                playerWithMost = playerId;
            } else if (controlled == maxControlled) {
                // Do nothing in case of tie
                playerWithMost = null;
            }
        }
        if (playerWithMost != null && playerWithMost.equals(controller.getId())) {
            for (Permanent permanent : game.getBattlefield().getActivePermanents(new FilterCreaturePermanent(SubType.byDescription(chosenType), chosenType), controller.getId(), source.getSourceId(), game)) {
                ContinuousEffect effect = new GainControlTargetEffect(Duration.EndOfGame);
                effect.setTargetPointer(new FixedTarget(permanent, game));
                game.addEffect(effect, source);
            }
        }
        return true;
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) Choice(mage.choices.Choice) FilterPermanent(mage.filter.FilterPermanent) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) GainControlTargetEffect(mage.abilities.effects.common.continuous.GainControlTargetEffect) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) ChoiceCreatureType(mage.choices.ChoiceCreatureType) PermanentsOnBattlefieldCount(mage.abilities.dynamicvalue.common.PermanentsOnBattlefieldCount) ContinuousEffect(mage.abilities.effects.ContinuousEffect) UUID(java.util.UUID)

Example 37 with FixedTarget

use of mage.target.targetpointer.FixedTarget in project mage by magefree.

the class PsychicBattleEffect method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    StackObject stackObject = game.getStack().getStackObject(event.getSourceId());
    if (stackObject != null) {
        if (!stackObject.isTargetChanged() && !stackObject.getName().equals("Psychic Battle")) {
            this.getEffects().get(0).setTargetPointer(new FixedTarget(event.getSourceId()));
            // resets the targetChanged flag
            stackObject.setTargetChanged(false);
            return true;
        }
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) StackObject(mage.game.stack.StackObject)

Example 38 with FixedTarget

use of mage.target.targetpointer.FixedTarget in project mage by magefree.

the class PsychicIntrusionSpendAnyManaEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player opponent = game.getPlayer(targetPointer.getFirst(game, source));
    MageObject sourceObject = game.getObject(source.getSourceId());
    if (opponent != null && sourceObject != null) {
        opponent.revealCards(sourceObject.getName(), opponent.getHand(), game);
        Player controller = game.getPlayer(source.getControllerId());
        if (controller != null) {
            int cardsGraveyard = opponent.getGraveyard().count(filter, game);
            int cardsHand = opponent.getHand().count(filter, game);
            boolean fromHand = false;
            if (cardsGraveyard > 0 && cardsHand > 0) {
                if (controller.chooseUse(Outcome.Detriment, "Exile card from opponents Hand?", source, game)) {
                    fromHand = true;
                }
            } else {
                if (cardsHand > 0) {
                    fromHand = true;
                }
            }
            Card card = null;
            if (cardsHand > 0 && fromHand) {
                TargetCard target = new TargetCard(Zone.HAND, filter);
                if (controller.choose(Outcome.Benefit, opponent.getHand(), target, game)) {
                    card = opponent.getHand().get(target.getFirstTarget(), game);
                }
            }
            if (cardsGraveyard > 0 && !fromHand) {
                TargetCard target = new TargetCard(Zone.GRAVEYARD, filter);
                if (controller.choose(Outcome.Benefit, opponent.getGraveyard(), target, game)) {
                    card = opponent.getGraveyard().get(target.getFirstTarget(), game);
                }
            }
            if (card != null) {
                // move card to exile
                UUID exileId = CardUtil.getCardExileZoneId(game, source);
                controller.moveCardToExileWithInfo(card, exileId, sourceObject.getIdName(), source, game, fromHand ? Zone.HAND : Zone.GRAVEYARD, true);
                // allow to cast the card
                ContinuousEffect effect = new PsychicIntrusionCastFromExileEffect();
                effect.setTargetPointer(new FixedTarget(card.getId()));
                game.addEffect(effect, source);
                // and you may spend mana as though it were mana of any color to cast it
                effect = new PsychicIntrusionSpendAnyManaEffect();
                effect.setTargetPointer(new FixedTarget(card.getId()));
                game.addEffect(effect, source);
            }
            return true;
        }
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) MageObject(mage.MageObject) TargetCard(mage.target.TargetCard) ContinuousEffect(mage.abilities.effects.ContinuousEffect) UUID(java.util.UUID) FilterNonlandCard(mage.filter.common.FilterNonlandCard) TargetCard(mage.target.TargetCard) Card(mage.cards.Card)

Example 39 with FixedTarget

use of mage.target.targetpointer.FixedTarget in project mage by magefree.

the class PsychicPurgeTriggeredAbility method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    if (getSourceId().equals(event.getTargetId())) {
        StackObject stackObject = game.getStack().getStackObject(event.getSourceId());
        if (stackObject != null) {
            if (game.getOpponents(this.getControllerId()).contains(stackObject.getControllerId())) {
                Effect effect = this.getEffects().get(0);
                effect.setTargetPointer(new FixedTarget(stackObject.getControllerId()));
                return true;
            }
        }
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) StackObject(mage.game.stack.StackObject) LoseLifeTargetEffect(mage.abilities.effects.common.LoseLifeTargetEffect) Effect(mage.abilities.effects.Effect) DamageTargetEffect(mage.abilities.effects.common.DamageTargetEffect)

Example 40 with FixedTarget

use of mage.target.targetpointer.FixedTarget in project mage by magefree.

the class PuppeteerCliqueEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Card card = game.getCard(getTargetPointer().getFirst(game, source));
    if (card == null) {
        return false;
    }
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null || !controller.moveCards(card, Zone.BATTLEFIELD, source, game)) {
        return false;
    }
    Permanent permanent = game.getPermanent(card.getId());
    if (permanent == null) {
        return false;
    }
    ContinuousEffect hasteEffect = new GainAbilityTargetEffect(HasteAbility.getInstance(), Duration.Custom);
    hasteEffect.setTargetPointer(new FixedTarget(permanent, game));
    game.addEffect(hasteEffect, source);
    ExileTargetEffect exileEffect = new ExileTargetEffect("exile " + permanent.getLogName());
    exileEffect.setTargetPointer(new FixedTarget(permanent, game));
    DelayedTriggeredAbility delayedAbility = new AtTheBeginOfNextEndStepDelayedTriggeredAbility(exileEffect, TargetController.YOU);
    game.addDelayedTriggeredAbility(delayedAbility, source);
    return true;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) AtTheBeginOfNextEndStepDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility) Permanent(mage.game.permanent.Permanent) DelayedTriggeredAbility(mage.abilities.DelayedTriggeredAbility) AtTheBeginOfNextEndStepDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility) GainAbilityTargetEffect(mage.abilities.effects.common.continuous.GainAbilityTargetEffect) ContinuousEffect(mage.abilities.effects.ContinuousEffect) FilterCreatureCard(mage.filter.common.FilterCreatureCard) Card(mage.cards.Card) ExileTargetEffect(mage.abilities.effects.common.ExileTargetEffect)

Aggregations

FixedTarget (mage.target.targetpointer.FixedTarget)746 Permanent (mage.game.permanent.Permanent)491 Player (mage.players.Player)385 ContinuousEffect (mage.abilities.effects.ContinuousEffect)248 Effect (mage.abilities.effects.Effect)222 OneShotEffect (mage.abilities.effects.OneShotEffect)185 UUID (java.util.UUID)178 Card (mage.cards.Card)174 AtTheBeginOfNextEndStepDelayedTriggeredAbility (mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility)116 TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)109 GainAbilityTargetEffect (mage.abilities.effects.common.continuous.GainAbilityTargetEffect)101 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)87 TargetPermanent (mage.target.TargetPermanent)84 FilterPermanent (mage.filter.FilterPermanent)71 MageObject (mage.MageObject)68 DelayedTriggeredAbility (mage.abilities.DelayedTriggeredAbility)63 BoostTargetEffect (mage.abilities.effects.common.continuous.BoostTargetEffect)53 GainControlTargetEffect (mage.abilities.effects.common.continuous.GainControlTargetEffect)53 CreateTokenCopyTargetEffect (mage.abilities.effects.common.CreateTokenCopyTargetEffect)50 FilterCard (mage.filter.FilterCard)46