fixed issue with attachments not removing themselves from creatures when moved to another creature

This commit is contained in:
BetaSteward 2011-01-10 22:04:15 -05:00
parent 547afe573c
commit 86025f4748
3 changed files with 13 additions and 8 deletions

View file

@ -29,7 +29,6 @@
package mage.game;
import mage.counters.CounterType;
import mage.game.match.MatchType;
import java.io.IOException;
import mage.game.stack.SpellStack;
import java.io.Serializable;
@ -390,7 +389,7 @@ public abstract class GameImpl<T extends GameImpl<T>> implements Game, Serializa
for (Card card: player.getHand().getCards(this)) {
if (card.getAbilities().containsKey(LeylineAbility.getInstance().getId())) {
if (player.chooseUse(Outcome.PutCardInPlay, "Do you wish to put " + card.getName() + " on the battlefield?", this)) {
player.getHand().remove(card);
player.getHand().remove(card.getId());
card.putOntoBattlefield(this, Zone.HAND, null, player.getId());
}
}
@ -673,7 +672,7 @@ public abstract class GameImpl<T extends GameImpl<T>> implements Game, Serializa
if (perm.getAttachedTo() != null) {
Permanent creature = getPermanent(perm.getAttachedTo());
if (creature == null) {
perm.attachTo(null);
perm.attachTo(null, this);
}
else if (!creature.getCardType().contains(CardType.CREATURE) || creature.hasProtectionFrom(perm)) {
if (creature.removeAttachment(perm.getId(), this))
@ -685,7 +684,7 @@ public abstract class GameImpl<T extends GameImpl<T>> implements Game, Serializa
if (perm.getAttachedTo() != null) {
Permanent land = getPermanent(perm.getAttachedTo());
if (land == null) {
perm.attachTo(null);
perm.attachTo(null, this);
}
else if (!land.getCardType().contains(CardType.LAND) || land.hasProtectionFrom(perm)) {
if (land.removeAttachment(perm.getId(), this))

View file

@ -60,7 +60,7 @@ public interface Permanent extends Card {
public List<UUID> getAttachments();
public UUID getAttachedTo();
public void attachTo(UUID permanentId);
public void attachTo(UUID permanentId, Game game);
public boolean addAttachment(UUID permanentId, Game game);
public boolean removeAttachment(UUID permanentId, Game game);

View file

@ -365,7 +365,7 @@ public abstract class PermanentImpl<T extends PermanentImpl<T>> extends CardImpl
this.attachments.add(permanentId);
Permanent attachment = game.getPermanent(permanentId);
if (attachment != null) {
attachment.attachTo(objectId);
attachment.attachTo(objectId, game);
game.fireEvent(new GameEvent(GameEvent.EventType.ATTACHED, objectId, permanentId, controllerId));
return true;
}
@ -381,7 +381,7 @@ public abstract class PermanentImpl<T extends PermanentImpl<T>> extends CardImpl
this.attachments.remove(permanentId);
Permanent attachment = game.getPermanent(permanentId);
if (attachment != null) {
attachment.attachTo(null);
attachment.attachTo(null, game);
}
game.fireEvent(new GameEvent(GameEvent.EventType.UNATTACHED, objectId, permanentId, controllerId));
return true;
@ -396,7 +396,13 @@ public abstract class PermanentImpl<T extends PermanentImpl<T>> extends CardImpl
}
@Override
public void attachTo(UUID permanentId) {
public void attachTo(UUID permanentId, Game game) {
if (this.attachedTo != null) {
Permanent attachment = game.getPermanent(this.attachedTo);
if (attachment != null) {
attachment.removeAttachment(this.objectId, game);
}
}
this.attachedTo = permanentId;
}