UGCProjects/GZJ/Script/Blueprint/AI/BTAttachment_FindTarget.lua
2025-01-08 22:46:12 +08:00

63 lines
2.2 KiB
Lua

---@class BTAttachment_FindTarget_C:BTAttachment_LuaBase
---@field Target FBlackboardKeySelector
---@field TrackPlayerRange float
--Edit Below--
local BTAttachment_FindTarget = {}
-- -- tick function
function BTAttachment_FindTarget:ReceiveTickAI(OwnerController, ControlledPawn, DeltaSeconds)
local GameState = UGCGameSystem.GameState
if not UE.IsValid(GameState) or not ControlledPawn then
return
end
if ControlledPawn.bIsStun == true then
BTFunctionLibrary.SetBlackboardValueAsObject(self, self.Target, nil)
return
end
local CurrentTarget = nil
local PlayersInArena = GameState:GetPlayersInArena()
if table.getCount(PlayersInArena) <= 0 then
CurrentTarget = GameState:GetCrystal()
elseif ControlledPawn.TrackPlayer and ControlledPawn.TrackPlayer.IsInArena then
CurrentTarget = ControlledPawn.TrackPlayer
else
local PawnLocation = ControlledPawn:K2_GetActorLocation()
local MinDist = 100000
for _, Player in pairs(PlayersInArena) do
if UE.IsValid(Player) and UGCPlayerStateSystem.IsAlive(UGCPawnAttrSystem.GetPlayerKeyInt64(Player)) then
local PlayerLocation = Player:K2_GetActorLocation()
local Dist = VectorHelper.GetDistance(PawnLocation, PlayerLocation)
if Dist < MinDist then
MinDist = Dist
CurrentTarget = Player
end
end
end
if CurrentTarget then
local TargetTrackPlayerRange = ControlledPawn.TrackPlayerRange or self.TrackPlayerRange
if MinDist > TargetTrackPlayerRange then
CurrentTarget = GameState:GetCrystal()
end
end
end
BTFunctionLibrary.SetBlackboardValueAsObject(self, self.Target, CurrentTarget)
end
-- -- attachment became active
-- function BTAttachment_FindTarget:ReceiveActivationAI(OwnerController, ControlledPawn)
-- end
-- -- attachment became inactive
-- function BTAttachment_FindTarget:ReceiveDeactivationAI(OwnerController, ControlledPawn)
-- end
-- -- task search enters branch of tree
-- function BTAttachment_FindTarget:ReceiveSearchStartAI(OwnerController, ControlledPawn)
-- end
return BTAttachment_FindTarget