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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations