if (perm.moveToZone(Zone.GRAVEYARD, null, this, false))
somethingHappened = true;
}
else {
//TODO: handle player auras
Permanent attachedTo = getPermanent(perm.getAttachedTo());
if (attachedTo == null) {
if (perm.moveToZone(Zone.GRAVEYARD, null, this, false))
somethingHappened = true;
}
else {
Filter auraFilter = perm.getSpellAbility().getTargets().get(0).getFilter();
if (!auraFilter.match(attachedTo) || attachedTo.hasProtectionFrom(perm)) {
if (perm.moveToZone(Zone.GRAVEYARD, null, this, false))
somethingHappened = true;
}
}
}
}
//20091005 - 704.5k, 801.12
if (getBattlefield().countAll(filterLegendary) > 1) { //don't bother checking if less than 2 legends in play
for (Permanent legend: getBattlefield().getAllActivePermanents(filterLegendary)) {
filterLegendName.getName().clear();
filterLegendName.getName().add(legend.getName());
if (getBattlefield().count(filterLegendName, legend.getControllerId(), this) > 1) {
for (Permanent dupLegend: getBattlefield().getActivePermanents(filterLegendName, legend.getControllerId(), this)) {
dupLegend.moveToZone(Zone.GRAVEYARD, null, this, false);
}
return true;
}
}
}
//20091005 - 704.5p, 702.14d
for (Permanent perm: getBattlefield().getAllActivePermanents(filterEquipment)) {
if (perm.getAttachedTo() != null) {
Permanent creature = getPermanent(perm.getAttachedTo());
if (creature == null) {
perm.attachTo(null);
}
else if (!creature.getCardType().contains(CardType.CREATURE) || creature.hasProtectionFrom(perm)) {
if (creature.removeAttachment(perm.getId(), this))
somethingHappened = true;
}
}
}
for (Permanent perm: getBattlefield().getAllActivePermanents(filterFortification)) {
if (perm.getAttachedTo() != null) {
Permanent land = getPermanent(perm.getAttachedTo());
if (land == null) {
perm.attachTo(null);
}
else if (!land.getCardType().contains(CardType.LAND) || land.hasProtectionFrom(perm)) {
if (land.removeAttachment(perm.getId(), this))
somethingHappened = true;
}
}
}
//20091005 - 704.5q
for (Permanent perm: getBattlefield().getAllActivePermanents()) {
if (perm.getAttachments().size() > 0) {
for (UUID attachmentId: perm.getAttachments()) {
Permanent attachment = getPermanent(attachmentId);
if (attachment != null && !(attachment.getSubtype().contains("Aura") ||
attachment.getSubtype().contains("Equipment") ||
attachment.getSubtype().contains("Fortification"))) {
if (perm.removeAttachment(id, this))
return true;
}
}
}