use of mage.abilities.costs.Cost in project mage by magefree.
the class SpellSyphonEffect 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());
if (player != null && controller != null) {
int amount = game.getBattlefield().count(filter, source.getSourceId(), controller.getId(), game);
if (amount == 0) {
game.informPlayers("Spell Syphon: no blue permanents in controller's battlefield.");
} else {
Cost cost = ManaUtil.createManaCost(amount, false);
if (!cost.pay(source, game, source, spell.getControllerId(), false)) {
game.informPlayers("Spell Syphon: cost wasn't payed - countering target spell.");
return game.getStack().counter(source.getFirstTarget(), source, game);
}
}
}
}
return false;
}
use of mage.abilities.costs.Cost in project mage by magefree.
the class SwordOfTheAgesEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Set<Card> cardsToExile = new HashSet<>();
if (controller != null) {
int totalPower = 0;
Card card = game.getCard(source.getSourceId());
if (card != null) {
// consulted this on mtgjudges - regardless of what zone they end up in after sac, the creature cards and Sword will be moved to exile (unless there's another replacement effect for exiling them)
cardsToExile.add(card);
}
for (Cost cost : source.getCosts()) {
// Sword of the Ages doesn't count itself for total damage if it's a creature: http://www.mtgsalvation.com/forums/the-game/commander-edh/202963-sword-of-the-ages
if (cost instanceof SacrificeTargetCost) {
for (Permanent permanent : ((SacrificeTargetCost) cost).getPermanents()) {
totalPower += permanent.getPower().getValue();
Card permanentCard = game.getCard(permanent.getId());
if (permanentCard != null) {
cardsToExile.add(permanentCard);
}
}
}
}
if (totalPower > 0) {
Player player = game.getPlayer(this.getTargetPointer().getFirst(game, source));
if (player != null) {
player.damage(totalPower, source.getSourceId(), source, game);
} else {
Permanent creature = game.getPermanent(this.getTargetPointer().getFirst(game, source));
if (creature != null) {
creature.damage(totalPower, source.getSourceId(), source, game, false, true);
}
}
}
return controller.moveCards(cardsToExile, Zone.EXILED, source, game);
}
return false;
}
use of mage.abilities.costs.Cost in project mage by magefree.
the class YasharnImplacableEarthEffect method applies.
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
boolean canTargetLand = true;
Permanent permanent = game.getPermanentOrLKIBattlefield(event.getSourceId());
if (event.getType() == GameEvent.EventType.ACTIVATE_ABILITY || event.getType() == GameEvent.EventType.CAST_SPELL) {
if (event.getType() == GameEvent.EventType.ACTIVATE_ABILITY) {
if (permanent == null) {
return false;
}
}
Optional<Ability> ability = game.getAbility(event.getTargetId(), event.getSourceId());
for (Cost cost : ability.get().getCosts()) {
if (cost instanceof PayLifeCost || cost instanceof PayVariableLifeCost) {
// can't pay with life
return true;
}
if (cost instanceof SacrificeSourceCost && !permanent.isLand()) {
return true;
}
if (cost instanceof SacrificeTargetCost) {
SacrificeTargetCost sacrificeCost = (SacrificeTargetCost) cost;
Filter filter = sacrificeCost.getTargets().get(0).getFilter();
for (Object predicate : filter.getPredicates()) {
if (predicate instanceof CardType.CardTypePredicate) {
if (!predicate.toString().equals("CardType(Land)")) {
canTargetLand = false;
}
}
}
// must be nonland target
return !canTargetLand;
}
if (cost instanceof SacrificeAllCost) {
SacrificeAllCost sacrificeAllCost = (SacrificeAllCost) cost;
Filter filter = sacrificeAllCost.getTargets().get(0).getFilter();
for (Object predicate : filter.getPredicates()) {
if (predicate instanceof CardType.CardTypePredicate) {
if (!predicate.toString().equals("CardType(Land)")) {
canTargetLand = false;
}
}
}
// must be nonland target
return !canTargetLand;
}
if (cost instanceof SacrificeAttachedCost) {
SacrificeAttachedCost sacrificeAllCost = (SacrificeAttachedCost) cost;
Filter filter = sacrificeAllCost.getTargets().get(0).getFilter();
for (Object predicate : filter.getPredicates()) {
if (predicate instanceof CardType.CardTypePredicate) {
if (!predicate.toString().equals("CardType(Land)")) {
canTargetLand = false;
}
}
}
// must be nonland target
return !canTargetLand;
}
if (cost instanceof SacrificeAttachmentCost) {
SacrificeAttachmentCost sacrificeAllCost = (SacrificeAttachmentCost) cost;
Filter filter = sacrificeAllCost.getTargets().get(0).getFilter();
for (Object predicate : filter.getPredicates()) {
if (predicate instanceof CardType.CardTypePredicate) {
if (!predicate.toString().equals("CardType(Land)")) {
canTargetLand = false;
}
}
}
// must be nonland target
return !canTargetLand;
}
if (cost instanceof SacrificeXTargetCost) {
SacrificeXTargetCost sacrificeCost = (SacrificeXTargetCost) cost;
Filter filter = sacrificeCost.getFilter();
for (Object predicate : filter.getPredicates()) {
if (predicate instanceof CardType.CardTypePredicate) {
if (!predicate.toString().equals("CardType(Land)")) {
canTargetLand = false;
}
}
}
// must be nonland target
return !canTargetLand;
}
}
}
return false;
}
use of mage.abilities.costs.Cost in project mage by magefree.
the class PayCostToAttackBlockEffectImpl method replaceEvent.
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
ManaCosts attackBlockManaTax = getManaCostToPay(event, source, game);
if (attackBlockManaTax != null) {
return handleManaCosts(attackBlockManaTax.copy(), event, source, game);
}
Cost attackBlockOtherTax = getOtherCostToPay(event, source, game);
if (attackBlockOtherTax != null) {
return handleOtherCosts(attackBlockOtherTax.copy(), event, source, game);
}
return false;
}
use of mage.abilities.costs.Cost in project mage by magefree.
the class EndemicPlagueEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
Permanent permanent = null;
for (Cost cost : source.getCosts()) {
if (cost instanceof SacrificeTargetCost && !((SacrificeTargetCost) cost).getPermanents().isEmpty()) {
permanent = ((SacrificeTargetCost) cost).getPermanents().get(0);
break;
}
}
if (permanent == null) {
return false;
}
FilterCreaturePermanent filter = new FilterCreaturePermanent();
filter.add(new SharesCreatureTypePredicate(permanent));
return new DestroyAllEffect(filter, true).apply(game, source);
}
Aggregations