use of mage.constants.Outcome in project mage by magefree.
the class NeverwinterHydraEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent permanent = game.getPermanentEntering(source.getSourceId());
Player player = game.getPlayer(source.getControllerId());
if (permanent == null || player == null) {
return true;
}
SpellAbility spellAbility = (SpellAbility) getValue(EntersBattlefieldEffect.SOURCE_CAST_SPELL_ABILITY);
if (spellAbility == null || !spellAbility.getSourceId().equals(source.getSourceId()) || permanent.getZoneChangeCounter(game) != spellAbility.getSourceObjectZoneChangeCounter()) {
return true;
}
if (!spellAbility.getSourceId().equals(source.getSourceId())) {
return true;
}
// put into play by normal cast
int xValue = spellAbility.getManaCostsToPay().getX();
if (xValue < 1) {
return false;
}
int amount = player.rollDice(outcome, source, game, 6, xValue, 0).stream().mapToInt(x -> x).sum();
List<UUID> appliedEffects = (ArrayList<UUID>) this.getValue("appliedEffects");
permanent.addCounters(CounterType.P1P1.createInstance(amount), source.getControllerId(), source, game, appliedEffects);
return true;
}
use of mage.constants.Outcome in project mage by magefree.
the class PainsRewardEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
PlayerList playerList = game.getPlayerList().copy();
playerList.setCurrent(controller.getId());
Player winner = game.getPlayer(controller.getId());
// -1 for start with 0 min big
int highBid = chooseLifeAmountToBid(controller, -1, game);
game.informPlayers(winner.getLogName() + " has bet " + highBid + " lifes");
Player currentPlayer = playerList.getNextInRange(controller, game);
while (currentPlayer != null && !Objects.equals(currentPlayer, winner)) {
String text = winner.getLogName() + " has bet " + highBid + " life" + (highBid > 1 ? "s" : "") + ". Top the bid?";
// AI hint
int safeLifeToLost = Math.min(6, currentPlayer.getLife() / 2);
Outcome aiOutcome = (highBid + 1 <= safeLifeToLost) ? Outcome.Benefit : Outcome.Detriment;
if (currentPlayer.chooseUse(aiOutcome, text, source, game)) {
int newBid = chooseLifeAmountToBid(currentPlayer, highBid, game);
if (newBid > highBid) {
highBid = newBid;
winner = currentPlayer;
game.informPlayers(currentPlayer.getLogName() + " bet " + newBid + " life" + (newBid > 1 ? "s" : ""));
}
}
currentPlayer = playerList.getNextInRange(controller, game);
}
game.informPlayers(winner.getLogName() + " won the auction with a bid of " + highBid + " life" + (highBid > 1 ? "s" : ""));
winner.loseLife(highBid, game, source, false);
winner.drawCards(4, source, game);
return true;
}
return false;
}
use of mage.constants.Outcome in project mage by magefree.
the class ReignOfTerrorEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
FilterPermanent filter = player.chooseUse(outcome, "Destroy all green creatures or all white creatures?", "", "Green", "White", source, game) ? greenFilter : whiteFilter;
int died = game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game).stream().mapToInt(permanent -> permanent.destroy(source, game, true) ? 1 : 0).sum();
return player.loseLife(2 * died, game, source, false) > 0;
}
use of mage.constants.Outcome in project mage by magefree.
the class RevivalExperimentTarget method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
RevivalExperimentTarget target = new RevivalExperimentTarget();
player.choose(outcome, target, source.getSourceId(), game);
Cards cards = new CardsImpl(target.getTargets());
player.moveCards(cards, Zone.BATTLEFIELD, source, game);
int toBattlefield = cards.stream().map(game.getState()::getZone).filter(Zone.EXILED::equals).mapToInt(x -> 1).sum();
player.loseLife(3 * toBattlefield, game, source, false);
return true;
}
use of mage.constants.Outcome in project mage by magefree.
the class DanseMacabreEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
int toughness = 0;
Cards cards = new CardsImpl();
for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
Player player = game.getPlayer(playerId);
if (player == null || game.getBattlefield().count(filter, source.getSourceId(), source.getControllerId(), game) < 1) {
continue;
}
TargetPermanent target = new TargetPermanent(filter);
target.setNotTarget(true);
player.choose(Outcome.Sacrifice, target, source.getSourceId(), game);
Permanent permanent = game.getPermanent(target.getFirstTarget());
if (permanent == null) {
continue;
}
if (source.isControlledBy(playerId)) {
toughness += permanent.getToughness().getValue();
}
cards.add(permanent);
permanent.sacrifice(source, game);
}
int result = controller.rollDice(outcome, source, game, 20) + toughness;
cards.retainZone(Zone.GRAVEYARD, game);
if (cards.isEmpty()) {
return true;
}
FilterCard filterCard = new FilterCard("card put into a graveyard this way");
filterCard.add(Predicates.or(cards.stream().map(cardId -> new CardIdPredicate(cardId)).collect(Collectors.toSet())));
TargetCardInGraveyard target;
if (result >= 15) {
target = new TargetCardInGraveyard(0, 2, filterCard);
} else if (result > 0) {
target = new TargetCardInGraveyard(filterCard);
} else {
return true;
}
target.setNotTarget(true);
controller.choose(Outcome.PutCreatureInPlay, target, source.getSourceId(), game);
controller.moveCards(new CardsImpl(target.getTargets()), Zone.BATTLEFIELD, source, game);
return true;
}
Aggregations