forked from TecProg-grupo4-2018-2/panel-attack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BattleRoom.lua
82 lines (69 loc) · 2.33 KB
/
BattleRoom.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
local logger = require("logger")
-- A Battle Room is a session of vs battles, keeping track of the room number, wins / losses etc
BattleRoom =
class(
function(self, mode)
self.playerWinCounts = {}
self.modifiedWinCounts = {}
self.playerWinCounts[1] = 0
self.playerWinCounts[2] = 0
self.modifiedWinCounts[1] = 0
self.modifiedWinCounts[2] = 0
self.mode = mode
self.playerNames = {} -- table with player which number -> display name
self.playerNames[1] = config.name or loc("player_n", "1")
self.playerNames[2] = loc("player_n", "2")
self.spectating = false
self.trainingModeSettings = nil
end
)
function BattleRoom.updateWinCounts(self, winCounts)
self.playerWinCounts = winCounts
end
function BattleRoom:totalGames()
local totalGames = 0
for _, winCount in ipairs(self.playerWinCounts) do
totalGames = totalGames + winCount
end
return totalGames
end
-- Returns the player with more win count.
-- TODO handle ties?
function BattleRoom.winningPlayer(self)
if not P2 then
return P1
end
if self.playerWinCounts[P1.player_number] >= self.playerWinCounts[P2.player_number] then
logger.trace("Player " .. P1.which .. " (" .. P1.player_number .. ") has more wins")
return P1
end
logger.trace("Player " .. P2.which .. " (" .. P2.player_number .. ") has more wins")
return P2
end
function BattleRoom.getPlayerWinCount(self, playerNumber)
return self.playerWinCounts[playerNumber] + self.modifiedWinCounts[playerNumber]
end
function BattleRoom.matchOutcome(self)
local gameResult = P1:gameResult()
if gameResult == nil then
return nil
end
local results = {}
if gameResult == 0 then -- draw
results["end_text"] = loc("ss_draw")
results["outcome_claim"] = 0
elseif gameResult == -1 then -- P2 wins
results["winSFX"] = P2:pick_win_sfx()
results["end_text"] = loc("ss_p_wins", GAME.battleRoom.playerNames[2])
-- win_counts will get overwritten by the server in net games
results["outcome_claim"] = P2.player_number
elseif gameResult == 1 then -- P1 wins
results["winSFX"] = P1:pick_win_sfx()
results["end_text"] = loc("ss_p_wins", GAME.battleRoom.playerNames[1])
-- win_counts will get overwritten by the server in net games
results["outcome_claim"] = P1.player_number
else
error("No win result")
end
return results
end