use of mage.game.Game in project mage by magefree.
the class GameReplay method loadGame.
private Game loadGame(UUID gameId) {
InputStream file = null;
InputStream buffer = null;
InputStream gzip = null;
ObjectInput input = null;
try {
file = new FileInputStream("saved/" + gameId.toString() + ".game");
buffer = new BufferedInputStream(file);
gzip = new GZIPInputStream(buffer);
input = new CopierObjectInputStream(Main.classLoader, gzip);
Game loadGame = (Game) input.readObject();
GameStates states = (GameStates) input.readObject();
loadGame.loadGameStates(states);
return loadGame;
} catch (ClassNotFoundException ex) {
logger.fatal("Cannot load game. Class not found.", ex);
} catch (IOException ex) {
logger.fatal("Cannot load game:" + gameId, ex);
} finally {
StreamUtils.closeQuietly(file);
StreamUtils.closeQuietly(buffer);
StreamUtils.closeQuietly(input);
StreamUtils.closeQuietly(gzip);
}
return null;
}
use of mage.game.Game in project mage by magefree.
the class BruenorBattlehammerWatcher method apply.
@Override
public boolean apply(Game game, Ability source) {
for (Permanent permanent : game.getBattlefield().getActivePermanents(StaticFilters.FILTER_CONTROLLED_CREATURE, source.getControllerId(), source.getSourceId(), game)) {
int equipped = permanent.getAttachments().stream().map(game::getPermanent).mapToInt(p -> p.hasSubtype(SubType.EQUIPMENT, game) ? 1 : 0).sum();
permanent.addPower(2 * equipped);
}
return true;
}
use of mage.game.Game in project mage by magefree.
the class BucknardsEverfullPurseEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
new TreasureToken().putOntoBattlefield(player.rollDice(outcome, source, game, 4), game, source, source.getControllerId());
Permanent permanent = source.getSourcePermanentIfItStillExists(game);
if (permanent == null) {
return true;
}
UUID playerToRightId = game.getState().getPlayersInRange(source.getControllerId(), game).stream().reduce((u1, u2) -> u2).orElse(null);
if (playerToRightId == null) {
return false;
}
game.addEffect(new GainControlTargetEffect(Duration.Custom, true, playerToRightId).setTargetPointer(new FixedTarget(permanent, game)), source);
return true;
}
use of mage.game.Game in project mage by magefree.
the class CryptIncursionEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
Player targetPlayer = game.getPlayer(source.getFirstTarget());
Cards cards = new CardsImpl(targetPlayer.getGraveyard().getCards(StaticFilters.FILTER_CARD_CREATURE, game));
player.moveCards(cards, Zone.EXILED, source, game);
int count = cards.stream().map(game.getState()::getZone).map(Zone.EXILED::equals).mapToInt(x -> x ? 1 : 0).sum();
player.gainLife(3 * count, game, source);
return true;
}
use of mage.game.Game in project mage by magefree.
the class CryptoplasmEffect method apply.
@Override
public boolean apply(Game game, final Ability source) {
Permanent creatureToCopy = game.getPermanent(getTargetPointer().getFirst(game, source));
if (creatureToCopy != null) {
CopyApplier applier = new CopyApplier() {
@Override
public boolean apply(Game game, MageObject blueprint, Ability source, UUID copyToObjectId) {
Ability upkeepAbility = new BeginningOfUpkeepTriggeredAbility(new CryptoplasmEffect(), TargetController.YOU, true);
upkeepAbility.addTarget(new TargetCreaturePermanent());
blueprint.getAbilities().add(upkeepAbility);
return true;
}
};
game.copyPermanent(creatureToCopy, source.getSourceId(), source, applier);
}
return true;
}
Aggregations