Search in sources :

Example 1 with HumanToken

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;
}
Also used : StaticFilters(mage.filter.StaticFilters) Outcome(mage.constants.Outcome) HumanToken(mage.game.permanent.token.HumanToken) Set(java.util.Set) OneShotEffect(mage.abilities.effects.OneShotEffect) UUID(java.util.UUID) Controllable(mage.game.Controllable) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) Player(mage.players.Player) CardSetInfo(mage.cards.CardSetInfo) Objects(java.util.Objects) Game(mage.game.Game) CardImpl(mage.cards.CardImpl) Map(java.util.Map) CardType(mage.constants.CardType) Ability(mage.abilities.Ability) Player(mage.players.Player) Controllable(mage.game.Controllable) Objects(java.util.Objects) UUID(java.util.UUID) HumanToken(mage.game.permanent.token.HumanToken)

Aggregations

Map (java.util.Map)1 Objects (java.util.Objects)1 Set (java.util.Set)1 UUID (java.util.UUID)1 Function (java.util.function.Function)1 Collectors (java.util.stream.Collectors)1 Ability (mage.abilities.Ability)1 OneShotEffect (mage.abilities.effects.OneShotEffect)1 CardImpl (mage.cards.CardImpl)1 CardSetInfo (mage.cards.CardSetInfo)1 CardType (mage.constants.CardType)1 Outcome (mage.constants.Outcome)1 StaticFilters (mage.filter.StaticFilters)1 Controllable (mage.game.Controllable)1 Game (mage.game.Game)1 HumanToken (mage.game.permanent.token.HumanToken)1 Player (mage.players.Player)1