-
Notifications
You must be signed in to change notification settings - Fork 4
/
PlayerState.lua
89 lines (59 loc) · 1.63 KB
/
PlayerState.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
--[[
This file contains the PlayerState class.
The PlayerState contains all the information needed for the player.
Currently this is only the selected and joined arena.
]]
local g_PlayerStates = {}
function cPlayerState(a_PlayerName)
local self = {}
local m_PlayerName = a_PlayerName
local m_JoinedArena
local m_SelectedArena
do
-- Returns true if the player did join an arena. Else it returns false
function self:DidJoinArena()
return (m_JoinedArena ~= nil)
end
-- Returns the arena that the player has joined.
function self:GetJoinedArena()
return m_JoinedArena
end
-- Leaves the current arena.
function self:LeaveArena()
m_JoinedArena = nil
end
-- Join an arena.
function self:JoinArena(a_ArenaName)
assert(type(a_ArenaName) == 'string')
m_JoinedArena = a_ArenaName
end
end
do
-- returns true if the player has an arena selected
function self:HasArenaSelected()
return (m_SelectedArena ~= nil)
end
-- Selects an arena. Returns false if it failed.
function self:SelectArena(a_ArenaName)
if (not ArenaExist(a_ArenaName)) then
return false, "The arena does not exist."
end
m_SelectedArena = a_ArenaName
return true
end
-- returns the arena wich the player has selected
function self:GetSelectedArena()
return m_SelectedArena
end
end
return self
end
function GetPlayerState(a_PlayerName)
assert(type(a_PlayerName) == "string")
if (g_PlayerStates[a_PlayerName]) then
return g_PlayerStates[a_PlayerName]
end
local PlayerState = cPlayerState(a_PlayerName)
g_PlayerStates[a_PlayerName] = PlayerState
return PlayerState
end