185 lines
6.0 KiB
Lua
Raw Normal View History

2025-01-04 23:00:19 +08:00
---@class BP_LaunchFloor_C:AActor
---@field BlockProjectBullet UStaticMeshComponent
---@field PuParticle UParticleSystemComponent
---@field TriggerBox UStaticMeshComponent
---@field WillHideParticle UParticleSystemComponent
---@field Floor UStaticMeshComponent
---@field Scene USceneComponent
---@field ZSpeed FVector
---@field CDTime float
---@field IsAddBuff bool
---@field IsActivate bool
---@field DisableFaillingTime int32
---@field BouncingSound UAkEventObject
---@field MaxHealth float
---@field Health float
---@field DefaultColor FLinearColor
---@field TargetColor FLinearColor
---@field DelayHideTime float
--Edit Below--
---@type Launch_C
local BP_LaunchFloor = {
ResetFloorTime = 10.;
IsLockActivate = false;
FloorID = -1;
};
function BP_LaunchFloor:ReceiveBeginPlay()
BP_LaunchFloor.SuperClass.ReceiveBeginPlay(self)
if self:HasAuthority() then
UGCSystemLibrary.BindBeginOverlapFunc(self.TriggerBox, self.OnBeginOverlap, self)
UGCLogSystem.Log("[BP_LaunchFloor_ReceiveBeginPlay]")
else
self.FloorMaterialInterface = self.Floor:GetMaterial(0)
self.DynamicMat = KismetMaterialLibrary.CreateDynamicMaterialInstance(self, self.FloorMaterialInterface);
self.Floor:SetMaterial(0, self.DynamicMat)
self.DynamicMat:SetVectorParameterValue("Color_Modifier", self.DefaultColor)
end
end
function BP_LaunchFloor:SetID(NewID)
self.FloorID = NewID
end
function BP_LaunchFloor:BindDamageCallBack(Func, Obj)
self.DamageCallBackFunc = Func
self.DamageCallBackObj = Obj
end
function BP_LaunchFloor:SetIsActivate(InIsActivate, LockOrUnLock)
if LockOrUnLock then
if InIsActivate then
self.IsLockActivate = false
else
self.IsLockActivate = true
end
self.IsActivate = InIsActivate
end
if not self.IsLockActivate then
self.IsActivate = InIsActivate
end
end
function BP_LaunchFloor:OnBeginOverlap(OverlappedComp, Other, OtherComp, OtherBodyIndex, bFromSweep, SweepResult)
UGCLogSystem.Log("[BP_LaunchFloor_OnBeginOverlap]")
if self.IsActivate then
local Character = Other.PlayerState:GetPlayerCharacter()
self:LaunchPlayer(Character)
self:HideFloor(true)
end
end
function BP_LaunchFloor:LaunchPlayer(Player)
--考虑角色跳起来的情况
if Player.CharacterMovement.Velocity.Z < 0 then
local AddSpeed = {X = 0, Y = 0, Z = self.ZSpeed.Z - Player.CharacterMovement.Velocity.Z}
Player.CharacterMovement:AddImpulse(AddSpeed, true)
elseif Player.CharacterMovement.Velocity.Z == 0 then
Player.CharacterMovement:AddImpulse(self.ZSpeed, true)
end
--UGCSendRPCSystem.ActorRPCNotify(nil, self, "PlayDisappear")
end
function BP_LaunchFloor:ReceiveEndPlay()
if self:HasAuthority() then
self.TriggerBox.OnComponentBeginOverlap:Remove(self.OnBeginOverlap, self)
if self.ResetFloorHandle then
UGCEventSystem.StopTimer(self.ResetFloorHandle)
self.ResetFloorHandle = nil
end
end
end
function BP_LaunchFloor:SetMaxHealth(NewMaxHealth)
self.MaxHealth = NewMaxHealth
self:AddHealth(NewMaxHealth)
end
function BP_LaunchFloor:AddHealth(InHealth)
if self.Health + InHealth <= 0 then
self:HideFloor(false)
end
self.Health = math.clamp(self.Health + InHealth, 0, self.MaxHealth)
end
---@field ReceiveAnyDamage:fun(Damage:float,DamageType:UDamageType,InstigatedBy:AController,DamageCauser:AActor)
function BP_LaunchFloor:ReceiveAnyDamage(Damage)
if self.IsActivate then
self:AddHealth(-Damage)
if self.DamageCallBackFunc then
if self.DamageCallBackObj then
self.DamageCallBackFunc(self.DamageCallBackObj, self.FloorID, self.Health)
end
end
end
end
-- 设置延迟关闭地板碰撞及隐藏地板的时间
function BP_LaunchFloor:SetDelayHideTime(InDelayHideTime)
self.DelayHideTime = InDelayHideTime
end
-- 设置重置地板的时间
function BP_LaunchFloor:SetResetFloorTime(NewTime)
self.ResetFloorTime = NewTime
end
function BP_LaunchFloor:HideFloor(IsLaunch)
UGCEventSystem.SetTimer(self, function()
self:SetFloorCollisionIsEnable(false)
if not UGCGameSystem.IsServer() then
self:HideFloorEffect()
end
end, self.DelayHideTime)
if UGCGameSystem.IsServer() then
self:SetIsActivate(false)
UGCSendRPCSystem.ActorRPCNotify(nil, self, "HideFloor", IsLaunch)
if self.ResetFloorHandle == nil then
self.ResetFloorHandle = UGCEventSystem.SetTimer(self, self.ResetFloor, self.ResetFloorTime)
end
else
if IsLaunch then
UGCSoundManagerSystem.PlaySoundAtLocation(self.BouncingSound, self:K2_GetActorLocation())
end
self.WillHideParticle:SetActive(true, true)
self:UpdateClientHealth(1, 0)
end
end
function BP_LaunchFloor:HideFloorEffect()
self.Floor:SetHiddenInGame(true)
self.PuParticle:SetActive(true, true)
SoundSystem.PlaySound(SoundSystem.ESound.Pu, self:K2_GetActorLocation(), self:K2_GetActorRotation())
end
function BP_LaunchFloor:ResetFloor()
self:SetFloorCollisionIsEnable(true)
if UGCGameSystem.IsServer() then
self.ResetFloorHandle = nil
self:SetIsActivate(true)
UGCSendRPCSystem.ActorRPCNotify(nil, self, "ResetFloor")
else
self.Floor:SetHiddenInGame(false)
self:UpdateClientHealth(1, 1)
end
end
function BP_LaunchFloor:SetFloorCollisionIsEnable(bEnable)
local BlockType = (bEnable and ECollisionEnabled.QueryAndPhysics or ECollisionEnabled.NoCollision)
self.Floor:SetCollisionEnabled(BlockType)
self.BlockProjectBullet:SetCollisionEnabled(BlockType)
end
function BP_LaunchFloor:UpdateClientHealth(MaxHealth, Health)
if self.DynamicMat then
local FloorTargetColor = KismetMathLibrary.LinearColorLerp(self.TargetColor, self.DefaultColor, Health / MaxHealth)
self.DynamicMat:SetVectorParameterValue("Color_Modifier", FloorTargetColor)
UGCLogSystem.Log("[BP_LaunchFloor_UpdateClientHealth]")
end
end
return BP_LaunchFloor;