Fixed double triggering. Fixed Issue 86.

This commit is contained in:
magenoxx 2011-06-26 19:18:43 +04:00
parent e8dc1b659c
commit 5e79f51f1d
2 changed files with 19 additions and 12 deletions

View file

@ -163,16 +163,18 @@ class NecroticPlagueEffect2 extends OneShotEffect<NecroticPlagueEffect2> {
Player controller = game.getPlayer(source.getControllerId()); Player controller = game.getPlayer(source.getControllerId());
if (controller != null) { if (controller != null) {
TargetCreaturePermanent target = new TargetCreaturePermanent(filter); TargetCreaturePermanent target = new TargetCreaturePermanent(filter);
if (controller.choose(Outcome.Detriment, target, game)) { if (target.canChoose(source.getControllerId(), game)) {
Card card = game.getCard(cardId); if (controller.choose(Outcome.Detriment, target, game)) {
if (card != null) { Card card = game.getCard(cardId);
card.putOntoBattlefield(game, Zone.GRAVEYARD, source.getId(), source.getControllerId()); if (card != null) {
Permanent permanent = game.getPermanent(target.getFirstTarget()); card.putOntoBattlefield(game, Zone.GRAVEYARD, source.getId(), source.getControllerId());
if (permanent != null) { Permanent permanent = game.getPermanent(target.getFirstTarget());
return permanent.addAttachment(cardId, game); if (permanent != null) {
} return permanent.addAttachment(cardId, game);
} }
} }
}
}
} }
return false; return false;
} }

View file

@ -45,6 +45,8 @@ import mage.game.events.GameEvent;
import mage.game.events.ZoneChangeEvent; import mage.game.events.ZoneChangeEvent;
import mage.players.Player; import mage.players.Player;
import javax.swing.*;
/** /**
* *
* @author BetaSteward_at_googlemail.com * @author BetaSteward_at_googlemail.com
@ -118,16 +120,19 @@ public class PermanentCard extends PermanentImpl<PermanentCard> {
// we only want to trigger abilities that are not on the underlying card ie. have been added by another effect // we only want to trigger abilities that are not on the underlying card ie. have been added by another effect
// or we want to trigger abilities that only trigger on leaving the battlefield // or we want to trigger abilities that only trigger on leaving the battlefield
// card abilities will get triggered later when the card hits the new zone // card abilities will get triggered later when the card hits the new zone
Card card = game.getCard(objectId).copy(); List<UUID> triggered = new ArrayList<UUID>();
Card card = game.getCard(objectId).copy();
for (TriggeredAbility ability: abilities.getTriggeredAbilities(event.getFromZone())) { for (TriggeredAbility ability: abilities.getTriggeredAbilities(event.getFromZone())) {
if (!card.getAbilities().containsKey(ability.getId())) { if (!card.getAbilities().containsKey(ability.getId())) {
if (ability.checkTrigger(event, game)) { if (ability.checkTrigger(event, game)) {
triggered.add(ability.getId());
ability.trigger(game, controllerId); ability.trigger(game, controllerId);
} }
} else if (ability instanceof ZoneChangeTriggeredAbility && event.getFromZone() == Zone.BATTLEFIELD) { } else if (ability instanceof ZoneChangeTriggeredAbility && event.getFromZone() == Zone.BATTLEFIELD) {
ZoneChangeTriggeredAbility zcAbility = (ZoneChangeTriggeredAbility)ability; ZoneChangeTriggeredAbility zcAbility = (ZoneChangeTriggeredAbility)ability;
if (zcAbility.getToZone() == null) { if (zcAbility.getToZone() == null) {
if (ability.checkTrigger(event, game)) { if (ability.checkTrigger(event, game)) {
triggered.add(ability.getId());
ability.trigger(game, controllerId); ability.trigger(game, controllerId);
} }
} }
@ -135,7 +140,7 @@ public class PermanentCard extends PermanentImpl<PermanentCard> {
} }
for (TriggeredAbility ability: abilities.getTriggeredAbilities(event.getToZone())) { for (TriggeredAbility ability: abilities.getTriggeredAbilities(event.getToZone())) {
if (!card.getAbilities().containsKey(ability.getId())) { if (!card.getAbilities().containsKey(ability.getId())) {
if (ability.checkTrigger(event, game)) { if (!triggered.contains(ability.getId()) && ability.checkTrigger(event, game)) {
ability.trigger(game, controllerId); ability.trigger(game, controllerId);
} }
} }