forked from sionar/Botc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BingoBotc.ttslua
475 lines (435 loc) · 14.3 KB
/
BingoBotc.ttslua
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
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
--[[
Blood on the Clocktower Bingo
Made by Sionar
--]]
------------------Constants
VERSION = '1.4.6'
NAME = 'BotC Bingo'
START_ROT = {0,180,0}
X_POS = {}
Z_POS = {}
POS_START = -1.1
POS_INC = POS_START * -2 / 4
BOX_SIZE = 1000
for i = 1,5 do
X_POS[i] = POS_START + (i-1) * POS_INC
Z_POS[i] = POS_START + (i-1) * POS_INC
end
SCALE = {1.93,1,1.93}
COLORS = {'White', 'Brown', 'Red', 'Orange', 'Yellow', 'Green', 'Teal', 'Blue', 'Purple', 'Pink'}
COORD =
{
White = {pos = {-35.61, -0.15, -44.95}, rot = {0, 225, 0}},
Brown = {pos = {-53.40, -0.15, -21.24}, rot = {0, 255, 0}},
Red = {pos = {-56.77, -0.15, 8.35}, rot = {0, 285, 0}},
Orange = {pos = {-45.08, -0.15, 35.60}, rot = {0, 315, 0}},
Yellow = {pos = {-21.19, -0.15, 53.34}, rot = {0, 345, 0}},
Green = {pos = {8.43, -0.15, 56.83}, rot = {0, 15, 0}},
Teal = {pos = {35.70, -0.15, 45.11}, rot = {0, 45, 0}},
Blue = {pos = {53.43, -0.15, 21.21}, rot = {0, 75, 0}},
Purple = {pos = {56.88, -0.15, -8.33}, rot = {0, 105, 0}},
Pink = {pos = {45.08, -0.15, -35.62}, rot = {0, 135, 0}},
}
BOOK =
{
'Player leaves right after game starts',
'Two players claim the same character',
'Good misvotes on last day and loses',
'Demon executed day one',
'Game ends with no dead evil',
'Town executes every dead evil',
'"Is this an Athiest game?"',
'Two evil players fight against each other',
'Player revised character claim twice during same day',
'Poisoner targets Imp during night',
'Town dies to unclaimed Virgin',
'Spy dies to Virgin',
'Non-poisoned Empath finds two evils',
'Soldier gets targeted by demon',
'Ravenkeeper ability activates',
'Imp wins after killing himself',
'Mayor victory',
'Virgin nominates self and dies',
'Town executes Saint',
'Slayer kills Demon',
'Scarlet Woman becomes Imp from execution',
'Fortune Teller is their own red herring',
'Slayer kills Recluse',
'Mayor ability malfunctions last day and town loses',
'Monk saves a player',
'Nobody dies three days in a row',
'Player executed three times',
'Devils Advocate saves Demon',
'Devils Advocate saves a good player',
'Mastermind win',
'Lunatic ends the game without realizing they\'re not the Demon',
'Professor resurrects town',
'Courtier poisons demon',
'Minstrel blocks a triple Po kill',
'Shabaloth resurrects two+ players',
'Zombuul kills himself at night',
'Goon switches alignment two+ times',
'Tea lady saves a town',
'Exorcist blocks demon kill',
'Sailor executed and saved by his own ability',
'Grandmother dies from Demon killing grandchild',
'Moonchild kills a good player',
'Gossip killed by their own statement',
'Town executes good twin',
'Vortox wins via zero executions',
'Player commits suicide with madness',
'Mutant is never executed by the storyteller',
'Snake Charmer swaps to demon and wins',
'Snake Charmer snipes Demon night one',
'Philosopher becomes an Outsider and wins',
'Philosopher makes a player drunk',
'Pit-Hag transforms own demon',
'Pit-Hag makes multiple demons',
'Player dies to Witch day one',
'Klutz guesses wrong and loses',
'Cerenovus targets the demon',
'Fang-Gu converts an Outsider',
'Sage ability triggers',
'Juggler successfully juggles five players',
'Dead player executed from madness',
}
------------------Variables
phrase = {}
selected = {}
for i = 1,25 do
selected[i] = false
end
player_id = nil
selfColor = nil
title = 'Blood on the Clocktower Bingo'
player_name = nil
tint = {0,0,0}
direction = true
timerID = nil
------------------Functions
function onLoad(saveString)
if not (saveString == '') then
local save = JSON.decode(saveString)
phrase = save['p']
selected = save['s']
player_id = save['id']
selfColor = save['c']
title = save['t']
tint = save['tint']
timerID = save['tid']
end
self.use_grid = false
self.use_snap_points = false
refreshButtons()
setSquares()
moveBoard()
self.setDescription('v ' .. VERSION .. '\nMade by Sionar')
if player_id ~= nil then
checkStarted()
end
end
function onSave()
local save = {}
save['p'] = phrase
save['s'] = selected
save['id'] = player_id
save['c'] = selfColor
save['t'] = title
save['tint'] = tint
save['tid'] = timerID
local saveString = JSON.encode(save)
return saveString
end
function checkStarted()
Wait.time(checkStartedTimer, 5)
end
function checkStartedTimer()
local started = Global.getVar('started')
if started then
relocateBoard()
else
checkStarted()
end
end
function moveBoard()
local global_name = Global.getVar('MOD_NAME')
local TABLE_OFFSET
if global_name == 'Blood on the Clocktower' then
TABLE_OFFSET = Global.getVar('TABLE_OFFSET')
self.setPositionSmooth({-50,1.15, TABLE_OFFSET + 85})
self.setRotationSmooth({0,180,0})
self.setLock(true)
end
end
function giveBoard(clickedButton, playerColor, index)
if Player[playerColor].admin then
local color = COLORS[index]
if not Player[color].seated then
broadcastToColor('ERROR: Player not seated.', playerColor, {1,0,0})
else
self.setPositionSmooth(COORD[color].pos)
self.setRotationSmooth(COORD[color].rot)
self.setScale(SCALE)
player_id = Player[color].steam_id
player_name = Player[color].steam_name
title = player_name .. '\'s Bingo Board'
self.setName(title)
self.editButton({index= 25, label = title})
for i = 29,38 do
self.removeButton(i)
end
selfColor = color
shuffleSquares()
checkStarted()
end
end
end
function relocateBoard()
local players = getSeatedPlayers()
local found = false
for k,v in pairs(players) do
if Player[v].steam_id == player_id then
found = true
selfColor = v
player_name = Player[v].steam_name
break
end
end
if found then
self.setPositionSmooth(COORD[selfColor].pos)
self.setRotationSmooth(COORD[selfColor].rot)
else
self.destruct()
end
end
for k = 1,10 do
_G['giveBoard' .. k] = function(obj, col)
giveBoard(obj, col, k)
end
end
function ij(clickedButton, playerColor, i, j)
local ind = (i - 1) * 5 + (j - 1) + 1
selected[ind] = not selected[ind]
if selected[ind] then
self.editButton({index= ind - 1, color= {i/5,0.5,j/5}, font_color = {1,1,1}})
else
self.editButton({index= ind - 1, color= {1,1,1}, font_color = {0,0,0}})
end
checkBingo(i, j)
end
for i = 1,5 do
for j = 1,5 do
_G['ij' .. i .. j] =
function(obj, col)
ij(obj, col, i, j)
end
end
end
function checkBingo(i, j)
local indices = {}
local strings = {}
local gotBingo = false
local buttonTable = self.getButtons()
local type
suspendTint()
if selected[5*(i-1) + 1] and selected[5*(i-1) + 2] and selected[5*(i-1) + 3] and selected[5*(i-1) + 4] and selected[5*(i-1) + 5] then
gotBingo = true
indices = {5*(i-1) + 1, 5*(i-1) + 2, 5*(i-1) + 3, 5*(i-1) + 4, 5*(i-1) + 5}
type = 'column'
elseif selected[5*0 + j] and selected[5*1 + j] and selected[5*2 + j] and selected[5*3 + j] and selected[5*4 + j] then
gotBingo = true
indices = {5*0 + j, 5*1 + j, 5*2 + j, 5*3 + j, 5*4 + j}
type = 'row'
end
local square = (i-1) * 5 + j
if (square == 1 or square == 7 or square == 13 or square == 19 or square == 25) and selected[1] and selected[7] and selected[13] and selected[19] and selected[25] then
gotBingo = true
indices = {1, 7, 13, 19, 25}
type = 'd1'
end
if (square == 5 or square == 9 or square == 13 or square == 17 or square == 21) and selected[5] and selected[9] and selected[13] and selected[17] and selected[21] then
gotBingo = true
indices = {5, 9, 13, 17, 21}
type = 'd2'
end
if gotBingo then
broadcastToAll('Thats a bingo!', {1,1,1})
printToAll('Squares:', {1,1,1})
for i = 1,5 do
strings[i] = string.gsub(phrase[indices[i]], '\n', ' ')
printToAll(strings[i], buttonTable[indices[i]].color)
end
changeTint(i, j, type)
end
end
function nullFunc() end
function setSquares()
local x,y
phrase[13] = 'Free Square'
for i = 0, 24 do
self.editButton({index = i, label = format(phrase[i+1]), tooltip = format(phrase[i+1])})
if selected[i+1] then
x = math.ceil((i+1)/5)/5
y = (i%5 + 1)/5
self.editButton({index = i, color = {x,0.5,y}, font_color = {1,1,1}})
end
end
self.editButton({index = 12, color = {0.6,0.5,0.6}, font_color = {1,1,1}})
selected[13] = true
end
function shuffleSquaresFunc(clickedButton, playerColor)
if Player[playerColor].admin then
shuffleSquares()
end
end
function shuffleSquares()
local temp, randNum
clearSquares()
for i = 1, #BOOK do
phrase[i] = BOOK[i]
end
for i = #BOOK, 1, -1 do
randNum = math.random(1, i)
temp = phrase[randNum]
phrase[randNum] = phrase[i]
phrase[i] = temp
end
phrase[13] = 'Free\nSquare'
setSquares()
suspendTint()
end
function clearSquares()
suspendTint()
for i = 0, 24 do
selected[i+1] = false
self.editButton({index = i, color = {1,1,1}, font_color = {0,0,0}})
end
end
function toggleLock()
if player_id ~= nil then
if self.getLock() then
self.setLock(false)
else
self.setLock(true)
self.setPositionSmooth(COORD[selfColor].pos)
self.setRotationSmooth(COORD[selfColor].rot)
end
end
end
function format(string)
local lineMax = 14
local result
local lineLen = 0
local output = ''
for word in string.gmatch(string, '%g+') do
if lineLen + string.len(word) + 1 > lineMax then
output = output .. '\n' .. word
lineLen = string.len(word)
else
if lineLen == 0 then
output = output .. word
lineLen = lineLen + string.len(word)
else
output = output .. ' ' .. word
lineLen = lineLen + 1 + string.len(word)
end
end
end
return output
end
function refreshButtons()
self.clearButtons()
for i = 1,5 do
for j = 1,5 do
local buttonParam = {click_function = 'ij' .. i .. j, label = '', color = {1,1,1,1}, font_color = stringColorToRGB('Black'), function_owner = self,
position = {X_POS[i],0.2,Z_POS[j]}, rotation = {0,0,0}, width = BOX_SIZE, height = BOX_SIZE, font_size = 140, scale = {0.25,0.25,0.25}}
self.createButton(buttonParam)
end
end
local buttonParam = {click_function = 'nullFunc', label = title, color = {0,0,0,1}, font_color = stringColorToRGB('Blue'), function_owner = self,
position = {0,0.2,-1.5}, rotation = {0,0,0}, width = 0, height = 0, font_size = 480, scale = {0.25,0.25,0.25}}
self.createButton(buttonParam)
local buttonParam = {click_function = 'clearSquares', label = 'Clear\nSquares', color = stringColorToRGB('Blue'), font_color = stringColorToRGB('White'), function_owner = self,
position = {-0.8,0.2,1.6}, rotation = {0,0,0}, width = 1200, height = 800, font_size = 240, scale = {0.25,0.25,0.25}}
self.createButton(buttonParam)
local buttonParam = {click_function = 'shuffleSquaresFunc', label = 'Shuffle\nSquares', color = stringColorToRGB('Blue'), font_color = stringColorToRGB('White'), function_owner = self,
position = {0,0.2,1.6}, rotation = {0,0,0}, width = 1200, height = 800, font_size = 240, scale = {0.25,0.25,0.25}}
self.createButton(buttonParam)
local buttonParam = {click_function = 'toggleLock', label = 'Toggle\nLock', color = stringColorToRGB('Blue'), font_color = stringColorToRGB('White'), function_owner = self,
position = {0.8,0.2,1.6}, rotation = {0,0,0}, width = 1200, height = 800, font_size = 240, scale = {0.25,0.25,0.25}}
self.createButton(buttonParam)
end
function changeTint(i, j, type)
tint = {0,0.5,0}
if type == 'd2' then
tint[1] = 1
end
direction = true
timerID = Wait.time(function() colorTint(i,j,type) end, 0.01, -1)
end
function colorTint(i, j, type)
if type == 'row' then
if direction then
tint[1] = tint[1] + 0.01
if tint[1] >= 1 then
direction = not direction
end
else
tint[1] = tint[1] - 0.01
if tint[1] <= 0 then
direction = not direction
end
end
self.setColorTint({tint[1], 0.5, j/5})
elseif type == 'column' then
if direction then
tint[3] = tint[3] + 0.01
if tint[3] >= 1 then
direction = not direction
end
else
tint[3] = tint[3] - 0.01
if tint[3] <= 0 then
direction = not direction
end
end
self.setColorTint({i/5, 0.5, tint[3]})
elseif type == 'd1' then
if direction then
tint[1] = tint[1] + 0.01
tint[3] = tint[3] + 0.01
if tint[1] >= 1 then
direction = not direction
end
else
tint[1] = tint[1] - 0.01
tint[3] = tint[3] - 0.01
if tint[1] <= 0 then
direction = not direction
end
end
self.setColorTint({tint[1], 0.5, tint[3]})
elseif type == 'd2' then
if direction then
tint[1] = tint[1] + 0.01
tint[3] = tint[3] - 0.01
if tint[1] >= 1 then
direction = not direction
end
else
tint[1] = tint[1] - 0.01
tint[3] = tint[3] + 0.01
if tint[1] <= 0 then
direction = not direction
end
end
self.setColorTint({tint[1], 0.5, tint[3]})
end
end
function suspendTint()
if timerID then
Wait.stop(timerID)
self.setColorTint({0,0,0})
timerID = nil
end
end