use of mage.target.Target in project mage by magefree.
the class WoodElementalEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Card sourceCard = game.getCard(source.getSourceId());
if (controller != null && sourceCard != null) {
Target target = new TargetControlledPermanent(0, Integer.MAX_VALUE, filter, true);
if (target.canChoose(source.getSourceId(), source.getControllerId(), game) && controller.chooseTarget(Outcome.Detriment, target, source, game)) {
if (!target.getTargets().isEmpty()) {
int sacrificedForests = target.getTargets().size();
game.informPlayers(controller.getLogName() + " sacrifices " + sacrificedForests + " untapped Forests for " + sourceCard.getLogName());
for (UUID targetId : target.getTargets()) {
Permanent targetPermanent = game.getPermanent(targetId);
if (targetPermanent != null) {
targetPermanent.sacrifice(source, game);
}
}
game.addEffect(new SetPowerToughnessSourceEffect(sacrificedForests, sacrificedForests, Duration.Custom, SubLayer.SetPT_7b), source);
return true;
}
}
}
return false;
}
use of mage.target.Target in project mage by magefree.
the class LicidSpecialActionEffect method apply.
@Override
public boolean apply(Layer layer, SubLayer sublayer, Ability source, Game game) {
Permanent licid = (Permanent) source.getSourceObjectIfItStillExists(game);
if (licid != null) {
switch(layer) {
case TypeChangingEffects_4:
licid.removeAllCardTypes(game);
licid.addCardType(game, CardType.ENCHANTMENT);
licid.removeAllSubTypes(game);
licid.addSubType(game, SubType.AURA);
break;
case AbilityAddingRemovingEffects_6:
List<Ability> toRemove = new ArrayList<>();
for (Ability ability : licid.getAbilities(game)) {
for (Effect effect : ability.getEffects()) {
if (effect instanceof LicidEffect) {
toRemove.add(ability);
break;
}
}
}
licid.removeAbilities(toRemove, source.getSourceId(), game);
Ability ability = new EnchantAbility("creature");
ability.setRuleAtTheTop(true);
licid.addAbility(ability, source.getSourceId(), game);
licid.getSpellAbility().getTargets().clear();
Target target = new TargetCreaturePermanent();
target.addTarget(this.getTargetPointer().getFirst(game, source), source, game);
licid.getSpellAbility().getTargets().add(target);
}
return true;
}
discard();
return false;
}
use of mage.target.Target in project mage by magefree.
the class CopyPermanentEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
MageObject sourcePermanent = game.getPermanentEntering(source.getSourceId());
if (sourcePermanent == null) {
sourcePermanent = game.getObject(source.getSourceId());
}
if (controller == null || sourcePermanent == null) {
return false;
}
Permanent copyFromPermanent = null;
if (useTargetOfAbility) {
copyFromPermanent = game.getPermanent(getTargetPointer().getFirst(game, source));
} else {
Target target = new TargetPermanent(filter);
target.setNotTarget(true);
if (target.canChoose(source.getSourceId(), controller.getId(), game)) {
controller.choose(Outcome.Copy, target, source.getSourceId(), game);
copyFromPermanent = game.getPermanent(target.getFirstTarget());
}
}
if (copyFromPermanent == null) {
return true;
}
bluePrintPermanent = game.copyPermanent(duration, copyFromPermanent, sourcePermanent.getId(), source, applier);
if (bluePrintPermanent == null) {
return false;
}
// if object is a copy of an aura, it needs to attach again for new target
if (!bluePrintPermanent.hasSubtype(SubType.AURA, game)) {
return true;
}
// copied from mage.cards.c.CopyEnchantment.java
// permanent can be attached (Estrid's Mask) or enchant (Utopia Sprawl)
// TODO: fix Animate Dead -- it's can't be copied (can't retarget)
Outcome auraOutcome = Outcome.BoostCreature;
Target auraTarget = null;
// attach - search effect in spell ability (example: cast Utopia Sprawl, cast Estrid's Invocation on it)
for (Ability ability : bluePrintPermanent.getAbilities()) {
if (!(ability instanceof SpellAbility)) {
continue;
}
auraOutcome = ability.getEffects().getOutcome(ability);
for (Effect effect : ability.getEffects()) {
if (!(effect instanceof AttachEffect)) {
continue;
}
if (bluePrintPermanent.getSpellAbility().getTargets().size() > 0) {
auraTarget = bluePrintPermanent.getSpellAbility().getTargets().get(0);
}
}
}
// enchant - search in all abilities (example: cast Estrid's Invocation on enchanted creature by Estrid, the Masked second ability, cast Estrid's Invocation on it)
if (auraTarget == null) {
for (Ability ability : bluePrintPermanent.getAbilities()) {
if (!(ability instanceof EnchantAbility)) {
continue;
}
auraOutcome = ability.getEffects().getOutcome(ability);
if (ability.getTargets().size() > 0) {
// Animate Dead don't have targets
auraTarget = ability.getTargets().get(0);
}
}
}
/* if this is a copy of a copy, the copy's target has been
* copied and needs to be cleared
*/
if (auraTarget == null) {
return true;
}
// clear selected target
if (auraTarget.getFirstTarget() != null) {
auraTarget.remove(auraTarget.getFirstTarget());
}
// select new target
auraTarget.setNotTarget(true);
if (!controller.choose(auraOutcome, auraTarget, source.getSourceId(), game)) {
return true;
}
UUID targetId = auraTarget.getFirstTarget();
Permanent targetPermanent = game.getPermanent(targetId);
Player targetPlayer = game.getPlayer(targetId);
if (targetPermanent != null) {
targetPermanent.addAttachment(sourcePermanent.getId(), source, game);
} else if (targetPlayer != null) {
targetPlayer.addAttachment(sourcePermanent.getId(), source, game);
} else {
return false;
}
return true;
}
use of mage.target.Target in project mage by magefree.
the class BecomeBlockedTargetEffect method getText.
@Override
public String getText(Mode mode) {
if (staticText != null && !staticText.isEmpty()) {
return staticText;
}
StringBuilder sb = new StringBuilder();
if (mode.getTargets().isEmpty()) {
return "that creature becomes blocked";
}
Target target = mode.getTargets().get(0);
if (target.getNumberOfTargets() == 1) {
String targetName = target.getTargetName();
sb.append("target ").append(targetName).append(" becomes blocked");
return sb.toString();
}
if (target.getMaxNumberOfTargets() != target.getMinNumberOfTargets()) {
sb.append("up to ");
}
sb.append(CardUtil.numberToText(target.getMaxNumberOfTargets()));
sb.append(" target ").append(target.getTargetName()).append(" become blocked");
return sb.toString();
}
use of mage.target.Target in project mage by magefree.
the class DamageMultiEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
this.damagedSet.clear();
if (source.getTargets().isEmpty()) {
return true;
}
Target multiTarget = source.getTargets().get(0);
for (UUID target : multiTarget.getTargets()) {
Permanent permanent = game.getPermanent(target);
if (permanent != null) {
if (permanent.damage(multiTarget.getTargetAmount(target), source.getSourceId(), source, game, false, true) > 0) {
damagedSet.add(new MageObjectReference(permanent, game));
}
} else {
Player player = game.getPlayer(target);
if (player != null) {
player.damage(multiTarget.getTargetAmount(target), source.getSourceId(), source, game);
}
}
}
return true;
}
Aggregations