fix additional test failures

This commit is contained in:
theelk801 2025-05-23 18:30:23 -04:00
parent 19bb4e7cd3
commit 501b7e882b
5 changed files with 45 additions and 40 deletions

View file

@ -7,10 +7,7 @@ import mage.abilities.*;
import mage.abilities.common.EntersBattlefieldTriggeredAbility;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.effects.common.continuous.HasSubtypesSourceEffect;
import mage.abilities.keyword.ChangelingAbility;
import mage.abilities.keyword.FlashbackAbility;
import mage.abilities.keyword.ReconfigureAbility;
import mage.abilities.keyword.SunburstAbility;
import mage.abilities.keyword.*;
import mage.abilities.mana.ActivatedManaAbilityImpl;
import mage.cards.mock.MockableCard;
import mage.cards.repository.PluginClassloaderRegistery;
@ -919,6 +916,32 @@ public abstract class CardImpl extends MageObjectImpl implements Card {
return attachments;
}
@Override
public boolean cantBeAttachedBy(MageObject attachment, Ability source, Game game, boolean silentMode) {
for (ProtectionAbility ability : this.getAbilities(game).getProtectionAbilities()) {
if ((!attachment.hasSubtype(SubType.AURA, game) || ability.removesAuras())
&& (!attachment.hasSubtype(SubType.EQUIPMENT, game) || ability.removesEquipment())
&& !attachment.getId().equals(ability.getAuraIdNotToBeRemoved())
&& !ability.canTarget(attachment, game)) {
return !ability.getDoesntRemoveControlled() || Objects.equals(getControllerOrOwnerId(), game.getControllerId(attachment.getId()));
}
}
boolean canAttach = true;
Permanent attachmentPermanent = game.getPermanent(attachment.getId());
// If attachment is an aura, ensures this permanent can still be legally enchanted, according to the enchantment's Enchant ability
if (attachment.hasSubtype(SubType.AURA, game)
&& attachmentPermanent != null
&& attachmentPermanent.getSpellAbility() != null
&& !attachmentPermanent.getSpellAbility().getTargets().isEmpty()) {
// Line of code below functionally gets the target of the aura's Enchant ability, then compares to this permanent. Enchant improperly implemented in XMage, see #9583
// Note: stillLegalTarget used exclusively to account for Dream Leash. Can be made canTarget in the event that that card is rewritten (and "stillLegalTarget" removed from TargetImpl).
canAttach = attachmentPermanent.getSpellAbility().getTargets().get(0).copy().withNotTarget(true).stillLegalTarget(attachmentPermanent.getControllerId(), this.getId(), source, game);
}
return !canAttach || game.getContinuousEffects().preventedByRuleModification(new StayAttachedEvent(this.getId(), attachment.getId(), source), null, game, silentMode);
}
@Override
public boolean addAttachment(UUID permanentId, Ability source, Game game) {
if (permanentId == null
@ -942,6 +965,9 @@ public abstract class CardImpl extends MageObjectImpl implements Card {
&& (attachment.isCreature(game) || !this.isLand(game))) {
return false;
}
if (this.cantBeAttachedBy(attachment, source, game, false)) {
return false;
}
if (game.replaceEvent(new AttachEvent(objectId, attachment, source))) {
return false;
}