forked from sionar/Botc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Global.ttslua
3373 lines (3097 loc) · 109 KB
/
Global.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
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
--[[
Blood in the Clocktower Scripted
Made by Sionar
UI code borrowed from Lost Savage and SilentxDream
--]]
------------------Constants
MOD_NAME = 'Blood on the Clocktower'
VERSION = '20.10.9'
LANGUAGE = 'ENG'
DEBUG = false
START_MESSAGE = 'Blood on the Clocktower\n Version [00FF00]' .. VERSION .. '[-]\n\n' ..
[[
[89C381]Player chat commands:[-]
[967BB6]c[-] : See the list of chat commands.
[967BB6]h[-] : Show the vote history.
[967BB6]r[-] : Show your character.
[967BB6]l[-] : Show all the logs.
[967BB6]n[-] : Show the night logs.
[967BB6]d[-] : Show the day logs.
[967BB6]w[-] [E29A8A]color[-] [49D5FD]message[-] : Whisper a player.
[967BB6].color[-] [49D5FD]message[-] : Whisper a player.
[89C381]Storyteller chat commands:[-]
[967BB6].m[-] [B8F161]player[-] [E29A8A]color[-] : Move a player to a color.
[967BB6].u[-] [B8F161]player[-] [FF007F]team[-] : Move a player to a team.
[967BB6].b[-] [E29A8A]color[-] : Move a color to Grey.
[967BB6].s[-] [E29A8A]color[-] [E29A8A]color[-]: Swap two colors + chars.
[967BB6].t[-] [E29A8A]color[-]: Make color traveler/non-traveler.'
]]
HELP_MESSAGE =
[[
[89C381]Player chat commands:[-]
[967BB6]c[-] : See the list of chat commands.
[967BB6]h[-] : Show the vote history.
[967BB6]r[-] : Show your character.
[967BB6]v[-] : Show the version number.
[967BB6]l[-] : Show all the logs.
[967BB6]n[-] : Show the night logs.
[967BB6]d[-] : Show the day logs.
[967BB6]w[-] [E29A8A]color[-] [49D5FD]message[-] : Whisper a player.[-]
[967BB6].color[-] [49D5FD]message[-] : Whisper a player.[-]
]]
STORYTELLER_MESSAGE =
[[
[89C381]Storyteller chat commands:[-]
[967BB6]n[-] : Show the night logs.
[967BB6]d[-] : Show the day logs.
[967BB6].m[-] [B8F161]player[-] [E29A8A]color[-] : Move a player to a color.
[967BB6].u[-] [B8F161]player[-] [FF007F]team[-] : Move a player to a team.
[967BB6].b[-] [E29A8A]color[-] : Move a color to Grey.
[967BB6].s[-] [E29A8A]color[-] [E29A8A]color[-]: Swap two colors + chars.
[967BB6].t[-] [E29A8A]color[-]: Make color traveler/non-traveler.
]]
TABLE_OFFSET = 0
STORYTELLER_TABLE_DIST = 129
COLORS = {'White', 'Brown', 'Red', 'Orange', 'Yellow', 'Green', 'Teal', 'Blue', 'Purple', 'Pink'}
COLORS_SEATABLE = {'White', 'Brown', 'Red', 'Orange', 'Yellow', 'Green', 'Teal', 'Blue', 'Purple', 'Pink', 'Black'}
COLORS_EX = {'Magenta', 'Lavender', 'Navy', 'Cyan', 'Mint', 'Lime', 'Peach', 'Coral', 'Maroon', 'Silver'}
COLORS_ALL = {'White', 'Brown', 'Red', 'Orange', 'Yellow', 'Green', 'Teal', 'Blue', 'Purple', 'Pink', 'Magenta', 'Lavender', 'Navy', 'Cyan', 'Mint', 'Lime', 'Peach', 'Coral', 'Maroon', 'Silver'}
COLORS_TYPE = {White = true, Brown = true, Red = true, Orange = true, Yellow = true, Green = true, Teal = true, Blue = true, Purple = true, Pink = true, Magenta = false, Lavender = false, Navy = false, Cyan = false, Mint = false, Lime = false, Peach = false, Coral = false, Maroon = false, Silver = false}
COLORS_BBC = {White = '[FFFFFF]', Brown = '[703A16]', Red = '[DA1917]', Orange = '[F3631C]', Yellow = '[E6E42B]', Green = '[30B22A]', Teal = '[20B09A]', Blue = '[1E87FF]', Purple = '[9F1FEF]', Pink = '[F46FCD]', Magenta = '[FF007F]', Lavender = '[967BB6]', Navy = '[616BD4]', Cyan = '[49D5FD]', Mint = '[89C381]', Lime = '[B8F161]', Peach = '[F1D4A2]', Coral = '[E29A8A]', Maroon = '[800000]', Silver = '[BEBEBE]', Black = '[3F3F3F]', Grey = '[AAAAAA]'}
COLORS_BBC_ROLE_TYPE = {Townsfolk = '[1E87FF]', Outsider = '[20B09A]', Minion = '[F3631C]', Demon = '[DA1917]', Traveler = '[30B22A]'}
COLORS_RGB = {White = {1,1,1}, Brown = {113/255,59/255,23/255}, Red = {219/255,26/255,24/255}, Orange = {244/255,100/255,29/255}, Yellow = {231/255,229/255,44/255}, Green = {49/255,179/255,43/255}, Teal = {33/255,177/255,155/255}, Blue = {31/255,136/255,255/255}, Purple = {160/255,32/255,240/255}, Pink = {245/255,112/255,206/255}, Magenta = {255/255,0/255,127/255}, Lavender = {150/255,123/255,182/255}, Navy = {99/255,109/255,212/255}, Cyan = {73/255,213/255,253/255}, Mint = {137/255,195/255,129/255}, Lime = {184/255,241/255,97/255}, Peach = {241/255,212/255,162/255}, Coral = {226/255,154/255,138/255}, Maroon = {128/255,0,0}, Silver = {190/255,190/255,190/255},}
FAKE_ZONE_RGB = {Magenta = {255/255,0/255,127/255,0.16}, Lavender = {150/255,123/255,182/255,0.16}, Navy = {0/255,0/255,128/255,0.16}, Cyan = {73/255,213/255,253/255,0.16}, Mint = {137/255,195/255,129/255,0.16}, Lime = {184/255,241/255,97/255,0.16}, Peach = {241/255,212/255,162/255,0.16}, Coral = {226/255,154/255,138/255,0.16}, Maroon = {128/255,0,0,0.16}, Silver = {190/255,190/255,190/255,0.16},}
COLORS_UI = {Magenta = "#FF007F40|#FF007FFF|#FF007F80|#FF007F80", Lavender = "#967BB640|#967BB6FF|#967BB680|#967BB680", Navy = "#00008040|#000080FF|#00008080|#00008080", Cyan = "#49D5FD40|#49D5FDFF|#49D5FD80|#49D5FD80", Mint = "#89C38140|#89C381FF|#89C38180|#89C38180", Lime = "#B8F16140|#B8F161FF|#B8F16180|#B8F16180", Peach = "#F1D4A240|#F1D4A2FF|#F1D4A280|#F1D4A280", Coral = "#E29A8A40|#E29A8AFF|#E29A8A80|#E29A8A80", Maroon = "#80000040|#800000FF|#80000080|#80000080", Silver = "#BEBEBE40|#BEBEBEFF|#BEBEBE80|#BEBEBE80"}
COLORS_ORDER = {White = 1, Brown = 2, Red = 3, Orange = 4, Yellow = 5, Green = 6, Teal = 7, Blue = 8, Purple = 9, Pink = 10, Magenta = 11, Lavender = 12, Navy = 13, Cyan = 14, Mint = 15, Lime = 16, Peach = 17, Coral = 18, Maroon = 19, Silver = 20}
VOTEHAND_SHOW_SCALE = {3,1,3}
VOTEHAND_HIDE_SCALE = {0.01,0.01,0.01}
BG_POS = {188, 141, -395}
#include GUIDs.ttslua
------------------Variables
objects = {}
tableSize = 10
firstLoad = true
storytellerMode = false
options = {
seatLock = false,
tableText = true,
decalsEnabled = true,
jokersDefault = true,
whispersOn = true,
whisperLengthOn = true,
safetyOn = true
}
timerID = 0
safetyExpired = true
started = false
lights = false
flipTimerExpired = true
autoTint = true
mode = 'TB'
notes = ''
history = {'[FFFFFF]Vote History:[-]'}
currentNominator = ''
currentNominated = ''
numAlive = 0
numPlayers = 0
numTrav = 0
currVotes = 0
currPlayers = 0
currMostVotes = 0
colors = {}
usedColors = {'White', 'Brown', 'Red', 'Orange', 'Yellow', 'Green', 'Teal', 'Blue', 'Purple', 'Pink', 'Magenta', 'Lavender', 'Navy', 'Cyan', 'Mint', 'Lime', 'Peach', 'Coral', 'Maroon', 'Silver'}
unusedColors = {}
for i = 1,10 do
unusedColors[COLORS_ALL[i]] = false
end
for i = 11,20 do
unusedColors[COLORS_ALL[i]] = true
end
removedColors = {}
chars = {}
angle = {}
lifeTokens = {}
lifeTokenPos = {}
canNominate = {}
canBeNominated = {}
living = {}
hasVote = {}
voted = {}
voteLock = {}
voteButtonsOn = {}
tokenTable = {}
decalTable = {}
for k,v in pairs(COLORS_ALL) do
lifeTokens[v] = {object = nil, vote = nil}
canNominate[v] = true
canBeNominated[v] = true
living[v] = true
hasVote[v] = true
voted[v] = false
voteLock[v] = false
voteButtonsOn[v] = false
end
players = {}
playersEx = {}
playersExIds = {}
avatarGuids = {}
for k,v in pairs(COLORS_EX) do
playersEx[v] = nil
playersExIds[v] = nil
avatarGuids[v] = nil
end
avatarUrl = ''
uiWhisperColor = {}
uiWhisperInput = {}
colorTable = false
uiVisibility = {}
charSheetActive = {}
for k,v in pairs(COLORS) do
uiVisibility[v] = true
charSheetActive[v] = false
end
uiVisibility['Black'] = true
charSheetActive['Black'] = false
customSet = false
imageLoaded = false
customList = {}
whisperActive = {}
for k,v in pairs(COLORS_ALL) do
whisperActive[v] = {}
for k1,v1 in pairs(COLORS_ALL) do
whisperActive[v][v1] = false
end
end
------------------Functions
function onLoad(saveString)
if saveString ~= nil then
local save = JSON.decode(saveString)
options = save['o']
started = save['s']
mode = save['m']
chars = save['r']
history = save['h']
playersExIds = save['p']
avatarGuids = save['a']
customSet = save['c']
imageLoaded = save['i']
customList = save['cl']
tableSize = save['t']
colors = save['co']
usedColors = save['ac']
unusedColors = save['uc']
removedColors = save['rc']
angle = save['an']
lights = save['l']
autoTint = save['at']
lifeTokenPos = save['lt']
end
assignStaticObjects()
assignDynamicObjects()
updateFakeZoneColliders()
setupObjects()
createFlipButtons()
Turns.order = {'Black', 'White', 'Brown', 'Red', 'Orange', 'Yellow', 'Green', 'Teal', 'Blue', 'Purple', 'Pink'}
updateTokenStatus()
refreshUI()
showExtensionUI()
if not started then
notes = START_MESSAGE
setNotes(notes)
updateNotebookTabs()
end
Wait.time(refreshObjects,5)
Wait.time(refreshBackground,1)
Wait.time(refreshNotes,1,-1)
Wait.time(updateTokenStatus,2,-1)
end
function onSave()
local save = {}
save['o'] = options
save['s'] = started
save['m'] = mode
save['r'] = chars
save['h'] = history
save['p'] = playersExIds
save['a'] = avatarGuids
save['c'] = customSet
save['i'] = imageLoaded
save['cl'] = customList
save['t'] = tableSize
save['co'] = colors
save['ac'] = usedColors
save['uc'] = unusedColors
save['rc'] = removedColors
save['an'] = angle
save['l'] = lights
save['at'] = autoTint
save['lt'] = lifeTokenPos
local saveString = JSON.encode(save)
return saveString
end
function assignStaticObjects()
objects.table = getObjectFromGUID(TABLE_GUID)
objects.storytellerTable = getObjectFromGUID(STORYTELLER_TABLE_GUID)
objects.scriptingZone = getObjectFromGUID(SCRIPTING_ZONE_GUID)
objects.bgObject = getObjectFromGUID(BG_OBJ_GUID)
objects.bgLight = getObjectFromGUID(BG_LIGHT_GUID)
objects.bgBox = getObjectFromGUID(BG_BOX_GUID)
objects.guillotine = getObjectFromGUID(GUILLOTINE_GUID)
objects.votePanel = getObjectFromGUID(VOTE_PANEL_GUID)
objects.storageBag = getObjectFromGUID(STORAGE_BAG_GUID)
objects.travelerBag = getObjectFromGUID(TRAVELER_BAG_GUID)
objects.voteTokenBag = getObjectFromGUID(VOTE_TOKEN_BAG_GUID)
objects.shroudBag = getObjectFromGUID(SHROUD_BAG_GUID)
objects.fabledReminderBag = getObjectFromGUID(FABLED_REMINDER_BAG_GUID)
objects.clock = getObjectFromGUID(CLOCK_GUID)
objects.secondHand = getObjectFromGUID(SECOND_HAND_GUID)
objects.minuteHand = getObjectFromGUID(MINUTE_HAND_GUID)
objects.hourHand = getObjectFromGUID(HOUR_HAND_GUID)
objects.nightHelper = getObjectFromGUID(NIGHT_HELPER_GUID)
objects.clockControls = getObjectFromGUID(CLOCK_CONTROLS_GUID)
objects.teamTool = getObjectFromGUID(TEAM_TOOL_GUID)
objects.characterTool = getObjectFromGUID(CHARACTER_TOOL_GUID)
objects.gameSettings = getObjectFromGUID(GAME_SETTINGS_GUID)
objects.playerDist = getObjectFromGUID(PLAYER_DIST_GUID)
objects.tableControls = getObjectFromGUID(TABLE_CONTROLS_GUID)
objects.seatTool = getObjectFromGUID(SEAT_TOOL_GUID)
end
function assignDynamicObjects()
objects.zones = {}
for k,v in pairs(ZONE_GUIDS) do
objects.zones[k] = getObjectFromGUID(v)
end
objects.avatarLights = {}
for k,v in pairs(AVATAR_LIGHT_GUIDS) do
objects.avatarLights[k] = getObjectFromGUID(v)
end
objects.nightLights = {}
for k,v in pairs(NIGHT_LIGHT_GUIDS) do
objects.nightLights[k] = getObjectFromGUID(v)
end
objects.lifeBases = {}
for k,v in pairs(LIFE_BASE_GUIDS) do
objects.lifeBases[k] = getObjectFromGUID(v)
end
objects.lifeTokens = {}
for k,v in pairs(LIFE_TOKEN_GUIDS) do
objects.lifeTokens[k] = getObjectFromGUID(v)
end
objects.voteHands = {}
for k,v in pairs(VOTEHAND_GUIDS) do
objects.voteHands[k] = getObjectFromGUID(v)
end
objects.dealBag = getObjectFromGUID(DEAL_BAG_GUID)
end
function setupObjects()
local obj
if objects.table ~= nil then
objects.table.interactable = false
end
if objects.storytellerTable ~= nil then
objects.storytellerTable.interactable = false
end
if objects.storageBag ~= nil then
objects.storageBag.interactable = false
end
if objects.bgObject ~= nil then
objects.bgObject.interactable = false
end
if objects.bgLight ~= nil then
objects.bgLight.interactable = false
end
if objects.bgBox ~= nil then
objects.bgBox.interactable = false
end
for color, nightLight in pairs(objects.nightLights) do
if nightLight ~= nil then
if DEBUG then
nightLight.setScale({1,1,1})
else
nightLight.setScale({0.01,0.01,0.01})
end
end
end
if objects.votePanel ~= nil then
objects.votePanel.interactable = false
end
for k,color in pairs(colors) do
obj = objects.lifeBases[color]
if obj ~= nil then
obj.setLock(true)
obj.interactable = false
end
obj = objects.lifeTokens[color]
if obj ~= nil then
obj.setLock(true)
end
obj = objects.voteHands[color]
if obj ~= nil then
obj.setLock(true)
obj.interactable = false
end
end
end
function updateNotebookTabs()
editNotebookTab(2, TB_LIST, 'Trouble Brewing Characters')
editNotebookTab(3, BM_LIST, 'Bad Moon Rising Characters')
editNotebookTab(4, SV_LIST, 'Sects & Violets Characters')
end
function editNotebookTab(tabIndex, charList, title)
local tab = {index = tabIndex, title = title, color = 'Grey'}
local text = ''
for k,v in pairs(TYPES) do
text = text .. '[i]' .. v .. '[/i]\r\n'
for k1,v1 in pairs(charList) do
if CHARACTERS[v1].Type == v then
text = text .. '\r\n[b]' .. v1 .. '[/b] - ' .. CHARACTERS[v1].Description
end
end
text = text .. '\r\n\n\r\n'
end
tab.body = text
Notes.editNotebookTab(tab)
end
function refreshObjects()
local obj, clock
if objects.teamTool ~= nil then
objects.teamTool = objects.teamTool.reload()
end
for k,color in pairs(colors) do
obj = objects.voteHands[color]
if obj ~= nil then
objects.voteHands[color] = obj.reload()
end
obj = objects.lifeBases[color]
if obj ~= nil then
objects.lifeBases[color] = obj.reload()
end
obj = objects.lifeTokens[color]
if obj ~= nil then
objects.lifeTokens[color] = obj.reload()
end
end
if objects.clockControls ~= nil then
local clockOn = objects.clockControls.getVar('clockOn')
if clockOn then
Wait.time(function () showVoteButtons({voteMode = 'execution'}) end, 2)
end
end
Wait.time(lockObjects, 2.1)
end
function refreshBackground()
if objects.bgObject ~= nil then
objects.bgObject = objects.bgObject.reload()
objects.bgObject.setLock(true)
objects.bgObject.interactable = false
end
end
function lockObjects()
local obj
for k,color in pairs(colors) do
obj = objects.voteHands[color]
if obj ~= nil then
obj.interactable = false
end
obj = objects.lifeBases[color]
if obj ~= nil then
obj.interactable = false
end
obj = objects.lifeTokens[color]
if obj ~= nil then
if storytellerMode then
obj.setLock(false)
else
obj.setLock(true)
end
end
end
createFlipButtons()
end
function resetNotes()
notes = START_MESSAGE
setNotes(notes)
end
function refreshNotes()
setNotes(notes)
end
function updateTokenStatus()
updatePlayers()
getLifeTokens()
handleLifeUI()
end
function updatePlayers()
local allPlayers = Player.getPlayers()
local found
local textObj
local prevNumPlayers = numPlayers
local currNumPlayers = 0
for k,v in pairs(COLORS) do
if Player[v].seated then
players[v] = Player[v]
currNumPlayers = currNumPlayers + 1
else
players[v] = nil
end
end
if Player['Black'].seated then
players['Black'] = Player['Black']
else
players['Black'] = nil
end
for k,v in pairs(COLORS_EX) do
if playersExIds[v] == nil then --no id for that color
playersEx[v] = nil
else
found = nil
for k1,v1 in pairs(allPlayers) do
if v1.steam_id == playersExIds[v] and v1.color == 'Grey' then
found = v1
currNumPlayers = currNumPlayers + 1
break
end
end
if found == nil then --cannot find player with that id
playersExIds[v] = nil
playersEx[v] = nil
objects.table.call('setName', {color = v, name = ''})
deleteAvatar(v)
else
playersEx[v] = found
end
end
players[v] = playersEx[v]
end
if objects.characterTool ~= nil and prevNumPlayers ~= currNumPlayers and not storytellerMode then
objects.characterTool.call('refreshMenu')
end
updateSitUI()
return players
end
function getPlayer(player)
for k,v in pairs(players) do
if v ~= nil and v.steam_id == player.steam_id then
return k
end
end
return nil
end
function getLifeTokens()
local base, pos
local lifeTokenFound, voteTokenFound, objectsFound
for k,v in pairs(COLORS_ALL) do
base = objects.lifeBases[v]
if base == nil then
lifeTokens[v].vote = nil
lifeTokens[v].object = nil
else
pos = base.getPosition()
lifeTokenFound = false
voteTokenFound = false
objectsFound = Physics.cast({
origin = pos,
direction = {0, 1, 0},
type = 1, -- int (1: Ray, 2: Sphere, 3: Box),
max_distance = 3,
debug = false-- bool (true = visualize cast),
}) -- returns { {Vector point, Vector normal, float distance, Object hit_object}, {...}, ...}
for i, hit in ipairs(objectsFound) do
if hit.hit_object.getName() == 'Life Token' then
lifeTokens[v].object = hit.hit_object
lifeTokenFound = true
elseif hit.hit_object.getName() == 'Vote Token' then
lifeTokens[v].vote = hit.hit_object
voteTokenFound = true
end
end
if not voteTokenFound then
lifeTokens[v].vote = nil
end
if not lifeTokenFound then
lifeTokens[v].object = nil
end
end
end
end
function handleLifeUI()
numAlive = 0
numPlayers = 0
local numberOfSkipped = 0 -- number of players not seated
local numberOfVotes = 0
local votesNeeded = 0
local allObjects = getAllObjects()
local allPlayers = Player.getPlayers()
local currentNumTrav = 0
local aliveTrav = 0
local zoneObj
for i=1,20 do
zoneObj = objects.zones[COLORS_ALL[i]]
if lifeTokens[COLORS_ALL[i]].object ~= nil and (players[COLORS_ALL[i]] ~= nil or storytellerMode) then
if started and i <= 10 and zoneObj ~= nil then
zoneObj.setValue(COLORS_ALL[i])
end
if started and i > 10 and zoneObj ~= nil then
zoneObj.setColorTint(FAKE_ZONE_RGB[COLORS_ALL[i]])
end
numPlayers = numPlayers + 1
if lifeTokens[COLORS_ALL[i]].object.is_face_down == true then -- if life token is face down...
if lifeTokens[COLORS_ALL[i]].vote ~= nil then -- ..then if a vote token is present
UI.setAttribute('aliveImage'..i - numberOfSkipped, 'image', 'deadWithVote'..i) -- counting skipped players to only make last images transparent
numberOfVotes = numberOfVotes + 1
else
UI.setAttribute('aliveImage'..i - numberOfSkipped, 'image', 'deadNoVote') -- counting skipped players to only make last images transparent
end
else
UI.setAttribute('aliveImage'..i - numberOfSkipped, 'image', 'alive'..i) -- counting skipped players to only make last images transparent
numAlive = numAlive +1
numberOfVotes = numberOfVotes + 1
if lifeTokens[COLORS_ALL[i]].object.getDescription() == 'Traveler' then
aliveTrav = aliveTrav + 1
end
end
if lifeTokens[COLORS_ALL[i]].object.getDescription() == 'Traveler' then
currentNumTrav = currentNumTrav + 1
end
else
if started and i <= 10 and zoneObj ~= nil and #allPlayers > 1 then
zoneObj.setValue('Black')
end
if started and i > 10 and zoneObj ~= nil and #allPlayers > 1 then
zoneObj.setColorTint({0.3,0.3,0.3,0.25})
end
numberOfSkipped = numberOfSkipped +1
UI.setAttribute('aliveImage'..21 - numberOfSkipped, 'image', 'empty') -- starting from 11 to work backwards through list of aliveImage
end
end
votesNeeded = math.ceil(numAlive/2)
if firstLoad or currPlayers ~= numAlive or currVotes ~= numberOfVotes or numTrav ~= currentNumTrav then
firstLoad = false
for k,v in pairs(allObjects) do
if v.getName() == 'Player Distribution Chart' then
v.call('updatePlayerDist', {num = numPlayers - currentNumTrav})
v.call('updateAlive', {numP = numPlayers, living = numAlive, nonTrav = numAlive - aliveTrav, withVotes = numberOfVotes, needed = votesNeeded})
end
end
end
if storytellerMode then
for k,v in pairs(allObjects) do
if v.getName() == 'Player Distribution Chart' then
v.call('updatePlayerDistST', {num = numPlayers - numTrav})
end
end
end
currPlayers = numAlive
currVotes = numberOfVotes
numTrav = currentNumTrav
end
function inTable(input, table)
for k,v in pairs(table) do
if input == v then
return true
end
end
return false
end
function findColor(input)
for k,v in pairs(COLORS_ALL) do
if string.match(string.lower(v), string.lower(input)) then
return v
end
end
if string.match('black', string.lower(input)) then
return 'Black'
end
return nil
end
------------------Table setup commands
function radius(rad, angle, height)
return {rad*math.sin(angle*math.pi/180), height, rad*math.cos(angle*math.pi/180) + TABLE_OFFSET}
end
function resizeTable()
local obj, objs, tab, pos, rot, colorPos
local charSheetGuids
local angleFirst, angleInc
local zoneSize
local radSt = tableSize * 0.6 + 6
local fontSize
local idx
local numGreySeats = getNumGreySeats()
if mode == 'TB' then
charSheetGuids = CHAR_SHEET_GUIDS_TB
elseif mode == 'BM' then
charSheetGuids = CHAR_SHEET_GUIDS_BM
elseif mode == 'SV' then
charSheetGuids = CHAR_SHEET_GUIDS_SV
elseif mode == 'CU' then
charSheetGuids = CHAR_SHEET_GUIDS_CU
end
updatePlayers()
colors = {}
unusedColors = {}
for i = 1, 20 do
unusedColors[COLORS_ALL[i]] = true
end
angle = {}
for i = 1, tableSize do
table.insert(colors, usedColors[i])
unusedColors[usedColors[i]] = false
angle[usedColors[i]] = (180 + 360 / tableSize * (i-1)) % 360
end
zoneSize = 2 * 71.5 * math.sin(math.pi / tableSize) * 0.67
if zoneSize > 40 then
zoneSize = 40
end
if tableSize > 10 and tableSize < 15 then
UI.setAttribute('sitTable', 'width', 100*(tableSize-10))
else
UI.setAttribute('sitTable', 'width', 500)
end
for k,color in pairs(colors) do
obj = objects.zones[color]
if obj == nil then
obj = objects.storageBag.takeObject({guid = ZONE_GUIDS[color], rotation = {0, angle[color], 0}})
objects.zones[color] = obj
end
if obj ~= nil then
obj.setLock(true)
obj.setScale({zoneSize,10,13})
obj.setPositionSmooth(radius(71.5,angle[color], 1))
obj.setRotationSmooth({0, angle[color], 0})
end
obj = getObjectFromGUID(charSheetGuids[color])
if obj ~= nil then
obj.setLock(true)
obj.setScale({1.64,1,1.64})
obj.setPositionSmooth(radius(72.5,angle[color], 1))
obj.setRotationSmooth({0, angle[color], 0})
obj.interactable = true
end
obj = objects.voteHands[color]
if obj == nil then
obj = objects.storageBag.takeObject({guid = VOTEHAND_GUIDS[color], rotation = {0, angle[color], 0}})
objects.voteHands[color] = obj
end
if obj ~= nil then
obj.setLock(true)
obj.setPositionSmooth(radius(75, angle[color], -5))
obj.setRotationSmooth({0, angle[color], 0})
end
obj = objects.lifeBases[color]
if obj == nil then
obj = objects.storageBag.takeObject({guid = LIFE_BASE_GUIDS[color], rotation = {0, angle[color], 0}})
objects.lifeBases[color] = obj
end
if obj ~= nil then
obj.setLock(true)
if storytellerMode then
obj.setPosition(radius(radSt, angle[color], 1))
obj.setRotation({0, angle[color], 0})
else
obj.setPosition(radius(55, angle[color], 1))
obj.setRotation({0, angle[color], 0})
end
end
if storytellerMode then
lifeTokenPos[color] = radius(radSt, angle[color], 1.35)
else
lifeTokenPos[color] = radius(55, angle[color], 1.35)
end
obj = lifeTokens[color].object
if (not obj and not started) or (not obj and started and chars[color] ~= nil and CHARACTERS[chars[color]].Type ~= 'Traveler') then
objs = objects.storageBag.getObjects()
for k,v in pairs(objs) do
if v.guid == LIFE_TOKEN_GUIDS[color] then
obj = objects.storageBag.takeObject({guid = LIFE_TOKEN_GUIDS[color]})
lifeTokens[color].object = obj
break
end
end
end
if obj ~= nil then
if storytellerMode then
obj.setLock(false)
else
obj.setLock(true)
end
obj.setScale({1.82,1,1.82})
if obj.is_face_down then
obj.setRotation({0,0,180})
else
obj.setRotation({0,0,0})
end
obj.setPosition(lifeTokenPos[color])
end
if lifeTokens[color].vote ~= nil then
if storytellerMode then
lifeTokens[color].vote.setPositionSmooth(radius(radSt, angle[color], 1.43))
else
lifeTokens[color].vote.setPositionSmooth(radius(55, angle[color], 1.43))
end
end
UI.setAttribute('select'..color,'active','true')
if COLORS_TYPE[color] == true then
Player[color].setHandTransform({position = radius(82,angle[color], 1), rotation = {0, angle[color] + 180, 0}, scale = {14,5,6.5}})
end
if COLORS_TYPE[color] == false then
obj = objects.avatarLights[color]
if obj == nil then
obj = objects.storageBag.takeObject({guid = AVATAR_LIGHT_GUIDS[color]})
objects.avatarLights[color] = obj
end
if obj ~= nil then
obj.setPositionSmooth(radius(81, angle[color], 6))
end
if avatarGuids[color] then
obj = getObjectFromGUID(avatarGuids[color])
if obj ~= nil then
obj.setPositionSmooth(radius(84, angle[color], 6))
obj.setRotationSmooth({180, angle[color], 180})
end
end
end
end
for k,color in pairs(COLORS_ALL) do
if unusedColors[color] == true then
voted[color] = false
obj = objects.zones[color]
if obj ~= nil then
objects.storageBag.putObject(obj)
end
obj = getObjectFromGUID(charSheetGuids[color])
if obj ~= nil then
obj.setScale({0.01,0.01,0.01})
obj.setPositionSmooth({0,-1,0 + TABLE_OFFSET})
end
obj = objects.voteHands[color]
if obj ~= nil then
obj.setScale(VOTEHAND_HIDE_SCALE)
objects.storageBag.putObject(obj)
end
obj = objects.lifeBases[color]
if obj ~= nil then
objects.storageBag.putObject(obj)
end
obj = objects.lifeTokens[color]
if obj ~= nil then
objects.storageBag.putObject(obj)
end
if lifeTokens[color].vote ~= nil then
objects.voteTokenBag.putObject(lifeTokens[color].vote)
end
UI.setAttribute('cell'..color,'active','false')
UI.setAttribute('select'..color,'active','false')
if COLORS_TYPE[color] == true then
Player[color].setHandTransform({position = {0,1000,0}, scale = {0,0,0}})
if Player[color].seated then
Player[color].changeColor('Grey')
end
end
if COLORS_TYPE[color] == false then
if players[color] ~= nil then
idx = getSeatIdx(color)
unsitGreyColor(players[color], color)
end
obj = objects.avatarLights[color]
if obj ~= nil then
objects.storageBag.putObject(obj)
end
end
end
end
objects.table.call('moveText', {tableSize = tableSize})
createSnapPoints()
toggleLights({switching = false})
UI.setAttribute('colorSelection','active',false)
local clockOn
if objects.clockControls ~= nil then
objects.clockControls.call('updateSettings')
clockOn = objects.clockControls.getVar('clockOn')
if clockOn then
objects.votePanel.call('createButtons')
end
end
Wait.time(updateFakeZoneColliders, 1)
showExtensionUI()
if storytellerMode then
if objects.playerDist ~= nil then
objects.playerDist.setPositionSmooth({0,1.25,0 + TABLE_OFFSET})
objects.playerDist.setRotationSmooth({0,0,0})
objects.playerDist.setScale({2 + 0.2 *(tableSize-5), 1, 2 + 0.2 *(tableSize-5)})
end
end
if objects.dealBag ~= nil then
objects.dealBag.setTable('previewChars', {})
objects.dealBag.call('generatePreview')
end
Wait.frames(assignDynamicObjects, 5)
Wait.time(lockObjects, 2)
end
function createSnapPoints()
local snapTable = {}
local pos, rad, radTokens
rad = tableSize * 0.4 + 6
radTokens = tableSize * 0.6 + 6
table.insert(snapTable, {position = {0,0,0 + TABLE_OFFSET}, rotation = {0,180,0}, rotation_snap = true})
table.insert(snapTable, {position = {-12,0,0 + TABLE_OFFSET}, rotation = {0,180,0}, rotation_snap = true})
table.insert(snapTable, {position = {12,0,0 + TABLE_OFFSET}, rotation = {0,180,0}, rotation_snap = true})
table.insert(snapTable, {position = {26,0,111 + TABLE_OFFSET}, rotation = {0,0,0}, rotation_snap = true})
table.insert(snapTable, {position = {-4,1.12, STORYTELLER_TABLE_DIST + TABLE_OFFSET}, rotation = {0,0,0}, rotation_snap = true})
table.insert(snapTable, {position = {0,1.12, STORYTELLER_TABLE_DIST + TABLE_OFFSET}, rotation = {0,0,0}, rotation_snap = true})
table.insert(snapTable, {position = {4,1.12, STORYTELLER_TABLE_DIST + TABLE_OFFSET}, rotation = {0,0,0}, rotation_snap = true})
for k,color in pairs(colors) do
if not storytellerMode then
table.insert(snapTable, {position = radius(55, angle[color], 1.16), rotation = {0, angle[color], 0}, rotation_snap = true})
else
table.insert(snapTable, {position = radius(radTokens, angle[color], 1.16), rotation = {0, angle[color], 0}, rotation_snap = true})
end
pos = radius(rad, angle[color], 1.0)
pos[3] = pos[3] + STORYTELLER_TABLE_DIST
table.insert(snapTable, {position = pos, rotation = {0,0,0}, rotation_snap = false})
end
self.setSnapPoints(snapTable)
end
function updateFakeZoneColliders()
local component, obj
for k,color in pairs(COLORS_EX) do
obj = objects.zones[color]
if obj ~= nil then
component = obj.getComponent("BoxCollider")
component.set("enabled", false)
end
end
end
function setTokenTable()
local objs
local posTable = {}
local rad = tableSize * 0.4 + 6
local margin = 1.5
if started then
for k,v in pairs(colors) do
posTable[v] = radius(rad, angle[v], 1.0)
posTable[v][3] = posTable[v][3] + STORYTELLER_TABLE_DIST
end
tokenTable = {}
if objects.scriptingZone ~= nil then
objs = objects.scriptingZone.getObjects()
for k,v in pairs(colors) do
tokenTable[v] = {}
for k1, v1 in pairs(objs) do
if math.abs(posTable[v][1] - v1.getPosition()[1]) < margin and math.abs(posTable[v][3] - v1.getPosition()[3]) < margin then
table.insert(tokenTable[v], v1)
end
end
end
end
end
end
function setDecalTable()
local globalDecals = Global.getDecals()
local decalTab
if globalDecals == nil then
return
end
decalTable = {}
for k,v in pairs(colors) do
decalTable[v] = nil
for i = 1,#globalDecals do
if math.abs(globalDecals[i].position[1] - radius(48, angle[v], 1.1)[1]) < 0.01 and math.abs(globalDecals[i].position[3] - radius(48, angle[v], 1.1)[3]) < 0.01 then
decalTable[v] = i
end
end
end
end
function moveTokens()
local objs, pos
local posTable = {}
local rad = tableSize * 0.4 + 6
if started then
for k,v in pairs(colors) do
posTable[v] = radius(rad, angle[v], 1.0)
posTable[v][3] = posTable[v][3] + STORYTELLER_TABLE_DIST
if tokenTable[v] ~= nil then
for k1,v1 in pairs(tokenTable[v]) do
pos = v1.getPosition()
v1.setPosition({posTable[v][1], pos[2], posTable[v][3]})
v1.setRotation({0,0,0})
end
end
end