use of mage.game.permanent.Permanent in project mage by magefree.
the class DireTacticsEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent permanent = game.getPermanent(source.getFirstTarget());
Player player = game.getPlayer(source.getControllerId());
if (permanent == null || player == null) {
return false;
}
int toughness = permanent.getToughness().getValue();
player.moveCards(permanent, Zone.EXILED, source, game);
if (game.getBattlefield().countAll(filter, player.getId(), game) < 1) {
player.loseLife(toughness, game, source, false);
}
return true;
}
use of mage.game.permanent.Permanent in project mage by magefree.
the class DispersalEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
Set<PermanentIdPredicate> permsToReturn = new HashSet<>();
for (UUID opponentId : game.getOpponents(player.getId())) {
Player opponent = game.getPlayer(opponentId);
if (opponent == null) {
continue;
}
int highestCMC = 0;
for (Permanent permanent : game.getBattlefield().getAllActivePermanents(opponentId)) {
if (permanent != null) {
highestCMC = Math.max(highestCMC, permanent.getManaValue());
}
}
FilterPermanent filter = new FilterNonlandPermanent("permanent you control with mana value " + highestCMC);
filter.add(new ManaValuePredicate(ComparisonType.EQUAL_TO, highestCMC));
filter.add(new ControllerIdPredicate(opponentId));
Target target = new TargetPermanent(1, 1, filter, true);
if (opponent.choose(outcome, target, source.getSourceId(), game)) {
if (target.getFirstTarget() == null) {
continue;
}
permsToReturn.add(new PermanentIdPredicate(target.getFirstTarget()));
}
}
FilterPermanent filter = new FilterPermanent();
filter.add(Predicates.or(permsToReturn));
new ReturnToHandFromBattlefieldAllEffect(filter).apply(game, source);
new DiscardEachPlayerEffect(StaticValue.get(1), false, TargetController.OPPONENT).apply(game, source);
return true;
}
use of mage.game.permanent.Permanent in project mage by magefree.
the class DiscordantDirgeEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent discordantDirge = game.getPermanentOrLKIBattlefield(source.getSourceId());
if (discordantDirge == null) {
return false;
}
int verseCounters = discordantDirge.getCounters(game).getCount(CounterType.VERSE);
Player targetOpponent = game.getPlayer(source.getFirstTarget());
Player controller = game.getPlayer(source.getControllerId());
if (targetOpponent == null || controller == null) {
return false;
}
controller.lookAtCards(targetOpponent.getName() + " hand", targetOpponent.getHand(), game);
TargetCard target = new TargetCard(0, verseCounters, Zone.HAND, new FilterCard());
target.setNotTarget(true);
if (!controller.choose(Outcome.Benefit, targetOpponent.getHand(), target, game)) {
return false;
}
targetOpponent.discard(new CardsImpl(target.getTargets()), false, source, game);
return true;
}
use of mage.game.permanent.Permanent in project mage by magefree.
the class ElkinLairPutIntoGraveyardEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(game.getActivePlayerId());
Permanent sourcePermanent = game.getPermanent(source.getSourceId());
if (player != null && sourcePermanent != null) {
Card[] cards = player.getHand().getCards(new FilterCard(), game).toArray(new Card[0]);
if (cards.length > 0) {
Card card = cards[RandomUtil.nextInt(cards.length)];
if (card != null) {
String exileName = sourcePermanent.getIdName() + " <this card may be played the turn it was exiled";
player.moveCardsToExile(card, source, game, true, source.getSourceId(), exileName);
if (game.getState().getZone(card.getId()) == Zone.EXILED) {
ContinuousEffect effect = new PlayFromNotOwnHandZoneTargetEffect(Zone.EXILED, Duration.EndOfTurn);
effect.setTargetPointer(new FixedTarget(card, game));
game.addEffect(effect, source);
DelayedTriggeredAbility delayed = new AtTheBeginOfNextEndStepDelayedTriggeredAbility(new ElkinLairPutIntoGraveyardEffect());
game.addDelayedTriggeredAbility(delayed, source);
return true;
}
}
}
}
return false;
}
use of mage.game.permanent.Permanent in project mage by magefree.
the class FightOrFlightEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
Player targetPlayer = game.getPlayer(game.getCombat().getAttackingPlayerId());
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 attack 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 CantAttackTargetEffect(Duration.EndOfTurn);
effect.setText("");
effect.setTargetPointer(new FixedTarget(permanent, game));
game.addEffect(effect, source);
}
}
game.informPlayers("Creatures that can attack this turn: " + otherPile.stream().map(Permanent::getLogName).collect(Collectors.joining(", ")));
return true;
}
return false;
}
Aggregations