use of mage.target.Target in project mage by magefree.
the class MurmursFromBeyondEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
MageObject sourceObject = game.getObject(source.getSourceId());
if (sourceObject != null && controller != null) {
Cards cards = new CardsImpl(controller.getLibrary().getTopCards(game, 3));
if (!cards.isEmpty()) {
controller.revealCards(staticText, cards, game);
Card cardToGraveyard;
if (cards.size() == 1) {
cardToGraveyard = cards.getRandom(game);
} else {
Player opponent;
Set<UUID> opponents = game.getOpponents(controller.getId());
if (opponents.size() == 1) {
opponent = game.getPlayer(opponents.iterator().next());
} else {
Target target = new TargetOpponent(true);
controller.chooseTarget(Outcome.Detriment, target, source, game);
opponent = game.getPlayer(target.getFirstTarget());
}
TargetCard target = new TargetCard(1, Zone.LIBRARY, new FilterCard());
opponent.chooseTarget(outcome, cards, target, source, game);
cardToGraveyard = game.getCard(target.getFirstTarget());
}
if (cardToGraveyard != null) {
controller.moveCards(cardToGraveyard, Zone.GRAVEYARD, source, game);
cards.remove(cardToGraveyard);
}
controller.moveCards(cards, Zone.HAND, source, game);
}
return true;
}
return false;
}
use of mage.target.Target in project mage by magefree.
the class AwakenElementalToken method apply.
@Override
public boolean apply(Game game, Ability source) {
UUID targetId = null;
for (Target target : source.getTargets()) {
targetId = target.getFirstTarget();
}
if (targetId != null) {
FixedTarget fixedTarget = new FixedTarget(targetId, game);
ContinuousEffect continuousEffect = new BecomesCreatureTargetEffect(new AwakenElementalToken(), false, true, Duration.EndOfGame);
continuousEffect.setTargetPointer(fixedTarget);
game.addEffect(continuousEffect, source);
Effect effect = new AddCountersTargetEffect(CounterType.P1P1.createInstance(3));
effect.setTargetPointer(fixedTarget);
return effect.apply(game, source);
}
return true;
}
use of mage.target.Target in project mage by magefree.
the class PurgingScytheEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Permanent sourcePermanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
if (controller != null && sourcePermanent != null) {
int leastToughness = Integer.MAX_VALUE;
boolean multipleExist = false;
Permanent permanentToDamage = null;
for (Permanent permanent : game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURES, source.getControllerId(), game)) {
if (permanent.getToughness().getValue() < leastToughness) {
permanentToDamage = permanent;
leastToughness = permanent.getToughness().getValue();
multipleExist = false;
} else {
if (permanent.getToughness().getValue() == leastToughness) {
multipleExist = true;
}
}
}
if (multipleExist) {
FilterCreaturePermanent filter = new FilterCreaturePermanent("one of the creatures with the least toughness");
filter.add(new ToughnessPredicate(ComparisonType.EQUAL_TO, leastToughness));
Target target = new TargetPermanent(filter);
target.setNotTarget(true);
if (target.canChoose(source.getSourceId(), source.getControllerId(), game)) {
if (controller.choose(outcome, target, source.getSourceId(), game)) {
permanentToDamage = game.getPermanent(target.getFirstTarget());
}
}
}
if (permanentToDamage != null) {
game.informPlayers(sourcePermanent.getName() + " chosen creature: " + permanentToDamage.getName());
return permanentToDamage.damage(2, source.getSourceId(), source, game, false, true) > 0;
}
return true;
}
return false;
}
use of mage.target.Target in project mage by magefree.
the class RescuerSphinxEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
if (!player.chooseUse(outcome, "Return a nonland permanent you control to your hand?", source, game)) {
return false;
}
Target target = new TargetPermanent(0, 1, filter, true);
if (!player.choose(outcome, target, source.getSourceId(), game)) {
return false;
}
Permanent permanent = game.getPermanent(target.getFirstTarget());
if (permanent == null || !player.moveCards(permanent, Zone.HAND, source, game)) {
return false;
}
return new AddCountersSourceEffect(CounterType.P1P1.createInstance()).apply(game, source);
}
use of mage.target.Target in project mage by magefree.
the class SeismicWaveEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Targets targets = source.getTargets();
if (targets.size() < 2) {
return false;
}
UUID firstTarget = targets.get(0).getFirstTarget();
if (firstTarget != null) {
Permanent targetPermanent = game.getPermanent(firstTarget);
if (targetPermanent != null) {
targetPermanent.damage(2, source, game);
} else {
Player targetPlayer = game.getPlayer(firstTarget);
if (targetPlayer != null) {
targetPlayer.damage(2, source, game);
}
}
}
Target targetOpponent = targets.get(1);
UUID opponentId = targetOpponent.getFirstTarget();
if (opponentId != null && targetOpponent.isLegal(source, game)) {
// Needs this check in case opponent gets hexproof at instant speed
for (Permanent permanent : game.getBattlefield().getAllActivePermanents(filter, opponentId, game)) {
permanent.damage(1, source, game);
}
}
return true;
}
Aggregations