server/states: Adjust to new RoundManager
This commit is contained in:
@@ -22,32 +22,38 @@
|
|||||||
SOFTWARE.
|
SOFTWARE.
|
||||||
--]]
|
--]]
|
||||||
|
|
||||||
local stateDef = {}
|
local CLASS = {}
|
||||||
stateDef.__index = stateDef
|
CLASS.__index = CLASS
|
||||||
|
|
||||||
function stateDef:__construct()
|
function CLASS:__construct()
|
||||||
self.Name = ""
|
self.name = "Unnamed"
|
||||||
|
self.id = 0
|
||||||
end
|
end
|
||||||
|
|
||||||
function stateDef:GetName()
|
function CLASS:GetName()
|
||||||
return self.Name
|
return self.name
|
||||||
end
|
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 = {}
|
local obj = {}
|
||||||
obj.__index = obj
|
obj.__index = obj
|
||||||
setmetatable(obj, stateDef)
|
setmetatable(obj, CLASS)
|
||||||
obj:__construct()
|
obj:__construct()
|
||||||
if (name != nil) then
|
if (name != nil) then
|
||||||
obj.Name = name
|
obj.name = name
|
||||||
else
|
end
|
||||||
obj.Name = "Unnamed"
|
if (id != nil) then
|
||||||
|
obj.id = id
|
||||||
end
|
end
|
||||||
return obj;
|
return obj;
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -24,14 +24,14 @@
|
|||||||
|
|
||||||
include "base.lua"
|
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
|
if GAMEMODE.Config:DebugLog() then print("StateHide: OnEnter") end
|
||||||
GAMEMODE:SetRoundState(GAMEMODE.States.Hide)
|
GAMEMODE:SetRoundState(GAMEMODE.States.Hide)
|
||||||
end
|
end
|
||||||
|
|
||||||
function StateHide:Tick()
|
function CLASS:Tick()
|
||||||
-- Update Game Time
|
-- Update Game Time
|
||||||
local deltaTime = (CurTime() - GAMEMODE.Data.RoundStartTime)
|
local deltaTime = (CurTime() - GAMEMODE.Data.RoundStartTime)
|
||||||
GAMEMODE.Data.RoundTime = GAMEMODE.Config.Round:Time() - deltaTime
|
GAMEMODE.Data.RoundTime = GAMEMODE.Config.Round:Time() - deltaTime
|
||||||
@@ -43,7 +43,7 @@ function StateHide:Tick()
|
|||||||
if (GAMEMODE.Data.StateTime <= 0) then
|
if (GAMEMODE.Data.StateTime <= 0) then
|
||||||
if GAMEMODE.Config:Debug() then print("StateHide: Advancing to Seek stage.") end
|
if GAMEMODE.Config:Debug() then print("StateHide: Advancing to Seek stage.") end
|
||||||
|
|
||||||
GAMEMODE.RoundManager:SetState(StateSeek)
|
RoundManager:SetState(StateSeek)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Freeze Seekers
|
-- Freeze Seekers
|
||||||
@@ -56,9 +56,11 @@ function StateHide:Tick()
|
|||||||
-- ToDo: Logic for more game modes here?
|
-- ToDo: Logic for more game modes here?
|
||||||
end
|
end
|
||||||
|
|
||||||
function StateHide:OnLeave(NewState)
|
function CLASS:OnLeave(NewState)
|
||||||
if GAMEMODE.Config:Debug() then print("StateHide: OnLeave") end
|
if GAMEMODE.Config:Debug() then print("StateHide: OnLeave") end
|
||||||
|
|
||||||
-- Fretta Hooks
|
-- Fretta Hooks
|
||||||
hook.Run("PropHuntUnblind")
|
hook.Run("PropHuntUnblind")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
_G["StateHide"] = CLASS
|
||||||
|
|||||||
@@ -24,9 +24,9 @@
|
|||||||
|
|
||||||
include "base.lua"
|
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
|
if GAMEMODE.Config:DebugLog() then print("StatePostMatch: OnEnter") end
|
||||||
GAMEMODE:SetRoundState(GAMEMODE.States.PostMatch)
|
GAMEMODE:SetRoundState(GAMEMODE.States.PostMatch)
|
||||||
|
|
||||||
@@ -46,11 +46,13 @@ function StatePostMatch:OnEnter(OldState)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function StatePostMatch:Tick()
|
function CLASS:Tick()
|
||||||
-- Advance State
|
-- Advance State
|
||||||
GAMEMODE.RoundManager:SetState(self.NextState)
|
RoundManager:SetState(self.NextState)
|
||||||
end
|
end
|
||||||
|
|
||||||
function StatePostMatch:OnLeave(NewState)
|
function CLASS:OnLeave(NewState)
|
||||||
if GAMEMODE.Config:DebugLog() then print("StatePostMatch: OnLeave") end
|
if GAMEMODE.Config:DebugLog() then print("StatePostMatch: OnLeave") end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
_G["StatePostMatch"] = CLASS
|
||||||
|
|||||||
@@ -24,9 +24,9 @@
|
|||||||
|
|
||||||
include "base.lua"
|
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
|
if GAMEMODE.Config:DebugLog() then print("StatePostRound: OnEnter") end
|
||||||
GAMEMODE:SetRoundState(GAMEMODE.States.PostRound)
|
GAMEMODE:SetRoundState(GAMEMODE.States.PostRound)
|
||||||
|
|
||||||
@@ -36,10 +36,10 @@ function StatePostRound:OnEnter(OldState)
|
|||||||
hook.Run("RoundEnd")
|
hook.Run("RoundEnd")
|
||||||
end
|
end
|
||||||
|
|
||||||
function StatePostRound:Tick()
|
function CLASS:Tick()
|
||||||
-- Advance State
|
-- Advance State
|
||||||
if (CurTime() - GAMEMODE.Data.RoundStartTime) >= 5 then -- ToDo: configureable time?
|
if (CurTime() - GAMEMODE.Data.RoundStartTime) >= 5 then -- ToDo: configureable time?
|
||||||
GAMEMODE.RoundManager:SetState(StatePostMatch)
|
RoundManager:SetState(StatePostMatch)
|
||||||
local players = team.GetPlayers(GAMEMODE.Teams.Seekers)
|
local players = team.GetPlayers(GAMEMODE.Teams.Seekers)
|
||||||
table.Add(players, team.GetPlayers(GAMEMODE.Teams.Hiders))
|
table.Add(players, team.GetPlayers(GAMEMODE.Teams.Hiders))
|
||||||
|
|
||||||
@@ -139,6 +139,8 @@ function StatePostRound:Tick()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function StatePostRound:OnLeave(NewState)
|
function CLASS:OnLeave(NewState)
|
||||||
if GAMEMODE.Config:DebugLog() then print("StatePostRound: OnLeave") end
|
if GAMEMODE.Config:DebugLog() then print("StatePostRound: OnLeave") end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
_G["StatePostRound"] = CLASS
|
||||||
|
|||||||
@@ -24,33 +24,35 @@
|
|||||||
|
|
||||||
include "base.lua"
|
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
|
if GAMEMODE.Config:DebugLog() then print("StatePreMatch: OnEnter") end
|
||||||
GAMEMODE:SetRoundState(GAMEMODE.States.PreMatch)
|
GAMEMODE:SetRoundState(GAMEMODE.States.PreMatch)
|
||||||
|
|
||||||
math.randomseed(CurTime())
|
math.randomseed(CurTime())
|
||||||
end
|
end
|
||||||
|
|
||||||
function StatePreMatch:Tick()
|
function CLASS:Tick()
|
||||||
-- Debug: Auto Advance to PreRound State
|
-- Debug: Auto Advance to PreRound State
|
||||||
if (GAMEMODE.Config:Debug()) then
|
if (GAMEMODE.Config:Debug()) then
|
||||||
if GAMEMODE.Config:DebugLog() then print("StatePreMatch: Advancing to StatePreRound") end
|
if GAMEMODE.Config:DebugLog() then print("StatePreMatch: Advancing to StatePreRound") end
|
||||||
GAMEMODE.RoundManager:SetState(StatePreRound)
|
RoundManager:SetState(StatePreRound)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Game Mode: Basic
|
-- Game Mode: Basic
|
||||||
if (GAMEMODE.Config:GameType() == GAMEMODE.Types.Original) then
|
if (GAMEMODE.Config:GameType() == GAMEMODE.Types.Original) then
|
||||||
-- Both Teams must have at least 1 player.
|
-- Both Teams must have at least 1 player.
|
||||||
if ((team.NumPlayers(GAMEMODE.Teams.Seekers) >= 1) && (team.NumPlayers(GAMEMODE.Teams.Hiders) >= 1)) then
|
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: <Original> Have enough players to start match.") end
|
if GAMEMODE.Config:DebugLog() then print("StatePreMatch: <Original> Have enough players to start match.") end
|
||||||
end
|
end
|
||||||
-- TODO: Other Gamemodes
|
-- TODO: Other Gamemodes
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function StatePreMatch:OnLeave(NewState)
|
function CLASS:OnLeave(NewState)
|
||||||
if GAMEMODE.Config:DebugLog() then print("StatePreMatch: OnLeave") end
|
if GAMEMODE.Config:DebugLog() then print("StatePreMatch: OnLeave") end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
_G["StatePreMatch"] = CLASS
|
||||||
|
|||||||
@@ -24,9 +24,9 @@
|
|||||||
|
|
||||||
include "base.lua"
|
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
|
if GAMEMODE.Config:DebugLog() then print("StatePreRound: OnEnter") end
|
||||||
GAMEMODE:SetRoundState(GAMEMODE.States.PreRound)
|
GAMEMODE:SetRoundState(GAMEMODE.States.PreRound)
|
||||||
GAMEMODE:SetRound(GAMEMODE:GetRound() + 1)
|
GAMEMODE:SetRound(GAMEMODE:GetRound() + 1)
|
||||||
@@ -39,12 +39,12 @@ function StatePreRound:OnEnter(OldState)
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function StatePreRound:Tick()
|
function CLASS:Tick()
|
||||||
-- Advance State
|
-- Advance State
|
||||||
GAMEMODE.RoundManager:SetState(StateHide)
|
RoundManager:SetState(StateHide)
|
||||||
end
|
end
|
||||||
|
|
||||||
function StatePreRound:OnLeave(NewState)
|
function CLASS:OnLeave(NewState)
|
||||||
if GAMEMODE.Config:DebugLog() then print("StatePreRound: OnLeave") end
|
if GAMEMODE.Config:DebugLog() then print("StatePreRound: OnLeave") end
|
||||||
|
|
||||||
-- Respawn Everyone
|
-- Respawn Everyone
|
||||||
@@ -66,3 +66,5 @@ function StatePreRound:OnLeave(NewState)
|
|||||||
-- Fretta Hooks
|
-- Fretta Hooks
|
||||||
hook.Run("RoundStart")
|
hook.Run("RoundStart")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
_G["StatePreRound"] = CLASS
|
||||||
|
|||||||
@@ -24,10 +24,9 @@
|
|||||||
|
|
||||||
include "base.lua"
|
include "base.lua"
|
||||||
|
|
||||||
StateSeek = {}
|
local CLASS = state("Seek", GM.States.Seek)
|
||||||
StateSeek.Name = "Seek"
|
|
||||||
|
|
||||||
function StateSeek:OnEnter(OldState)
|
function CLASS:OnEnter(OldState)
|
||||||
if GAMEMODE.Config:DebugLog() then print("StateSeek: OnEnter") end
|
if GAMEMODE.Config:DebugLog() then print("StateSeek: OnEnter") end
|
||||||
GAMEMODE:SetRoundState(GAMEMODE.States.Seek)
|
GAMEMODE:SetRoundState(GAMEMODE.States.Seek)
|
||||||
|
|
||||||
@@ -40,7 +39,7 @@ function StateSeek:OnEnter(OldState)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function StateSeek:Tick()
|
function CLASS:Tick()
|
||||||
-- Update Game Time
|
-- Update Game Time
|
||||||
local deltaTime = (CurTime() - GAMEMODE.Data.RoundStartTime)
|
local deltaTime = (CurTime() - GAMEMODE.Data.RoundStartTime)
|
||||||
GAMEMODE.Data.RoundTime = GAMEMODE.Config.Round:Time() - deltaTime
|
GAMEMODE.Data.RoundTime = GAMEMODE.Config.Round:Time() - deltaTime
|
||||||
@@ -67,25 +66,25 @@ function StateSeek:Tick()
|
|||||||
if (hiderAlive == false) then
|
if (hiderAlive == false) then
|
||||||
if (seekerAlive == false) then -- Draw, both teams dead.
|
if (seekerAlive == false) then -- Draw, both teams dead.
|
||||||
GAMEMODE:SetRoundWinner(GAMEMODE.Teams.Spectators)
|
GAMEMODE:SetRoundWinner(GAMEMODE.Teams.Spectators)
|
||||||
GAMEMODE.RoundManager:SetState(StatePostRound)
|
RoundManager:SetState(StatePostRound)
|
||||||
else -- Seeker victory, Hiders dead
|
else -- Seeker victory, Hiders dead
|
||||||
GAMEMODE:SetRoundWinner(GAMEMODE.Teams.Seekers)
|
GAMEMODE:SetRoundWinner(GAMEMODE.Teams.Seekers)
|
||||||
GAMEMODE.RoundManager:SetState(StatePostRound)
|
RoundManager:SetState(StatePostRound)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
if (seekerAlive == false) then -- Hider Victory, Seeker dead.
|
if (seekerAlive == false) then -- Hider Victory, Seeker dead.
|
||||||
GAMEMODE:SetRoundWinner(GAMEMODE.Teams.Hiders)
|
GAMEMODE:SetRoundWinner(GAMEMODE.Teams.Hiders)
|
||||||
GAMEMODE.RoundManager:SetState(StatePostRound)
|
RoundManager:SetState(StatePostRound)
|
||||||
else
|
else
|
||||||
if (GAMEMODE.Data.StateTime <= 0) then -- No Time remaining
|
if (GAMEMODE.Data.StateTime <= 0) then -- No Time remaining
|
||||||
GAMEMODE:SetRoundWinner(GAMEMODE.Teams.Hiders)
|
GAMEMODE:SetRoundWinner(GAMEMODE.Teams.Hiders)
|
||||||
GAMEMODE.RoundManager:SetState(StatePostRound)
|
RoundManager:SetState(StatePostRound)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function StateSeek:OnLeave(NewState)
|
function CLASS:OnLeave(NewState)
|
||||||
if GAMEMODE.Config:DebugLog() then print("StateSeek: OnLeave") end
|
if GAMEMODE.Config:DebugLog() then print("StateSeek: OnLeave") end
|
||||||
|
|
||||||
if GAMEMODE:GetRoundWinner() == GAMEMODE.Teams.Seekers then
|
if GAMEMODE:GetRoundWinner() == GAMEMODE.Teams.Seekers then
|
||||||
@@ -105,3 +104,5 @@ function StateSeek:OnLeave(NewState)
|
|||||||
hook.Run("RoundVictoryDraw")
|
hook.Run("RoundVictoryDraw")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
_G["StateSeek"] = CLASS
|
||||||
|
|||||||
Reference in New Issue
Block a user