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;
}
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;
}
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;
}
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;
}
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();
}
Aggregations