2025-01-04 23:00:19 +08:00

132 lines
3.9 KiB
Lua

---@class BP_RecoveryPool_C:AActor
---@field ShowHealthWidget UWidgetComponent
---@field StaticMesh UStaticMeshComponent
---@field Box UBoxComponent
---@field ParticleSystem UParticleSystemComponent
---@field DefaultSceneRoot USceneComponent
---@field MaxHealth float
---@field RecoverySpeed float
---@field PlayerRecoverySpeed float
--Edit Below--
---@type BP_RecoveryPool_C
local BP_RecoveryPool = {
Health = 0.;
AddHealthFrequency = 10.;
};
function BP_RecoveryPool:ReceiveBeginPlay()
self.SuperClass.ReceiveBeginPlay(self);
if UGCGameSystem.IsServer() then
UGCEventSystem.SetTimerLoop(self, self.TriggerAddHealth, 1. / self.AddHealthFrequency)
end
end
function BP_RecoveryPool:ReceiveTick(DeltaTime)
self.SuperClass.ReceiveTick(self, DeltaTime);
if UGCGameSystem.IsServer() then
else
local LocalPC = UGCSystemLibrary.GetLocalPlayerController()
if LocalPC then
local CameraPos = LocalPC.PlayerCameraManager:K2_GetActorLocation()
local Pos = self:K2_GetActorLocation()
CameraPos.Z = 0.
Pos.Z = 0.
local Dir = KismetMathLibrary.MakeRotFromX(VectorHelper.Sub(CameraPos, Pos))
self.ShowHealthWidget:K2_SetWorldRotation(Dir)
end
end
end
function BP_RecoveryPool:GetShowValueWidget()
return self.ShowHealthWidget:GetUserWidgetObject()
end
function BP_RecoveryPool:OnRep_Health()
if self.LastHealth ~= self:GetPoolHealth() then
self:GetShowValueWidget():UpdateHealth(self:GetPoolHealth(), self.MaxHealth)
self.ShowHealthWidget:RequestRedraw()
self.LastHealth = self:GetPoolHealth()
end
end
function BP_RecoveryPool:GetPoolHealth()
return self.Health
end
function BP_RecoveryPool:SetPoolHealth(NewHealth)
self.Health = math.clamp(NewHealth, 0., self.MaxHealth)
end
function BP_RecoveryPool:TriggerAddHealth()
self:PoolAddHealth()
self:PlayerAddHealth()
end
function BP_RecoveryPool:PoolAddHealth()
if self:GetPoolHealth() >= self.MaxHealth then return end
self:SetPoolHealth(self:GetPoolHealth() + self.RecoverySpeed / self.AddHealthFrequency)
end
function BP_RecoveryPool:PlayerAddHealth()
local OverlappingPlayers = self:GetOverlappingPlayer()
local OverlappingPlayerCount = #OverlappingPlayers
if OverlappingPlayerCount == 0 then return end
local AddHealthValue = self.PlayerRecoverySpeed / self.AddHealthFrequency
if self:GetPoolHealth() < OverlappingPlayerCount * AddHealthValue then
AddHealthValue = self:GetPoolHealth() / OverlappingPlayerCount
end
for i, PlayerPawn in pairs(OverlappingPlayers) do
local ResidualBloodValue = UGCPawnAttrSystem.GetHealthMax(PlayerPawn) - UGCPawnAttrSystem.GetHealth(PlayerPawn)
if ResidualBloodValue < AddHealthValue then
UGCPawnAttrSystem.SetHealth(PlayerPawn, UGCPawnAttrSystem.GetHealthMax(PlayerPawn))
self:SetPoolHealth(self:GetPoolHealth() - ResidualBloodValue)
else
UGCPawnAttrSystem.SetHealth(PlayerPawn, UGCPawnAttrSystem.GetHealth(PlayerPawn) + AddHealthValue)
self:SetPoolHealth(self:GetPoolHealth() - AddHealthValue)
end
end
end
function BP_RecoveryPool:GetOverlappingPlayer()
local ResPawn = {}
local AllPawn = UGCGameSystem.GetAllPlayerPawn()
for i, PlayerPawn in pairs(AllPawn) do
---回血条件:存活、重叠、非满血
if PlayerPawn:IsAlive()
and self.Box:IsOverlappingActor(PlayerPawn)
and UGCPawnAttrSystem.GetHealth(PlayerPawn) < UGCPawnAttrSystem.GetHealthMax(PlayerPawn)
then
ResPawn[#ResPawn + 1] = PlayerPawn
end
end
return ResPawn
end
--[[
function BP_RecoveryPool:ReceiveEndPlay()
self.SuperClass.ReceiveEndPlay(self);
end
--]]
function BP_RecoveryPool:GetReplicatedProperties()
return
"Health"
end
--[[
function BP_RecoveryPool:GetAvailableServerRPCs()
return
end
--]]
return BP_RecoveryPool;