- Integrating the zone restriction check as a mandatory part of SpellAbility#canTarget.

This commit is contained in:
Agetian
2017-06-27 16:35:49 +00:00
parent 934683f4d5
commit 247f8f5be1
3 changed files with 10 additions and 18 deletions

View File

@@ -63,7 +63,7 @@ public class ChangeTargetsAi extends SpellAbilityAi {
// make sure not to redirect our own abilities
return false;
}
if (!topSa.canTarget(sa.getHostCard(), true)) {
if (!topSa.canTarget(sa.getHostCard())) {
// don't try targeting it if we can't legally target the host card with it in the first place
return false;
}

View File

@@ -81,7 +81,7 @@ public class ChangeTargetsEffect extends SpellAbilityEffect {
// 3. test if updated choices would be correct.
GameObject newTarget = Iterables.getFirst(getDefinedCardsOrTargeted(sa), null);
if (replaceIn.getSpellAbility(true).canTarget(newTarget, true)) {
if (replaceIn.getSpellAbility(true).canTarget(newTarget)) {
newTargetBlock.add(newTarget);
replaceIn.updateTarget(newTargetBlock, oldTarget, newTarget);
}
@@ -103,7 +103,7 @@ public class ChangeTargetsEffect extends SpellAbilityEffect {
}
else if (sa.hasParam("DefinedMagnet")){
GameObject newTarget = Iterables.getFirst(getDefinedCardsOrTargeted(sa, "DefinedMagnet"), null);
if (newTarget != null && changingTgtSA.canTarget(newTarget, true)) {
if (newTarget != null && changingTgtSA.canTarget(newTarget)) {
changingTgtSA.resetTargets();
changingTgtSA.getTargets().add(newTarget);
changingTgtSI.updateTarget(changingTgtSA.getTargets(), null, newTarget);

View File

@@ -973,27 +973,19 @@ public abstract class SpellAbility extends CardTraitBase implements ISpellAbilit
return false;
}
}
if (entity instanceof Card) {
final Card c = (Card) entity;
if (!tr.getZone().contains(c.getZone().getZoneType())) {
return false;
}
}
}
// Restrictions coming from target
return entity.canBeTargetedBy(this);
}
public final boolean canTarget(final GameObject object, final boolean zoneCheck) {
// TODO: the zone check should most likely be integrated as a part of the
// regular canTarget call, but that needs testing.
boolean zoneTestPassed = true;
if (object instanceof Card && zoneCheck) {
final TargetRestrictions tr = getTargetRestrictions();
final Card c = (Card)object;
if (!tr.getZone().contains(c.getZone().getZoneType())) {
zoneTestPassed = false;
}
}
return zoneTestPassed && canTarget(object);
}
// is this a wrapping ability (used by trigger abilities)
public boolean isWrapper() {
return false;