use of mage.abilities.costs.mana.ManaCostsImpl in project mage by magefree.
the class LimDulsHexEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent sourcePermanent = game.getPermanent(source.getSourceId());
if (sourcePermanent != null) {
for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
Player player = game.getPlayer(playerId);
if (player != null) {
OrCost costToPay = new OrCost(new ManaCostsImpl("{B}"), new ManaCostsImpl("{3}"), "{B} or {3}");
costToPay.clearPaid();
if (!(player.chooseUse(Outcome.Benefit, "Pay {B} or {3}?", source, game) && costToPay.pay(source, game, source, player.getId(), false, null))) {
game.informPlayers(player.getLogName() + " chooses not to pay " + costToPay.getText() + " to prevent 1 damage from " + sourcePermanent.getLogName());
player.damage(1, sourcePermanent.getId(), source, game);
} else {
game.informPlayers(player.getLogName() + " chooses to pay " + costToPay.getText() + " to prevent 1 damage from " + sourcePermanent.getLogName());
}
}
}
return true;
}
return false;
}
use of mage.abilities.costs.mana.ManaCostsImpl in project mage by magefree.
the class SakashimaTheImpostorCopyApplier method apply.
@Override
public boolean apply(Game game, MageObject blueprint, Ability source, UUID copyToObjectId) {
blueprint.addSuperType(SuperType.LEGENDARY);
blueprint.setName("Sakashima the Impostor");
// {2}{U}{U}: Return Sakashima the Impostor to its owner's hand at the beginning of the next end step
blueprint.getAbilities().add(new SimpleActivatedAbility(Zone.BATTLEFIELD, new CreateDelayedTriggeredAbilityEffect(new AtTheBeginOfNextEndStepDelayedTriggeredAbility(new ReturnToHandSourceEffect(true)), false), new ManaCostsImpl("{2}{U}{U}")));
return true;
}
use of mage.abilities.costs.mana.ManaCostsImpl in project mage by magefree.
the class StringOfDisappearancesEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent permanent = game.getPermanent(source.getFirstTarget());
if (permanent == null) {
return false;
}
Player affectedPlayer = game.getPlayer(permanent.getControllerId());
new ReturnToHandTargetEffect().apply(game, source);
if (affectedPlayer == null) {
return false;
}
if (!affectedPlayer.chooseUse(Outcome.Copy, "Pay {U}{U} to copy the spell?", source, game)) {
return true;
}
Cost cost = new ManaCostsImpl("{U}{U}");
if (!cost.pay(source, game, source, affectedPlayer.getId(), false, null)) {
return true;
}
Spell spell = game.getStack().getSpell(source.getSourceId());
if (spell == null) {
return true;
}
spell.createCopyOnStack(game, source, affectedPlayer.getId(), true);
return true;
}
use of mage.abilities.costs.mana.ManaCostsImpl 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.ManaCostsImpl 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));
}
Aggregations