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

View file

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

View file

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

View file

@ -1,6 +1,7 @@
package mage.cards.d;
import mage.MageInt;
import mage.MageObject;
import mage.abilities.Ability;
import mage.abilities.common.DiesCreatureTriggeredAbility;
import mage.abilities.common.EntersBattlefieldTriggeredAbility;
@ -19,6 +20,7 @@ import mage.counters.CounterType;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.game.permanent.token.GuenhwyvarToken;
import mage.util.CardUtil;
import java.util.UUID;
@ -66,15 +68,13 @@ enum DrizztDoUrdenCondition implements Condition {
@Override
public boolean apply(Game game, Ability source) {
Permanent sourcePermanent = source.getSourcePermanentOrLKI(game);
Permanent creatureDied = (Permanent) source
.getEffects()
.stream()
.map(effect -> effect.getValue("creatureDied"))
.findFirst()
.orElse(null);
return sourcePermanent != null
&& creatureDied != null
&& creatureDied.getPower().getValue() > sourcePermanent.getPower().getValue();
&& CardUtil
.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
public boolean apply(Game game, Ability source) {
return CardUtil.castStream(
source.getEffects()
.stream()
.map(effect -> effect.getValue("spellCast")),
Spell.class
)
.findFirst()
return CardUtil
.getEffectValueFromAbility(source, "spellCast", Spell.class)
.map(Spell::getPower)
.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.SuperType;
import mage.game.Game;
import mage.util.CardUtil;
import java.util.Objects;
import java.util.UUID;
/**
@ -65,12 +65,9 @@ enum FaridehDevilsChosenCondition implements Condition {
@Override
public boolean apply(Game game, Ability source) {
return source
.getEffects()
.stream()
.map(effect -> effect.getValue("maxDieRoll"))
.filter(Objects::nonNull)
.mapToInt(Integer.class::cast)
.anyMatch(x -> x >= 10);
return CardUtil
.getEffectValueFromAbility(source, "maxDieRoll", Integer.class)
.filter(x -> x >= 10)
.isPresent();
}
}

View file

@ -70,19 +70,10 @@ enum HammerheadTyrantPredicate implements ObjectSourcePlayerPredicate<Permanent>
@Override
public boolean apply(ObjectSourcePlayer<Permanent> input, Game game) {
return input
.getObject()
.getManaValue()
<= CardUtil
.castStream(
input.getSource()
.getEffects()
.stream()
.map(effect -> effect.getValue("spellCast")),
Spell.class
)
.findFirst()
return CardUtil
.getEffectValueFromAbility(input.getSource(), "spellCast", Spell.class)
.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.Mana;
import mage.ObjectColor;
import mage.abilities.Ability;
import mage.abilities.common.SpellCastControllerTriggeredAbility;
import mage.abilities.condition.Condition;
@ -23,7 +24,6 @@ import mage.game.permanent.token.AngelVigilanceToken;
import mage.game.stack.Spell;
import mage.util.CardUtil;
import java.util.Objects;
import java.util.UUID;
/**
@ -72,15 +72,12 @@ enum JensonCarthalionDruidExileCondition implements Condition {
@Override
public boolean apply(Game game, Ability source) {
return CardUtil.castStream(
source.getEffects()
.stream()
.map(effect -> effect.getValue("spellCast")),
Spell.class
).findAny()
.filter(Objects::nonNull)
.map(spell -> spell.getColor(game).getColorCount())
.orElse(0) >= 5;
return CardUtil
.getEffectValueFromAbility(source, "spellCast", Spell.class)
.map(spell -> spell.getColor(game))
.map(ObjectColor::getColorCount)
.filter(x -> x >= 5)
.isPresent();
}
@Override

View file

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

View file

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

View file

@ -14,6 +14,7 @@ import mage.counters.CounterType;
import mage.filter.StaticFilters;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.util.CardUtil;
import java.util.UUID;
@ -68,17 +69,13 @@ class SharpEyedRookieTriggeredAbility extends EntersBattlefieldAllTriggeredAbili
@Override
public boolean checkInterveningIfClause(Game game) {
Permanent sourcePermanent = getSourcePermanentOrLKI(game);
Permanent permanentEntering = (Permanent) this
.getEffects()
.stream()
.map(effect -> effect.getValue("permanentEnteringBattlefield"))
.findFirst()
.orElse(null);
return sourcePermanent != null
&& permanentEntering != null
&& sourcePermanent.isCreature(game)
&& permanentEntering.isCreature(game)
&& (permanentEntering.getPower().getValue() > sourcePermanent.getPower().getValue()
|| permanentEntering.getToughness().getValue() > sourcePermanent.getToughness().getValue());
&& CardUtil
.getEffectValueFromAbility(this, "permanentEnteringBattlefield", Permanent.class)
.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.game.Game;
import mage.game.permanent.token.custom.CreatureToken;
import mage.util.CardUtil;
import java.util.Objects;
import java.util.UUID;
/**
@ -65,11 +65,8 @@ enum WeatherseedTotemCondition implements Condition {
@Override
public boolean apply(Game game, Ability source) {
return source
.getEffects()
.stream()
.map(effect -> effect.getValue("permanentWasCreature"))
.filter(Objects::nonNull)
.anyMatch(Boolean.class::cast);
return CardUtil
.getEffectValueFromAbility(source, "permanentWasCreature", Boolean.class)
.orElse(false);
}
}

View file

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

View file

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