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;
}
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();
}
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();
}
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();
}
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;
}
Aggregations