server/states: Adjust to new RoundManager

This commit is contained in:
Michael Fabian 'Xaymar' Dirks
2019-08-15 15:46:14 +02:00
parent f31244432e
commit eafb71c5bb
7 changed files with 71 additions and 54 deletions
@@ -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
@@ -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
end
_G["StateHide"] = CLASS
@@ -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
end
_G["StatePostMatch"] = CLASS
@@ -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
end
_G["StatePostRound"] = CLASS
@@ -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: <Original> 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
end
_G["StatePreMatch"] = CLASS
@@ -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
@@ -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
end
_G["StateSeek"] = CLASS