Search in sources :

Example 66 with Target

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

the class DamageTargetEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    if (!useOnlyTargetPointer && source.getTargets().size() > 1) {
        for (Target target : source.getTargets()) {
            for (UUID targetId : target.getTargets()) {
                Permanent permanent = game.getPermanent(targetId);
                if (permanent != null) {
                    permanent.damage(amount.calculate(game, source, this), source.getSourceId(), source, game, false, preventable);
                }
                Player player = game.getPlayer(targetId);
                if (player != null) {
                    player.damage(amount.calculate(game, source, this), source.getSourceId(), source, game, false, preventable);
                }
            }
        }
        return true;
    }
    for (UUID targetId : this.getTargetPointer().getTargets(game, source)) {
        Permanent permanent = game.getPermanent(targetId);
        if (permanent != null) {
            permanent.damage(amount.calculate(game, source, this), source.getSourceId(), source, game, false, preventable);
        } else {
            Player player = game.getPlayer(targetId);
            if (player != null) {
                player.damage(amount.calculate(game, source, this), source.getSourceId(), source, game, false, preventable);
            }
        }
    }
    return true;
}
Also used : Target(mage.target.Target) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) UUID(java.util.UUID)

Example 67 with Target

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

the class DamageTargetEffect method getText.

@Override
public String getText(Mode mode) {
    if (staticText != null && !staticText.isEmpty()) {
        return staticText;
    }
    StringBuilder sb = new StringBuilder();
    String message = amount.getMessage();
    sb.append(this.sourceName).append(" deals ");
    if (message.isEmpty() || !message.equals("1")) {
        sb.append(amount).append(' ');
    }
    sb.append("damage to ");
    if (!targetDescription.isEmpty()) {
        sb.append(targetDescription);
    } else {
        if (!mode.getTargets().isEmpty()) {
            Target firstTarget = mode.getTargets().get(0);
            String targetName = firstTarget.getTargetName();
            if (targetName.contains("any")) {
                sb.append(targetName);
            } else {
                if (firstTarget.getMinNumberOfTargets() == 0) {
                    int maxTargets = firstTarget.getMaxNumberOfTargets();
                    if (maxTargets == Integer.MAX_VALUE) {
                        sb.append("any number of ");
                    } else {
                        sb.append("up to ");
                        sb.append(CardUtil.numberToText(maxTargets));
                        sb.append(' ');
                    }
                }
                sb.append("target ").append(targetName);
            }
        } else {
            sb.append("that target");
        }
    }
    if (!message.isEmpty()) {
        if (message.equals("1")) {
            sb.append(" equal to the number of ");
        } else {
            if (message.startsWith("the") || message.startsWith("twice")) {
                sb.append(" equal to ");
            } else {
                sb.append(" for each ");
            }
        }
        sb.append(message);
    }
    if (!preventable) {
        sb.append(". The damage can't be prevented");
    }
    return sb.toString();
}
Also used : Target(mage.target.Target)

Example 68 with Target

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

the class LoseAbilityTargetEffect method getText.

@Override
public String getText(Mode mode) {
    if (staticText != null && !staticText.isEmpty()) {
        return staticText;
    }
    StringBuilder sb = new StringBuilder();
    Target target = mode.getTargets().get(0);
    if (target.getNumberOfTargets() > 1) {
        if (target.getNumberOfTargets() < target.getMaxNumberOfTargets()) {
            sb.append("Up to");
        }
        sb.append(target.getMaxNumberOfTargets()).append(" target ").append(target.getTargetName()).append(" loses ");
    } else {
        sb.append("Target ").append(target.getTargetName()).append(" loses ");
    }
    sb.append(ability.getRule());
    if (!duration.toString().isEmpty()) {
        sb.append(' ').append(duration.toString());
    }
    return sb.toString();
}
Also used : Target(mage.target.Target)

Example 69 with Target

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

the class LoseAbilityOrAnotherAbilityTargetEffect method getText.

@Override
public String getText(Mode mode) {
    if (staticText != null && !staticText.isEmpty()) {
        return staticText;
    }
    StringBuilder sb = new StringBuilder();
    Target target = mode.getTargets().get(0);
    if (target.getNumberOfTargets() > 1) {
        if (target.getNumberOfTargets() < target.getMaxNumberOfTargets()) {
            sb.append("Up to");
        }
        sb.append(target.getMaxNumberOfTargets()).append(" target ").append(target.getTargetName()).append(" loses ");
    } else {
        sb.append("Target ").append(target.getTargetName()).append(" loses ");
    }
    sb.append(ability.getRule());
    sb.append(" or ");
    sb.append(ability2.getRule());
    if (!duration.toString().isEmpty()) {
        sb.append(' ').append(duration.toString());
    }
    return sb.toString();
}
Also used : Target(mage.target.Target)

Example 70 with Target

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

the class CastWithoutPayingManaCostEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    int cmc = manaCost.calculate(game, source, this);
    FilterCard filter = this.filter.copy();
    filter.setMessage(filter.getMessage().replace("%mv", "" + cmc));
    filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, cmc + 1));
    Target target = new TargetCardInHand(filter);
    if (!target.canChoose(source.getSourceId(), controller.getId(), game) || !controller.chooseUse(Outcome.PlayForFree, "Cast " + CardUtil.addArticle(filter.getMessage()) + " without paying its mana cost?", source, game)) {
        return true;
    }
    Card cardToCast = null;
    boolean cancel = false;
    while (controller.canRespond() && !cancel) {
        if (controller.chooseTarget(Outcome.PlayForFree, target, source, game)) {
            cardToCast = game.getCard(target.getFirstTarget());
            if (cardToCast != null) {
                if (cardToCast.getSpellAbility() == null) {
                    Logger.getLogger(CastWithoutPayingManaCostEffect.class).fatal("Card: " + cardToCast.getName() + " is no land and has no spell ability!");
                    cancel = true;
                }
                if (cardToCast.getSpellAbility().canChooseTarget(game, controller.getId())) {
                    cancel = true;
                }
            }
        } else {
            cancel = true;
        }
    }
    if (cardToCast != null) {
        game.getState().setValue("PlayFromNotOwnHandZone" + cardToCast.getId(), Boolean.TRUE);
        controller.cast(controller.chooseAbilityForCast(cardToCast, game, true), game, true, new ApprovingObject(source, game));
        game.getState().setValue("PlayFromNotOwnHandZone" + cardToCast.getId(), null);
    }
    return true;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) Target(mage.target.Target) ApprovingObject(mage.ApprovingObject) TargetCardInHand(mage.target.common.TargetCardInHand) FilterCard(mage.filter.FilterCard) FilterNonlandCard(mage.filter.common.FilterNonlandCard) Card(mage.cards.Card)

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