use of mage.abilities.costs.mana.GenericManaCost in project mage by magefree.
the class FadeAwayEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
Player player = game.getPlayer(playerId);
if (player != null) {
int creaturesNumber = game.getBattlefield().getAllActivePermanents(FILTER_CREATURE, playerId, game).size();
if (creaturesNumber > 0) {
String message = "For how many creatures will you pay (up to " + creaturesNumber + ")?";
int payAmount = 0;
boolean paid = false;
while (player.canRespond() && !paid) {
payAmount = player.getAmount(0, creaturesNumber, message, game);
ManaCostsImpl cost = new ManaCostsImpl();
cost.add(new GenericManaCost(payAmount));
cost.clearPaid();
if (cost.payOrRollback(source, game, source, playerId)) {
paid = true;
}
}
int sacrificeNumber = creaturesNumber - payAmount;
game.informPlayers(player.getLogName() + " pays {" + payAmount + "} and sacrifices " + sacrificeNumber + " permanent" + (sacrificeNumber == 1 ? "" : "s"));
if (sacrificeNumber > 0) {
int permanentsNumber = game.getBattlefield().getAllActivePermanents(playerId).size();
int targetsNumber = Math.min(sacrificeNumber, permanentsNumber);
TargetControlledPermanent target = new TargetControlledPermanent(targetsNumber);
player.chooseTarget(Outcome.Sacrifice, target, source, game);
for (UUID permanentId : target.getTargets()) {
Permanent permanent = game.getPermanent(permanentId);
if (permanent != null) {
permanent.sacrifice(source, game);
}
}
}
} else {
game.informPlayers(player.getLogName() + " has no creatures");
}
}
}
return true;
}
use of mage.abilities.costs.mana.GenericManaCost in project mage by magefree.
the class HeroOfLeinaTowerEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player you = game.getPlayer(source.getControllerId());
ManaCosts cost = new ManaCostsImpl("{X}");
if (you != null && you.chooseUse(Outcome.BoostCreature, "Do you want to to pay {X}?", source, game)) {
int costX = you.announceXMana(0, Integer.MAX_VALUE, "Announce the value for {X}", game, source);
cost.add(new GenericManaCost(costX));
if (cost.pay(source, game, source, source.getControllerId(), false, null)) {
Permanent sourcePermanent = game.getPermanent(source.getSourceId());
if (sourcePermanent != null) {
return new AddCountersSourceEffect(CounterType.P1P1.createInstance(costX), true).apply(game, source);
}
}
}
return false;
}
use of mage.abilities.costs.mana.GenericManaCost in project mage by magefree.
the class ThespiansStageCopyEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent sourcePermanent = game.getPermanent(source.getSourceId());
Permanent copyFromPermanent = game.getPermanent(getTargetPointer().getFirst(game, source));
if (sourcePermanent != null && copyFromPermanent != null) {
Permanent newPermanent = game.copyPermanent(copyFromPermanent, sourcePermanent.getId(), source, new EmptyCopyApplier());
Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, new ThespiansStageCopyEffect(), new GenericManaCost(2));
ability.addCost(new TapSourceCost());
ability.addTarget(new TargetLandPermanent());
newPermanent.addAbility(ability, source.getSourceId(), game);
return true;
}
return false;
}
use of mage.abilities.costs.mana.GenericManaCost in project mage by magefree.
the class WildbornPreserverCreateReflexiveTriggerEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
ManaCosts cost = new ManaCostsImpl("{X}");
if (player == null) {
return false;
}
if (!player.chooseUse(outcome, "Pay " + cost.getText() + "?", source, game)) {
return false;
}
int costX = player.announceXMana(0, Integer.MAX_VALUE, "Announce the value for {X}", game, source);
cost.add(new GenericManaCost(costX));
if (!cost.pay(source, game, source, source.getControllerId(), false, null)) {
return false;
}
game.fireReflexiveTriggeredAbility(new ReflexiveTriggeredAbility(new AddCountersSourceEffect(CounterType.P1P1.createInstance(costX)), false, "put X +1/+1 counters on {this}"), source);
return true;
}
use of mage.abilities.costs.mana.GenericManaCost in project mage by magefree.
the class RandomPlayer method getAction.
private Ability getAction(Game game) {
List<ActivatedAbility> playables = getPlayableAbilities(game);
Ability ability;
while (true) {
if (playables.size() == 1) {
ability = playables.get(0);
} else {
ability = playables.get(RandomUtil.nextInt(playables.size()));
}
List<Ability> options = getPlayableOptions(ability, game);
if (!options.isEmpty()) {
if (options.size() == 1) {
ability = options.get(0);
} else {
ability = options.get(RandomUtil.nextInt(options.size()));
}
}
if (!ability.getManaCosts().getVariableCosts().isEmpty()) {
int amount = getAvailableManaProducers(game).size() - ability.getManaCosts().manaValue();
if (amount > 0) {
ability = ability.copy();
ability.getManaCostsToPay().add(new GenericManaCost(RandomUtil.nextInt(amount)));
}
}
// else {
break;
// }
}
return ability;
}
Aggregations