use of mage.game.Game in project mage by magefree.
the class MindlinkMechApplier method watch.
@Override
public void watch(GameEvent event, Game game) {
Permanent vehicle;
Permanent crewer;
switch(event.getType()) {
case VEHICLE_CREWED:
vehicle = game.getPermanent(event.getTargetId());
crewer = null;
break;
case CREWED_VEHICLE:
vehicle = game.getPermanent(event.getSourceId());
crewer = game.getPermanent(event.getTargetId());
break;
default:
return;
}
if (vehicle == null) {
return;
}
if (crewer == null) {
crewCount.compute(new MageObjectReference(vehicle, game), (m, i) -> i == null ? 1 : Integer.sum(i, 1));
return;
}
crewMap.computeIfAbsent(new MageObjectReference(vehicle, game), x -> new HashSet<>()).add(new MageObjectReference(crewer, game));
}
use of mage.game.Game in project mage by magefree.
the class MindreaverExileEffect method canTarget.
@Override
public boolean canTarget(UUID id, Ability source, Game game) {
Spell spell = game.getSpell(id);
ExileZone exileZone = game.getExile().getExileZone(CardUtil.getExileZoneId(game, source));
return super.canTarget(id, source, game) && spell != null && exileZone != null && !exileZone.isEmpty() && exileZone.getCards(game).stream().filter(Objects::nonNull).anyMatch(card -> CardUtil.haveSameNames(spell, card));
}
use of mage.game.Game in project mage by magefree.
the class MindleecherLookEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
Cards cards = new CardsImpl();
game.getOpponents(controller.getId()).stream().map(game::getPlayer).map(Player::getLibrary).map(library -> library.getFromTop(game)).forEach(cards::add);
if (cards.isEmpty()) {
return false;
}
controller.moveCards(cards, Zone.EXILED, source, game);
cards.removeIf(uuid -> game.getState().getZone(uuid) != Zone.EXILED);
if (cards.isEmpty()) {
return false;
}
cards.getCards(game).stream().forEach(card -> card.setFaceDown(true, game));
for (Card card : cards.getCards(game)) {
game.addEffect(new MindleecherCastFromExileEffect(controller.getId()).setTargetPointer(new FixedTarget(card, game)), source);
game.addEffect(new MindleecherLookEffect(controller.getId()).setTargetPointer(new FixedTarget(card, game)), source);
}
return true;
}
use of mage.game.Game in project mage by magefree.
the class PakoArcaneRetrieverWatcher method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
PakoArcaneRetrieverWatcher watcher = game.getState().getWatcher(PakoArcaneRetrieverWatcher.class);
if (controller == null || watcher == null) {
return false;
}
Cards cards = new CardsImpl();
game.getState().getPlayersInRange(controller.getId(), game).stream().map(game::getPlayer).map(Player::getLibrary).map(library -> library.getFromTop(game)).forEach(cards::add);
controller.moveCards(cards, Zone.EXILED, source, game);
cards.removeIf(cardId -> game.getState().getZone(cardId) != Zone.EXILED);
int counters = cards.count(StaticFilters.FILTER_CARD_NON_CREATURE, game);
if (cards.isEmpty()) {
return true;
}
cards.getCards(game).stream().filter(card -> card.addCounters(CounterType.FETCH.createInstance(), source.getControllerId(), source, game)).filter(card -> !card.isCreature(game)).forEach(card -> watcher.addCard(controller.getId(), card, game));
Permanent permanent = game.getPermanent(source.getSourceId());
if (permanent == null || counters == 0) {
return true;
}
return permanent.addCounters(CounterType.P1P1.createInstance(counters), source.getControllerId(), source, game);
}
use of mage.game.Game in project mage by magefree.
the class SerpentsSoulJarWatcher method addPlayable.
static void addPlayable(Ability source, Game game) {
MageObjectReference mor = new MageObjectReference(source);
game.getState().getWatcher(SerpentsSoulJarWatcher.class).morMap.computeIfAbsent(mor, m -> new HashMap<>()).compute(source.getControllerId(), CardUtil::setOrIncrementValue);
}
Aggregations