Search in sources :

Example 31 with ManaCostsImpl

use of mage.abilities.costs.mana.ManaCostsImpl in project mage by magefree.

the class EntwineAbility method addOptionalAdditionalCosts.

@Override
public void addOptionalAdditionalCosts(Ability ability, Game game) {
    if (!(ability instanceof SpellAbility)) {
        return;
    }
    Player player = game.getPlayer(ability.getControllerId());
    if (player == null) {
        return;
    }
    this.resetEntwine(game, ability);
    if (entwineCost == null) {
        return;
    }
    // AI can use it
    if (entwineCost.canPay(ability, this, ability.getControllerId(), game) && player.chooseUse(Outcome.Benefit, "Pay " + entwineCost.getText(false) + " ?", ability, game)) {
        for (Iterator it = ((Costs) entwineCost).iterator(); it.hasNext(); ) {
            Cost cost = (Cost) it.next();
            if (cost instanceof ManaCostsImpl) {
                ability.getManaCostsToPay().add((ManaCostsImpl) cost.copy());
            } else {
                ability.getCosts().add(cost.copy());
            }
        }
        activateEntwine(game, ability);
    }
}
Also used : Player(mage.players.Player) Iterator(java.util.Iterator) SpellAbility(mage.abilities.SpellAbility) ManaCostsImpl(mage.abilities.costs.mana.ManaCostsImpl)

Example 32 with ManaCostsImpl

use of mage.abilities.costs.mana.ManaCostsImpl in project mage by magefree.

the class HeroOfLeinaTowerEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player you = game.getPlayer(source.getControllerId());
    ManaCosts cost = new ManaCostsImpl("{X}");
    if (you != null && you.chooseUse(Outcome.BoostCreature, "Do you want to to pay {X}?", source, game)) {
        int costX = you.announceXMana(0, Integer.MAX_VALUE, "Announce the value for {X}", game, source);
        cost.add(new GenericManaCost(costX));
        if (cost.pay(source, game, source, source.getControllerId(), false, null)) {
            Permanent sourcePermanent = game.getPermanent(source.getSourceId());
            if (sourcePermanent != null) {
                return new AddCountersSourceEffect(CounterType.P1P1.createInstance(costX), true).apply(game, source);
            }
        }
    }
    return false;
}
Also used : ManaCosts(mage.abilities.costs.mana.ManaCosts) AddCountersSourceEffect(mage.abilities.effects.common.counter.AddCountersSourceEffect) Player(mage.players.Player) GenericManaCost(mage.abilities.costs.mana.GenericManaCost) Permanent(mage.game.permanent.Permanent) ManaCostsImpl(mage.abilities.costs.mana.ManaCostsImpl)

Example 33 with ManaCostsImpl

use of mage.abilities.costs.mana.ManaCostsImpl in project mage by magefree.

the class IceCaveEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent sourcePermanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
    Spell spell = (Spell) game.getStack().getStackObject(targetPointer.getFirst(game, source));
    if (sourcePermanent != null && spell != null && controller != null) {
        Player spellController = game.getPlayer(spell.getControllerId());
        Cost cost = new ManaCostsImpl(spell.getSpellAbility().getManaCosts().getText());
        if (spellController != null) {
            for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
                Player player = game.getPlayer(playerId);
                if (player != null && !player.equals(spellController)) {
                    cost.clearPaid();
                    if (cost.canPay(source, source, player.getId(), game) && player.chooseUse(outcome, "Pay " + cost.getText() + " to counter " + spell.getIdName() + '?', source, game)) {
                        if (cost.pay(source, game, source, playerId, false, null)) {
                            game.informPlayers(player.getLogName() + " pays" + cost.getText() + " to counter " + spell.getIdName() + '.');
                            game.getStack().counter(spell.getId(), source, game);
                            break;
                        }
                    }
                }
            }
        }
    }
    return true;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) UUID(java.util.UUID) Cost(mage.abilities.costs.Cost) ManaCostsImpl(mage.abilities.costs.mana.ManaCostsImpl) Spell(mage.game.stack.Spell)

Example 34 with ManaCostsImpl

use of mage.abilities.costs.mana.ManaCostsImpl in project mage by magefree.

the class WildbornPreserverCreateReflexiveTriggerEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    ManaCosts cost = new ManaCostsImpl("{X}");
    if (player == null) {
        return false;
    }
    if (!player.chooseUse(outcome, "Pay " + cost.getText() + "?", source, game)) {
        return false;
    }
    int costX = player.announceXMana(0, Integer.MAX_VALUE, "Announce the value for {X}", game, source);
    cost.add(new GenericManaCost(costX));
    if (!cost.pay(source, game, source, source.getControllerId(), false, null)) {
        return false;
    }
    game.fireReflexiveTriggeredAbility(new ReflexiveTriggeredAbility(new AddCountersSourceEffect(CounterType.P1P1.createInstance(costX)), false, "put X +1/+1 counters on {this}"), source);
    return true;
}
Also used : ManaCosts(mage.abilities.costs.mana.ManaCosts) AddCountersSourceEffect(mage.abilities.effects.common.counter.AddCountersSourceEffect) Player(mage.players.Player) GenericManaCost(mage.abilities.costs.mana.GenericManaCost) ReflexiveTriggeredAbility(mage.abilities.common.delayed.ReflexiveTriggeredAbility) ManaCostsImpl(mage.abilities.costs.mana.ManaCostsImpl)

Example 35 with ManaCostsImpl

use of mage.abilities.costs.mana.ManaCostsImpl in project mage by magefree.

the class TargetPriorityTest method test_targetAmount_BadCase.

@Test
public void test_targetAmount_BadCase() {
    // choose targets as enters battlefield (e.g. can't be canceled)
    SpellAbility spell = new SpellAbility(new ManaCostsImpl("R"), "damage 3", Zone.HAND);
    Ability ability = new EntersBattlefieldTriggeredAbility(new DamageMultiEffect(3));
    ability.addTarget(new TargetCreaturePermanentAmount(3));
    addCustomCardWithSpell(playerA, spell, ability, CardType.ENCHANTMENT);
    addCard(Zone.BATTLEFIELD, playerA, "Mountain", 1);
    // 
    // 1/1
    addCard(Zone.BATTLEFIELD, playerA, "Memnite", 3);
    // 2/2
    addCard(Zone.BATTLEFIELD, playerA, "Balduvian Bears", 3);
    // 2/2 with ability
    addCard(Zone.BATTLEFIELD, playerA, "Ashcoat Bear", 3);
    // 4/3
    addCard(Zone.BATTLEFIELD, playerA, "Golden Bear", 3);
    // 4/4 with ability
    addCard(Zone.BATTLEFIELD, playerA, "Battering Sliver", 3);
    castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "damage 3");
    // must damage x3 Balduvian Bears by -1 to keep alive
    checkDamage("pt after", 1, PhaseStep.BEGIN_COMBAT, playerA, "Balduvian Bears", 1);
    // showBattlefield("after", 1, PhaseStep.BEGIN_COMBAT, playerA);
    setStopAt(1, PhaseStep.BEGIN_COMBAT);
    execute();
    assertAllCommandsUsed();
    assertPermanentCount(playerA, "damage 3", 1);
    assertPermanentCount(playerA, "Memnite", 3);
    assertPermanentCount(playerA, "Balduvian Bears", 3);
    assertPermanentCount(playerA, "Ashcoat Bear", 3);
    assertPermanentCount(playerA, "Golden Bear", 3);
    assertPermanentCount(playerA, "Battering Sliver", 3);
}
Also used : SimpleActivatedAbility(mage.abilities.common.SimpleActivatedAbility) EntersBattlefieldTriggeredAbility(mage.abilities.common.EntersBattlefieldTriggeredAbility) SpellAbility(mage.abilities.SpellAbility) Ability(mage.abilities.Ability) TargetCreaturePermanentAmount(mage.target.common.TargetCreaturePermanentAmount) DamageMultiEffect(mage.abilities.effects.common.DamageMultiEffect) SpellAbility(mage.abilities.SpellAbility) EntersBattlefieldTriggeredAbility(mage.abilities.common.EntersBattlefieldTriggeredAbility) ManaCostsImpl(mage.abilities.costs.mana.ManaCostsImpl) Test(org.junit.Test)

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