Search in sources :

Example 21 with ManaCostsImpl

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;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) OrCost(mage.abilities.costs.OrCost) UUID(java.util.UUID) ManaCostsImpl(mage.abilities.costs.mana.ManaCostsImpl)

Example 22 with ManaCostsImpl

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;
}
Also used : AtTheBeginOfNextEndStepDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility) ReturnToHandSourceEffect(mage.abilities.effects.common.ReturnToHandSourceEffect) CreateDelayedTriggeredAbilityEffect(mage.abilities.effects.common.CreateDelayedTriggeredAbilityEffect) SimpleActivatedAbility(mage.abilities.common.SimpleActivatedAbility) ManaCostsImpl(mage.abilities.costs.mana.ManaCostsImpl)

Example 23 with ManaCostsImpl

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;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) ReturnToHandTargetEffect(mage.abilities.effects.common.ReturnToHandTargetEffect) Cost(mage.abilities.costs.Cost) ManaCostsImpl(mage.abilities.costs.mana.ManaCostsImpl) Spell(mage.game.stack.Spell)

Example 24 with ManaCostsImpl

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));
    }
}
Also used : Mana(mage.Mana) ManaCost(mage.abilities.costs.mana.ManaCost) ManaCostsImpl(mage.abilities.costs.mana.ManaCostsImpl)

Example 25 with ManaCostsImpl

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));
}
Also used : ManaCost(mage.abilities.costs.mana.ManaCost) ActivatedManaAbilityImpl(mage.abilities.mana.ActivatedManaAbilityImpl) UUID(java.util.UUID) ManaCostsImpl(mage.abilities.costs.mana.ManaCostsImpl) Card(mage.cards.Card) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

ManaCostsImpl (mage.abilities.costs.mana.ManaCostsImpl)98 Player (mage.players.Player)63 Permanent (mage.game.permanent.Permanent)33 Ability (mage.abilities.Ability)26 Cost (mage.abilities.costs.Cost)26 SimpleActivatedAbility (mage.abilities.common.SimpleActivatedAbility)23 UUID (java.util.UUID)16 Card (mage.cards.Card)16 ManaCosts (mage.abilities.costs.mana.ManaCosts)15 SpellAbility (mage.abilities.SpellAbility)14 FixedTarget (mage.target.targetpointer.FixedTarget)13 Test (org.junit.Test)13 GenericManaCost (mage.abilities.costs.mana.GenericManaCost)12 ManaCost (mage.abilities.costs.mana.ManaCost)11 ContinuousEffect (mage.abilities.effects.ContinuousEffect)8 SimpleStaticAbility (mage.abilities.common.SimpleStaticAbility)7 TargetPermanent (mage.target.TargetPermanent)7 MageObjectReference (mage.MageObjectReference)6 Effect (mage.abilities.effects.Effect)6 DamageTargetEffect (mage.abilities.effects.common.DamageTargetEffect)6