allow attachments on players

This commit is contained in:
BetaSteward 2011-09-28 22:00:38 -04:00
parent 8bbcf05c86
commit e7165fe00b
5 changed files with 80 additions and 14 deletions

View file

@ -33,6 +33,7 @@ import mage.abilities.Ability;
import mage.abilities.effects.OneShotEffect;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.players.Player;
/**
*
@ -64,6 +65,12 @@ public class AttachEffect extends OneShotEffect<AttachEffect> {
if (permanent != null) {
return permanent.addAttachment(source.getSourceId(), game);
}
else {
Player player = game.getPlayer(source.getFirstTarget());
if (player != null) {
return player.addAttachment(source.getSourceId(), game);
}
}
return false;
}

View file

@ -64,6 +64,8 @@ import mage.abilities.common.ChancellorAbility;
import mage.abilities.mana.TriggeredManaAbility;
import mage.cards.CardsImpl;
import mage.target.Target;
import mage.target.TargetPermanent;
import mage.watchers.common.MorbidWatcher;
import org.apache.log4j.Logger;
@ -741,19 +743,35 @@ public abstract class GameImpl<T extends GameImpl<T>> implements Game, Serializa
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;
}
}
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))
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;
}
}
}
else if (target instanceof TargetPlayer) {
Player attachedTo = getPlayer(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

View file

@ -97,6 +97,7 @@ public class GameEvent {
DECLARE_BLOCKER, BLOCKER_DECLARED,
SEARCH_LIBRARY, LIBRARY_SEARCHED,
SHUFFLE_LIBRARY, LIBRARY_SHUFFLED,
ENCHANT_PLAYER, ENCHANTED_PLAYER,
//permanent events
ENTERS_THE_BATTLEFIELD,

View file

@ -239,5 +239,7 @@ public interface Player extends MageItem, Copyable<Player> {
public List<Ability> getPlayableOptions(Ability ability, Game game);
public void addCounters(Counter counter, Game game);
public List<UUID> getAttachments();
public boolean addAttachment(UUID permanentId, Game game);
public boolean removeAttachment(UUID permanentId, Game game);
}

View file

@ -108,6 +108,7 @@ public abstract class PlayerImpl<T extends PlayerImpl<T>> implements Player, Ser
protected boolean isGameUnderControl = true;
protected UUID turnController;
protected Set<UUID> playersUnderYourControl = new HashSet<UUID>();
protected List<UUID> attachments = new ArrayList<UUID>();
protected boolean topCardRevealed = false;
@ -424,6 +425,43 @@ public abstract class PlayerImpl<T extends PlayerImpl<T>> implements Player, Ser
}
@Override
public List<UUID> getAttachments() {
return attachments;
}
@Override
public boolean addAttachment(UUID permanentId, Game game) {
if (!this.attachments.contains(permanentId)) {
Permanent aura = game.getPermanent(permanentId);
if (aura != null) {
if (!game.replaceEvent(new GameEvent(GameEvent.EventType.ENCHANT_PLAYER, playerId, permanentId, aura.getControllerId()))) {
this.attachments.add(permanentId);
aura.attachTo(playerId, game);
game.fireEvent(new GameEvent(GameEvent.EventType.ENCHANTED_PLAYER, playerId, permanentId, aura.getControllerId()));
return true;
}
}
}
return false;
}
@Override
public boolean removeAttachment(UUID permanentId, Game game) {
if (this.attachments.contains(permanentId)) {
Permanent aura = game.getPermanent(permanentId);
if (aura != null) {
if (!game.replaceEvent(new GameEvent(GameEvent.EventType.UNATTACH, playerId, permanentId, aura.getControllerId()))) {
this.attachments.remove(permanentId);
aura.attachTo(null, game);
}
game.fireEvent(new GameEvent(GameEvent.EventType.UNATTACHED, playerId, permanentId, aura.getControllerId()));
return true;
}
}
return false;
}
@Override
public boolean removeFromBattlefield(Permanent permanent, Game game) {
permanent.removeFromCombat(game);
game.getBattlefield().removePermanent(permanent.getId());