-
Notifications
You must be signed in to change notification settings - Fork 2
/
hud_leaderboard.lua
379 lines (308 loc) · 14.2 KB
/
hud_leaderboard.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
local hudTimer = 0
local fade = 0
local addedStats = false
local function update()
if hudTimer > 0 then
hudTimer = hudTimer - 1
end
end
local function hud_black_bg()
local theme = get_selected_theme()
local screenWidth = djui_hud_get_screen_width()
local screenHeight = djui_hud_get_screen_height()
djui_hud_set_color(theme.background.r, theme.background.g, theme.background.b, fade)
djui_hud_render_rect(0, 0, screenWidth, screenHeight)
end
local function hud_winner_group_render()
local theme = get_selected_theme()
local text = "What the heck is happening."
if gGlobalSyncTable.roundState == ROUND_RUNNERS_WIN then
text = "Runners Win!"
if gGlobalSyncTable.gamemode == FREEZE_TAG and gGlobalSyncTable.freezeHealthDrain > 0 then
text = "Runners and Frozen Win!"
end
elseif gGlobalSyncTable.roundState == ROUND_TAGGERS_WIN then
text = "Taggers Win!"
if gGlobalSyncTable.gamemode == INFECTION then
text = "Infected Win!"
elseif gGlobalSyncTable.gamemode == HOT_POTATO then
text = "Potato Wielders Win!"
elseif gGlobalSyncTable.gamemode == ASSASSINS then
text = "Assassins Win!"
elseif gGlobalSyncTable.gamemode == SARDINES then
text = "Leaderboard"
end
end
local screenWidth = djui_hud_get_screen_width()
local width = djui_hud_measure_text(text)
local x = (screenWidth - width) / 2
local y = 20
djui_hud_set_color(theme.text.r, theme.text.g, theme.text.b, fade)
djui_hud_print_text(text, x, y, 1)
end
local function hud_leaderboard()
local theme = get_selected_theme()
local renderedIndex = 0
local winners = {}
for i = 0, MAX_PLAYERS - 1 do
if gNetworkPlayers[i].connected then
if gGlobalSyncTable.roundState == ROUND_TAGGERS_WIN then
if gPlayerSyncTable[i].state ~= TAGGER or gPlayerSyncTable[i].amountOfTags <= 0 then goto continue end
elseif gGlobalSyncTable.roundState == ROUND_RUNNERS_WIN then
-- cursed
if (gPlayerSyncTable[i].state ~= RUNNER
and gGlobalSyncTable.gamemode ~= SARDINES
and (gGlobalSyncTable.gamemode ~= FREEZE_TAG
or gGlobalSyncTable.freezeHealthDrain == 0))
or (gPlayerSyncTable[i].state ~= WILDCARD_ROLE
and (gPlayerSyncTable[i].state ~= RUNNER
or gGlobalSyncTable.gamemode == SARDINES)
and ((gGlobalSyncTable.gamemode == FREEZE_TAG
and gGlobalSyncTable.freezeHealthDrain > 0)
or gGlobalSyncTable.gamemode == SARDINES))
or gPlayerSyncTable[i].amountOfTimeAsRunner <= 0
then goto continue end
end
table.insert(winners, i)
end
::continue::
end
-- sort
if gGlobalSyncTable.roundState == ROUND_TAGGERS_WIN or gGlobalSyncTable.gamemode == FREEZE_TAG then
table.sort(winners, function (a, b)
return gPlayerSyncTable[a].amountOfTags > gPlayerSyncTable[b].amountOfTags
end)
elseif gGlobalSyncTable.roundState == ROUND_RUNNERS_WIN then
table.sort(winners, function (a, b)
return gPlayerSyncTable[a].amountOfTimeAsRunner > gPlayerSyncTable[b].amountOfTimeAsRunner
end)
end
-- stats
if not addedStats then
addedStats = true
local stat = stats[gGlobalSyncTable.gamemode]
-- playTime is handled in main.lua, save it here though
save_int("stats_" .. gGlobalSyncTable.gamemode .. "_playTime", stat.playTime)
save_int("stats_global_playTime", stats.globalStats.playTime)
if stat.runnerVictories ~= nil
and gGlobalSyncTable.roundState == ROUND_RUNNERS_WIN
and winners[1] == 0 then
stat.runnerVictories = stat.runnerVictories + 1
save_int("stats_" .. tostring(gGlobalSyncTable.gamemode) .. "_runnerVictories", stat.runnerVictories)
stats.globalStats.runnerVictories = stats.globalStats.runnerVictories + 1
save_int("stats_global_runnerVictories", stats.globalStats.runnerVictories)
elseif stat.taggerVictories ~= nil
and gGlobalSyncTable.roundState == ROUND_TAGGERS_WIN
and winners[1] == 0 then
stat.taggerVictories = stat.taggerVictories + 1
save_int("stats_" .. tostring(gGlobalSyncTable.gamemode) .. "_taggerVictories", stat.taggerVictories)
stats.globalStats.taggerVictories = stats.globalStats.taggerVictories + 1
save_int("stats_global_taggerVictories", stats.globalStats.taggerVictories)
end
if stat.totalTimeAsRunner ~= nil then
stat.totalTimeAsRunner = stat.totalTimeAsRunner + gPlayerSyncTable[0].amountOfTimeAsRunner
save_int("stats_" .. tostring(gGlobalSyncTable.gamemode) .. "_totalTimeAsRunner", stat.totalTimeAsRunner)
stats.globalStats.totalTimeAsRunner = stats.globalStats.totalTimeAsRunner + gPlayerSyncTable[0].amountOfTimeAsRunner
save_int("stats_global_totalTimeAsRunner", stats.globalStats.totalTimeAsRunner)
end
if stat.totalTags ~= nil then
stat.totalTags = stat.totalTags + gPlayerSyncTable[0].amountOfTags
save_int("stats_" .. tostring(gGlobalSyncTable.gamemode) .. "_totalTags", stat.totalTags)
stats.globalStats.totalTags = stats.globalStats.totalTags + gPlayerSyncTable[0].amountOfTags
save_int("stats_global_totalTags", stats.globalStats.totalTags)
end
-- if we are in tournament mode, add tournament points to stats
if gGlobalSyncTable.tournamentMode then
local addedPoints = 0
-- per tag we got, add half a point, round down
addedPoints = addedPoints + math.floor(gPlayerSyncTable[0].amountOfTags / 2)
-- depending on our placement, add points
if winners[1] == 0 then
addedPoints = addedPoints + 5
elseif winners[2] == 0 then
addedPoints = addedPoints + 3
elseif winners[3] == 0 then
addedPoints = addedPoints + 1
end
-- save to global stats
stats.globalStats.totalTournamentPoints = stats.globalStats.totalTournamentPoints + addedPoints
save_int("stats_global_totalTournamentPoints", stats.globalStats.totalTournamentPoints)
-- add to our points
gPlayerSyncTable[0].tournamentPoints = gPlayerSyncTable[0].tournamentPoints + addedPoints
-- increment tournament round
if network_is_server() then
gGlobalSyncTable.tournamentRound = gGlobalSyncTable.tournamentRound + 1
end
end
end
local position = 1
for w = 1, #winners do
local i = winners[w]
if gNetworkPlayers[i].connected then
local screenWidth = djui_hud_get_screen_width()
local width = 1000
local x = (screenWidth - width) / 2
local y = 110 + (renderedIndex * 50)
djui_hud_set_color(theme.rect.r, theme.rect.g, theme.rect.b, fade)
djui_hud_render_rect_rounded_outlined(x, y - 5, width, 42, theme.rectOutline.r, theme.rectOutline.g, theme.rectOutline.b, 3, fade)
x = screenWidth / 2 - width / 2 + 10
render_player_head(i, x, y, 1.9, 1.9, fade)
x = x + 40
-- decide what position this player should be at. Don't use w variable to allow for ties as shown below
if (gGlobalSyncTable.roundState == ROUND_TAGGERS_WIN or gGlobalSyncTable.gamemode == FREEZE_TAG) and w > 1 then
-- check the previous index and see if they tie, if they don't, increase position
if gPlayerSyncTable[i].amountOfTags ~= gPlayerSyncTable[winners[w - 1]].amountOfTags then
position = position + 1
end
elseif w > 1 then
-- check the previous index and see if they tie, if they don't, increase position
if gPlayerSyncTable[i].amountOfTimeAsRunner ~= gPlayerSyncTable[winners[w - 1]].amountOfTimeAsRunner then
position = position + 1
end
end
local text = "#" .. position
if position == 1 then
djui_hud_set_color(255, 215, 0, fade)
elseif position == 2 then
djui_hud_set_color(169, 169, 169, fade)
elseif position == 3 then
djui_hud_set_color(205, 127, 50, fade)
else
djui_hud_set_color(theme.text.r, theme.text.g, theme.text.b, fade)
end
djui_hud_print_text(text, x, y, 1)
x = x + djui_hud_measure_text(text) + 10
text = get_player_name(i)
djui_hud_set_color(theme.text.r, theme.text.g, theme.text.b, fade)
djui_hud_print_colored_text(text, x, y, 1, fade)
if gGlobalSyncTable.roundState == ROUND_RUNNERS_WIN then
if gGlobalSyncTable.gamemode ~= FREEZE_TAG then
text = "Time as runner: " .. math.floor(gPlayerSyncTable[i].amountOfTimeAsRunner / 30) .. "s"
else
text = "Saves: " .. gPlayerSyncTable[i].amountOfTags
end
else
if gGlobalSyncTable.gamemode ~= INFECTION then
text = "Tags: " .. gPlayerSyncTable[i].amountOfTags
else
text = "Infections: " .. gPlayerSyncTable[i].amountOfTags
end
end
local textWidth = djui_hud_measure_text(text)
x = screenWidth / 2 + width / 2 - textWidth - 10
if gPlayerSyncTable[i].amountOfTimeAsRunner / 30 < gGlobalSyncTable.amountOfTime / 30 or gGlobalSyncTable.roundState == ROUND_TAGGERS_WIN then
djui_hud_set_color(theme.text.r, theme.text.g, theme.text.b, fade)
elseif gPlayerSyncTable[i].amountOfTimeAsRunner / 30 >= gGlobalSyncTable.amountOfTime / 30
and gGlobalSyncTable.gamemode ~= HOT_POTATO and gGlobalSyncTable.gamemode ~= FREEZE_TAG then
djui_hud_set_color(255, 215, 0, fade)
else
djui_hud_set_color(theme.text.r, theme.text.g, theme.text.b, fade)
end
djui_hud_print_text(text, x, y, 1)
renderedIndex = renderedIndex + 1
end
end
if renderedIndex == 0 then
local text = ""
if gGlobalSyncTable.roundState == ROUND_RUNNERS_WIN then
if gGlobalSyncTable.gamemode == FREEZE_TAG and gGlobalSyncTable.freezeHealthDrain > 0 then
text = "No Runners or Frozen Won"
else
text = "No Runners Won"
end
elseif gGlobalSyncTable.roundState == ROUND_TAGGERS_WIN then
if gGlobalSyncTable.gamemode == INFECTION then
text = "No Infected Players Won"
elseif gGlobalSyncTable.gamemode == HOT_POTATO then
text = "No Potato Wielders Win"
elseif gGlobalSyncTable.gamemode == ASSASSINS then
text = "No Assassins Win"
elseif gGlobalSyncTable.gamemode == SARDINES then
text = "Nobody Wins"
else
text = "No Taggers Won"
end
end
local screenWidth = djui_hud_get_screen_width()
local screenHeight = djui_hud_get_screen_height()
local width = djui_hud_measure_text(text)
local x = (screenWidth - width) / 2
local y = screenHeight / 2
djui_hud_set_color(theme.text.r, theme.text.g, theme.text.b, fade)
djui_hud_print_text(text, x, y, 1)
end
end
local function hud_voting_begins_in()
local theme = get_selected_theme()
local text = tostring(math.floor(gGlobalSyncTable.displayTimer / 30) + 1) .. " seconds"
if gGlobalSyncTable.tournamentMode then
text = "Tournament Leaderboard in " .. text
elseif gGlobalSyncTable.doVoting and gGlobalSyncTable.autoMode then
text = "Voting begins in " .. text
elseif gGlobalSyncTable.autoMode then
text = "Next round in " .. text
else
text = "Returning to lobby in " .. text
end
local x = 40
local y = 20
djui_hud_set_color(theme.text.r, theme.text.g, theme.text.b, fade)
djui_hud_print_text(text, x, y, 1)
end
local function hud_gamemode()
local theme = get_selected_theme()
local text = "Gamemode is set to " .. get_gamemode_including_random(gGlobalSyncTable.gamemode)
local screenWidth = djui_hud_get_screen_width()
local width = djui_hud_measure_text(strip_hex(text))
local x = screenWidth - width - 40
local y = 60
djui_hud_set_color(theme.text.r, theme.text.g, theme.text.b, fade)
djui_hud_print_colored_text(text, x, y, 1, fade)
end
local function hud_modifier()
local theme = get_selected_theme()
local text = "Modifier is set to " .. get_modifier_including_random()
local screenWidth = djui_hud_get_screen_width()
local width = djui_hud_measure_text(strip_hex(text))
local x = screenWidth - width - 40
local y = 20
djui_hud_set_color(theme.text.r, theme.text.g, theme.text.b, fade)
djui_hud_print_colored_text(text, x, y, 1, fade)
end
local function hud_render()
if gGlobalSyncTable.roundState ~= ROUND_RUNNERS_WIN and gGlobalSyncTable.roundState ~= ROUND_TAGGERS_WIN then
fade = 0
hudTimer = 5 * 30
addedStats = false
return
end
-- set djui font and resolution
djui_hud_set_font(djui_menu_get_font())
djui_hud_set_resolution(RESOLUTION_DJUI)
-- render stuff
if hudTimer > 0.5 * 30 then
if fade < 255 then
fade = fade + 20
end
else
fade = fade - 20
end
fade = clamp(fade, 0, 255)
hud_black_bg()
hud_winner_group_render()
hud_leaderboard()
hud_voting_begins_in()
hud_gamemode()
hud_modifier()
end
---@param m MarioState
local function mario_update(m)
if m.playerIndex ~= 0 then return end
if gGlobalSyncTable.roundState ~= ROUND_RUNNERS_WIN
and gGlobalSyncTable.roundState ~= ROUND_TAGGERS_WIN then return end
m.freeze = 1
set_mario_action(m, ACT_NOTHING, 0)
end
hook_event(HOOK_UPDATE, update)
hook_event(HOOK_ON_HUD_RENDER, hud_render)
hook_event(HOOK_MARIO_UPDATE, mario_update)