Search in sources :

Example 76 with Game

use of mage.game.Game in project mage by magefree.

the class OccultEpiphanyEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    int xValue = source.getManaCostsToPay().getX();
    if (player == null || xValue < 1) {
        return false;
    }
    player.drawCards(xValue, source, game);
    int cardTypes = player.discard(xValue, false, false, source, game).getCards(game).stream().map(card -> card.getCardType(game)).flatMap(Collection::stream).distinct().mapToInt(x -> 1).sum();
    if (cardTypes > 0) {
        new SpiritWhiteToken().putOntoBattlefield(cardTypes, game, source);
    }
    return true;
}
Also used : CardSetInfo(mage.cards.CardSetInfo) Game(mage.game.Game) SpiritWhiteToken(mage.game.permanent.token.SpiritWhiteToken) CardImpl(mage.cards.CardImpl) Collection(java.util.Collection) CardType(mage.constants.CardType) Outcome(mage.constants.Outcome) OneShotEffect(mage.abilities.effects.OneShotEffect) UUID(java.util.UUID) Player(mage.players.Player) Ability(mage.abilities.Ability) Player(mage.players.Player) SpiritWhiteToken(mage.game.permanent.token.SpiritWhiteToken)

Example 77 with Game

use of mage.game.Game in project mage by magefree.

the class TheUpsideDownLeavesAbility method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    ZoneChangeEvent zEvent = (ZoneChangeEvent) event;
    Set<MageObjectReference> morSet = (Set<MageObjectReference>) game.getState().getValue(TheUpsideDown.makeKey(this, game));
    return morSet != null && !morSet.isEmpty() && morSet.stream().anyMatch(mor -> mor.refersTo(zEvent.getTarget(), game));
}
Also used : BlackManaAbility(mage.abilities.mana.BlackManaAbility) StaticFilters(mage.filter.StaticFilters) TargetCardInYourGraveyard(mage.target.common.TargetCardInYourGraveyard) Zone(mage.constants.Zone) PayLifeCost(mage.abilities.costs.common.PayLifeCost) Outcome(mage.constants.Outcome) Set(java.util.Set) MageObjectReference(mage.MageObjectReference) OneShotEffect(mage.abilities.effects.OneShotEffect) UUID(java.util.UUID) TransformSourceEffect(mage.abilities.effects.common.TransformSourceEffect) Player(mage.players.Player) CardSetInfo(mage.cards.CardSetInfo) HashSet(java.util.HashSet) TriggeredAbilityImpl(mage.abilities.TriggeredAbilityImpl) Game(mage.game.Game) GameEvent(mage.game.events.GameEvent) ZoneChangeEvent(mage.game.events.ZoneChangeEvent) CardImpl(mage.cards.CardImpl) Permanent(mage.game.permanent.Permanent) CardType(mage.constants.CardType) Card(mage.cards.Card) SuperType(mage.constants.SuperType) Ability(mage.abilities.Ability) ZoneChangeEvent(mage.game.events.ZoneChangeEvent) Set(java.util.Set) HashSet(java.util.HashSet) MageObjectReference(mage.MageObjectReference)

Example 78 with Game

use of mage.game.Game in project mage by magefree.

the class TheOzolithMoveCountersEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent permanent = game.getPermanent(source.getSourceId());
    Permanent creature = game.getPermanent(source.getFirstTarget());
    if (permanent == null || creature == null) {
        return false;
    }
    permanent.getCounters(game).copy().values().stream().filter(counter -> creature.addCounters(counter, source.getControllerId(), source, game)).forEach(counter -> permanent.removeCounters(counter, source, game));
    return true;
}
Also used : BeginningOfCombatTriggeredAbility(mage.abilities.common.BeginningOfCombatTriggeredAbility) StaticFilters(mage.filter.StaticFilters) Condition(mage.abilities.condition.Condition) Counters(mage.counters.Counters) Outcome(mage.constants.Outcome) OneShotEffect(mage.abilities.effects.OneShotEffect) LeavesBattlefieldAllTriggeredAbility(mage.abilities.common.LeavesBattlefieldAllTriggeredAbility) UUID(java.util.UUID) TargetController(mage.constants.TargetController) CardSetInfo(mage.cards.CardSetInfo) Game(mage.game.Game) GameEvent(mage.game.events.GameEvent) ZoneChangeEvent(mage.game.events.ZoneChangeEvent) CardImpl(mage.cards.CardImpl) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) ConditionalInterveningIfTriggeredAbility(mage.abilities.decorator.ConditionalInterveningIfTriggeredAbility) CardType(mage.constants.CardType) Counter(mage.counters.Counter) SuperType(mage.constants.SuperType) Ability(mage.abilities.Ability) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent)

Example 79 with Game

use of mage.game.Game in project mage by magefree.

the class UnderworldBreachEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    controller.getGraveyard().getCards(game).stream().filter(Objects::nonNull).filter(// card must have a mana cost
    card -> !card.getManaCost().getText().isEmpty()).filter(card -> !card.isLand(game)).forEach(card -> {
        Ability ability = new EscapeAbility(card, card.getManaCost().getText(), 3);
        ability.setSourceId(card.getId());
        ability.setControllerId(card.getOwnerId());
        game.getState().addOtherAbility(card, ability);
    });
    return true;
}
Also used : SimpleStaticAbility(mage.abilities.common.SimpleStaticAbility) UUID(java.util.UUID) BeginningOfEndStepTriggeredAbility(mage.abilities.common.BeginningOfEndStepTriggeredAbility) Player(mage.players.Player) CardSetInfo(mage.cards.CardSetInfo) Objects(java.util.Objects) ContinuousEffectImpl(mage.abilities.effects.ContinuousEffectImpl) Game(mage.game.Game) EscapeAbility(mage.abilities.keyword.EscapeAbility) CardImpl(mage.cards.CardImpl) SacrificeSourceEffect(mage.abilities.effects.common.SacrificeSourceEffect) mage.constants(mage.constants) Ability(mage.abilities.Ability) SimpleStaticAbility(mage.abilities.common.SimpleStaticAbility) BeginningOfEndStepTriggeredAbility(mage.abilities.common.BeginningOfEndStepTriggeredAbility) EscapeAbility(mage.abilities.keyword.EscapeAbility) Ability(mage.abilities.Ability) Player(mage.players.Player) EscapeAbility(mage.abilities.keyword.EscapeAbility)

Example 80 with Game

use of mage.game.Game in project mage by magefree.

the class PlayGameTest method playOneGame.

@Ignore
@Test
public void playOneGame() throws GameException, FileNotFoundException, IllegalArgumentException {
    Game game = new TwoPlayerDuel(MultiplayerAttackOption.LEFT, RangeOfInfluence.ALL, MulliganType.GAME_DEFAULT.getMulligan(0), 20);
    Player computerA = createPlayer("ComputerA", PlayerType.COMPUTER_MINIMAX_HYBRID);
    // Player playerA = createPlayer("ComputerA", "Computer - mad");
    // Deck deck = Deck.load(Sets.loadDeck("RB Aggro.dck"));
    Deck deck = generateRandomDeck();
    if (deck.getCards().size() < DECK_SIZE) {
        throw new IllegalArgumentException("Couldn't load deck, deck size = " + deck.getCards().size() + ", but must be " + DECK_SIZE);
    }
    game.addPlayer(computerA, deck);
    game.loadCards(deck.getCards(), computerA.getId());
    Player computerB = createPlayer("ComputerB", PlayerType.COMPUTER_MINIMAX_HYBRID);
    // Player playerB = createPlayer("ComputerB", "Computer - mad");
    // Deck deck2 = Deck.load(Sets.loadDeck("RB Aggro.dck"));
    Deck deck2 = generateRandomDeck();
    if (deck2.getCards().size() < DECK_SIZE) {
        throw new IllegalArgumentException("Couldn't load deck, deck size = " + deck2.getCards().size() + ", but must be " + DECK_SIZE);
    }
    game.addPlayer(computerB, deck2);
    game.loadCards(deck2.getCards(), computerB.getId());
    // parseScenario("scenario1.txt");
    // game.cheat(playerA.getId(), commandsA);
    // game.cheat(playerA.getId(), libraryCardsA, handCardsA, battlefieldCardsA, graveyardCardsA);
    // game.cheat(playerB.getId(), commandsB);
    // game.cheat(playerB.getId(), libraryCardsB, handCardsB, battlefieldCardsB, graveyardCardsB);
    // boolean testMode = false;
    boolean testMode = true;
    long t1 = System.nanoTime();
    GameOptions options = new GameOptions();
    options.testMode = true;
    game.setGameOptions(options);
    game.start(computerA.getId());
    long t2 = System.nanoTime();
    logger.info("Winner: " + game.getWinner());
    logger.info("Time: " + (t2 - t1) / 1000000 + " ms");
/*if (!game.getWinner().equals("Player ComputerA is the winner")) {
            throw new RuntimeException("Lost :(");
        }*/
}
Also used : Player(mage.players.Player) ComputerPlayer(mage.player.ai.ComputerPlayer) Game(mage.game.Game) GameOptions(mage.game.GameOptions) TwoPlayerDuel(mage.game.TwoPlayerDuel) Deck(mage.cards.decks.Deck) Ignore(org.junit.Ignore) Test(org.junit.Test)

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