use of mage.filter.predicate.other.PlayerIdPredicate in project mage by magefree.
the class LoxodonPeacekeeperEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Permanent sourcePermanent = game.getPermanent(source.getSourceId());
if (sourcePermanent != null) {
int lowLife = Integer.MAX_VALUE;
Set<UUID> tiedPlayers = new HashSet<>();
for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
Player player = game.getPlayer(playerId);
if (player != null) {
if (player.getLife() < lowLife) {
lowLife = player.getLife();
}
}
}
for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
Player player = game.getPlayer(playerId);
if (player != null) {
if (player.getLife() == lowLife) {
tiedPlayers.add(playerId);
}
}
}
if (tiedPlayers.size() > 0) {
UUID newControllerId = null;
if (tiedPlayers.size() > 1) {
FilterPlayer filter = new FilterPlayer("a player tied for lowest life total");
for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
if (!tiedPlayers.contains(playerId)) {
filter.add(Predicates.not(new PlayerIdPredicate(playerId)));
}
}
TargetPlayer target = new TargetPlayer(1, 1, true, filter);
if (target.canChoose(source.getSourceId(), controller.getId(), game)) {
while (!target.isChosen() && target.canChoose(source.getSourceId(), controller.getId(), game) && controller.canRespond()) {
controller.chooseTarget(outcome, target, source, game);
}
} else {
return false;
}
newControllerId = game.getPlayer(target.getFirstTarget()).getId();
} else {
for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
if (tiedPlayers.contains(playerId)) {
newControllerId = playerId;
break;
}
}
}
if (newControllerId != null) {
ContinuousEffect effect = new GainControlTargetEffect(Duration.Custom, newControllerId);
effect.setTargetPointer(new FixedTarget(sourcePermanent, game));
game.addEffect(effect, source);
game.informPlayers(game.getPlayer(newControllerId).getLogName() + " has gained control of " + sourcePermanent.getLogName());
return true;
}
}
}
}
return false;
}
use of mage.filter.predicate.other.PlayerIdPredicate in project mage by magefree.
the class CapricopianEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
Permanent permanent = game.getPermanent(source.getSourceId());
if (player == null || permanent == null) {
return false;
}
if (!player.chooseUse(outcome, "Reselect attacker for " + permanent.getIdName() + "?", source, game)) {
return false;
}
FilterPlayer filterPlayer = new FilterPlayer();
filterPlayer.add(Predicates.not(new PlayerIdPredicate(permanent.getControllerId())));
filterPlayer.add(Predicates.not(new PlayerIdPredicate(game.getCombat().getDefenderId(permanent.getId()))));
TargetPlayer targetPlayer = new TargetPlayer(0, 1, true, filterPlayer);
player.choose(outcome, targetPlayer, source.getSourceId(), game);
Player newPlayer = game.getPlayer(targetPlayer.getFirstTarget());
if (newPlayer == null) {
return false;
}
game.getCombat().removeAttacker(permanent.getId(), game);
return game.getCombat().addAttackingCreature(permanent.getId(), game, newPlayer.getId());
}
use of mage.filter.predicate.other.PlayerIdPredicate in project mage by magefree.
the class EonFrolickerEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getFirstTarget());
if (player == null) {
return false;
}
game.getState().getTurnMods().add(new TurnMod(player.getId(), false));
FilterPlayer filter = new FilterPlayer(player.getName());
filter.add(new PlayerIdPredicate(player.getId()));
Ability ability = new ProtectionAbility(filter);
game.addEffect(new GainAbilityControlledEffect(ability, Duration.UntilYourNextTurn, StaticFilters.FILTER_PERMANENT_PLANESWALKER), source);
game.addEffect(new GainAbilityControllerEffect(ability, Duration.UntilYourNextTurn), source);
return true;
}
use of mage.filter.predicate.other.PlayerIdPredicate in project mage by magefree.
the class HansErikssonEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
Card card = player.getLibrary().getFromTop(game);
if (card == null) {
return false;
}
player.revealCards(source, new CardsImpl(card), game);
if (!card.isCreature(game)) {
return player.moveCards(card, Zone.HAND, source, game);
}
player.moveCards(card, Zone.BATTLEFIELD, source, game, true, false, false, null);
Permanent permanent = game.getPermanent(card.getId());
if (permanent == null) {
return true;
}
UUID defendingPlayerId = getTargetPointer().getFirst(game, source);
UUID defenderId;
if (game.getBattlefield().count(StaticFilters.FILTER_CONTROLLED_PERMANENT_PLANESWALKER, source.getSourceId(), defendingPlayerId, game) < 1) {
defenderId = defendingPlayerId;
} else {
FilterPlayerOrPlaneswalker filter = new FilterPlayerOrPlaneswalker("defending player or a planeswalker they control");
filter.getPlayerFilter().add(new PlayerIdPredicate(defendingPlayerId));
filter.getPermanentFilter().add(new ControllerIdPredicate(defendingPlayerId));
TargetPlayerOrPlaneswalker target = new TargetPlayerOrPlaneswalker(filter);
target.setNotTarget(true);
player.choose(outcome, target, source.getSourceId(), game);
defenderId = target.getFirstTarget();
}
if (defenderId != null) {
game.getCombat().addAttackerToCombat(permanent.getId(), defenderId, game);
}
Effect fightEffect = new FightTargetSourceEffect();
fightEffect.setTargetPointer(new FixedTarget(permanent, game));
ReflexiveTriggeredAbility ability = new ReflexiveTriggeredAbility(fightEffect, false, "When you put a creature card onto the battlefield this way, it fights {this}");
game.fireReflexiveTriggeredAbility(ability, source);
return true;
}
use of mage.filter.predicate.other.PlayerIdPredicate in project mage by magefree.
the class ZaraRenegadeRecruiterEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Player player = game.getPlayer(targetPointer.getFirst(game, source));
if (controller == null || player == null || player.getHand().isEmpty()) {
return false;
}
TargetCardInHand targetCard = new TargetCardInHand(0, 1, StaticFilters.FILTER_CARD_CREATURE);
controller.choose(outcome, player.getHand(), targetCard, game);
Card card = game.getCard(targetCard.getFirstTarget());
if (card == null) {
return false;
}
controller.moveCards(card, Zone.BATTLEFIELD, source, game, true, false, false, null);
Permanent permanent = game.getPermanent(card.getId());
if (permanent == null) {
return false;
}
UUID defenderId;
if (game.getBattlefield().count(StaticFilters.FILTER_CONTROLLED_PERMANENT_PLANESWALKER, source.getSourceId(), player.getId(), game) < 1) {
defenderId = player.getId();
} else {
FilterPlayerOrPlaneswalker filter = new FilterPlayerOrPlaneswalker(player.getName() + " or a planeswalker controlled by " + player.getName());
filter.getPlayerFilter().add(new PlayerIdPredicate(player.getId()));
filter.getPermanentFilter().add(new ControllerIdPredicate(player.getId()));
TargetPlayerOrPlaneswalker target = new TargetPlayerOrPlaneswalker(filter);
target.setNotTarget(true);
controller.choose(outcome, target, source.getSourceId(), game);
defenderId = target.getFirstTarget();
}
game.getCombat().addAttackerToCombat(permanent.getId(), defenderId, game);
game.addDelayedTriggeredAbility(new AtTheBeginOfNextEndStepDelayedTriggeredAbility(new ReturnToHandTargetEffect().setTargetPointer(new FixedTarget(permanent, game))), source);
return true;
}
Aggregations