Package mage.target

Examples of mage.target.Target


        this(card, amount, false);
    }

    public ModularAbility(Card card, int amount, boolean sunburst) {
        super(new ModularDistributeCounterEffect(), true);
        Target target = new TargetArtifactPermanent(filter);
        this.addTarget(target);
        this.amount = amount;
        this.sunburst = sunburst;
        if (sunburst) {
            Ability ability = new SunburstAbility(card);
View Full Code Here


            for (SpellAbility spellAbility : spellAbilities) {
                // Some spells can have more than one mode
                for (UUID modeId : spellAbility.getModes().getSelectedModes()) {
                    Mode mode = spellAbility.getModes().get(modeId);
                    for (Target target : mode.getTargets()) {
                        Target newTarget = chooseNewTarget(player, spellAbility, mode, target, forceChange, game);
                        // clear the old target and copy all targets from new target
                        target.clearChosen();
                        for (UUID targetId : newTarget.getTargets()) {
                            target.addTarget(targetId, newTarget.getTargetAmount(targetId), spellAbility, game, false);                           
                        }

                    }
                    newTargetDescription.append(getSpellAbility().getTargetDescription(mode.getTargets(), game));
                }
View Full Code Here

     * @param forceChange
     * @param game
     * @return
     */
    private Target chooseNewTarget(Player player, SpellAbility spellAbility, Mode mode, Target target, boolean forceChange, Game game) {
        Target newTarget = target.copy();
        newTarget.clearChosen();
        for (UUID targetId : target.getTargets()) {
            String targetNames = getNamesOftargets(targetId, game);
            // change the target?
            if (targetNames != null
                    && (forceChange || player.chooseUse(mode.getEffects().get(0).getOutcome(), "Change this target: " + targetNames + "?", game))) {              
                // choose exactly one other target
                if (forceChange && target.possibleTargets(this.getSourceId(), getControllerId(), game).size() > 1) { // controller of spell must be used (e.g. TargetOpponent)
                    int iteration = 0;
                    do {
                        if (iteration > 0) {
                            game.informPlayer(player, "You may only select exactly one target that must be different from the origin target!");
                        }
                        iteration++;
                        newTarget.clearChosen();
                        // TODO: Distinction between "spell controller" and "player that can change the target" - here player is used for both
                        newTarget.chooseTarget(mode.getEffects().get(0).getOutcome(), player.getId(), spellAbility, game);
                    } while (player.isInGame() && (targetId.equals(newTarget.getFirstTarget()) || newTarget.getTargets().size() != 1));
                // choose a new target
                } else {
                    // build a target definition with exactly one possible target to select that replaces old target
                    Target tempTarget = target.copy();
                    if (target instanceof TargetAmount) {
                        ((TargetAmount)tempTarget).setAmountDefinition(new StaticValue(target.getTargetAmount(targetId)));
                    }
                    tempTarget.setMinNumberOfTargets(1);
                    tempTarget.setMaxNumberOftargets(1);
                    boolean again;
                    do {
                        again = false;
                        tempTarget.clearChosen();
                        if (!tempTarget.chooseTarget(mode.getEffects().get(0).getOutcome(), player.getId(), spellAbility, game)) {
                            if (player.chooseUse(Outcome.Benefit, "No target object selected. Reset to original target?", game)) {
                                // use previous target no target was selected
                                newTarget.addTarget(targetId, target.getTargetAmount(targetId), spellAbility, game, false);
                            } else {
                                again = true;
                            }
                        } else {
                            // if possible add the alternate Target - it may not be included in the old definition nor in the already selected targets of the new definition
                            if (newTarget.getTargets().contains(tempTarget.getFirstTarget()) || target.getTargets().contains(tempTarget.getFirstTarget())) {
                                if(player.isHuman()) {
                                    game.informPlayer(player, "This target was already selected from origin spell. You can only keep this target!");
                                    again = true;
                                } else {
                                    newTarget.addTarget(targetId, target.getTargetAmount(targetId), spellAbility, game, false);
                                }
                            } else {
                                // valid target was selected, add it to the new target definition
                                newTarget.addTarget(tempTarget.getFirstTarget(), target.getTargetAmount(targetId), spellAbility, game, false);
                            }
                        }
                    } while (again && player.isInGame());
                }           
            }
View Full Code Here

    }

    @Override
    public boolean apply(Game game, Ability source) {
        Player controller = game.getPlayer(source.getControllerId());
        Target target = new TargetPermanentOrPlayerWithCounter(0, Integer.MAX_VALUE, true);

        //A spell or ability could have removed the only legal target this player
        //had, if thats the case this ability should fizzle.
        if (target.canChoose(controller.getId(), game)) {
            boolean abilityApplied = false;
            Map<String, Serializable> options = new HashMap<>();
            options.put("UI.right.btn.text", "Done");
            while (target.canChoose(controller.getId(), game)) {
                if (controller.choose(Outcome.Benefit, target, source.getSourceId(), game, options)) {
                    break;
                }
            }

            for (int idx = 0; idx < target.getTargets().size(); idx++) {
                UUID chosen = (UUID) target.getTargets().get(idx);
                Permanent permanent = game.getPermanent(chosen);
                if (permanent != null) {
                    if (permanent.getCounters().size() > 0) {
                        if (permanent.getCounters().size() == 1) {
                            for (Counter counter : permanent.getCounters().values()) {
View Full Code Here

    }

    @Override
    public boolean apply(Game game, Ability source) {
        if (source.getTargets().size() > 0) {
            Target multiTarget = source.getTargets().get(0);
            for (UUID target: multiTarget.getTargets()) {
                Permanent permanent = game.getPermanent(target);
                if (permanent != null) {
                    permanent.damage(multiTarget.getTargetAmount(target), source.getSourceId(), game, false, true);
                }
                else {
                    Player player = game.getPlayer(target);
                    if (player != null) {
                        player.damage(multiTarget.getTargetAmount(target), source.getSourceId(), game, false, true);
                    }
                }
            }
        }
        return true;
View Full Code Here

    @Override
    public boolean apply(Game game, Ability source) {
        boolean result = false;
        UUID targetPlayerId = null;
        // get Target to exile
        Target exileTarget = null;
        for (Target target : source.getTargets()) {
            if (target instanceof TargetPermanent) {
                exileTarget = target;
                break;
            }
        }       
        if (exileTarget != null) {
            Permanent permanentToExile = game.getPermanent(exileTarget.getFirstTarget());
            if (permanentToExile != null) {
                targetPlayerId = permanentToExile.getControllerId();
                result = permanentToExile.moveToExile(null, "", source.getSourceId(), game);
                this.applySearchAndExile(game, source, permanentToExile.getName(), targetPlayerId);               
            }
View Full Code Here

        if (event.getType() == EventType.ENTERS_THE_BATTLEFIELD) {
            Permanent permanent = game.getPermanent(event.getTargetId());
            if (filter.match(permanent, sourceId, controllerId, game)
                    && (permanent.getControllerId().equals(this.controllerId) ^ opponentController)) {
                if (!this.getTargets().isEmpty()) {
                    Target target = this.getTargets().get(0);
                    if (target instanceof TargetPlayer) {
                        target.add(permanent.getControllerId(), game);
                    }
                    if (target instanceof TargetCreaturePermanent) {
                        target.add(event.getTargetId(), game);
                    }
                }
                return true;
            }
        }
View Full Code Here

    public String getText(Mode mode) {
        if (staticText != null && !staticText.isEmpty()) {
            return staticText;
        }
        StringBuilder sb = new StringBuilder();
        Target target = mode.getTargets().get(0);
        if(target.getMaxNumberOfTargets() > 1){
            if (target.getNumberOfTargets() < target.getMaxNumberOfTargets()) {
                sb.append("Up to ");
            }
            sb.append(CardUtil.numberToText(target.getMaxNumberOfTargets())).append(" target ").append(target.getTargetName()).append("  each become ");
        } else {
            sb.append("Target ").append(target.getTargetName()).append(" becomes a ");
        }
        sb.append(token.getDescription());
        sb.append(" ").append(duration.toString());
        if (type != null && type.length() > 0) {
            if (target.getMaxNumberOfTargets() > 1) {
                sb.append(". They're still ").append(type);
            } else {
                sb.append(". It's still a ").append(type);
            }
        }
View Full Code Here

            Card card = player.getLibrary().getCard(target.getFirstTarget(), game);
            if (card != null) {
                card.putOntoBattlefield(game, Zone.LIBRARY, source.getSourceId(), source.getControllerId());
                Permanent equipment = game.getPermanent(card.getId());

                Target targetCreature = new TargetControlledCreaturePermanent();
                if (equipment != null && player.choose(Outcome.BoostCreature, targetCreature, source.getSourceId(), game)) {
                    Permanent permanent = game.getPermanent(targetCreature.getFirstTarget());
                    permanent.addAttachment(equipment.getId(), game);
                }
            }
        }
        player.shuffleLibrary(game);
View Full Code Here

    public String getText(Mode mode) {
        if (staticText != null && !staticText.isEmpty()) {
            return staticText;
        }
        StringBuilder sb = new StringBuilder();
        Target target = mode.getTargets().get(0);
        if(target.getMaxNumberOfTargets() > 1){
            if (target.getNumberOfTargets() < target.getMaxNumberOfTargets()) {
                sb.append("Up to");
            }
            sb.append(target.getMaxNumberOfTargets()).append(" target ").append(target.getTargetName()).append(" gain ");
        } else {
            if (!target.getTargetName().toUpperCase().startsWith("ANOTHER")) {
                sb.append("Target ");
            }
            sb.append(target.getTargetName()).append(" gains ");

        }
        if (durationPhaseStep != null) {
            sb.append(" until your next ").append(durationPhaseStep.toString().toLowerCase(Locale.ENGLISH));
        }
View Full Code Here

TOP

Related Classes of mage.target.Target

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.