use of mage.abilities.costs.Cost in project mage by magefree.
the class PayVariableLoyaltyCost method getMaxValue.
@Override
public int getMaxValue(Ability source, Game game) {
Permanent permanent = game.getPermanent(source.getSourceId());
if (permanent == null) {
return 0;
}
int maxValue = permanent.getCounters(game).getCount(CounterType.LOYALTY.getName());
// apply cost modification
if (source instanceof LoyaltyAbility) {
LoyaltyAbility copiedAbility = ((LoyaltyAbility) source).copy();
permanent.adjustCosts(copiedAbility, game);
game.getContinuousEffects().costModification(copiedAbility, game);
for (Cost cost : copiedAbility.getCosts()) {
if (cost instanceof PayVariableLoyaltyCost) {
maxValue += ((PayVariableLoyaltyCost) cost).getCostModification();
}
}
}
return Math.max(0, maxValue);
}
use of mage.abilities.costs.Cost in project mage by magefree.
the class RevealNinjutsuCardCost method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
Card card = game.getCard(source.getSourceId());
if (card != null) {
controller.moveCards(card, Zone.BATTLEFIELD, source, game, true, false, false, null);
Permanent permanent = game.getPermanent(source.getSourceId());
if (permanent != null) {
UUID defendingPlayerId = null;
for (Cost cost : source.getCosts()) {
if (cost instanceof ReturnAttackerToHandTargetCost) {
defendingPlayerId = ((ReturnAttackerToHandTargetCost) cost).getDefendingPlayerId();
}
}
if (defendingPlayerId != null) {
game.getCombat().addAttackerToCombat(permanent.getId(), defendingPlayerId, game);
return true;
}
}
}
return false;
}
use of mage.abilities.costs.Cost in project mage by magefree.
the class CephalidShrineEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
int count = 0;
MageObject mageObject = game.getObject(source.getSourceId());
if (mageObject != null) {
Spell spell = (Spell) game.getState().getValue("cephalidShrine" + mageObject);
if (spell != null) {
Player controller = game.getPlayer(spell.getControllerId());
if (controller != null) {
String name = spell.getName();
FilterCard filterCardName = new FilterCard();
filterCardName.add(new NamePredicate(name));
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
Player player = game.getPlayer(playerId);
if (player != null) {
count += player.getGraveyard().count(filterCardName, game);
}
}
// even if the cost is 0, we still offer
Cost cost = ManaUtil.createManaCost(count, true);
if (game.getStack().contains(spell) && cost.canPay(source, source, controller.getId(), game) && controller.chooseUse(outcome, "Pay " + cost.getText() + " to prevent countering " + spell.getName() + "?", source, game) && cost.pay(source, game, source, controller.getId(), false) && cost.isPaid()) {
return false;
} else {
game.getStack().counter(spell.getId(), source, game);
game.informPlayers(spell.getName() + " has been countered due to " + controller.getName() + " not paying " + cost.getText());
return true;
}
}
}
}
return false;
}
use of mage.abilities.costs.Cost in project mage by magefree.
the class DargoTheShipwreckerWatcher method apply.
@Override
public boolean apply(Game game, Ability source, Ability abilityToModify) {
SpellAbility spellAbility = (SpellAbility) abilityToModify;
int reduction = 0;
for (Cost cost : spellAbility.getCosts()) {
if (!(cost instanceof SacrificeXTargetCost)) {
continue;
}
if (game.inCheckPlayableState()) {
// allows to cast in getPlayable
reduction += ((SacrificeXTargetCost) cost).getMaxValue(spellAbility, game);
} else {
// real cast
reduction += ((SacrificeXTargetCost) cost).getAmount();
}
break;
}
DargoTheShipwreckerWatcher watcher = game.getState().getWatcher(DargoTheShipwreckerWatcher.class);
if (watcher != null) {
reduction += watcher.getSacCount(source.getControllerId());
}
CardUtil.adjustCost(spellAbility, reduction * 2);
return true;
}
use of mage.abilities.costs.Cost in project mage by magefree.
the class EnergyVortexEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(game.getActivePlayerId());
Permanent permanent = game.getPermanent(source.getSourceId());
if (player == null || permanent == null) {
return false;
}
int counters = permanent.getCounters(game).getCount(CounterType.VORTEX);
Cost cost = ManaUtil.createManaCost(counters, false);
if (cost.pay(source, game, source, player.getId(), false)) {
return true;
}
return player.damage(3, source.getSourceId(), source, game) > 0;
}
Aggregations