use of mage.abilities.costs.mana.ManaCost in project mage by magefree.
the class RemnantOfTheRisingStarEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
ManaCosts<ManaCost> cost = new ManaCostsImpl<>("{X}");
if (player == null || !player.chooseUse(Outcome.BoostCreature, "Pay " + cost.getText() + "?", source, game)) {
return false;
}
int xValue = player.announceXMana(0, Integer.MAX_VALUE, "Announce the value for {X}", game, source);
cost.add(new GenericManaCost(xValue));
if (!cost.pay(source, game, source, source.getControllerId(), false, null)) {
return false;
}
Permanent permanent = (Permanent) getValue("permanentEnteringBattlefield");
if (permanent == null) {
return false;
}
game.fireReflexiveTriggeredAbility(new ReflexiveTriggeredAbility(new AddCountersTargetEffect(CounterType.P1P1.createInstance(xValue)).setTargetPointer(new FixedTarget(permanent, game)), false), source);
return true;
}
use of mage.abilities.costs.mana.ManaCost in project mage by magefree.
the class OrCost method pay.
@Override
public boolean pay(Ability ability, Game game, Ability source, UUID controllerId, boolean noMana, Cost costToPay) {
selectedCost = null;
// if only one can be paid select it
if (!firstCost.canPay(ability, source, controllerId, game)) {
selectedCost = secondCost;
}
if (!secondCost.canPay(ability, source, controllerId, game)) {
selectedCost = firstCost;
}
// if both can be paid player has to select
if (selectedCost == null) {
Player controller = game.getPlayer(controllerId);
if (controller != null) {
StringBuilder sb = new StringBuilder();
if (firstCost instanceof ManaCost) {
sb.append("Pay ");
}
sb.append(firstCost.getText()).append('?');
if (controller.chooseUse(Outcome.Detriment, sb.toString(), ability, game)) {
selectedCost = firstCost;
} else {
selectedCost = secondCost;
}
}
}
if (selectedCost == null) {
return false;
}
return selectedCost.pay(ability, game, source, controllerId, noMana, costToPay);
}
use of mage.abilities.costs.mana.ManaCost in project mage by magefree.
the class OfferingCostReductionEffect method getManaOptions.
@Override
public ManaOptions getManaOptions(Ability source, Game game, ManaCost unpaid) {
ManaOptions additionalManaOptionsForThisAbility = new ManaOptions();
// Creatures from the offerd type
game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game).stream().map(Card::getSpellAbility).filter(Objects::nonNull).forEach(spellAbility -> {
ManaOptions manaOptionsForThisPermanent = new ManaOptions();
for (ManaCost manaCost : spellAbility.getManaCosts()) {
if (manaCost instanceof HybridManaCost) {
ManaOptions manaOptionsForHybrid = new ManaOptions();
manaOptionsForHybrid.addAll(manaCost.getManaOptions());
manaOptionsForThisPermanent.addMana(manaOptionsForHybrid);
} else {
manaOptionsForThisPermanent.addMana(manaCost.getMana());
}
}
additionalManaOptionsForThisAbility.addAll(manaOptionsForThisPermanent);
});
additionalManaOptionsForThisAbility.removeDuplicated();
return additionalManaOptionsForThisAbility;
}
use of mage.abilities.costs.mana.ManaCost in project mage by magefree.
the class CounterUnlessPaysEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
StackObject spell = game.getStack().getStackObject(targetPointer.getFirst(game, source));
if (spell == null) {
return false;
}
Player player = game.getPlayer(spell.getControllerId());
if (player == null) {
return false;
}
Cost costToPay;
String costValueMessage;
if (cost != null) {
costToPay = cost.copy();
costValueMessage = costToPay.getText();
} else {
costToPay = ManaUtil.createManaCost(genericMana, game, source, this);
costValueMessage = "{" + genericMana.calculate(game, source, this) + "}";
}
String message = "";
if (costToPay instanceof ManaCost) {
message += "Pay ";
}
message += costValueMessage + '?';
costToPay.clearPaid();
if (!(player.chooseUse(Outcome.Benefit, message, source, game) && costToPay.pay(source, game, source, spell.getControllerId(), false, null))) {
game.informPlayers(player.getLogName() + " chooses not to pay " + costValueMessage + " to prevent the counter effect");
if (exile) {
game.getStack().counter(spell.getId(), source, game, Zone.EXILED, false, ZoneDetail.NONE);
} else {
return game.getStack().counter(spell.getId(), source, game);
}
}
game.informPlayers(player.getLogName() + " chooses to pay " + costValueMessage + " to prevent the counter effect");
return true;
}
use of mage.abilities.costs.mana.ManaCost in project mage by magefree.
the class DepalaPilotExemplarEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
ManaCosts<ManaCost> cost = new ManaCostsImpl<>("{X}");
int xValue = controller.announceXMana(0, Integer.MAX_VALUE, "Choose the amount of mana to pay", game, source);
cost.add(new GenericManaCost(xValue));
if (cost.pay(source, game, source, source.getControllerId(), false) && xValue > 0) {
new RevealLibraryPutIntoHandEffect(xValue, filter, Zone.LIBRARY, false).apply(game, source);
}
return true;
}
return false;
}
Aggregations