-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTableTop_Dixit.lua
957 lines (805 loc) · 25.6 KB
/
TableTop_Dixit.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
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
--If you want to use a different deck of your own, create and load a fresh save with
--your deck somewhere, then copy its GUID and replace the one below labeled bigDeck_GUID.
--If you want to modify the deck I have, go to 'onLoad' below and put '--' before bigDeck.interactable,
--then use the gizmo tool at the top of the table where the deck is hidden, to lift it up.
bigDeck_GUID = '837a6f'
scoreClicked = false
storyCard = {
guid = nil,
number = nil,
storyTeller = nil
}
answer = {
position = {-29.34, 0.97, -2.16},
scale = {5.40, 1.00, 5.40},
rotation = {0.00, 180.00, 0.00}
}
playerColors = {
"Red",
"Yellow",
"Orange",
"Green",
"Blue",
"Purple",
"Pink",
"White"
}
scoreCounters = {
["Green"] = "92bc7d",
["Blue"] = "46c679",
["Purple"] = "2c9804",
["Pink"] = "b81596",
["White"] = "1de687",
["Red"] = "4c27b7",
["Orange"] = "b447ec",
["Yellow"] = "217709"
}
playerTokens = {
["Green"] = "de1faa",
["Blue"] = "21336c",
["Purple"] = "c7b29e",
["Pink"] = "d0e019",
["White"] = "7920a5",
["Red"] = "4102cf",
["Orange"] = "01ab47",
["Yellow"] = "3f5383"
}
scoreAvatars = {
["Green"] = "fb056c",
["Blue"] = "859a36",
["Purple"] = "92f730",
["Pink"] = "402eaa",
["White"] = "868415",
["Red"] = "e2d03a",
["Orange"] = "513ba3",
["Yellow"] = "018d64"
}
tokenStartPos = {}
antiSpam = false
cardOwnership = {
--color: tableOfValidGUIDS
["Green"] = {},
["Blue"] = {},
["Purple"] = {},
["Pink"] = {},
["White"] = {},
["Red"] = {},
["Orange"] = {},
["Yellow"] = {}
}
scoreGreen = 0
scoreBlue = 0
scorePurple = 0
scorePink = 0
scoreWhite = 0
scoreRed = 0
scoreOrange = 0
scoreYellow = 0
scores = {
--color: tableOfValidGUIDS
["Green"] = 0,
["Blue"] = 0,
["Purple"] = 0,
["Pink"] = 0,
["White"] = 0,
["Red"] = 0,
["Orange"] = 0,
["Yellow"] = 0
}
--
------
drawNumber = 6
buttonLabel = "Draw to " .. drawNumber
-----------------------------------
winToken_GUID = '1c21a0'
buttons_GUID = 'c5fe7e'
scoreZone_1_GUID = '328476'
scoreZone_2_GUID = '8a16a5'
scoreZone_3_GUID = '6b8fec'
scoreZone_4_GUID = 'af7f06'
scoreZone_5_GUID = '917e6d'
scoreZone_6_GUID = '556289'
scoreZone_7_GUID = '5fa7f8'
score_zones = {
[1] = '328476',
[2] = '8a16a5',
[3] = '6b8fec',
[4] = 'af7f06',
[5] = '917e6d',
[6] = '556289',
[7] = '5fa7f8'
}
zone_1_win_GUID = 'bfcb3d'
zone_2_win_GUID = '2f6101'
zone_3_win_GUID = '98484a'
zone_4_win_GUID = '5bd6c7'
zone_5_win_GUID = '771f7c'
zone_6_win_GUID = 'dca112'
zone_7_win_GUID = 'c17c26'
zone_8_win_GUID = '25fc6d'
numberZones = {
[1] ='bfcb3d',
[2] ='2f6101',
[3] ='98484a',
[4] ='5bd6c7',
[5] ='771f7c',
[6] ='dca112',
[7] ='c17c26',
[8] ='25fc6d'
}
cardZones = {
[1] = 'dbdc9a',
[2] = '0673b5',
[3] = 'b3e7f9',
[4] = '65ac24',
[5] = '1ff5cd',
[6] = '93f517',
[7] = 'ea953c',
[8] = '82638c'
}
zone_1_a_GUID = 'dbdc9a'
zone_2_a_GUID = '0673b5'
zone_3_a_GUID = 'b3e7f9'
zone_4_a_GUID = '65ac24'
zone_5_a_GUID = '1ff5cd'
zone_6_a_GUID = '93f517'
zone_7_a_GUID = 'ea953c'
zone_8_a_GUID = '82638c'
centerZones = {}
scoreZones = {}
stuffZone = {}
scoreTileZone = {}
reveal = 1
score = 0
clean = 0
rows = {['a'] = -1.72,}
cols = {[1] = -16.04, [2] = -11.48, [3] = -6.92, [4] = -2.36, [5] = 2.20, [6] = 6.79, [7] = 11.39, [8] = 15.99}
function onload()
bigDeck = getObjectFromGUID(bigDeck_GUID)
bigDeck.interactable = false
for player, counter in pairs(scoreCounters) do
getObjectFromGUID(counter).interactable = false
end
for player, guid in pairs(playerTokens) do
tokenStartPos[player] = getObjectFromGUID(guid).getPosition()
end
setPlayerAvatars()
getObjectFromGUID('3c3931').call("pushSet", {})
getObjectFromGUID('2c1953').call("pushSet", {})
getObjectFromGUID('636b2b').call("pushSet", {})
getObjectFromGUID('b83670').call("pushSet", {})
getObjectFromGUID('189f59').call("pushSet", {})
getObjectFromGUID('7f6134').call("pushSet", {})
getObjectFromGUID('2e874b').call("pushSet", {})
getObjectFromGUID('b5dee7').call("pushSet", {})
winToken = getObjectFromGUID(winToken_GUID)
stars = getObjectFromGUID('8430cf')
stars.interactable = false
stuffZone[1] = {['stuff'] = getObjectFromGUID('949f62')}
scoreTileZone[1] = {['tiles'] = getObjectFromGUID('61ad29')}
scoreZones['1'] = {['sco'] = getObjectFromGUID(scoreZone_1_GUID)}
scoreZones['2'] = {['sco'] = getObjectFromGUID(scoreZone_2_GUID)}
scoreZones['3'] = {['sco'] = getObjectFromGUID(scoreZone_3_GUID)}
scoreZones['4'] = {['sco'] = getObjectFromGUID(scoreZone_4_GUID)}
scoreZones['5'] = {['sco'] = getObjectFromGUID(scoreZone_5_GUID)}
scoreZones['6'] = {['sco'] = getObjectFromGUID(scoreZone_6_GUID)}
scoreZones['7'] = {['sco'] = getObjectFromGUID(scoreZone_7_GUID)}
centerZones['1'] = {['win'] = getObjectFromGUID(zone_1_win_GUID), ['a'] = getObjectFromGUID(zone_1_a_GUID)}
centerZones['2'] = {['win'] = getObjectFromGUID(zone_2_win_GUID), ['a'] = getObjectFromGUID(zone_2_a_GUID)}
centerZones['3'] = {['win'] = getObjectFromGUID(zone_3_win_GUID), ['a'] = getObjectFromGUID(zone_3_a_GUID)}
centerZones['4'] = {['win'] = getObjectFromGUID(zone_4_win_GUID), ['a'] = getObjectFromGUID(zone_4_a_GUID)}
centerZones['5'] = {['win'] = getObjectFromGUID(zone_5_win_GUID), ['a'] = getObjectFromGUID(zone_5_a_GUID)}
centerZones['6'] = {['win'] = getObjectFromGUID(zone_6_win_GUID), ['a'] = getObjectFromGUID(zone_6_a_GUID)}
centerZones['7'] = {['win'] = getObjectFromGUID(zone_7_win_GUID), ['a'] = getObjectFromGUID(zone_7_a_GUID)}
centerZones['8'] = {['win'] = getObjectFromGUID(zone_8_win_GUID), ['a'] = getObjectFromGUID(zone_8_a_GUID)}
buttonZone = getObjectFromGUID(buttons_GUID)
buttonZone.createButton({click_function = 'randomizePlayArea', label = "1. Reveal",
position = {5,0,0}, rotation = {0,180,0}, width = 900, height = 300, font_size = 150
})
buttonZone.createButton({click_function = 'buttonScore', label = "2. Score",
position = {0,0,1.25}, rotation = {0,180,0}, width = 775, height = 300, font_size = 150
})
buttonZone.createButton({click_function = 'buttonCleanup', label = "3. Clean Up",
position = {-5,0,0}, rotation = {0,180,0}, width = 900, height = 300, font_size = 150
})
buttonZone.createButton({click_function = 'drawTo', label = buttonLabel,
position = {0,0,4.5}, rotation = {0,180,0}, width = 775, height = 300, font_size = 150
})
bigDeck.shuffle()
doofie1 = getObjectFromGUID('89ab53')
doofie2 = getObjectFromGUID('1e4708')
doofie3 = getObjectFromGUID('6f9b19')
doofie4 = getObjectFromGUID('ab4532')
doofie5 = getObjectFromGUID('38f68c')
doofie6 = getObjectFromGUID('a83bd0')
doofie7 = getObjectFromGUID('19111f')
doofie8 = getObjectFromGUID('a1f8fc')
--doofie1.interactable = false
--doofie2.interactable = false
--doofie3.interactable = false
--doofie4.interactable = false
--doofie5.interactable = false
--doofie6.interactable = false
--doofie7.interactable = false
--doofie8.interactable = false
textStory = getObjectFromGUID('56a44e')
textStory.interactable = false
end
function filterObjectEnterContainer(container, obj)
if obj.tag == "Card" then
return false
end
return true
end
function drawTo(object, player, alt)
if alt then
if drawNumber < 10 then
drawNumber = drawNumber + 1
else
drawNumber = 6
end
buttonZone.editButton({
index = 3,
label = "Draw To " .. drawNumber
})
else
if not antiSpam then
antiSpam = true
dealTo(player, drawNumber)
Wait.time(function() antiSpam = false end, 1)
end
end
--bigDeck.deal(6, pl)
end
function dealTo(player, number)
if #Player[player].getHandObjects() < number then
bigDeck.deal(number - #Player[player].getHandObjects(), player)
--populate ownership
Wait.frames(function()
local handObjects = Player[player].getHandObjects()
for _, obj in pairs(handObjects) do
if obj.tag == "Card" then
if not isInTbl(cardOwnership[player], obj.getGUID()) then
table.insert(cardOwnership[player], obj.getGUID())
end
end
end
end, 100)
end
end
function getStoryCard()
local firstZone = getObjectFromGUID("dbdc9a")
local objects = firstZone.getObjects()
for _, obj in pairs(objects) do
if obj.tag == "Card" then
return obj
end
end
return nil
end
function randomizePlayArea()
if reveal == 0 then print("Cards already revealed, click 'Score' or 'Clean Up'")
end
if reveal == 1 then
for i,s in pairs(stuffZone) do
stuffs = s.stuff.getObjects()
if (#stuffs == 0 ) then print("Place cards facedown in the center row")
end
if (#stuffs > 0 ) then
winToken.setPositionSmooth({-21.32, 2, 2.29})
local storyObj = getStoryCard()
if storyCard == nil then
print("Put your story in the first slot")
return nil
end
storyCard.guid = storyObj.getGUID()
storyCard.storyTeller = getOwner(storyCard.guid)
--set token color to story teller Color
--winToken.setColorTint(Color.fromString(storyCard.storyTeller))
print("Place votes facedown in the upper grid, then click 'Score'")
clean = 1
score = 1
reveal = 0
cards = {}
order = {}
count = 0
for k,v in pairs(centerZones) do
carda = v.a.getObjects()
if (#carda > 0 ) then
count = count + 1
order[count] = k
cards[tostring(k)] = { ['a'] = nil }
if (#carda > 0) then cards[tostring(k)]['a'] = carda[1]
end
end
end
N = count
for i = N, 2, -1 do -- backwards
local r = math.random(i) -- select a random number between 1 and i
order[i], order[r] = order[r], order[i]
--cards[i], cards[r] = cards[r], cards[i] -- swap the randomly selected item to position i
end
count = 0
for k,v in pairs(cards) do
count = count + 1
random = order[count] + 0
if cards[k]['a'] != nil then cards[k]['a'].setPosition({cols[random], 0.97, rows['a']})
end
end
Wait.time(function()
for index, zoneGUID in pairs(cardZones) do
local zone = getObjectFromGUID(zoneGUID)
local objects = zone.getObjects()
for _, obj in pairs(objects) do
if obj.tag == "Card" then
if obj.getGUID() == storyCard.guid then
storyCard.number = index
end
end
end
end
end,
1)
Timer.create({identifier='allCardsFlip', function_name='allCardsFlip', delay=0.1})
end
end
end
end
function allCardsFlip(owner, color)
card_direction = 0
for k,v in pairs(centerZones) do
card = {}
for kt,vt in pairs({'a'}) do
card[kt] = v[vt].getObjects()
if #card[kt] > 0 then
face = card_faceup(card[kt][1])
if face and card_direction == 0 then card_direction = -1 end
if not face and card_direction == 0 then card_direction = 1 end
if face and card_direction == -1 then card[kt][1].flip() end
if not face and card_direction == 1 then card[kt][1].flip() end
end
end
end
end
function card_faceup(card)
rot = card.getRotation()
if (rot.z < 90) or (rot.z > 270) then
return true
else
return false
end
end
function buttonScore(owner, color)
if score == 0 then print("Once cards are placed in the center, click 'Reveal'")
end
if score == 1 then
for i,s in pairs(scoreTileZone) do
voteTiles = s.tiles.getObjects()
if (#voteTiles == 0 ) then print("Place votes facedown in the upper grid, then click 'Score'")
end
if (#voteTiles > 0 ) then
textStory.call("blankName", {})
Timer.create({identifier='lockTiles', function_name='lockTiles', delay=1.5})
score = 0
height = 1.5
length1 = -3.5
length2 = -3.5
length3 = -3.5
length4 = -3.5
length5 = -3.5
length6 = -3.5
length7 = -3.5
length8 = -3.5
local playerVotes = {
["Green"] = nil,
["Blue"] = nil,
["Purple"] = nil,
["Pink"] = nil,
["White"] = nil,
["Red"] = nil,
["Orange"] = nil,
["Yellow"] = nil
}
scoreClicked = true
for index, zoneGUID in pairs(score_zones) do
local zone = getObjectFromGUID(zoneGUID)
local objects = zone.getObjects()
for _, obj in pairs(objects) do
if obj.tag == "Card" then
if isInTbl(playerColors ,obj.getDescription()) then
playerVotes[obj.getDescription()] = tonumber(obj.getName())
end
end
end
end
addScores(playerVotes)
--updateAvatarPositions
setScorePositions()
----highlight cards and send player Tokens
for index, zoneGUID in pairs(cardZones) do
local zone = getObjectFromGUID(zoneGUID)
local objects = zone.getObjects()
for _, obj in pairs(objects) do
if obj.tag == "Card" then
local guid = obj.getGUID()
local owner = getOwner(guid)
if owner ~= nil then
obj.highlightOn(Color.fromString(owner))
local token = getObjectFromGUID(playerTokens[owner])
local numberZone = getObjectFromGUID(numberZones[index])
token.setPositionSmooth(numberZone.getPosition(), false, true)
end
end
end
end
--Move win token to storytellers card
local cardGUID = storyCard.guid
answerCard = getObjectFromGUID(cardGUID)
winToken.setPositionSmooth(answerCard.getPosition() + vector(0, 1, 0), false, true)
answerCard.setPositionSmooth(answer.position, false, false)
answerCard.setScale(answer.scale)
answerCard.setRotation(answer.rotation)
answerCard.interactable = false
for k,v in pairs(scoreZones) do
card = {}
for kt,vt in pairs({'sco'}) do
card[kt] = v[vt].getObjects()
if #card[kt] > 0 then
if card[kt][1].tag == "Card" or card[kt][1].tag == "Deck" then
if card[kt][1].getName() == '1' then
length1 = length1 + -1.75
card[kt][1].flip()
card[kt][1].setRotationSmooth({180,0,180})
card[kt][1].setPositionSmooth({-16.04,height,length1})
end
if card[kt][1].getName() == '2' then
length2 = length2 + -1.75
card[kt][1].flip()
card[kt][1].setRotationSmooth({180,0,180})
card[kt][1].setPositionSmooth({-11.48,height,length2})
end
if card[kt][1].getName() == '3' then
length3 = length3 + -1.75
card[kt][1].flip()
card[kt][1].setRotationSmooth({180,0,180})
card[kt][1].setPositionSmooth({-6.92,height,length3})
end
if card[kt][1].getName() == '4' then
length4 = length4 + -1.75
card[kt][1].flip()
card[kt][1].setRotationSmooth({180,0,180})
card[kt][1].setPositionSmooth({-2.36,height,length4})
end
if card[kt][1].getName() == '5' then
length5 = length5 + -1.75
card[kt][1].flip()
card[kt][1].setRotationSmooth({180,0,180})
card[kt][1].setPositionSmooth({2.20,height,length5})
end
if card[kt][1].getName() == '6' then
length6 = length6 + -1.75
card[kt][1].flip()
card[kt][1].setRotationSmooth({180,0,180})
card[kt][1].setPositionSmooth({6.79,height,length6})
end
if card[kt][1].getName() == '7' then
length7 = length7 + -1.75
card[kt][1].flip()
card[kt][1].setRotationSmooth({180,0,180})
card[kt][1].setPositionSmooth({11.39,height,length7})
end
if card[kt][1].getName() == '8' then
length8 = length8 + -1.75
card[kt][1].flip()
card[kt][1].setRotationSmooth({180,0,180})
card[kt][1].setPositionSmooth({15.99,height,length8})
end
end
end
end
end
end
end
end
end
function addScores(votes)
---check if all guessed correct
allCorrect = true
for player, vote in pairs(votes) do
if vote ~= nil then
if vote ~= storyCard.number then
allCorrect = false
end
end
end
if allCorrect then
print("Everyone got it Right")
for player, vote in pairs(votes) do
if vote ~= nil and player ~= storyCard.storyTeller then
scores[player] = scores[player] + 2
if Player[player].seated then
broadcastToColor("You got 2 Points", player, Color.fromString(player))
end
end
end
displayScores()
return true
end
allWrong = true
for player, vote in pairs(votes) do
if vote ~= nil then
if vote == storyCard.number then
allWrong = false
end
end
end
if allWrong then
print("Everyone got it Wrong")
for player, vote in pairs(votes) do
if vote ~= nil and player ~= storyCard.storyTeller then
scores[player] = scores[player] + 2
if Player[player].seated then
broadcastToColor("You got 2 Points", player, Color.fromString(tostring(player)))
end
end
end
end
if not allWrong then
--story teller gets 3 Points
scores[storyCard.storyTeller] = scores[storyCard.storyTeller] + 3
if Player[storyCard.storyTeller].seated then
broadcastToColor("You got 3 Points as the Story Teller", storyCard.storyTeller, Color.fromString(storyCard.storyTeller))
end
--correct players get 3 points
for player, vote in pairs(votes) do
if vote ~= nil and player ~= storyCard.storyTeller then
if vote == storyCard.number then
scores[player] = scores[player] + 3
if Player[player].seated then
broadcastToColor("You get 3 Points for guessing correctly", player, Color.fromString(player))
end
end
end
end
end
--card owners get a point per vote
for player, vote in pairs(votes) do
if vote ~= nil and player ~= storyCard.storyTeller then
local chosenZoneGUID = cardZones[vote]
local chosenZone = getObjectFromGUID(chosenZoneGUID)
local objects = chosenZone.getObjects()
local cardGUID = nil
for _, obj in pairs(objects) do
if obj.tag == "Card" then
cardGUID = obj.getGUID()
end
end
if cardGUID ~= nil then
local owner = getOwner(cardGUID)
if owner ~= player and owner ~= storyCard.storyTeller then
scores[owner] = scores[owner] + 1
if Player[player].seated then
broadcastToColor(player.." guessed your card 1 point", owner, Color.fromString(owner))
end
end
end
end
end
displayScores()
end
function displayScores()
for player, score in pairs(scores) do
local scoreCounter = getObjectFromGUID(scoreCounters[player])
scoreCounter.call("set_Val", {number = score})
if Player[player].seated then
printToAll(player.." has "..score.." points", Color.fromString(player))
if score >= 30 then
broadcastToAll(player.." Wins!", Color.fromString(player))
end
end
end
end
function lockTiles()
local lockZone = getObjectFromGUID('949f62')
for i, obj in ipairs(lockZone.getObjects()) do
if not isInTbl(playerTokens, obj.getGUID()) then
obj.setLock(true)
end
end
end
function buttonCleanup(owner, color)
if clean == 0
then print("Once cards are placed in the center, click 'Reveal'")
end
if clean == 1
then
--winToken.setColorTint(Color.fromString("White"))
textStory.call("reloadAll", {})
unlockTiles()
clean = 0
reveal = 1
score = 0
getObjectFromGUID('3c3931').call("recall", {})
getObjectFromGUID('2c1953').call("recall", {})
getObjectFromGUID('636b2b').call("recall", {})
getObjectFromGUID('b83670').call("recall", {})
getObjectFromGUID('189f59').call("recall", {})
getObjectFromGUID('7f6134').call("recall", {})
getObjectFromGUID('2e874b').call("recall", {})
getObjectFromGUID('b5dee7').call("recall", {})
for _, player in pairs(getSeatedPlayers()) do
dealTo(player, drawNumber)
end
if scoreClicked then
Turns.turn_color = Turns.getNextTurnColor()
end
height = 3
for k,v in pairs(centerZones) do
card = {}
for kt,vt in pairs({'a'}) do
card[kt] = v[vt].getObjects()
if #card[kt] > 0 then
height = height + 0.1
if card[kt][1].tag == "Card" or card[kt][1].tag == "Deck" then
card[kt][1].setRotationSmooth({180,0,180})
revokeOwnership(card[kt][1].getGUID())
card[kt][1].destruct()
end
end
end
if scoreClicked then
revokeOwnership(answerCard.getGUID())
answerCard.destruct()
end
winToken.setPositionSmooth({-16.04, 2, 2.29})
for player, guid in pairs(playerTokens) do
local token = getObjectFromGUID(guid)
token.setPositionSmooth(tokenStartPos[player], false, false)
end
scoreClicked = false
end
end
end
function unlockTiles()
local lockZone = getObjectFromGUID('949f62')
for i, obj in ipairs(lockZone.getObjects()) do
if not isInTbl(playerTokens, obj.getGUID()) then
obj.setLock(false)
end
end
end
function isInTbl(tbl, value)
for k, v in pairs(tbl) do
if v == value then
return true
end
end
return false
end
function getOwner(chosenGUID)
for player, tbl in pairs(cardOwnership) do
for _, guid in pairs(tbl) do
if chosenGUID == guid then
return player
end
end
end
return nil
end
function setPlayerImage(p)
if p.color != 'Grey' and p.color != 'Black' then
local webData = WebRequest.get('http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=' .. "B12285081AC59DD0B3B4CD7E03E300A0" .. '&steamids=' .. p.steam_id,
function(response)
local steamData = JSON.decode(response.text)
local img = steamData['response']['players'][1]['avatarfull'] .. '&hash=' .. steamData['response']['players'][1]['avatarhash']
getObjectFromGUID(playerTokens[p.color]).setCustomObject({
image = img
})
getObjectFromGUID(scoreAvatars[p.color]).setCustomObject({
image = img
})
local newToken = getObjectFromGUID(playerTokens[p.color]).reload()
newToken.interactable = false
playerTokens[p.color] = newToken.getGUID()
local newScoreToken = getObjectFromGUID(scoreAvatars[p.color]).reload()
newScoreToken.interactable = false
end)
end
end
function onPlayerChangeColor(color)
setPlayerAvatars()
end
function setPlayerAvatars()
local players = getOrderedPlayers()
for _, player in pairs(players) do
setPlayerImage(Player[player])
end
for _, player in pairs(playerColors) do
if not isInTbl(players, player) then
resetToken(player)
end
end
Wait.time(function() setScorePositions() end, 0.5)
end
function setScorePositions()
local centerPoint = {x =-0.08, y = 1, z = 14.14}
local players = getOrderedPlayers()
local playerCount = #players
local width = 3
local leftPoint = centerPoint.x - ((width * playerCount) / 2) + (width/2)
for index, player in ipairs(players) do
local scoreAvatar = getObjectFromGUID(scoreAvatars[player])
local scoreCounter = getObjectFromGUID(scoreCounters[player])
local avatarPosition = vector(
leftPoint + (index - 1) * width,
centerPoint.y,
centerPoint.z + (width / 2))
scoreAvatar.setPositionSmooth(avatarPosition, false, true)
local scoreCounterPosition = vector(
leftPoint + (index - 1) * width,
centerPoint.y,
centerPoint.z - (width / 2))
scoreCounter.setPositionSmooth(scoreCounterPosition, false, true)
end
for _, player in pairs(playerColors) do
if not isInTbl(players, player) then
local scoreAvatar = getObjectFromGUID(scoreAvatars[player])
local scoreCounter = getObjectFromGUID(scoreCounters[player])
scoreAvatar.setPositionSmooth({0, 0, 36}, false, true)
scoreCounter.setPositionSmooth({0,0, 36}, false, true)
end
end
end
function getOrderedPlayers()
local seatedPlayers = getSeatedPlayers()
local scores = scores
local mergedTable = {}
local returnTbl = {}
for _, player in ipairs(seatedPlayers) do
table.insert(mergedTable, {player = player, score = scores[player]})
end
table.sort(mergedTable, function(a, b) return a.score > b.score end)
for index, tbl in ipairs(mergedTable) do
table.insert(returnTbl, tbl.player)
end
return returnTbl
end
function resetToken(player)
if player ~= "Grey" and player ~= "Black" then
local token = getObjectFromGUID(playerTokens[player])
token.setCustomObject({
image = "http://cloud-3.steamusercontent.com/ugc/1461933361183063701/7812EAA12B13D1380BF4871EF917F783F4D340CC/"
})
local newToken = token.reload()
playerTokens[player] = newToken.getGUID()
newToken.interactable = false
local scoreToken = getObjectFromGUID(scoreAvatars[player])
scoreToken.setCustomObject({
image = "http://cloud-3.steamusercontent.com/ugc/1461933361183063701/7812EAA12B13D1380BF4871EF917F783F4D340CC/"
})
local newScoreToken = scoreToken.reload()
scoreAvatars[player] = scoreToken.getGUID()
newScoreToken.interactable = false
end
end
function revokeOwnership(guid)
local owner = getOwner(guid)
if owner == nil then
return nil
end
for index, cardGUID in ipairs(cardOwnership[owner]) do
if guid == cardGUID then
table.remove(cardOwnership[owner], index)
end
end
end
function onUpdate()
scoreGreen = scores["Green"]
scoreBlue = scores["Blue"]
scorePurple = scores["Purple"]
scorePink = scores["Pink"]
scoreWhite = scores["White"]
scoreRed = scores["Red"]
scoreOrange = scores["Orange"]
scoreYellow = scores["Yellow"]
end