use of mage.game.stack.Spell in project mage by magefree.
the class GripOfAmnesiaEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Spell spell = game.getStack().getSpell(source.getFirstTarget());
if (spell != null) {
Player controller = game.getPlayer(spell.getControllerId());
if (controller != null && controller.chooseUse(Outcome.Benefit, "Exile all cards from your graveyard? (Otherwise " + spell.getLogName() + " will be countered)", source, game)) {
controller.moveCards(controller.getGraveyard(), Zone.EXILED, source, game);
game.informPlayers(controller.getLogName() + " exiles all cards from their graveyard to prevent counter effect");
} else {
game.getStack().counter(spell.getId(), source, game);
}
return true;
}
return false;
}
use of mage.game.stack.Spell in project mage by magefree.
the class IceCaveEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Permanent sourcePermanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
Spell spell = (Spell) game.getStack().getStackObject(targetPointer.getFirst(game, source));
if (sourcePermanent != null && spell != null && controller != null) {
Player spellController = game.getPlayer(spell.getControllerId());
Cost cost = new ManaCostsImpl(spell.getSpellAbility().getManaCosts().getText());
if (spellController != null) {
for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
Player player = game.getPlayer(playerId);
if (player != null && !player.equals(spellController)) {
cost.clearPaid();
if (cost.canPay(source, source, player.getId(), game) && player.chooseUse(outcome, "Pay " + cost.getText() + " to counter " + spell.getIdName() + '?', source, game)) {
if (cost.pay(source, game, source, playerId, false, null)) {
game.informPlayers(player.getLogName() + " pays" + cost.getText() + " to counter " + spell.getIdName() + '.');
game.getStack().counter(spell.getId(), source, game);
break;
}
}
}
}
}
}
return true;
}
use of mage.game.stack.Spell in project mage by magefree.
the class IgniteTheFutureEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Spell spell = (Spell) game.getStack().getStackObject(source.getSourceId());
if (controller == null || spell == null) {
return false;
}
Set<Card> cards = controller.getLibrary().getTopCards(game, 3);
return PlayFromNotOwnHandZoneTargetEffect.exileAndPlayFromExile(game, source, cards, TargetController.YOU, Duration.UntilEndOfYourNextTurn, Zone.GRAVEYARD.equals(spell.getFromZone()), false, false);
}
use of mage.game.stack.Spell in project mage by magefree.
the class MagesContestEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Spell spell = game.getStack().getSpell(this.getTargetPointer().getFirst(game, source));
if (spell != null) {
Player you = game.getPlayer(source.getControllerId());
Player spellController = game.getPlayer(spell.getControllerId());
if (you != null && spellController != null) {
int highBid = 1;
game.informPlayers(you.getLogName() + " has bet " + highBid + " life");
Player winner = you;
Player currentPlayer = spellController;
do {
if (currentPlayer.canRespond()) {
int newBid = 0;
if (currentPlayer.isComputer()) {
// AI hint
// make AI evaluate value of the spell to decide on bidding, should be reworked
int maxBid = Math.min(RandomUtil.nextInt(Math.max(currentPlayer.getLife(), 1)) + RandomUtil.nextInt(Math.max(spell.getManaValue(), 1)), currentPlayer.getLife());
if (highBid + 1 < maxBid) {
newBid = highBid + 1;
}
} else if (currentPlayer.chooseUse(Outcome.Benefit, winner.getLogName() + " has bet " + highBid + " life. Top the bid?", source, game)) {
// Human choose
newBid = currentPlayer.getAmount(highBid + 1, Integer.MAX_VALUE, "Choose bid", game);
}
if (newBid > highBid) {
highBid = newBid;
winner = currentPlayer;
game.informPlayers(currentPlayer.getLogName() + " has bet " + newBid + " life");
currentPlayer = (winner == you ? spellController : you);
} else {
break;
}
}
} while (!Objects.equals(currentPlayer, winner));
game.informPlayers(winner.getLogName() + " has won the contest with a high bid of " + highBid + " life");
winner.loseLife(highBid, game, source, false);
if (winner == you) {
game.getStack().counter(spell.getId(), source, game);
}
return true;
}
}
return false;
}
use of mage.game.stack.Spell in project mage by magefree.
the class MageHunterTriggeredAbility method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
Spell spell = game.getSpell(event.getTargetId());
if (spell == null || !game.getOpponents(getControllerId()).contains(spell.getControllerId()) || !spell.isInstantOrSorcery(game)) {
return false;
}
getEffects().setTargetPointer(new FixedTarget(spell.getControllerId()));
return true;
}
Aggregations