From 48d139393d0f9e97a56527333954ae8775dea0f6 Mon Sep 17 00:00:00 2001 From: Evan Kranzler Date: Thu, 24 Feb 2022 17:26:22 -0500 Subject: [PATCH] [FUT] reworked Daybreak Coronet --- .../src/mage/cards/d/DaybreakCoronet.java | 92 +++++++++---------- Mage/src/main/java/mage/game/GameImpl.java | 4 +- 2 files changed, 47 insertions(+), 49 deletions(-) diff --git a/Mage.Sets/src/mage/cards/d/DaybreakCoronet.java b/Mage.Sets/src/mage/cards/d/DaybreakCoronet.java index 2d0b71ed7c..3e7d04984a 100644 --- a/Mage.Sets/src/mage/cards/d/DaybreakCoronet.java +++ b/Mage.Sets/src/mage/cards/d/DaybreakCoronet.java @@ -1,12 +1,7 @@ - package mage.cards.d; -import java.util.LinkedList; -import java.util.List; -import java.util.UUID; import mage.abilities.Ability; import mage.abilities.common.SimpleStaticAbility; -import mage.abilities.effects.Effect; import mage.abilities.effects.common.AttachEffect; import mage.abilities.effects.common.continuous.BoostEnchantedEffect; import mage.abilities.effects.common.continuous.GainAbilityAttachedEffect; @@ -17,44 +12,54 @@ import mage.abilities.keyword.VigilanceAbility; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.*; +import mage.filter.FilterPermanent; import mage.filter.common.FilterCreaturePermanent; -import mage.filter.predicate.Predicate; +import mage.filter.predicate.ObjectSourcePlayer; +import mage.filter.predicate.ObjectSourcePlayerPredicate; import mage.game.Game; import mage.game.permanent.Permanent; import mage.target.TargetPermanent; -import mage.target.common.TargetCreaturePermanent; + +import java.util.LinkedList; +import java.util.List; +import java.util.Objects; +import java.util.UUID; /** - * * @author jeffwadsworth */ public final class DaybreakCoronet extends CardImpl { - + + private static final FilterPermanent filter + = new FilterCreaturePermanent("creature with another Aura attached to it"); + + static { + filter.add(AuraAttachedPredicate.instance); + } + public DaybreakCoronet(UUID ownerId, CardSetInfo setInfo) { - super(ownerId,setInfo,new CardType[]{CardType.ENCHANTMENT},"{W}{W}"); + super(ownerId, setInfo, new CardType[]{CardType.ENCHANTMENT}, "{W}{W}"); this.subtype.add(SubType.AURA); - // Enchant creature with another Aura attached to it - FilterCreaturePermanent filter = new FilterCreaturePermanent("creature with another Aura attached to it."); - filter.add(new AuraAttachedPredicate(this.getId())); - TargetPermanent auraTarget = new TargetCreaturePermanent(filter); + TargetPermanent auraTarget = new TargetPermanent(filter); this.getSpellAbility().addTarget(auraTarget); this.getSpellAbility().addEffect(new AttachEffect(Outcome.BoostCreature)); - Ability ability = new EnchantAbility(auraTarget.getTargetName()); - this.addAbility(ability); - + this.addAbility(new EnchantAbility(auraTarget.getTargetName())); + // Enchanted creature gets +3/+3 and has first strike, vigilance, and lifelink. - ability = new SimpleStaticAbility(Zone.BATTLEFIELD, new BoostEnchantedEffect(3, 3, Duration.WhileOnBattlefield)); - Effect effect = new GainAbilityAttachedEffect(FirstStrikeAbility.getInstance(), AttachmentType.AURA); - effect.setText("and has first strike"); - ability.addEffect(effect); - effect = new GainAbilityAttachedEffect(VigilanceAbility.getInstance(), AttachmentType.AURA); - effect.setText(", vigilance"); - ability.addEffect(effect); - effect = new GainAbilityAttachedEffect(LifelinkAbility.getInstance(), AttachmentType.AURA); - effect.setText(", and lifelink"); - ability.addEffect(effect); + Ability ability = new SimpleStaticAbility(new BoostEnchantedEffect( + 3, 3, Duration.WhileOnBattlefield + )); + ability.addEffect(new GainAbilityAttachedEffect( + FirstStrikeAbility.getInstance(), AttachmentType.AURA + ).setText("and has first strike")); + ability.addEffect(new GainAbilityAttachedEffect( + VigilanceAbility.getInstance(), AttachmentType.AURA + ).setText(", vigilance")); + ability.addEffect(new GainAbilityAttachedEffect( + LifelinkAbility.getInstance(), AttachmentType.AURA + ).setText(", and lifelink")); this.addAbility(ability); } @@ -68,28 +73,21 @@ public final class DaybreakCoronet extends CardImpl { } } -class AuraAttachedPredicate implements Predicate { - - private final UUID ownId; - - public AuraAttachedPredicate(UUID ownId) { - this.ownId = ownId; - } +enum AuraAttachedPredicate implements ObjectSourcePlayerPredicate { + instance; @Override - public boolean apply(Permanent input, Game game) { - List attachments = new LinkedList(); - attachments.addAll(input.getAttachments()); - for (UUID uuid : attachments) { - if (!uuid.equals(ownId)) { - Permanent attachment = game.getPermanent(uuid); - if (attachment != null - && attachment.hasSubtype(SubType.AURA, game)) { - return true; - } - } - } - return false; + public boolean apply(ObjectSourcePlayer input, Game game) { + List attachments = new LinkedList<>(); + attachments.addAll(input.getObject().getAttachments()); + return input + .getObject() + .getAttachments() + .stream() + .filter(uuid -> !uuid.equals(input.getSourceId())) + .map(game::getPermanent) + .filter(Objects::nonNull) + .anyMatch(permanent -> permanent.hasSubtype(SubType.AURA, game)); } @Override diff --git a/Mage/src/main/java/mage/game/GameImpl.java b/Mage/src/main/java/mage/game/GameImpl.java index 4d188c997c..eb84945b56 100644 --- a/Mage/src/main/java/mage/game/GameImpl.java +++ b/Mage/src/main/java/mage/game/GameImpl.java @@ -2386,8 +2386,8 @@ public abstract class GameImpl implements Game { } } else { Filter auraFilter = spellAbility.getTargets().get(0).getFilter(); - if (auraFilter instanceof FilterControlledPermanent) { - if (!((FilterControlledPermanent) auraFilter).match(attachedTo, perm.getId(), perm.getControllerId(), this) + if (auraFilter instanceof FilterPermanent) { + if (!((FilterPermanent) auraFilter).match(attachedTo, perm.getId(), perm.getControllerId(), this) || attachedTo.cantBeAttachedBy(perm, null, this, true)) { if (movePermanentToGraveyardWithInfo(perm)) { somethingHappened = true;