fixed Ongoing Investigation trigger (#4052)

This commit is contained in:
Evan Kranzler 2017-09-25 10:10:00 -04:00
parent 70c50656dd
commit 954ebd1652
2 changed files with 20 additions and 32 deletions

View file

@ -27,15 +27,14 @@
*/ */
package mage.cards.o; package mage.cards.o;
import java.util.HashSet; import java.util.ArrayList;
import java.util.Set; import java.util.List;
import java.util.UUID; import java.util.UUID;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.TriggeredAbilityImpl; import mage.abilities.TriggeredAbilityImpl;
import mage.abilities.common.SimpleActivatedAbility; import mage.abilities.common.SimpleActivatedAbility;
import mage.abilities.costs.common.ExileFromGraveCost; import mage.abilities.costs.common.ExileFromGraveCost;
import mage.abilities.costs.mana.ManaCostsImpl; import mage.abilities.costs.mana.ManaCostsImpl;
import mage.abilities.effects.Effect;
import mage.abilities.effects.common.GainLifeEffect; import mage.abilities.effects.common.GainLifeEffect;
import mage.abilities.effects.keyword.InvestigateEffect; import mage.abilities.effects.keyword.InvestigateEffect;
import mage.cards.CardImpl; import mage.cards.CardImpl;
@ -46,7 +45,6 @@ import mage.filter.common.FilterCreatureCard;
import mage.game.Game; import mage.game.Game;
import mage.game.events.DamagedPlayerEvent; import mage.game.events.DamagedPlayerEvent;
import mage.game.events.GameEvent; import mage.game.events.GameEvent;
import mage.game.events.GameEvent.EventType;
import mage.game.permanent.Permanent; import mage.game.permanent.Permanent;
import mage.target.common.TargetCardInYourGraveyard; import mage.target.common.TargetCardInYourGraveyard;
@ -57,7 +55,7 @@ import mage.target.common.TargetCardInYourGraveyard;
public class OngoingInvestigation extends CardImpl { public class OngoingInvestigation extends CardImpl {
public OngoingInvestigation(UUID ownerId, CardSetInfo setInfo) { public OngoingInvestigation(UUID ownerId, CardSetInfo setInfo) {
super(ownerId,setInfo,new CardType[]{CardType.ENCHANTMENT},"{1}{U}"); super(ownerId, setInfo, new CardType[]{CardType.ENCHANTMENT}, "{1}{U}");
// Whenever one or more creatures you control deal combat damage to a player, investigate. // Whenever one or more creatures you control deal combat damage to a player, investigate.
this.addAbility(new OngoingInvestigationTriggeredAbility()); this.addAbility(new OngoingInvestigationTriggeredAbility());
@ -81,8 +79,7 @@ public class OngoingInvestigation extends CardImpl {
class OngoingInvestigationTriggeredAbility extends TriggeredAbilityImpl { class OngoingInvestigationTriggeredAbility extends TriggeredAbilityImpl {
private boolean madeDamage = false; List<UUID> damagedPlayerIds = new ArrayList<>();
private Set<UUID> damagedPlayers = new HashSet<>();
public OngoingInvestigationTriggeredAbility() { public OngoingInvestigationTriggeredAbility() {
super(Zone.BATTLEFIELD, new InvestigateEffect(), false); super(Zone.BATTLEFIELD, new InvestigateEffect(), false);
@ -90,9 +87,6 @@ class OngoingInvestigationTriggeredAbility extends TriggeredAbilityImpl {
public OngoingInvestigationTriggeredAbility(final OngoingInvestigationTriggeredAbility ability) { public OngoingInvestigationTriggeredAbility(final OngoingInvestigationTriggeredAbility ability) {
super(ability); super(ability);
this.madeDamage = ability.madeDamage;
this.damagedPlayers = new HashSet<>();
this.damagedPlayers.addAll(ability.damagedPlayers);
} }
@Override @Override
@ -102,36 +96,30 @@ class OngoingInvestigationTriggeredAbility extends TriggeredAbilityImpl {
@Override @Override
public boolean checkEventType(GameEvent event, Game game) { public boolean checkEventType(GameEvent event, Game game) {
return event.getType() == EventType.DAMAGED_PLAYER || event.getType() == EventType.COMBAT_DAMAGE_STEP_POST; return event.getType() == GameEvent.EventType.DAMAGED_PLAYER
|| event.getType() == GameEvent.EventType.END_COMBAT_STEP_POST;
} }
@Override @Override
public boolean checkTrigger(GameEvent event, Game game) { public boolean checkTrigger(GameEvent event, Game game) {
if (event.getType() == EventType.DAMAGED_PLAYER) { if (event.getType() == GameEvent.EventType.DAMAGED_PLAYER) {
DamagedPlayerEvent damageEvent = (DamagedPlayerEvent) event; if (((DamagedPlayerEvent) event).isCombatDamage()) {
Permanent p = game.getPermanent(event.getSourceId()); Permanent creature = game.getPermanent(event.getSourceId());
if (damageEvent.isCombatDamage() && p != null && p.getControllerId().equals(this.getControllerId())) { if (creature != null && creature.getControllerId().equals(controllerId)
madeDamage = true; && !damagedPlayerIds.contains(event.getTargetId())) {
damagedPlayers.add(event.getPlayerId()); damagedPlayerIds.add(event.getTargetId());
return true;
}
} }
} }
if (event.getType() == EventType.COMBAT_DAMAGE_STEP_POST) { if (event.getType() == GameEvent.EventType.END_COMBAT_STEP_POST) {
if (madeDamage) { damagedPlayerIds.clear();
Set<UUID> damagedPlayersCopy = new HashSet<>();
damagedPlayersCopy.addAll(damagedPlayers);
for(Effect effect: this.getEffects()) {
effect.setValue("damagedPlayers", damagedPlayersCopy);
}
damagedPlayers.clear();
madeDamage = false;
return true;
}
} }
return false; return false;
} }
@Override @Override
public String getRule() { public String getRule() {
return "Whenever one or more creatures you control deal combat damage to a player, " + super.getRule(); return "Whenever one or more creatures you control deal combat damage to a player, investigate";
} }
} }

View file

@ -51,7 +51,7 @@ import mage.game.permanent.token.ThopterColorlessToken;
public class ThopterSpyNetwork extends CardImpl { public class ThopterSpyNetwork extends CardImpl {
public ThopterSpyNetwork(UUID ownerId, CardSetInfo setInfo) { public ThopterSpyNetwork(UUID ownerId, CardSetInfo setInfo) {
super(ownerId,setInfo,new CardType[]{CardType.ENCHANTMENT},"{2}{U}{U}"); super(ownerId, setInfo, new CardType[]{CardType.ENCHANTMENT}, "{2}{U}{U}");
// At the beginning of your upkeep, if you control an artifact, create a 1/1 colorless Thopter artifact creature token with flying. // At the beginning of your upkeep, if you control an artifact, create a 1/1 colorless Thopter artifact creature token with flying.
this.addAbility(new ThopterSpyNetworkUpkeepTriggeredAbility()); this.addAbility(new ThopterSpyNetworkUpkeepTriggeredAbility());
@ -149,6 +149,6 @@ class ThopterSpyNetworkDamageTriggeredAbility extends TriggeredAbilityImpl {
@Override @Override
public String getRule() { public String getRule() {
return "Whenever one or more artifact creatures you control deals combat damage to a player, draw a card"; return "Whenever one or more artifact creatures you control deal combat damage to a player, draw a card";
} }
} }