-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGlobal.-1.lua
2991 lines (2764 loc) · 90.9 KB
/
Global.-1.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
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
--[[ Scripted version of Sheepshead built inside of Tabletop Simulator By: WardLordRuby
Scoring currently uses a modified version of the blackjack counting script by: MrStump
I liked how EpicWolverine handled rebuilding the deck so I modified his code ]]--
DEBUG = true
--[[CONST values]]--
ALL_PLAYERS = {"White", "Red", "Yellow", "Green", "Blue", "Pink"}
BLACK_SEVENS = {"Seven of Clubs", "Seven of Spades"}
BLINDS_STR = "Blinds"
CHAT_COMMANDS = {
"[b415ff]Sheepshead Console Help[-]\n",
"[21AF21].rules[-] [Displays Rule and Gameplay Tip Booklet]\n",
"[21AF21].hiderules[-] [Hides Rule and Gameplay Tip Booklet]\n",
"[21AF21].respawndeck[-] [Removes all Cards and Spawns a Fresh Deck]\n",
"[21AF21].spawnchips[-] [Gives all seated players 15 additional chips]\n",
"[21AF21].settings[-] [Opens Window to Change Game Settings]"
}
COIN_PRAM = {
mesh = "https://steamusercontent-a.akamaihd.net/ugc/2205135744307283952/DEF0BF91642CF5636724CA3A37083385C810BA06/",
diffuse = "https://steamusercontent-a.akamaihd.net/ugc/2288456143464578824/E739670FE62B8267C90E54D4B786C1C83BA7CC22/",
type = 5,
material = 2,
specular_sharpness = 5
}
FAIL_STRENGTHS = {"Seven", "Eight", "Nine", "King", "Ten", "Ace"}
GUID = {
TRICK_ZONE_WHITE = "70f1a5",
TRICK_ZONE_RED = "b14dc7",
TRICK_ZONE_YELLOW = "db8133",
TRICK_ZONE_GREEN = "85fad3",
TRICK_ZONE_BLUE = "69cfb0",
TRICK_ZONE_PINK = "de62ee",
HAND_ZONE_WHITE = "f01eb8",
HAND_ZONE_RED = "c57287",
HAND_ZONE_YELLOW = "bfea25",
HAND_ZONE_GREEN = "98ae00",
HAND_ZONE_BLUE = "1222be",
HAND_ZONE_PINK = "166a59",
CENTER_ZONE = "548811",
TABLE_ZONE = "3c99b3",
DROP_ZONE = "ba398c",
HIDDEN_BAG = "b3d3a5",
TABLE_BLOCK = "8e445a",
DEALER_CHIP = "e18594",
SET_BURIED_BUTTON = "37d199",
DECK_COPY = "f247a7"
}
POS = {
center = Vector(0, 1.5, 0),
objectRespawn = Vector(0, 3, 0),
defaultDeckRotation = Vector(0, 0, 180)
}
ROTATION = {
color = {
White = 0,
Red = 60,
Yellow = 120,
Green = 180,
Blue = 240,
Pink = 300
},
block = {
Pink = 30,
Yellow = 30,
White = 270,
Green = 270,
Red = 330,
Blue = 330
}
}
RULE_BOOK_JSON = [[{
"Name": "Custom_PDF",
"Transform": {
"posX": 0.0,
"posY": 0.0,
"posZ": 0.0,
"rotX": 0.0,
"rotY": 0.0,
"rotZ": 0.0,
"scaleX": 1.0,
"scaleY": 1.0,
"scaleZ": 1.0
},
"Nickname": "Rules and Tips",
"Description": "",
"GMNotes": "",
"ColorDiffuse": {
"r": 1.0,
"g": 1.0,
"b": 1.0
},
"Locked": false,
"Grid": true,
"Snap": true,
"IgnoreFoW": false,
"Autoraise": true,
"Sticky": true,
"Tooltip": true,
"GridProjection": false,
"HideWhenFaceDown": false,
"Hands": false,
"CustomPDF": {
"PDFUrl": "https://steamusercontent-a.akamaihd.net/ugc/2288456143469151321/BB82096AE4DD8D9295A3B9062729704F9B5A2A5B/",
"PDFPassword": "",
"PDFPage": 0,
"PDFPageOffset": 0
},
"XmlUI": "<!-- -->",
"LuaScript": "--foo",
"LuaScriptState": "",
"GUID": "pdf001"
}]]
SPAWN_POS = {
tableBlock = Vector(0, 3.96, 0),
pickerCounter = Vector(0, 1.83, -4.04),
tableCounter = Vector(0, 1.83, 4.04),
leasterCards = Vector(-3.84, 1, -6.63),
ruleBook = Vector(0, 0.96, -9.5),
dealerChip = Vector(4, -2.58, 7),
deck = Vector(2, -2.5, 5),
setBuriedButton = Vector(0, 0.96, -8),
blinds = {
Vector(-0.7, 1, 0),
Vector(0.8, 1, 0)
},
chips = {
Vector(4.62, -2, 3),
Vector(6.12, -2, 3.13),
Vector(5.31, -2, 4.35)
}
}
TRUMP_IDENTIFIER = {"Diamonds", "Jack", "Queen"}
TRUMP_STRENGTHS = {
"Seven of Diamonds", "Eight of Diamonds", "Nine of Diamonds", "King of Diamonds", "Ten of Diamonds",
"Ace of Diamonds", "Jack of Diamonds", "Jack of Hearts", "Jack of Spades", "Jack of Clubs",
"Queen of Diamonds", "Queen of Hearts", "Queen of Spades", "Queen of Clubs"
}
--[[GLOBAL values]]--
---Timer that loops the `displayWonOrLossText` function passing calculated values back into itself<br>
---Responsible for displaying the number of chips won or loss in a hand<br>
---@type integer<UID>|nil
CHIP_SCORE_TEXT_TIMER = nil
---Note: `object` table contains: `z = object<zone>, c = object<counter>`<br>
---Picker `object` group is always in index `1`<br>Can not be stringified
---@type table<table<objects>>
COUNTER_OBJ_SETS = {}
---Note: Can not be stringified
---@type object<"3DText">|nil
SCORE_TEXT_OBJ = nil
---Timer that loops the responsible functions for displaying the score of a hand<br>
---this value is instantiated by `startTrickCount`
---@type integer<UID>|nil
TRICK_COUNTER_TIMER = nil
---@param script_state JSON<table>
function onLoad(script_state)
TRICK_ZONE = {
White = getObjectFromGUID(GUID.TRICK_ZONE_WHITE),
Red = getObjectFromGUID(GUID.TRICK_ZONE_RED),
Yellow = getObjectFromGUID(GUID.TRICK_ZONE_YELLOW),
Green = getObjectFromGUID(GUID.TRICK_ZONE_GREEN),
Blue = getObjectFromGUID(GUID.TRICK_ZONE_BLUE),
Pink = getObjectFromGUID(GUID.TRICK_ZONE_PINK)
}
HAND_ZONE = {
White = getObjectFromGUID(GUID.HAND_ZONE_WHITE),
Red = getObjectFromGUID(GUID.HAND_ZONE_RED),
Yellow = getObjectFromGUID(GUID.HAND_ZONE_YELLOW),
Green = getObjectFromGUID(GUID.HAND_ZONE_GREEN),
Blue = getObjectFromGUID(GUID.HAND_ZONE_BLUE),
Pink = getObjectFromGUID(GUID.HAND_ZONE_PINK)
}
SCRIPT_ZONE = {
center = getObjectFromGUID(GUID.CENTER_ZONE),
table = getObjectFromGUID(GUID.TABLE_ZONE),
drop = getObjectFromGUID(GUID.DROP_ZONE)
}
STATIC_OBJECT = {
hiddenBag = getObjectFromGUID(GUID.HIDDEN_BAG),
dealerChip = getObjectFromGUID(GUID.DEALER_CHIP),
setBuriedButton = getObjectFromGUID(GUID.SET_BURIED_BUTTON)
}
STATIC_OBJECT.hiddenBag.interactable = false
STATIC_OBJECT.dealerChip.interactable = false
STATIC_OBJECT.setBuriedButton.interactable = false
STATIC_OBJECT.hiddenBag.setInvisibleTo(ALL_PLAYERS)
STATIC_OBJECT.setBuriedButton.setInvisibleTo(ALL_PLAYERS)
---@type {
--- playerCount: integer|nil,
--- sortedSeatedPlayers: table<"Colors">|nil,
--- dealOrder: table<"Colors"|BLINDS_STR>|nil,
--- blackSevens: string<"GUID">|nil,
--- dealerColorIdx: integer<index>|nil,
--- holdCards: table<"cardName">|nil,
--- currentTrick: table<metaData>|nil,
--- gameSetupPlayer: string<"Color">|nil,
--- pickingPlayer: string<"Color">|nil,
--- partnerCard: string<"cardName">|nil,
--- leadOutPlayer: string<"Color">|nil,
--- lastLeasterTrick: string<"GUID">|nil,
--- unknownText: string<"GUID">|nil,
--- chipScoreText: string<"GUID">|nil,
--- counterGUIDs: table<string<"zoneGUID">, string<"counterGUID">>|nil
--- }
GLOBAL = {
playerCount = nil,
sortedSeatedPlayers = nil,
dealOrder = nil,
blackSevens = nil,
dealerColorIdx = nil,
holdCards = nil, --Note: `nil` == unknown mode
currentTrick = nil, --Note: `self[1]` contains general trickMetadata, followed by metadata for each card in the trick
gameSetupPlayer = nil,
pickingPlayer = nil,
partnerCard = nil,
leadOutPlayer = nil,
lastLeasterTrick = nil,
unknownText = nil, --Note: Shares position data with leasterCards
chipScoreText = nil,
counterGUIDs = nil --Note: Linked by Key, Value pairs
}
FLAG = {
gameSetup = {
inProgress = false,
ran = false
},
trick = {
inProgress = false,
handOut = false
},
leasterHand = false,
stopCoroutine = false,
dealInProgress = false,
lookForPlayerText = false,
continue = nil,
cardsToBeBuried = false,
counterVisible = false,
firstDealOfGame = false,
allowGrouping = true,
selectingPartner = false,
fnRunning = false
}
---Note: the ordering of these values matters for correctly setting state `onLoad`
---@type {
--- jdPartner: boolean|nil,
--- dealerSitsOut: boolean,
--- calls: boolean,
--- threeHanded: boolean,
--- }
SETTINGS = {
jdPartner = true, --Note: `false` == Call an Ace && `nil` == No Partner
dealerSitsOut = false,
calls = false,
threeHanded = false
}
CALL_SETTINGS = {
sheepshead = false,
blitz = false,
leaster = false,
crack = false,
crackBack = false,
crackAroundTheCorner = false
}
local state = JSON.decode(script_state)
if not isEmpty(state) then
for rule, saved in pairs(state.settings) do
if SETTINGS[rule] ~= saved then
updateRules(rule, saved)
toggleUISettingsButtonState(rule, saved)
end
end
for call, saved in pairs(state.callSettings) do
if CALL_SETTINGS[call] ~= saved then
updateCalls(call, saved)
toggleUISettingsButtonState(call, saved)
end
end
for flag, saved in pairs(state.flags) do
FLAG[flag] = saved
end
for global, saved in pairs(state.globals) do
GLOBAL[global] = saved
end
if FLAG.counterVisible then
local tableBlock = getObjectFromGUID(GUID.TABLE_BLOCK)
tableBlock.setInvisibleTo(ALL_PLAYERS)
tableBlock.setLock(true)
startTrickCount()
if not FLAG.leasterHand then
SCORE_TEXT_OBJ = getObjectFromGUID(GLOBAL.chipScoreText)
SCORE_TEXT_OBJ.interactable = false
displayWonOrLossText()
end
end
if FLAG.cardsToBeBuried and GLOBAL.pickingPlayer then
showSetBuriedButton()
end
end
if DEBUG then
UI.show("playerUp")
UI.show("playerDown")
end
displayRules()
end
---@return JSON<table>
function onSave()
local state = {
settings = SETTINGS,
callSettings = CALL_SETTINGS,
flags = FLAG,
globals = GLOBAL
}
return JSON.encode(state)
end
--[[Utility functions]]--
---Checks `dealInProgress`, `trick.handOut`, `gameSetup.inProgress`, `selectingPartner`, and `fnRunning`
---@return boolean
function safeToContinue()
if FLAG.dealInProgress
or FLAG.trick.handOut
or FLAG.gameSetup.inProgress
or FLAG.fnRunning
or FLAG.selectingPartner then
return false
end
return true
end
---Returns `true` if thier are 6 seated players and `SETTINGS.dealerSitsOut` is active
---@return boolean
function dealerSitsOutActive()
return GLOBAL.playerCount ~= #GLOBAL.sortedSeatedPlayers
end
---Sets the FLAG.fnRunning to true when safe this must be ran within a coroutine
function startFnRunFlag()
while FLAG.fnRunning do
coroutine.yield(0)
end
FLAG.fnRunning = true
end
---Pauses script, must be called from within a coroutine
---@param time integer<seconds>
function pause(time)
local start = Time.time
repeat coroutine.yield(0) until Time.time > start + time or FLAG.continue ~= nil
end
--[[String manipulation]]--
---@param str string
---@return string
function getLastWord(str)
return str:match("%S+$") --%S+ = one or more non-space characters, $ = match end of string
end
---@param str string
---@return string
function upperFirstChar(str)
return str:sub(1, 1):upper() .. str:sub(2)
end
---@param str string
---@return string
function lowerFirstChar(str)
return str:sub(1, 1):lower() .. str:sub(2)
end
---Inserts a space before every capital letter in string
---@param str string
---@return string
function insertSpaces(str)
return str:gsub("(%u)", " %1") --(%u) = capture group match upperCase letter, %1 = link to capture group
end
---@param str string
---@return string
function removeSpaces(str)
return str:gsub("%s", "") --%s = space character
end
--[[Table manipulation]]--
---@param list table
---@return table
function copyTable(list)
return JSON.decode(JSON.encode(list))
end
---Copys input table and removes the first matching value, if value not found returns original table<br>
---Table must have numerical indexes
---@param remove any
---@param from table<any>
---@return table<any>
function removeFromClonedList(remove, from)
local foundIdx
for i, v in ipairs(from) do
if v == remove then
foundIdx = i
break
end
end
if foundIdx then
local modifiedList = copyTable(from)
table.remove(modifiedList, foundIdx)
return modifiedList
end
return from
end
---@param color string<"Color">
---@param pipeList string
---@return pipeList string
function addColorToPipeList(color, pipeList)
if not pipeList or pipeList == "" then
pipeList = color
else
pipeList = pipeList .. "|" .. color
end
return pipeList
end
---@param color string<"Color">
---@param pipeList string
---@return pipeList string
function removeColorFromPipeList(color, pipeList)
pipeList = string.gsub(pipeList, color .. '|', "")
pipeList = string.gsub(pipeList, '|' .. color, "")
pipeList = string.gsub(pipeList, color, "")
return pipeList
end
--[[Data retrieval]]--
---@param object object
---@param zone object<zone>
---@return boolean
function isInZone(object, zone)
local occupiedZones = object.getZones()
for _, zoneObject in ipairs(occupiedZones) do
if zoneObject == zone then
return true
end
end
return false
end
---Used to ensure 0 is returned if table empty or nil,<br>
---or used if you want to get number of elements in table with non integer keys
---@param table table<any>|nil
---@return integer
function len(table)
if isEmpty(table) then
return 0
end
local count = 0
for _ in pairs(table) do
count = count + 1
end
return count
end
---Used to ensure `true` is returned if table empty or nil
---@param table table<any>|nil
---@return boolean
function isEmpty(table)
return table == nil or next(table) == nil
end
---Does not check table keys
---@param table table<any>
---@param value any
---@return boolean
function tableContains(table, value)
for _, v in pairs(table) do
if v == value then
return true
end
end
return false
end
---Returns the deck from given zone
---If you are aware of more than one deck in a given zone getDeck()<br> can return the smaller or larger
---of the decks found. This function has the possibility to error if not ran within a coroutine
---@param zone object<zone>
---@param size option_string <"big"|"small">
---@return object<deck>|nil
function getDeck(zone, size)
local decks = {}
for _, obj in ipairs(zone.getObjects()) do
if obj.type == "Deck" then
table.insert(decks, obj)
end
end
if #decks == 0 then
return nil
elseif #decks == 1 then
return decks[1]
elseif size == "small" then
local smallDeck = decks[1]
for i = 2, #decks do
if decks[i].getQuantity() < smallDeck.getQuantity() then
smallDeck = decks[i]
end
end
return smallDeck
elseif size == "big" then
local bigDeck = decks[1]
for i = 2, #decks do
if decks[i].getQuantity() > bigDeck.getQuantity() then
bigDeck = decks[i]
end
end
return bigDeck
end
group(decks)
pause(1)
return getDeck(zone)
end
---getLooseCards also provieds a safe way to return a deck Object from outside of a coroutine<br>
---@param zone object<zone>
---@param returnFirstDeck option_boolean
---@return table<card_Objects_and_deck_Objects>|nil
function getLooseCards(zone, returnFirstDeck)
local looseCards = {}
for _, obj in ipairs(zone.getObjects()) do
if obj.type == "Deck" or obj.type == "Card" then
if returnFirstDeck and obj.type == "Deck" then
return obj
end
table.insert(looseCards, obj)
end
end
if not returnFirstDeck then
return looseCards
end
return nil
end
---Searches table for given input and return the index value if found, otherwise returns `nil`
---@param find any
---@param list table<any>|nil
function getIndex(find, list)
for i, v in ipairs(list) do
if v == find then
return i
end
end
return nil
end
---Returns the index of the player seated clockwise from given index, will never return `BLINDS_STR` index<br>
---Can also return the counter-clockwise index postion if the `reverse` flag is set
---@param index integer
---@param list table<"Colors">
---@param reverse option_boolean
---@return integer<index>|nil
function cycleColorIndex(index, list, reverse)
if isEmpty(list) then
return nil
end
local listLength = #list
if index > listLength or index < 1 then
return nil
end
local step
if reverse then
step = function(curr)
return ((curr - 2) % listLength) + 1
end
else
step = function(curr)
return (curr % listLength) + 1
end
end
local i = step(index)
while list[i] == BLINDS_STR do
i = step(i)
end
return i
end
---Returns the rotationValue.z associated for cards if more cards are face up or face down in a given zone
---@param zone object<zone>
---@return integer<0|180>
function moreFaceUpOrDown(zone)
local total, faceDownCount = countCards(zone)
local halfOfTotal = math.floor(total / 2)
if halfOfTotal >= faceDownCount then
return 0
end
return 180
end
---Returns the number of cards in a given zone, also returns faceDownCount
---@param zone object<zone>
---@return integer<numCards>, integer<numCardsFaceDown>
function countCards(zone)
local objects = zone.getObjects()
local cardCount, faceDownCount = 0, 0
for _, obj in ipairs(objects) do
if obj.type == "Deck" then
cardCount = cardCount + obj.getQuantity()
if obj.is_face_down then
faceDownCount = faceDownCount + obj.getQuantity()
end
elseif obj.type == "Card" then
cardCount = cardCount + 1
if obj.is_face_down then
faceDownCount = faceDownCount + 1
end
end
end
return cardCount, faceDownCount
end
---@param player string<"Color">
---@param cardName string
---@return boolean
function doesPlayerPossessCard(player, cardName)
local playerCards = getPlayerCards(player)
for _, name in ipairs(playerCards) do
if name == cardName then
return true
end
end
return false
end
---Searches `player`'s `HAND_ZONE` and `TRICK_ZONE`
---@param player string<"Color">
---@return table<"cardNames">
function getPlayerCards(player)
local cards = {}
for _, card in ipairs(getLooseCards(HAND_ZONE[player])) do
table.insert(cards, card.getName())
end
for _, object in ipairs(getLooseCards(TRICK_ZONE[player])) do
if object.type == "Card" then
table.insert(cards, object.getName())
else
for _, card in ipairs(object.getObjects()) do
table.insert(cards, card.getName())
end
end
end
return cards
end
---Filters cards relevant to determining Call an Ace conditions or finding next highest card to call
---@param player string<"Color">
---@param scheme string<"suitableFail"|"King"|"Ace"|"Ten"|"Jack"|"Queen">
---@param doNotInclude option_string
---@return table<"cardNames">
function filterPlayerCards(player, scheme, doNotInclude)
local playerCards = getPlayerCards(player)
local filteredCards, filterList = {}, {}
local validCard
if scheme == "suitableFail" then
for i = 1, 5 do
filterList[i] = FAIL_STRENGTHS[i]
end
else
filterList[1] = scheme
end
if doNotInclude then
validCard = function(name, findName)
return string.find(name, findName) and not string.find(name, doNotInclude)
end
else
validCard = function(name, findName)
return string.find(name, findName)
end
end
for _, name in ipairs(playerCards) do
for _, findName in ipairs(filterList) do
if validCard(name, findName) then
table.insert(filteredCards, name)
end
end
end
return filteredCards
end
---@param player string<"Color">
---@return integer<rotationAngle>, vector<playerPosition>
function getItemMoveData(player)
return ROTATION.color[player], Player[player].getHandTransform().position
end
---Prints `CURRENT_RULES` to the screen
function displayRules()
setNotes(table.concat(CURRENT_RULES, ""))
end
--[[Object manipulation]]--
---Checks if a deck in the given zone is face up, if so it flips the deck<br>
---Recomended to be ran from within a coroutine
---@param zone object<zone>
function flipDeck(zone)
local deck = getDeck(zone)
if not deck then
return
end
if not deck.is_face_down then
deck.flip()
end
end
---Checks if cards in the given zone are face up, if so it flips cards
---@param zone object<zone>
function flipCards(zone)
for _, card in ipairs(getLooseCards(zone)) do
if not card.is_face_down then
card.flip()
end
end
end
---Called to remove items from a zone. Must be called from within a coroutine if `not skipAnimation`
---@param zone object<zone>
---@param items table<"Types">|string<"Type">
---@param skipAnimation option_boolean
function removeItem(zone, items, skipAnimation)
if type(items) == "string" then
items = {items}
end
local zoneObjects = zone.getObjects()
for i = #zoneObjects, 1 , -1 do
local object = zoneObjects[i]
if tableContains(items, object.type) then
object.destruct()
if not skipAnimation then
pause(0.06)
end
end
end
end
---Moves deck and dealer chip in front of the next clockwise seated player<br>
---Needs to be ran from within a coroutine
function moveDeckAndDealerChip()
local rotationAngle, playerPos = getItemMoveData(GLOBAL.sortedSeatedPlayers[GLOBAL.dealerColorIdx])
local rotatedChipOffset = SPAWN_POS.dealerChip:copy():rotateOver('y', rotationAngle)
local rotatedDeckOffset = SPAWN_POS.deck:copy():rotateOver('y', rotationAngle)
local chipRotation = STATIC_OBJECT.dealerChip.getRotation()
local deck = getDeck(SCRIPT_ZONE.table)
while not deck do
coroutine.yield(0)
deck = getDeck(SCRIPT_ZONE.table)
end
STATIC_OBJECT.dealerChip.setRotationSmooth({ chipRotation.x, rotationAngle - 90, chipRotation.z })
STATIC_OBJECT.dealerChip.setPositionSmooth(playerPos + rotatedChipOffset)
deck.setRotationSmooth({ deck.getRotation().x, rotationAngle, POS.defaultDeckRotation.z })
deck.setPositionSmooth(playerPos + rotatedDeckOffset)
end
---prepCards will group and center all cards and respawn the deck if any error is encountered<br>
---Needs to be ran from within a coroutine
function prepCards()
local looseCards = getLooseCards(SCRIPT_ZONE.table)
if not looseCards then
respawnDeckCoroutine()
return
end
if #looseCards > 1 then
group(looseCards)
pause(0.5)
local deck = getDeck(SCRIPT_ZONE.table)
if not deck then
respawnDeckCoroutine()
return
end
deck.setPosition(POS.center)
deck.setRotation(POS.defaultDeckRotation)
pause(1)
end
end
---Just checks to make sure cards are all there<br>
---Needs to be ran from within a coroutine
function verifyCardCount()
local cardCount = countCards(SCRIPT_ZONE.table)
local modifyDeck, deckModifiable, correctCount
if GLOBAL.playerCount == 4 then
correctCount = 30
modifyDeck = removeBlackSevens
deckModifiable = function(deck)
return deck and deck.getQuantity() == 32 and cardCount == 32
end
else
correctCount = 32
modifyDeck = returnDecktoPiquet
deckModifiable = function(deck)
return deck and deck.getQuantity() == 30 and cardCount == 30 and GLOBAL.blackSevens
end
end
if cardCount ~= correctCount then
local deck = getDeck(SCRIPT_ZONE.table)
if deckModifiable(deck) then
modifyDeck(deck)
else
respawnDeckCoroutine()
end
end
end
---Spreads cards out over the center of the table, makes sure they are face down, and groups cards
function rebuildDeck()
FLAG.allowGrouping = false
local faceRotation = moreFaceUpOrDown(SCRIPT_ZONE.table)
for _, object in ipairs(getLooseCards(SCRIPT_ZONE.table)) do
if object.type == "Deck" then
for _, card in ipairs(object.getObjects()) do
object.takeObject({
rotation = { 0, math.random(0, 360), faceRotation },
position = { math.random(-5.75, 5.75), 1.4, math.random(-5.75, 5.75) },
guid = card.guid
})
pause(0.03)
end
else
object.setRotation({ 0, math.random(0, 360), faceRotation })
object.setPosition({ math.random(-5.75, 5.75), 1.4, math.random(-5.75, 5.75) })
pause(0.03)
end
end
pause(0.25)
flipCards(SCRIPT_ZONE.table)
FLAG.allowGrouping = true
pause(0.5)
group(getLooseCards(SCRIPT_ZONE.table))
pause(0.5)
group(getLooseCards(SCRIPT_ZONE.table))
pause(0.5)
end
--[[Start of functions used by Set Up Game event]]--
---Runs everytime a chat occurs.
---<br>Return: true, hides player msg | false, shows player msg
---@param message string<playerInput>
---@param player object<player>
---@return boolean
function onChat(message, player)
--Sets flags for determining if to reset gameboard
if FLAG.lookForPlayerText and player.color == GLOBAL.gameSetupPlayer then
local lowerMessage = string.lower(message)
if lowerMessage == 'y' then
print("[21AF21]" .. player.steam_name .. " selected new game.[-]")
print("[21AF21]New game is being set up.[-]")
FLAG.continue = true
return false
elseif lowerMessage == 'n' then
FLAG.continue = false
return false
end
end
--Handles chat event for game commands
if string.sub(message, 1, 1) == '.' then
local command = string.lower(string.sub(message, 2))
if command == "help" then
print(table.concat(CHAT_COMMANDS, ""))
elseif command == "rules" then
getRuleBook(player.color)
elseif command == "hiderules" then
removeItem(SCRIPT_ZONE.table, "Tile", true)
elseif command == "respawndeck" then
if adminCheck(player) then
respawnDeck(player.color)
end
elseif command == "settings" then
if adminCheck(player) then
toggleWindowVisibility(player.color, "settingsWindow")
end
elseif command == "spawnchips" then
startChipSpawn(player)
else
broadcastToColor("[DC0000]Command not found.[-]", player.color)
end
return false
end
end
---@param player object
---@return boolean
function adminCheck(player)
if not player.admin then
broadcastToColor("[DC0000]You do not have permission to access this feature.[-]", player.color)
return false
end
return true
end
---Spawns a rule book in front of player color
---@param player string<"Color">
function getRuleBook(player)
local playerRotation = ROTATION.color[player]
local ruleBookPos = SPAWN_POS.ruleBook:copy():rotateOver('y', playerRotation)
spawnObjectJSON({
json = RULE_BOOK_JSON,
position = { ruleBookPos.x, 1.5, ruleBookPos.z },
rotation = { 0, playerRotation - 180, 0 }
})
end
---Removes any cards on the table and respawns the deck
---@param player string<"Color">
function respawnDeck(player)
if not safeToContinue() then
broadcastToColor("[DC0000]Please wait till event is over and try again.[-]", player)
return
end
startLuaCoroutine(self, "respawnDeckCoroutine")
end
function respawnDeckCoroutine()
local remainingTableCards = getLooseCards(SCRIPT_ZONE.table)
if not isEmpty(remainingTableCards) then
removeItem(SCRIPT_ZONE.table, {"Card", "Deck"})
end
STATIC_OBJECT.hiddenBag.takeObject({
guid = GUID.DECK_COPY,
position = { 3, 2, 0 },
rotation = POS.defaultDeckRotation,
smooth = false
})
local deckCopy = getObjectFromGUID(GUID.DECK_COPY)
deckCopy.setInvisibleTo(ALL_PLAYERS)
local newDeck = deckCopy.clone({
position = { 0, -3, 0 }
})
STATIC_OBJECT.hiddenBag.putObject(deckCopy)
if GLOBAL.blackSevens then
STATIC_OBJECT.hiddenBag.takeObject({
guid = GLOBAL.blackSevens,
position = { 5, 2, 0 },
rotation = POS.defaultDeckRotation,
smooth = false
})
getObjectFromGUID(GLOBAL.blackSevens).destruct()
GLOBAL.blackSevens = nil
end
if GLOBAL.playerCount and GLOBAL.playerCount == 4 then
pause(0.2)
removeBlackSevens(newDeck)
end
if FLAG.gameSetup.ran and FLAG.firstDealOfGame then
pause(0.4)
moveDeckAndDealerChip()
end
pause(0.75)
return 1
end
---Builds the `GLOBAL.sortedSeatedPlayers` table of all seated players