From 50faf41e3319523fba16d1bfd93c17e95660d8bc Mon Sep 17 00:00:00 2001 From: Evan Kranzler Date: Mon, 21 Feb 2022 21:21:08 -0500 Subject: [PATCH] a few more getId fixes --- Mage.Sets/src/mage/cards/s/SquirrelMob.java | 32 +++++------ .../cards/t/TomikDistinguishedAdvokist.java | 27 +++++----- .../src/mage/cards/v/VerdelothTheAncient.java | 54 +++++++++++++------ 3 files changed, 67 insertions(+), 46 deletions(-) diff --git a/Mage.Sets/src/mage/cards/s/SquirrelMob.java b/Mage.Sets/src/mage/cards/s/SquirrelMob.java index ecca5201dee..a0db1770d85 100644 --- a/Mage.Sets/src/mage/cards/s/SquirrelMob.java +++ b/Mage.Sets/src/mage/cards/s/SquirrelMob.java @@ -1,44 +1,44 @@ - package mage.cards.s; -import java.util.UUID; import mage.MageInt; import mage.abilities.common.SimpleStaticAbility; import mage.abilities.dynamicvalue.DynamicValue; import mage.abilities.dynamicvalue.common.PermanentsOnBattlefieldCount; -import mage.abilities.effects.Effect; import mage.abilities.effects.common.continuous.BoostSourceEffect; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; import mage.constants.Duration; import mage.constants.SubType; -import mage.constants.Zone; -import mage.filter.common.FilterCreaturePermanent; -import mage.filter.predicate.Predicates; -import mage.filter.predicate.permanent.PermanentIdPredicate; +import mage.filter.FilterPermanent; +import mage.filter.predicate.mageobject.AnotherPredicate; + +import java.util.UUID; /** - * * @author LevelX2 */ public final class SquirrelMob extends CardImpl { + private static final FilterPermanent filter = new FilterPermanent(SubType.SQUIRREL, ""); + + static { + filter.add(AnotherPredicate.instance); + } + + private static final DynamicValue xValue = new PermanentsOnBattlefieldCount(filter); + public SquirrelMob(UUID ownerId, CardSetInfo setInfo) { - super(ownerId,setInfo,new CardType[]{CardType.CREATURE},"{1}{G}{G}"); + super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{1}{G}{G}"); this.subtype.add(SubType.SQUIRREL); this.power = new MageInt(2); this.toughness = new MageInt(2); // Squirrel Mob gets +1/+1 for each other Squirrel on the battlefield. - FilterCreaturePermanent filter = new FilterCreaturePermanent("other Squirrel"); - filter.add(SubType.SQUIRREL.getPredicate()); - filter.add(Predicates.not(new PermanentIdPredicate(this.getId()))); - DynamicValue xValue = new PermanentsOnBattlefieldCount(filter); - Effect effect = new BoostSourceEffect(xValue, xValue, Duration.WhileOnBattlefield, false); - effect.setText("{this} gets +1/+1 for each other Squirrel on the battlefield"); - this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, effect)); + this.addAbility(new SimpleStaticAbility(new BoostSourceEffect( + xValue, xValue, Duration.WhileOnBattlefield, false + ).setText("{this} gets +1/+1 for each other Squirrel on the battlefield"))); } private SquirrelMob(final SquirrelMob card) { diff --git a/Mage.Sets/src/mage/cards/t/TomikDistinguishedAdvokist.java b/Mage.Sets/src/mage/cards/t/TomikDistinguishedAdvokist.java index 2250dea4f3d..6d9df04acaf 100644 --- a/Mage.Sets/src/mage/cards/t/TomikDistinguishedAdvokist.java +++ b/Mage.Sets/src/mage/cards/t/TomikDistinguishedAdvokist.java @@ -11,10 +11,10 @@ import mage.cards.Card; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.*; -import mage.filter.FilterObject; import mage.filter.FilterStackObject; import mage.filter.StaticFilters; -import mage.filter.predicate.Predicate; +import mage.filter.predicate.ObjectSourcePlayer; +import mage.filter.predicate.ObjectSourcePlayerPredicate; import mage.game.Game; import mage.game.events.GameEvent; import mage.game.permanent.Permanent; @@ -28,6 +28,12 @@ import java.util.UUID; */ public final class TomikDistinguishedAdvokist extends CardImpl { + private static final FilterStackObject filter = new FilterStackObject(); + + static { + filter.add(TargetedByOpponentsPredicate.instance); + } + public TomikDistinguishedAdvokist(UUID ownerId, CardSetInfo setInfo) { super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{W}{W}"); @@ -41,8 +47,6 @@ public final class TomikDistinguishedAdvokist extends CardImpl { this.addAbility(FlyingAbility.getInstance()); // Lands on the battlefield and land cards in graveyards can't be the targets of spells or abilities your opponents control. - FilterObject filter = new FilterStackObject(); - filter.add(new TargetedByOpponentsPredicate(this.getId())); Ability ability = new SimpleStaticAbility(new CantBeTargetedAllEffect( StaticFilters.FILTER_LANDS, filter, Duration.WhileOnBattlefield ).setText("lands on the battlefield")); @@ -63,18 +67,13 @@ public final class TomikDistinguishedAdvokist extends CardImpl { } } -class TargetedByOpponentsPredicate implements Predicate { - - private final UUID sourceId; - - public TargetedByOpponentsPredicate(UUID sourceId) { - this.sourceId = sourceId; - } +enum TargetedByOpponentsPredicate implements ObjectSourcePlayerPredicate { + instance; @Override - public boolean apply(MageObject input, Game game) { - StackObject stackObject = game.getStack().getStackObject(input.getId()); - Permanent source = game.getPermanentOrLKIBattlefield(this.sourceId); + public boolean apply(ObjectSourcePlayer input, Game game) { + StackObject stackObject = game.getStack().getStackObject(input.getObject().getId()); + Permanent source = game.getPermanentOrLKIBattlefield(input.getSourceId()); if (stackObject != null && source != null) { Player controller = game.getPlayer(source.getControllerId()); return controller != null && game.isOpponent(controller, stackObject.getControllerId()); diff --git a/Mage.Sets/src/mage/cards/v/VerdelothTheAncient.java b/Mage.Sets/src/mage/cards/v/VerdelothTheAncient.java index d8269f60b52..7e243abcc7c 100644 --- a/Mage.Sets/src/mage/cards/v/VerdelothTheAncient.java +++ b/Mage.Sets/src/mage/cards/v/VerdelothTheAncient.java @@ -1,6 +1,7 @@ package mage.cards.v; import mage.MageInt; +import mage.MageObject; import mage.abilities.common.EntersBattlefieldTriggeredAbility; import mage.abilities.common.SimpleStaticAbility; import mage.abilities.condition.common.KickedCondition; @@ -11,10 +12,15 @@ import mage.abilities.effects.common.continuous.BoostAllEffect; import mage.abilities.keyword.KickerAbility; import mage.cards.CardImpl; import mage.cards.CardSetInfo; -import mage.constants.*; +import mage.constants.CardType; +import mage.constants.Duration; +import mage.constants.SubType; +import mage.constants.SuperType; import mage.filter.common.FilterCreaturePermanent; -import mage.filter.predicate.Predicates; -import mage.filter.predicate.permanent.PermanentIdPredicate; +import mage.filter.predicate.ObjectSourcePlayer; +import mage.filter.predicate.ObjectSourcePlayerPredicate; +import mage.game.Game; +import mage.game.permanent.Permanent; import mage.game.permanent.token.SaprolingToken; import java.util.UUID; @@ -24,6 +30,13 @@ import java.util.UUID; */ public final class VerdelothTheAncient extends CardImpl { + private static final FilterCreaturePermanent filter + = new FilterCreaturePermanent("Saproling creatures and other Treefolk creatures"); + + static { + filter.add(VerdelothTheAncientPredicate.instance); + } + public VerdelothTheAncient(UUID ownerId, CardSetInfo setInfo) { super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{4}{G}{G}"); addSuperType(SuperType.LEGENDARY); @@ -36,20 +49,15 @@ public final class VerdelothTheAncient extends CardImpl { this.addAbility(new KickerAbility("{X}")); // Saproling creatures and other Treefolk creatures get +1/+1. - FilterCreaturePermanent filter = new FilterCreaturePermanent("Saproling creatures and other Treefolk creatures"); - filter.add(Predicates.or( - Predicates.and(SubType.TREEFOLK.getPredicate(), Predicates.not(new PermanentIdPredicate(this.getId()))), - SubType.SAPROLING.getPredicate()) - ); - filter.add(Predicates.not(new PermanentIdPredicate(this.getId()))); - - this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new BoostAllEffect(1, 1, Duration.WhileOnBattlefield, filter, false))); + this.addAbility(new SimpleStaticAbility(new BoostAllEffect( + 1, 1, Duration.WhileOnBattlefield, filter, false + ))); // When Verdeloth the Ancient enters the battlefield, if it was kicked, create X 1/1 green Saproling creature tokens. - EntersBattlefieldTriggeredAbility ability = new EntersBattlefieldTriggeredAbility(new CreateTokenEffect(new SaprolingToken(), GetKickerXValue.instance), false); - this.addAbility(new ConditionalInterveningIfTriggeredAbility(ability, KickedCondition.instance, - "When {this} enters the battlefield, if it was kicked, create X 1/1 green Saproling creature tokens.")); - + this.addAbility(new ConditionalInterveningIfTriggeredAbility(new EntersBattlefieldTriggeredAbility( + new CreateTokenEffect(new SaprolingToken(), GetKickerXValue.instance), false + ), KickedCondition.instance, "When {this} enters the battlefield, " + + "if it was kicked, create X 1/1 green Saproling creature tokens.")); } private VerdelothTheAncient(final VerdelothTheAncient card) { @@ -60,4 +68,18 @@ public final class VerdelothTheAncient extends CardImpl { public VerdelothTheAncient copy() { return new VerdelothTheAncient(this); } -} \ No newline at end of file +} + +enum VerdelothTheAncientPredicate implements ObjectSourcePlayerPredicate { + instance; + + @Override + public boolean apply(ObjectSourcePlayer input, Game game) { + MageObject obj = input.getObject(); + if (obj.getId().equals(input.getSourceId())) { + return obj.hasSubtype(SubType.SAPROLING, game); + } + return obj.hasSubtype(SubType.TREEFOLK, game) + || obj.hasSubtype(SubType.SAPROLING, game); + } +}