UGCProjects/TrainingCamp/Script/Blueprint/UGCPlayerController.lua

256 lines
8.0 KiB
Lua
Raw Permalink Normal View History

2025-01-04 23:00:19 +08:00
---@class UGCPlayerController_C:BP_UGCPlayerController_C
--Edit Below--
---@type UGCPlayerController_C
local UGCPlayerController = {};
UGCPlayerController.CachedBodySize = nil;
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)
end
function UGCPlayerController:GetReplicatedProperties()
return "CachedBodySize";
end
function UGCPlayerController:GetAvailableServerRPCs()
return "Test_Func"
end
--- 重置游戏
function UGCPlayerController:ResetGame()
self.CachedBodySize = 1;
local PlayerState = UGCGameSystem.GetPlayerStateByPlayerKey(self.PlayerKey)
PlayerState:ResetGame();
end
-------------------------------- 伤害 --------------------------------
---@param InVictim PlayerKey 击杀者
function UGCPlayerController:OnKillPlayer(InVictim)
local Pawn = UGCGameSystem.GetPlayerPawnByPlayerKey(self.PlayerKey)
if UE.IsValid(Pawn) and Pawn:IsAlive() then
if DefaultSettings.KillReload then
ItemTool.Reload(Pawn, false);
end
end
end
function UGCPlayerController:ChangeBody(InVal)
local Pawn = UGCGameSystem.GetPlayerPawnByPlayerKey(self.PlayerKey)
Pawn:ChangeBody(InVal);
self.CachedBodySize = InVal;
end
function UGCPlayerController:OnRep_CachedBodySize()
local Pawn = UGCGameSystem.GetPlayerPawnByPlayerKey(self.PlayerKey);
if Pawn then
if Pawn:GetActorScale3D().X ~= self.CachedBodySize then
Pawn:ClientChangeBody(self.CachedBodySize);
end
end
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: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:Test_GetArmor()
ItemTool.RemoveArmorItem(self)
end
function UGCPlayerController:Test_Skill(InNum)
local Pawn = UGCGameSystem.GetPlayerPawnByPlayerKey(self.PlayerKey);
Pawn:Repulse(InNum);
end
---@param InValue float 限制在 0 - 1 之间
function UGCPlayerController:OnSliderMouseEnd(InValue)
UGCLogSystem.Log("[UGCPlayerController:OnSliderMouseEnd] 执行")
end
function UGCPlayerController:GetTestValue()
return self.Test_Slider_Value;
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:Test_LaunchCharacter(InVal)
local Pawn = UGCGameSystem.GetPlayerPawnByPlayerKey(self.PlayerKey);
Pawn:PlayerLaunch();
end
function UGCPlayerController:Test_Stun(InVal)
local Pawn = UGCGameSystem.GetPlayerPawnByPlayerKey(self.PlayerKey);
Pawn:Stun(true);
end
function UGCPlayerController:Test_CurrentWeapon()
local Pawn = UGCGameSystem.GetPlayerPawnByPlayerKey(self.PlayerKey);
local Weapon = UGCWeaponManagerSystem.GetCurrentWeapon(Pawn)
local Str = "[UGCPlayerController:Test_CurrentWeapon] ";
if Weapon then
Str = Str .. string.format("Current Weapon = %s", UE.GetName(Weapon))
else
Str = Str .. "Current Weapon = nil"
end
Str = Str .. ', '
Weapon = UGCWeaponManagerSystem.GetWeaponBySlot(Pawn, ShootWeaponEnums[1])
if Weapon then
Str = Str .. string.format("First Weapon = %s", UE.GetName(Weapon))
else
Str = Str .. "First Weapon = nil"
end
UGCLogSystem.UGCLog(Str);
UGCLogSystem.Log(Str)
end
function UGCPlayerController:Test_TransShape(InVal)
local Pawn = UGCGameSystem.GetPlayerPawnByPlayerKey(self.PlayerKey);
Pawn:TransShape(InVal);
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_ClearWrappers()
GameState:ClearWrappers();
end
function UGCPlayerController:Test_RemoveAttachment()
local Pawn = UGCGameSystem.GetPlayerPawnByPlayerKey(self.PlayerKey);
Pawn:Test_RemoveAttachment();
end
function UGCPlayerController:Test_LogCurrArmor()
local Pawn = UGCGameSystem.GetPlayerPawnByPlayerKey(self.PlayerKey);
local Info = UGCBackPackSystem.GetArmorInBackpack(Pawn);
local Table = UE.ToTable(Info);
UGCLogSystem.LogTree(string.format("[UGCPlayerController:Test_LogCurrArmor] Table ="), Table)
UGCLogSystem.UGCLog("[UGCPlayerController:Test_LogCurrArmor] Info.Count = %d", Info.Count);
end
function UGCPlayerController:Test_AddArmor()
local Pawn = UGCGameSystem.GetPlayerPawnByPlayerKey(self.PlayerKey);
Pawn:AddItem(503003, 1);
end
function UGCPlayerController:Test_AddRangeParts()
local Pawn = UGCGameSystem.GetPlayerPawnByPlayerKey(self.PlayerKey);
Pawn:Test_AddRangeParts();
end
function UGCPlayerController:Test_ApplyDamage()
for i, v in pairs(EDamageType) do
UGCLogSystem.Log("[UGCPlayerController:Test_ApplyDamage] Key = %s, Val = %d", i, v);
end
local Pawn = self:GetPlayerCharacterSafety();
local Damage = UGCGameSystem.ApplyDamage(self:GetPlayerCharacterSafety(), 1000, self, UGCWeaponManagerSystem.GetCurrentWeapon(Pawn), EDamageType.UGCCustomDamageType + 1);
UGCLogSystem.Log("[UGCPlayerController:Test_ApplyDamage] Damage = %s", tostring(Damage));
end
--function UGCPlayerController:ReceiveTick(DeltaTime)
-- self.SuperClass.ReceiveTick(self, DeltaTime);
--end
--function UGCPlayerController:Tick1s(dt, ServerTime)
--end
--[[
function UGCPlayerController:ReceiveEndPlay()
self.SuperClass.ReceiveEndPlay(self);
end
--]]
return UGCPlayerController;