use of mage.abilities.costs.Cost in project mage by magefree.
the class RootwaterThiefEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Player damagedPlayer = game.getPlayer(targetPointer.getFirst(game, source));
if (controller == null || damagedPlayer == null) {
return false;
}
String message = "Pay {2} to exile a card from damaged player's library?";
Cost cost = new ManaCostsImpl("{2}");
if (controller.chooseUse(Outcome.Benefit, message, source, game) && cost.pay(source, game, source, controller.getId(), false, null)) {
TargetCardInLibrary target = new TargetCardInLibrary();
if (controller.searchLibrary(target, source, game, damagedPlayer.getId())) {
if (!target.getTargets().isEmpty()) {
Card card = damagedPlayer.getLibrary().remove(target.getFirstTarget(), game);
if (card != null) {
controller.moveCardToExileWithInfo(card, null, "", source, game, Zone.LIBRARY, true);
}
}
}
damagedPlayer.shuffleLibrary(source, game);
return true;
}
return false;
}
use of mage.abilities.costs.Cost in project mage by magefree.
the class GreatestPowerCountCreatureYouControl method apply.
@Override
public boolean apply(Game game, Ability source) {
StackObject spell = game.getStack().getStackObject(targetPointer.getFirst(game, source));
if (spell != null) {
Player player = game.getPlayer(spell.getControllerId());
Player controller = game.getPlayer(source.getControllerId());
MageObject sourceObject = game.getObject(source.getSourceId());
if (player != null && controller != null && sourceObject != null) {
int maxPower = new GreatestPowerCountCreatureYouControl().calculate(game, source, this);
Cost cost = ManaUtil.createManaCost(maxPower, true);
if (player.chooseUse(Outcome.Benefit, "Pay " + cost.getText() + "? (otherwise " + spell.getName() + " will be countered)", source, game) && cost.pay(source, game, source, player.getId(), false)) {
return true;
}
game.informPlayers(sourceObject.getName() + ": cost wasn't payed - countering " + spell.getName());
return game.getStack().counter(source.getFirstTarget(), source, game);
}
}
return false;
}
use of mage.abilities.costs.Cost in project mage by magefree.
the class StenchOfEvilEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
for (Permanent land : game.getBattlefield().getAllActivePermanents(filter, game)) {
UUID landControllerId = land.getControllerId();
if (land.destroy(source, game, false)) {
Cost cost = new ManaCostsImpl("{2}");
Player landController = game.getPlayer(landControllerId);
if (landController != null && cost.canPay(source, source, landControllerId, game) && !cost.pay(source, game, source, landControllerId, false)) {
landController.damage(1, source.getSourceId(), source, game);
}
}
}
return true;
}
use of mage.abilities.costs.Cost in project mage by magefree.
the class TortureChamberEffect2 method apply.
@Override
public boolean apply(Game game, Ability source) {
int countersRemoved = 0;
for (Cost cost : source.getCosts()) {
if (cost instanceof RemoveAllCountersSourceCost) {
countersRemoved = ((RemoveAllCountersSourceCost) cost).getRemovedCounters();
}
}
Permanent permanent = game.getPermanent(source.getFirstTarget());
if (permanent != null) {
permanent.damage(countersRemoved, source.getSourceId(), source, game, false, true);
return true;
}
return false;
}
use of mage.abilities.costs.Cost in project mage by magefree.
the class TormentedThoughtsDiscardEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Player targetPlayer = game.getPlayer(getTargetPointer().getFirst(game, source));
if (controller != null && targetPlayer != null) {
int power = 0;
COSTS: for (Cost cost : source.getCosts()) {
if (cost instanceof SacrificeTargetCost) {
SacrificeTargetCost sacCost = (SacrificeTargetCost) cost;
for (Permanent permanent : sacCost.getPermanents()) {
power = permanent.getPower().getValue();
break COSTS;
}
}
}
if (power > 0) {
targetPlayer.discard(power, false, false, source, game);
}
return true;
}
return false;
}
Aggregations