Search in sources :

Example 1 with TargetPointer

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

the class BesmirchEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    if (game.getPermanent(source.getFirstTarget()) != null) {
        TargetPointer target = new FixedTarget(source.getFirstTarget(), game);
        // gain control
        game.addEffect(new GainControlTargetEffect(Duration.EndOfTurn).setTargetPointer(target), source);
        // haste
        game.addEffect(new GainAbilityTargetEffect(HasteAbility.getInstance(), Duration.EndOfTurn).setTargetPointer(target), source);
        // goad
        game.addEffect(new GoadTargetEffect().setTargetPointer(target), source);
        // untap
        new UntapTargetEffect().setTargetPointer(target).apply(game, source);
        return true;
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) GainAbilityTargetEffect(mage.abilities.effects.common.continuous.GainAbilityTargetEffect) UntapTargetEffect(mage.abilities.effects.common.UntapTargetEffect) TargetPointer(mage.target.targetpointer.TargetPointer) GainControlTargetEffect(mage.abilities.effects.common.continuous.GainControlTargetEffect) GoadTargetEffect(mage.abilities.effects.common.combat.GoadTargetEffect)

Example 2 with TargetPointer

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

the class ExileTargetForSourceEffect 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) {
        return false;
    }
    Set<UUID> objectsToMove = new LinkedHashSet<>();
    if (this.targetPointer instanceof FirstTargetPointer && source.getTargets().size() > 1) {
        for (Target target : source.getTargets()) {
            objectsToMove.addAll(target.getTargets());
        }
    } else {
        if (this.targetPointer != null && !this.targetPointer.getTargets(game, source).isEmpty()) {
            objectsToMove.addAll(this.targetPointer.getTargets(game, source));
        } else {
            // issue with Madness keyword  #6889
            UUID fixedTargetId = null;
            for (Effect effect : source.getEffects()) {
                TargetPointer targetPointerId = effect.getTargetPointer();
                if (targetPointerId instanceof FixedTarget) {
                    fixedTargetId = (((FixedTarget) targetPointerId).getTarget());
                }
            }
            if (fixedTargetId != null) {
                objectsToMove.add(fixedTargetId);
            }
        }
    }
    UUID exileId = CardUtil.getExileZoneId(game, source.getSourceId(), source.getSourceObjectZoneChangeCounter());
    // it can target permanents on battlefield, so use objects first
    Set<Card> cardsToMove = objectsToMove.stream().map(game::getObject).filter(Objects::nonNull).map(object -> {
        if (object instanceof Card) {
            return (Card) object;
        } else {
            return game.getCard(object.getId());
        }
    }).filter(Objects::nonNull).collect(Collectors.toSet());
    return controller.moveCardsToExile(cardsToMove, source, game, true, exileId, sourceObject.getIdName());
}
Also used : LinkedHashSet(java.util.LinkedHashSet) FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) MageObject(mage.MageObject) Card(mage.cards.Card) Target(mage.target.Target) FixedTarget(mage.target.targetpointer.FixedTarget) FirstTargetPointer(mage.target.targetpointer.FirstTargetPointer) OneShotEffect(mage.abilities.effects.OneShotEffect) Effect(mage.abilities.effects.Effect) UUID(java.util.UUID) TargetPointer(mage.target.targetpointer.TargetPointer) FirstTargetPointer(mage.target.targetpointer.FirstTargetPointer)

Example 3 with TargetPointer

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

the class StackAbilityView method updateTargets.

private void updateTargets(Game game, StackAbility ability) {
    List<String> names = new ArrayList<>();
    for (UUID modeId : ability.getModes().getSelectedModes()) {
        Mode mode = ability.getModes().get(modeId);
        if (!mode.getTargets().isEmpty()) {
            addTargets(mode.getTargets(), mode.getEffects(), ability, game);
        } else {
            List<UUID> targetList = new ArrayList<>();
            for (Effect effect : mode.getEffects()) {
                TargetPointer targetPointer = effect.getTargetPointer();
                if (targetPointer instanceof FixedTarget) {
                    targetList.add(((FixedTarget) targetPointer).getTarget());
                }
            }
            if (!targetList.isEmpty()) {
                overrideTargets(targetList);
                for (UUID uuid : targetList) {
                    MageObject mageObject = game.getObject(uuid);
                    if (mageObject != null) {
                        if ((mageObject instanceof Card) && ((Card) mageObject).isFaceDown(game)) {
                            continue;
                        }
                        String newName = GameLog.getColoredObjectIdNameForTooltip(mageObject);
                        if (!names.contains(newName)) {
                            names.add(newName);
                        }
                    }
                }
            }
        }
    }
    if (!names.isEmpty()) {
        getRules().add("<i>Related objects: " + names + "</i>");
    }
    // show for modal ability, which mode was choosen
    if (ability.isModal()) {
        Modes modes = ability.getModes();
        for (UUID modeId : modes.getSelectedModes()) {
            Mode mode = modes.get(modeId);
            this.rules.add("<span color='green'><i>Chosen mode: " + mode.getEffects().getText(mode) + "</i></span>");
        }
    }
    if (HintUtils.ABILITY_HINTS_ENABLE) {
        List<String> abilityHints = new ArrayList<>();
        for (Hint hint : ability.getHints()) {
            abilityHints.add(hint.getText(game, ability));
        }
        // total hints
        if (!abilityHints.isEmpty()) {
            rules.add(HintUtils.HINT_START_MARK);
            HintUtils.appendHints(rules, abilityHints);
        }
    }
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Modes(mage.abilities.Modes) Hint(mage.abilities.hint.Hint) Mode(mage.abilities.Mode) ArrayList(java.util.ArrayList) MageObject(mage.MageObject) Card(mage.cards.Card) Effect(mage.abilities.effects.Effect) UUID(java.util.UUID) TargetPointer(mage.target.targetpointer.TargetPointer)

Aggregations

FixedTarget (mage.target.targetpointer.FixedTarget)3 TargetPointer (mage.target.targetpointer.TargetPointer)3 UUID (java.util.UUID)2 MageObject (mage.MageObject)2 Effect (mage.abilities.effects.Effect)2 Card (mage.cards.Card)2 ArrayList (java.util.ArrayList)1 LinkedHashSet (java.util.LinkedHashSet)1 Mode (mage.abilities.Mode)1 Modes (mage.abilities.Modes)1 OneShotEffect (mage.abilities.effects.OneShotEffect)1 UntapTargetEffect (mage.abilities.effects.common.UntapTargetEffect)1 GoadTargetEffect (mage.abilities.effects.common.combat.GoadTargetEffect)1 GainAbilityTargetEffect (mage.abilities.effects.common.continuous.GainAbilityTargetEffect)1 GainControlTargetEffect (mage.abilities.effects.common.continuous.GainControlTargetEffect)1 Hint (mage.abilities.hint.Hint)1 Player (mage.players.Player)1 Target (mage.target.Target)1 FirstTargetPointer (mage.target.targetpointer.FirstTargetPointer)1