use of mage.abilities.costs.Cost in project mage by magefree.
the class HarnessedLightningEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
new GetEnergyCountersControllerEffect(3).apply(game, source);
int numberToPay = controller.getAmount(0, controller.getCounters().getCount(CounterType.ENERGY), "How many {E} do you like to pay?", game);
if (numberToPay > 0) {
Cost cost = new PayEnergyCost(numberToPay);
if (cost.pay(source, game, source, source.getControllerId(), true)) {
Permanent targetCreature = game.getPermanent(getTargetPointer().getFirst(game, source));
if (targetCreature != null) {
targetCreature.damage(numberToPay, source.getSourceId(), source, game, false, true);
}
}
}
return true;
}
return false;
}
use of mage.abilities.costs.Cost in project mage by magefree.
the class HornOfPlentyEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player caster = game.getPlayer(targetPointer.getFirst(game, source));
if (caster != null) {
if (caster.chooseUse(Outcome.DrawCard, "Pay {1} to draw a card at the beginning of the next end step?", source, game)) {
Cost cost = new ManaCostsImpl("{1}");
if (cost.pay(source, game, source, caster.getId(), false, null)) {
Effect effect = new DrawCardTargetEffect(1);
effect.setTargetPointer(new FixedTarget(caster.getId()));
game.addDelayedTriggeredAbility(new AtTheBeginOfNextEndStepDelayedTriggeredAbility(effect, TargetController.ANY), source);
return true;
}
}
}
return false;
}
use of mage.abilities.costs.Cost in project mage by magefree.
the class JhoiraOfTheGhituSuspendEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
List<Card> cards = new ArrayList<>();
for (Cost cost : source.getCosts()) {
if (cost instanceof ExileFromHandCost) {
cards = ((ExileFromHandCost) cost).getCards();
}
}
if (cards != null && !cards.isEmpty()) {
// always one card to exile
Card card = game.getCard(cards.get(0).getId());
if (card == null) {
return false;
}
card = card.getMainCard();
boolean hasSuspend = card.getAbilities(game).containsClass(SuspendAbility.class);
UUID exileId = SuspendAbility.getSuspendExileId(controller.getId(), game);
if (controller.moveCardToExileWithInfo(card, exileId, "Suspended cards of " + controller.getName(), source, game, Zone.HAND, true)) {
card.addCounters(CounterType.TIME.createInstance(4), source.getControllerId(), source, game);
if (!hasSuspend) {
game.addEffect(new GainSuspendEffect(new MageObjectReference(card, game)), source);
}
game.informPlayers(controller.getLogName() + " suspends 4 - " + card.getName());
return true;
}
}
return false;
}
use of mage.abilities.costs.Cost in project mage by magefree.
the class MagneticMountainEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(targetPointer.getFirst(game, source));
Permanent sourcePermanent = game.getPermanent(source.getSourceId());
if (player != null && sourcePermanent != null) {
int countBattlefield = game.getBattlefield().getAllActivePermanents(filter2, game.getActivePlayerId(), game).size();
while (player.canRespond() && countBattlefield > 0 && player.chooseUse(Outcome.Benefit, "Pay {4} and untap a tapped blue creature under your control?", source, game)) {
Target tappedCreatureTarget = new TargetControlledCreaturePermanent(1, 1, filter2, true);
if (player.choose(Outcome.Untap, tappedCreatureTarget, source.getSourceId(), game)) {
Cost cost = ManaUtil.createManaCost(4, false);
Permanent tappedCreature = game.getPermanent(tappedCreatureTarget.getFirstTarget());
if (tappedCreature != null && cost.pay(source, game, source, player.getId(), false)) {
tappedCreature.untap(game);
} else {
break;
}
} else {
break;
}
countBattlefield = game.getBattlefield().getAllActivePermanents(filter2, game.getActivePlayerId(), game).size();
}
return true;
}
return false;
}
use of mage.abilities.costs.Cost in project mage by magefree.
the class MercadianLiftEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
int numberOfCounters = 0;
for (Cost cost : source.getCosts()) {
if (cost instanceof RemoveVariableCountersSourceCost) {
numberOfCounters = ((RemoveVariableCountersSourceCost) cost).getAmount();
}
}
System.out.println("The number is " + numberOfCounters);
FilterCreatureCard filter = new FilterCreatureCard();
filter.add(new ManaValuePredicate(ComparisonType.EQUAL_TO, numberOfCounters));
filter.setMessage("creature card with mana value " + numberOfCounters);
TargetCardInHand target = new TargetCardInHand(filter);
if (target.canChoose(source.getSourceId(), controller.getId(), game) && controller.chooseUse(Outcome.PutCardInPlay, "Put " + filter.getMessage() + " from your hand onto the battlefield?", source, game) && controller.choose(Outcome.PutCardInPlay, target, source.getSourceId(), game)) {
target.setRequired(false);
Card card = game.getCard(target.getFirstTarget());
if (card != null) {
return controller.moveCards(card, Zone.BATTLEFIELD, source, game);
}
}
}
return false;
}
Aggregations