diff --git a/source/gamemodes/prophuntextended/gamemode/server/states/base.lua b/source/gamemodes/prophuntextended/gamemode/server/states/base.lua index d40ad53..789f342 100644 --- a/source/gamemodes/prophuntextended/gamemode/server/states/base.lua +++ b/source/gamemodes/prophuntextended/gamemode/server/states/base.lua @@ -22,32 +22,38 @@ SOFTWARE. --]] -local stateDef = {} -stateDef.__index = stateDef +local CLASS = {} +CLASS.__index = CLASS -function stateDef:__construct() - self.Name = "" +function CLASS:__construct() + self.name = "Unnamed" + self.id = 0 end -function stateDef:GetName() - return self.Name +function CLASS:GetName() + return self.name end -function stateDef:OnEnter() end +function CLASS:GetId() + return self.id +end -function stateDef:Tick() end +function CLASS:OnEnter() end -function stateDef:OnLeave() end +function CLASS:Tick() end -function state(name) +function CLASS:OnLeave() end + +function state(name, id) local obj = {} obj.__index = obj - setmetatable(obj, stateDef) + setmetatable(obj, CLASS) obj:__construct() if (name != nil) then - obj.Name = name - else - obj.Name = "Unnamed" + obj.name = name + end + if (id != nil) then + obj.id = id end return obj; end diff --git a/source/gamemodes/prophuntextended/gamemode/server/states/state_hide.lua b/source/gamemodes/prophuntextended/gamemode/server/states/state_hide.lua index b76882a..fe112ed 100644 --- a/source/gamemodes/prophuntextended/gamemode/server/states/state_hide.lua +++ b/source/gamemodes/prophuntextended/gamemode/server/states/state_hide.lua @@ -24,14 +24,14 @@ include "base.lua" -StateHide = state("Hide") +local CLASS = state("Hide", GM.States.Hide) -function StateHide:OnEnter(OldState) +function CLASS:OnEnter(OldState) if GAMEMODE.Config:DebugLog() then print("StateHide: OnEnter") end GAMEMODE:SetRoundState(GAMEMODE.States.Hide) end -function StateHide:Tick() +function CLASS:Tick() -- Update Game Time local deltaTime = (CurTime() - GAMEMODE.Data.RoundStartTime) GAMEMODE.Data.RoundTime = GAMEMODE.Config.Round:Time() - deltaTime @@ -43,7 +43,7 @@ function StateHide:Tick() if (GAMEMODE.Data.StateTime <= 0) then if GAMEMODE.Config:Debug() then print("StateHide: Advancing to Seek stage.") end - GAMEMODE.RoundManager:SetState(StateSeek) + RoundManager:SetState(StateSeek) end -- Freeze Seekers @@ -56,9 +56,11 @@ function StateHide:Tick() -- ToDo: Logic for more game modes here? end -function StateHide:OnLeave(NewState) +function CLASS:OnLeave(NewState) if GAMEMODE.Config:Debug() then print("StateHide: OnLeave") end -- Fretta Hooks hook.Run("PropHuntUnblind") -end \ No newline at end of file +end + +_G["StateHide"] = CLASS diff --git a/source/gamemodes/prophuntextended/gamemode/server/states/state_postmatch.lua b/source/gamemodes/prophuntextended/gamemode/server/states/state_postmatch.lua index 42ca168..6560cf3 100644 --- a/source/gamemodes/prophuntextended/gamemode/server/states/state_postmatch.lua +++ b/source/gamemodes/prophuntextended/gamemode/server/states/state_postmatch.lua @@ -24,9 +24,9 @@ include "base.lua" -StatePostMatch = state("PostMatch") +local CLASS = state("PostMatch", GM.States.PostMatch) -function StatePostMatch:OnEnter(OldState) +function CLASS:OnEnter(OldState) if GAMEMODE.Config:DebugLog() then print("StatePostMatch: OnEnter") end GAMEMODE:SetRoundState(GAMEMODE.States.PostMatch) @@ -46,11 +46,13 @@ function StatePostMatch:OnEnter(OldState) end end -function StatePostMatch:Tick() +function CLASS:Tick() -- Advance State - GAMEMODE.RoundManager:SetState(self.NextState) + RoundManager:SetState(self.NextState) end -function StatePostMatch:OnLeave(NewState) +function CLASS:OnLeave(NewState) if GAMEMODE.Config:DebugLog() then print("StatePostMatch: OnLeave") end -end \ No newline at end of file +end + +_G["StatePostMatch"] = CLASS diff --git a/source/gamemodes/prophuntextended/gamemode/server/states/state_postround.lua b/source/gamemodes/prophuntextended/gamemode/server/states/state_postround.lua index ee8da28..17d67bf 100644 --- a/source/gamemodes/prophuntextended/gamemode/server/states/state_postround.lua +++ b/source/gamemodes/prophuntextended/gamemode/server/states/state_postround.lua @@ -24,9 +24,9 @@ include "base.lua" -StatePostRound = state("PostRound") +local CLASS = state("PostRound", GM.States.PostRound) -function StatePostRound:OnEnter(OldState) +function CLASS:OnEnter(OldState) if GAMEMODE.Config:DebugLog() then print("StatePostRound: OnEnter") end GAMEMODE:SetRoundState(GAMEMODE.States.PostRound) @@ -36,10 +36,10 @@ function StatePostRound:OnEnter(OldState) hook.Run("RoundEnd") end -function StatePostRound:Tick() +function CLASS:Tick() -- Advance State if (CurTime() - GAMEMODE.Data.RoundStartTime) >= 5 then -- ToDo: configureable time? - GAMEMODE.RoundManager:SetState(StatePostMatch) + RoundManager:SetState(StatePostMatch) local players = team.GetPlayers(GAMEMODE.Teams.Seekers) table.Add(players, team.GetPlayers(GAMEMODE.Teams.Hiders)) @@ -139,6 +139,8 @@ function StatePostRound:Tick() end end -function StatePostRound:OnLeave(NewState) +function CLASS:OnLeave(NewState) if GAMEMODE.Config:DebugLog() then print("StatePostRound: OnLeave") end -end \ No newline at end of file +end + +_G["StatePostRound"] = CLASS diff --git a/source/gamemodes/prophuntextended/gamemode/server/states/state_prematch.lua b/source/gamemodes/prophuntextended/gamemode/server/states/state_prematch.lua index 173f359..8ea0eec 100644 --- a/source/gamemodes/prophuntextended/gamemode/server/states/state_prematch.lua +++ b/source/gamemodes/prophuntextended/gamemode/server/states/state_prematch.lua @@ -24,33 +24,35 @@ include "base.lua" -StatePreMatch = state("PreMatch") +local CLASS = state("PreMatch", GM.States.PreMatch) -function StatePreMatch:OnEnter(OldState) +function CLASS:OnEnter(OldState) if GAMEMODE.Config:DebugLog() then print("StatePreMatch: OnEnter") end GAMEMODE:SetRoundState(GAMEMODE.States.PreMatch) math.randomseed(CurTime()) end -function StatePreMatch:Tick() +function CLASS:Tick() -- Debug: Auto Advance to PreRound State if (GAMEMODE.Config:Debug()) then if GAMEMODE.Config:DebugLog() then print("StatePreMatch: Advancing to StatePreRound") end - GAMEMODE.RoundManager:SetState(StatePreRound) + RoundManager:SetState(StatePreRound) end -- Game Mode: Basic if (GAMEMODE.Config:GameType() == GAMEMODE.Types.Original) then -- Both Teams must have at least 1 player. if ((team.NumPlayers(GAMEMODE.Teams.Seekers) >= 1) && (team.NumPlayers(GAMEMODE.Teams.Hiders) >= 1)) then - GAMEMODE.RoundManager:SetState(StatePreRound) + RoundManager:SetState(StatePreRound) if GAMEMODE.Config:DebugLog() then print("StatePreMatch: Have enough players to start match.") end end -- TODO: Other Gamemodes end end -function StatePreMatch:OnLeave(NewState) +function CLASS:OnLeave(NewState) if GAMEMODE.Config:DebugLog() then print("StatePreMatch: OnLeave") end -end \ No newline at end of file +end + +_G["StatePreMatch"] = CLASS diff --git a/source/gamemodes/prophuntextended/gamemode/server/states/state_preround.lua b/source/gamemodes/prophuntextended/gamemode/server/states/state_preround.lua index 93ac0d3..a911127 100644 --- a/source/gamemodes/prophuntextended/gamemode/server/states/state_preround.lua +++ b/source/gamemodes/prophuntextended/gamemode/server/states/state_preround.lua @@ -24,9 +24,9 @@ include "base.lua" -StatePreRound = state("PreRound") +local CLASS = state("PreRound", GM.States.PreRound) -function StatePreRound:OnEnter(OldState) +function CLASS:OnEnter(OldState) if GAMEMODE.Config:DebugLog() then print("StatePreRound: OnEnter") end GAMEMODE:SetRoundState(GAMEMODE.States.PreRound) GAMEMODE:SetRound(GAMEMODE:GetRound() + 1) @@ -39,12 +39,12 @@ function StatePreRound:OnEnter(OldState) end -function StatePreRound:Tick() +function CLASS:Tick() -- Advance State - GAMEMODE.RoundManager:SetState(StateHide) + RoundManager:SetState(StateHide) end -function StatePreRound:OnLeave(NewState) +function CLASS:OnLeave(NewState) if GAMEMODE.Config:DebugLog() then print("StatePreRound: OnLeave") end -- Respawn Everyone @@ -66,3 +66,5 @@ function StatePreRound:OnLeave(NewState) -- Fretta Hooks hook.Run("RoundStart") end + +_G["StatePreRound"] = CLASS diff --git a/source/gamemodes/prophuntextended/gamemode/server/states/state_seek.lua b/source/gamemodes/prophuntextended/gamemode/server/states/state_seek.lua index 5065c1f..a500428 100644 --- a/source/gamemodes/prophuntextended/gamemode/server/states/state_seek.lua +++ b/source/gamemodes/prophuntextended/gamemode/server/states/state_seek.lua @@ -24,10 +24,9 @@ include "base.lua" -StateSeek = {} -StateSeek.Name = "Seek" +local CLASS = state("Seek", GM.States.Seek) -function StateSeek:OnEnter(OldState) +function CLASS:OnEnter(OldState) if GAMEMODE.Config:DebugLog() then print("StateSeek: OnEnter") end GAMEMODE:SetRoundState(GAMEMODE.States.Seek) @@ -40,7 +39,7 @@ function StateSeek:OnEnter(OldState) end end -function StateSeek:Tick() +function CLASS:Tick() -- Update Game Time local deltaTime = (CurTime() - GAMEMODE.Data.RoundStartTime) GAMEMODE.Data.RoundTime = GAMEMODE.Config.Round:Time() - deltaTime @@ -67,25 +66,25 @@ function StateSeek:Tick() if (hiderAlive == false) then if (seekerAlive == false) then -- Draw, both teams dead. GAMEMODE:SetRoundWinner(GAMEMODE.Teams.Spectators) - GAMEMODE.RoundManager:SetState(StatePostRound) + RoundManager:SetState(StatePostRound) else -- Seeker victory, Hiders dead GAMEMODE:SetRoundWinner(GAMEMODE.Teams.Seekers) - GAMEMODE.RoundManager:SetState(StatePostRound) + RoundManager:SetState(StatePostRound) end else if (seekerAlive == false) then -- Hider Victory, Seeker dead. GAMEMODE:SetRoundWinner(GAMEMODE.Teams.Hiders) - GAMEMODE.RoundManager:SetState(StatePostRound) + RoundManager:SetState(StatePostRound) else if (GAMEMODE.Data.StateTime <= 0) then -- No Time remaining GAMEMODE:SetRoundWinner(GAMEMODE.Teams.Hiders) - GAMEMODE.RoundManager:SetState(StatePostRound) + RoundManager:SetState(StatePostRound) end end end end -function StateSeek:OnLeave(NewState) +function CLASS:OnLeave(NewState) if GAMEMODE.Config:DebugLog() then print("StateSeek: OnLeave") end if GAMEMODE:GetRoundWinner() == GAMEMODE.Teams.Seekers then @@ -104,4 +103,6 @@ function StateSeek:OnLeave(NewState) -- Run external Hooks hook.Run("RoundVictoryDraw") end -end \ No newline at end of file +end + +_G["StateSeek"] = CLASS