- FIXME: Introducing a temporary measure to check for TargetedPlayerCtrl/TargetedPlayerOwn via the CastSA chain when the standard check fails. This can happen, for example, when an opponent's card is activated in hand (e.g. Chandra's Fury via Sen Triplets). Please assist, if possible, in investigating the source of this issue and fixing it (this may manifest itself in other places too, and most likely does). Feel free to revert this commit if you know a good solution.

This commit is contained in:
Agetian
2017-10-23 06:55:20 +00:00
parent 6c51f7c6bc
commit 6433eff8ec

View File

@@ -216,9 +216,11 @@ public class CardProperty {
return false;
}
} else if (property.equals("TargetedPlayerCtrl")) {
boolean foundTargetingSA = false;
for (final SpellAbility sa : source.getCurrentState().getNonManaAbilities()) {
final SpellAbility saTargeting = sa.getSATargetingPlayer();
if (saTargeting != null) {
foundTargetingSA = true;
for (final Player p : saTargeting.getTargets().getTargetPlayers()) {
if (!controller.equals(p)) {
return false;
@@ -226,6 +228,28 @@ public class CardProperty {
}
}
}
if (!foundTargetingSA) {
// FIXME: Something went wrong with detecting the SA that has a target, this can happen
// e.g. when activating a SA on a card from another player's hand (e.g. opponent's Chandra's Fury
// activated via Sen Triplets). Needs further investigation as to why this is happening, it might
// cause issues elsewhere too.
System.err.println("Warning: could not deduce a player target for TargetedPlayerCtrl for " + source + ", trying to locate it via CastSA...");
SpellAbility castSA = source.getCastSA();
while (castSA != null) {
if (!Iterables.isEmpty(castSA.getTargets().getTargetPlayers())) {
foundTargetingSA = true;
for (final Player p : castSA.getTargets().getTargetPlayers()) {
if (!controller.equals(p)) {
return false;
}
}
}
castSA = castSA.getSubAbility();
}
if (!foundTargetingSA) {
System.err.println("Warning: checking targets in CastSA did not yield any results as well, TargetedPlayerCtrl check failed.");
}
}
} else if (property.equals("TargetedControllerCtrl")) {
for (final SpellAbility sa : source.getCurrentState().getNonManaAbilities()) {
final CardCollectionView cards = AbilityUtils.getDefinedCards(source, "Targeted", sa);
@@ -264,9 +288,11 @@ public class CardProperty {
return false;
}
} else if (property.equals("TargetedPlayerOwn")) {
boolean foundTargetingSA = false;
for (final SpellAbility sa : source.getCurrentState().getNonManaAbilities()) {
final SpellAbility saTargeting = sa.getSATargetingPlayer();
if (saTargeting != null) {
foundTargetingSA = true;
for (final Player p : saTargeting.getTargets().getTargetPlayers()) {
if (!card.getOwner().equals(p)) {
return false;
@@ -274,6 +300,25 @@ public class CardProperty {
}
}
}
if (!foundTargetingSA) {
// FIXME: Something went wrong with detecting the SA that has a target, needs investigation
System.err.println("Warning: could not deduce a player target for TargetedPlayerOwn for " + source + ", trying to locate it via CastSA...");
SpellAbility castSA = source.getCastSA();
while (castSA != null) {
if (!Iterables.isEmpty(castSA.getTargets().getTargetPlayers())) {
foundTargetingSA = true;
for (final Player p : castSA.getTargets().getTargetPlayers()) {
if (!card.getOwner().equals(p)) {
return false;
}
}
}
castSA = castSA.getSubAbility();
}
if (!foundTargetingSA) {
System.err.println("Warning: checking targets in CastSA did not yield any results as well, TargetedPlayerOwn check failed.");
}
}
} else if (property.startsWith("OwnedBy")) {
final String valid = property.substring(8);
if (!card.getOwner().isValid(valid, sourceController, source, spellAbility)) {