298 lines
9.5 KiB
Lua
298 lines
9.5 KiB
Lua
---@class UGCPlayerController_C:BP_UGCPlayerController_C
|
|
--Edit Below--
|
|
|
|
require('Script.Global.Global');
|
|
|
|
---@type UGCPlayerController_C
|
|
local UGCPlayerController = {};
|
|
|
|
function UGCPlayerController:ReceiveBeginPlay()
|
|
self.SuperClass.ReceiveBeginPlay(self);
|
|
GlobalInit.InitGlobalVar()
|
|
if IsClient then
|
|
WidgetManager:Init(self);
|
|
if not DefaultSettings.EnableAutoPickUp then UITool.HidePickUpPanel(); end
|
|
UGCEventSystem.SetTimer(self, function()
|
|
WidgetManager:ShowPanel(WidgetConfig.EUIType.Main, false);
|
|
end, 1);
|
|
end
|
|
-- 添加玩家死亡复活回调
|
|
self.OnCharacterDeadDelegate:Add(self.OnCharacterDeath, self);
|
|
self.PlayerControllerRespawnedDelegate:AddInstance(self.OnRespawnPawn, self)
|
|
end
|
|
|
|
--function UGCPlayerController:ReceiveTick(DeltaTime)
|
|
-- self.SuperClass.ReceiveTick(self, DeltaTime);
|
|
--end
|
|
|
|
--[[
|
|
function UGCPlayerController:ReceiveEndPlay()
|
|
self.SuperClass.ReceiveEndPlay(self);
|
|
end
|
|
--]]
|
|
|
|
function UGCPlayerController:GetReplicatedProperties()
|
|
return { "Buffs", "Lazy" }
|
|
end
|
|
|
|
function UGCPlayerController:GetAvailableServerRPCs()
|
|
return "Test_Func"
|
|
, "UseBuff"
|
|
end
|
|
|
|
function UGCPlayerController:OnRespawnPawn()
|
|
local Pawn = UGCGameSystem.GetPlayerPawnByPlayerKey(self.PlayerKey);
|
|
PluginManager:OnPawnInit(Pawn);
|
|
if IsServer then
|
|
Pawn:AddInitItems();
|
|
Pawn:TestPawn();
|
|
end
|
|
end
|
|
|
|
--- 重置游戏
|
|
function UGCPlayerController:ResetGame()
|
|
if IsServer then
|
|
local PlayerState = UGCGameSystem.GetPlayerStateByPlayerKey(self.PlayerKey)
|
|
if PlayerState ~= nil and UE.IsValid(PlayerState) then
|
|
PlayerState:ResetGame();
|
|
end
|
|
end
|
|
end
|
|
|
|
-------------------------------- 伤害 --------------------------------
|
|
---@param InVictim PlayerKey 击杀者
|
|
function UGCPlayerController:OnKillPlayer(InVictim)
|
|
end
|
|
|
|
---@param Character UGCPlayerPawn_C
|
|
function UGCPlayerController:OnCharacterDeath(Character)
|
|
UGCLogSystem.Log("[UGCPlayerController:OnCharacterDeath] 执行")
|
|
end
|
|
|
|
-------------------------------- 观战 --------------------------------
|
|
|
|
---@param IsEnterSpectate bool
|
|
function UGCPlayerController:EnterSpectate(IsEnterSpectate)
|
|
if IsServer then
|
|
local OBKeys = {};
|
|
local LocalTeamId = UGCPlayerStateSystem.GetTeamID(self.PlayerKey);
|
|
local PlayerLists = GameState.PlayerList[LocalTeamId];
|
|
for i, PlayerKey in pairs(PlayerLists) do
|
|
if PlayerKey ~= self.PlayerKey then OBKeys[#OBKeys + 1] = PlayerKey; end
|
|
end
|
|
|
|
if table.getCount(OBKeys) == 0 then
|
|
UnrealNetwork.CallUnrealRPC(self, self, "EnterSpectate", false);
|
|
return ;
|
|
end
|
|
|
|
UGCGameSystem.ChangeAllowOBPlayerKeys(self, OBKeys);
|
|
UGCGameSystem.EnterSpectating(self);
|
|
UnrealNetwork.CallUnrealRPC(self, self, "EnterSpectate", true);
|
|
else
|
|
|
|
end
|
|
end
|
|
|
|
--- 设置能否移动
|
|
function UGCPlayerController:SetCanMove(IsCan)
|
|
self:SetCinematicMode(not IsCan, false, false, true, false);
|
|
end
|
|
|
|
function UGCPlayerController:BlendToGodCamera()
|
|
-- 查找 GodCamera
|
|
if Resources["GodCamera"] == nil then
|
|
Resources["GodCamera"] = {};
|
|
ObjectPath.AddFunc("BP_GodCamera", function(TargetClass)
|
|
UE.FindActorsByClass(TargetClass, Resources["GodCamera"]);
|
|
self:BlendToGodCamera1();
|
|
end);
|
|
else
|
|
self:BlendToGodCamera1();
|
|
end
|
|
end
|
|
|
|
function UGCPlayerController:BlendToGodCamera1()
|
|
-- 找到需要的
|
|
local CameraCount = #(Resources["GodCamera"])
|
|
local TargetCamera = nil;
|
|
if CameraCount == 1 then
|
|
TargetCamera = Resources["GodCamera"][1];
|
|
elseif CameraCount == 0 then
|
|
return ;
|
|
else
|
|
-- 拿到对应的
|
|
local CameraDis = {};
|
|
for i, GodCamera in pairs(Resources["GodCamera"]) do
|
|
local TotalDis, PawnCount = 0, 0;
|
|
for _, Pawn in pairs(UGCGameSystem.GetAllPlayerPawn()) do
|
|
if UE.IsValidPawn(Pawn) then
|
|
TotalDis = VectorHelper.GetActorDis2D(Pawn, GodCamera);
|
|
PawnCount = PawnCount + 1;
|
|
end
|
|
end
|
|
CameraDis[GodCamera] = TotalDis / PawnCount;
|
|
end
|
|
|
|
local MinDis = 100000000;
|
|
for GodCamera, Dis in pairs(CameraDis) do
|
|
if Dis < MinDis then
|
|
MinDis = Dis;
|
|
TargetCamera = GodCamera;
|
|
end
|
|
end
|
|
end
|
|
self:SetViewTargetWithBlend(TargetCamera, 0.5, EViewTargetBlendFunction.VTBlend_EaseInOut, 0, false);
|
|
end
|
|
|
|
-------------------------------- MINI GAME --------------------------------
|
|
function UGCPlayerController:MiniFunc(InFuncName, ...)
|
|
GameState:MiniFunc(InFuncName, ...);
|
|
end
|
|
|
|
function UGCPlayerController:Test_MiniFunc(InFuncName, ...)
|
|
GameState:MiniFunc("TestFunc", InFuncName, self.PlayerKey, ...);
|
|
end
|
|
|
|
-------------------------------- BUFF --------------------------------
|
|
function UGCPlayerController:ChangeBuff(InIndex, InBuffType)
|
|
self.Buffs[InIndex] = InBuffType;
|
|
DOREPONCE(self, "Buffs");
|
|
end
|
|
|
|
function UGCPlayerController:AddBuff(BuffType, ...)
|
|
UGCLogSystem.Log("[UGCPlayerController:AddBuff] 执行 BuffType = %s", TableHelper.printEnum(EBuffType, BuffType));
|
|
BuffManager:Add(BuffType, self.PlayerKey, ...);
|
|
end
|
|
|
|
function UGCPlayerController:UseBuff(...)
|
|
if IsServer then
|
|
local Ret = BuffManager:Apply(self.PlayerKey, ...);
|
|
-- 发送 RPC
|
|
UnrealNetwork.CallUnrealRPC_Multicast(self, "UseBuff", Ret, UE.GetServerTime());
|
|
else
|
|
UGCEventSystem.SendEvent(EventTypes.PlayerUseBuff, self.PlayerKey, ...)
|
|
end
|
|
end
|
|
|
|
UGCPlayerController.Buffs = {};
|
|
|
|
function UGCPlayerController:SetBuff(BuffType)
|
|
UGCLogSystem.Log("[UGCPlayerController:SetBuff] 执行")
|
|
self.Buffs = { BuffType, };
|
|
DOREPONCE(self, "Buffs");
|
|
end
|
|
|
|
function UGCPlayerController:OnRep_Buffs()
|
|
UGCEventSystem.SendEvent(EventTypes.ChangeBuffs, self.PlayerKey, self.Buffs);
|
|
end
|
|
|
|
-------------------------------- 测试 --------------------------------
|
|
|
|
function UGCPlayerController:Test_Func(InFuncName, ...)
|
|
UGCLogSystem.Log("[UGCPlayerController:Test_Func] 执行 %s", InFuncName)
|
|
self[InFuncName](self, ...)
|
|
end
|
|
|
|
UGCPlayerController.WeaponIndex = 1;
|
|
|
|
function UGCPlayerController:Test_SetWeaponItemIndex(InIndex)
|
|
local TestTable = {
|
|
106005,
|
|
106002,
|
|
106001,
|
|
104001,
|
|
};
|
|
|
|
local Table = false and TestTable or WeaponIdTable;
|
|
self.WeaponIndex = self.WeaponIndex + InIndex;
|
|
if self.WeaponIndex < 0 then self.WeaponIndex = #Table; end
|
|
if self.WeaponIndex > #Table then self.WeaponIndex = 1; end
|
|
if Table[self.WeaponIndex] then
|
|
local Pawn = UGCGameSystem.GetPlayerPawnByPlayerKey(self.PlayerKey);
|
|
ItemTool.ReplaceCurrentWeapon(Pawn, Table[self.WeaponIndex])
|
|
end
|
|
end
|
|
|
|
function UGCPlayerController:Test1(InVal)
|
|
if IsServer then
|
|
local Pawn = UGCGameSystem.GetPlayerPawnByPlayerKey(self.PlayerKey);
|
|
local Vec = Pawn:GetActorForwardVector()
|
|
local MoveLoc = VectorHelper.Add(VectorHelper.MulNumber(Vec, InVal), Pawn:K2_GetActorLocation())
|
|
UE.MovePlayerToLocation(Pawn, MoveLoc);
|
|
UnrealNetwork.CallUnrealRPC_Multicast(self, "Test1", MoveLoc);
|
|
else
|
|
--local Pawn = UGCGameSystem.GetPlayerPawnByPlayerKey(self.PlayerKey);
|
|
--local Vec = Pawn:GetActorForwardVector()
|
|
--UE.MovePlayerToLocation(Pawn, VectorHelper.Add(VectorHelper.MulNumber(Vec, InVal), Pawn:K2_GetActorLocation()));
|
|
--Pawn:K2_SetActorLocation(InVal);
|
|
end
|
|
end
|
|
|
|
function UGCPlayerController:Test_Buff(...)
|
|
UGCLogSystem.Log("[UGCPlayerController:Test_Buff] 执行 %s", tostring(...))
|
|
local Pawn = UGCGameSystem.GetPlayerPawnByPlayerKey(self.PlayerKey);
|
|
Pawn:ApplyBuff(BuffTable.EBuffType[...], nil, 1, nil, nil);
|
|
end
|
|
|
|
function UGCPlayerController:UISomething()
|
|
UGCLogSystem.UGCLog("[UGCPlayerController:UISomething] Kills = %s", tostring(self.PlayerState.Kills))
|
|
self.PlayerState.Kills = 0;
|
|
self.PlayerState.KillPlayerNum = 0;
|
|
DOREPONCE(self.PlayerState, "Kills");
|
|
DOREPONCE(self.PlayerState, "KillPlayerNum");
|
|
end
|
|
|
|
function UGCPlayerController:Test_AddRangeParts()
|
|
local Pawn = UGCGameSystem.GetPlayerPawnByPlayerKey(self.PlayerKey);
|
|
Pawn:Test_AddRangeParts();
|
|
end
|
|
|
|
function UGCPlayerController:Test_AddBolt()
|
|
local Pawn = UGCGameSystem.GetPlayerPawnByPlayerKey(self.PlayerKey);
|
|
local ItemInfo = UGCItemSystem.GetItemData(307001);
|
|
local WrapperPath = UGCItemSystem.GetPickupWrapperClassPath(307001);
|
|
UE.AsyncLoadClass_Cached(WrapperPath, function(TargetClass)
|
|
local Item = UGCGameSystem.SpawnActor(self, TargetClass, Pawn:K2_GetActorLocation(), VectorHelper.RotZero(), VectorHelper.MakeVector1(1), GameState);
|
|
UGCLogSystem.Log("[UGCPlayerController:Test_AddRangeParts] 生成出来:%s", UE.GetName(Item));
|
|
end)
|
|
end
|
|
|
|
function UGCPlayerController:Test_AddSkill(InSkillId)
|
|
GameState:AddSkill(InSkillId, self.PlayerKey);
|
|
end
|
|
|
|
function UGCPlayerController:Test_AddBuff(InBuffId)
|
|
UGCLogSystem.Log("[UGCPlayerController:Test_AddBuff] Buff = %s", tostring(InBuffId))
|
|
if type(InBuffId) == 'string' then
|
|
local Pawn = UGCGameSystem.GetPlayerPawnByPlayerKey(self.PlayerKey);
|
|
if UE.IsValidPawn(Pawn) then
|
|
Pawn:AddBuff(InBuffId, nil, 1);
|
|
end
|
|
end
|
|
end
|
|
|
|
function UGCPlayerController:Test_AddStunBomb()
|
|
local Path = '/Game/Arts_PlayerBluePrints/Weapon/Grenade/Grenade_Stun/BP_Grenade_Stun_Weapon.BP_Grenade_Stun_Weapon_C';
|
|
UE.AsyncLoadClass_Cached(Path, function(TargetClass)
|
|
UGCLogSystem.Log("[UGCPlayerController:Test_AddStunBomb] 执行")
|
|
local Pawn = UGCGameSystem.GetPlayerPawnByPlayerKey(self.PlayerKey);
|
|
local Actor = UE.SpawnActor(TargetClass, self, VectorHelper.Add(Pawn:K2_GetActorLocation(), VectorHelper.MulNumber(Pawn:GetActorForwardVector(), 100)), VectorHelper.RotZero(), VectorHelper.ScaleOne());
|
|
UGCLogSystem.Log("[UGCPlayerController:Test_AddStunBomb] Actor = %s", UE.GetName(Actor));
|
|
end)
|
|
end
|
|
|
|
function UGCPlayerController:Test_SetBuff(InBuffType)
|
|
UGCLogSystem.Log("[UGCPlayerController:Test_SetBuff] 执行")
|
|
self:SetBuff(InBuffType);
|
|
end
|
|
|
|
UGCPlayerController.IsSelfShow = true;
|
|
|
|
function UGCPlayerController:HideSelf()
|
|
local Pawn = UGCGameSystem.GetPlayerPawnByPlayerKey(self.PlayerKey);
|
|
Pawn:HiddenMySelf(self.IsSelfShow);
|
|
self.IsSelfShow = not self.IsSelfShow;
|
|
end
|
|
|
|
return UGCPlayerController; |