From 4a8b95bdb4053dd34e4687d78cc34b6a6f8b2523 Mon Sep 17 00:00:00 2001 From: Michael Fabian 'Xaymar' Dirks Date: Sat, 12 Jan 2019 21:17:49 +0100 Subject: [PATCH] Modify time logic to split RoundTime and StateTime Adds two new functions: - GM:GetRoundStateTime (Shared) - GM:SetRoundStateTime (Server) --- source/gamemodes/prophuntextended/gamemode/init.lua | 12 +++++++++--- .../gamemode/server/states/state_hide.lua | 13 +++++-------- .../gamemode/server/states/state_preround.lua | 7 ++++++- .../gamemode/server/states/state_seek.lua | 12 ++++++------ .../gamemodes/prophuntextended/gamemode/sh_init.lua | 10 +++++++--- 5 files changed, 33 insertions(+), 21 deletions(-) diff --git a/source/gamemodes/prophuntextended/gamemode/init.lua b/source/gamemodes/prophuntextended/gamemode/init.lua index 388328b..a01a147 100644 --- a/source/gamemodes/prophuntextended/gamemode/init.lua +++ b/source/gamemodes/prophuntextended/gamemode/init.lua @@ -76,7 +76,9 @@ function GM:Initialize() print("Prop Hunt: Initializing Gamemode Data...") self.Data = {} - self.Data.StartTime = CurTime() + self.Data.RoundTime = 0 + self.Data.RoundStartTime = 0 + self.Data.StateTime = 0 print("Prop Hunt: Initializing Round Manager") self.RoundManager = roundManager(StatePreMatch) @@ -275,12 +277,16 @@ function GM:SetRound(Round) SetGlobalInt("Round", Round) end +function GM:SetRoundTime(Time) + SetGlobalInt("RoundTime", Time) +end + function GM:SetRoundState(State) SetGlobalInt("RoundState", State) end -function GM:SetRoundTime(Time) - SetGlobalInt("RoundTime", Time) +function GM:SetRoundStateTime(Time) + SetGlobalInt("RoundStateTime", Time) end function GM:SetRoundWinner(Winner) diff --git a/source/gamemodes/prophuntextended/gamemode/server/states/state_hide.lua b/source/gamemodes/prophuntextended/gamemode/server/states/state_hide.lua index b7e3984..b76882a 100644 --- a/source/gamemodes/prophuntextended/gamemode/server/states/state_hide.lua +++ b/source/gamemodes/prophuntextended/gamemode/server/states/state_hide.lua @@ -29,21 +29,18 @@ StateHide = state("Hide") function StateHide:OnEnter(OldState) if GAMEMODE.Config:DebugLog() then print("StateHide: OnEnter") end GAMEMODE:SetRoundState(GAMEMODE.States.Hide) - - -- Round Data - GAMEMODE.Data.RoundTime = math.abs(GAMEMODE.Config.Round:BlindTime()) - GAMEMODE.Data.RoundStartTime = CurTime() - - GAMEMODE:SetRoundTime(GAMEMODE.Data.RoundTime) end function StateHide:Tick() -- Update Game Time - GAMEMODE.Data.RoundTime = math.abs(GAMEMODE.Config.Round:BlindTime()) - (CurTime() - GAMEMODE.Data.RoundStartTime) + local deltaTime = (CurTime() - GAMEMODE.Data.RoundStartTime) + GAMEMODE.Data.RoundTime = GAMEMODE.Config.Round:Time() - deltaTime + GAMEMODE.Data.StateTime = math.abs(GAMEMODE.Config.Round:BlindTime()) - deltaTime GAMEMODE:SetRoundTime(GAMEMODE.Data.RoundTime) + GAMEMODE:SetRoundStateTime(GAMEMODE.Data.StateTime) -- Advance to Seeking State - if (GAMEMODE.Data.RoundTime <= 0) then + if (GAMEMODE.Data.StateTime <= 0) then if GAMEMODE.Config:Debug() then print("StateHide: Advancing to Seek stage.") end GAMEMODE.RoundManager:SetState(StateSeek) diff --git a/source/gamemodes/prophuntextended/gamemode/server/states/state_preround.lua b/source/gamemodes/prophuntextended/gamemode/server/states/state_preround.lua index 23f24cc..93ac0d3 100644 --- a/source/gamemodes/prophuntextended/gamemode/server/states/state_preround.lua +++ b/source/gamemodes/prophuntextended/gamemode/server/states/state_preround.lua @@ -34,11 +34,16 @@ function StatePreRound:OnEnter(OldState) -- Clean Up the Map game.CleanUpMap() + -- Set Round Start Time + GAMEMODE.Data.RoundStartTime = CurTime() + end + function StatePreRound:Tick() -- Advance State GAMEMODE.RoundManager:SetState(StateHide) end + function StatePreRound:OnLeave(NewState) if GAMEMODE.Config:DebugLog() then print("StatePreRound: OnLeave") end @@ -60,4 +65,4 @@ function StatePreRound:OnLeave(NewState) -- Fretta Hooks hook.Run("RoundStart") -end \ No newline at end of file +end diff --git a/source/gamemodes/prophuntextended/gamemode/server/states/state_seek.lua b/source/gamemodes/prophuntextended/gamemode/server/states/state_seek.lua index 7517fae..5065c1f 100644 --- a/source/gamemodes/prophuntextended/gamemode/server/states/state_seek.lua +++ b/source/gamemodes/prophuntextended/gamemode/server/states/state_seek.lua @@ -31,9 +31,6 @@ function StateSeek:OnEnter(OldState) if GAMEMODE.Config:DebugLog() then print("StateSeek: OnEnter") end GAMEMODE:SetRoundState(GAMEMODE.States.Seek) - -- Round Data - GAMEMODE.Data.RoundTime = GAMEMODE.Config.Round:Time() - -- Unfreeze Seekers for i, ply in ipairs(team.GetPlayers(GAMEMODE.Teams.Seekers)) do ply:Freeze(false) @@ -45,8 +42,11 @@ end function StateSeek:Tick() -- Update Game Time - GAMEMODE.Data.RoundTime = GAMEMODE.Config.Round:Time() - (CurTime() - GAMEMODE.Data.RoundStartTime) + local deltaTime = (CurTime() - GAMEMODE.Data.RoundStartTime) + GAMEMODE.Data.RoundTime = GAMEMODE.Config.Round:Time() - deltaTime + GAMEMODE.Data.StateTime = GAMEMODE.Config.Round:Time() - deltaTime GAMEMODE:SetRoundTime(GAMEMODE.Data.RoundTime) + GAMEMODE:SetRoundStateTime(GAMEMODE.Data.StateTime) -- Victory Conditions local hiders, seekers = team.GetPlayers(GAMEMODE.Teams.Hiders), team.GetPlayers(GAMEMODE.Teams.Seekers) @@ -61,7 +61,7 @@ function StateSeek:Tick() end for i,ply in ipairs(seekers) do if (ply.Data.Alive) then - seekerAlive = true + seekerAlive = truew end end if (hiderAlive == false) then @@ -77,7 +77,7 @@ function StateSeek:Tick() GAMEMODE:SetRoundWinner(GAMEMODE.Teams.Hiders) GAMEMODE.RoundManager:SetState(StatePostRound) else - if (GAMEMODE.Data.RoundTime <= 0) then -- No Time remaining + if (GAMEMODE.Data.StateTime <= 0) then -- No Time remaining GAMEMODE:SetRoundWinner(GAMEMODE.Teams.Hiders) GAMEMODE.RoundManager:SetState(StatePostRound) end diff --git a/source/gamemodes/prophuntextended/gamemode/sh_init.lua b/source/gamemodes/prophuntextended/gamemode/sh_init.lua index b03eb75..953025f 100644 --- a/source/gamemodes/prophuntextended/gamemode/sh_init.lua +++ b/source/gamemodes/prophuntextended/gamemode/sh_init.lua @@ -49,7 +49,7 @@ GM.States.PostMatch = 5 -- Game Modes GM.Types = {} GM.Types.Original = 0 -GM.Types.TheDeadHunt = 1 -- One Hunter, Dead Prop become Hunter, Props can't see each other. +GM.Types.TheDeadHunt = 1 -- Deprecated: One Hunter, Dead Prop become Hunter, Props can't see each other. -- Teams GM.Teams = {} @@ -115,12 +115,16 @@ function GM:GetRound() return GetGlobalInt("Round", 0) end +function GM:GetRoundTime() + return GetGlobalInt("RoundTime", 0) +end + function GM:GetRoundState() return GetGlobalInt("RoundState", self.States.PreMatch) end -function GM:GetRoundTime() - return GetGlobalInt("RoundTime", 0) +function GM:GetRoundStateTime() + return GetGlobalInt("RoundStateTime", 0) end function GM:GetRoundWinner()