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;
}
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));
}
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;
}
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;
}
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;
}
Aggregations