rework some effects to use CardUtil::getEffectValueFromAbility

This commit is contained in:
theelk801 2025-06-04 08:35:08 -04:00
parent bccbb2ee8e
commit 562bd9ffeb
14 changed files with 74 additions and 132 deletions

View file

@ -20,6 +20,7 @@ import mage.game.Game;
import mage.game.permanent.Permanent; import mage.game.permanent.Permanent;
import mage.players.Player; import mage.players.Player;
import mage.target.TargetPermanent; import mage.target.TargetPermanent;
import mage.util.CardUtil;
import java.util.UUID; import java.util.UUID;
@ -67,14 +68,11 @@ enum BladeOfSharedSoulsPredicate implements ObjectSourcePlayerPredicate<Permanen
@Override @Override
public boolean apply(ObjectSourcePlayer<Permanent> input, Game game) { public boolean apply(ObjectSourcePlayer<Permanent> input, Game game) {
return input.getSource() return !CardUtil
.getEffects() .getEffectValueFromAbility(input.getSource(), "attachedPermanent", Permanent.class)
.stream() .filter(permanent -> input.getObject().getId().equals(permanent.getId())
.map(effect -> effect.getValue("attachedPermanent")) && input.getObject().getZoneChangeCounter(game) == permanent.getZoneChangeCounter(game))
.filter(Permanent.class::isInstance) .isPresent();
.map(Permanent.class::cast)
.noneMatch(permanent -> input.getObject().getId().equals(permanent.getId())
&& input.getObject().getZoneChangeCounter(game) == permanent.getZoneChangeCounter(game));
} }
} }
@ -141,4 +139,4 @@ class BladeOfSharedSoulsCopyEffect extends CopyEffect {
} }
return false; return false;
} }
} }

View file

@ -14,7 +14,6 @@ import mage.cards.CardSetInfo;
import mage.constants.*; import mage.constants.*;
import mage.filter.FilterPermanent; import mage.filter.FilterPermanent;
import mage.filter.StaticFilters; import mage.filter.StaticFilters;
import mage.filter.common.FilterControlledCreaturePermanent;
import mage.filter.common.FilterCreaturePermanent; import mage.filter.common.FilterCreaturePermanent;
import mage.filter.predicate.ObjectSourcePlayer; import mage.filter.predicate.ObjectSourcePlayer;
import mage.filter.predicate.ObjectSourcePlayerPredicate; import mage.filter.predicate.ObjectSourcePlayerPredicate;
@ -23,10 +22,10 @@ import mage.game.events.GameEvent;
import mage.game.permanent.Permanent; import mage.game.permanent.Permanent;
import mage.game.permanent.token.TreasureToken; import mage.game.permanent.token.TreasureToken;
import mage.target.TargetPermanent; import mage.target.TargetPermanent;
import mage.util.CardUtil;
import mage.watchers.Watcher; import mage.watchers.Watcher;
import java.util.HashSet; import java.util.HashSet;
import java.util.Objects;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
@ -75,19 +74,11 @@ enum BoxingRingPredicate implements ObjectSourcePlayerPredicate<Permanent> {
@Override @Override
public boolean apply(ObjectSourcePlayer<Permanent> input, Game game) { public boolean apply(ObjectSourcePlayer<Permanent> input, Game game) {
return input return CardUtil
.getObject() .getEffectValueFromAbility(input.getSource(), "permanentEnteringBattlefield", Permanent.class)
.getManaValue()
== input
.getSource()
.getEffects()
.stream()
.map(effect -> effect.getValue("permanentEnteringBattlefield"))
.map(Permanent.class::cast)
.filter(Objects::nonNull)
.map(MageObject::getManaValue) .map(MageObject::getManaValue)
.findFirst() .filter(x -> x == input.getObject().getManaValue())
.orElse(-1); .isPresent();
} }
} }

View file

@ -162,12 +162,10 @@ class DranaAndLinvalaManaEffect extends AsThoughEffectImpl implements AsThoughMa
return CardUtil return CardUtil
.getMainCardId(game, objectId) .getMainCardId(game, objectId)
.equals(source.getSourceId()) .equals(source.getSourceId())
&& affectedAbility && CardUtil
.getEffects() .getEffectValueFromAbility(
.stream() affectedAbility, "dranaLinvalaFlag", Boolean.class
.map(effect -> effect.getValue("dranaLinvalaFlag")) ).orElse(false)
.filter(Boolean.class::isInstance)
.anyMatch(Boolean.class::cast)
&& source.isControlledBy(playerId); && source.isControlledBy(playerId);
} }

View file

@ -1,6 +1,7 @@
package mage.cards.d; package mage.cards.d;
import mage.MageInt; import mage.MageInt;
import mage.MageObject;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.common.DiesCreatureTriggeredAbility; import mage.abilities.common.DiesCreatureTriggeredAbility;
import mage.abilities.common.EntersBattlefieldTriggeredAbility; import mage.abilities.common.EntersBattlefieldTriggeredAbility;
@ -19,6 +20,7 @@ import mage.counters.CounterType;
import mage.game.Game; import mage.game.Game;
import mage.game.permanent.Permanent; import mage.game.permanent.Permanent;
import mage.game.permanent.token.GuenhwyvarToken; import mage.game.permanent.token.GuenhwyvarToken;
import mage.util.CardUtil;
import java.util.UUID; import java.util.UUID;
@ -66,15 +68,13 @@ enum DrizztDoUrdenCondition implements Condition {
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
Permanent sourcePermanent = source.getSourcePermanentOrLKI(game); Permanent sourcePermanent = source.getSourcePermanentOrLKI(game);
Permanent creatureDied = (Permanent) source
.getEffects()
.stream()
.map(effect -> effect.getValue("creatureDied"))
.findFirst()
.orElse(null);
return sourcePermanent != null return sourcePermanent != null
&& creatureDied != null && CardUtil
&& creatureDied.getPower().getValue() > sourcePermanent.getPower().getValue(); .getEffectValueFromAbility(source, "creatureDied", Permanent.class)
.map(MageObject::getPower)
.map(MageInt::getValue)
.filter(x -> sourcePermanent.getPower().getValue() < x)
.isPresent();
} }
} }

View file

@ -75,15 +75,11 @@ enum EshkiTemursRoarCondition implements Condition {
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
return CardUtil.castStream( return CardUtil
source.getEffects() .getEffectValueFromAbility(source, "spellCast", Spell.class)
.stream()
.map(effect -> effect.getValue("spellCast")),
Spell.class
)
.findFirst()
.map(Spell::getPower) .map(Spell::getPower)
.map(MageInt::getValue) .map(MageInt::getValue)
.orElse(0) >= amount; .filter(x -> x >= amount)
.isPresent();
} }
} }

View file

@ -16,8 +16,8 @@ import mage.constants.Duration;
import mage.constants.SubType; import mage.constants.SubType;
import mage.constants.SuperType; import mage.constants.SuperType;
import mage.game.Game; import mage.game.Game;
import mage.util.CardUtil;
import java.util.Objects;
import java.util.UUID; import java.util.UUID;
/** /**
@ -65,12 +65,9 @@ enum FaridehDevilsChosenCondition implements Condition {
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
return source return CardUtil
.getEffects() .getEffectValueFromAbility(source, "maxDieRoll", Integer.class)
.stream() .filter(x -> x >= 10)
.map(effect -> effect.getValue("maxDieRoll")) .isPresent();
.filter(Objects::nonNull)
.mapToInt(Integer.class::cast)
.anyMatch(x -> x >= 10);
} }
} }

View file

@ -70,19 +70,10 @@ enum HammerheadTyrantPredicate implements ObjectSourcePlayerPredicate<Permanent>
@Override @Override
public boolean apply(ObjectSourcePlayer<Permanent> input, Game game) { public boolean apply(ObjectSourcePlayer<Permanent> input, Game game) {
return input return CardUtil
.getObject() .getEffectValueFromAbility(input.getSource(), "spellCast", Spell.class)
.getManaValue()
<= CardUtil
.castStream(
input.getSource()
.getEffects()
.stream()
.map(effect -> effect.getValue("spellCast")),
Spell.class
)
.findFirst()
.map(Spell::getManaValue) .map(Spell::getManaValue)
.orElse(-1); .filter(x -> x >= input.getObject().getManaValue())
.isPresent();
} }
} }

View file

@ -2,6 +2,7 @@ package mage.cards.j;
import mage.MageInt; import mage.MageInt;
import mage.Mana; import mage.Mana;
import mage.ObjectColor;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.common.SpellCastControllerTriggeredAbility; import mage.abilities.common.SpellCastControllerTriggeredAbility;
import mage.abilities.condition.Condition; import mage.abilities.condition.Condition;
@ -23,7 +24,6 @@ import mage.game.permanent.token.AngelVigilanceToken;
import mage.game.stack.Spell; import mage.game.stack.Spell;
import mage.util.CardUtil; import mage.util.CardUtil;
import java.util.Objects;
import java.util.UUID; import java.util.UUID;
/** /**
@ -72,15 +72,12 @@ enum JensonCarthalionDruidExileCondition implements Condition {
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
return CardUtil.castStream( return CardUtil
source.getEffects() .getEffectValueFromAbility(source, "spellCast", Spell.class)
.stream() .map(spell -> spell.getColor(game))
.map(effect -> effect.getValue("spellCast")), .map(ObjectColor::getColorCount)
Spell.class .filter(x -> x >= 5)
).findAny() .isPresent();
.filter(Objects::nonNull)
.map(spell -> spell.getColor(game).getColorCount())
.orElse(0) >= 5;
} }
@Override @Override

View file

@ -16,8 +16,8 @@ import mage.filter.predicate.ObjectSourcePlayerPredicate;
import mage.game.Game; import mage.game.Game;
import mage.game.permanent.Permanent; import mage.game.permanent.Permanent;
import mage.target.common.TargetCardInYourGraveyard; import mage.target.common.TargetCardInYourGraveyard;
import mage.util.CardUtil;
import java.util.Objects;
import java.util.UUID; import java.util.UUID;
/** /**
@ -59,18 +59,10 @@ enum RiveteersAscendancyPredicate implements ObjectSourcePlayerPredicate<Card> {
@Override @Override
public boolean apply(ObjectSourcePlayer<Card> input, Game game) { public boolean apply(ObjectSourcePlayer<Card> input, Game game) {
return input return CardUtil
.getObject() .getEffectValueFromAbility(input.getSource(), "sacrificedPermanent", Permanent.class)
.getManaValue() .map(MageObject::getManaValue)
< input .filter(x -> input.getObject().getManaValue() < x)
.getSource() .isPresent();
.getEffects()
.stream()
.map(effect -> effect.getValue("sacrificedPermanent"))
.filter(Objects::nonNull)
.map(Permanent.class::cast)
.mapToInt(MageObject::getManaValue)
.max()
.orElse(0);
} }
} }

View file

@ -19,7 +19,6 @@ import mage.target.TargetPermanent;
import mage.target.common.TargetNonlandPermanent; import mage.target.common.TargetNonlandPermanent;
import mage.util.CardUtil; import mage.util.CardUtil;
import java.util.Objects;
import java.util.Optional; import java.util.Optional;
import java.util.UUID; import java.util.UUID;
@ -215,12 +214,9 @@ class SchemingFenceManaEffect extends AsThoughEffectImpl implements AsThoughMana
@Override @Override
public boolean applies(UUID objectId, Ability affectedAbility, Ability source, Game game, UUID playerId) { public boolean applies(UUID objectId, Ability affectedAbility, Ability source, Game game, UUID playerId) {
return source.isControlledBy(playerId) return source.isControlledBy(playerId)
&& affectedAbility && CardUtil.getEffectValueFromAbility(affectedAbility, "schemingFence", UUID.class)
.getEffects() .filter(source.getSourceId()::equals)
.stream() .isPresent();
.map(effect -> effect.getValue("schemingFence"))
.filter(Objects::nonNull)
.anyMatch(source.getSourceId()::equals);
} }
@Override @Override

View file

@ -14,6 +14,7 @@ import mage.counters.CounterType;
import mage.filter.StaticFilters; import mage.filter.StaticFilters;
import mage.game.Game; import mage.game.Game;
import mage.game.permanent.Permanent; import mage.game.permanent.Permanent;
import mage.util.CardUtil;
import java.util.UUID; import java.util.UUID;
@ -68,17 +69,13 @@ class SharpEyedRookieTriggeredAbility extends EntersBattlefieldAllTriggeredAbili
@Override @Override
public boolean checkInterveningIfClause(Game game) { public boolean checkInterveningIfClause(Game game) {
Permanent sourcePermanent = getSourcePermanentOrLKI(game); Permanent sourcePermanent = getSourcePermanentOrLKI(game);
Permanent permanentEntering = (Permanent) this
.getEffects()
.stream()
.map(effect -> effect.getValue("permanentEnteringBattlefield"))
.findFirst()
.orElse(null);
return sourcePermanent != null return sourcePermanent != null
&& permanentEntering != null
&& sourcePermanent.isCreature(game) && sourcePermanent.isCreature(game)
&& permanentEntering.isCreature(game) && CardUtil
&& (permanentEntering.getPower().getValue() > sourcePermanent.getPower().getValue() .getEffectValueFromAbility(this, "permanentEnteringBattlefield", Permanent.class)
|| permanentEntering.getToughness().getValue() > sourcePermanent.getToughness().getValue()); .filter(permanent -> permanent.isCreature(game))
.filter(permanent -> sourcePermanent.getPower().getValue() < permanent.getPower().getValue()
|| sourcePermanent.getToughness().getValue() < permanent.getToughness().getValue())
.isPresent();
} }
} }

View file

@ -17,8 +17,8 @@ import mage.constants.Duration;
import mage.constants.SubType; import mage.constants.SubType;
import mage.game.Game; import mage.game.Game;
import mage.game.permanent.token.custom.CreatureToken; import mage.game.permanent.token.custom.CreatureToken;
import mage.util.CardUtil;
import java.util.Objects;
import java.util.UUID; import java.util.UUID;
/** /**
@ -65,11 +65,8 @@ enum WeatherseedTotemCondition implements Condition {
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
return source return CardUtil
.getEffects() .getEffectValueFromAbility(source, "permanentWasCreature", Boolean.class)
.stream() .orElse(false);
.map(effect -> effect.getValue("permanentWasCreature"))
.filter(Objects::nonNull)
.anyMatch(Boolean.class::cast);
} }
} }

View file

@ -21,7 +21,6 @@ import mage.players.Player;
import mage.target.common.TargetControlledPermanent; import mage.target.common.TargetControlledPermanent;
import mage.util.CardUtil; import mage.util.CardUtil;
import java.util.Objects;
import java.util.UUID; import java.util.UUID;
/* /*
@ -188,13 +187,9 @@ class ConspireTriggeredAbility extends CastSourceTriggeredAbility {
return false; return false;
} }
Spell spell = game.getStack().getSpell(event.getSourceId()); Spell spell = game.getStack().getSpell(event.getSourceId());
return spell != null return spell != null && CardUtil.getEffectValueFromAbility(
&& spell spell.getSpellAbility(), "ConspireActivation" + conspireId + addedById, Boolean.class
.getSpellAbility() ).orElse(false);
.getAllEffects()
.stream()
.map(effect -> effect.getValue("ConspireActivation" + conspireId + addedById))
.anyMatch(Objects::nonNull);
} }
@Override @Override

View file

@ -10,6 +10,7 @@ import mage.filter.StaticFilters;
import mage.game.Game; import mage.game.Game;
import mage.game.events.GameEvent; import mage.game.events.GameEvent;
import mage.game.permanent.Permanent; import mage.game.permanent.Permanent;
import mage.util.CardUtil;
/** /**
* FAQ 2013/01/11 * FAQ 2013/01/11
@ -75,18 +76,14 @@ public class EvolveAbility extends EntersBattlefieldAllTriggeredAbility {
@Override @Override
public boolean checkInterveningIfClause(Game game) { public boolean checkInterveningIfClause(Game game) {
Permanent sourcePermanent = getSourcePermanentOrLKI(game); Permanent sourcePermanent = getSourcePermanentOrLKI(game);
Permanent permanentEntering = (Permanent) this
.getEffects()
.stream()
.map(effect -> effect.getValue("permanentEnteringBattlefield"))
.findFirst()
.orElse(null);
return sourcePermanent != null return sourcePermanent != null
&& permanentEntering != null
&& sourcePermanent.isCreature(game) && sourcePermanent.isCreature(game)
&& permanentEntering.isCreature(game) && CardUtil
&& (permanentEntering.getPower().getValue() > sourcePermanent.getPower().getValue() .getEffectValueFromAbility(this, "permanentEnteringBattlefield", Permanent.class)
|| permanentEntering.getToughness().getValue() > sourcePermanent.getToughness().getValue()); .filter(permanent -> permanent.isCreature(game))
.filter(permanent -> sourcePermanent.getPower().getValue() < permanent.getPower().getValue()
|| sourcePermanent.getToughness().getValue() < permanent.getToughness().getValue())
.isPresent();
} }
@Override @Override