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.Set;
import java.util.UUID;
import mage.constants.CardType;
import mage.constants.Rarity;
import mage.MageObject;
import mage.abilities.Ability;
import mage.abilities.effects.common.ExileTargetEffect;
import mage.cards.CardImpl;
import mage.constants.CardType;
import mage.constants.Rarity;
import mage.filter.common.FilterCreaturePermanent;
import mage.game.Game;
import mage.game.permanent.Permanent;
@ -46,7 +45,7 @@ import mage.target.common.TargetCreaturePermanent;
import mage.watchers.common.PlayerDamagedBySourceWatcher;
/**
* @author LevelX
* @author LevelX2
*/
public class Reciprocate extends CardImpl<Reciprocate> {
@ -84,7 +83,7 @@ class ReciprocateTarget<T extends TargetCreaturePermanent<T>> extends TargetPerm
@Override
public boolean canTarget(UUID id, Ability source, Game game) {
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 false;
@ -97,7 +96,7 @@ class ReciprocateTarget<T extends TargetCreaturePermanent<T>> extends TargetPerm
PlayerDamagedBySourceWatcher watcher = (PlayerDamagedBySourceWatcher) game.getState().getWatchers().get("PlayerDamagedBySource", sourceControllerId);
for (UUID targetId : availablePossibleTargets) {
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);
}
}
@ -115,7 +114,7 @@ class ReciprocateTarget<T extends TargetCreaturePermanent<T>> extends TargetPerm
PlayerDamagedBySourceWatcher watcher = (PlayerDamagedBySourceWatcher) game.getState().getWatchers().get("PlayerDamagedBySource", sourceControllerId);
for (Permanent permanent: game.getBattlefield().getActivePermanents(filter, sourceControllerId, sourceId, 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++;
if (count >= remainingTargets) {
return true;

View file

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

View file

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

View file

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

View file

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

View file

@ -27,16 +27,16 @@
*/
package mage.watchers.common;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import mage.constants.WatcherScope;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.events.GameEvent.EventType;
import mage.util.CardUtil;
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
*
@ -44,16 +44,16 @@ import java.util.UUID;
*/
public class PlayerDamagedBySourceWatcher extends WatcherImpl<PlayerDamagedBySourceWatcher> {
public List<UUID> damageSources = new ArrayList<UUID>();
private Set<String> damageSourceIds = new HashSet<String>();
public PlayerDamagedBySourceWatcher(UUID playerId) {
super("PlayerDamagedBySource", WatcherScope.PLAYER);
setControllerId(playerId);
setControllerId(playerId);
}
public PlayerDamagedBySourceWatcher(final PlayerDamagedBySourceWatcher watcher) {
super(watcher);
this.damageSources.addAll(watcher.damageSources);
this.damageSourceIds.addAll(watcher.damageSourceIds);
}
@Override
@ -64,15 +64,27 @@ public class PlayerDamagedBySourceWatcher extends WatcherImpl<PlayerDamagedBySou
@Override
public void watch(GameEvent event, Game game) {
if (event.getType() == EventType.DAMAGED_PLAYER) {
if (event.getTargetId().equals(controllerId) && !damageSources.contains(event.getSourceId())) {
damageSources.add(event.getSourceId());
}
}
if (event.getTargetId().equals(controllerId)) {
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
public void reset() {
super.reset();
damageSources.clear();
damageSourceIds.clear();
}
}