Search in sources :

Example 91 with Game

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

the class PlayerDiedStackTargetHandlingTest method createNewGameAndPlayers.

@Override
protected Game createNewGameAndPlayers() throws GameException, FileNotFoundException {
    // Start Life = 2
    Game game = new FreeForAll(MultiplayerAttackOption.MULTIPLE, RangeOfInfluence.ONE, MulliganType.GAME_DEFAULT.getMulligan(0), 3);
    // Player order: A -> D -> C -> B
    playerA = createPlayer(game, playerA, "PlayerA");
    playerB = createPlayer(game, playerB, "PlayerB");
    playerC = createPlayer(game, playerC, "PlayerC");
    playerD = createPlayer(game, playerD, "PlayerD");
    return game;
}
Also used : Game(mage.game.Game) FreeForAll(mage.game.FreeForAll)

Example 92 with Game

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

the class AegarTheFreezingFlameWatcher method watch.

@Override
public void watch(GameEvent event, Game game) {
    if (event.getType() != GameEvent.EventType.DAMAGED_PERMANENT) {
        return;
    }
    DamagedEvent dEvent = (DamagedEvent) event;
    MageObject sourceObject = game.getObject(event.getSourceId());
    if (sourceObject == null) {
        return;
    }
    if (game.getSpellOrLKIStack(event.getSourceId()) == null && !sourceObject.hasSubtype(SubType.GIANT, game) && !sourceObject.hasSubtype(SubType.WIZARD, game)) {
        return;
    }
    playerMap.computeIfAbsent(game.getControllerId(event.getSourceId()), x -> new HashSet<>()).add(new MageObjectReference(event.getTargetId(), game));
}
Also used : java.util(java.util) DrawCardSourceControllerEffect(mage.abilities.effects.common.DrawCardSourceControllerEffect) MageObjectReference(mage.MageObjectReference) MageInt(mage.MageInt) CardSetInfo(mage.cards.CardSetInfo) TriggeredAbilityImpl(mage.abilities.TriggeredAbilityImpl) Game(mage.game.Game) Watcher(mage.watchers.Watcher) GameEvent(mage.game.events.GameEvent) CardImpl(mage.cards.CardImpl) DamagedEvent(mage.game.events.DamagedEvent) MageObject(mage.MageObject) mage.constants(mage.constants) DamagedEvent(mage.game.events.DamagedEvent) MageObject(mage.MageObject) MageObjectReference(mage.MageObjectReference)

Example 93 with Game

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

the class GenesisUltimatumEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    Cards toHand = new CardsImpl(player.getLibrary().getTopCards(game, 5));
    player.lookAtCards(source, null, toHand, game);
    TargetCard targetCard = new TargetCardInLibrary(0, 5, filter);
    targetCard.withChooseHint("put to battlefield");
    player.choose(outcome, toHand, targetCard, game);
    Cards toBattlefield = new CardsImpl(targetCard.getTargets());
    if (player.moveCards(toBattlefield, Zone.BATTLEFIELD, source, game)) {
        toBattlefield.stream().filter(id -> Zone.BATTLEFIELD.equals(game.getState().getZone(id))).forEach(toHand::remove);
    }
    player.moveCards(toHand, Zone.HAND, source, game);
    return true;
}
Also used : FilterCard(mage.filter.FilterCard) FilterPermanentCard(mage.filter.common.FilterPermanentCard) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) Zone(mage.constants.Zone) Cards(mage.cards.Cards) Outcome(mage.constants.Outcome) OneShotEffect(mage.abilities.effects.OneShotEffect) UUID(java.util.UUID) CardsImpl(mage.cards.CardsImpl) Player(mage.players.Player) CardSetInfo(mage.cards.CardSetInfo) ExileSpellEffect(mage.abilities.effects.common.ExileSpellEffect) Game(mage.game.Game) CardImpl(mage.cards.CardImpl) TargetCard(mage.target.TargetCard) CardType(mage.constants.CardType) Ability(mage.abilities.Ability) Player(mage.players.Player) TargetCard(mage.target.TargetCard) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl) TargetCardInLibrary(mage.target.common.TargetCardInLibrary)

Example 94 with Game

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

the class GeodeGolemEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Card selectedCommander = null;
        Set<Card> commandersInCommandZone = game.getCommanderCardsFromCommandZone(controller, CommanderCardType.COMMANDER_OR_OATHBREAKER);
        if (commandersInCommandZone.isEmpty()) {
            return false;
        }
        // select from commanders
        if (commandersInCommandZone.size() == 1) {
            selectedCommander = commandersInCommandZone.stream().findFirst().get();
        } else {
            TargetCard target = new TargetCard(Zone.COMMAND, new FilterCard("commander to cast without mana cost"));
            target.setNotTarget(true);
            if (controller.canRespond() && controller.choose(Outcome.PlayForFree, new CardsImpl(commandersInCommandZone), target, game)) {
                selectedCommander = commandersInCommandZone.stream().filter(c -> c.getId().equals(target.getFirstTarget())).findFirst().orElse(null);
            }
        }
        if (selectedCommander == null) {
            return false;
        }
        // commander tax applies as additional cost
        if (selectedCommander.getSpellAbility() != null) {
            game.getState().setValue("PlayFromNotOwnHandZone" + selectedCommander.getId(), Boolean.TRUE);
            Boolean commanderWasCast = controller.cast(controller.chooseAbilityForCast(selectedCommander, game, true), game, true, new ApprovingObject(source, game));
            game.getState().setValue("PlayFromNotOwnHandZone" + selectedCommander.getId(), null);
            return commanderWasCast;
        } else {
            // TODO: improve lands support for "cast your commander" (allow land play from mdf cards)?
            return controller.playLand(selectedCommander, game, true);
        }
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) FilterCard(mage.filter.FilterCard) ApprovingObject(mage.ApprovingObject) DealsCombatDamageToAPlayerTriggeredAbility(mage.abilities.common.DealsCombatDamageToAPlayerTriggeredAbility) Set(java.util.Set) OneShotEffect(mage.abilities.effects.OneShotEffect) UUID(java.util.UUID) MageInt(mage.MageInt) CardsImpl(mage.cards.CardsImpl) Player(mage.players.Player) CardSetInfo(mage.cards.CardSetInfo) Game(mage.game.Game) CardImpl(mage.cards.CardImpl) TargetCard(mage.target.TargetCard) TrampleAbility(mage.abilities.keyword.TrampleAbility) Card(mage.cards.Card) mage.constants(mage.constants) Ability(mage.abilities.Ability) Player(mage.players.Player) ApprovingObject(mage.ApprovingObject) TargetCard(mage.target.TargetCard) CardsImpl(mage.cards.CardsImpl) FilterCard(mage.filter.FilterCard) TargetCard(mage.target.TargetCard) Card(mage.cards.Card)

Example 95 with Game

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

the class LegionWarbossAbility method apply.

@Override
public boolean apply(Game game, Ability source) {
    CreateTokenEffect effect = new CreateTokenEffect(new GoblinToken());
    effect.apply(game, source);
    effect.getLastAddedTokenIds().stream().map((tokenId) -> {
        ContinuousEffect continuousEffect = new GainAbilityTargetEffect(HasteAbility.getInstance(), Duration.EndOfTurn);
        continuousEffect.setTargetPointer(new FixedTarget(tokenId, game));
        return continuousEffect;
    }).forEachOrdered((continuousEffect) -> {
        game.addEffect(continuousEffect, source);
    });
    effect.getLastAddedTokenIds().stream().map((tokenId) -> {
        ContinuousEffect continuousEffect = new GainAbilityTargetEffect(new LegionWarbossAbility(), Duration.EndOfCombat);
        continuousEffect.setTargetPointer(new FixedTarget(tokenId, game));
        return continuousEffect;
    }).forEachOrdered((continuousEffect) -> {
        game.addEffect(continuousEffect, source);
    });
    return true;
}
Also used : BeginningOfCombatTriggeredAbility(mage.abilities.common.BeginningOfCombatTriggeredAbility) Zone(mage.constants.Zone) MentorAbility(mage.abilities.keyword.MentorAbility) HasteAbility(mage.abilities.keyword.HasteAbility) Outcome(mage.constants.Outcome) OneShotEffect(mage.abilities.effects.OneShotEffect) UUID(java.util.UUID) GoblinToken(mage.game.permanent.token.GoblinToken) MageInt(mage.MageInt) StaticAbility(mage.abilities.StaticAbility) SubType(mage.constants.SubType) TargetController(mage.constants.TargetController) ContinuousEffect(mage.abilities.effects.ContinuousEffect) FixedTarget(mage.target.targetpointer.FixedTarget) CardSetInfo(mage.cards.CardSetInfo) Duration(mage.constants.Duration) Game(mage.game.Game) CreateTokenEffect(mage.abilities.effects.common.CreateTokenEffect) CardImpl(mage.cards.CardImpl) CardType(mage.constants.CardType) Ability(mage.abilities.Ability) AttacksIfAbleSourceEffect(mage.abilities.effects.common.combat.AttacksIfAbleSourceEffect) GainAbilityTargetEffect(mage.abilities.effects.common.continuous.GainAbilityTargetEffect) FixedTarget(mage.target.targetpointer.FixedTarget) CreateTokenEffect(mage.abilities.effects.common.CreateTokenEffect) GainAbilityTargetEffect(mage.abilities.effects.common.continuous.GainAbilityTargetEffect) ContinuousEffect(mage.abilities.effects.ContinuousEffect) GoblinToken(mage.game.permanent.token.GoblinToken)

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