ActionFunction = function(unit, action)
local result = false
local actionBp = HeroAIActionTemplates[action.ActionName]
local aiBrain = unit:GetAIBrain()
-- Check to see if there is a nearby flag that we control - if not, then don't continue
local flags = aiBrain:GetUnitsAroundPoint( categories.FLAG, unit:GetPosition(), 32, 'Ally' )
if table.empty(flags) then
return
end
flags = SortEntitiesByDistanceXZ(unit.Position, flags)
--# 0.27.07 added local flag = false per miri - this SHOULD keep the ai from recasting locks on locked flags
local flag = false
for k,v in flags do --Mithy: Add check for being locked before proceeding
if aiBrain:GetBlipsAroundPoint( categories.HERO, v.Position, 20, 'Enemy' ) > 0 and v.CanBeCaptured and not v.BeingLocked then
flag = v
break
end
end
if not flag then
return
end
local ready = GetReadyAbility(unit, actionBp.Abilities)
if(ready) then
result = true
end
if(result) then
local captureUnits = flag:GetCaptureList()
for k,v in captureUnits do
if (v == 'ugbportal01') then
local announcement = "Lock Portal flag."
AIUtils.AIChat(unit, announcement)
elseif (v == 'unbidol01') then
local announcement = "Lock Valor flag."
AIUtils.AIChat(unit, announcement)
else
#Do nothing
end
end
--Mithy: Mark this flag as being locked until we're done casting (at which point it will be non-capturable)
flag.BeingLocked = true
local endResult = AIAbility.UseTargetedAbility(unit, ready, flag, actionBp.ActionTimeout)
flag.BeingLocked = nil
return endResult
else
return false
end
end,