---@class BP_PunctureBalloonManager_C:AActor ---@field DefaultSceneRoot USceneComponent ---@field CarClass UClass ---@field ResetCarTime float --Edit Below-- local BP_PunctureBalloonManager = { AllCars = {}; CarIndex = 0; PlayerDriveCar = {}; -- PlayerKey = Car ResetHandle = {}; bIsPlay = false; }; function BP_PunctureBalloonManager:ReceiveBeginPlay() self.SuperClass.ReceiveBeginPlay(self); if UGCGameSystem.IsServer() then -- self:InitCar() UGCEventSystem.AddListener(EventEnum.PierceBalloon, self.PierceBalloon, self) end end function BP_PunctureBalloonManager:InitCar() local Cars = GameplayStatics.GetAllActorsOfClass(UGCGameSystem.GameState, self.CarClass); for i, v in pairs(Cars) do self.AllCars[#self.AllCars + 1] = v end if #self.AllCars < 4 then UGCLogSystem.LogError("[BP_PunctureBalloonManager_InitCar] 载具数量不对:%s", tostring(#self.AllCars)) end end function BP_PunctureBalloonManager:AllPlayerDriverCar() local AllPC = UGCGameSystem.GetAllPlayerController() for i, v in pairs(AllPC) do local PlayerKey = v.PlayerKey local Pawn = UGCGameSystem.GetPlayerPawnByPlayerKey(PlayerKey) local Car = self:GetCar() if Car then UGCVehicleSystem.EnterVehicle(Pawn, Car, ESTExtraVehicleSeatType.ESeatType_DriversSeat, true) Car:SetOwnerPlayer(PlayerKey) self.PlayerDriveCar[PlayerKey] = Car UGCSendRPCSystem.ActorRPCNotify(PlayerKey, self, "ClientPlayerDriveCar", Car) UGCLogSystem.Log("[BP_PunctureBalloonManager_AllPlayerDriverCar] EnterVehicle Succeed") end end self:RemoveOtherCar() self.bIsPlay = true end -- Client function BP_PunctureBalloonManager:ClientPlayerDriveCar(Car) local LocalPlayer = UGCSystemLibrary.GetLocalPlayerPawn() if UE.IsValid(LocalPlayer) then UGCVehicleSystem.EnterVehicle(LocalPlayer, Car, ESTExtraVehicleSeatType.ESeatType_DriversSeat, true) end end function BP_PunctureBalloonManager:GetCar() self.CarIndex = self.CarIndex + 1 if self.CarIndex > #self.AllCars then return nil end return self.AllCars[self.CarIndex] end function BP_PunctureBalloonManager:RemoveOtherCar() if self.CarIndex < 4 then for i = 4, self.CarIndex + 1, -1 do local Car = self.AllCars[i] UGCVehicleSystem.DestroySelf(Car) UGCLogSystem.Log("[BP_PunctureBalloonManager_RemoveOtherCar]") self.AllCars[i] = nil end end end function BP_PunctureBalloonManager:RemoveAllCar() for i, Car in pairs(self.AllCars) do UGCVehicleSystem.DestroySelf(Car) UGCLogSystem.Log("[BP_PunctureBalloonManager_RemoveAllCar]") end self.AllCars = {} end function BP_PunctureBalloonManager:PierceBalloon(StabPlayer, PuncturedPlayer) self.PlayerDriveCar[PuncturedPlayer]:Pierce() self.ResetHandle[PuncturedPlayer] = UGCEventSystem.SetTimer(self, function() self.PlayerDriveCar[PuncturedPlayer]:ResetCar() self.ResetHandle[PuncturedPlayer] = nil end, self.ResetCarTime) end function BP_PunctureBalloonManager:ReceiveTick(DeltaTime) self.SuperClass.ReceiveTick(self, DeltaTime); if UGCGameSystem.IsServer() then self:CheckStabBalloon() end end function BP_PunctureBalloonManager:CheckStabBalloon() if not self.bIsPlay then return end for _, StabCar in pairs(self.AllCars) do if StabCar:GetCanStab() then -- UGCLogSystem.Log("[BP_PunctureBalloonManager_CheckStabBalloon] StabCar Pos:%s", VectorHelper.ToString(StabCar:GetActorPos())) local StabPos = StabCar:GetStabPos() local Radius = StabCar:GetRadius() local StabPlayer = StabCar:GetOwnerPlayerKey() for __, PuncturedCar in pairs(self.AllCars) do if StabCar ~= PuncturedCar and PuncturedCar:GetCanStab() then local BalloonCenter, Radius = PuncturedCar:GetBalloonInfo() local Dis = VectorHelper.Length(VectorHelper.Sub(BalloonCenter, StabPos)) - Radius -- UGCLogSystem.Log("[BP_PunctureBalloonManager_CheckStabBalloon]StabPos:%s, BalloonCenter:%s, Radius:%s, Dis:%s", VectorHelper.ToString(StabPos), VectorHelper.ToString(BalloonCenter), tostring(Radius), tostring(Dis)) if Dis <= Radius then --UGCLogSystem.Log("[BP_PunctureBalloonManager_CheckStabBalloon] Succeed Radius:%s", tostring(Radius)) UGCEventSystem.SendEvent(EventEnum.PierceBalloon, StabPlayer, PuncturedCar:GetOwnerPlayerKey()) end end end end end end function BP_PunctureBalloonManager:ReceiveEndPlay() self.SuperClass.ReceiveEndPlay(self); if UGCGameSystem.IsServer() then UGCEventSystem.RemoveListener(EventEnum.PierceBalloon, self.PierceBalloon, self) end end --[[ function BP_PunctureBalloonManager:GetReplicatedProperties() return end --]] --[[ function BP_PunctureBalloonManager:GetAvailableServerRPCs() return end --]] return BP_PunctureBalloonManager;