use of mage.abilities.costs.common.SacrificeTargetCost 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.common.SacrificeTargetCost in project mage by magefree.
the class DroughtAdditionalCostEffect method apply.
@Override
public boolean apply(Game game, Ability source, Ability abilityToModify) {
int blackSymbols = abilityToModify.getManaCosts().getMana().getBlack();
TargetControlledPermanent target = new TargetControlledPermanent(blackSymbols, blackSymbols, filter, true);
target.setRequired(false);
abilityToModify.addCost(new SacrificeTargetCost(target));
return true;
}
use of mage.abilities.costs.common.SacrificeTargetCost 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);
}
use of mage.abilities.costs.common.SacrificeTargetCost in project mage by magefree.
the class FalkenrathTorturerEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
for (Cost cost : source.getCosts()) {
if (cost instanceof SacrificeTargetCost) {
Permanent sacrificedCreature = ((SacrificeTargetCost) cost).getPermanents().get(0);
Permanent sourceCreature = game.getPermanent(source.getSourceId());
if (sacrificedCreature.hasSubtype(SubType.HUMAN, game) && sourceCreature != null) {
sourceCreature.addCounters(CounterType.P1P1.createInstance(), source.getControllerId(), source, game);
return true;
}
}
}
return false;
}
use of mage.abilities.costs.common.SacrificeTargetCost in project mage by magefree.
the class EyeOfYawgmothEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
int power = 0;
for (Cost cost : source.getCosts()) {
if (cost instanceof SacrificeTargetCost && !((SacrificeTargetCost) cost).getPermanents().isEmpty()) {
power = ((SacrificeTargetCost) cost).getPermanents().get(0).getPower().getValue();
break;
}
}
if (power > 0) {
Cards cards = new CardsImpl(controller.getLibrary().getTopCards(game, power));
controller.revealCards(source, cards, game);
TargetCard target = new TargetCard(Zone.LIBRARY, new FilterCard("card to put into your hand"));
if (controller.choose(Outcome.DrawCard, cards, target, game)) {
Card card = cards.get(target.getFirstTarget(), game);
if (card != null) {
controller.moveCards(card, Zone.HAND, source, game);
cards.remove(card);
}
}
controller.moveCards(cards, Zone.EXILED, source, game);
}
return true;
}
Aggregations