58 lines
1.9 KiB
Lua
58 lines
1.9 KiB
Lua
local SimpleSkillSelector = require("Script.SimpleSkill.Selector.SimpleSkillSelector")
|
|
local SimpleSkillSelector_NearestPawn = LuaClass("SimpleSkillSelector_NearestPawn", SimpleSkillSelector)
|
|
|
|
function SimpleSkillSelector_NearestPawn:ctor()
|
|
SimpleSkillSelector_NearestPawn.super.ctor(self)
|
|
end
|
|
|
|
function SimpleSkillSelector_NearestPawn:InitSelectorFromData(SelectorData, CasterPawn)
|
|
SimpleSkillSelector.InitSelectorFromData(self, SelectorData, CasterPawn)
|
|
end
|
|
|
|
--- 子类实现
|
|
function SimpleSkillSelector_NearestPawn:ActivateSelector()
|
|
SimpleSkillSelector.ActivateSelector(self)
|
|
|
|
UE.Log("[SimpleSkillSelector_NearestPawn] activated")
|
|
|
|
self:GetNearestPawn()
|
|
end
|
|
|
|
function SimpleSkillSelector_NearestPawn:GetNearestPawn()
|
|
local PawnLoc = self.CasterPawn:K2_GetActorLocation()
|
|
|
|
local AllMonsters = {}
|
|
|
|
if self.CasterPawn.IsInArena then
|
|
local AttackWaveSpawner = UGCGameSystem.GameState:GetAttackWaveSpawner()
|
|
if AttackWaveSpawner then
|
|
AllMonsters = AttackWaveSpawner.SpawnedMonsters
|
|
end
|
|
else
|
|
local TargetSpawner = UGCGameSystem.GameState:GetSpawnerByPlayerKey(self.CasterPawn.PlayerKey)
|
|
if TargetSpawner then
|
|
AllMonsters = TargetSpawner.SpawnedMonsters
|
|
end
|
|
end
|
|
|
|
local Target = nil
|
|
local MinDist = 999999
|
|
for _, Monster in pairs(AllMonsters) do
|
|
if Monster ~= nil and UE.IsValid(Monster) then
|
|
if UGCSimpleCharacterSystem.GetHealth(Monster) > 0 then
|
|
local MonsterLoc = Monster:K2_GetActorLocation()
|
|
local Dist = VectorHelper.GetDistance(PawnLoc, MonsterLoc)
|
|
if Dist <= MinDist then
|
|
MinDist = Dist
|
|
Target = Monster
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
if Target ~= nil then
|
|
table.insert(self.TargetPawns, Target)
|
|
end
|
|
end
|
|
|
|
return SimpleSkillSelector_NearestPawn; |