use of mage.abilities.costs.mana.ManaCostsImpl in project mage by magefree.
the class ManaUtilTest method testManaReduction.
/**
* Checks if a given mana reduction left the expected amount of mana costs
*
* @param manaCostsToPay
* @param availablyAny
* @param available
* @param expected
*/
private void testManaReduction(String manaCostsToPay, String manaToReduce, String restMana) {
SpellAbility spellAbility = new SpellAbility(new ManaCostsImpl(manaCostsToPay), "Test");
CardUtil.adjustCost(spellAbility, new ManaCostsImpl(manaToReduce), true);
Assert.assertTrue("The mana cost to pay " + manaCostsToPay + " reduced by " + manaToReduce + " should left " + restMana + " but the rest was " + spellAbility.getManaCostsToPay().getText(), spellAbility.getManaCostsToPay().getText().equals(restMana));
}
use of mage.abilities.costs.mana.ManaCostsImpl in project mage by magefree.
the class StriveCostIncreasingEffect method apply.
@Override
public boolean apply(Game game, Ability source, Ability abilityToModify) {
for (Target target : abilityToModify.getTargets()) {
if (target.getMaxNumberOfTargets() == Integer.MAX_VALUE) {
// strive works with "any number of target" only
int additionalTargets = target.getTargets().size() - 1;
StringBuilder sb = new StringBuilder();
for (int i = 0; i < additionalTargets; i++) {
// Build up a string of strive costs for each target
sb.append(striveCosts.getText());
}
String finalCost = ManaUtil.condenseManaCostString(sb.toString());
abilityToModify.getManaCostsToPay().add(new ManaCostsImpl(finalCost));
return true;
}
}
return false;
}
use of mage.abilities.costs.mana.ManaCostsImpl in project mage by magefree.
the class CumulativeUpkeepEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
Permanent permanent = game.getPermanent(source.getSourceId());
if (player != null && permanent != null) {
int ageCounter = permanent.getCounters(game).getCount(CounterType.AGE);
if (cumulativeCost instanceof ManaCost) {
ManaCostsImpl totalCost = new ManaCostsImpl<>();
for (int i = 0; i < ageCounter; i++) {
totalCost.add((ManaCost) cumulativeCost.copy());
}
if (player.chooseUse(Outcome.Benefit, "Pay " + totalCost.getText() + '?', source, game)) {
totalCost.clearPaid();
if (totalCost.payOrRollback(source, game, source, source.getControllerId())) {
game.fireEvent(new ManaEvent(EventType.PAID_CUMULATIVE_UPKEEP, permanent.getId(), source, player.getId(), totalCost.getUsedManaToPay()));
return true;
}
}
game.fireEvent(new GameEvent(GameEvent.EventType.DIDNT_PAY_CUMULATIVE_UPKEEP, permanent.getId(), source, player.getId(), ageCounter, false));
if (source.getControllerId().equals(permanent.getControllerId())) {
// Permanent can only be sacrificed if you still control it
permanent.sacrifice(source, game);
}
return true;
} else {
CostsImpl<Cost> totalCost = new CostsImpl<>();
for (int i = 0; i < ageCounter; i++) {
totalCost.add(cumulativeCost.copy());
}
if (player.chooseUse(Outcome.Benefit, totalCost.getText() + '?', source, game)) {
totalCost.clearPaid();
int bookmark = game.bookmarkState();
if (totalCost.pay(source, game, source, source.getControllerId(), false, null)) {
game.fireEvent(new GameEvent(GameEvent.EventType.PAID_CUMULATIVE_UPKEEP, permanent.getId(), source, player.getId(), ageCounter, false));
return true;
} else {
player.restoreState(bookmark, source.getRule(), game);
}
}
game.fireEvent(new GameEvent(GameEvent.EventType.DIDNT_PAY_CUMULATIVE_UPKEEP, permanent.getId(), source, player.getId(), ageCounter, false));
permanent.sacrifice(source, game);
return true;
}
}
return false;
}
use of mage.abilities.costs.mana.ManaCostsImpl in project mage by magefree.
the class DashAddDelayedTriggeredAbilityEffect method addDashCost.
public final AlternativeCost2 addDashCost(String manaString) {
AlternativeCost2 evokeCost = new AlternativeCost2Impl(KEYWORD, REMINDER_TEXT, new ManaCostsImpl(manaString));
alternativeSourceCosts.add(evokeCost);
return evokeCost;
}
use of mage.abilities.costs.mana.ManaCostsImpl in project mage by magefree.
the class ConspireTriggeredAbility method addOptionalAdditionalCosts.
@Override
public void addOptionalAdditionalCosts(Ability ability, Game game) {
if (!(ability instanceof SpellAbility)) {
return;
}
Player player = game.getPlayer(getControllerId());
if (player == null) {
return;
}
// AI supports conspire
if (!conspireCost.canPay(ability, this, getControllerId(), game) || !player.chooseUse(Outcome.Benefit, "Pay " + conspireCost.getText(false) + " ?", ability, game)) {
return;
}
ability.getEffects().setValue("ConspireActivation" + conspireId + addedById, true);
for (Iterator<Cost> it = ((Costs<Cost>) conspireCost).iterator(); it.hasNext(); ) {
Cost cost = (Cost) it.next();
if (cost instanceof ManaCostsImpl) {
ability.getManaCostsToPay().add((ManaCostsImpl<?>) cost.copy());
} else {
ability.getCosts().add(cost.copy());
}
}
}
Aggregations