Search in sources :

Example 1 with Controllable

use of mage.game.Controllable in project mage by magefree.

the class ScholarshipSponsorEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Map<UUID, Integer> playerMap = game.getBattlefield().getActivePermanents(StaticFilters.FILTER_LAND, source.getControllerId(), source.getSourceId(), game).stream().map(Controllable::getControllerId).collect(Collectors.toMap(Function.identity(), x -> 1, Integer::sum));
    int maxValue = playerMap.values().stream().mapToInt(x -> x).max().orElse(0);
    if (maxValue < 1) {
        return false;
    }
    for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
        Player player = game.getPlayer(playerId);
        int diff = maxValue - playerMap.getOrDefault(playerId, 0);
        if (player == null || diff < 1) {
            continue;
        }
        TargetCardInLibrary target = new TargetCardInLibrary(diff, StaticFilters.FILTER_CARD_BASIC_LAND);
        player.searchLibrary(target, source, game);
        Cards cards = new CardsImpl(target.getTargets());
        cards.retainZone(Zone.LIBRARY, game);
        player.moveCards(cards.getCards(game), Zone.BATTLEFIELD, source, game, true, false, false, null);
        player.shuffleLibrary(source, game);
    }
    return true;
}
Also used : StaticFilters(mage.filter.StaticFilters) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) Zone(mage.constants.Zone) EntersBattlefieldTriggeredAbility(mage.abilities.common.EntersBattlefieldTriggeredAbility) Cards(mage.cards.Cards) Outcome(mage.constants.Outcome) OneShotEffect(mage.abilities.effects.OneShotEffect) UUID(java.util.UUID) MageInt(mage.MageInt) CardsImpl(mage.cards.CardsImpl) SubType(mage.constants.SubType) Controllable(mage.game.Controllable) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) Player(mage.players.Player) CardSetInfo(mage.cards.CardSetInfo) Game(mage.game.Game) CardImpl(mage.cards.CardImpl) Map(java.util.Map) CardType(mage.constants.CardType) Ability(mage.abilities.Ability) Player(mage.players.Player) UUID(java.util.UUID) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl)

Example 2 with Controllable

use of mage.game.Controllable 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)

Example 3 with Controllable

use of mage.game.Controllable in project mage by magefree.

the class OversimplifyEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    List<Permanent> permanents = game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, source.getControllerId(), source.getSourceId(), game);
    Map<UUID, Integer> playerMap = permanents.stream().filter(Objects::nonNull).collect(Collectors.toMap(Controllable::getControllerId, p -> p.getPower().getValue(), Integer::sum));
    controller.moveCards(new CardsImpl(permanents), Zone.EXILED, source, game);
    for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
        Token token = new FractalToken();
        token.putOntoBattlefield(1, game, source, playerId);
        int counter = playerMap.getOrDefault(playerId, 0);
        for (UUID tokenId : token.getLastAddedTokenIds()) {
            Permanent permanent = game.getPermanent(tokenId);
            if (permanent != null) {
                permanent.addCounters(CounterType.P1P1.createInstance(counter), playerId, source, game);
            }
        }
    }
    return true;
}
Also used : StaticFilters(mage.filter.StaticFilters) Zone(mage.constants.Zone) Outcome(mage.constants.Outcome) OneShotEffect(mage.abilities.effects.OneShotEffect) UUID(java.util.UUID) CardsImpl(mage.cards.CardsImpl) FractalToken(mage.game.permanent.token.FractalToken) Controllable(mage.game.Controllable) Collectors(java.util.stream.Collectors) Player(mage.players.Player) CardSetInfo(mage.cards.CardSetInfo) Objects(java.util.Objects) Game(mage.game.Game) List(java.util.List) Token(mage.game.permanent.token.Token) CardImpl(mage.cards.CardImpl) Permanent(mage.game.permanent.Permanent) Map(java.util.Map) CardType(mage.constants.CardType) CounterType(mage.counters.CounterType) Ability(mage.abilities.Ability) FractalToken(mage.game.permanent.token.FractalToken) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) FractalToken(mage.game.permanent.token.FractalToken) Token(mage.game.permanent.token.Token) UUID(java.util.UUID) CardsImpl(mage.cards.CardsImpl)

Example 4 with Controllable

use of mage.game.Controllable in project mage by magefree.

the class SuddenSalvationEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    Cards cards = new CardsImpl(getTargetPointer().getTargets(game, source));
    if (player == null || cards.isEmpty()) {
        return false;
    }
    player.moveCards(cards.getCards(game), Zone.BATTLEFIELD, source, game, true, false, true, null);
    int opponents = cards.stream().map(game::getPermanent).filter(Objects::nonNull).map(Controllable::getControllerId).distinct().mapToInt(uuid -> player.hasOpponent(uuid, game) ? 1 : 0).sum();
    player.drawCards(opponents, source, game);
    return true;
}
Also used : FilterCard(mage.filter.FilterCard) FilterPermanentCard(mage.filter.common.FilterPermanentCard) Zone(mage.constants.Zone) Cards(mage.cards.Cards) Outcome(mage.constants.Outcome) OneShotEffect(mage.abilities.effects.OneShotEffect) TargetCardInGraveyard(mage.target.common.TargetCardInGraveyard) UUID(java.util.UUID) CardsImpl(mage.cards.CardsImpl) Controllable(mage.game.Controllable) Player(mage.players.Player) PutIntoGraveFromBattlefieldThisTurnPredicate(mage.filter.predicate.card.PutIntoGraveFromBattlefieldThisTurnPredicate) CardSetInfo(mage.cards.CardSetInfo) Objects(java.util.Objects) Game(mage.game.Game) CardImpl(mage.cards.CardImpl) CardType(mage.constants.CardType) CardsPutIntoGraveyardWatcher(mage.watchers.common.CardsPutIntoGraveyardWatcher) Ability(mage.abilities.Ability) Player(mage.players.Player) Objects(java.util.Objects) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl)

Example 5 with Controllable

use of mage.game.Controllable in project mage by magefree.

the class DamagedPlayerThisTurnPredicate method apply.

@Override
public boolean apply(ObjectSourcePlayer<Controllable> input, Game game) {
    Controllable object = input.getObject();
    UUID playerId = input.getPlayerId();
    switch(controller) {
        case YOU:
            PlayerDamagedBySourceWatcher watcher = game.getState().getWatcher(PlayerDamagedBySourceWatcher.class, playerId);
            if (watcher != null) {
                return watcher.hasSourceDoneDamage(object.getId(), game);
            }
            break;
        case OPPONENT:
            for (UUID opponentId : game.getOpponents(playerId)) {
                watcher = game.getState().getWatcher(PlayerDamagedBySourceWatcher.class, opponentId);
                if (watcher != null) {
                    return watcher.hasSourceDoneDamage(object.getId(), game);
                }
            }
            break;
        case NOT_YOU:
            for (UUID notYouId : game.getState().getPlayersInRange(playerId, game)) {
                if (!notYouId.equals(playerId)) {
                    watcher = game.getState().getWatcher(PlayerDamagedBySourceWatcher.class, notYouId);
                    if (watcher != null) {
                        return watcher.hasSourceDoneDamage(object.getId(), game);
                    }
                }
            }
            break;
        case ANY:
            for (UUID anyId : game.getState().getPlayersInRange(playerId, game)) {
                watcher = game.getState().getWatcher(PlayerDamagedBySourceWatcher.class, anyId);
                if (watcher != null) {
                    return watcher.hasSourceDoneDamage(object.getId(), game);
                }
            }
            return true;
    }
    return false;
}
Also used : Controllable(mage.game.Controllable) PlayerDamagedBySourceWatcher(mage.watchers.common.PlayerDamagedBySourceWatcher) UUID(java.util.UUID)

Aggregations

UUID (java.util.UUID)6 Controllable (mage.game.Controllable)6 Ability (mage.abilities.Ability)5 OneShotEffect (mage.abilities.effects.OneShotEffect)5 CardImpl (mage.cards.CardImpl)5 CardSetInfo (mage.cards.CardSetInfo)5 CardType (mage.constants.CardType)5 Outcome (mage.constants.Outcome)5 Game (mage.game.Game)5 Player (mage.players.Player)5 Map (java.util.Map)4 Objects (java.util.Objects)4 Collectors (java.util.stream.Collectors)4 CardsImpl (mage.cards.CardsImpl)4 Zone (mage.constants.Zone)4 Function (java.util.function.Function)3 StaticFilters (mage.filter.StaticFilters)3 List (java.util.List)2 Cards (mage.cards.Cards)2 Permanent (mage.game.permanent.Permanent)2