use of mage.target.TargetPermanent in project mage by magefree.
the class CephalidConstableTriggeredAbility method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (event.getSourceId().equals(this.sourceId) && ((DamagedPlayerEvent) event).isCombatDamage()) {
FilterPermanent filter = new FilterPermanent("permanent" + (event.getAmount() > 1 ? "s" : "") + " damaged player control");
filter.add(new ControllerIdPredicate(event.getPlayerId()));
Target target = new TargetPermanent(0, event.getAmount(), filter, false);
this.getTargets().clear();
this.getTargets().add(target);
return true;
}
return false;
}
use of mage.target.TargetPermanent in project mage by magefree.
the class DarkIntimationsReplacementEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
List<UUID> perms = new ArrayList<>();
filter.add(TargetController.YOU.getControllerPredicate());
for (UUID playerId : game.getOpponents(source.getControllerId())) {
Player player = game.getPlayer(playerId);
if (player != null) {
TargetPermanent target = new TargetPermanent(1, 1, filter, true);
if (target.canChoose(source.getSourceId(), player.getId(), game)) {
player.chooseTarget(Outcome.Sacrifice, target, source, game);
perms.addAll(target.getTargets());
}
}
}
for (UUID permID : perms) {
Permanent permanent = game.getPermanent(permID);
if (permanent != null) {
permanent.sacrifice(source, game);
}
}
for (UUID playerId : game.getOpponents(source.getControllerId())) {
Player player = game.getPlayer(playerId);
if (player != null) {
player.discardOne(false, false, source, game);
}
}
TargetCardInYourGraveyard target = new TargetCardInYourGraveyard(filterCard);
if (target.canChoose(source.getSourceId(), source.getControllerId(), game) && controller.choose(Outcome.ReturnToHand, target, source.getSourceId(), game)) {
Card card = game.getCard(target.getFirstTarget());
if (card == null) {
return false;
}
controller.moveCards(card, Zone.HAND, source, game);
}
controller.drawCards(1, source, game);
return true;
}
use of mage.target.TargetPermanent in project mage by magefree.
the class DoomForetoldEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Player player = game.getPlayer(game.getActivePlayerId());
if (controller == null || player == null) {
return false;
}
FilterPermanent filter2 = filter.copy();
filter2.add(new ControllerIdPredicate(player.getId()));
if (game.getBattlefield().contains(filter2, source, game, 1)) {
TargetPermanent target = new TargetPermanent(filter2);
target.setNotTarget(true);
if (player.choose(Outcome.Sacrifice, target, source.getSourceId(), game)) {
Permanent permanent = game.getPermanent(target.getFirstTarget());
if (permanent != null && permanent.sacrifice(source, game)) {
return true;
}
}
}
player.discard(1, false, false, source, game);
player.loseLife(2, game, source, false);
controller.drawCards(1, source, game);
controller.gainLife(2, game, source);
effect1.apply(game, source);
effect2.apply(game, source);
return true;
}
use of mage.target.TargetPermanent in project mage by magefree.
the class EnigmaticIncarnationEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null || game.getBattlefield().count(filter, source.getSourceId(), source.getControllerId(), game) == 0 || !player.chooseUse(outcome, "Sacrifice an enchantment?", source, game)) {
return false;
}
TargetPermanent target = new TargetPermanent(0, 1, filter, true);
player.choose(outcome, target, source.getSourceId(), game);
Permanent permanent = game.getPermanent(target.getFirstTarget());
if (permanent == null) {
return false;
}
game.getState().processAction(game);
int cmc = permanent.getManaValue();
if (!permanent.sacrifice(source, game)) {
return false;
}
FilterCard filterCard = new FilterCreatureCard("creature card with mana value " + (cmc + 1));
filterCard.add(new ManaValuePredicate(ComparisonType.EQUAL_TO, cmc + 1));
return new SearchLibraryPutInPlayEffect(new TargetCardInLibrary(filterCard)).apply(game, source);
}
use of mage.target.TargetPermanent in project mage by magefree.
the class FaerieImpostorEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
TargetPermanent target = new TargetPermanent(1, 1, filter, true);
if (target.canChoose(source.getSourceId(), controller.getId(), game) && controller.chooseUse(outcome, "Return another creature you control to its owner's hand?", source, game)) {
controller.chooseTarget(Outcome.ReturnToHand, target, source, game);
Permanent permanent = game.getPermanent(target.getFirstTarget());
if (permanent != null) {
controller.moveCards(permanent, Zone.HAND, source, game);
return true;
}
}
Permanent permanent = source.getSourcePermanentIfItStillExists(game);
return permanent != null && permanent.sacrifice(source, game);
}
Aggregations