use of mage.target.common.TargetCreaturePermanent in project mage by magefree.
the class DeadReckoningEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
TargetCardInYourGraveyard target1 = new TargetCardInYourGraveyard(new FilterCreatureCard("creature card in your graveyard"));
TargetCreaturePermanent target2 = new TargetCreaturePermanent();
if (controller != null) {
if (target1.canChoose(source.getSourceId(), source.getControllerId(), game) && controller.choose(Outcome.Benefit, target1, source.getSourceId(), game) && target2.canChoose(source.getSourceId(), source.getControllerId(), game) && controller.choose(Outcome.Damage, target2, source.getSourceId(), game)) {
Card creatureInGraveyard = game.getCard(target1.getFirstTarget());
if (creatureInGraveyard != null) {
if (controller.putCardsOnTopOfLibrary(creatureInGraveyard, game, source, true)) {
int power = creatureInGraveyard.getPower().getValue();
Permanent creature = game.getPermanent(target2.getFirstTarget());
if (creature != null) {
creature.damage(power, source.getSourceId(), source, game, false, true);
return true;
}
}
}
}
}
return false;
}
use of mage.target.common.TargetCreaturePermanent in project mage by magefree.
the class DoOrDieEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
Player targetPlayer = game.getPlayer(source.getFirstTarget());
if (player != null && targetPlayer != null) {
int count = game.getBattlefield().countAll(StaticFilters.FILTER_PERMANENT_CREATURES, targetPlayer.getId(), game);
TargetCreaturePermanent creatures = new TargetCreaturePermanent(0, count, new FilterCreaturePermanent("creatures to put in the first pile"), true);
List<Permanent> pile1 = new ArrayList<>();
creatures.setRequired(false);
if (player.choose(Outcome.Neutral, creatures, source.getSourceId(), game)) {
List<UUID> targets = creatures.getTargets();
for (UUID targetId : targets) {
Permanent p = game.getPermanent(targetId);
if (p != null) {
pile1.add(p);
}
}
}
List<Permanent> pile2 = new ArrayList<>();
for (Permanent p : game.getBattlefield().getAllActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, targetPlayer.getId(), game)) {
if (!pile1.contains(p)) {
pile2.add(p);
}
}
boolean choice = targetPlayer.choosePile(Outcome.DestroyPermanent, "Choose a pile to destroy.", pile1, pile2, game);
if (choice) {
destroyPermanents(pile1, game, source);
} else {
destroyPermanents(pile2, game, source);
}
return true;
}
return false;
}
use of mage.target.common.TargetCreaturePermanent in project mage by magefree.
the class GiftOfDoomEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
Permanent giftOfDoom = game.getPermanent(source.getSourceId());
if (player == null || giftOfDoom == null) {
return false;
}
TargetCreaturePermanent target = new TargetCreaturePermanent(filter);
target.setNotTarget(true);
if (player.choose(outcome, target, source.getSourceId(), game) && game.getPermanent(target.getFirstTarget()) != null && !game.getPermanent(target.getFirstTarget()).cantBeAttachedBy(giftOfDoom, source, game, false)) {
game.getState().setValue("attachTo:" + giftOfDoom.getId(), target.getFirstTarget());
game.getPermanent(target.getFirstTarget()).addAttachment(giftOfDoom.getId(), source, game);
return true;
}
// no legal target
player.moveCardToGraveyardWithInfo(giftOfDoom, source, game, Zone.BATTLEFIELD);
return false;
}
use of mage.target.common.TargetCreaturePermanent in project mage by magefree.
the class MistbladeShinobiTriggeredAbility method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (((DamagedPlayerEvent) event).isCombatDamage() && event.getSourceId().equals(sourceId)) {
Player opponent = game.getPlayer(event.getPlayerId());
if (opponent != null) {
FilterCreaturePermanent filter = new FilterCreaturePermanent("creature " + opponent.getLogName() + " controls");
filter.add(new ControllerIdPredicate(opponent.getId()));
this.getTargets().clear();
this.addTarget(new TargetCreaturePermanent(filter));
return true;
}
}
return false;
}
use of mage.target.common.TargetCreaturePermanent in project mage by magefree.
the class RiptideEntrancerTriggeredAbility method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
Player opponent = game.getPlayer(event.getPlayerId());
if (opponent != null && event.getSourceId().equals(this.sourceId)) {
FilterCreaturePermanent filter = new FilterCreaturePermanent("creature " + opponent.getLogName() + " controls");
filter.add(new ControllerIdPredicate(opponent.getId()));
this.getTargets().clear();
this.addTarget(new TargetCreaturePermanent(filter));
return true;
}
return false;
}
Aggregations