* Prowl ability - Fixed the bug, that creatures with Changeling did not count for Prowl.

This commit is contained in:
LevelX2 2013-07-01 00:08:46 +02:00
parent 093bc5e0e9
commit 71e3670d0c
2 changed files with 28 additions and 14 deletions

View file

@ -117,14 +117,12 @@ public class ProwlAbility extends StaticAbility<ProwlAbility> implements Alterna
throw new IllegalArgumentException("Params can't be null"); throw new IllegalArgumentException("Params can't be null");
} }
boolean canProwl = false; boolean canProwl = false;
if (prowlWatcher.getDamagingSubtypes(ability.getControllerId()) != null) { for (String subtype: card.getSubtype()) {
for (String subtype : prowlWatcher.getDamagingSubtypes(ability.getControllerId())) { if (prowlWatcher.hasSubtypeMadeCombatDamage(ability.getControllerId(), subtype)) {
if (card.getSubtype().contains(subtype)) {
canProwl = true; canProwl = true;
break; break;
} }
} }
}
if (canProwl) { if (canProwl) {
this.resetProwl(); this.resetProwl();
for (AlternativeCost2 prowlCost: prowlCosts) { for (AlternativeCost2 prowlCost: prowlCosts) {

View file

@ -28,11 +28,13 @@
package mage.watchers.common; package mage.watchers.common;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
import mage.abilities.keyword.ChangelingAbility;
import mage.constants.WatcherScope; import mage.constants.WatcherScope;
import mage.game.Game; import mage.game.Game;
import mage.game.events.DamagedPlayerEvent; import mage.game.events.DamagedPlayerEvent;
@ -50,6 +52,7 @@ import mage.watchers.WatcherImpl;
public class ProwlWatcher extends WatcherImpl<ProwlWatcher> { public class ProwlWatcher extends WatcherImpl<ProwlWatcher> {
private Map<UUID, Set<String>> damagingSubtypes = new HashMap<UUID, Set<String>>(); private Map<UUID, Set<String>> damagingSubtypes = new HashMap<UUID, Set<String>>();
private Set<UUID> allSubtypes = new HashSet<UUID>();
public ProwlWatcher() { public ProwlWatcher() {
super("Prowl", WatcherScope.GAME); super("Prowl", WatcherScope.GAME);
@ -73,7 +76,10 @@ public class ProwlWatcher extends WatcherImpl<ProwlWatcher> {
DamagedPlayerEvent dEvent = (DamagedPlayerEvent) event; DamagedPlayerEvent dEvent = (DamagedPlayerEvent) event;
if (dEvent.isCombatDamage()) { if (dEvent.isCombatDamage()) {
Permanent creature = game.getPermanent(dEvent.getSourceId()); Permanent creature = game.getPermanent(dEvent.getSourceId());
if (creature != null) { if (creature != null && !allSubtypes.contains(creature.getControllerId())) {
if (creature.getAbilities().containsKey(ChangelingAbility.getInstance().getId())) {
allSubtypes.add(creature.getControllerId());
} else {
Set<String> subtypes = damagingSubtypes.get(creature.getControllerId()); Set<String> subtypes = damagingSubtypes.get(creature.getControllerId());
if (subtypes == null) { if (subtypes == null) {
subtypes = new LinkedHashSet<String>(); subtypes = new LinkedHashSet<String>();
@ -84,14 +90,24 @@ public class ProwlWatcher extends WatcherImpl<ProwlWatcher> {
} }
} }
} }
}
@Override @Override
public void reset() { public void reset() {
super.reset(); super.reset();
damagingSubtypes.clear(); damagingSubtypes.clear();
allSubtypes.clear();
} }
public Set<String> getDamagingSubtypes(UUID playerId) { public boolean hasSubtypeMadeCombatDamage(UUID playerId, String subtype) {
return damagingSubtypes.get(playerId); if (allSubtypes.contains(playerId)) {
return true;
} }
Set<String> subtypes = damagingSubtypes.get(playerId);
if (subtypes != null) {
return subtypes.contains(subtype);
}
return false;
}
} }