use of mage.abilities.effects.common.ReturnFromGraveyardToBattlefieldWithCounterTargetEffect in project mage by magefree.
the class GraveEndeavorEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
List<Integer> results = player.rollDice(outcome, source, game, 10, 2, 0);
int firstResult = results.get(0);
int secondResult = results.get(1);
int first, second;
if (firstResult != secondResult && player.chooseUse(outcome, "Choose a number of +1/+1 counters to put on the creature you return", "The other number will be the amount of life your opponents lose and you gain", "" + firstResult, "" + secondResult, source, game)) {
first = firstResult;
second = secondResult;
} else {
first = secondResult;
second = firstResult;
}
if (player.getGraveyard().count(StaticFilters.FILTER_CARD_CREATURE, game) > 0) {
TargetCard target = new TargetCardInYourGraveyard(StaticFilters.FILTER_CARD_CREATURE_YOUR_GRAVEYARD);
target.setNotTarget(true);
player.choose(outcome, target, source.getControllerId(), game);
if (target.getFirstTarget() != null) {
new ReturnFromGraveyardToBattlefieldWithCounterTargetEffect(CounterType.P1P1.createInstance(first)).setTargetPointer(new FixedTarget(target.getFirstTarget(), game)).apply(game, source);
}
}
for (UUID playerId : game.getOpponents(source.getControllerId())) {
Player opponent = game.getPlayer(playerId);
if (opponent == null) {
continue;
}
opponent.loseLife(second, game, source, false);
}
player.gainLife(second, game, source);
return true;
}
Aggregations