From 9ed5900500c2077638023b03ed9d8146015f1b82 Mon Sep 17 00:00:00 2001 From: Berwind24 <73523410+Berwind24@users.noreply.github.com> Date: Tue, 27 Oct 2020 17:34:25 -0500 Subject: [PATCH 1/2] Allow for large-sized creatures/tokens to flank Allow for large-sized and smaller creatures/tokens to flank. --- scripts/flanking/flanking.lua | 247 +++++++++++++++++++++++++++++----- 1 file changed, 213 insertions(+), 34 deletions(-) diff --git a/scripts/flanking/flanking.lua b/scripts/flanking/flanking.lua index 4fa3d1f..223b120 100644 --- a/scripts/flanking/flanking.lua +++ b/scripts/flanking/flanking.lua @@ -51,77 +51,256 @@ function isFlanking(rActor, rTarget) -- determine direction of attack and set sDirection to N, NE, E, SE, S, SW, W, NW. - local sDirection; - if aTokenMap[sTargetPath].size == 'Medium' or aTokenMap[sTargetPath].size == 'Small' or aTokenMap[sTargetPath].size == 'Tiny' then - if (actorX == targetX) and (actorY == targetY + 1) then sDirection = 'N'; end - if (actorX == targetX - 1) and (actorY == targetY + 1) then sDirection = 'NE'; end - if (actorX == targetX - 1) and (actorY == targetY) then sDirection = 'E'; end - if (actorX == targetX - 1) and (actorY == targetY - 1) then sDirection = 'SE'; end - if (actorX == targetX) and (actorY == targetY - 1) then sDirection = 'S'; end - if (actorX == targetX + 1) and (actorY == targetY - 1) then sDirection = 'SW'; end - if (actorX == targetX + 1) and (actorY == targetY) then sDirection = 'W'; end - if (actorX == targetX + 1) and (actorY == targetY + 1) then sDirection = 'NW'; end + local sDirection = ''; + local sDirectionB = ''; + local sDirectionC = ''; + if aTokenMap[sActorPath].size == 'Medium' or aTokenMap[sActorPath].size == 'Small' or aTokenMap[sActorPath].size == 'Tiny' then + if aTokenMap[sTargetPath].size == 'Medium' or aTokenMap[sTargetPath].size == 'Small' or aTokenMap[sTargetPath].size == 'Tiny' then + if (actorX == targetX) and (actorY == targetY + 1) then sDirection = 'N'; sDirectionB = 'N'; end + if (actorX == targetX - 1) and (actorY == targetY + 1) then sDirection = 'NE'; end + if (actorX == targetX - 1) and (actorY == targetY) then sDirection = 'E'; sDirectionB = 'E'; end + if (actorX == targetX - 1) and (actorY == targetY - 1) then sDirection = 'SE'; end + if (actorX == targetX) and (actorY == targetY - 1) then sDirection = 'S'; sDirectionB = 'S'; end + if (actorX == targetX + 1) and (actorY == targetY - 1) then sDirection = 'SW'; end + if (actorX == targetX + 1) and (actorY == targetY) then sDirection = 'W'; sDirectionB = 'W'; end + if (actorX == targetX + 1) and (actorY == targetY + 1) then sDirection = 'NW'; end + end + + -- if target is large look for top left corner of target token. + if aTokenMap[sTargetPath].size == 'Large' then + if (actorX == targetX) and (actorY == targetY + 2) then sDirection = 'N'; sDirectionB = 'N'; sDirectionC = 'N'; end + if (actorX == targetX + 1) and (actorY == targetY + 2) then sDirection = 'N'; sDirectionB = 'N'; sDirectionC = 'N'; end + if (actorX == targetX - 1) and (actorY == targetY + 2) then sDirection = 'NE'; end + if (actorX == targetX - 1) and (actorY == targetY) then sDirection = 'E'; sDirectionB = 'E'; sDirectionC = 'E';end + if (actorX == targetX - 1) and (actorY == targetY + 1) then sDirection = 'E'; sDirectionB = 'E'; sDirectionC = 'E'; end + if (actorX == targetX - 1) and (actorY == targetY - 1) then sDirection = 'SE'; end + if (actorX == targetX) and (actorY == targetY - 1) then sDirection = 'S'; sDirectionB = 'S'; sDirectionC = 'S'; end + if (actorX == targetX + 1) and (actorY == targetY - 1) then sDirection = 'S'; sDirectionB = 'S'; sDirectionC = 'S'; end + if (actorX == targetX + 2) and (actorY == targetY - 1) then sDirection = 'SW'; end + if (actorX == targetX + 2) and (actorY == targetY) then sDirection = 'W'; sDirectionB = 'W'; sDirectionC = 'W'; end + if (actorX == targetX + 2) and (actorY == targetY + 1) then sDirection = 'W'; sDirectionB = 'W'; sDirectionC = 'W'; end + if (actorX == targetX + 2) and (actorY == targetY + 2) then sDirection = 'NW'; end + end + end + + --large actor medium or smaller target; searches from top left corner of actor + if aTokenMap[sActorPath].size == 'Large' then + if aTokenMap[sTargetPath].size == 'Medium' or aTokenMap[sTargetPath].size == 'Small' or aTokenMap[sTargetPath].size == 'Tiny' then + if (actorX == targetX) and (actorY == targetY + 1) then sDirection = 'N'; sDirectionB = 'N'; end + if (actorX == targetX - 1) and (actorY == targetY + 1) then sDirection = 'N'; sDirectionB = 'N'; end + if (actorX == targetX - 2) and (actorY == targetY + 1) then sDirection = 'NE'; end + if (actorX == targetX - 2) and (actorY == targetY) then sDirection = 'E'; sDirectionB = 'E'; end + if (actorX == targetX - 2) and (actorY == targetY - 1) then sDirection = 'E'; sDirectionB = 'E'; end + if (actorX == targetX - 2) and (actorY == targetY - 2) then sDirection = 'SE'; end + if (actorX == targetX) and (actorY == targetY - 2) then sDirection = 'S'; sDirectionB = 'S'; end + if (actorX == targetX - 1) and (actorY == targetY - 2) then sDirection = 'S'; sDirectionB = 'S'; end + if (actorX == targetX + 1) and (actorY == targetY - 2) then sDirection = 'SW'; end + if (actorX == targetX + 1) and (actorY == targetY) then sDirection = 'W'; sDirectionB = 'W'; end + if (actorX == targetX + 1) and (actorY == targetY - 1) then sDirection= 'W'; sDirectionB ='W'; end + if (actorX == targetX + 1) and (actorY == targetY + 1) then sDirection = 'NW'; end + end + + --Large actor large target; searches from top left of actor to top left of target + if aTokenMap[sTargetPath].size == 'Large' then + if (actorX == targetX - 1) and (actorY == targetY + 2) then sDirection = 'N'; sDirectionB = 'N'; sDirectionC = 'N'; end + if (actorX == targetX) and (actorY == targetY + 2) then sDirection = 'N'; sDirectionB = 'N'; sDirectionC = 'N'; end + if (actorX == targetX + 1) and (actorY == targetY + 2) then sDirection = 'N'; sDirectionB = 'N'; sDirectionC = 'N'; end + if (actorX == targetX - 2) and (actorY == targetY + 2) then sDirection = 'NE'; end + if (actorX == targetX - 2) and (actorY == targetY - 1) then sDirection = 'E'; sDirectionB = 'E'; sDirectionC = 'E'; end + if (actorX == targetX - 2) and (actorY == targetY) then sDirection = 'E'; sDirectionB = 'E'; sDirectionC = 'E'; end + if (actorX == targetX - 2) and (actorY == targetY + 1) then sDirection = 'E'; sDirectionB = 'E'; sDirectionC = 'E'; end + if (actorX == targetX - 2) and (actorY == targetY - 2) then sDirection = 'SE'; end + if (actorX == targetX - 1) and (actorY == targetY - 2) then sDirection = 'S'; sDirectionB = 'S'; sDirectionC = 'S'; end + if (actorX == targetX) and (actorY == targetY - 2) then sDirection = 'S'; sDirectionB = 'S'; sDirectionC = 'S'; end + if (actorX == targetX + 1) and (actorY == targetY - 2) then sDirection = 'S'; sDirectionB = 'S'; sDirectionC = 'S'; end + if (actorX == targetX + 2) and (actorY == targetY - 2) then sDirection = 'SW'; end + if (actorX == targetX + 2) and (actorY == targetY -1) then sDirection = 'W'; sDirectionB = 'W'; sDirectionC = 'W'; end + if (actorX == targetX + 2) and (actorY == targetY) then sDirection = 'W'; sDirectionB = 'W'; sDirectionC = 'W'; end + if (actorX == targetX + 2) and (actorY == targetY + 1) then sDirection = 'W'; sDirectionB = 'W'; sDirectionC = 'W'; end + if (actorX == targetX + 2) and (actorY == targetY + 2) then sDirection = 'NW'; end + end end - if aTokenMap[sTargetPath].size == 'Large' then - end - -- search for ally + -- search for medium ally local sAllyPath = ''; + local sAllyPathB = ''; + local sAllyPathC = ''; if aTokenMap[sTargetPath].size == 'Medium' or aTokenMap[sTargetPath].size == 'Small' or aTokenMap[sTargetPath].size == 'Tiny' then - if sDirection == 'N' then sAllyPath = TokenHelper.getActorByGrid(aTokenMap, targetX, targetY - 1); end + if sDirection == 'N' then sAllyPath = TokenHelper.getActorByGrid(aTokenMap, targetX, targetY - 1); end if sDirection == 'NE' then sAllyPath = TokenHelper.getActorByGrid(aTokenMap, targetX + 1, targetY - 1); end - if sDirection == 'E' then sAllyPath = TokenHelper.getActorByGrid(aTokenMap, targetX + 1, targetY); end + if sDirection == 'E' then sAllyPath = TokenHelper.getActorByGrid(aTokenMap, targetX + 1, targetY); end if sDirection == 'SE' then sAllyPath = TokenHelper.getActorByGrid(aTokenMap, targetX + 1, targetY + 1); end - if sDirection == 'S' then sAllyPath = TokenHelper.getActorByGrid(aTokenMap, targetX, targetY + 1); end + if sDirection == 'S' then sAllyPath = TokenHelper.getActorByGrid(aTokenMap, targetX, targetY + 1); end if sDirection == 'SW' then sAllyPath = TokenHelper.getActorByGrid(aTokenMap, targetX - 1, targetY + 1); end - if sDirection == 'W' then sAllyPath = TokenHelper.getActorByGrid(aTokenMap, targetX - 1, targetY); end + if sDirection == 'W' then sAllyPath = TokenHelper.getActorByGrid(aTokenMap, targetX - 1, targetY); end + if sDirection == 'NW' then sAllyPath = TokenHelper.getActorByGrid(aTokenMap, targetX - 1, targetY - 1); end + end + + -- large target token begins search from top left corner. + if aTokenMap[sTargetPath].size == 'Large' then + if sDirection == 'N' then sAllyPath = TokenHelper.getActorByGrid(aTokenMap, targetX, targetY - 1); end + if sDirectionB == 'N' then sAllyPathB = TokenHelper.getActorByGrid(aTokenMap, targetX + 1, targetY - 1); end + if sDirection == 'NE' then sAllyPath = TokenHelper.getActorByGrid(aTokenMap, targetX + 2, targetY - 1); end + if sDirection == 'E' then sAllyPath = TokenHelper.getActorByGrid(aTokenMap, targetX + 2, targetY); end + if sDirectionB == 'E' then sAllyPathB = TokenHelper.getActorByGrid(aTokenMap, targetX + 2, targetY + 1); end + if sDirection == 'SE' then sAllyPath = TokenHelper.getActorByGrid(aTokenMap, targetX + 2, targetY + 2); end + if sDirection == 'S' then sAllyPath = TokenHelper.getActorByGrid(aTokenMap, targetX, targetY + 2); end + if sDirectionB == 'S' then sAllyPathB = TokenHelper.getActorByGrid(aTokenMap, targetX + 1, targetY + 2); end + if sDirection == 'SW' then sAllyPath = TokenHelper.getActorByGrid(aTokenMap, targetX - 1, targetY + 2); end + if sDirection == 'W' then sAllyPath = TokenHelper.getActorByGrid(aTokenMap, targetX - 1, targetY); end + if sDirectionB == 'W' then sAllyPathB = TokenHelper.getActorByGrid(aTokenMap, targetX - 1, targetY + 1); end if sDirection == 'NW' then sAllyPath = TokenHelper.getActorByGrid(aTokenMap, targetX - 1, targetY - 1); end end + + --if large token found when looking for medium ally, then remove them + if sAllyPath ~= '' then + if (aTokenMap[sAllyPath].size ~= 'Medium') and (aTokenMap[sAllyPath].size ~= 'Small') and (aTokenMap[sAllyPath].size ~= 'Tiny') then + sAllyPath = ''; end + end + if sAllyPathB ~= '' then + if (aTokenMap[sAllyPathB].size ~= 'Medium') and (aTokenMap[sAllyPathB].size ~= 'Small') and (aTokenMap[sAllyPathB].size ~= 'Tiny') + then sAllyPath = ''; end + end + -- Search for large ally + -- Only check if sAllyPath and sAllyPathB ~= '': so no tokens already found as an ally + if (sAllyPath == '') and (sAllyPathB == '') then + --medium target;large ally + if aTokenMap[sTargetPath].size == 'Medium' or aTokenMap[sTargetPath].size == 'Small' or aTokenMap[sTargetPath].size == 'Tiny' then + if sDirection == 'N' then sAllyPath = TokenHelper.getActorByGrid(aTokenMap, targetX, targetY - 2); end + if sDirectionB == 'N' then sAllyPathB = TokenHelper.getActorByGrid(aTokenMap, targetX - 1, targetY - 2); end + if sDirection == 'NE' then sAllyPath = TokenHelper.getActorByGrid(aTokenMap, targetX + 1, targetY - 2); end + if sDirection == 'E' then sAllyPath = TokenHelper.getActorByGrid(aTokenMap, targetX + 1, targetY); end + if sDirectionB == 'E' then sAllyPathB = TokenHelper.getActorByGrid(aTokenMap, targetX + 1, targetY - 1); end + if sDirection == 'SE' then sAllyPath = TokenHelper.getActorByGrid(aTokenMap, targetX + 1, targetY + 1); end + if sDirection == 'S' then sAllyPath = TokenHelper.getActorByGrid(aTokenMap, targetX, targetY + 1); end + if sDirectionB == 'S' then sAllyPathB = TokenHelper.getActorByGrid(aTokenMap, targetX - 1, targetY + 1); end + if sDirection == 'SW' then sAllyPath = TokenHelper.getActorByGrid(aTokenMap, targetX - 2, targetY + 1); end + if sDirection == 'W' then sAllyPath = TokenHelper.getActorByGrid(aTokenMap, targetX - 2, targetY); end + if sDirectionB == 'W' then sAllyPathB = TokenHelper.getActorByGrid(aTokenMap, targetX - 2, targetY - 1); end + if sDirection == 'NW' then sAllyPath = TokenHelper.getActorByGrid(aTokenMap, targetX - 2, targetY - 2); end + end + + --large target; large ally + if aTokenMap[sTargetPath].size == 'Large' then + if sDirection == 'N' then sAllyPath = TokenHelper.getActorByGrid(aTokenMap, targetX - 1, targetY - 2); end + if sDirectionB == 'N' then sAllyPathB = TokenHelper.getActorByGrid(aTokenMap, targetX, targetY - 2); end + if sDirectionC == 'N' then sAllyPathC = TokenHelper.getActorByGrid(aTokenMap, targetX + 1, targetY - 2); end + if sDirection == 'NE' then sAllyPath = TokenHelper.getActorByGrid(aTokenMap, targetX + 2, targetY - 2); end + if sDirection == 'E' then sAllyPath = TokenHelper.getActorByGrid(aTokenMap, targetX + 2, targetY - 1); end + if sDirectionB == 'E' then sAllyPathB = TokenHelper.getActorByGrid(aTokenMap, targetX + 2, targetY); end + if sDirectionB == 'E' then sAllyPathC = TokenHelper.getActorByGrid(aTokenMap, targetX + 2, targetY + 1); end + if sDirection == 'SE' then sAllyPath = TokenHelper.getActorByGrid(aTokenMap, targetX + 2, targetY + 2); end + if sDirection == 'S' then sAllyPath = TokenHelper.getActorByGrid(aTokenMap, targetX - 1, targetY + 2); end + if sDirectionB == 'S' then sAllyPathB = TokenHelper.getActorByGrid(aTokenMap, targetX, targetY + 2); end + if sDirectionC == 'S' then sAllyPathC = TokenHelper.getActorByGrid(aTokenMap, targetX + 1, targetY + 2); end + if sDirection == 'SW' then sAllyPath = TokenHelper.getActorByGrid(aTokenMap, targetX - 2, targetY + 2); end + if sDirection == 'W' then sAllyPath = TokenHelper.getActorByGrid(aTokenMap, targetX - 2, targetY - 1); end + if sDirectionB == 'W' then sAllyPathB = TokenHelper.getActorByGrid(aTokenMap, targetX - 2, targetY); end + if sDirectionC == 'W' then sAllyPathC = TokenHelper.getActorByGrid(aTokenMap, targetX - 2, targetY + 1); end + if sDirection == 'NW' then sAllyPath = TokenHelper.getActorByGrid(aTokenMap, targetX - 2, targetY - 2); end + end + + --if medium ally found while looking for large ally, remove medium + if (sAllyPath ~= '') then + if aTokenMap[sAllyPath].size ~= 'Large' then + sAllyPath = ''; end + end + if (sAllyPathB ~= '') then + if aTokenMap[sAllyPathB].size ~= 'Large' then + sAllyPathB = ''; end + end + if (sAllyPathC ~= '') then + if aTokenMap[sAllyPathC].size ~= 'Large' then + sAllyPathC = ''; end + end + end -- get ally CT entry local allyNodePath = ''; + local allyNodePathB = ''; + local allyNodePathC = ''; local aEntries = CombatManager.getSortedCombatantList(); - local nIndexActive = 0; - for i = nIndexActive + 1, #aEntries do - local entryNodePath = DB.getPath(aEntries[i]); - - if entryNodePath == sAllyPath then allyNodePath = entryNodePath; end - nIndexActive = nIndexActive + 1; - end + local nIndexActive = 0; + if sAllyPath ~= '' then + for i = nIndexActive + 1, #aEntries do + local entryNodePath = DB.getPath(aEntries[i]); + if entryNodePath == sAllyPath then allyNodePath = entryNodePath; end + + nIndexActive = nIndexActive + 1; + end + end + if sAllyPathB ~= '' then + for i = nIndexActive + 1, #aEntries do + local entryNodePath = DB.getPath(aEntries[i]); + if entryNodePath == sAllyPathB then allyNodePathB = entryNodePath; end + + nIndexActive = nIndexActive + 1; + end + end + if sAllyPathC ~= '' then + for i = nIndexActive + 1, #aEntries do + local entryNodePath = DB.getPath(aEntries[i]); + if entryNodePath == sAllyPathC then allyNodePathC = entryNodePath; end + + nIndexActive = nIndexActive + 1; + end + end -- consider altitude -- get nodes -> tokens -> token height local actorNode = rActor.sCTNode; local targetNode = rTarget.sCTNode; - local allyNode = CombatManager.getCTFromNode(allyNodePath); + local allyNode = CombatManager.getCTFromNode(allyNodePath); + local allyNodeB = CombatManager.getCTFromNode(allyNodePathB); + local allyNodeC = CombatManager.getCTFromNode(allyNodePathC); local actorToken = CombatManager.getTokenFromCT(actorNode); local targetToken = CombatManager.getTokenFromCT(targetNode); - local allyToken = CombatManager.getTokenFromCT(allyNode); + local allyToken = CombatManager.getTokenFromCT(allyNode); + local allyTokenB = CombatManager.getTokenFromCT(allyNodeB); + local allyTokenC = CombatManager.getTokenFromCT(allyNodeC); -- get height local actorHeight = TokenHeight.getTokenHeight(actorToken); local targetHeight = TokenHeight.getTokenHeight(targetToken); local allyHeight = TokenHeight.getTokenHeight(allyToken); - + local allyHeightB = TokenHeight.getTokenHeight(allyTokenB); + local allyHeightC = TokenHeight.getTokenHeight(allyTokenC); + -- if either actor or ally are out of range of melee attack, height wise, then no flanking benefit local bOutOfRange = false; - if (math.sqrt(actorHeight^2 - targetHeight^2) > 5) or (math.sqrt(allyHeight^2 - targetHeight^2) > 5) then bOutOfRange = true; end + if (math.sqrt(actorHeight^2 - targetHeight^2) > 5) or (math.sqrt(allyHeight^2 - targetHeight^2) > 5) then bOutOfRange = true end + if (math.sqrt(actorHeight^2 - targetHeight^2) > 5) or (math.sqrt(allyHeightB^2 - targetHeight^2) > 5) then bOutOfRange = true end + if (math.sqrt(actorHeight^2 - targetHeight^2) > 5) or (math.sqrt(allyHeightC^2 - targetHeight^2) > 5) then bOutOfRange = true end local actorFriendFoe = aTokenMap[sActorPath].friendfoe; local allyFriendFoe = ''; - if sAllyPath ~= '' then allyFriendFoe = aTokenMap[sAllyPath].friendfoe; end + + if sAllyPath ~= '' then + allyFriendFoe = aTokenMap[sAllyPath].friendfoe; + end + if sAllyPathB ~= '' then + allyFriendFoeB = aTokenMap[sAllyPathB].friendfoe; + end + if sAllyPathC ~= '' then + allyFriendFoeC = aTokenMap[sAllyPathC].friendfoe; + end + + + -- set bFlanking=true, if a flanking ally is found that is not unconscious/paralyzed/petrified/prone/stunned/restrained - if actorFriendFoe == allyFriendFoe then + if (actorFriendFoe == allyFriendFoe) or (actorFriendFoe == allyFriendFoeB) or (actorFriendFoe == allyFriendFoeC) then local bAllyDisabled = TokenHelper.isActorDisabled5e(sAllyPath); - if (bAllyDisabled == false) and (allyNodePath ~= '') + local bAllyDisabledB = TokenHelper.isActorDisabled5e(sAllyPathB); + local bAllyDisabledC = TokenHelper.isActorDisabled5e(sAllyPathC); + + if ((bAllyDisabled == false) and (allyNodePath ~= '')) or ((bAllyDisabledB == false) and (allyNodePathB ~= '')) or ((bAllyDisabledC == false) and (allyNodePathC ~= '')) then bFlanking = true; end end - if bOutOfRange == true then bFlanking = false; end - + return bFlanking; -end \ No newline at end of file +end From 6ea94b08e83ee909029c65d336fe00b01c0a5309 Mon Sep 17 00:00:00 2001 From: Berwind <73523410+Berwind24@users.noreply.github.com> Date: Wed, 18 Nov 2020 06:13:49 -0600 Subject: [PATCH 2/2] Update flanking.lua Added missing positions for large flanking creatures --- scripts/flanking/flanking.lua | 373 ++++++++++++++++++++++++++-------- 1 file changed, 287 insertions(+), 86 deletions(-) diff --git a/scripts/flanking/flanking.lua b/scripts/flanking/flanking.lua index 223b120..a048033 100644 --- a/scripts/flanking/flanking.lua +++ b/scripts/flanking/flanking.lua @@ -52,33 +52,31 @@ function isFlanking(rActor, rTarget) -- determine direction of attack and set sDirection to N, NE, E, SE, S, SW, W, NW. local sDirection = ''; - local sDirectionB = ''; - local sDirectionC = ''; if aTokenMap[sActorPath].size == 'Medium' or aTokenMap[sActorPath].size == 'Small' or aTokenMap[sActorPath].size == 'Tiny' then if aTokenMap[sTargetPath].size == 'Medium' or aTokenMap[sTargetPath].size == 'Small' or aTokenMap[sTargetPath].size == 'Tiny' then - if (actorX == targetX) and (actorY == targetY + 1) then sDirection = 'N'; sDirectionB = 'N'; end + if (actorX == targetX) and (actorY == targetY + 1) then sDirection = 'N1'; end if (actorX == targetX - 1) and (actorY == targetY + 1) then sDirection = 'NE'; end - if (actorX == targetX - 1) and (actorY == targetY) then sDirection = 'E'; sDirectionB = 'E'; end + if (actorX == targetX - 1) and (actorY == targetY) then sDirection = 'E1'; end if (actorX == targetX - 1) and (actorY == targetY - 1) then sDirection = 'SE'; end - if (actorX == targetX) and (actorY == targetY - 1) then sDirection = 'S'; sDirectionB = 'S'; end + if (actorX == targetX) and (actorY == targetY - 1) then sDirection = 'S1'; end if (actorX == targetX + 1) and (actorY == targetY - 1) then sDirection = 'SW'; end - if (actorX == targetX + 1) and (actorY == targetY) then sDirection = 'W'; sDirectionB = 'W'; end + if (actorX == targetX + 1) and (actorY == targetY) then sDirection = 'W1'; end if (actorX == targetX + 1) and (actorY == targetY + 1) then sDirection = 'NW'; end end -- if target is large look for top left corner of target token. if aTokenMap[sTargetPath].size == 'Large' then - if (actorX == targetX) and (actorY == targetY + 2) then sDirection = 'N'; sDirectionB = 'N'; sDirectionC = 'N'; end - if (actorX == targetX + 1) and (actorY == targetY + 2) then sDirection = 'N'; sDirectionB = 'N'; sDirectionC = 'N'; end + if (actorX == targetX) and (actorY == targetY + 2) then sDirection = 'N1'; end + if (actorX == targetX + 1) and (actorY == targetY + 2) then sDirection = 'N2'; end if (actorX == targetX - 1) and (actorY == targetY + 2) then sDirection = 'NE'; end - if (actorX == targetX - 1) and (actorY == targetY) then sDirection = 'E'; sDirectionB = 'E'; sDirectionC = 'E';end - if (actorX == targetX - 1) and (actorY == targetY + 1) then sDirection = 'E'; sDirectionB = 'E'; sDirectionC = 'E'; end + if (actorX == targetX - 1) and (actorY == targetY) then sDirection = 'E1';end + if (actorX == targetX - 1) and (actorY == targetY + 1) then sDirection = 'E2'; end if (actorX == targetX - 1) and (actorY == targetY - 1) then sDirection = 'SE'; end - if (actorX == targetX) and (actorY == targetY - 1) then sDirection = 'S'; sDirectionB = 'S'; sDirectionC = 'S'; end - if (actorX == targetX + 1) and (actorY == targetY - 1) then sDirection = 'S'; sDirectionB = 'S'; sDirectionC = 'S'; end + if (actorX == targetX) and (actorY == targetY - 1) then sDirection = 'S1'; end + if (actorX == targetX + 1) and (actorY == targetY - 1) then sDirection = 'S2'; end if (actorX == targetX + 2) and (actorY == targetY - 1) then sDirection = 'SW'; end - if (actorX == targetX + 2) and (actorY == targetY) then sDirection = 'W'; sDirectionB = 'W'; sDirectionC = 'W'; end - if (actorX == targetX + 2) and (actorY == targetY + 1) then sDirection = 'W'; sDirectionB = 'W'; sDirectionC = 'W'; end + if (actorX == targetX + 2) and (actorY == targetY) then sDirection = 'W1'; end + if (actorX == targetX + 2) and (actorY == targetY + 1) then sDirection = 'W2'; end if (actorX == targetX + 2) and (actorY == targetY + 2) then sDirection = 'NW'; end end end @@ -86,37 +84,37 @@ function isFlanking(rActor, rTarget) --large actor medium or smaller target; searches from top left corner of actor if aTokenMap[sActorPath].size == 'Large' then if aTokenMap[sTargetPath].size == 'Medium' or aTokenMap[sTargetPath].size == 'Small' or aTokenMap[sTargetPath].size == 'Tiny' then - if (actorX == targetX) and (actorY == targetY + 1) then sDirection = 'N'; sDirectionB = 'N'; end - if (actorX == targetX - 1) and (actorY == targetY + 1) then sDirection = 'N'; sDirectionB = 'N'; end + if (actorX == targetX) and (actorY == targetY + 1) then sDirection = 'N2'; end + if (actorX == targetX - 1) and (actorY == targetY + 1) then sDirection = 'N1'; end if (actorX == targetX - 2) and (actorY == targetY + 1) then sDirection = 'NE'; end - if (actorX == targetX - 2) and (actorY == targetY) then sDirection = 'E'; sDirectionB = 'E'; end - if (actorX == targetX - 2) and (actorY == targetY - 1) then sDirection = 'E'; sDirectionB = 'E'; end + if (actorX == targetX - 2) and (actorY == targetY) then sDirection = 'E2'; end + if (actorX == targetX - 2) and (actorY == targetY - 1) then sDirection = 'E1'; end if (actorX == targetX - 2) and (actorY == targetY - 2) then sDirection = 'SE'; end - if (actorX == targetX) and (actorY == targetY - 2) then sDirection = 'S'; sDirectionB = 'S'; end - if (actorX == targetX - 1) and (actorY == targetY - 2) then sDirection = 'S'; sDirectionB = 'S'; end + if (actorX == targetX) and (actorY == targetY - 2) then sDirection = 'S2'; end + if (actorX == targetX - 1) and (actorY == targetY - 2) then sDirection = 'S1'; end if (actorX == targetX + 1) and (actorY == targetY - 2) then sDirection = 'SW'; end - if (actorX == targetX + 1) and (actorY == targetY) then sDirection = 'W'; sDirectionB = 'W'; end - if (actorX == targetX + 1) and (actorY == targetY - 1) then sDirection= 'W'; sDirectionB ='W'; end + if (actorX == targetX + 1) and (actorY == targetY) then sDirection = 'W2'; end + if (actorX == targetX + 1) and (actorY == targetY - 1) then sDirection= 'W1'; end if (actorX == targetX + 1) and (actorY == targetY + 1) then sDirection = 'NW'; end end --Large actor large target; searches from top left of actor to top left of target if aTokenMap[sTargetPath].size == 'Large' then - if (actorX == targetX - 1) and (actorY == targetY + 2) then sDirection = 'N'; sDirectionB = 'N'; sDirectionC = 'N'; end - if (actorX == targetX) and (actorY == targetY + 2) then sDirection = 'N'; sDirectionB = 'N'; sDirectionC = 'N'; end - if (actorX == targetX + 1) and (actorY == targetY + 2) then sDirection = 'N'; sDirectionB = 'N'; sDirectionC = 'N'; end + if (actorX == targetX - 1) and (actorY == targetY + 2) then sDirection = 'N1'; end + if (actorX == targetX) and (actorY == targetY + 2) then sDirection = 'N2'; end + if (actorX == targetX + 1) and (actorY == targetY + 2) then sDirection = 'N3'; end if (actorX == targetX - 2) and (actorY == targetY + 2) then sDirection = 'NE'; end - if (actorX == targetX - 2) and (actorY == targetY - 1) then sDirection = 'E'; sDirectionB = 'E'; sDirectionC = 'E'; end - if (actorX == targetX - 2) and (actorY == targetY) then sDirection = 'E'; sDirectionB = 'E'; sDirectionC = 'E'; end - if (actorX == targetX - 2) and (actorY == targetY + 1) then sDirection = 'E'; sDirectionB = 'E'; sDirectionC = 'E'; end + if (actorX == targetX - 2) and (actorY == targetY - 1) then sDirection = 'E1'; end + if (actorX == targetX - 2) and (actorY == targetY) then sDirection = 'E2'; end + if (actorX == targetX - 2) and (actorY == targetY + 1) then sDirection = 'E3'; end if (actorX == targetX - 2) and (actorY == targetY - 2) then sDirection = 'SE'; end - if (actorX == targetX - 1) and (actorY == targetY - 2) then sDirection = 'S'; sDirectionB = 'S'; sDirectionC = 'S'; end - if (actorX == targetX) and (actorY == targetY - 2) then sDirection = 'S'; sDirectionB = 'S'; sDirectionC = 'S'; end - if (actorX == targetX + 1) and (actorY == targetY - 2) then sDirection = 'S'; sDirectionB = 'S'; sDirectionC = 'S'; end + if (actorX == targetX - 1) and (actorY == targetY - 2) then sDirection = 'S1'; end + if (actorX == targetX) and (actorY == targetY - 2) then sDirection = 'S2'; end + if (actorX == targetX + 1) and (actorY == targetY - 2) then sDirection = 'S3'; end if (actorX == targetX + 2) and (actorY == targetY - 2) then sDirection = 'SW'; end - if (actorX == targetX + 2) and (actorY == targetY -1) then sDirection = 'W'; sDirectionB = 'W'; sDirectionC = 'W'; end - if (actorX == targetX + 2) and (actorY == targetY) then sDirection = 'W'; sDirectionB = 'W'; sDirectionC = 'W'; end - if (actorX == targetX + 2) and (actorY == targetY + 1) then sDirection = 'W'; sDirectionB = 'W'; sDirectionC = 'W'; end + if (actorX == targetX + 2) and (actorY == targetY -1) then sDirection = 'W1'; end + if (actorX == targetX + 2) and (actorY == targetY) then sDirection = 'W2'; end + if (actorX == targetX + 2) and (actorY == targetY + 1) then sDirection = 'W3'; end if (actorX == targetX + 2) and (actorY == targetY + 2) then sDirection = 'NW'; end end end @@ -125,37 +123,54 @@ function isFlanking(rActor, rTarget) local sAllyPath = ''; local sAllyPathB = ''; local sAllyPathC = ''; + local sAllyPathD = ''; + local sAllyPathE = ''; if aTokenMap[sTargetPath].size == 'Medium' or aTokenMap[sTargetPath].size == 'Small' or aTokenMap[sTargetPath].size == 'Tiny' then - if sDirection == 'N' then sAllyPath = TokenHelper.getActorByGrid(aTokenMap, targetX, targetY - 1); end - if sDirection == 'NE' then sAllyPath = TokenHelper.getActorByGrid(aTokenMap, targetX + 1, targetY - 1); end - if sDirection == 'E' then sAllyPath = TokenHelper.getActorByGrid(aTokenMap, targetX + 1, targetY); end - if sDirection == 'SE' then sAllyPath = TokenHelper.getActorByGrid(aTokenMap, targetX + 1, targetY + 1); end - if sDirection == 'S' then sAllyPath = TokenHelper.getActorByGrid(aTokenMap, targetX, targetY + 1); end - if sDirection == 'SW' then sAllyPath = TokenHelper.getActorByGrid(aTokenMap, targetX - 1, targetY + 1); end - if sDirection == 'W' then sAllyPath = TokenHelper.getActorByGrid(aTokenMap, targetX - 1, targetY); end - if sDirection == 'NW' then sAllyPath = TokenHelper.getActorByGrid(aTokenMap, targetX - 1, targetY - 1); end + if sDirection == 'N1' or sDirection == 'N2' then + sAllyPath = TokenHelper.getActorByGrid(aTokenMap, targetX, targetY - 1); end + if sDirection == 'NE' then + sAllyPath = TokenHelper.getActorByGrid(aTokenMap, targetX + 1, targetY - 1); end + if sDirection == 'E1' or sDirection == 'E2' then + sAllyPath = TokenHelper.getActorByGrid(aTokenMap, targetX + 1, targetY); end + if sDirection == 'SE' then + sAllyPath = TokenHelper.getActorByGrid(aTokenMap, targetX + 1, targetY + 1); end + if sDirection == 'S1' or sDirection == 'S2' then + sAllyPath = TokenHelper.getActorByGrid(aTokenMap, targetX, targetY + 1); end + if sDirection == 'SW' then + sAllyPath = TokenHelper.getActorByGrid(aTokenMap, targetX - 1, targetY + 1); end + if sDirection == 'W1' or sDirection == 'W2' then + sAllyPath = TokenHelper.getActorByGrid(aTokenMap, targetX - 1, targetY); end + if sDirection == 'NW' then + sAllyPath = TokenHelper.getActorByGrid(aTokenMap, targetX - 1, targetY - 1); end end -- large target token begins search from top left corner. if aTokenMap[sTargetPath].size == 'Large' then - if sDirection == 'N' then sAllyPath = TokenHelper.getActorByGrid(aTokenMap, targetX, targetY - 1); end - if sDirectionB == 'N' then sAllyPathB = TokenHelper.getActorByGrid(aTokenMap, targetX + 1, targetY - 1); end - if sDirection == 'NE' then sAllyPath = TokenHelper.getActorByGrid(aTokenMap, targetX + 2, targetY - 1); end - if sDirection == 'E' then sAllyPath = TokenHelper.getActorByGrid(aTokenMap, targetX + 2, targetY); end - if sDirectionB == 'E' then sAllyPathB = TokenHelper.getActorByGrid(aTokenMap, targetX + 2, targetY + 1); end - if sDirection == 'SE' then sAllyPath = TokenHelper.getActorByGrid(aTokenMap, targetX + 2, targetY + 2); end - if sDirection == 'S' then sAllyPath = TokenHelper.getActorByGrid(aTokenMap, targetX, targetY + 2); end - if sDirectionB == 'S' then sAllyPathB = TokenHelper.getActorByGrid(aTokenMap, targetX + 1, targetY + 2); end - if sDirection == 'SW' then sAllyPath = TokenHelper.getActorByGrid(aTokenMap, targetX - 1, targetY + 2); end - if sDirection == 'W' then sAllyPath = TokenHelper.getActorByGrid(aTokenMap, targetX - 1, targetY); end - if sDirectionB == 'W' then sAllyPathB = TokenHelper.getActorByGrid(aTokenMap, targetX - 1, targetY + 1); end - if sDirection == 'NW' then sAllyPath = TokenHelper.getActorByGrid(aTokenMap, targetX - 1, targetY - 1); end + if sDirection == 'N1' or sDirection == 'N2' or sDirection == 'N3' then + sAllyPath = TokenHelper.getActorByGrid(aTokenMap, targetX, targetY - 1); + sAllyPathB = TokenHelper.getActorByGrid(aTokenMap, targetX + 1, targetY - 1); end + if sDirection == 'NE' then + sAllyPath = TokenHelper.getActorByGrid(aTokenMap, targetX + 2, targetY - 1); end + if sDirection == 'E1' or sDirection == 'E2' or sDirection == 'E3' then + sAllyPath = TokenHelper.getActorByGrid(aTokenMap, targetX + 2, targetY); + sAllyPathB = TokenHelper.getActorByGrid(aTokenMap, targetX + 2, targetY + 1); end + if sDirection == 'SE' then + sAllyPath = TokenHelper.getActorByGrid(aTokenMap, targetX + 2, targetY + 2); end + if sDirection == 'S1' or sDirection == 'S2' or sDirection == 'S3' then + sAllyPath = TokenHelper.getActorByGrid(aTokenMap, targetX, targetY + 2); + sAllyPathB = TokenHelper.getActorByGrid(aTokenMap, targetX + 1, targetY + 2); end + if sDirection == 'SW' then + sAllyPath = TokenHelper.getActorByGrid(aTokenMap, targetX - 1, targetY + 2); end + if sDirection == 'W1' or sDirection == 'W2' or sDirection == 'W3' then + sAllyPath = TokenHelper.getActorByGrid(aTokenMap, targetX - 1, targetY); + sAllyPathB = TokenHelper.getActorByGrid(aTokenMap, targetX - 1, targetY + 1); end + if sDirection == 'NW' then + sAllyPath = TokenHelper.getActorByGrid(aTokenMap, targetX - 1, targetY - 1); end end --if large token found when looking for medium ally, then remove them if sAllyPath ~= '' then - if (aTokenMap[sAllyPath].size ~= 'Medium') and (aTokenMap[sAllyPath].size ~= 'Small') and (aTokenMap[sAllyPath].size ~= 'Tiny') then - sAllyPath = ''; end + if (aTokenMap[sAllyPath].size ~= 'Medium') and (aTokenMap[sAllyPath].size ~= 'Small') and (aTokenMap[sAllyPath].size ~= 'Tiny') then sAllyPath = ''; end end if sAllyPathB ~= '' then if (aTokenMap[sAllyPathB].size ~= 'Medium') and (aTokenMap[sAllyPathB].size ~= 'Small') and (aTokenMap[sAllyPathB].size ~= 'Tiny') @@ -166,38 +181,183 @@ function isFlanking(rActor, rTarget) if (sAllyPath == '') and (sAllyPathB == '') then --medium target;large ally if aTokenMap[sTargetPath].size == 'Medium' or aTokenMap[sTargetPath].size == 'Small' or aTokenMap[sTargetPath].size == 'Tiny' then - if sDirection == 'N' then sAllyPath = TokenHelper.getActorByGrid(aTokenMap, targetX, targetY - 2); end - if sDirectionB == 'N' then sAllyPathB = TokenHelper.getActorByGrid(aTokenMap, targetX - 1, targetY - 2); end - if sDirection == 'NE' then sAllyPath = TokenHelper.getActorByGrid(aTokenMap, targetX + 1, targetY - 2); end - if sDirection == 'E' then sAllyPath = TokenHelper.getActorByGrid(aTokenMap, targetX + 1, targetY); end - if sDirectionB == 'E' then sAllyPathB = TokenHelper.getActorByGrid(aTokenMap, targetX + 1, targetY - 1); end - if sDirection == 'SE' then sAllyPath = TokenHelper.getActorByGrid(aTokenMap, targetX + 1, targetY + 1); end - if sDirection == 'S' then sAllyPath = TokenHelper.getActorByGrid(aTokenMap, targetX, targetY + 1); end - if sDirectionB == 'S' then sAllyPathB = TokenHelper.getActorByGrid(aTokenMap, targetX - 1, targetY + 1); end - if sDirection == 'SW' then sAllyPath = TokenHelper.getActorByGrid(aTokenMap, targetX - 2, targetY + 1); end - if sDirection == 'W' then sAllyPath = TokenHelper.getActorByGrid(aTokenMap, targetX - 2, targetY); end - if sDirectionB == 'W' then sAllyPathB = TokenHelper.getActorByGrid(aTokenMap, targetX - 2, targetY - 1); end - if sDirection == 'NW' then sAllyPath = TokenHelper.getActorByGrid(aTokenMap, targetX - 2, targetY - 2); end + if sDirection == 'N1' then + sAllyPath = TokenHelper.getActorByGrid(aTokenMap, targetX, targetY - 2); + sAllyPathB = TokenHelper.getActorByGrid(aTokenMap, targetX - 1, targetY - 2); + if aTokenMap[sActorPath].size == 'Large' then + sAllyPathC = TokenHelper.getActorByGrid(aTokenMap, targetX + 1, targetY - 2); + sAllyPathD = TokenHelper.getActorByGrid(aTokenMap, targetX + 1, targetY - 1); end + end + if sDirection == 'N2' then + sAllyPath = TokenHelper.getActorByGrid(aTokenMap, targetX, targetY - 2); + sAllyPathB = TokenHelper.getActorByGrid(aTokenMap, targetX - 1, targetY - 2); + if aTokenMap[sActorPath].size == 'Large' then + sAllyPathC = TokenHelper.getActorByGrid(aTokenMap, targetX - 2, targetY - 2); + sAllyPathD = TokenHelper.getActorByGrid(aTokenMap, targetX - 2, targetY - 1); end + end + if sDirection == 'NE' then + sAllyPath = TokenHelper.getActorByGrid(aTokenMap, targetX + 1, targetY - 2); + sAllyPathB = TokenHelper.getActorByGrid(aTokenMap, targetX, targetY - 2); + sAllyPathC = TokenHelper.getActorByGrid(aTokenMap, targetX + 1, targetY - 1); end + if sDirection == 'E1' then + sAllyPath = TokenHelper.getActorByGrid(aTokenMap, targetX + 1, targetY); + sAllyPathB = TokenHelper.getActorByGrid(aTokenMap, targetX + 1, targetY - 1); + if aTokenMap[sActorPath].size == 'Large' then + sAllyPathC = TokenHelper.getActorByGrid(aTokenMap, targetX + 1, targetY + 1); + sAllyPathD = TokenHelper.getActorByGrid(aTokenMap, targetX, targetY + 1); end + end + if sDirection == 'E2' then + sAllyPath = TokenHelper.getActorByGrid(aTokenMap, targetX + 1, targetY); + sAllyPathB = TokenHelper.getActorByGrid(aTokenMap, targetX + 1, targetY - 1); + if aTokenMap[sActorPath].size == 'Large' then + sAllyPathC = TokenHelper.getActorByGrid(aTokenMap, targetX + 1, targetY - 2); + sAllyPathD = TokenHelper.getActorByGrid(aTokenMap, targetX, targetY - 2); end + end + if sDirection == 'SE' then + sAllyPath = TokenHelper.getActorByGrid(aTokenMap, targetX + 1, targetY + 1); + sAllyPathB = TokenHelper.getActorByGrid(aTokenMap, targetX + 1, targetY); + sAllyPathC = TokenHelper.getActorByGrid(aTokenMap, targetX, targetY + 1); end + if sDirection == 'S1' then + sAllyPath = TokenHelper.getActorByGrid(aTokenMap, targetX, targetY + 1); + sAllyPathB = TokenHelper.getActorByGrid(aTokenMap, targetX - 1, targetY + 1); + if aTokenMap[sActorPath].size == 'Large' then + sAllyPathC = TokenHelper.getActorByGrid(aTokenMap, targetX + 1, targetY + 1); + sAllyPathD = TokenHelper.getActorByGrid(aTokenMap, targetX + 1, targetY); end + end + if sDirection == 'S2' then + sAllyPath = TokenHelper.getActorByGrid(aTokenMap, targetX, targetY + 1); + sAllyPathB = TokenHelper.getActorByGrid(aTokenMap, targetX - 1, targetY + 1); + if aTokenMap[sActorPath].size == 'Large' then + sAllyPathC = TokenHelper.getActorByGrid(aTokenMap, targetX - 2, targetY + 1); + sAllyPathD = TokenHelper.getActorByGrid(aTokenMap, targetX - 2, targetY); end + end + if sDirection == 'SW' then + sAllyPath = TokenHelper.getActorByGrid(aTokenMap, targetX - 2, targetY + 1); + sAllyPathB = TokenHelper.getActorByGrid(aTokenMap, targetX - 1, targetY + 1); + sAllyPathC = TokenHelper.getActorByGrid(aTokenMap, targetX - 2, targetY); end + if sDirection == 'W1' then + sAllyPath = TokenHelper.getActorByGrid(aTokenMap, targetX - 2, targetY); + sAllyPathB = TokenHelper.getActorByGrid(aTokenMap, targetX - 2, targetY - 1); + if aTokenMap[sActorPath].size == 'Large' then + sAllyPathC = TokenHelper.getActorByGrid(aTokenMap, targetX - 2, targetY + 1); + sAllyPathD = TokenHelper.getActorByGrid(aTokenMap, targetX - 1, targetY + 1); end + end + if sDirection == 'W2' then + sAllyPath = TokenHelper.getActorByGrid(aTokenMap, targetX - 2, targetY); + sAllyPathB = TokenHelper.getActorByGrid(aTokenMap, targetX - 2, targetY - 1); + if aTokenMap[sActorPath].size == 'Large' then + sAllyPathC = TokenHelper.getActorByGrid(aTokenMap, targetX - 2, targetY - 2); + sAllyPathD = TokenHelper.getActorByGrid(aTokenMap, targetX - 1, targetY - 2); end + end + if sDirection == 'NW' then + sAllyPath = TokenHelper.getActorByGrid(aTokenMap, targetX - 2, targetY - 2); + sAllyPathB = TokenHelper.getActorByGrid(aTokenMap, targetX - 2, targetY - 1); + sAllyPathC = TokenHelper.getActorByGrid(aTokenMap, targetX - 1, targetY - 2); end end --large target; large ally if aTokenMap[sTargetPath].size == 'Large' then - if sDirection == 'N' then sAllyPath = TokenHelper.getActorByGrid(aTokenMap, targetX - 1, targetY - 2); end - if sDirectionB == 'N' then sAllyPathB = TokenHelper.getActorByGrid(aTokenMap, targetX, targetY - 2); end - if sDirectionC == 'N' then sAllyPathC = TokenHelper.getActorByGrid(aTokenMap, targetX + 1, targetY - 2); end - if sDirection == 'NE' then sAllyPath = TokenHelper.getActorByGrid(aTokenMap, targetX + 2, targetY - 2); end - if sDirection == 'E' then sAllyPath = TokenHelper.getActorByGrid(aTokenMap, targetX + 2, targetY - 1); end - if sDirectionB == 'E' then sAllyPathB = TokenHelper.getActorByGrid(aTokenMap, targetX + 2, targetY); end - if sDirectionB == 'E' then sAllyPathC = TokenHelper.getActorByGrid(aTokenMap, targetX + 2, targetY + 1); end - if sDirection == 'SE' then sAllyPath = TokenHelper.getActorByGrid(aTokenMap, targetX + 2, targetY + 2); end - if sDirection == 'S' then sAllyPath = TokenHelper.getActorByGrid(aTokenMap, targetX - 1, targetY + 2); end - if sDirectionB == 'S' then sAllyPathB = TokenHelper.getActorByGrid(aTokenMap, targetX, targetY + 2); end - if sDirectionC == 'S' then sAllyPathC = TokenHelper.getActorByGrid(aTokenMap, targetX + 1, targetY + 2); end - if sDirection == 'SW' then sAllyPath = TokenHelper.getActorByGrid(aTokenMap, targetX - 2, targetY + 2); end - if sDirection == 'W' then sAllyPath = TokenHelper.getActorByGrid(aTokenMap, targetX - 2, targetY - 1); end - if sDirectionB == 'W' then sAllyPathB = TokenHelper.getActorByGrid(aTokenMap, targetX - 2, targetY); end - if sDirectionC == 'W' then sAllyPathC = TokenHelper.getActorByGrid(aTokenMap, targetX - 2, targetY + 1); end - if sDirection == 'NW' then sAllyPath = TokenHelper.getActorByGrid(aTokenMap, targetX - 2, targetY - 2); end + if sDirection == 'N1' then + sAllyPath = TokenHelper.getActorByGrid(aTokenMap, targetX - 1, targetY - 2); + sAllyPathB = TokenHelper.getActorByGrid(aTokenMap, targetX, targetY - 2); + sAllyPathC = TokenHelper.getActorByGrid(aTokenMap, targetX + 1, targetY - 2); + if aTokenMap[sActorPath].size == 'Large' then + sAllyPathD = TokenHelper.getActorByGrid(aTokenMap, targetX + 2, targetY - 2); + sAllyPathE = TokenHelper.getActorByGrid(aTokenMap, targetX + 2, targetY - 1); end + end + if sDirection == 'N2' then + sAllyPath = TokenHelper.getActorByGrid(aTokenMap, targetX - 1, targetY - 2); + sAllyPathB = TokenHelper.getActorByGrid(aTokenMap, targetX, targetY - 2); + sAllyPathC = TokenHelper.getActorByGrid(aTokenMap, targetX + 1, targetY - 2); end + if sDirection == 'N3' then + sAllyPath = TokenHelper.getActorByGrid(aTokenMap, targetX - 1, targetY - 2); + sAllyPathB = TokenHelper.getActorByGrid(aTokenMap, targetX, targetY - 2); + sAllyPathC = TokenHelper.getActorByGrid(aTokenMap, targetX + 1, targetY - 2); + if aTokenMap[sActorPath].size == 'Large' then + sAllyPathD = TokenHelper.getActorByGrid(aTokenMap, targetX - 2, targetY - 2); + sAllyPathE = TokenHelper.getActorByGrid(aTokenMap, targetX - 2, targetY - 1); end + end + if sDirection == 'NE' then + sAllyPath = TokenHelper.getActorByGrid(aTokenMap, targetX + 2, targetY - 2); + sAllyPathB = TokenHelper.getActorByGrid(aTokenMap, targetX + 1, targetY - 2); + sAllyPathC = TokenHelper.getActorByGrid(aTokenMap, targetX + 2, targetY - 1); + end + if sDirection == 'E1' then + sAllyPath = TokenHelper.getActorByGrid(aTokenMap, targetX + 2, targetY - 1); + sAllyPathB = TokenHelper.getActorByGrid(aTokenMap, targetX + 2, targetY); + sAllyPathC = TokenHelper.getActorByGrid(aTokenMap, targetX + 2, targetY + 1); + if aTokenMap[sActorPath].size == 'Large' then + sAllyPathD = TokenHelper.getActorByGrid(aTokenMap, targetX + 2, targetY + 2); + sAllyPathE = TokenHelper.getActorByGrid(aTokenMap, targetX + 1, targetY + 2); end + end + if sDirection == 'E2' then + sAllyPath = TokenHelper.getActorByGrid(aTokenMap, targetX + 2, targetY - 1); + sAllyPathB = TokenHelper.getActorByGrid(aTokenMap, targetX + 2, targetY); + sAllyPathC = TokenHelper.getActorByGrid(aTokenMap, targetX + 2, targetY + 1); end + if sDirection == 'E3' then + sAllyPath = TokenHelper.getActorByGrid(aTokenMap, targetX + 2, targetY - 1); + sAllyPathB = TokenHelper.getActorByGrid(aTokenMap, targetX + 2, targetY); + sAllyPathC = TokenHelper.getActorByGrid(aTokenMap, targetX + 2, targetY + 1); + if aTokenMap[sActorPath].size == 'Large' then + sAllyPathD = TokenHelper.getActorByGrid(aTokenMap, targetX + 2, targetY - 2); + sAllyPathE = TokenHelper.getActorByGrid(aTokenMap, targetX - 2, targetY + 1); end + end + if sDirection == 'SE' then + sAllyPath = TokenHelper.getActorByGrid(aTokenMap, targetX + 2, targetY + 2); + sAllyPathB = TokenHelper.getActorByGrid(aTokenMap, targetX + 2, targetY + 1); + sAllyPathC = TokenHelper.getActorByGrid(aTokenMap, targetX + 1, targetY + 2); + end + if sDirection == 'S1' then + sAllyPath = TokenHelper.getActorByGrid(aTokenMap, targetX - 1, targetY + 2); + sAllyPathB = TokenHelper.getActorByGrid(aTokenMap, targetX, targetY + 2); + sAllyPathC = TokenHelper.getActorByGrid(aTokenMap, targetX + 1, targetY + 2); + if aTokenMap[sActorPath].size == 'Large' then + sAllyPathD = TokenHelper.getActorByGrid(aTokenMap, targetX + 2, targetY + 2); + sAllyPathE = TokenHelper.getActorByGrid(aTokenMap, targetX + 2, targetY + 1); end + end + if sDirection == 'S2' then + sAllyPath = TokenHelper.getActorByGrid(aTokenMap, targetX - 1, targetY + 2); + sAllyPathB = TokenHelper.getActorByGrid(aTokenMap, targetX, targetY + 2); + sAllyPathC = TokenHelper.getActorByGrid(aTokenMap, targetX + 1, targetY + 2); end + if sDirection == 'S3' then + sAllyPath = TokenHelper.getActorByGrid(aTokenMap, targetX - 1, targetY + 2); + sAllyPathB = TokenHelper.getActorByGrid(aTokenMap, targetX, targetY + 2); + sAllyPathC = TokenHelper.getActorByGrid(aTokenMap, targetX + 1, targetY + 2); + if aTokenMap[sActorPath].size == 'Large' then + sAllyPathD = TokenHelper.getActorByGrid(aTokenMap, targetX - 2, targetY + 2); + sAllyPathE = TokenHelper.getActorByGrid(aTokenMap, targetX - 2, targetY + 1); end + end + if sDirection == 'SW' then + sAllyPath = TokenHelper.getActorByGrid(aTokenMap, targetX - 2, targetY + 2); + sAllyPathB = TokenHelper.getActorByGrid(aTokenMap, targetX - 2, targetY + 1); + sAllyPathC = TokenHelper.getActorByGrid(aTokenMap, targetX - 1, targetY + 2); + end + if sDirection == 'W1' then + sAllyPath = TokenHelper.getActorByGrid(aTokenMap, targetX - 2, targetY - 1); + sAllyPathB = TokenHelper.getActorByGrid(aTokenMap, targetX - 2, targetY); + sAllyPathC = TokenHelper.getActorByGrid(aTokenMap, targetX - 2, targetY + 1); + if aTokenMap[sActorPath].size == 'Large' then + sAllyPathD = TokenHelper.getActorByGrid(aTokenMap, targetX - 2, targetY + 2); + sAllyPathE = TokenHelper.getActorByGrid(aTokenMap, targetX - 1, targetY + 2); end + end + if sDirection == 'W2' then + sAllyPath = TokenHelper.getActorByGrid(aTokenMap, targetX - 2, targetY - 1); + sAllyPathB = TokenHelper.getActorByGrid(aTokenMap, targetX - 2, targetY); + sAllyPathC = TokenHelper.getActorByGrid(aTokenMap, targetX - 2, targetY + 1); + end + if sDirection == 'W3' then + sAllyPath = TokenHelper.getActorByGrid(aTokenMap, targetX - 2, targetY - 1); + sAllyPathB = TokenHelper.getActorByGrid(aTokenMap, targetX - 2, targetY); + sAllyPathC = TokenHelper.getActorByGrid(aTokenMap, targetX - 2, targetY + 1); + if aTokenMap[sActorPath].size == 'Large' then + sAllyPathD = TokenHelper.getActorByGrid(aTokenMap, targetX - 2, targetY - 2); + sAllyPathE = TokenHelper.getActorByGrid(aTokenMap, targetX - 1, targetY - 2); end + end + if sDirection == 'NW' then + sAllyPath = TokenHelper.getActorByGrid(aTokenMap, targetX - 2, targetY - 2); + sAllyPathB = TokenHelper.getActorByGrid(aTokenMap, targetX - 2, targetY - 1); + sAllyPathC = TokenHelper.getActorByGrid(aTokenMap, targetX - 1, targetY - 2); + end end --if medium ally found while looking for large ally, remove medium @@ -213,12 +373,22 @@ function isFlanking(rActor, rTarget) if aTokenMap[sAllyPathC].size ~= 'Large' then sAllyPathC = ''; end end + if (sAllyPathD ~= '') then + if aTokenMap[sAllyPathD].size ~= 'Large' then + sAllyPathD = ''; end + end + if (sAllyPathE ~= '') then + if aTokenMap[sAllyPathE].size ~= 'Large' then + sAllyPathE = ''; end + end end -- get ally CT entry local allyNodePath = ''; local allyNodePathB = ''; local allyNodePathC = ''; + local allyNodePathD = ''; + local allyNodePathE = ''; local aEntries = CombatManager.getSortedCombatantList(); local nIndexActive = 0; if sAllyPath ~= '' then @@ -245,6 +415,22 @@ function isFlanking(rActor, rTarget) nIndexActive = nIndexActive + 1; end end + if sAllyPathD ~= '' then + for i = nIndexActive + 1, #aEntries do + local entryNodePath = DB.getPath(aEntries[i]); + if entryNodePath == sAllyPathD then allyNodePathD = entryNodePath; end + + nIndexActive = nIndexActive + 1; + end + end + if sAllyPathE ~= '' then + for i = nIndexActive + 1, #aEntries do + local entryNodePath = DB.getPath(aEntries[i]); + if entryNodePath == sAllyPathE then allyNodePathE = entryNodePath; end + + nIndexActive = nIndexActive + 1; + end + end -- consider altitude -- get nodes -> tokens -> token height @@ -253,12 +439,16 @@ function isFlanking(rActor, rTarget) local allyNode = CombatManager.getCTFromNode(allyNodePath); local allyNodeB = CombatManager.getCTFromNode(allyNodePathB); local allyNodeC = CombatManager.getCTFromNode(allyNodePathC); + local allyNodeD = CombatManager.getCTFromNode(allyNodePathD); + local allyNodeE = CombatManager.getCTFromNode(allyNodePathE); local actorToken = CombatManager.getTokenFromCT(actorNode); local targetToken = CombatManager.getTokenFromCT(targetNode); local allyToken = CombatManager.getTokenFromCT(allyNode); local allyTokenB = CombatManager.getTokenFromCT(allyNodeB); local allyTokenC = CombatManager.getTokenFromCT(allyNodeC); + local allyTokenD = CombatManager.getTokenFromCT(allyNodeD); + local allyTokenE = CombatManager.getTokenFromCT(allyNodeE); -- get height local actorHeight = TokenHeight.getTokenHeight(actorToken); @@ -266,12 +456,16 @@ function isFlanking(rActor, rTarget) local allyHeight = TokenHeight.getTokenHeight(allyToken); local allyHeightB = TokenHeight.getTokenHeight(allyTokenB); local allyHeightC = TokenHeight.getTokenHeight(allyTokenC); + local allyHeightD = TokenHeight.getTokenHeight(allyTokenD); + local allyHeightE = TokenHeight.getTokenHeight(allyTokenE); -- if either actor or ally are out of range of melee attack, height wise, then no flanking benefit local bOutOfRange = false; if (math.sqrt(actorHeight^2 - targetHeight^2) > 5) or (math.sqrt(allyHeight^2 - targetHeight^2) > 5) then bOutOfRange = true end if (math.sqrt(actorHeight^2 - targetHeight^2) > 5) or (math.sqrt(allyHeightB^2 - targetHeight^2) > 5) then bOutOfRange = true end if (math.sqrt(actorHeight^2 - targetHeight^2) > 5) or (math.sqrt(allyHeightC^2 - targetHeight^2) > 5) then bOutOfRange = true end + if (math.sqrt(actorHeight^2 - targetHeight^2) > 5) or (math.sqrt(allyHeightD^2 - targetHeight^2) > 5) then bOutOfRange = true end + if (math.sqrt(actorHeight^2 - targetHeight^2) > 5) or (math.sqrt(allyHeightE^2 - targetHeight^2) > 5) then bOutOfRange = true end local actorFriendFoe = aTokenMap[sActorPath].friendfoe; local allyFriendFoe = ''; @@ -285,7 +479,12 @@ function isFlanking(rActor, rTarget) if sAllyPathC ~= '' then allyFriendFoeC = aTokenMap[sAllyPathC].friendfoe; end - + if sAllyPathD ~= '' then + allyFriendFoeD = aTokenMap[sAllyPathD].friendfoe; + end + if sAllyPathE ~= '' then + allyFriendFoeE = aTokenMap[sAllyPathE].friendfoe; + end @@ -294,8 +493,10 @@ function isFlanking(rActor, rTarget) local bAllyDisabled = TokenHelper.isActorDisabled5e(sAllyPath); local bAllyDisabledB = TokenHelper.isActorDisabled5e(sAllyPathB); local bAllyDisabledC = TokenHelper.isActorDisabled5e(sAllyPathC); + local bAllyDisabledD = TokenHelper.isActorDisabled5e(sAllyPathD); + local bAllyDisabledE = TokenHelper.isActorDisabled5e(sAllyPathE); - if ((bAllyDisabled == false) and (allyNodePath ~= '')) or ((bAllyDisabledB == false) and (allyNodePathB ~= '')) or ((bAllyDisabledC == false) and (allyNodePathC ~= '')) + if ((bAllyDisabled == false) and (allyNodePath ~= '')) or ((bAllyDisabledB == false) and (allyNodePathB ~= '')) or ((bAllyDisabledC == false) and (allyNodePathC ~= '')) or ((bAllyDisabledD == false) and (allyNodePathD ~= '')) or ((bAllyDisabledE == false) and (allyNodePathE ~= '')) then bFlanking = true; end