use of mage.game.Game in project mage by magefree.
the class LegionsEndEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent permanent = game.getPermanent(source.getFirstTarget());
if (permanent == null) {
return false;
}
Player player = game.getPlayer(permanent.getControllerId());
if (player == null) {
return false;
}
String name = permanent.getName();
if (name == null || name.equals("")) {
player.revealCards(source, player.getHand(), game);
return player.moveCards(permanent, Zone.EXILED, source, game);
}
Cards cards = new CardsImpl();
game.getBattlefield().getAllActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, player.getId(), game).stream().filter(perm -> name.equals(perm.getName())).forEach(cards::add);
player.revealCards(source, player.getHand(), game);
player.getHand().getCards(game).stream().filter(card -> name.equals(card.getName())).forEach(cards::add);
player.getGraveyard().getCards(game).stream().filter(card -> name.equals(card.getName())).forEach(cards::add);
return player.moveCards(cards, Zone.EXILED, source, game);
}
use of mage.game.Game in project mage by magefree.
the class NimbleTrapfinderWatcher method watch.
@Override
public void watch(GameEvent event, Game game) {
if (event.getType() != GameEvent.EventType.ENTERS_THE_BATTLEFIELD) {
return;
}
Permanent permanent = game.getPermanent(event.getTargetId());
if (!filter.match(permanent, game)) {
return;
}
playerMap.computeIfAbsent(event.getPlayerId(), u -> new HashSet<>()).add(new MageObjectReference(permanent, game));
}
use of mage.game.Game in project mage by magefree.
the class PortalOfSanctuaryEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent permanent = game.getPermanent(source.getFirstTarget());
Player player = game.getPlayer(source.getControllerId());
if (permanent == null || player == null) {
return false;
}
Cards cards = new CardsImpl(permanent);
permanent.getAttachments().stream().map(uuid -> game.getPermanent(uuid)).filter(perm -> perm != null && perm.hasSubtype(SubType.AURA, game)).forEach(perm -> cards.add(perm));
return player.moveCards(cards, Zone.HAND, source, game);
}
use of mage.game.Game in project mage by magefree.
the class WillScholarOfFrostEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
Cards cards = new CardsImpl(targetPointer.getTargets(game, source));
Map<UUID, Integer> playerMap = cards.getCards(game).stream().filter(Objects::nonNull).map(MageItem::getId).map(game::getControllerId).filter(Objects::nonNull).collect(Collectors.toMap(Function.identity(), x -> 1, Integer::sum));
player.moveCards(cards, Zone.EXILED, source, game);
for (Map.Entry<UUID, Integer> entry : playerMap.entrySet()) {
new Elemental44Token().putOntoBattlefield(entry.getValue(), game, source, entry.getKey());
}
return true;
}
use of mage.game.Game in project mage by magefree.
the class SphinxsTutelageEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player targetPlayer = game.getPlayer(this.getTargetPointer().getFirst(game, source));
if (targetPlayer != null) {
int possibleIterations = targetPlayer.getLibrary().size() / 2;
int iteration = 0;
boolean colorShared;
do {
iteration++;
if (iteration > possibleIterations + 20) {
// 801.16. If the game somehow enters a "loop" of mandatory actions, repeating a sequence of events
// with no way to stop, the game is a draw for each player who controls an object that's involved in
// that loop, as well as for each player within the range of influence of any of those players. They
// leave the game. All remaining players continue to play the game.
game.setDraw(source.getControllerId());
return true;
}
colorShared = false;
List<Card> cards = targetPlayer.millCards(2, source, game).getCards(game).stream().filter(card -> !card.isLand(game)).collect(Collectors.toList());
if (cards.size() < 2) {
break;
}
for (int i = 0; i < cards.size(); i++) {
if (colorShared) {
break;
}
ObjectColor color1 = cards.get(i).getColor(game);
if (color1.isColorless()) {
continue;
}
for (int j = 0; j < cards.size(); j++) {
if (i >= j) {
continue;
}
ObjectColor color2 = cards.get(j).getColor(game);
if (color1.shares(color2)) {
colorShared = true;
break;
}
}
}
} while (colorShared);
return true;
}
return false;
}
Aggregations