use of mage.filter.FilterPlayer in project mage by magefree.
the class BurningCinderFuryOfCrimsonChaosFireWatcher method apply.
@Override
public boolean apply(Game game, Ability source) {
Player tappingPlayer = game.getPlayer(firstControllerId);
Permanent permanentToControl = game.getPermanent(this.getTargetPointer().getFirst(game, source));
if (tappingPlayer != null && permanentToControl != null) {
// Create opponent filter list manually because otherwise opponent check prevents controller of this to be valid
FilterPlayer filter = new FilterPlayer("opponent to control " + permanentToControl.getIdName());
List<PlayerIdPredicate> opponentPredicates = new ArrayList<>();
for (UUID opponentId : game.getOpponents(firstControllerId)) {
opponentPredicates.add(new PlayerIdPredicate(opponentId));
}
filter.add(Predicates.or(opponentPredicates));
Target target = new TargetPlayer(1, 1, true, filter);
target.setTargetController(firstControllerId);
target.setAbilityController(source.getControllerId());
if (tappingPlayer.chooseTarget(outcome, target, source, game)) {
Player chosenOpponent = game.getPlayer(target.getFirstTarget());
if (chosenOpponent != null) {
game.informPlayers(tappingPlayer.getLogName() + " chose " + chosenOpponent.getLogName() + " to gain control of " + permanentToControl.getLogName() + " at the beginning of the next end step");
ContinuousEffect effect = new BurningCinderFuryOfCrimsonChaosFireCreatureGainControlEffect(Duration.Custom, chosenOpponent.getId());
effect.setTargetPointer(new FixedTarget(permanentToControl.getId(), game));
game.addDelayedTriggeredAbility(new AtTheBeginOfNextEndStepDelayedTriggeredAbility(effect), source);
return true;
}
}
}
return false;
}
Aggregations