Search in sources :

Example 1 with TargetSpell

use of mage.target.TargetSpell in project mage by magefree.

the class KozilekDiscardCost method pay.

@Override
public boolean pay(Ability ability, Game game, Ability source, UUID controllerId, boolean noMana, Cost costToPay) {
    Spell targetSpell = game.getStack().getSpell(ability.getFirstTarget());
    if (targetSpell == null) {
        return false;
    }
    Player player = game.getPlayer(controllerId);
    if (player == null) {
        return false;
    }
    FilterCard filter = new FilterCard("card with mana value of " + targetSpell.getManaValue());
    filter.add(new ManaValuePredicate(ComparisonType.EQUAL_TO, targetSpell.getManaValue()));
    TargetCardInHand target = new TargetCardInHand(filter);
    this.getTargets().clear();
    this.getTargets().add(target);
    if (targets.choose(Outcome.Discard, controllerId, source.getSourceId(), game)) {
        for (UUID targetId : targets.get(0).getTargets()) {
            Card card = player.getHand().get(targetId, game);
            if (card == null) {
                return false;
            }
            player.discard(card, true, source, game);
            paid = true;
        }
    }
    return paid;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) TargetCardInHand(mage.target.common.TargetCardInHand) UUID(java.util.UUID) Spell(mage.game.stack.Spell) TargetSpell(mage.target.TargetSpell) FilterSpell(mage.filter.FilterSpell) Card(mage.cards.Card) FilterCard(mage.filter.FilterCard)

Example 2 with TargetSpell

use of mage.target.TargetSpell in project mage by magefree.

the class DeniedEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Spell targetSpell = game.getStack().getSpell(source.getFirstTarget());
    if (targetSpell == null) {
        return true;
    }
    Player player = game.getPlayer(targetSpell.getControllerId());
    String cardName = (String) game.getState().getValue(source.getSourceId().toString() + ChooseACardNameEffect.INFO_KEY);
    if (player != null && cardName != null) {
        player.revealCards("Denied!", player.getHand(), game, true);
        for (Card card : player.getHand().getCards(game)) {
            if (card != null && CardUtil.haveSameNames(card, cardName, game)) {
                game.getStack().counter(targetSpell.getId(), source, game);
                break;
            }
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) Spell(mage.game.stack.Spell) TargetSpell(mage.target.TargetSpell) Card(mage.cards.Card)

Example 3 with TargetSpell

use of mage.target.TargetSpell in project mage by magefree.

the class DrainingWhelkEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Spell targetSpell = game.getStack().getSpell(getTargetPointer().getFirst(game, source));
    if (targetSpell != null) {
        int spellCMC = targetSpell.getManaValue();
        super.apply(game, source);
        new AddCountersSourceEffect(CounterType.P1P1.createInstance(spellCMC)).apply(game, source);
        return true;
    }
    return false;
}
Also used : AddCountersSourceEffect(mage.abilities.effects.common.counter.AddCountersSourceEffect) Spell(mage.game.stack.Spell) TargetSpell(mage.target.TargetSpell)

Example 4 with TargetSpell

use of mage.target.TargetSpell in project mage by magefree.

the class ReverberationEffect method replaceEvent.

@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
    Player controller = game.getPlayer(source.getControllerId());
    DamageEvent damageEvent = (DamageEvent) event;
    if (controller != null) {
        Spell targetSpell = game.getStack().getSpell(source.getFirstTarget());
        if (targetSpell != null) {
            Player targetsController = game.getPlayer(targetSpell.getControllerId());
            if (targetsController != null) {
                targetsController.damage(damageEvent.getAmount(), damageEvent.getSourceId(), source, game, damageEvent.isCombatDamage(), damageEvent.isPreventable(), damageEvent.getAppliedEffects());
                return true;
            }
        }
    }
    return false;
}
Also used : Player(mage.players.Player) DamageEvent(mage.game.events.DamageEvent) FilterSpell(mage.filter.FilterSpell) Spell(mage.game.stack.Spell) TargetSpell(mage.target.TargetSpell)

Example 5 with TargetSpell

use of mage.target.TargetSpell in project mage by magefree.

the class ManaPoolTest method test_ConditionalMana_OneXPart.

@Test
public void test_ConditionalMana_OneXPart() {
    // {R}
    addCard(Zone.HAND, playerA, "Lightning Bolt");
    addCard(Zone.BATTLEFIELD, playerA, "Mountain", 1);
    // 
    addCustomCardWithAbility("add 10", playerA, new SimpleManaAbility(Zone.ALL, new AddConditionalManaEffect(Mana.RedMana(10), new SimpleActivatedAbilityManaBuilder()), new ManaCostsImpl("")));
    // 
    Ability ability = new SimpleActivatedAbility(Zone.ALL, new DamageTargetEffect(ManacostVariableValue.REGULAR), new ManaCostsImpl(""));
    ability.addTarget(new TargetAnyTarget());
    addCustomCardWithAbility("damage X", playerA, ability);
    // 
    // {X}: Counter target spell
    ability = new SimpleActivatedAbility(Zone.ALL, new CounterUnlessPaysEffect(ManacostVariableValue.REGULAR), new ManaCostsImpl("{X}"));
    ability.addTarget(new TargetSpell());
    addCustomCardWithAbility("counter until pay X", playerB, ability);
    addCard(Zone.BATTLEFIELD, playerB, "Island", 3);
    // make mana for spell
    activateAbility(1, PhaseStep.PRECOMBAT_MAIN, playerA, "{T}: Add {R}");
    checkManaPool("mana spell", 1, PhaseStep.PRECOMBAT_MAIN, playerA, "R", 1);
    // cast spell
    castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Lightning Bolt", playerB);
    // make mana for pay X to prevent
    activateAbility(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Add {R}");
    checkManaPool("mana prevent", 1, PhaseStep.PRECOMBAT_MAIN, playerA, "R", 10);
    // counter by X=3
    activateAbility(1, PhaseStep.PRECOMBAT_MAIN, playerB, "{X}: Counter");
    setChoice(playerB, "X=3");
    addTarget(playerB, "Lightning Bolt");
    // pay to prevent
    // pay 3 to prevent counter
    setChoice(playerA, true);
    waitStackResolved(1, PhaseStep.PRECOMBAT_MAIN);
    checkManaPool("mana after", 1, PhaseStep.PRECOMBAT_MAIN, playerA, "R", 10 + 1 - 1 - 3);
    checkLife("after", 1, PhaseStep.END_TURN, playerB, 20 - 3);
    setStopAt(1, PhaseStep.END_TURN);
    setStrictChooseMode(true);
    execute();
    assertAllCommandsUsed();
}
Also used : SimpleActivatedAbility(mage.abilities.common.SimpleActivatedAbility) SimpleManaAbility(mage.abilities.mana.SimpleManaAbility) Ability(mage.abilities.Ability) AddConditionalManaEffect(mage.abilities.effects.mana.AddConditionalManaEffect) CounterUnlessPaysEffect(mage.abilities.effects.common.CounterUnlessPaysEffect) SimpleActivatedAbilityManaBuilder(mage.abilities.mana.builder.common.SimpleActivatedAbilityManaBuilder) SimpleActivatedAbility(mage.abilities.common.SimpleActivatedAbility) TargetSpell(mage.target.TargetSpell) SimpleManaAbility(mage.abilities.mana.SimpleManaAbility) DamageTargetEffect(mage.abilities.effects.common.DamageTargetEffect) ManaCostsImpl(mage.abilities.costs.mana.ManaCostsImpl) TargetAnyTarget(mage.target.common.TargetAnyTarget) Test(org.junit.Test)

Aggregations

TargetSpell (mage.target.TargetSpell)9 Spell (mage.game.stack.Spell)5 Card (mage.cards.Card)4 Player (mage.players.Player)4 UUID (java.util.UUID)3 FilterSpell (mage.filter.FilterSpell)3 MageObject (mage.MageObject)2 Ability (mage.abilities.Ability)2 SimpleActivatedAbility (mage.abilities.common.SimpleActivatedAbility)2 ManaCostsImpl (mage.abilities.costs.mana.ManaCostsImpl)2 CounterUnlessPaysEffect (mage.abilities.effects.common.CounterUnlessPaysEffect)2 DamageTargetEffect (mage.abilities.effects.common.DamageTargetEffect)2 SimpleManaAbility (mage.abilities.mana.SimpleManaAbility)2 DamageEvent (mage.game.events.DamageEvent)2 StackObject (mage.game.stack.StackObject)2 TargetAnyTarget (mage.target.common.TargetAnyTarget)2 Test (org.junit.Test)2 AddCountersSourceEffect (mage.abilities.effects.common.counter.AddCountersSourceEffect)1 AddConditionalManaEffect (mage.abilities.effects.mana.AddConditionalManaEffect)1 SimpleActivatedAbilityManaBuilder (mage.abilities.mana.builder.common.SimpleActivatedAbilityManaBuilder)1