100 lines
3.7 KiB
Lua
100 lines
3.7 KiB
Lua
local SimpleSkillTask = require("Script.SimpleSkill.Task.SimpleSkillTask")
|
|
local SimpleSkillTask_Crack = LuaClass("SimpleSkillTask_Crack", SimpleSkillTask)
|
|
|
|
SimpleSkillTask_Crack.CrackTargetLimitNumTable = {1, 2, 3, 4}
|
|
SimpleSkillTask_Crack.CurCrackTargetLimitNum = 0
|
|
|
|
SimpleSkillTask_Crack.BindWeapon = nil
|
|
|
|
function SimpleSkillTask_Crack:ctor(OwnerSkill)
|
|
SimpleSkillTask_Crack.super.ctor(self, OwnerSkill)
|
|
end
|
|
|
|
function SimpleSkillTask_Crack:InitTaskFromData(TaskData, CasterPawn)
|
|
SimpleSkillTask.InitTaskFromData(self, TaskData, CasterPawn)
|
|
self.TaskName = "Crack"
|
|
end
|
|
|
|
function SimpleSkillTask_Crack:UpdateSkillLevel(NewSkillLevel)
|
|
SimpleSkillTask.UpdateSkillLevel(self, NewSkillLevel)
|
|
|
|
self.CurCrackTargetLimitNum = self.CrackTargetLimitNumTable[NewSkillLevel]
|
|
end
|
|
|
|
function SimpleSkillTask_Crack:ActivateTask()
|
|
SimpleSkillTask.ActivateTask(self)
|
|
|
|
local CasterPawnWeapon = self.CasterPawn:GetWeaponComponent()
|
|
if CasterPawnWeapon ~= nil and UE.IsValid(CasterPawnWeapon) then
|
|
self.BindWeapon = CasterPawnWeapon
|
|
self.BindWeapon.OnFireDelegate:Add(self.OnCasterPawnFire, self)
|
|
else
|
|
self.CasterPawn.OnWeaponSpawnedDelegate:Add(self.OnWeaponSpawned, self)
|
|
end
|
|
end
|
|
|
|
function SimpleSkillTask_Crack:DeactivateTask()
|
|
self.CasterPawn.OnWeaponSpawnedDelegate:Remove(self.OnWeaponSpawned, self)
|
|
|
|
if self.BindWeapon ~= nil and UE.IsValid(self.BindWeapon) then
|
|
self.BindWeapon.OnFireDelegate:Remove(self.OnCasterPawnFire, self)
|
|
self.BindWeapon = nil
|
|
end
|
|
end
|
|
|
|
function SimpleSkillTask_Crack:OnWeaponSpawned(Pawn)
|
|
if Pawn ~= self.CasterPawn then
|
|
return
|
|
end
|
|
|
|
local CasterPawnWeapon = self.CasterPawn:GetWeaponComponent()
|
|
if CasterPawnWeapon ~= nil and UE.IsValid(CasterPawnWeapon) then
|
|
self.BindWeapon = CasterPawnWeapon
|
|
self.BindWeapon.OnFireDelegate:Add(self.OnCasterPawnFire, self)
|
|
end
|
|
end
|
|
|
|
function SimpleSkillTask_Crack:OnCasterPawnFire(Weapon, BaseDamage)
|
|
if self.BindWeapon ~= Weapon then
|
|
return
|
|
end
|
|
|
|
local ShootTarget = Weapon.TargetMonster
|
|
local SphereLoc = ShootTarget:K2_GetActorLocation()
|
|
SphereLoc.Z = SphereLoc.Z - ShootTarget.CapsuleComponent.CapsuleHalfHeight
|
|
|
|
local ObjectTypes = {}
|
|
local ActorClassFilter = UE.LoadClass(BPClassPath.MonsterBase)
|
|
local ActorsToIgnore = {self.CasterPawn, ShootTarget}
|
|
local Radius = 200
|
|
local RetVal, OutActors = KismetSystemLibrary.SphereOverlapActors(self.CasterPawn, SphereLoc, Radius, ObjectTypes, ActorClassFilter, ActorsToIgnore)
|
|
|
|
if GlobalConfigs.OpenDebug then
|
|
UnrealNetwork.CallUnrealRPC_Multicast(self.CasterPawn, "DrawDebugSphere", VectorHelper.ToLuaTable(SphereLoc), {1,0,0,1}, Radius)
|
|
end
|
|
|
|
local NearbyPawns = {}
|
|
if RetVal then
|
|
local PickedMonsterNum = 0
|
|
for _, Monster in pairs(OutActors) do
|
|
if PickedMonsterNum >= self.CurCrackTargetLimitNum then
|
|
break
|
|
end
|
|
|
|
if Monster ~= nil and UE.IsValid(Monster) and UGCSimpleCharacterSystem.GetHealth(Monster) > 0 then
|
|
table.insert(NearbyPawns, Monster)
|
|
PickedMonsterNum = PickedMonsterNum + 1
|
|
end
|
|
end
|
|
end
|
|
if not table.isEmpty(NearbyPawns) then
|
|
local DamageAmount = BaseDamage * 0.25
|
|
local EventInstigator = UGCGameSystem.GetPlayerControllerByPlayerKey(self.CasterPawn.PlayerKey)
|
|
for _, Monster in pairs(NearbyPawns) do
|
|
UGCGameSystem.ApplyDamage(Monster, DamageAmount, EventInstigator, self.CasterPawn, EDamageType.ShootDamage)
|
|
end
|
|
self:EnableSkillEffect(self.CasterPawn, NearbyPawns, EEffectSpawnLocationType.Middle)
|
|
end
|
|
end
|
|
|
|
return SimpleSkillTask_Crack; |