use of mage.abilities.costs.mana.ManaCost in project mage by magefree.
the class ManaUtilTest method testManaAvailEnough.
/**
* Checks if the given available Mana is enough to pay a given mana cost
*
* @param manaCostsToPay
* @param availablyAny
* @param available
* @param expected
*/
private void testManaAvailEnough(String manaCostsToPay, int availablyAny, String available, boolean expected) {
ManaCost unpaid = new ManaCostsImpl(manaCostsToPay);
ManaCost costAvailable = new ManaCostsImpl(available);
Mana manaAvailable = costAvailable.getMana();
manaAvailable.setAny(availablyAny);
if (expected) {
Assert.assertTrue("The available Mana " + costAvailable.getText() + " should be enough to pay the costs " + unpaid.getText(), unpaid.getMana().enough(manaAvailable));
} else {
Assert.assertFalse("The available Mana " + costAvailable.getText() + " shouldn't be enough to pay the costs " + unpaid.getText(), unpaid.getMana().enough(manaAvailable));
}
}
use of mage.abilities.costs.mana.ManaCost in project mage by magefree.
the class ManaUtilTest method testManaToPayVsLand.
/**
* Another way to test ManaUtil.tryToAutoPay Here we also check what ability
* was auto chosen
*
* N.B. This method can be used ONLY if we have one ability left that auto
* choose mode! That's why we assert the following: Assert.assertEquals(1,
* useableAbilities.size());
*
* We get all mana abilities, then try to auto pay and compare to expected1
* and expected2 params.
*
* @param manaToPay Mana that should be paid using land.
* @param landName Land to use as mana producer.
* @param expected1 The amount of mana abilities the land should have.
* @param expectedChosen
*/
private void testManaToPayVsLand(String manaToPay, String landName, int expected1, Class<? extends BasicManaAbility> expectedChosen) {
ManaCost unpaid = new ManaCostsImpl(manaToPay);
Card card = CardRepository.instance.findCard(landName).getCard();
Assert.assertNotNull(card);
Map<UUID, ActivatedManaAbilityImpl> useableAbilities = getManaAbilities(card);
Assert.assertEquals(expected1, useableAbilities.size());
useableAbilities = ManaUtil.tryToAutoPay(unpaid, (LinkedHashMap<UUID, ActivatedManaAbilityImpl>) useableAbilities);
Assert.assertEquals(1, useableAbilities.size());
ActivatedManaAbilityImpl ability = useableAbilities.values().iterator().next();
Assert.assertTrue("Wrong mana ability has been chosen", expectedChosen.isInstance(ability));
}
use of mage.abilities.costs.mana.ManaCost in project mage by magefree.
the class SpellAbility method getConvertedXManaCost.
public int getConvertedXManaCost(Card card) {
int xMultiplier = 0;
int amount = 0;
if (card == null) {
return 0;
}
// mana cost instances
for (ManaCost manaCost : card.getManaCost()) {
if (manaCost instanceof VariableManaCost) {
xMultiplier = ((VariableManaCost) manaCost).getXInstancesCount();
break;
}
}
// mana cost final X value
boolean hasNonManaXCost = false;
for (Cost cost : getCosts()) {
if (cost instanceof VariableCost) {
hasNonManaXCost = true;
amount = ((VariableCost) cost).getAmount();
break;
}
}
if (!hasNonManaXCost) {
amount = getManaCostsToPay().getX();
}
return amount * xMultiplier;
}
use of mage.abilities.costs.mana.ManaCost 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.ManaCost in project mage by magefree.
the class PowerLeakEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(game.getActivePlayerId());
Permanent permanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
if (player == null || permanent == null) {
return false;
}
ManaCosts<ManaCost> cost = new ManaCostsImpl<>("{X}");
String message = "Pay {X} to prevent X damage from " + permanent.getLogName() + "?";
int xValue = 0;
if (player.chooseUse(Outcome.Neutral, message, source, game)) {
xValue = player.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, player.getId(), false, null)) {
game.informPlayers(player.getLogName() + " paid {" + xValue + "} for " + permanent.getLogName());
} else {
game.informPlayers(player.getLogName() + " didn't pay {X} for " + permanent.getLogName());
}
} else {
game.informPlayers(player.getLogName() + " didn't pay {X} for " + permanent.getLogName());
}
PreventDamageByTargetEffect effect = new PreventDamageByTargetEffect(Duration.OneUse, xValue, false);
if (xValue != 0 && cost.isPaid()) {
effect.setTargetPointer(new FixedTarget(permanent, game));
game.addEffect(effect, source);
}
player.damage(2, source.getSourceId(), source, game);
effect.discard();
return true;
}
Aggregations