From 86025f4748d0d50be34111d8baa42e62a13a16d6 Mon Sep 17 00:00:00 2001 From: BetaSteward Date: Mon, 10 Jan 2011 22:04:15 -0500 Subject: [PATCH] fixed issue with attachments not removing themselves from creatures when moved to another creature --- Mage/src/mage/game/GameImpl.java | 7 +++---- Mage/src/mage/game/permanent/Permanent.java | 2 +- Mage/src/mage/game/permanent/PermanentImpl.java | 12 +++++++++--- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/Mage/src/mage/game/GameImpl.java b/Mage/src/mage/game/GameImpl.java index 7ecc3c62ebf..785fcb3ab08 100644 --- a/Mage/src/mage/game/GameImpl.java +++ b/Mage/src/mage/game/GameImpl.java @@ -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> 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> 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> 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)) diff --git a/Mage/src/mage/game/permanent/Permanent.java b/Mage/src/mage/game/permanent/Permanent.java index c34de155501..e4f1a890c95 100644 --- a/Mage/src/mage/game/permanent/Permanent.java +++ b/Mage/src/mage/game/permanent/Permanent.java @@ -60,7 +60,7 @@ public interface Permanent extends Card { public List 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); diff --git a/Mage/src/mage/game/permanent/PermanentImpl.java b/Mage/src/mage/game/permanent/PermanentImpl.java index e2c88f66aec..579b2eac7ad 100644 --- a/Mage/src/mage/game/permanent/PermanentImpl.java +++ b/Mage/src/mage/game/permanent/PermanentImpl.java @@ -365,7 +365,7 @@ public abstract class PermanentImpl> 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> 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> 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; }