UGCProjects/JungleSpecialOperations/Script/Global/BuffSystem/BuffAction/BuffAction_BulletHitApplyRadialDamage.lua

124 lines
4.4 KiB
Lua
Raw Permalink Normal View History

2025-01-04 23:00:19 +08:00
local BuffActionBase = require('Script.Global.BuffSystem.BuffActionBase')
local BuffAction_BulletHitApplyRadialDamage = setmetatable(
{
-- Param ---------------------------
-- 仅枪械武器触发
IsShootWeapon = true;
-- 筛选武器,若不为空则内部对应的武器攻击才会触发,若为空则全部武器均会触发
FilterWeaponItemID = {};
-- Damage --
MaxDamage = 20;
MinDamage = 20;
-- 内部范围,既最高伤害的范围
InnerRadius = 50;
-- 外部范围,既伤害范围,到该范围边界则为最低伤害
OuterRadius = 200;
-- Inner到Outer范围区间的伤害衰减指数
FallOff = 2;
-- Damage --
-- 冷却时间
CoolingTime = 2;
-- 粒子类型
ParticleType = nil;
-- 音效类型
SoundType = nil;
-- Param End -----------------------
-- 正在冷却
bIsCooling = false;
ShootWeaponType = {
EWeaponTypeNew.EWeaponTypeNew_Rifle,
EWeaponTypeNew.EWeaponTypeNew_SingleShotSniper,
EWeaponTypeNew.EWeaponTypeNew_BurstShotSniper,
EWeaponTypeNew.EWeaponTypeNew_Submachine,
EWeaponTypeNew.EWeaponTypeNew_ShotGun,
EWeaponTypeNew.EWeaponTypeNew_Pistol,
EWeaponTypeNew.EWeaponTypeNew_Crossbow,
}
},
{ __index = BuffActionBase, __metatable = BuffActionBase }
);
function BuffAction_BulletHitApplyRadialDamage:LuaDoAction()
BuffActionBase.LuaDoAction(self)
if not UGCGameSystem.IsServer() then return true end
UGCLogSystem.LogTree("[BuffAction_BulletHitApplyRadialDamage_LuaUndoAction]", self.ShootWeaponType)
-- 绑定Event传入的self可能有点问题需要与存储OwnerPawn才能获取到正确的OwnerPawn
UGCEventSystem.AddListener(EventEnum.BulletHitCallBack, self.BulletHitCallBack, self)
-- 启用Tick
self:EnableTick()
end
function BuffAction_BulletHitApplyRadialDamage:LuaUndoAction()
BuffActionBase.LuaUndoAction(self)
if not UGCGameSystem.IsServer() then return true end
if self.CoolingHandle then
UGCEventSystem.StopTimer(self.CoolingHandle)
end
UGCEventSystem.RemoveListener(EventEnum.BulletHitCallBack, self.BulletHitCallBack, self)
end
--function BuffAction_BulletHitApplyRadialDamage:LuaUpdateAction(DeltaSeconds)
-- BuffActionBase.LuaUpdateAction(self, DeltaSeconds)
--end
function BuffAction_BulletHitApplyRadialDamage:CheckWeapon(InWeaponInst)
local WeaponItemID = InWeaponInst:GetWeaponItemID()
if #self.FilterWeaponItemID > 0 then
return table.hasValue(self.FilterWeaponItemID, WeaponItemID)
end
local WeaponTypeNew = InWeaponInst:GetWeaponTypeNew()
UGCLogSystem.Log("[BuffAction_BulletHitApplyRadialDamage_CheckWeapon] WeaponTypeNew:%s", tostring(WeaponTypeNew))
if self.IsShootWeapon then
return table.hasValue(self.ShootWeaponType, WeaponTypeNew)
end
return true
end
function BuffAction_BulletHitApplyRadialDamage:BulletHitCallBack(TargetPawn, WeaponInst, BulletInst, HitInfo)
if self:GetOwnerPawn() == TargetPawn and self.bIsCooling == false and self:CheckWeapon(WeaponInst) then
-- 冷却
if self.CoolingTime > 1e-2 then
self.bIsCooling = true
self.CoolingHandle = UGCEventSystem.SetTimer(UGCGameSystem.GameState, function()
self.bIsCooling = false
self.CoolingHandle = nil
end, self.CoolingTime)
end
local Pos = HitInfo.Location
-- 施加范围伤害
UGCGameSystem.ApplyRadialDamage(
self.MaxDamage,
self.MinDamage,
Pos,
self.InnerRadius,
self.OuterRadius,
self.FallOff,
EDamageType.RadialDamage,
{},
WeaponInst,
TargetPawn:GetController(),
ECollisionChannel.ECC_Visibility,
WeaponInst:GetWeaponItemID()
);
BuffSystemAPI.RPCAction(nil, self:GetInstID(), BuffActionConfig.EActionType.BulletHitApplyRadialDamage, "ClientExplosionFX", VectorHelper.ToLuaTable(Pos))
end
end
function BuffAction_BulletHitApplyRadialDamage:ClientExplosionFX(Pos)
if self.ParticleType then
ParticleConfig.AddParticleFromPosAndRot(self.ParticleType, Pos, nil, self.OuterRadius / 100)
end
if self.SoundType then
SoundSystem.PlaySound(self.SoundType, Pos, VectorHelper.RotZero())
end
end
return BuffAction_BulletHitApplyRadialDamage;