[BLB] fix implementation of Clement, the Worrywort

This commit is contained in:
theelk801 2025-06-03 22:04:51 -04:00
parent 8633a100fb
commit d4f1d42c3e

View file

@ -15,30 +15,38 @@ import mage.abilities.mana.builder.ConditionalManaBuilder;
import mage.abilities.mana.conditional.CreatureCastManaCondition;
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.Filter;
import mage.filter.FilterPermanent;
import mage.filter.StaticFilters;
import mage.filter.common.FilterControlledCreaturePermanent;
import mage.filter.predicate.mageobject.ManaValuePredicate;
import mage.filter.predicate.ObjectSourcePlayer;
import mage.filter.predicate.ObjectSourcePlayerPredicate;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.permanent.Permanent;
import mage.target.TargetPermanent;
import mage.util.CardUtil;
import java.util.UUID;
/**
*
* @author earchip94
*/
public final class ClementTheWorrywort extends CardImpl {
private static final FilterPermanent filter = new FilterControlledCreaturePermanent("creature you control with lesser mana value");
private static final FilterPermanent frogFilter = new FilterPermanent(SubType.FROG, "Frogs");
static {
filter.add(ClementTheWorrywortPredicate.instance);
}
public ClementTheWorrywort(UUID ownerId, CardSetInfo setInfo) {
super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{1}{G}{U}");
this.supertype.add(SuperType.LEGENDARY);
this.subtype.add(SubType.FROG);
this.subtype.add(SubType.DRUID);
@ -49,12 +57,16 @@ public final class ClementTheWorrywort extends CardImpl {
this.addAbility(VigilanceAbility.getInstance());
// Whenever Clement, the Worrywort or another creature you control enters, return up to one target creature you control with lesser mana value to its owner's hand.
this.addAbility(new ClementTheWorrywortTriggeredAbility());
Ability ability = new EntersBattlefieldThisOrAnotherTriggeredAbility(
new ReturnToHandTargetEffect(), StaticFilters.FILTER_CONTROLLED_CREATURE, false, false
);
ability.addTarget(new TargetPermanent(0, 1, filter));
this.addAbility(ability);
// Frogs you control have "{T}: Add {G} or {U}. Spend this mana only to cast a creature spell."
Ability gMana = new ConditionalColoredManaAbility(new TapSourceCost(), Mana.GreenMana(1), new ClementTheWorrywortManaBuilder());
Ability bMana = new ConditionalColoredManaAbility(new TapSourceCost(), Mana.BlueMana(1), new ClementTheWorrywortManaBuilder());
Ability ability = new SimpleStaticAbility(
ability = new SimpleStaticAbility(
new GainAbilityControlledEffect(gMana, Duration.WhileOnBattlefield, frogFilter, false)
.setText("Frogs you control have \"{T}: Add {G} or {U}.")
);
@ -75,40 +87,17 @@ public final class ClementTheWorrywort extends CardImpl {
}
}
class ClementTheWorrywortTriggeredAbility extends EntersBattlefieldThisOrAnotherTriggeredAbility {
ClementTheWorrywortTriggeredAbility() {
super(new ReturnToHandTargetEffect().setText("return up to one target creature you control with lesser mana value to its owner's hand"),
StaticFilters.FILTER_PERMANENT_CREATURE, false, true);
}
ClementTheWorrywortTriggeredAbility(final ClementTheWorrywortTriggeredAbility ability) {
super(ability);
}
enum ClementTheWorrywortPredicate implements ObjectSourcePlayerPredicate<Permanent> {
instance;
@Override
public ClementTheWorrywortTriggeredAbility copy() {
return new ClementTheWorrywortTriggeredAbility(this);
public boolean apply(ObjectSourcePlayer<Permanent> input, Game game) {
return CardUtil.getEffectValueFromAbility(
input.getSource(), "permanentEnteringBattlefield", Permanent.class
)
.filter(permanent -> input.getObject().getManaValue() < permanent.getManaValue())
.isPresent();
}
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (super.checkTrigger(event, game)) {
this.getTargets().clear();
Permanent permanent = game.getPermanent(event.getTargetId());
if (permanent == null) {
return false;
}
int mv = permanent.getManaValue();
FilterControlledCreaturePermanent filter =
new FilterControlledCreaturePermanent("creature you control with mana value " + (mv - 1) + " or less");
filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, mv));
this.addTarget(new TargetPermanent(0,1, filter));
return true;
}
return false;
}
}
class ClementTheWorrywortConditionalMana extends ConditionalMana {