use of mage.target.common.TargetCreaturePermanent in project mage by magefree.
the class SparkMageTriggeredAbility method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
DamagedPlayerEvent damageEvent = (DamagedPlayerEvent) event;
if (damageEvent.isCombatDamage() && event.getSourceId().equals(this.getSourceId())) {
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.getTargets().add(new TargetCreaturePermanent(filter));
return true;
}
}
return false;
}
use of mage.target.common.TargetCreaturePermanent in project mage by magefree.
the class StandOrFallEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
// 802.2. As the combat phase starts, the attacking player doesn’t choose an opponent to become the defending player.
// Instead, all the attacking player’s opponents are defending players during the combat phase.
//
// 802.2a Any rule, object, or effect that refers to a “defending player” refers to one specific defending player, not to all of the defending players.
// If an ability of an attacking creature refers to a defending player, or a spell or ability refers to both an attacking creature and a defending player,
// then unless otherwise specified, the defending player it’s referring to is the player that creature was attacking at the time it became an attacking
// creature that combat, or the controller of the planeswalker that creature was attacking at the time it became an attacking creature that combat. If a spell or ability
// could apply to multiple attacking creatures, the appropriate defending player is individually determined for each of those attacking creatures.
// If there are multiple defending players that could be chosen, the controller of the spell or ability chooses one.
//
// https://www.mtgsalvation.com/forums/magic-fundamentals/magic-rulings/756140-stand-or-fall-mechanics
Player player = game.getPlayer(source.getControllerId());
Set<UUID> opponents = game.getOpponents(source.getControllerId());
if (!opponents.isEmpty()) {
Player targetPlayer = game.getPlayer(opponents.iterator().next());
if (opponents.size() > 1) {
TargetOpponent targetOpponent = new TargetOpponent(true);
if (player != null && player.chooseTarget(Outcome.Neutral, targetOpponent, source, game)) {
targetPlayer = game.getPlayer(targetOpponent.getFirstTarget());
game.informPlayers(player.getLogName() + " chose " + targetPlayer.getLogName() + " as the defending player");
}
}
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, "Choose which pile can block this turn.", pile1, pile2, game);
List<Permanent> chosenPile = choice ? pile2 : pile1;
List<Permanent> otherPile = choice ? pile1 : pile2;
for (Permanent permanent : chosenPile) {
if (permanent != null) {
RestrictionEffect effect = new CantBlockTargetEffect(Duration.EndOfTurn);
effect.setText("");
effect.setTargetPointer(new FixedTarget(permanent, game));
game.addEffect(effect, source);
}
}
game.informPlayers("Creatures that can block this turn: " + otherPile.stream().map(Permanent::getLogName).collect(Collectors.joining(", ")));
return true;
}
}
return false;
}
use of mage.target.common.TargetCreaturePermanent in project mage by magefree.
the class ZndrspltsJudgmentEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
ChooseFriendsAndFoes choice = new ChooseFriendsAndFoes();
choice.chooseFriendOrFoe(controller, source, game);
for (Player player : choice.getFriends()) {
if (player == null) {
continue;
}
FilterCreaturePermanent filter = new FilterCreaturePermanent("creature you control");
filter.add(new ControllerIdPredicate(player.getId()));
TargetCreaturePermanent target = new TargetCreaturePermanent(filter);
if (!player.choose(Outcome.Copy, target, source.getSourceId(), game)) {
continue;
}
Effect effect = new CreateTokenCopyTargetEffect(player.getId());
effect.setTargetPointer(new FixedTarget(target.getFirstTarget(), game));
effect.apply(game, source);
}
for (Player player : choice.getFoes()) {
FilterCreaturePermanent filter = new FilterCreaturePermanent("creature you control");
filter.add(new ControllerIdPredicate(player.getId()));
TargetCreaturePermanent target = new TargetCreaturePermanent(filter);
if (!player.choose(Outcome.ReturnToHand, target, source.getSourceId(), game)) {
continue;
}
Effect effect = new ReturnToHandTargetEffect();
effect.setTargetPointer(new FixedTarget(target.getFirstTarget(), game));
effect.apply(game, source);
}
return true;
}
use of mage.target.common.TargetCreaturePermanent in project mage by magefree.
the class BecomesAuraAttachToManifestSourceEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Permanent enchantment = game.getPermanent(source.getSourceId());
if (controller != null && enchantment != null) {
// manifest top card
Card card = controller.getLibrary().getFromTop(game);
if (card != null) {
new ManifestEffect(1).apply(game, source);
Permanent enchantedCreature = game.getPermanent(card.getId());
if (enchantedCreature != null) {
enchantedCreature.addAttachment(enchantment.getId(), source, game);
FilterCreaturePermanent filter = new FilterCreaturePermanent();
Target target = new TargetCreaturePermanent(filter);
target.addTarget(enchantedCreature.getId(), source, game);
game.addEffect(new BecomesAuraSourceEffect(target), source);
}
}
return true;
}
return false;
}
use of mage.target.common.TargetCreaturePermanent in project mage by magefree.
the class SnappingThraggTriggeredAbility 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