178 lines
6.4 KiB
Lua
178 lines
6.4 KiB
Lua
local MiniGameMode_RPGChaoticWar = {
|
|
IsGameEnd = false;
|
|
-- 给玩家结算添加的得分{[PlayerKey] = AddScore, ...}
|
|
PlayerAddScore = {};
|
|
|
|
bIsInGame = false;
|
|
LastCheckPlayerBackPack = 0.;
|
|
PlayerGravityScale = 1;
|
|
DefaultBackPack = {};
|
|
StarManagerPath = "";
|
|
RespawnList = {};
|
|
TacticalReloadTime = 1;
|
|
}
|
|
|
|
--- 游戏初始化
|
|
function MiniGameMode_RPGChaoticWar:Init()
|
|
self.DefaultBackPack = MiniGameConfig.MiniGameInfo[MiniGameConfig.MiniGameType.RPGChaoticWar].GameParam.DefaultBackPack
|
|
self.PlayerGravityScale = MiniGameConfig.MiniGameInfo[MiniGameConfig.MiniGameType.RPGChaoticWar].GameParam.GravityScale
|
|
self.JumpScale = MiniGameConfig.MiniGameInfo[MiniGameConfig.MiniGameType.RPGChaoticWar].GameParam.JumpVelocityScale
|
|
self.StarManagerPath = MiniGameConfig.MiniGameInfo[MiniGameConfig.MiniGameType.RPGChaoticWar].GameParam.StarManagerPath
|
|
self.MoveSpeedScale = MiniGameConfig.MiniGameInfo[MiniGameConfig.MiniGameType.RPGChaoticWar].GameParam.MoveSpeedScale
|
|
self.ReloadTime = MiniGameConfig.MiniGameInfo[MiniGameConfig.MiniGameType.RPGChaoticWar].GameParam.ReloadTime
|
|
self.StarManager = UGCSystemLibrary.GetUniqueInstanceFromPath(self.StarManagerPath)
|
|
|
|
|
|
UGCEventSystem.AddListener(EventEnum.PlayerPickStar, self.PlayerPickStar, self)
|
|
|
|
|
|
end
|
|
|
|
--- 准备时间结束游戏开始
|
|
function MiniGameMode_RPGChaoticWar:GameBegin()
|
|
self.bIsInGame = true
|
|
-- 二次赋值
|
|
if not UE.IsValid(self.StarManager) then
|
|
self.StarManager = UGCSystemLibrary.GetUniqueInstanceFromPath(self.StarManagerPath)
|
|
end
|
|
end
|
|
|
|
function MiniGameMode_RPGChaoticWar:Update(DeltaTime)
|
|
-- 判断该玩法是否已结束
|
|
if self.IsGameEnd then return end
|
|
|
|
-- Update逻辑
|
|
|
|
-- 验证背包
|
|
self.LastCheckPlayerBackPack = self.LastCheckPlayerBackPack + DeltaTime
|
|
if self.LastCheckPlayerBackPack >= 1. then
|
|
self.LastCheckPlayerBackPack = 0.
|
|
self:CheckBackPack()
|
|
end
|
|
|
|
-- Update逻辑 End
|
|
end
|
|
|
|
--- 设置游戏结束,手动触发会结束该玩法,倒计时结束将自动触发该函数
|
|
function MiniGameMode_RPGChaoticWar:SetMiniGameModeEnd()
|
|
if not self.IsGameEnd then
|
|
self.IsGameEnd = true
|
|
self:MiniGameEnd()
|
|
end
|
|
end
|
|
|
|
--- 获取当前回合游戏结算,
|
|
---@return "{[PlayerKey] = AddScore, ...}"
|
|
function MiniGameMode_RPGChaoticWar:GetPlayerAddScore()
|
|
return self.PlayerAddScore
|
|
end
|
|
|
|
--- 外层调用,判断该玩法是否已结束
|
|
function MiniGameMode_RPGChaoticWar:CheckGameFinish()
|
|
return self.IsGameEnd
|
|
end
|
|
|
|
--- 内部作用,判断玩法是否结束函数
|
|
function MiniGameMode_RPGChaoticWar:CheckTrapGameIsFinish_InternalCall()
|
|
return #UGCGameSystem.GetAllPlayerPawn() <= 1
|
|
end
|
|
|
|
--- 结束触发
|
|
function MiniGameMode_RPGChaoticWar:MiniGameEnd()
|
|
for i, v in pairs(self.RespawnList) do
|
|
UGCEventSystem.StopTimer(v)
|
|
end
|
|
self.RespawnList = {}
|
|
|
|
self.PlayerAddScore = UGCGameSystem.GameState:GetPlayerMiniGameAddScore()
|
|
|
|
|
|
UGCEventSystem.RemoveListener(EventEnum.PlayerPickStar, self.PlayerPickStar, self)
|
|
end
|
|
|
|
|
|
|
|
------------------------------------------ Player ------------------------------------------
|
|
|
|
--- 玩家死亡
|
|
function MiniGameMode_RPGChaoticWar:PlayerDead(VictimKey, CauserKey, WeaponID, DamageType, IsHeadShotDamage, Distance, DamageValue, Assister)
|
|
if UGCGameSystem.GameState:GetPlayerMiniGameScore(VictimKey) > 0 then
|
|
UGCGameSystem.GameState:PlayerAddMiniGameScore(VictimKey, -1)
|
|
local PlayerPawn = UGCGameSystem.GetPlayerPawnByPlayerKey(VictimKey)
|
|
if PlayerPawn then
|
|
self.StarManager:AddStarFromPos(PlayerPawn:K2_GetActorLocation(), true, true)
|
|
end
|
|
end
|
|
|
|
-- 复活死者
|
|
self.RespawnList[VictimKey] = UGCEventSystem.SetTimer(UGCGameSystem.GameState,
|
|
function()
|
|
if not self.IsGameEnd then
|
|
UGCGameSystem.RespawnPlayer(VictimKey)
|
|
end
|
|
self.RespawnList[VictimKey] = nil
|
|
end,
|
|
MiniGameConfig.MiniGameInfo[MiniGameConfig.MiniGameType.RPGChaoticWar].GameParam.RespawnTime
|
|
)
|
|
end
|
|
|
|
--- 玩家伤害修改
|
|
function MiniGameMode_RPGChaoticWar:PlayerDamageModify(DamageAmount, VictimPawn, CauserPC)
|
|
if self.bIsInGame then
|
|
return DamageAmount
|
|
else
|
|
return 0.
|
|
end
|
|
end
|
|
|
|
--- 玩家受控时
|
|
function MiniGameMode_RPGChaoticWar:PlayerPossessed(PlayerKey)
|
|
|
|
end
|
|
|
|
--- 玩家BeginPlay触发
|
|
function MiniGameMode_RPGChaoticWar:PlayerBeginPlay(PlayerPawn)
|
|
PlayerPawn:SetGravityScale(self.PlayerGravityScale)
|
|
PlayerPawn:SetCustomJumpZVelocity(443 * self.JumpScale)
|
|
UGCEventSystem.SetTimer(UGCGameSystem.GameState, function()
|
|
if UE.IsValid(PlayerPawn) then
|
|
PlayerPawn:SetGravityScale(self.PlayerGravityScale)
|
|
PlayerPawn:SetCustomJumpZVelocity(443 * self.JumpScale)
|
|
UGCPawnAttrSystem.SetSpeedScale(PlayerPawn, self.MoveSpeedScale)
|
|
UGCLogSystem.Log("[MiniGameMode_RPGChaoticWar_PlayerBeginPlay]")
|
|
end
|
|
end, 1)
|
|
end
|
|
|
|
---------------------------------------- Player End ----------------------------------------
|
|
|
|
function MiniGameMode_RPGChaoticWar:PlayerPickStar(PlayerKey)
|
|
UGCGameSystem.GameState:PlayerAddMiniGameScore(PlayerKey, 1)
|
|
MiniGameConfig.CheckPlayerTask(PlayerKey, MiniGameConfig.MiniGameType.RPGChaoticWar, UGCGameSystem.GameState:GetPlayerMiniGameScore(PlayerKey), false)
|
|
end
|
|
|
|
--- 验证背包
|
|
function MiniGameMode_RPGChaoticWar:CheckBackPack()
|
|
local AllPawn = UGCGameSystem.GetAllPlayerPawn()
|
|
for _, PlayerPawn in pairs(AllPawn) do
|
|
for i, ItemID in pairs(self.DefaultBackPack) do
|
|
if ItemID > 0 and UGCBackPackSystem.GetItemCount(PlayerPawn, ItemID) == 0 then
|
|
UGCBackPackSystem.AddItem(PlayerPawn, ItemID, 1)
|
|
--if ItemID < 200000 then
|
|
-- for __, SlotType in pairs(ShootWeaponEnums) do
|
|
-- local Gun = UGCWeaponManagerSystem.GetWeaponBySlot(PlayerPawn, SlotType)
|
|
-- if Gun then
|
|
-- local GunReloadTime = UGCGunSystem.GetReloadTime(Gun)
|
|
-- UGCLogSystem.Log("[MiniGameMode_RPGChaoticWar_CheckBackPack] GunReloadTime:%s", tostring(GunReloadTime))
|
|
-- UGCGunSystem.SetReloadTime(Gun, self.ReloadTime)
|
|
-- UGCGunSystem.SetTacticalReloadTime(Gun, self.ReloadTime)
|
|
-- end
|
|
-- end
|
|
--end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
|
|
return MiniGameMode_RPGChaoticWar |