-
Notifications
You must be signed in to change notification settings - Fork 1
/
Bingo.ttslua
553 lines (515 loc) · 16.7 KB
/
Bingo.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
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
--[[
Secret Hitler Expansion
Made by Sionar
--]]
------------------Constants
VERSION = '1.5.3'
NAME = 'Expansion Bingo'
START_POS = {x = 100, y = 1.1, z = -52}
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 = {2.5,1,2.5}
COLOR = {'White', 'Brown', 'Red', 'Orange', 'Yellow', 'Green', 'Teal', 'Blue', 'Purple', 'Pink'}
COORD =
{
White = {pos = {38.5, 1.06, -33}, rot = {0, 180, 0}},
Brown = {pos = {9.2, 1.06, -33}, rot = {0, 180, 0}},
Red = {pos = {-20.1, 1.06, -33}, rot = {0, 180, 0}},
Green = {pos = {-38.5, 1.06, 33}, rot = {0, 0, 0}},
Teal = {pos = {-9.2, 1.06, 33}, rot = {0, 0, 0}},
Blue = {pos = {20.1, 1.06, 33}, rot = {0, 0, 0}},
Orange = {pos = {-50, 1.06, -32.5}, rot = {0, 270, 0}},
Yellow = {pos = {-50, 1.06, 32.5}, rot = {0, 270, 0}},
Purple = {pos = {50, 1.06, 32.5}, rot = {0, 90, 0}},
Pink = {pos = {50, 1.06, -32.5}, rot = {0, 90, 0}},
}
BOOK =
{
'"Don\'t play to me, I have Pariah"',
'"Host advantage"',
'"I always play turn one Harbinger"',
'"If you\'re Hitler you deserved it"',
'"Is this an all lib game?"',
'"Nobody\'s coming out"',
'"What is this weeb shit?"',
'"Would I do X as X?"',
'Ability gets fizzled',
'All fascists outed',
'Altruist on Confirmed',
'Broker away four+ cards',
'Broker gets Jestered',
'Bullet gets bandited',
'Claimed card gets stolen',
'Collector forces topdeck',
'Confirmed player gets Mentored',
'Conflict over ability claim',
'Conflict over Reporter',
'Creative usage of Dervish',
'Cursed Crown kills player',
'Dagger on last play',
'Decider decides a vote with lib pres',
'Decider wins the game',
'Deep undercover fascist',
'Denouncer saves the game',
'Dervish on Harbinger player',
'Disruptor causes topdeck',
'Draw two libs with Fisherman',
'Elitist or Naysayer two libs away',
'Enforcer wins game',
'Ethereal gets Knighted',
'Everyone has "Not Hitler" except Hitler',
'Fas plays a reactionary ability on a fascist',
'Fas-fas conflict',
'Fascist plays Confirmed liberally',
'Fascist plays Spy liberally',
'Fascists gain majority',
'Fascists lose with Confirmed in hand',
'First president plays Swindler',
'Five+ players dead',
'Four+ players card contest',
'Gambler fails with one lib in deck',
'Gambler into top tier card',
'Game ends before Hitler Territory',
'Game ends with zero conflicts',
'Gravekeeper for roles',
'Harbinger gets Hacked',
'Heated argument between libs',
'Hitler comes out first',
'Hitler elected right after Hitler Territory',
'Hitler plays Desperado',
'Hitler saved with Confirmed',
'Hitler sniped with inspect',
'Hitler wins after playing Hero',
'Inspected lib conflicts inspector',
'Knight saves player',
'Lib conflicts two+ fascists',
'Lib gives fas strong ability with Reporter',
'Lib gives Confirmed to fascist',
'Lib Hacks or Sabs a lib',
'Lib pres cannot play to a lib',
'Liberal plays Surgeon',
'Liberal policies doubled ditched',
'Magician bullet',
'Martyr for liberal',
'Martyr Soulmate',
'Mentor self for one ability',
'Messiah resurrects three+ players',
'Mighty gets removed',
'Misvote on last play',
'Peacemaker saves the game',
'Peacemaker removes 4+ effects/artifacts',
'Player accidentally reveals cards',
'Player asks question instead of reading card',
'Player claims Underdog and doesn\'t play it',
'Player gets all cards stolen',
'Player given two bullets',
'Player joins a conflict',
'Player kills teammate',
'Player leaves right after game starts',
'Player lies about having Underdog',
'Player plays 10+ cards',
'Player not saved with Pacifist',
'Player ruins perfect card count',
'Player scammed with Trader',
'Post game lecture',
'Puppeteer on Detective',
'Questionable usage of Mimic',
'Questionable usage of Saboteur',
'Revised conflict',
'Round one conflict',
'Sab/Hacker gets Sabbed/Hacked',
'Scion for Confirmed',
'Scion for Underdog',
'Scout used to reshuffle',
'Self proclaimed confirmed lib',
'Senator into bullet',
'Senator into topdeck',
'Soulmate Puppeteered',
'Soulmate comboed',
'Spelunker into lib policy',
'Spiritualist saves the game',
'Spy own inspect',
'Successful Anarchist',
'Swindler gets Mimiced',
'Swindler gets negated',
'Three fas policies played in a row',
'Three lib policies played in a row',
'Too many libs claimed',
'Top tier card gets stolen',
'Topdeck corner',
'Topdeck into Hitler Territory',
'Topdeck with Usurper',
'Trickster for bullet',
'Two lib claim at reshuffle',
'Two or more Fascists dead',
'Two players silenced',
'Usurper saves the game',
'Veto spam into topdeck lib',
'Visionary gets Jestered',
'Voting abilities wasted',
'White tier ability gets copied or negated',
'Zero lib or fas inspect with Detective',
}
------------------Variables
phrase = {}
selected = {}
for i = 1,25 do
selected[i] = false
end
player_id = nil
selfColor = nil
title = 'Expansion 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'] or phrase
selected = save['s'] or selected
player_id = save['id']
selfColor = save['c']
title = save['t'] or title
tint = save['tint'] or tint
timerID = save['tid'] or timerID
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')
if global_name == 'Secret Hitler: CE' then
if player_id == nil then
local tab = getAllObjects()
local foundTab = {}
for _, v in pairs(tab) do
if string.match(v.getName(), NAME) then
table.insert(foundTab,1,v)
end
end
self.setPositionSmooth({START_POS['x'] + (#foundTab-1) * 30, START_POS['y'], START_POS['z']})
self.setLock(true)
end
end
end
function giveBoard(clickedButton, playerColor, index)
if Player[playerColor].admin then
local color = COLOR[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
if title == 'Expansion Bingo' then
broadcastToAll('Thats a bingo!', {1,1,1})
else
broadcastToAll(player_name.. ' got a bingo!', stringColorToRGB(selfColor))
end
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
relocateBoard()
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)
if player_id == nil then
local inc = -0.2
for i = 1,10 do
local buttonParam = {click_function = 'giveBoard'..i, color = stringColorToRGB(COLOR[i]), function_owner = self,
position = {-1.7,0.2,1.6+(i-1)*inc}, rotation = {0,0,0}, width = 350, height = 350, tooltip = 'Give board to ' .. COLOR[i], scale = {0.25,0.25,0.25}}
self.createButton(buttonParam)
end
end
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