Saagael
May 3rd, 2022, 18:27
I discovered some strange behavior when working on an extension of mine, and I don't know if this is a bug or not. In my extension players can create a power action that targets all tokens within a certain radius around them. Naturally I check to see if a token is visible before targeting it, however it was discovered that when a token is selected and line of sight is enabled on a map, tokeninstance.isVisible() returns false, even if the token is otherwise visible. If the token is not selected, isVisible() returns true as expected.
Here's the code I've got, with the relevant section bolded.
function targetAllWithinDistance(node, nDistance, sFaction, bIgnoreVisible)
local finaltargets = {};
local nodeCT = CombatManager.getCTFromNode(node);
if nodeCT then
local tokenCT = CombatManager.getTokenFromCT(nodeCT);
if tokenCT then
local targets = Token.getTokensWithinDistance(tokenCT, nDistance);
for index,token in ipairs(targets) do
local targetCT = CombatManager.getCTFromToken(token);
if sFaction == "all" or ActorManager.getFaction(targetCT) == sFaction then
local rTarget = ActorManager.resolveActor(targetCT);
local bIsVisible = token.isVisible();
Debug.chat(rTarget.sName .. " is visible?", token.isVisible());
if bIgnoreVisible or bIsVisible then
table.insert(finaltargets, targetCT);
end
end
end
end
end
if #finaltargets > 0 then
for _, targetCT in ipairs(finaltargets) do
TargetingManager.addCTTarget(nodeCT, targetCT);
end
end
end
Here is the questionable behavior with line of sight enabled on the map. (https://i.imgur.com/L8Ii4Zv.gif) You can see the debug statement in chat show that when a token is selected, isVisible is returning false for that token, but returning true if the token is not selected.
And for reference, here is the extension working as expected when line of sight is disabled. (https://i.imgur.com/tXrTpK3.gif) The debug statements show that isVisible is true regardless of if the token is selected.
I've attached the campaign zip and extension I'm using for the above examples for any further testing.
Is this expected behavior? If it is, what should I be doing to test for token visibility that doesn't have this behavior?
Here's the code I've got, with the relevant section bolded.
function targetAllWithinDistance(node, nDistance, sFaction, bIgnoreVisible)
local finaltargets = {};
local nodeCT = CombatManager.getCTFromNode(node);
if nodeCT then
local tokenCT = CombatManager.getTokenFromCT(nodeCT);
if tokenCT then
local targets = Token.getTokensWithinDistance(tokenCT, nDistance);
for index,token in ipairs(targets) do
local targetCT = CombatManager.getCTFromToken(token);
if sFaction == "all" or ActorManager.getFaction(targetCT) == sFaction then
local rTarget = ActorManager.resolveActor(targetCT);
local bIsVisible = token.isVisible();
Debug.chat(rTarget.sName .. " is visible?", token.isVisible());
if bIgnoreVisible or bIsVisible then
table.insert(finaltargets, targetCT);
end
end
end
end
end
if #finaltargets > 0 then
for _, targetCT in ipairs(finaltargets) do
TargetingManager.addCTTarget(nodeCT, targetCT);
end
end
end
Here is the questionable behavior with line of sight enabled on the map. (https://i.imgur.com/L8Ii4Zv.gif) You can see the debug statement in chat show that when a token is selected, isVisible is returning false for that token, but returning true if the token is not selected.
And for reference, here is the extension working as expected when line of sight is disabled. (https://i.imgur.com/tXrTpK3.gif) The debug statements show that isVisible is true regardless of if the token is selected.
I've attached the campaign zip and extension I'm using for the above examples for any further testing.
Is this expected behavior? If it is, what should I be doing to test for token visibility that doesn't have this behavior?