---@class BP_MatrixTargetManager_C:AActor ---@field Arrow UArrowComponent ---@field DefaultSceneRoot USceneComponent ---@field ShowNumTarget int32 ---@field Col int32 ---@field Raw int32 ---@field Interval float ---@field IceTargetClass UClass ---@field ResetTargetRoundNum int32 ---@field IceMoveTargetClass UClass ---@field MoveTime float ---@field MoveTargetScore int32 ---@field MoveTargetDirClass UClass --Edit Below-- local BP_MatrixTargetManager = { AllIceTarget = {}; ResetTargetList = {}; ShowingTargets = {}; FindRandomTargetCount = 5; }; function BP_MatrixTargetManager:ReceiveBeginPlay() self.SuperClass.ReceiveBeginPlay(self); if UGCGameSystem.IsServer() then UGCEventSystem.AddListener(EventEnum.BreakingIceCubes, self.PlayerHitTarget, self) self:SpawnAllIceTarget() self:SpawnAllMoveIceTarget() end end function BP_MatrixTargetManager:StartGame() self:UpdateNewShowTarget(self.ShowNumTarget) UGCSendRPCSystem.ActorRPCNotify(nil, self, "CloseAutoAimEnabled") end --- 关闭所有玩家的辅助瞄准 function BP_MatrixTargetManager:CloseAutoAimEnabled() local LocalPawn = UGCSystemLibrary.GetLocalPlayerPawn() if UE.IsValid(LocalPawn) then UGCGunSystem.SetIsAutoAimEnabled(LocalPawn, false) end end function BP_MatrixTargetManager:SpawnAllIceTarget() local StartY = -(self.Col - 1) / 2. * self.Interval local StartZ = -(self.Raw - 1) / 2. * self.Interval for i = 0, self.Col - 1 do for j = 0, self.Raw - 1 do local Y = StartY + i * self.Interval local Z = StartZ + j * self.Interval self:SpawnIceTarget(VectorHelper.Add(self:K2_GetActorLocation(), {X = 0, Y = Y, Z = Z}), self:K2_GetActorRotation()) end end end function BP_MatrixTargetManager:SpawnIceTarget(Pos, Rot) local IceTarget = UGCGameSystem.SpawnActor(self, self.IceTargetClass, Pos, Rot, VectorHelper.ScaleOne(), nil) self.AllIceTarget[#self.AllIceTarget + 1] = IceTarget IceTarget:SetID(#self.AllIceTarget) end function BP_MatrixTargetManager:SpawnAllMoveIceTarget() local AllMoveTargetDir = GameplayStatics.GetAllActorsOfClass(UGCGameSystem.GameState, self.MoveTargetDirClass, {}) for i, v in pairs(AllMoveTargetDir) do local StartPos = VectorHelper.ToLuaTable(v:K2_GetActorLocation()) local EndPos = VectorHelper.ToLuaTable(v.TargetPos:K2_GetComponentLocation()) local IceTarget = UGCGameSystem.SpawnActor(self, self.IceMoveTargetClass, StartPos, self:K2_GetActorRotation(), VectorHelper.ScaleOne(), nil) self.AllIceTarget[#self.AllIceTarget + 1] = IceTarget IceTarget:SetID(#self.AllIceTarget) IceTarget:SetMoveParam(StartPos, EndPos, self.MoveTime, self.MoveTargetScore) end end --[[ function BP_MatrixTargetManager:ReceiveTick(DeltaTime) self.SuperClass.ReceiveTick(self, DeltaTime); end --]] function BP_MatrixTargetManager:ReceiveEndPlay() self.SuperClass.ReceiveEndPlay(self); if UGCGameSystem.IsServer() then for i, v in pairs(self.AllIceTarget) do if UE.IsValid(v) then v:K2_DestroyActor() end end UGCEventSystem.RemoveListener(EventEnum.BreakingIceCubes, self.PlayerHitTarget, self) end end function BP_MatrixTargetManager:PlayerHitTarget(PlayerKey, TargetID) if self.ResetTargetRoundNum > 0 then for i, v in pairs(self.ResetTargetList) do if self.ResetTargetList[i] == 1 then self.ResetTargetList[i] = nil else self.ResetTargetList[i] = self.ResetTargetList[i] - 1 end end self.ResetTargetList[TargetID] = self.ResetTargetRoundNum end table.removeValue(self.ShowingTargets, TargetID, true) self:UpdateNewShowTarget(1) end function BP_MatrixTargetManager:UpdateNewShowTarget(ShowNum) for i = 1, ShowNum do local SelectSucceed = false local WhileCount = 0; while not SelectSucceed do if self.FindRandomTargetCount < WhileCount then SelectSucceed = true end local RandomTargetID = math.random(1, #self.AllIceTarget) if SelectSucceed or (not table.hasValue(self.ResetTargetList, RandomTargetID) and not self.AllIceTarget[RandomTargetID]:GetIsShowing()) then self.ShowingTargets[#self.ShowingTargets + 1] = RandomTargetID self.AllIceTarget[RandomTargetID]:SetShowTarget(true) SelectSucceed = true end WhileCount = WhileCount + 1 end end UGCSendRPCSystem.ActorRPCNotify(nil, self, "ClientUpdateShowTarget", self.ShowingTargets) --UGCLogSystem.LogTree("[BP_MatrixTargetManager_UpdateNewShowTarget]", self.ShowingTargets) end function BP_MatrixTargetManager:ClientUpdateShowTarget(InShowingTargets) --UGCLogSystem.LogTree("[BP_MatrixTargetManager_ClientUpdateShowTarget]", InShowingTargets) for i, v in pairs(self.AllIceTarget) do --UGCLogSystem.Log("[BP_MatrixTargetManager_ClientUpdateShowTarget] i:%s", tostring(i)) v:SetShowTarget(table.hasValue(InShowingTargets, i)) end end function BP_MatrixTargetManager:GetReplicatedProperties() return "AllIceTarget" end --[[ function BP_MatrixTargetManager:GetAvailableServerRPCs() return end --]] return BP_MatrixTargetManager;