new common predicate class

ManaValueLessThanOrEqualToSourcePowerPredicate
This commit is contained in:
xenohedron 2024-01-10 23:55:43 -05:00
parent a19103a958
commit 60ad6c2325
6 changed files with 41 additions and 103 deletions

View file

@ -1,27 +1,21 @@
package mage.cards.a;
import mage.MageInt;
import mage.MageObject;
import mage.abilities.Ability;
import mage.abilities.common.EntersBattlefieldTriggeredAbility;
import mage.abilities.condition.common.CastFromEverywhereSourceCondition;
import mage.abilities.decorator.ConditionalInterveningIfTriggeredAbility;
import mage.abilities.effects.common.ExileTargetCardCopyAndCastEffect;
import mage.abilities.keyword.PrototypeAbility;
import mage.cards.Card;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.SubType;
import mage.filter.FilterCard;
import mage.filter.common.FilterInstantOrSorceryCard;
import mage.filter.predicate.ObjectSourcePlayer;
import mage.filter.predicate.ObjectSourcePlayerPredicate;
import mage.game.Game;
import mage.filter.predicate.card.ManaValueLessThanOrEqualToSourcePowerPredicate;
import mage.target.common.TargetCardInYourGraveyard;
import java.util.Objects;
import java.util.Optional;
import java.util.UUID;
/**
@ -34,7 +28,7 @@ public final class ArcaneProxy extends CardImpl {
);
static {
filter.add(ArcaneProxyPredicate.instance);
filter.add(ManaValueLessThanOrEqualToSourcePowerPredicate.instance);
}
public ArcaneProxy(UUID ownerId, CardSetInfo setInfo) {
@ -67,18 +61,3 @@ public final class ArcaneProxy extends CardImpl {
return new ArcaneProxy(this);
}
}
enum ArcaneProxyPredicate implements ObjectSourcePlayerPredicate<Card> {
instance;
@Override
public boolean apply(ObjectSourcePlayer<Card> input, Game game) {
return Optional
.ofNullable(input.getSource().getSourcePermanentOrLKI(game))
.filter(Objects::nonNull)
.map(MageObject::getPower)
.map(MageInt::getValue)
.map(p -> input.getObject().getManaValue() <= p)
.orElse(false);
}
}

View file

@ -1,7 +1,6 @@
package mage.cards.a;
import mage.MageInt;
import mage.MageObject;
import mage.abilities.common.AttacksTriggeredAbility;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.condition.Condition;
@ -9,7 +8,6 @@ import mage.abilities.condition.common.PermanentsOnTheBattlefieldCondition;
import mage.abilities.decorator.ConditionalRestrictionEffect;
import mage.abilities.effects.common.LookLibraryAndPickControllerEffect;
import mage.abilities.effects.common.combat.CantBeBlockedSourceEffect;
import mage.cards.Card;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.*;
@ -17,13 +15,9 @@ import mage.filter.FilterCard;
import mage.filter.FilterPermanent;
import mage.filter.common.FilterArtifactCard;
import mage.filter.common.FilterControlledArtifactPermanent;
import mage.filter.predicate.ObjectSourcePlayer;
import mage.filter.predicate.ObjectSourcePlayerPredicate;
import mage.filter.predicate.card.ManaValueLessThanOrEqualToSourcePowerPredicate;
import mage.filter.predicate.permanent.DefendingPlayerControlsSourceAttackingPredicate;
import mage.game.Game;
import java.util.Objects;
import java.util.Optional;
import java.util.UUID;
/**
@ -37,7 +31,7 @@ public final class AyeshaTanakaArmorer extends CardImpl {
private static final FilterPermanent filter2 = new FilterControlledArtifactPermanent();
static {
filter.add(AyeshaTanakaArmorerPredicate.instance);
filter.add(ManaValueLessThanOrEqualToSourcePowerPredicate.instance);
filter2.add(DefendingPlayerControlsSourceAttackingPredicate.instance);
}
@ -74,18 +68,3 @@ public final class AyeshaTanakaArmorer extends CardImpl {
return new AyeshaTanakaArmorer(this);
}
}
enum AyeshaTanakaArmorerPredicate implements ObjectSourcePlayerPredicate<Card> {
instance;
@Override
public boolean apply(ObjectSourcePlayer<Card> input, Game game) {
return Optional
.ofNullable(input.getSource().getSourcePermanentOrLKI(game))
.filter(Objects::nonNull)
.map(MageObject::getPower)
.map(MageInt::getValue)
.map(p -> input.getObject().getManaValue() <= p)
.orElse(false);
}
}

View file

@ -1,6 +1,5 @@
package mage.cards.c;
import java.util.UUID;
import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.TriggeredAbilityImpl;
@ -8,21 +7,23 @@ import mage.abilities.common.AttacksTriggeredAbility;
import mage.abilities.effects.common.GainLifeEffect;
import mage.abilities.effects.common.ReturnFromGraveyardToBattlefieldTargetEffect;
import mage.abilities.effects.common.counter.AddCountersSourceEffect;
import mage.cards.Card;
import mage.constants.*;
import mage.abilities.keyword.FlyingAbility;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.SubType;
import mage.constants.SuperType;
import mage.constants.Zone;
import mage.counters.CounterType;
import mage.filter.FilterCard;
import mage.filter.common.FilterPermanentCard;
import mage.filter.predicate.ObjectSourcePlayer;
import mage.filter.predicate.ObjectSourcePlayerPredicate;
import mage.filter.predicate.card.ManaValueLessThanOrEqualToSourcePowerPredicate;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.permanent.Permanent;
import mage.target.common.TargetCardInYourGraveyard;
import java.util.UUID;
/**
*
* @author skaspels
@ -32,7 +33,7 @@ public final class CarmenCruelSkymarcher extends CardImpl {
private static final FilterCard filter = new FilterPermanentCard(
"permanent card with mana value less than or equal to {this}'s power from your graveyard");
static {
filter.add(CarmenPredicate.instance);
filter.add(ManaValueLessThanOrEqualToSourcePowerPredicate.instance);
}
public CarmenCruelSkymarcher(UUID ownerId, CardSetInfo setInfo) {
super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{3}{W}{B}");
@ -96,13 +97,3 @@ class CarmenTriggeredAbility extends TriggeredAbilityImpl {
return "Whenever a player sacrifices a permanent, put a +1/+1 counter on {this} and you gain 1 life.";
}
}
enum CarmenPredicate implements ObjectSourcePlayerPredicate<Card> {
instance;
@Override
public boolean apply(ObjectSourcePlayer<Card> input, Game game) {
Permanent sourcePermanent = input.getSource().getSourcePermanentOrLKI(game);
return sourcePermanent != null
&& input.getObject().getManaValue() <= sourcePermanent.getPower().getValue();
}
}

View file

@ -5,17 +5,13 @@ import mage.abilities.Ability;
import mage.abilities.common.AttacksTriggeredAbility;
import mage.abilities.effects.common.MayCastTargetThenExileEffect;
import mage.abilities.keyword.TrampleAbility;
import mage.cards.Card;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.SubType;
import mage.filter.FilterCard;
import mage.filter.common.FilterInstantOrSorceryCard;
import mage.filter.predicate.ObjectSourcePlayer;
import mage.filter.predicate.ObjectSourcePlayerPredicate;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.filter.predicate.card.ManaValueLessThanOrEqualToSourcePowerPredicate;
import mage.target.common.TargetCardInYourGraveyard;
import java.util.UUID;
@ -30,7 +26,7 @@ public final class DreadhordeArcanist extends CardImpl {
);
static {
filter.add(DreadhordeArcanistPredicate.instance);
filter.add(ManaValueLessThanOrEqualToSourcePowerPredicate.instance);
}
public DreadhordeArcanist(UUID ownerId, CardSetInfo setInfo) {
@ -60,14 +56,3 @@ public final class DreadhordeArcanist extends CardImpl {
return new DreadhordeArcanist(this);
}
}
enum DreadhordeArcanistPredicate implements ObjectSourcePlayerPredicate<Card> {
instance;
@Override
public boolean apply(ObjectSourcePlayer<Card> input, Game game) {
Permanent sourcePermanent = input.getSource().getSourcePermanentOrLKI(game);
return sourcePermanent != null
&& input.getObject().getManaValue() <= sourcePermanent.getPower().getValue();
}
}

View file

@ -1,14 +1,12 @@
package mage.cards.g;
import mage.MageInt;
import mage.MageObject;
import mage.abilities.Ability;
import mage.abilities.common.DiesSourceTriggeredAbility;
import mage.abilities.common.DrawNthCardTriggeredAbility;
import mage.abilities.effects.common.ReturnFromGraveyardToBattlefieldTargetEffect;
import mage.abilities.effects.common.counter.AddCountersSourceEffect;
import mage.abilities.keyword.FlyingAbility;
import mage.cards.Card;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
@ -16,14 +14,10 @@ import mage.constants.SubType;
import mage.counters.CounterType;
import mage.filter.FilterCard;
import mage.filter.common.FilterCreatureCard;
import mage.filter.predicate.ObjectSourcePlayer;
import mage.filter.predicate.ObjectSourcePlayerPredicate;
import mage.filter.predicate.card.ManaValueLessThanOrEqualToSourcePowerPredicate;
import mage.filter.predicate.mageobject.AnotherPredicate;
import mage.game.Game;
import mage.target.common.TargetCardInYourGraveyard;
import java.util.Objects;
import java.util.Optional;
import java.util.UUID;
/**
@ -37,7 +31,7 @@ public final class GurglingAnointer extends CardImpl {
static {
filter.add(AnotherPredicate.instance);
filter.add(GurglingAnointerPredicate.instance);
filter.add(ManaValueLessThanOrEqualToSourcePowerPredicate.instance);
}
public GurglingAnointer(UUID ownerId, CardSetInfo setInfo) {
@ -69,18 +63,3 @@ public final class GurglingAnointer extends CardImpl {
return new GurglingAnointer(this);
}
}
enum GurglingAnointerPredicate implements ObjectSourcePlayerPredicate<Card> {
instance;
@Override
public boolean apply(ObjectSourcePlayer<Card> input, Game game) {
return Optional
.ofNullable(input.getSource().getSourcePermanentOrLKI(game))
.filter(Objects::nonNull)
.map(MageObject::getPower)
.map(MageInt::getValue)
.map(p -> input.getObject().getManaValue() <= p)
.orElse(false);
}
}

View file

@ -0,0 +1,25 @@
package mage.filter.predicate.card;
import mage.cards.Card;
import mage.filter.predicate.ObjectSourcePlayer;
import mage.filter.predicate.ObjectSourcePlayerPredicate;
import mage.game.Game;
import mage.game.permanent.Permanent;
/**
* @author xenohedron
*/
public enum ManaValueLessThanOrEqualToSourcePowerPredicate implements ObjectSourcePlayerPredicate<Card> {
instance;
@Override
public boolean apply(ObjectSourcePlayer<Card> input, Game game) {
Permanent sourcePermanent = input.getSource().getSourcePermanentOrLKI(game);
return sourcePermanent != null && input.getObject().getManaValue() <= sourcePermanent.getPower().getValue();
}
@Override
public String toString() {
return "mana value less than or equal to {this}'s power";
}
}