use of mage.game.permanent.token.HumanToken in project mage by magefree.
the class SunsetRevelryEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
Set<UUID> opponents = game.getOpponents(source.getControllerId());
if (opponents.stream().map(game::getPlayer).filter(Objects::nonNull).mapToInt(Player::getLife).anyMatch(x -> x > player.getLife())) {
player.gainLife(4, game, source);
}
Map<UUID, Integer> map = game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, source.getControllerId(), game).stream().filter(Objects::nonNull).map(Controllable::getControllerId).filter(uuid -> opponents.contains(uuid) || source.getControllerId().equals(uuid)).collect(Collectors.toMap(Function.identity(), x -> 1, Integer::sum));
if (map.getOrDefault(source.getControllerId(), 0) < map.values().stream().mapToInt(x -> x).max().orElse(0)) {
new HumanToken().putOntoBattlefield(2, game, source, source.getControllerId());
}
if (opponents.stream().map(game::getPlayer).filter(Objects::nonNull).map(Player::getHand).mapToInt(Set::size).anyMatch(x -> x > player.getHand().size())) {
player.drawCards(1, source, game);
}
return true;
}
Aggregations