use of mage.abilities.costs.Cost in project mage by magefree.
the class PyreOfHeroesEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent sacrificedPermanent = null;
for (Cost cost : source.getCosts()) {
if (cost instanceof SacrificeTargetCost) {
SacrificeTargetCost sacrificeCost = (SacrificeTargetCost) cost;
if (!sacrificeCost.getPermanents().isEmpty()) {
sacrificedPermanent = sacrificeCost.getPermanents().get(0);
}
break;
}
}
Player controller = game.getPlayer(source.getControllerId());
if (sacrificedPermanent == null || controller == null) {
return false;
}
int newConvertedCost = sacrificedPermanent.getManaValue() + 1;
FilterCard filter = new FilterCard("creature card with mana value " + newConvertedCost);
filter.add(new ManaValuePredicate(ComparisonType.EQUAL_TO, newConvertedCost));
filter.add(CardType.CREATURE.getPredicate());
filter.add(new SharesCreatureTypePredicate(sacrificedPermanent));
TargetCardInLibrary target = new TargetCardInLibrary(filter);
if (controller.searchLibrary(target, source, game)) {
Card card = controller.getLibrary().getCard(target.getFirstTarget(), game);
controller.moveCards(card, Zone.BATTLEFIELD, source, game);
}
controller.shuffleLibrary(source, game);
return true;
}
use of mage.abilities.costs.Cost in project mage by magefree.
the class SageOfHoursEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player != null) {
int countersRemoved = 0;
for (Cost cost : source.getCosts()) {
if (cost instanceof RemoveAllCountersSourceCost) {
countersRemoved = ((RemoveAllCountersSourceCost) cost).getRemovedCounters();
}
}
int turns = countersRemoved / 5;
for (int i = 0; i < turns; i++) {
game.getState().getTurnMods().add(new TurnMod(player.getId(), false));
}
game.informPlayers("Removed " + countersRemoved + " +1/+1 counters: " + player.getLogName() + " takes " + CardUtil.numberToText(turns, "an") + (turns > 1 ? " extra turns " : " extra turn ") + "after this one");
return true;
}
return false;
}
use of mage.abilities.costs.Cost 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;
}
use of mage.abilities.costs.Cost in project mage by magefree.
the class TivashGloomSummonerEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
PlayerGainedLifeWatcher watcher = game.getState().getWatcher(PlayerGainedLifeWatcher.class);
if (player == null || watcher == null) {
return false;
}
int lifeGained = watcher.getLifeGained(source.getControllerId());
Cost cost = new PayLifeCost(lifeGained);
if (!cost.canPay(source, source, source.getControllerId(), game) || !player.chooseUse(Outcome.PutCreatureInPlay, "Pay " + lifeGained + " life?", source, game) || !cost.pay(source, game, source, source.getControllerId(), true)) {
return false;
}
new DemonFlyingToken(lifeGained).putOntoBattlefield(1, game, source, source.getControllerId());
return true;
}
use of mage.abilities.costs.Cost in project mage by magefree.
the class TymnaTheWeaverWatcher method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
TymnaTheWeaverWatcher watcher = game.getState().getWatcher(TymnaTheWeaverWatcher.class);
if (watcher != null) {
int cardsToDraw = watcher.opponentsThatGotCombatDamage(source.getControllerId(), game);
Cost cost = new PayLifeCost(cardsToDraw);
if (cost.canPay(source, source, source.getControllerId(), game) && cost.pay(source, game, source, source.getControllerId(), false)) {
controller.drawCards(cardsToDraw, source, game);
}
return true;
}
}
return false;
}
Aggregations