forked from Kyle-P/Scripted-Plus-Uno
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGlobal.-1.ttslua
More file actions
1368 lines (1216 loc) · 38.3 KB
/
Global.-1.ttslua
File metadata and controls
1368 lines (1216 loc) · 38.3 KB
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
players = {}
PLAYERS = {Player.Green, Player.Blue, Player.Purple, Player.Pink, Player.White, Player.Red, Player.Orange, Player.Yellow}
TOKENLOCATIONS = { ["Green"] = { 0, 1, 9},
["Blue"] = { 6.36, 1, 6.36},
["Purple"] = { 9, 1, 0},
["Pink"] = { 6.36, 1,-6.36},
["White"] = { 0, 1, -9},
["Red"] = {-6.36, 1,-6.36},
["Orange"] = { -9, 1, 0},
["Yellow"] = {-6.36, 1, 6.36}}
DIRECTIONLOCATIONS = { ["Green"] = { 0, 1, 7},
["Blue"] = { 5, 1, 5},
["Purple"] = { 7, 1, 0},
["Pink"] = { 5, 1, -5},
["White"] = { 0, 1, -7},
["Red"] = { -5, 1, -5},
["Orange"] = { -7, 1, 0},
["Yellow"] = { -5, 1, 5}}
TOKENROTATIONS = { ["Green"] = { 0, 180, 0},
["Blue"] = { 0, 225, 0},
["Purple"] = { 0, 270, 0},
["Pink"] = { 0, 315, 0},
["White"] = { 0, 360, 0},
["Red"] = { 0, 45, 0},
["Orange"] = { 0, 90, 0},
["Yellow"] = { 0, 135, 0}}
math.randomseed(os.time())
tokenLocations = {}
currentPlayer = nil
currentPlayer_index = nil
currentPlayer_Label = nil
winner = nil
lastCard_Name = nil
lastCard_Desc = nil
clockwisePlay = true
stackingButton = nil
stacking_Draw = 0
isStacking = false
stackingOption = true
drawOneOption = false
randPlayerOneOption = true
zeroSevenOption = false
jumpInOption = false
challengeOption = false
chaosOption = false
startButtonObj_GUID = "d60f3a"
startButtonObj = nil
playerLabelObj = nil
playDirectionObj = nil
drawButton = nil
drawButton2 = nil
wildButtons = {}
sevenButtons = {}
yieldState = nil
deckZone_GUID = "c94b89"
deckObject_GUID = "18c2e8"
deck = nil
playMatObject_GUID = "f82f1f"
cardZone_GUID = "5d5c74"
cardZone = nil
playDeck = nil
stackingOption_GUID = "397699"
drawingOption_GUID = "b36922"
randomOption_GUID = "7f3e9e"
zeroSevenOption_GUID = "6dbe87"
jumpInOption_GUID = "055580"
challengeOption_GUID = "20e735"
chaosOption_GUID = "03158e"
playerHands = {}
lastCardPlayedBy = nil
deckReset = false
lastDeck = nil
gameStarted = false
needShuffle = false
lastCardCount = 0
lastPlayer = nil
lastColor = nil
challengeSuccess = false
canChallenge = true
version = "0.3.1"
nextTurn = nil--coroutine.create(co)
function onLoadMessage()
broadcastToAll("Scripted+ UNO by Tuumn", "White")
broadcastToAll("Version: " .. version, "White")
broadcastToAll("!reset : Resets the game at any time", "White")
end
function onFixedUpdate()
if needShuffle
then
deckObjects = deck.getObjects()
if #deckObjects > lastCardCount
then
shuffleDeck()
needShuffle = false
lastCardCount = #deckObjects
end
end
if gameStarted == false
then
deckObjects = deck.getObjects()
if #deckObjects == 108 and deck.getLock() == false
then
deck.lock()
end
end
end
function onLoad(save_state)
cardZone = getObjectFromGUID(cardZone_GUID)
cardZone.setPosition({1.5, 0, 0})
cardZone.setRotation({0, 0, 0})
startButtonObj = getObjectFromGUID(startButtonObj_GUID)
stackingOptionObject = getObjectFromGUID(stackingOption_GUID)
drawingOptionObject = getObjectFromGUID(drawingOption_GUID)
randomOptionObject = getObjectFromGUID(randomOption_GUID)
zeroSevenOptionObject = getObjectFromGUID(zeroSevenOption_GUID)
jumpInOptionObject = getObjectFromGUID(jumpInOption_GUID)
challengeOptionObject = getObjectFromGUID(challengeOption_GUID)
chaosOptionObject = getObjectFromGUID(chaosOption_GUID)
deck = getObjectFromGUID(deckObject_GUID)
deck.setPosition({-1.5, 1.5, 0})
deck.interactable=false
deck.lock()
playMat = getObjectFromGUID(playMatObject_GUID)
playMat.setPosition({1.5, 1, 0})
playMat.interactable = false
playMat.lock()
GrabPlayerList()
onLoadMessage()
end
function onPlayerDisconnect(player)
if currentPlayer ~= nil
then
if player == currentPlayer
then
broadcastToAll("We lost the current player. Moving to next turn?", "Black")
nextPlayer(1)
end
end
end
function onChat(message, sender)
if message == "!reset"
then
if sender.host
then
if gameStarted
then
resetGame()
else
broadcastToColor("Game has not started yet", sender.color, sender.color)
end
end
end
end
function shuffleDeck()
deck.shuffle()
end
function toggleStacking(obj,color)
stackingOption = not stackingOption
if stackingOption
then
--messaage = "Stacking : On"
obj.editButton({index=0, label = 'Stacking : On'})
else
--message = "Stacking : Off"
obj.editButton({index=0, label = 'Stacking : Off'})
end
end
function toggleDrawing(obj, color)
drawOneOption = not drawOneOption
if drawOneOption
then
obj.editButton({index=0, label='Draw : One Card'})
else
obj.editButton({index=0, label='Draw : Multiple Cards'})
end
end
function toggleRandomPlayerOne(obj, color)
randPlayerOneOption = not randPlayerOneOption
if randPlayerOneOption
then
obj.editButton({index=0, label='First Player : Random'})
else
obj.editButton({index=0, label='First Player : Starter'})
end
end
function toggleJumpIn(obj, color)
jumpInOption = not jumpInOption
if jumpInOption
then
obj.editButton({index=0, label='Jump In Rule : On'})
else
obj.editButton({index=0, label='Jump In Rule : Off'})
end
end
function toggleZeroSeven(obj, color)
zeroSevenOption = not zeroSevenOption
if zeroSevenOption
then
obj.editButton({index=0, label='Zero Seven Rule : On'})
else
obj.editButton({index=0, label='Zero Seven Rule : Off'})
end
end
function toggleChallenge(obj, color)
challengeOption = not challengeOption
if challengeOption
then
obj.editButton({index=0, label='+4 Challenge Rule : On'})
else
obj.editButton({index=0, label='+4 Challenge Rule : Off'})
end
end
function toggleChaos(obj, color)
chaosOption = not chaosOption
if chaosOption then
obj.editButton({index=0, label='Chaos Rule : On'})
else
obj.editButton({index=0, label='Chaos Rule : Off'})
end
end
function resetStacktingDraw()
if chaosOption then
local i = math.random(0,4)
if i <= 1 then return end
end
stacking_Draw = 0
end
function setUp()
currentPlayer_label = spawnObject({type="PiecePack_Suns",position = {100, 100, 0}, callback = "updatePlayerLabel"})
currentDirection_label = spawnObject({type="PiecePack_Suns",position = {100, 100, 0}, callback = "updateDirectionLabel"})
drawButton = spawnObject({type = "PiecePack_Suns",position = {-1.5,1,-3}, callback = "createDrawButton"})
drawButton2 = spawnObject({type = "PiecePack_Suns",position = {-1.5,1,3},rotation={0,180,0}, callback = "createDrawButton"})
hideStartMenu()
listPlayers()
deck.shuffle()
for i,player in ipairs(players)
do
deck.dealToColor(7, player.color)
end
gameStarted = true
end
function hideStartMenu()
startButtonObj.setScale({0,0,0})
stackingOptionObject.setScale({0,0,0})
drawingOptionObject.setScale({0,0,0})
randomOptionObject.setScale({0,0,0})
zeroSevenOptionObject.setScale({0,0,0})
jumpInOptionObject.setScale({0,0,0})
challengeOptionObject.setScale({0,0,0})
chaosOptionObject.setScale({0,0,0})
end
function showStartMenu()
startButtonObj.setScale({1,1,1})
stackingOptionObject.setScale({1,1,1})
drawingOptionObject.setScale({1,1,1})
randomOptionObject.setScale({1,1,1})
zeroSevenOptionObject.setScale({1,1,1})
jumpInOptionObject.setScale({1,1,1})
challengeOptionObject.setScale({1,1,1})
chaosOptionObject.setScale({1,1,1})
end
function resetGame()
if deck ~= nil
then
deck.reset()
end
if playDeck ~= nil
then
playDeck.flip()
playDeck.setPositionSmooth({deck.getPosition()['x'],deck.getPosition()['y']+2.8,deck.getPosition()['z']})
end
clockwisePlay = true
currentPlayer = nil
currentPlayer_index = nil
currentPlayer_Label = nil
winner = nil
lastCard_Name = nil
lastCard_Desc = nil
lastCardPlayedBy = nil
lastPlayer = nil
lastColor = nil
currentDirection_label.destruct()
currentPlayer_label.destruct()
drawButton.destruct()
drawButton2.destruct()
playMat.setColorTint({1, 1, 1})
showStartMenu()
gameStarted = false
end
function checkForWinner()
if lastCardPlayedBy ~= nil
then
if #lastCardPlayedBy.getHandObjects() == 0 and lastCardPlayedBy.seated -- Make sure player hasn't DCed or swapped colors
then
winner = lastCardPlayedBy
resetGameButton = spawnObject({type="PiecePack_Suns",position = {0, 1, 4}, rotation = {0, 180, 0}, callback = "createResetButton"})
hideDrawButton()
broadcastToAll(lastCardPlayedBy.steam_name .. ' Has Won The Game!',getColorfromPlayer(lastCardPlayedBy.color))
return true
end
end
return false
end
function onObjectEnterScriptingZone(zone, obj)
if winner == nil
then
if zone == cardZone
then
if obj.held_by_color ~= nil
then
if nextTurn ~= nil
then
if coroutine.status(nextTurn) == "suspended"
then
if yieldState ~= nil
then
if yieldState == "stack" or yieldState == "stack/challenge"
then
if obj.getName() == lastCard_Name
then
checkCard(obj)
else
rejectCard(obj, "Must Stack Or Draw Cards")
end
elseif yieldState == "wild"
then
rejectCard(obj,"Must Make A Choice First")
elseif yieldState == "7"
then
rejectCard(obj,"Must Make A Choice First")
end
end
else
checkCard(obj)
end
else
checkCard(obj)
end
end
end
end
end
function checkCard(obj)
if obj.held_by_color ~= nil
then -- object entered is being held by a player
if currentPlayer ~= nil
then
if obj.held_by_color == currentPlayer.color
then -- if it is the players turn
if lastCard_Name == nil
then -- if no cards have been played yet
playCard(obj)
else -- if cards have already been played
if obj.getDescription() == "WILD"
then -- if the card being palyed is a wild card
playCard(obj)
elseif obj.getName() == lastCard_Name
then -- if the card being played has the same face value as the last card
playCard(obj)
elseif obj.getDescription() == lastCard_Desc
then -- if the card being played is the same color as the last card
playCard(obj)
else -- if the card being played cannot be played
rejectCard(obj,"This Card Cannot Be Played")
end
end
elseif jumpInOption
then
if lastCard_Name == nil and lastCard_Desc == nil
then -- if no cards have been played yet
rejectCard(obj, "You can not jump in on the first turn")
else -- if cards have already been played
if obj.getName() == lastCard_Name and obj.getName() == "wild"
then
playCard(obj)
elseif obj.getName() == lastCard_Name and obj.getName() == "+4"
then
playCard(obj)
elseif obj.getName() == lastCard_Name and obj.getDescription() == lastCard_Desc
then -- if the card being played is the exact same as the last card
playCard(obj)
else -- if the card being played cannot be played
rejectCard(obj,"You can not jump in now (Does Not Exactly Match the Previous)")
end
end
else -- if it is not the players turn
rejectCard(obj,"It Is Not Your Turn")
end
end
end
end
function playCard(cardObj)
if nextTurn ~= nil
then
if coroutine.status(nextTurn) == "suspended"
then
isChallenging = false
coroutine.resume(nextTurn)
end
end
local playedByColor = getColorfromPlayer(cardObj.held_by_color)
local playedByPlayer = getPlayerFromColor(playedByColor)
lastCardPlayedBy = playedByPlayer
lastColor = lastCard_Desc
if lastCardPlayedBy ~= nil
then
if lastCardPlayedBy ~= currentPlayer and jumpInOption
then
broadcastToAll(lastCardPlayedBy.steam_name .. ' has jumped in!', lastCardPlayedBy.color)
currentPlayer = lastCardPlayedBy
currentPlayer_index = getPlayerIndex(lastCardPlayedBy)
updatePlayerLabel(currentPlayer_label)
updateDirectionLabel(currentDirection_label)
end
end
cardObj.setRotationSmooth({0,180,0})
local FixedPos= cardZone.getPosition()
cardObj.setPositionSmooth({FixedPos.x,2,FixedPos.z})
if checkForWinner() == false
then
lastCard_Name = cardObj.getName()
lastCard_Desc = cardObj.getDescription()
if(lastCard_Desc~="WILD")then
playMat.setColorTint(getColorfromCard(lastCard_Desc))
end
if lastCard_Name == "0" and zeroSevenOption
then
moveHandsRight()
end
updateDecks()
nextTurn = coroutine.create(co)
coroutine.resume(nextTurn)
end
end
function rejectCard(cardObj, rejectMessage)
player = Player[cardObj.held_by_color]
broadcastToColor(rejectMessage, player.color, getColorfromPlayer(player.color))
pos = {player.getPlayerHand()['pos_x'],player.getPlayerHand()['pos_y'],player.getPlayerHand()['pos_z']}
cardObj.setPositionSmooth(pos)
end
function moveHandsRight()
broadcastToAll(currentPlayer.steam_name .. ' has played a zero. Moving hands to the right', currentPlayer.color)
playerHands = {}
for i, player in ipairs(players)
do
local playerHand = player.getHandObjects()
table.insert(playerHands, playerHand)
end
for i, hand in ipairs(playerHands)
do
local playerToRight = 0
if i - 1 < 1
then
playerToRight = #players
else
playerToRight = i - 1
end
pos = {players[playerToRight].getPlayerHand()['pos_x'],players[playerToRight].getPlayerHand()['pos_y'],players[playerToRight].getPlayerHand()['pos_z']}
carRot = players[playerToRight].getPlayerHand()['rot_y'] + 180
for h, card in ipairs(hand)
do
card.setPosition(pos)
card.setRotation({0, carRot, 0})
end
end
end
function createDrawButton(obj)
obj.lock()
obj.createButton({click_function="drawCard", label = "Draw", function_owner = Global, position = {0,0.1,0}, rotation = {0,180,0}, width = 1500, height = 500, font_size=350})
end
function hideDrawButton()
drawButton.setScale({0,0,0})
drawButton2.setScale({0,0,0})
end
function showDrawButton()
drawButton.setScale({1,1,1})
drawButton2.setScale({1,1,1})
end
function createResetButton(button)
button.lock()
button.setColorTint(getColorfromPlayer(winner.color))
button.createButton({click_function='clickResetButton', label='Reset Game', function_owner=Global, position={0, 0.1, 0}, rotation={0, 0, 0}, width=2500, height=850, font_size=400})
end
function clickResetButton(obj, color)
resetGame()
obj.destruct()
end
function createStackingButton(button)
hideDrawButton()
button.lock()
button.setColorTint(getColorfromPlayer(currentPlayer.color))
button.createButton({click_function='clickStackingButton', label='Click here if \nyou can\'t stack', function_owner=Global, position={0, 0.1, 0}, rotation=rotationPlayerReadable(currentPlayer.color), width=2500, height=850, font_size=350})
end
function createWildButton(button)
hideDrawButton()
button.lock()
color = nil
for i, wildbutton in ipairs(wildButtons)
do
if wildbutton == button
then
if i == 1
then
color= "RED"
elseif i == 2
then
color="YELLOW"
elseif i == 3
then
color="GREEN"
elseif i == 4
then
color="BLUE"
end
end
end
button.setColorTint(getColorfromCard(color))
button.createButton({click_function='clickWildButton', label=''.. color, function_owner=Global, position={0, 0.1, 0}, rotation=rotationPlayerReadable(currentPlayer.color), width=1600, height=325, font_size=350})
end
function createSevenSelectionButton(button)
table.insert(sevenButtons, button)
hideDrawButton()
button.interactable=false
button.lock()
button.createButton({click_function='clickTakeHandButton', label='Take hand', function_owner=Global, position={0, 0.1, 0}, rotation=rotationPlayerReadable(currentPlayer.color), width=2000, height=850, font_size=350})
end
function createChallengeButton(button)
hideDrawButton()
button.lock()
button.setColorTint(getColorfromPlayer(currentPlayer.color))
button.createButton({click_function='clickChallengeButton', label='Challenge\n' .. lastPlayer.steam_name, function_owner=Global, position={0, 0.1, 0}, rotation=rotationPlayerReadable(currentPlayer.color), width=2500, height=850, font_size=350})
end
function clickTakeHandButton(obj, color)
if color == lastCardPlayedBy.color
then
local chosenPlayer = getPlayerFromColor(obj.getColorTint())
if chosenPlayer ~= nil and lastCardPlayedBy ~= nil and chosenPlayer ~= lastCardPlayedBy
then
local currentPlayer_Hand = lastCardPlayedBy.getHandObjects()
local chosenPlayer_Hand = chosenPlayer.getHandObjects()
for i, playerCard in ipairs(currentPlayer_Hand)
do
playerCard.deal(1, chosenPlayer.color)
end
Wait.condition(function()
for i, chosenCard in ipairs(chosenPlayer_Hand)
do
chosenCard.deal(1, lastCardPlayedBy.color)
end
end, function() return #lastCardPlayedBy.getHandObjects() == 0 end)
end
coroutine.resume(nextTurn)
showDrawButton()
destroySevenButtons()
end
end
function destroySevenButtons()
for i, button in ipairs(sevenButtons)
do
button.destruct()
end
sevenButtons = {}
end
function drawCard(obj,color)
if color ~= nil
then
if color == currentPlayer.color
then
if yieldState == "stack"
then
broadcastToColor('You Can Not Draw A Card At This Time', color , getColorfromPlayer(color))
elseif yieldState == "wild"
then
broadcastToColor('You Can Not Draw A Card At This Time', color , getColorfromPlayer(color))
else
deck.dealToColor(1, color)
if drawOneOption
then
nextPlayer(1)
end
end
else
broadcastToColor('You Can Only Draw On Your Turn', color , getColorfromPlayer(color))
end
end
end
function clickStackingButton(obj, color)
if color == currentPlayer.color
then
isStacking = false
lastCardPlayedBy = currentPlayer
coroutine.resume(nextTurn)
obj.destruct()
showDrawButton()
end
if challengeButton ~= nil
then
challengeButton.destruct()
end
end
function clickWildButton(obj, color)
if color == currentPlayer.color
then
if obj == wildButtons[1]
then
lastCard_Desc = "RED"
elseif obj == wildButtons[2]
then
lastCard_Desc = "YELLOW"
elseif obj == wildButtons[3]
then
lastCard_Desc = "GREEN"
elseif obj == wildButtons[4]
then
lastCard_Desc = "BLUE"
end
broadcastToAll('Color Is Now ' .. lastCard_Desc,getColorfromCard(lastCard_Desc))
playMat.setColorTint(getColorfromCard(lastCard_Desc))
coroutine.resume(nextTurn)
wildButtons[1].destruct()
wildButtons[2].destruct()
wildButtons[3].destruct()
wildButtons[4].destruct()
showDrawButton()
end
end
function clickChallengeButton(obj, color)
if color == currentPlayer.color
then
if lastPlayer ~= nil
then
local lastPlayer_Hand = lastPlayer.getHandObjects()
for i, card in ipairs(lastPlayer_Hand)
do
if card.getDescription() == lastColor
then
challengeSuccess = true
break
end
end
end
coroutine.resume(nextTurn)
obj.destruct()
showDrawButton()
end
if stackingButton ~= nil
then
stackingButton.destruct()
end
end
function onPlayerChangedColor(player_color)
if currentPlayer ~= nil
then
if player_color ~= "Grey"
then
cleanHands()
if player_color ~= "Black"
then
if #Player[player_color].getHandObjects() == 0
then
deck.dealToColor(7, player_color)
end
end
end
end
GrabPlayerList()
end
function updateDecks()
zoneObjects = cardZone.getObjects()
deckObjects = deck.getObjects()
if deck.getLock()
then
deck.unlock()
end
for i, obj in ipairs(zoneObjects)
do
if obj ~= playMat
then
playDeck = obj
--playDeck.interactable=false
break
end
end
if #deckObjects < 18
then
lastCardCount = #deckObjects
playDeck.flip()
playDeck.shuffle()
playDeck.setPositionSmooth({deck.getPosition()['x'],deck.getPosition()['y']+2.8,deck.getPosition()['z']})
needShuffle = true
end
end
function startGame(obj, color)
if gameStarted == false
then
if randPlayerOneOption
then
pickRandPlayerOne(obj,color)
else
pickPlayerOne(obj,color)
end
end
end
function pickRandPlayerOne(obj,color)
local playerCount = 0
for i , player in ipairs(players)
do
playerCount = playerCount + 1
end
if playerCount > 0
then
local rand = math.random(1, playerCount)
for i , player in ipairs(players)
do
if i == rand
then
currentPlayer = player
currentPlayer_index = i
end
end
if currentPlayer ~= nil
then
setUp()
else
printToColor('There was an error getting the starting player', color ,getColorfromPlayer(color))
end
else
printToColor('Need at least two players to start', color ,getColorfromPlayer(color))
end
end
function pickPlayerOne(obj,color)
if color ~= "Grey"
then
if color ~= "Black"
then
for i , player in ipairs(players)
do
if color == player.color
then
currentPlayer = player
currentPlayer_index = i
end
end
setUp()
else
printToColor('Game Masters cannot be a player', color,getColorfromPlayer(color))
end
else
printToColor('Spectators cannot be a player', color ,getColorfromPlayer(color))
end
end
function updatePlayerLabel(this)
this.interactable = false
this.lock()
this.setColorTint(getColorfromPlayer(currentPlayer.color))
this.setPosition(getTokenLocation(currentPlayer.color))
this.setRotation(getTokenRotation(currentPlayer.color))
if this.getButtons() ~= nil
then
this.editButton({index=0,label=currentPlayer.steam_name})
else
this.createButton({click_function='dummy', label=currentPlayer.steam_name, function_owner=Global, position={0, 0.1, 0}, rotation={0, 180, 0}, width=2250, height=400, font_size=350})
end
end
function updateDirectionLabel(this)
this.interactable = false
this.lock()
this.setColorTint(getColorfromPlayer(currentPlayer.color))
this.setPosition(getDirectionLocation(currentPlayer.color))
this.setRotation(getTokenRotation(currentPlayer.color))
if this.getButtons() ~= nil
then
if clockwisePlay
then
this.editButton({index=0,label='<---'})
else
this.editButton({index=0,label='--->'})
end
else
if clockwisePlay
then
this.createButton({click_function='dummy', label='<---', function_owner=Global, position={0, 0.1, 0}, rotation={0, 180, 0}, width=2250, height=400, font_size=350})
else
this.createButton({click_function='dummy', label='--->', function_owner=Global, position={0, 0.1, 0}, rotation={0, 180, 0}, width=2250, height=400, font_size=350})
end
end
end
function dummy()
end
function GrabPlayerList()
counter = 1
players = {}
tokenLocations= {}
tokenRotations= {}
for i, player in ipairs(PLAYERS)
do
if player.seated
then
players[counter] = player
tokenLocations[counter] = getTokenLocation(i)
counter = counter + 1
end
end
if currentPlayer ~= nil
then
if #players > 0
then
if currentPlayer.seated == false
then
currentPlayer = players[#players]
updatePlayerLabel(currentPlayer_label)
updateDirectionLabel(currentDirection_label)
end
end
end
end
function cleanHands()
for i, player in ipairs(PLAYERS)
do
if player.seated == false
then
if #player.getHandObjects() > 0
then
deckPosition = { deck.getPosition()['x'], deck.getPosition()['y'] + 0.5, deck.getPosition()['z'] }
deckRotation = deck.getRotation()
for i, card in ipairs(player.getHandObjects())
do
card.setRotation(deckRotation)
card.setPosition(deckPosition)
end
deck.shuffle()
end
end
end
end
function listPlayers()
GrabPlayerList()
counter = 0
for i = 1,#players,1
do
broadcastToAll(players[(currentPlayer_index+counter)].steam_name .. " is player " .. i, getColorfromPlayer(players[(currentPlayer_index+counter)].color))
--broadcastToColor("You Are Player " .. i, players[(currentPlayer_index+counter)].color,getColorfromPlayer(players[(currentPlayer_index+counter)].color))
if (currentPlayer_index + counter + 1) <= #players
then
counter = counter + 1
else
counter = (-currentPlayer_index)+1
end
end
end
function round(num, numDecimalPlaces)
local mult = 10^(numDecimalPlaces or 0)
return math.floor(num * mult + 0.5) / mult
end
function getPlayerFromColor(color)
for i, player in ipairs(players)
do
local pc = getColorfromPlayer(player.color)
if pc[1] == round(color[1], 3) and pc[2] == round(color[2], 3) and pc[3] == round(color[3], 3) -- This seems like a crap way to do this...
then
return player
end
end
broadcastToAll('Did not find player', "Black")
end
function getColorfromPlayer(player_color)
if player_color == "Green"
then
do return {0.129,0.701,0.168} end