use of mage.target.Target in project mage by magefree.
the class GlyphOfReincarnationEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Permanent targetWall = getTargetPointer().getFirstTargetPermanentOrLKI(game, source);
if (controller != null && targetWall != null) {
BlockedAttackerWatcher watcher = game.getState().getWatcher(BlockedAttackerWatcher.class);
if (watcher != null) {
Map<UUID, Player> destroyed = new HashMap<>();
for (Permanent creature : game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, source.getControllerId(), source.getSourceId(), game)) {
if (!creature.getId().equals(targetWall.getId())) {
if (watcher.creatureHasBlockedAttacker(new MageObjectReference(creature, game), new MageObjectReference(targetWall, game), game)) {
if (creature.destroy(source, game, true) && game.getState().getZone(creature.getId()) == Zone.GRAVEYARD) {
// If a commander is replaced to command zone, the creature does not die
Player permController = game.getPlayer(creature.getControllerId());
if (permController != null) {
destroyed.put(creature.getId(), permController);
}
}
}
}
}
// onto the battlefield under its owner’s control
for (Map.Entry<UUID, Player> entry : destroyed.entrySet()) {
Permanent permanent = (Permanent) game.getLastKnownInformation(entry.getKey(), Zone.BATTLEFIELD);
Player player = entry.getValue();
if (permanent != null && player != null) {
FilterCreatureCard filter = new FilterCreatureCard("a creature card from " + player.getName() + "'s graveyard");
filter.add(new OwnerIdPredicate(player.getId()));
Target targetCreature = new TargetCardInGraveyard(filter);
targetCreature.setNotTarget(true);
if (targetCreature.canChoose(source.getSourceId(), controller.getId(), game) && controller.chooseTarget(outcome, targetCreature, source, game)) {
Card card = game.getCard(targetCreature.getFirstTarget());
if (card != null && game.getState().getZone(card.getId()) == Zone.GRAVEYARD) {
controller.moveCards(card, Zone.BATTLEFIELD, source, game, false, false, true, null);
}
}
}
}
return true;
}
}
return false;
}
use of mage.target.Target in project mage by magefree.
the class GlowsporeShamanEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
Target target = new TargetCardInYourGraveyard(0, 1, filter, true);
if (player.chooseUse(outcome, "Put a land card on top of your library?", source, game) && player.choose(outcome, target, source.getSourceId(), game)) {
Card card = game.getCard(target.getFirstTarget());
if (card != null) {
return player.putCardsOnTopOfLibrary(new CardsImpl(card), game, source, false);
}
}
return true;
}
use of mage.target.Target in project mage by magefree.
the class HeartPiercerManticoreSacrificeEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
Target target = new TargetControlledCreaturePermanent(1, 1, StaticFilters.FILTER_CONTROLLED_ANOTHER_CREATURE, true);
if (!controller.choose(outcome, target, source.getSourceId(), game)) {
return false;
}
Permanent toSacrifice = game.getPermanent(target.getFirstTarget());
if (toSacrifice == null) {
return false;
}
int power = toSacrifice.getPower().getValue();
if (!toSacrifice.sacrifice(source, game)) {
return false;
}
ReflexiveTriggeredAbility trigger = new ReflexiveTriggeredAbility(new DamageTargetEffect(power), false, "{this} deals damage equal to that creature's power to any target.");
trigger.addTarget(new TargetAnyTarget());
game.fireReflexiveTriggeredAbility(trigger, source);
return true;
}
use of mage.target.Target in project mage by magefree.
the class HateMirageEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
source.getTargets().stream().map(Target::getTargets).flatMap(Collection::stream).forEach(uuid -> {
CreateTokenCopyTargetEffect effect = new CreateTokenCopyTargetEffect(source.getControllerId(), null, true);
effect.setTargetPointer(new FixedTarget(uuid, game));
effect.apply(game, source);
effect.exileTokensCreatedAtNextEndStep(game, source);
});
return true;
}
use of mage.target.Target in project mage by magefree.
the class LordOfThePitEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
Permanent sourcePermanent = game.getPermanent(source.getSourceId());
if (sourcePermanent == null) {
sourcePermanent = (Permanent) game.getLastKnownInformation(source.getSourceId(), Zone.BATTLEFIELD);
}
if (player == null || sourcePermanent == null) {
return false;
}
FilterControlledCreaturePermanent filter = new FilterControlledCreaturePermanent("creature other than " + sourcePermanent.getName());
filter.add(AnotherPredicate.instance);
Target target = new TargetControlledCreaturePermanent(1, 1, filter, true);
if (target.canChoose(source.getSourceId(), player.getId(), game)) {
player.choose(Outcome.Sacrifice, target, source.getSourceId(), game);
Permanent permanent = game.getPermanent(target.getFirstTarget());
if (permanent != null) {
permanent.sacrifice(source, game);
return true;
}
} else {
player.damage(7, source.getSourceId(), source, game);
return true;
}
return false;
}
Aggregations