Search in sources :

Example 41 with Game

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;
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) GameStates(mage.game.GameStates) Game(mage.game.Game) BufferedInputStream(java.io.BufferedInputStream) GZIPInputStream(java.util.zip.GZIPInputStream) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) CopierObjectInputStream(mage.util.CopierObjectInputStream) InputStream(java.io.InputStream) ObjectInput(java.io.ObjectInput) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) CopierObjectInputStream(mage.util.CopierObjectInputStream)

Example 42 with Game

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;
}
Also used : SimpleStaticAbility(mage.abilities.common.SimpleStaticAbility) StaticFilters(mage.filter.StaticFilters) EquipAbility(mage.abilities.keyword.EquipAbility) Set(java.util.Set) UUID(java.util.UUID) MageInt(mage.MageInt) Player(mage.players.Player) CardSetInfo(mage.cards.CardSetInfo) HashSet(java.util.HashSet) ContinuousEffectImpl(mage.abilities.effects.ContinuousEffectImpl) Game(mage.game.Game) Watcher(mage.watchers.Watcher) GameEvent(mage.game.events.GameEvent) CardImpl(mage.cards.CardImpl) Permanent(mage.game.permanent.Permanent) StackObject(mage.game.stack.StackObject) mage.constants(mage.constants) CostModificationEffectImpl(mage.abilities.effects.common.cost.CostModificationEffectImpl) Ability(mage.abilities.Ability) Permanent(mage.game.permanent.Permanent)

Example 43 with Game

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;
}
Also used : SimpleActivatedAbility(mage.abilities.common.SimpleActivatedAbility) GainControlTargetEffect(mage.abilities.effects.common.continuous.GainControlTargetEffect) Outcome(mage.constants.Outcome) OneShotEffect(mage.abilities.effects.OneShotEffect) UUID(java.util.UUID) Player(mage.players.Player) FixedTarget(mage.target.targetpointer.FixedTarget) CardSetInfo(mage.cards.CardSetInfo) Duration(mage.constants.Duration) Game(mage.game.Game) TapSourceCost(mage.abilities.costs.common.TapSourceCost) GenericManaCost(mage.abilities.costs.mana.GenericManaCost) CardImpl(mage.cards.CardImpl) Permanent(mage.game.permanent.Permanent) CardType(mage.constants.CardType) TreasureToken(mage.game.permanent.token.TreasureToken) Ability(mage.abilities.Ability) FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TreasureToken(mage.game.permanent.token.TreasureToken) UUID(java.util.UUID) GainControlTargetEffect(mage.abilities.effects.common.continuous.GainControlTargetEffect)

Example 44 with Game

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;
}
Also used : StaticFilters(mage.filter.StaticFilters) Zone(mage.constants.Zone) Cards(mage.cards.Cards) Outcome(mage.constants.Outcome) OneShotEffect(mage.abilities.effects.OneShotEffect) TargetPlayer(mage.target.TargetPlayer) UUID(java.util.UUID) CardsImpl(mage.cards.CardsImpl) Player(mage.players.Player) CardSetInfo(mage.cards.CardSetInfo) Game(mage.game.Game) CardImpl(mage.cards.CardImpl) CardType(mage.constants.CardType) Ability(mage.abilities.Ability) TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl)

Example 45 with Game

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;
}
Also used : BeginningOfUpkeepTriggeredAbility(mage.abilities.common.BeginningOfUpkeepTriggeredAbility) Ability(mage.abilities.Ability) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) Game(mage.game.Game) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) CopyApplier(mage.util.functions.CopyApplier) MageObject(mage.MageObject) BeginningOfUpkeepTriggeredAbility(mage.abilities.common.BeginningOfUpkeepTriggeredAbility) UUID(java.util.UUID)

Aggregations

Game (mage.game.Game)212 Ability (mage.abilities.Ability)139 Player (mage.players.Player)126 UUID (java.util.UUID)117 OneShotEffect (mage.abilities.effects.OneShotEffect)104 CardSetInfo (mage.cards.CardSetInfo)102 CardImpl (mage.cards.CardImpl)100 CardType (mage.constants.CardType)82 Outcome (mage.constants.Outcome)78 Permanent (mage.game.permanent.Permanent)66 MageInt (mage.MageInt)60 mage.constants (mage.constants)47 Zone (mage.constants.Zone)46 GameEvent (mage.game.events.GameEvent)44 Objects (java.util.Objects)41 StaticFilters (mage.filter.StaticFilters)40 Collectors (java.util.stream.Collectors)35 SubType (mage.constants.SubType)34 Card (mage.cards.Card)32 MageObjectReference (mage.MageObjectReference)30