145 lines
5.4 KiB
Lua
145 lines
5.4 KiB
Lua
---@class BP_ShootingTarget_Move_C:AActor
|
|
---@field EndTF UStaticMeshComponent
|
|
---@field Widget UWidgetComponent
|
|
---@field TripleScoreRange USphereComponent
|
|
---@field TargetMesh UStaticMeshComponent
|
|
---@field DefaultRootComponent USceneComponent
|
|
---@field DoubleScoreRange USphereComponent
|
|
---@field BaseScoreRange USphereComponent
|
|
---@field Center USceneComponent
|
|
---@field HitEffectPlayTime float
|
|
---@field StartTF FTransform
|
|
---@field FinishTF FTransform
|
|
---@field ResetTime float
|
|
---@field BaseScore int32
|
|
---@field CycleTime float
|
|
---@field RandomMul float
|
|
---@field AutoStart bool
|
|
---@field AutoDelayStart float
|
|
--Edit Below--
|
|
---@type BP_ShootingTarget_Move_C
|
|
local ShootingTargetBase = require('Script.Blueprint.MiniLevelActor.ShootLevel.ShootingTargetBase')
|
|
|
|
local BP_ShootingTarget_Move = setmetatable(
|
|
{
|
|
BeginTFPos = {X = 0., Y = 0., Z = 0.};
|
|
EndTFPos = {X = 0., Y = 0., Z = 0.};
|
|
Floor_UnitVector = {X = 0., Y = 0., Z = 0.}; -- 单位向量
|
|
PathLength = 0.;
|
|
Direction = 1;
|
|
bIsEnable = false;
|
|
},
|
|
{
|
|
__index = ShootingTargetBase,
|
|
__metatable = ShootingTargetBase
|
|
}
|
|
);
|
|
|
|
function BP_ShootingTarget_Move:ReceiveBeginPlay()
|
|
self.SuperClass.ReceiveBeginPlay(self);
|
|
self.BaseScoreRangeRadius = self.BaseScoreRange:GetScaledSphereRadius()
|
|
self.DoubleScoreRangeRadius = self.DoubleScoreRange:GetScaledSphereRadius()
|
|
self.TripleScoreRangeRadius = self.TripleScoreRange:GetScaledSphereRadius()
|
|
if UGCGameSystem.IsServer() then
|
|
self:InitParam()
|
|
self:InitRandomPos()
|
|
if self.AutoStart then
|
|
UGCEventSystem.SetTimer(self, self.EnableItem, self.AutoDelayStart)
|
|
end
|
|
end
|
|
end
|
|
|
|
function BP_ShootingTarget_Move:ReceiveTick(DeltaTime)
|
|
self.SuperClass.ReceiveTick(self, DeltaTime);
|
|
self:TickSetPos(DeltaTime)
|
|
if UGCGameSystem.IsServer() then
|
|
else
|
|
self:TickPlayEffect()
|
|
end
|
|
end
|
|
|
|
function BP_ShootingTarget_Move:ReceivePointDamage(Damage, DamageType, HitLocation, HitNormal, HitComponent, BoneName, ShotFromDirection, InstigatedBy, DamageCauser, HitInfo)
|
|
ShootingTargetBase.ReceivePointDamage(self, Damage, DamageType, HitLocation, HitNormal, HitComponent, BoneName, ShotFromDirection, InstigatedBy, DamageCauser, HitInfo)
|
|
end
|
|
|
|
|
|
function BP_ShootingTarget_Move:InitParam()
|
|
self.BeginTFPos = VectorHelper.ToLuaTable(self:K2_GetActorLocation())
|
|
self.EndTFPos = VectorHelper.ToLuaTable(self.EndTF:K2_GetComponentLocation())
|
|
local PathVector = VectorHelper.Sub(self.EndTFPos, self.BeginTFPos)
|
|
self.Floor_UnitVector = VectorHelper.ToLuaTable(VectorHelper.MulNumber(PathVector, 1. / VectorHelper.Length(PathVector)))
|
|
self.PathLength = VectorHelper.Length(PathVector)
|
|
self:K2_SetActorLocation(self.BeginTFPos)
|
|
UGCLogSystem.Log("[BP_MoveFloor_InitParam] PathLength:%f", self.PathLength)
|
|
--table.print(self.BeginTFPos)
|
|
--table.print(self.EndTFPos)
|
|
--table.print(self.Floor_UnitVector)
|
|
end
|
|
|
|
function BP_ShootingTarget_Move:InitRandomPos()
|
|
local TargetInitLocation = KismetMathLibrary.VLerp(self.BeginTFPos, self.EndTFPos, math.random())
|
|
self.CycleTime = self.CycleTime + (math.random() * 2 - 1) * self.RandomMul
|
|
DOREPONCE(self, "CycleTime")
|
|
self:K2_SetActorLocation(TargetInitLocation)
|
|
end
|
|
|
|
function BP_ShootingTarget_Move:ChangeDirection()
|
|
self.Direction = -self.Direction
|
|
end
|
|
|
|
function BP_ShootingTarget_Move:EnableItem()
|
|
if self:HasAuthority() then
|
|
self.bIsEnable = true
|
|
end
|
|
end
|
|
|
|
function BP_ShootingTarget_Move:DisableItem()
|
|
if self:HasAuthority() then
|
|
self.bIsEnable = false
|
|
end
|
|
end
|
|
|
|
function BP_ShootingTarget_Move:TickSetPos(DeltaTime)
|
|
if self.bIsEnable then
|
|
local MulNum = (DeltaTime / (self.CycleTime / 2.) * self.PathLength) * self.Direction
|
|
local AddVector = VectorHelper.MulNumber(self.Floor_UnitVector, MulNum)
|
|
-- self:K2_AddActorLocalOffset(AddVector)
|
|
self:K2_AddActorWorldOffset(AddVector)
|
|
--local Dis1 = VectorHelper.GetDistance(self:K2_GetActorLocation(),self.BeginTFPos)
|
|
--local Dis2 = VectorHelper.GetDistance(self:K2_GetActorLocation(),self.EndTFPos)
|
|
--UGCLogSystem.Log("[BP_ShootingTarget_Move_ReceiveTick] AddVector:%s", VectorHelper.ToString(AddVector))
|
|
--table.print(Dis1)
|
|
--table.print(Dis2)
|
|
|
|
if self.Direction > 0 then
|
|
local DisFromBegin = VectorHelper.GetDistance(self:K2_GetActorLocation(),self.BeginTFPos)
|
|
if self.PathLength <= DisFromBegin then
|
|
self:ChangeDirection()
|
|
local DisDifference = DisFromBegin - self.PathLength
|
|
local AddDifferenceVector = VectorHelper.MulNumber(self.Floor_UnitVector, DisDifference * 2 * self.Direction)
|
|
self:K2_AddActorWorldOffset(AddDifferenceVector)
|
|
end
|
|
else
|
|
local DisFromEnd = VectorHelper.GetDistance(self:K2_GetActorLocation(),self.EndTFPos)
|
|
if self.PathLength <= DisFromEnd then
|
|
self:ChangeDirection()
|
|
local DisDifference = DisFromEnd - self.PathLength
|
|
local AddDifferenceVector = VectorHelper.MulNumber(self.Floor_UnitVector, DisDifference * 2 * self.Direction)
|
|
self:K2_AddActorWorldOffset(AddDifferenceVector)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
function BP_ShootingTarget_Move:GetReplicatedProperties()
|
|
return
|
|
"Direction",
|
|
"bIsEnable",
|
|
"PathLength",
|
|
"Floor_UnitVector",
|
|
"EndTFPos",
|
|
"BeginTFPos"
|
|
end
|
|
|
|
|
|
return BP_ShootingTarget_Move; |