Search in sources :

Example 56 with FixedTarget

use of mage.target.targetpointer.FixedTarget 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 57 with FixedTarget

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

the class HauntEffect method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    switch(event.getType()) {
        case ENTERS_THE_BATTLEFIELD:
            return game.getState().getZone(getSourceId()) == Zone.BATTLEFIELD && event.getTargetId().equals(getSourceId());
        case ZONE_CHANGE:
            if (usedFromExile || game.getState().getZone(getSourceId()) != Zone.EXILED) {
                return false;
            }
            ZoneChangeEvent zEvent = (ZoneChangeEvent) event;
            if (!zEvent.isDiesEvent()) {
                return false;
            }
            Card card = game.getCard(getSourceId());
            if (card == null || game.getCard(event.getTargetId()) == null) {
                return false;
            }
            String key = new StringBuilder("Haunting_").append(getSourceId().toString()).append(card.getZoneChangeCounter(game) + (game.getPermanentOrLKIBattlefield(event.getTargetId())).getZoneChangeCounter(game)).toString();
            Object object = game.getState().getValue(key);
            if (!(object instanceof FixedTarget)) {
                return false;
            }
            FixedTarget target = (FixedTarget) object;
            if (target.getTarget() != null && target.getTarget().equals(event.getTargetId())) {
                usedFromExile = true;
                return true;
            }
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) ZoneChangeEvent(mage.game.events.ZoneChangeEvent) MageObject(mage.MageObject) Card(mage.cards.Card)

Example 58 with FixedTarget

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

the class HauntEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    Card card = game.getCard(source.getSourceId());
    if (player == null || card == null) {
        return false;
    }
    Permanent hauntedCreature = game.getPermanent(targetPointer.getFirst(game, source));
    // haunting card will only be moved to exile, if
    if (hauntedCreature == null) {
        return false;
    }
    if (!player.moveCards(card, Zone.EXILED, source, game)) {
        return true;
    }
    // remember the haunted creature
    String key = new StringBuilder("Haunting_").append(source.getSourceId().toString()).append(card.getZoneChangeCounter(game) + hauntedCreature.getZoneChangeCounter(game)).toString();
    game.getState().setValue(key, new FixedTarget(targetPointer.getFirst(game, source), game));
    card.addInfo("hauntinfo", new StringBuilder("Haunting ").append(hauntedCreature.getLogName()).toString(), game);
    hauntedCreature.addInfo("hauntinfo", new StringBuilder("Haunted by ").append(card.getLogName()).toString(), game);
    game.informPlayers(new StringBuilder(card.getName()).append(" haunting ").append(hauntedCreature.getLogName()).toString());
    return true;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) Card(mage.cards.Card)

Example 59 with FixedTarget

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

the class AchHansRunEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    String cardName = ChooseACardNameEffect.TypeOfName.CREATURE_NAME.getChoice(controller, game, source, false);
    game.informPlayers(controller.getLogName() + ": \"Ach! Hans, run! It's the " + cardName + "!\"");
    FilterCard nameFilter = new FilterCard();
    nameFilter.add(new NamePredicate(cardName));
    TargetCardInLibrary target = new TargetCardInLibrary(1, 1, nameFilter);
    if (!controller.searchLibrary(target, source, game)) {
        return false;
    }
    Card card = controller.getLibrary().remove(target.getFirstTarget(), game);
    if (card == null || !controller.moveCards(card, Zone.BATTLEFIELD, source, game)) {
        return false;
    }
    Permanent creature = game.getPermanent(card.getId());
    if (creature == null) {
        return false;
    }
    // gains haste
    ContinuousEffect effect = new GainAbilityTargetEffect(HasteAbility.getInstance(), Duration.EndOfTurn);
    effect.setTargetPointer(new FixedTarget(creature, game));
    game.addEffect(effect, source);
    // Exile at begin of next end step
    ExileTargetEffect exileEffect = new ExileTargetEffect(null, null, Zone.BATTLEFIELD);
    exileEffect.setTargetPointer(new FixedTarget(creature, game));
    DelayedTriggeredAbility delayedAbility = new AtTheBeginOfNextEndStepDelayedTriggeredAbility(exileEffect);
    game.addDelayedTriggeredAbility(delayedAbility, source);
    controller.shuffleLibrary(source, game);
    return true;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) NamePredicate(mage.filter.predicate.mageobject.NamePredicate) Permanent(mage.game.permanent.Permanent) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) FilterCard(mage.filter.FilterCard) Card(mage.cards.Card) FilterCard(mage.filter.FilterCard) AtTheBeginOfNextEndStepDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility) DelayedTriggeredAbility(mage.abilities.DelayedTriggeredAbility) AtTheBeginOfNextEndStepDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility) GainAbilityTargetEffect(mage.abilities.effects.common.continuous.GainAbilityTargetEffect) ContinuousEffect(mage.abilities.effects.ContinuousEffect) ExileTargetEffect(mage.abilities.effects.common.ExileTargetEffect)

Example 60 with FixedTarget

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

the class AminatousAuguryCastFromExileEffect 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) {
        // move cards from library to exile
        controller.moveCardsToExile(controller.getLibrary().getTopCards(game, 8), source, game, true, source.getSourceId(), CardUtil.createObjectRealtedWindowTitle(source, game, null));
        ExileZone auguryExileZone = game.getExile().getExileZone(source.getSourceId());
        if (auguryExileZone == null) {
            return true;
        }
        Cards cardsToCast = new CardsImpl();
        cardsToCast.addAll(auguryExileZone.getCards(game));
        // put a land card from among them onto the battlefield
        TargetCard target = new TargetCard(Zone.EXILED, StaticFilters.FILTER_CARD_LAND_A);
        if (cardsToCast.count(StaticFilters.FILTER_CARD_LAND, game) > 0) {
            if (controller.chooseUse(Outcome.PutLandInPlay, "Put a land from among the exiled cards into play?", source, game)) {
                if (controller.choose(Outcome.PutLandInPlay, cardsToCast, target, game)) {
                    Card card = cardsToCast.get(target.getFirstTarget(), game);
                    if (card != null) {
                        cardsToCast.remove(card);
                        controller.moveCards(card, Zone.BATTLEFIELD, source, game, false, false, true, null);
                    }
                }
            }
        }
        for (Card card : cardsToCast.getCards(StaticFilters.FILTER_CARD_NON_LAND, game)) {
            AminatousAuguryCastFromExileEffect effect = new AminatousAuguryCastFromExileEffect();
            effect.setTargetPointer(new FixedTarget(card, game));
            game.addEffect(effect, source);
        }
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) MageObject(mage.MageObject) ExileZone(mage.game.ExileZone) TargetCard(mage.target.TargetCard) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl) TargetCard(mage.target.TargetCard) Card(mage.cards.Card)

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