Fixed Spear of Heliod, Dunerider Outlaw, Whirling Dervish, Reciprocate, Wicked Akuba, Giltspire Avenger only counting damage done, if the same permanent had done the damage (i.e. it cant be selected if the creature was exiled with Cloudshift).

This commit is contained in:
LevelX2 2013-10-10 00:01:20 +02:00
parent 45c875384c
commit 0579ddc1bd
6 changed files with 51 additions and 42 deletions

View file

@ -31,13 +31,12 @@ package mage.sets.championsofkamigawa;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
import mage.constants.CardType;
import mage.constants.Rarity;
import mage.MageObject; import mage.MageObject;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.effects.common.ExileTargetEffect; import mage.abilities.effects.common.ExileTargetEffect;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.constants.CardType;
import mage.constants.Rarity;
import mage.filter.common.FilterCreaturePermanent; import mage.filter.common.FilterCreaturePermanent;
import mage.game.Game; import mage.game.Game;
import mage.game.permanent.Permanent; import mage.game.permanent.Permanent;
@ -46,7 +45,7 @@ import mage.target.common.TargetCreaturePermanent;
import mage.watchers.common.PlayerDamagedBySourceWatcher; import mage.watchers.common.PlayerDamagedBySourceWatcher;
/** /**
* @author LevelX * @author LevelX2
*/ */
public class Reciprocate extends CardImpl<Reciprocate> { public class Reciprocate extends CardImpl<Reciprocate> {
@ -84,7 +83,7 @@ class ReciprocateTarget<T extends TargetCreaturePermanent<T>> extends TargetPerm
@Override @Override
public boolean canTarget(UUID id, Ability source, Game game) { public boolean canTarget(UUID id, Ability source, Game game) {
PlayerDamagedBySourceWatcher watcher = (PlayerDamagedBySourceWatcher) game.getState().getWatchers().get("PlayerDamagedBySource",source.getControllerId()); PlayerDamagedBySourceWatcher watcher = (PlayerDamagedBySourceWatcher) game.getState().getWatchers().get("PlayerDamagedBySource",source.getControllerId());
if (watcher != null && watcher.damageSources.contains(id)) { if (watcher != null && watcher.hasSourceDoneDamage(id, game)) {
return super.canTarget(id, source, game); return super.canTarget(id, source, game);
} }
return false; return false;
@ -97,7 +96,7 @@ class ReciprocateTarget<T extends TargetCreaturePermanent<T>> extends TargetPerm
PlayerDamagedBySourceWatcher watcher = (PlayerDamagedBySourceWatcher) game.getState().getWatchers().get("PlayerDamagedBySource", sourceControllerId); PlayerDamagedBySourceWatcher watcher = (PlayerDamagedBySourceWatcher) game.getState().getWatchers().get("PlayerDamagedBySource", sourceControllerId);
for (UUID targetId : availablePossibleTargets) { for (UUID targetId : availablePossibleTargets) {
Permanent permanent = game.getPermanent(targetId); Permanent permanent = game.getPermanent(targetId);
if(permanent != null && watcher != null && watcher.damageSources.contains(targetId)){ if(permanent != null && watcher != null && watcher.hasSourceDoneDamage(targetId, game)){
possibleTargets.add(targetId); possibleTargets.add(targetId);
} }
} }
@ -115,7 +114,7 @@ class ReciprocateTarget<T extends TargetCreaturePermanent<T>> extends TargetPerm
PlayerDamagedBySourceWatcher watcher = (PlayerDamagedBySourceWatcher) game.getState().getWatchers().get("PlayerDamagedBySource", sourceControllerId); PlayerDamagedBySourceWatcher watcher = (PlayerDamagedBySourceWatcher) game.getState().getWatchers().get("PlayerDamagedBySource", sourceControllerId);
for (Permanent permanent: game.getBattlefield().getActivePermanents(filter, sourceControllerId, sourceId, game)) { for (Permanent permanent: game.getBattlefield().getActivePermanents(filter, sourceControllerId, sourceId, game)) {
if (!targets.containsKey(permanent.getId()) && permanent.canBeTargetedBy(targetSource, sourceControllerId, game) if (!targets.containsKey(permanent.getId()) && permanent.canBeTargetedBy(targetSource, sourceControllerId, game)
&& watcher != null && watcher.damageSources.contains(permanent.getId())) { && watcher != null && watcher.hasSourceDoneDamage(permanent.getId(), game)) {
count++; count++;
if (count >= remainingTargets) { if (count >= remainingTargets) {
return true; return true;

View file

@ -28,17 +28,16 @@
package mage.sets.championsofkamigawa; package mage.sets.championsofkamigawa;
import java.util.UUID; import java.util.UUID;
import mage.constants.CardType;
import mage.constants.Rarity;
import mage.constants.Zone;
import mage.MageInt; import mage.MageInt;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.common.SimpleActivatedAbility; import mage.abilities.common.SimpleActivatedAbility;
import mage.abilities.costs.mana.ColoredManaCost; import mage.abilities.costs.mana.ColoredManaCost;
import mage.abilities.effects.common.LoseLifeTargetEffect; import mage.abilities.effects.common.LoseLifeTargetEffect;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.constants.CardType;
import mage.constants.ColoredManaSymbol; import mage.constants.ColoredManaSymbol;
import mage.constants.Rarity;
import mage.constants.Zone;
import mage.filter.FilterPlayer; import mage.filter.FilterPlayer;
import mage.filter.predicate.ObjectSourcePlayer; import mage.filter.predicate.ObjectSourcePlayer;
import mage.filter.predicate.ObjectSourcePlayerPredicate; import mage.filter.predicate.ObjectSourcePlayerPredicate;
@ -89,8 +88,8 @@ class WickedAkubaPredicate implements ObjectSourcePlayerPredicate<ObjectSourcePl
@Override @Override
public boolean apply(ObjectSourcePlayer<Player> input, Game game) { public boolean apply(ObjectSourcePlayer<Player> input, Game game) {
PlayerDamagedBySourceWatcher watcher = (PlayerDamagedBySourceWatcher) game.getState().getWatchers().get("PlayerDamagedBySource", input.getObject().getId()); PlayerDamagedBySourceWatcher watcher = (PlayerDamagedBySourceWatcher) game.getState().getWatchers().get("PlayerDamagedBySource", input.getObject().getId());
if (watcher != null && watcher.damageSources.contains(input.getSourceId())) { if (watcher != null) {
return true; return watcher.hasSourceDoneDamage(input.getSourceId(), game);
} }
return false; return false;

View file

@ -30,9 +30,6 @@ package mage.sets.conflux;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
import mage.constants.CardType;
import mage.constants.Rarity;
import mage.constants.Zone;
import mage.MageInt; import mage.MageInt;
import mage.MageObject; import mage.MageObject;
import mage.abilities.Ability; import mage.abilities.Ability;
@ -41,6 +38,9 @@ import mage.abilities.costs.common.TapSourceCost;
import mage.abilities.effects.common.DestroyTargetEffect; import mage.abilities.effects.common.DestroyTargetEffect;
import mage.abilities.keyword.ExaltedAbility; import mage.abilities.keyword.ExaltedAbility;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.constants.CardType;
import mage.constants.Rarity;
import mage.constants.Zone;
import mage.filter.common.FilterCreaturePermanent; import mage.filter.common.FilterCreaturePermanent;
import mage.game.Game; import mage.game.Game;
import mage.game.permanent.Permanent; import mage.game.permanent.Permanent;
@ -48,7 +48,6 @@ import mage.target.TargetPermanent;
import mage.target.common.TargetCreaturePermanent; import mage.target.common.TargetCreaturePermanent;
import mage.watchers.common.PlayerDamagedBySourceWatcher; import mage.watchers.common.PlayerDamagedBySourceWatcher;
/** /**
* *
* @author BetaSteward_at_googlemail.com * @author BetaSteward_at_googlemail.com
@ -103,7 +102,7 @@ class GiltspireAvengerTarget<T extends TargetCreaturePermanent<T>> extends Targe
@Override @Override
public boolean canTarget(UUID id, Ability source, Game game) { public boolean canTarget(UUID id, Ability source, Game game) {
PlayerDamagedBySourceWatcher watcher = (PlayerDamagedBySourceWatcher) game.getState().getWatchers().get("PlayerDamagedBySource",source.getControllerId()); PlayerDamagedBySourceWatcher watcher = (PlayerDamagedBySourceWatcher) game.getState().getWatchers().get("PlayerDamagedBySource",source.getControllerId());
if (watcher != null && watcher.damageSources.contains(id)) { if (watcher != null && watcher.hasSourceDoneDamage(id, game)) {
return super.canTarget(id, source, game); return super.canTarget(id, source, game);
} }
return false; return false;
@ -116,7 +115,7 @@ class GiltspireAvengerTarget<T extends TargetCreaturePermanent<T>> extends Targe
PlayerDamagedBySourceWatcher watcher = (PlayerDamagedBySourceWatcher) game.getState().getWatchers().get("PlayerDamagedBySource", sourceControllerId); PlayerDamagedBySourceWatcher watcher = (PlayerDamagedBySourceWatcher) game.getState().getWatchers().get("PlayerDamagedBySource", sourceControllerId);
for (UUID targetId : availablePossibleTargets) { for (UUID targetId : availablePossibleTargets) {
Permanent permanent = game.getPermanent(targetId); Permanent permanent = game.getPermanent(targetId);
if(permanent != null && watcher != null && watcher.damageSources.contains(targetId)){ if(permanent != null && watcher != null && watcher.hasSourceDoneDamage(targetId, game)){
possibleTargets.add(targetId); possibleTargets.add(targetId);
} }
} }
@ -134,7 +133,7 @@ class GiltspireAvengerTarget<T extends TargetCreaturePermanent<T>> extends Targe
PlayerDamagedBySourceWatcher watcher = (PlayerDamagedBySourceWatcher) game.getState().getWatchers().get("PlayerDamagedBySource", sourceControllerId); PlayerDamagedBySourceWatcher watcher = (PlayerDamagedBySourceWatcher) game.getState().getWatchers().get("PlayerDamagedBySource", sourceControllerId);
for (Permanent permanent: game.getBattlefield().getActivePermanents(filter, sourceControllerId, sourceId, game)) { for (Permanent permanent: game.getBattlefield().getActivePermanents(filter, sourceControllerId, sourceId, game)) {
if (!targets.containsKey(permanent.getId()) && permanent.canBeTargetedBy(targetSource, sourceControllerId, game) if (!targets.containsKey(permanent.getId()) && permanent.canBeTargetedBy(targetSource, sourceControllerId, game)
&& watcher != null && watcher.damageSources.contains(permanent.getId())) { && watcher != null && watcher.hasSourceDoneDamage(permanent.getId(), game)) {
count++; count++;
if (count >= remainingTargets) { if (count >= remainingTargets) {
return true; return true;

View file

@ -45,8 +45,8 @@ public class DealtDamageToAnOpponent implements Condition {
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
for (UUID opponentId: game.getOpponents(source.getControllerId())) { for (UUID opponentId: game.getOpponents(source.getControllerId())) {
PlayerDamagedBySourceWatcher watcher = (PlayerDamagedBySourceWatcher) game.getState().getWatchers().get("PlayerDamagedBySource", opponentId); PlayerDamagedBySourceWatcher watcher = (PlayerDamagedBySourceWatcher) game.getState().getWatchers().get("PlayerDamagedBySource", opponentId);
if (watcher != null && watcher.damageSources.contains(source.getSourceId())) { if (watcher != null) {
return true; return watcher.hasSourceDoneDamage(source.getSourceId(), game);
} }
} }
return false; return false;

View file

@ -57,15 +57,15 @@ public class DamagedPlayerThisTurnPredicate implements ObjectPlayerPredicate<Obj
switch (controller) { switch (controller) {
case YOU: case YOU:
PlayerDamagedBySourceWatcher watcher = (PlayerDamagedBySourceWatcher) game.getState().getWatchers().get("PlayerDamagedBySource",playerId); PlayerDamagedBySourceWatcher watcher = (PlayerDamagedBySourceWatcher) game.getState().getWatchers().get("PlayerDamagedBySource",playerId);
if (watcher != null && watcher.damageSources.contains(object.getId())) { if (watcher != null ) {
return true; return watcher.hasSourceDoneDamage(object.getId(), game);
} }
break; break;
case OPPONENT: case OPPONENT:
for (UUID opponentId : game.getOpponents(playerId)) { for (UUID opponentId : game.getOpponents(playerId)) {
watcher = (PlayerDamagedBySourceWatcher) game.getState().getWatchers().get("PlayerDamagedBySource",opponentId); watcher = (PlayerDamagedBySourceWatcher) game.getState().getWatchers().get("PlayerDamagedBySource",opponentId);
if (watcher != null && watcher.damageSources.contains(object.getId())) { if (watcher != null ) {
return true; return watcher.hasSourceDoneDamage(object.getId(), game);
} }
} }
break; break;
@ -75,8 +75,8 @@ public class DamagedPlayerThisTurnPredicate implements ObjectPlayerPredicate<Obj
for (UUID notYouId : you.getInRange()) { for (UUID notYouId : you.getInRange()) {
if (!notYouId.equals(playerId)) { if (!notYouId.equals(playerId)) {
watcher = (PlayerDamagedBySourceWatcher) game.getState().getWatchers().get("PlayerDamagedBySource",notYouId); watcher = (PlayerDamagedBySourceWatcher) game.getState().getWatchers().get("PlayerDamagedBySource",notYouId);
if (watcher != null && watcher.damageSources.contains(object.getId())) { if (watcher != null ) {
return true; return watcher.hasSourceDoneDamage(object.getId(), game);
} }
} }
} }
@ -87,8 +87,8 @@ public class DamagedPlayerThisTurnPredicate implements ObjectPlayerPredicate<Obj
if (you != null) { if (you != null) {
for (UUID anyId : you.getInRange()) { for (UUID anyId : you.getInRange()) {
watcher = (PlayerDamagedBySourceWatcher) game.getState().getWatchers().get("PlayerDamagedBySource",anyId); watcher = (PlayerDamagedBySourceWatcher) game.getState().getWatchers().get("PlayerDamagedBySource",anyId);
if (watcher != null && watcher.damageSources.contains(object.getId())) { if (watcher != null ) {
return true; return watcher.hasSourceDoneDamage(object.getId(), game);
} }
} }
} }

View file

@ -27,16 +27,16 @@
*/ */
package mage.watchers.common; package mage.watchers.common;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import mage.constants.WatcherScope; import mage.constants.WatcherScope;
import mage.game.Game; import mage.game.Game;
import mage.game.events.GameEvent; import mage.game.events.GameEvent;
import mage.game.events.GameEvent.EventType; import mage.game.events.GameEvent.EventType;
import mage.util.CardUtil;
import mage.watchers.WatcherImpl; import mage.watchers.WatcherImpl;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
/** /**
* Watcher stores whitch sources did damage to a player * Watcher stores whitch sources did damage to a player
* *
@ -44,7 +44,7 @@ import java.util.UUID;
*/ */
public class PlayerDamagedBySourceWatcher extends WatcherImpl<PlayerDamagedBySourceWatcher> { public class PlayerDamagedBySourceWatcher extends WatcherImpl<PlayerDamagedBySourceWatcher> {
public List<UUID> damageSources = new ArrayList<UUID>(); private Set<String> damageSourceIds = new HashSet<String>();
public PlayerDamagedBySourceWatcher(UUID playerId) { public PlayerDamagedBySourceWatcher(UUID playerId) {
super("PlayerDamagedBySource", WatcherScope.PLAYER); super("PlayerDamagedBySource", WatcherScope.PLAYER);
@ -53,7 +53,7 @@ public class PlayerDamagedBySourceWatcher extends WatcherImpl<PlayerDamagedBySou
public PlayerDamagedBySourceWatcher(final PlayerDamagedBySourceWatcher watcher) { public PlayerDamagedBySourceWatcher(final PlayerDamagedBySourceWatcher watcher) {
super(watcher); super(watcher);
this.damageSources.addAll(watcher.damageSources); this.damageSourceIds.addAll(watcher.damageSourceIds);
} }
@Override @Override
@ -64,15 +64,27 @@ public class PlayerDamagedBySourceWatcher extends WatcherImpl<PlayerDamagedBySou
@Override @Override
public void watch(GameEvent event, Game game) { public void watch(GameEvent event, Game game) {
if (event.getType() == EventType.DAMAGED_PLAYER) { if (event.getType() == EventType.DAMAGED_PLAYER) {
if (event.getTargetId().equals(controllerId) && !damageSources.contains(event.getSourceId())) { if (event.getTargetId().equals(controllerId)) {
damageSources.add(event.getSourceId()); damageSourceIds.add(CardUtil.getCardZoneString(null, event.getSourceId(), game));
} }
} }
} }
/**
* Checks if the current object with sourceId has damaged the player during the current turn.
* The zoneChangeCounter will be taken into account.
*
* @param sourceId
* @param game
* @return
*/
public boolean hasSourceDoneDamage(UUID sourceId, Game game) {
return damageSourceIds.contains(CardUtil.getCardZoneString(null, sourceId, game));
}
@Override @Override
public void reset() { public void reset() {
super.reset(); super.reset();
damageSources.clear(); damageSourceIds.clear();
} }
} }