use of mage.abilities.SpellAbility in project mage by magefree.
the class FeedingGroundsEffect method applies.
@Override
public boolean applies(Ability abilityToModify, Ability source, Game game) {
if (abilityToModify instanceof SpellAbility) {
Plane cPlane = game.getState().getCurrentPlane();
if (cPlane == null) {
return false;
}
if (!cPlane.getPlaneType().equals(Planes.PLANE_FEEDING_GROUNDS)) {
return false;
}
Spell spell = (Spell) game.getStack().getStackObject(abilityToModify.getId());
if (spell != null) {
return filter.match(spell, game) && selectedByRuntimeData(spell, source, game);
} else {
// used at least for flashback ability because Flashback ability doesn't use stack
Card sourceCard = game.getCard(abilityToModify.getSourceId());
return filter.match(sourceCard, game) && selectedByRuntimeData(sourceCard, source, game);
}
}
return false;
}
use of mage.abilities.SpellAbility in project mage by magefree.
the class GorexTheTombshellReturnEffect method apply.
@Override
public boolean apply(Game game, Ability source, Ability abilityToModify) {
SpellAbility spellAbility = (SpellAbility) abilityToModify;
for (Cost cost : spellAbility.getCosts()) {
if (!(cost instanceof ExileXFromYourGraveCost)) {
continue;
}
if (game.inCheckPlayableState()) {
// allows to cast in getPlayable
int reduction = ((ExileXFromYourGraveCost) cost).getMaxValue(spellAbility, game);
CardUtil.adjustCost(spellAbility, reduction * 2);
} else {
// real cast
int reduction = ((ExileXFromYourGraveCost) cost).getAmount();
CardUtil.adjustCost(spellAbility, reduction * 2);
}
break;
}
return true;
}
use of mage.abilities.SpellAbility in project mage by magefree.
the class MaelstromMuseWatcher method applies.
@Override
public boolean applies(Ability abilityToModify, Ability source, Game game) {
MaelstromMuseWatcher watcher = game.getState().getWatcher(MaelstromMuseWatcher.class);
if (watcher == null) {
return false;
}
if (watcher.getCount(source.getControllerId()) > spellsCast) {
// only one use
discard();
return false;
}
if (!(abilityToModify instanceof SpellAbility) || !abilityToModify.isControlledBy(source.getControllerId())) {
return false;
}
Card spellCard = ((SpellAbility) abilityToModify).getCharacteristics(game);
return spellCard != null && spellCard.isInstantOrSorcery(game);
}
use of mage.abilities.SpellAbility in project mage by magefree.
the class MythUnboundCostReductionEffect method apply.
@Override
public boolean apply(Game game, Ability source, Ability abilityToModify) {
Ability spellAbility = abilityToModify;
if (spellAbility != null) {
CommanderPlaysCountWatcher watcher = game.getState().getWatcher(CommanderPlaysCountWatcher.class);
int castCount = watcher.getPlaysCount(abilityToModify.getSourceId());
CardUtil.reduceCost(spellAbility, castCount);
return true;
}
return false;
}
use of mage.abilities.SpellAbility in project mage by magefree.
the class AlternativeCostSourceAbility method askToActivateAlternativeCosts.
@Override
public boolean askToActivateAlternativeCosts(Ability ability, Game game) {
if (ability != null && AbilityType.SPELL == ability.getAbilityType()) {
if (filter != null) {
Card card = game.getCard(ability.getSourceId());
if (!filter.match(card, ability.getSourceId(), ability.getControllerId(), game)) {
return false;
}
}
Player player = game.getPlayer(ability.getControllerId());
if (player != null) {
Costs<AlternativeCost2> alternativeCostsToCheck;
if (dynamicCost != null) {
alternativeCostsToCheck = new CostsImpl<>();
alternativeCostsToCheck.add(convertToAlternativeCost(dynamicCost.getCost(ability, game)));
} else {
alternativeCostsToCheck = this.alternateCosts;
}
String costChoiceText;
if (dynamicCost != null) {
costChoiceText = dynamicCost.getText(ability, game);
} else {
costChoiceText = alternativeCostsToCheck.isEmpty() ? "Cast without paying its mana cost?" : "Pay alternative costs? (" + alternativeCostsToCheck.getText() + ')';
}
if (alternativeCostsToCheck.canPay(ability, ability, ability.getControllerId(), game) && player.chooseUse(Outcome.Benefit, costChoiceText, this, game)) {
if (ability instanceof SpellAbility) {
ability.getManaCostsToPay().removeIf(manaCost -> manaCost instanceof VariableCost);
CardUtil.reduceCost((SpellAbility) ability, ability.getManaCosts());
} else {
ability.getManaCostsToPay().clear();
}
if (!onlyMana) {
ability.getCosts().clear();
}
for (AlternativeCost2 alternateCost : alternativeCostsToCheck) {
alternateCost.activate();
for (Iterator it = ((Costs) alternateCost).iterator(); it.hasNext(); ) {
Cost costDetailed = (Cost) it.next();
if (costDetailed instanceof ManaCost) {
ability.getManaCostsToPay().add((ManaCost) costDetailed.copy());
} else if (costDetailed != null) {
ability.getCosts().add(costDetailed.copy());
}
}
}
// save activated status
game.getState().setValue(getActivatedKey(ability), Boolean.TRUE);
} else {
return false;
}
} else {
return false;
}
}
return isActivated(ability, game);
}
Aggregations