use of mage.abilities.SpellAbility in project mage by magefree.
the class CardCanBeCastPredicate method apply.
@Override
public boolean apply(Card input, Game game) {
SpellAbility ability = input.getSpellAbility().copy();
ability.setControllerId(controllerId);
input.adjustTargets(ability, game);
return ability.canChooseTarget(game, controllerId);
}
use of mage.abilities.SpellAbility in project mage by magefree.
the class OfferingCostReductionEffect method applies.
@Override
public boolean applies(Ability abilityToModify, Ability source, Game game) {
if (game.inCheckPlayableState()) {
// Cost modifaction does not work correctly for checking available spells
return false;
}
if (abilityToModify.getSourceId().equals(source.getSourceId()) && abilityToModify instanceof SpellAbility) {
Card card = game.getCard(source.getSourceId());
if (card != null) {
Object object = game.getState().getValue("offering_Id_" + card.getId());
if (object != null && object.equals(this.activationId) && getTargetPointer().getFirst(game, source) != null) {
return true;
}
}
// to target to offer, no correct activation ID this effect is no longer valid
this.discard();
}
return false;
}
use of mage.abilities.SpellAbility in project mage by magefree.
the class ProwlAbility method askToActivateAlternativeCosts.
@Override
public boolean askToActivateAlternativeCosts(Ability ability, Game game) {
if (ability instanceof SpellAbility) {
Player player = game.getPlayer(ability.getControllerId());
if (player == null) {
return false;
}
if (ProwlCondition.instance.apply(game, ability)) {
this.resetProwl();
for (AlternativeCost2 prowlCost : prowlCosts) {
if (prowlCost.canPay(ability, this, ability.getControllerId(), game) && player.chooseUse(Outcome.Benefit, "Cast for " + PROWL_KEYWORD + " cost " + prowlCost.getText(true) + " ?", ability, game)) {
prowlCost.activate();
ability.getManaCostsToPay().clear();
ability.getCosts().clear();
for (Iterator it = ((Costs) prowlCost).iterator(); it.hasNext(); ) {
Cost cost = (Cost) it.next();
if (cost instanceof ManaCostsImpl) {
ability.getManaCostsToPay().add((ManaCostsImpl) cost.copy());
} else {
ability.getCosts().add(cost.copy());
}
}
}
}
}
}
return isActivated(ability, game);
}
use of mage.abilities.SpellAbility in project mage by magefree.
the class KickerAbility method addOptionalAdditionalCosts.
@Override
public void addOptionalAdditionalCosts(Ability ability, Game game) {
if (ability instanceof SpellAbility) {
Player player = game.getPlayer(ability.getControllerId());
if (player != null) {
this.resetKicker();
for (OptionalAdditionalCost kickerCost : kickerCosts) {
boolean again = true;
while (player.canRespond() && again) {
String times = "";
if (kickerCost.isRepeatable()) {
int activatedCount = getKickedCounterStrict(game, ability, kickerCost.getText(true));
times = (activatedCount + 1) + (activatedCount == 0 ? " time " : " times ");
}
// canPay checks only single mana available, not total mana usage
if (kickerCost.canPay(ability, this, ability.getControllerId(), game) && player.chooseUse(/*Outcome.Benefit*/
Outcome.AIDontUseIt, "Pay " + times + kickerCost.getText(false) + " ?", ability, game)) {
this.activateKicker(kickerCost, ability, game);
if (kickerCost instanceof Costs) {
// as multiple costs
for (Iterator itKickerCost = ((Costs) kickerCost).iterator(); itKickerCost.hasNext(); ) {
Object kickerCostObject = itKickerCost.next();
if ((kickerCostObject instanceof Costs)) {
for (@SuppressWarnings("unchecked") Iterator<Cost> itDetails = ((Costs) kickerCostObject).iterator(); itDetails.hasNext(); ) {
addKickerCostsToAbility(itDetails.next(), ability, game);
}
} else {
addKickerCostsToAbility((Cost) kickerCostObject, ability, game);
}
}
} else {
// as single cost
addKickerCostsToAbility(kickerCost, ability, game);
}
again = kickerCost.isRepeatable();
} else {
again = false;
}
}
}
}
}
}
use of mage.abilities.SpellAbility 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;
}
Aggregations