mirror of
https://github.com/magefree/mage.git
synced 2025-12-24 20:41:58 -08:00
Permanents now detach all attachments when they change zones. Ready to test.
This commit is contained in:
parent
1bc022a94a
commit
e1bfd8a196
3 changed files with 76 additions and 10 deletions
39
Mage/src/main/java/mage/cards/AuraCreature.java
Normal file
39
Mage/src/main/java/mage/cards/AuraCreature.java
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
package mage.cards;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import mage.constants.CardType;
|
||||
import mage.constants.Zone;
|
||||
import mage.game.Game;
|
||||
|
||||
/**
|
||||
* A class to represent creature cards that can be auras.
|
||||
* i.e., cards with bestow and licids
|
||||
* @author kevinwshin
|
||||
*/
|
||||
public abstract class AuraCreature extends CardImpl{
|
||||
|
||||
public AuraCreature(UUID ownerId, CardSetInfo setInfo, CardType[] cardTypes, String costs) {
|
||||
super(ownerId, setInfo, cardTypes, costs);
|
||||
}
|
||||
|
||||
//unattach all attached permanents after moving to exile
|
||||
@Override
|
||||
public boolean moveToExile(UUID exileId, String name, UUID sourceId, Game game, List<UUID> appliedEffects) {
|
||||
boolean successfullyMoved = super.moveToExile(exileId, name, sourceId, game, appliedEffects);
|
||||
unattach();
|
||||
return successfullyMoved;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean moveToZone(Zone toZone, UUID sourceId, Game game, boolean flag, List<UUID> appliedEffects) {
|
||||
boolean successfullyMoved = super.moveToZone(toZone, sourceId, game, flag);
|
||||
unattach();
|
||||
return successfullyMoved;
|
||||
}
|
||||
|
||||
private void unattach() {
|
||||
//GameImpl.java:1980
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1980,10 +1980,11 @@ public abstract class GameImpl implements Game, Serializable {
|
|||
// handle bestow unattachment
|
||||
Card card = this.getCard(perm.getId());
|
||||
if (card != null && card.isCreature()) {
|
||||
UUID wasAttachedTo = perm.getAttachedTo();
|
||||
perm.attachTo(null, this);
|
||||
BestowAbility.becomeCreature(perm, this);
|
||||
fireEvent(new GameEvent(GameEvent.EventType.UNATTACHED, wasAttachedTo, perm.getId(), perm.getControllerId()));
|
||||
//TODO: cleanup
|
||||
//UUID wasAttachedTo = perm.getAttachedTo();
|
||||
//perm.attachTo(null, this);
|
||||
//BestowAbility.becomeCreature(perm, this);
|
||||
//fireEvent(new GameEvent(GameEvent.EventType.UNATTACHED, wasAttachedTo, perm.getId(), perm.getControllerId()));
|
||||
} else if (movePermanentToGraveyardWithInfo(perm)) {
|
||||
somethingHappened = true;
|
||||
}
|
||||
|
|
@ -2000,10 +2001,11 @@ public abstract class GameImpl implements Game, Serializable {
|
|||
// handle bestow unattachment
|
||||
Card card = this.getCard(perm.getId());
|
||||
if (card != null && card.isCreature()) {
|
||||
UUID wasAttachedTo = perm.getAttachedTo();
|
||||
perm.attachTo(null, this);
|
||||
BestowAbility.becomeCreature(perm, this);
|
||||
fireEvent(new GameEvent(GameEvent.EventType.UNATTACHED, wasAttachedTo, perm.getId(), perm.getControllerId()));
|
||||
//TODO: cleanup
|
||||
//UUID wasAttachedTo = perm.getAttachedTo();
|
||||
//perm.attachTo(null, this);
|
||||
//BestowAbility.becomeCreature(perm, this);
|
||||
//fireEvent(new GameEvent(GameEvent.EventType.UNATTACHED, wasAttachedTo, perm.getId(), perm.getControllerId()));
|
||||
} else if (movePermanentToGraveyardWithInfo(perm)) {
|
||||
somethingHappened = true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1437,6 +1437,26 @@ public abstract class PermanentImpl extends CardImpl implements Permanent {
|
|||
return color;
|
||||
}
|
||||
|
||||
//20180810 - 701.3d
|
||||
//If an object leaves the zone it's in, all attached permanents become unattached
|
||||
public void detachAllAttachments(Game game) {
|
||||
for(UUID attachmentId : getAttachments()) {
|
||||
Permanent attachment = game.getPermanent(attachmentId);
|
||||
Card attachmentCard = game.getCard(attachmentId);
|
||||
if(attachment != null && attachmentCard != null) {
|
||||
attachment.attachTo(null, game);
|
||||
|
||||
//make bestow cards and licids into creatures
|
||||
if(attachmentCard.isCreature()) {
|
||||
BestowAbility.becomeCreature(attachment, game);
|
||||
}
|
||||
|
||||
game.fireEvent(new GameEvent(GameEvent.EventType.UNATTACHED,
|
||||
getId(), attachment.getId(), attachment.getControllerId()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean moveToZone(Zone toZone, UUID sourceId, Game game, boolean flag, List<UUID> appliedEffects) {
|
||||
Zone fromZone = game.getState().getZone(objectId);
|
||||
|
|
@ -1449,7 +1469,9 @@ public abstract class PermanentImpl extends CardImpl implements Permanent {
|
|||
} else {
|
||||
zoneChangeInfo = new ZoneChangeInfo(event);
|
||||
}
|
||||
return ZonesHandler.moveCard(zoneChangeInfo, game);
|
||||
boolean successfullyMoved = ZonesHandler.moveCard(zoneChangeInfo, game);
|
||||
detachAllAttachments(game);
|
||||
return successfullyMoved;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
@ -1459,7 +1481,10 @@ public abstract class PermanentImpl extends CardImpl implements Permanent {
|
|||
Zone fromZone = game.getState().getZone(objectId);
|
||||
ZoneChangeEvent event = new ZoneChangeEvent(this, sourceId, ownerId, fromZone, Zone.EXILED, appliedEffects);
|
||||
ZoneChangeInfo.Exile info = new ZoneChangeInfo.Exile(event, exileId, name);
|
||||
return ZonesHandler.moveCard(info, game);
|
||||
|
||||
boolean successfullyMoved = ZonesHandler.moveCard(info, game);
|
||||
detachAllAttachments(game);
|
||||
return successfullyMoved;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue