Fix for issue #88 (incomplete handling of unattach effects caused by zone changes of permanents).

This commit is contained in:
LevelX2 2012-12-30 11:09:06 +01:00
parent efaeef0cde
commit 412577e6b4

View file

@ -1004,25 +1004,28 @@ public abstract class GameImpl<T extends GameImpl<T>> implements Game, Serializa
if (filterAura.match(perm, this)) {
//20091005 - 704.5n, 702.14c
if (perm.getAttachedTo() == null) {
if (perm.moveToZone(Zone.GRAVEYARD, null, this, false))
if (perm.moveToZone(Zone.GRAVEYARD, null, this, false)) {
somethingHappened = true;
}
}
else {
Target target = perm.getSpellAbility().getTargets().get(0);
if (target instanceof TargetPermanent) {
Permanent attachedTo = getPermanent(perm.getAttachedTo());
if (attachedTo == null) {
if (perm.moveToZone(Zone.GRAVEYARD, null, this, false))
if (attachedTo == null || !attachedTo.getAttachments().contains(perm.getId())) {
if (perm.moveToZone(Zone.GRAVEYARD, null, this, false)) {
somethingHappened = true;
}
}
else {
Filter auraFilter = perm.getSpellAbility().getTargets().get(0).getFilter();
if (!auraFilter.match(attachedTo, this) || attachedTo.hasProtectionFrom(perm, this)) {
if (perm.moveToZone(Zone.GRAVEYARD, null, this, false))
if (perm.moveToZone(Zone.GRAVEYARD, null, this, false)) {
somethingHappened = true;
}
}
}
}
else if (target instanceof TargetPlayer) {
Player attachedTo = getPlayer(perm.getAttachedTo());
if (attachedTo == null) {
@ -1039,33 +1042,35 @@ public abstract class GameImpl<T extends GameImpl<T>> implements Game, Serializa
}
}
}
if (filterLegendary.match(perm, this))
if (filterLegendary.match(perm, this)) {
legendary.add(perm);
}
if (filterEquipment.match(perm, this)) {
//20091005 - 704.5p, 702.14d
if (perm.getAttachedTo() != null) {
Permanent creature = getPermanent(perm.getAttachedTo());
if (creature == null) {
if (creature == null || !creature.getAttachments().contains(perm.getId())) {
perm.attachTo(null, this);
}
else if (!creature.getCardType().contains(CardType.CREATURE) || creature.hasProtectionFrom(perm, this)) {
if (creature.removeAttachment(perm.getId(), this))
} else if (!creature.getCardType().contains(CardType.CREATURE) || creature.hasProtectionFrom(perm, this)) {
if (creature.removeAttachment(perm.getId(), this)) {
somethingHappened = true;
}
}
}
}
if (filterFortification.match(perm, this)) {
if (perm.getAttachedTo() != null) {
Permanent land = getPermanent(perm.getAttachedTo());
if (land == null) {
if (land == null || !land.getAttachments().contains(perm.getId())) {
perm.attachTo(null, this);
}
else if (!land.getCardType().contains(CardType.LAND) || land.hasProtectionFrom(perm, this)) {
if (land.removeAttachment(perm.getId(), this))
if (land.removeAttachment(perm.getId(), this)) {
somethingHappened = true;
}
}
}
}
//20091005 - 704.5q
if (perm.getAttachments().size() > 0) {
for (UUID attachmentId: perm.getAttachments()) {