mirror of
https://github.com/magefree/mage.git
synced 2025-12-22 19:41:59 -08:00
fix additional test failures
This commit is contained in:
parent
19bb4e7cd3
commit
501b7e882b
5 changed files with 45 additions and 40 deletions
|
|
@ -250,6 +250,16 @@ public interface Card extends MageObject, Ownerable {
|
||||||
|
|
||||||
List<UUID> getAttachments();
|
List<UUID> getAttachments();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param attachment can be any object: card, permanent, token
|
||||||
|
* @param source can be null for default checks like state base
|
||||||
|
* @param game
|
||||||
|
* @param silentMode - use it to ignore warning message for users (e.g. for
|
||||||
|
* checking only)
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
boolean cantBeAttachedBy(MageObject attachment, Ability source, Game game, boolean silentMode);
|
||||||
|
|
||||||
boolean addAttachment(UUID permanentId, Ability source, Game game);
|
boolean addAttachment(UUID permanentId, Ability source, Game game);
|
||||||
|
|
||||||
boolean removeAttachment(UUID permanentId, Ability source, Game game);
|
boolean removeAttachment(UUID permanentId, Ability source, Game game);
|
||||||
|
|
|
||||||
|
|
@ -7,10 +7,7 @@ import mage.abilities.*;
|
||||||
import mage.abilities.common.EntersBattlefieldTriggeredAbility;
|
import mage.abilities.common.EntersBattlefieldTriggeredAbility;
|
||||||
import mage.abilities.common.SimpleStaticAbility;
|
import mage.abilities.common.SimpleStaticAbility;
|
||||||
import mage.abilities.effects.common.continuous.HasSubtypesSourceEffect;
|
import mage.abilities.effects.common.continuous.HasSubtypesSourceEffect;
|
||||||
import mage.abilities.keyword.ChangelingAbility;
|
import mage.abilities.keyword.*;
|
||||||
import mage.abilities.keyword.FlashbackAbility;
|
|
||||||
import mage.abilities.keyword.ReconfigureAbility;
|
|
||||||
import mage.abilities.keyword.SunburstAbility;
|
|
||||||
import mage.abilities.mana.ActivatedManaAbilityImpl;
|
import mage.abilities.mana.ActivatedManaAbilityImpl;
|
||||||
import mage.cards.mock.MockableCard;
|
import mage.cards.mock.MockableCard;
|
||||||
import mage.cards.repository.PluginClassloaderRegistery;
|
import mage.cards.repository.PluginClassloaderRegistery;
|
||||||
|
|
@ -919,6 +916,32 @@ public abstract class CardImpl extends MageObjectImpl implements Card {
|
||||||
return attachments;
|
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
|
@Override
|
||||||
public boolean addAttachment(UUID permanentId, Ability source, Game game) {
|
public boolean addAttachment(UUID permanentId, Ability source, Game game) {
|
||||||
if (permanentId == null
|
if (permanentId == null
|
||||||
|
|
@ -942,6 +965,9 @@ public abstract class CardImpl extends MageObjectImpl implements Card {
|
||||||
&& (attachment.isCreature(game) || !this.isLand(game))) {
|
&& (attachment.isCreature(game) || !this.isLand(game))) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (this.cantBeAttachedBy(attachment, source, game, false)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
if (game.replaceEvent(new AttachEvent(objectId, attachment, source))) {
|
if (game.replaceEvent(new AttachEvent(objectId, attachment, source))) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -132,16 +132,6 @@ public interface Permanent extends Card, Controllable {
|
||||||
|
|
||||||
boolean hasProtectionFrom(MageObject source, Game game);
|
boolean hasProtectionFrom(MageObject source, Game game);
|
||||||
|
|
||||||
/**
|
|
||||||
* @param attachment can be any object: card, permanent, token
|
|
||||||
* @param source can be null for default checks like state base
|
|
||||||
* @param game
|
|
||||||
* @param silentMode - use it to ignore warning message for users (e.g. for
|
|
||||||
* checking only)
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
boolean cantBeAttachedBy(MageObject attachment, Ability source, Game game, boolean silentMode);
|
|
||||||
|
|
||||||
boolean wasControlledFromStartOfControllerTurn();
|
boolean wasControlledFromStartOfControllerTurn();
|
||||||
|
|
||||||
boolean hasSummoningSickness();
|
boolean hasSummoningSickness();
|
||||||
|
|
|
||||||
|
|
@ -1363,32 +1363,6 @@ public abstract class PermanentImpl extends CardImpl implements Permanent {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@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() || isControlledBy(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
|
@Override
|
||||||
public boolean destroy(Ability source, Game game) {
|
public boolean destroy(Ability source, Game game) {
|
||||||
return destroy(source, game, false);
|
return destroy(source, game, false);
|
||||||
|
|
|
||||||
|
|
@ -1204,6 +1204,11 @@ public class Spell extends StackObjectImpl implements Card {
|
||||||
throw new UnsupportedOperationException("Not supported.");
|
throw new UnsupportedOperationException("Not supported.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean cantBeAttachedBy(MageObject attachment, Ability source, Game game, boolean silentMode) {
|
||||||
|
throw new UnsupportedOperationException("Not supported.");
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean addAttachment(UUID permanentId, Ability source, Game game) {
|
public boolean addAttachment(UUID permanentId, Ability source, Game game) {
|
||||||
throw new UnsupportedOperationException("Not supported.");
|
throw new UnsupportedOperationException("Not supported.");
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue