@pompidup/kingdomino-engine 3.3.0 → 3.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -168,6 +168,25 @@ var wrapWithDebug = (engine2, options) => {
168
168
  engine2.getDynastyResults,
169
169
  logger,
170
170
  level
171
+ ),
172
+ placeKnight: wrapMethod(
173
+ "placeKnight",
174
+ engine2.placeKnight,
175
+ logger,
176
+ level
177
+ ),
178
+ constructBuilding: wrapMethod(
179
+ "constructBuilding",
180
+ engine2.constructBuilding,
181
+ logger,
182
+ level
183
+ ),
184
+ useDragon: wrapMethod("useDragon", engine2.useDragon, logger, level),
185
+ skipOptionalAction: wrapMethod(
186
+ "skipOptionalAction",
187
+ engine2.skipOptionalAction,
188
+ logger,
189
+ level
171
190
  )
172
191
  };
173
192
  };
@@ -232,7 +251,12 @@ var wrapWithEvents = (engine2, callbacks) => ({
232
251
  callbacks.onGameEnd?.({ game });
233
252
  }
234
253
  return game;
235
- }
254
+ },
255
+ // Queendomino methods — pass through (no specific events yet)
256
+ placeKnight: (cmd) => engine2.placeKnight(cmd),
257
+ constructBuilding: (cmd) => engine2.constructBuilding(cmd),
258
+ useDragon: (cmd) => engine2.useDragon(cmd),
259
+ skipOptionalAction: (cmd) => engine2.skipOptionalAction(cmd)
236
260
  });
237
261
 
238
262
  // src/adapterServerside/consoleLogger.ts
@@ -261,6 +285,61 @@ var silentLogger = {
261
285
  }
262
286
  };
263
287
 
288
+ // src/datasources/buildings.json
289
+ var buildings_default = [
290
+ { id: 1, name: "The Bakery", cost: 1, immediateBonus: { type: "coins", amount: 2 }, crowns: 0, towers: 0 },
291
+ { id: 2, name: "The Bakery", cost: 1, immediateBonus: { type: "coins", amount: 2 }, crowns: 0, towers: 0 },
292
+ { id: 3, name: "The Sawmill", cost: 2, crowns: 0, towers: 0, endGameScoring: { type: "perTerrain", terrain: "forest", points: 1 } },
293
+ { id: 4, name: "The Fishmonger's", cost: 2, immediateBonus: { type: "coins", amount: 1 }, crowns: 0, towers: 0, endGameScoring: { type: "perTerrain", terrain: "sea", points: 1 } },
294
+ { id: 5, name: "The Fishmonger's", cost: 2, immediateBonus: { type: "coins", amount: 1 }, crowns: 0, towers: 0, endGameScoring: { type: "perTerrain", terrain: "sea", points: 1 } },
295
+ { id: 6, name: "The Weaving Shop", cost: 3, crowns: 1, towers: 0, endGameScoring: { type: "perTerrain", terrain: "wheat", points: 1 } },
296
+ { id: 7, name: "The Magic School", cost: 4, crowns: 1, towers: 0, endGameScoring: { type: "perCrown", points: 1 } },
297
+ { id: 8, name: "The Fountain", cost: 3, crowns: 0, towers: 1, endGameScoring: { type: "perTower", points: 2 } },
298
+ { id: 9, name: "The Church", cost: 4, crowns: 1, towers: 0, endGameScoring: { type: "perBuilding", points: 2 } },
299
+ { id: 10, name: "The Bath", cost: 2, immediateBonus: { type: "coins", amount: 1 }, crowns: 0, towers: 0, endGameScoring: { type: "flat", points: 4 } },
300
+ { id: 11, name: "The Guard Tower", cost: 1, crowns: 0, towers: 1, endGameScoring: { type: "flat", points: 2 } },
301
+ { id: 12, name: "The Guard Tower", cost: 1, crowns: 0, towers: 1, endGameScoring: { type: "flat", points: 2 } },
302
+ { id: 13, name: "The Big Tower", cost: 3, crowns: 0, towers: 2, endGameScoring: { type: "flat", points: 4 } },
303
+ { id: 14, name: "The Guardhouse", cost: 2, crowns: 0, towers: 1, endGameScoring: { type: "perBuilding", points: 1 } },
304
+ { id: 15, name: "The Fortified Castle", cost: 5, crowns: 2, towers: 1, endGameScoring: { type: "flat", points: 6 } },
305
+ { id: 16, name: "The Travelling Castle", cost: 3, crowns: 1, towers: 1, endGameScoring: { type: "perTower", points: 1 } },
306
+ { id: 17, name: "The Travelling Group", cost: 2, immediateBonus: { type: "coins", amount: 1 }, crowns: 0, towers: 0, endGameScoring: { type: "perBuilding", points: 1 } },
307
+ { id: 18, name: "The Harbour", cost: 3, crowns: 0, towers: 0, endGameScoring: { type: "perTerrain", terrain: "sea", points: 2 } }
308
+ ];
309
+
310
+ // src/adapterServerside/jsonBuildings.ts
311
+ var jsonBuildings = () => {
312
+ const buildings = buildings_default.map((b) => {
313
+ const tile = {
314
+ id: b.id,
315
+ name: b.name,
316
+ cost: b.cost,
317
+ crowns: b.crowns,
318
+ towers: b.towers
319
+ };
320
+ if (b.immediateBonus) {
321
+ tile.immediateBonus = {
322
+ type: b.immediateBonus.type,
323
+ amount: b.immediateBonus.amount
324
+ };
325
+ }
326
+ if ("endGameScoring" in b && b.endGameScoring) {
327
+ tile.endGameScoring = {
328
+ type: b.endGameScoring.type,
329
+ points: b.endGameScoring.points,
330
+ ..."terrain" in b.endGameScoring && {
331
+ terrain: b.endGameScoring.terrain
332
+ }
333
+ };
334
+ }
335
+ return tile;
336
+ });
337
+ return {
338
+ getAll: () => buildings
339
+ };
340
+ };
341
+ var jsonBuildings_default = jsonBuildings;
342
+
264
343
  // src/datasources/dominoes.json
265
344
  var dominoes_default = {
266
345
  Classic: [
@@ -314,84 +393,614 @@ var dominoes_default = {
314
393
  crowns: 0
315
394
  },
316
395
  right: {
317
- type: "forest",
396
+ type: "forest",
397
+ crowns: 0
398
+ },
399
+ number: 5
400
+ },
401
+ {
402
+ left: {
403
+ type: "forest",
404
+ crowns: 0
405
+ },
406
+ right: {
407
+ type: "forest",
408
+ crowns: 0
409
+ },
410
+ number: 6
411
+ },
412
+ {
413
+ left: {
414
+ type: "sea",
415
+ crowns: 0
416
+ },
417
+ right: {
418
+ type: "sea",
419
+ crowns: 0
420
+ },
421
+ number: 7
422
+ },
423
+ {
424
+ left: {
425
+ type: "sea",
426
+ crowns: 0
427
+ },
428
+ right: {
429
+ type: "sea",
430
+ crowns: 0
431
+ },
432
+ number: 8
433
+ },
434
+ {
435
+ left: {
436
+ type: "sea",
437
+ crowns: 0
438
+ },
439
+ right: {
440
+ type: "sea",
441
+ crowns: 0
442
+ },
443
+ number: 9
444
+ },
445
+ {
446
+ left: {
447
+ type: "plain",
448
+ crowns: 0
449
+ },
450
+ right: {
451
+ type: "plain",
452
+ crowns: 0
453
+ },
454
+ number: 10
455
+ },
456
+ {
457
+ left: {
458
+ type: "plain",
459
+ crowns: 0
460
+ },
461
+ right: {
462
+ type: "plain",
463
+ crowns: 0
464
+ },
465
+ number: 11
466
+ },
467
+ {
468
+ left: {
469
+ type: "swamp",
470
+ crowns: 0
471
+ },
472
+ right: {
473
+ type: "swamp",
474
+ crowns: 0
475
+ },
476
+ number: 12
477
+ },
478
+ {
479
+ left: {
480
+ type: "wheat",
481
+ crowns: 0
482
+ },
483
+ right: {
484
+ type: "forest",
485
+ crowns: 0
486
+ },
487
+ number: 13
488
+ },
489
+ {
490
+ left: {
491
+ type: "wheat",
492
+ crowns: 0
493
+ },
494
+ right: {
495
+ type: "sea",
496
+ crowns: 0
497
+ },
498
+ number: 14
499
+ },
500
+ {
501
+ left: {
502
+ type: "wheat",
503
+ crowns: 0
504
+ },
505
+ right: {
506
+ type: "plain",
507
+ crowns: 0
508
+ },
509
+ number: 15
510
+ },
511
+ {
512
+ left: {
513
+ type: "wheat",
514
+ crowns: 0
515
+ },
516
+ right: {
517
+ type: "swamp",
518
+ crowns: 0
519
+ },
520
+ number: 16
521
+ },
522
+ {
523
+ left: {
524
+ type: "forest",
525
+ crowns: 0
526
+ },
527
+ right: {
528
+ type: "sea",
529
+ crowns: 0
530
+ },
531
+ number: 17
532
+ },
533
+ {
534
+ left: {
535
+ type: "forest",
536
+ crowns: 0
537
+ },
538
+ right: {
539
+ type: "plain",
540
+ crowns: 0
541
+ },
542
+ number: 18
543
+ },
544
+ {
545
+ left: {
546
+ type: "wheat",
547
+ crowns: 1
548
+ },
549
+ right: {
550
+ type: "forest",
551
+ crowns: 0
552
+ },
553
+ number: 19
554
+ },
555
+ {
556
+ left: {
557
+ type: "wheat",
558
+ crowns: 1
559
+ },
560
+ right: {
561
+ type: "sea",
562
+ crowns: 0
563
+ },
564
+ number: 20
565
+ },
566
+ {
567
+ left: {
568
+ type: "wheat",
569
+ crowns: 1
570
+ },
571
+ right: {
572
+ type: "plain",
573
+ crowns: 0
574
+ },
575
+ number: 21
576
+ },
577
+ {
578
+ left: {
579
+ type: "wheat",
580
+ crowns: 1
581
+ },
582
+ right: {
583
+ type: "swamp",
584
+ crowns: 0
585
+ },
586
+ number: 22
587
+ },
588
+ {
589
+ left: {
590
+ type: "wheat",
591
+ crowns: 1
592
+ },
593
+ right: {
594
+ type: "mine",
595
+ crowns: 0
596
+ },
597
+ number: 23
598
+ },
599
+ {
600
+ left: {
601
+ type: "forest",
602
+ crowns: 1
603
+ },
604
+ right: {
605
+ type: "wheat",
606
+ crowns: 0
607
+ },
608
+ number: 24
609
+ },
610
+ {
611
+ left: {
612
+ type: "forest",
613
+ crowns: 1
614
+ },
615
+ right: {
616
+ type: "wheat",
617
+ crowns: 0
618
+ },
619
+ number: 25
620
+ },
621
+ {
622
+ left: {
623
+ type: "forest",
624
+ crowns: 1
625
+ },
626
+ right: {
627
+ type: "wheat",
628
+ crowns: 0
629
+ },
630
+ number: 26
631
+ },
632
+ {
633
+ left: {
634
+ type: "forest",
635
+ crowns: 1
636
+ },
637
+ right: {
638
+ type: "wheat",
639
+ crowns: 0
640
+ },
641
+ number: 27
642
+ },
643
+ {
644
+ left: {
645
+ type: "forest",
646
+ crowns: 1
647
+ },
648
+ right: {
649
+ type: "sea",
650
+ crowns: 0
651
+ },
652
+ number: 28
653
+ },
654
+ {
655
+ left: {
656
+ type: "forest",
657
+ crowns: 1
658
+ },
659
+ right: {
660
+ type: "plain",
661
+ crowns: 0
662
+ },
663
+ number: 29
664
+ },
665
+ {
666
+ left: {
667
+ type: "sea",
668
+ crowns: 1
669
+ },
670
+ right: {
671
+ type: "wheat",
672
+ crowns: 0
673
+ },
674
+ number: 30
675
+ },
676
+ {
677
+ left: {
678
+ type: "sea",
679
+ crowns: 1
680
+ },
681
+ right: {
682
+ type: "wheat",
683
+ crowns: 0
684
+ },
685
+ number: 31
686
+ },
687
+ {
688
+ left: {
689
+ type: "sea",
690
+ crowns: 1
691
+ },
692
+ right: {
693
+ type: "forest",
694
+ crowns: 0
695
+ },
696
+ number: 32
697
+ },
698
+ {
699
+ left: {
700
+ type: "sea",
701
+ crowns: 1
702
+ },
703
+ right: {
704
+ type: "forest",
705
+ crowns: 0
706
+ },
707
+ number: 33
708
+ },
709
+ {
710
+ left: {
711
+ type: "sea",
712
+ crowns: 1
713
+ },
714
+ right: {
715
+ type: "forest",
716
+ crowns: 0
717
+ },
718
+ number: 34
719
+ },
720
+ {
721
+ left: {
722
+ type: "sea",
723
+ crowns: 1
724
+ },
725
+ right: {
726
+ type: "forest",
727
+ crowns: 0
728
+ },
729
+ number: 35
730
+ },
731
+ {
732
+ left: {
733
+ type: "wheat",
734
+ crowns: 0
735
+ },
736
+ right: {
737
+ type: "plain",
738
+ crowns: 1
739
+ },
740
+ number: 36
741
+ },
742
+ {
743
+ left: {
744
+ type: "sea",
745
+ crowns: 0
746
+ },
747
+ right: {
748
+ type: "plain",
749
+ crowns: 1
750
+ },
751
+ number: 37
752
+ },
753
+ {
754
+ left: {
755
+ type: "wheat",
756
+ crowns: 0
757
+ },
758
+ right: {
759
+ type: "swamp",
760
+ crowns: 1
761
+ },
762
+ number: 38
763
+ },
764
+ {
765
+ left: {
766
+ type: "plain",
767
+ crowns: 0
768
+ },
769
+ right: {
770
+ type: "swamp",
771
+ crowns: 0
772
+ },
773
+ number: 39
774
+ },
775
+ {
776
+ left: {
777
+ type: "mine",
778
+ crowns: 1
779
+ },
780
+ right: {
781
+ type: "wheat",
782
+ crowns: 0
783
+ },
784
+ number: 40
785
+ },
786
+ {
787
+ left: {
788
+ type: "wheat",
789
+ crowns: 0
790
+ },
791
+ right: {
792
+ type: "plain",
793
+ crowns: 2
794
+ },
795
+ number: 41
796
+ },
797
+ {
798
+ left: {
799
+ type: "sea",
800
+ crowns: 0
801
+ },
802
+ right: {
803
+ type: "plain",
804
+ crowns: 2
805
+ },
806
+ number: 42
807
+ },
808
+ {
809
+ left: {
810
+ type: "wheat",
811
+ crowns: 0
812
+ },
813
+ right: {
814
+ type: "swamp",
815
+ crowns: 2
816
+ },
817
+ number: 43
818
+ },
819
+ {
820
+ left: {
821
+ type: "plain",
822
+ crowns: 0
823
+ },
824
+ right: {
825
+ type: "swamp",
826
+ crowns: 2
827
+ },
828
+ number: 44
829
+ },
830
+ {
831
+ left: {
832
+ type: "mine",
833
+ crowns: 2
834
+ },
835
+ right: {
836
+ type: "wheat",
837
+ crowns: 0
838
+ },
839
+ number: 45
840
+ },
841
+ {
842
+ left: {
843
+ type: "swamp",
844
+ crowns: 0
845
+ },
846
+ right: {
847
+ type: "mine",
848
+ crowns: 2
849
+ },
850
+ number: 46
851
+ },
852
+ {
853
+ left: {
854
+ type: "swamp",
855
+ crowns: 0
856
+ },
857
+ right: {
858
+ type: "mine",
859
+ crowns: 2
860
+ },
861
+ number: 47
862
+ },
863
+ {
864
+ left: {
865
+ type: "wheat",
866
+ crowns: 0
867
+ },
868
+ right: {
869
+ type: "mine",
870
+ crowns: 3
871
+ },
872
+ number: 48
873
+ }
874
+ ],
875
+ QueenDomino: [
876
+ {
877
+ left: {
878
+ type: "wheat",
879
+ crowns: 0
880
+ },
881
+ right: {
882
+ type: "wheat",
883
+ crowns: 0
884
+ },
885
+ number: 1
886
+ },
887
+ {
888
+ left: {
889
+ type: "wheat",
890
+ crowns: 0
891
+ },
892
+ right: {
893
+ type: "wheat",
894
+ crowns: 0
895
+ },
896
+ number: 2
897
+ },
898
+ {
899
+ left: {
900
+ type: "forest",
901
+ crowns: 0
902
+ },
903
+ right: {
904
+ type: "forest",
905
+ crowns: 0
906
+ },
907
+ number: 3
908
+ },
909
+ {
910
+ left: {
911
+ type: "forest",
912
+ crowns: 0
913
+ },
914
+ right: {
915
+ type: "forest",
916
+ crowns: 0
917
+ },
918
+ number: 4
919
+ },
920
+ {
921
+ left: {
922
+ type: "sea",
923
+ crowns: 0
924
+ },
925
+ right: {
926
+ type: "sea",
318
927
  crowns: 0
319
928
  },
320
929
  number: 5
321
930
  },
322
931
  {
323
932
  left: {
324
- type: "forest",
933
+ type: "sea",
325
934
  crowns: 0
326
935
  },
327
936
  right: {
328
- type: "forest",
937
+ type: "sea",
329
938
  crowns: 0
330
939
  },
331
940
  number: 6
332
941
  },
333
942
  {
334
943
  left: {
335
- type: "sea",
944
+ type: "plain",
336
945
  crowns: 0
337
946
  },
338
947
  right: {
339
- type: "sea",
948
+ type: "plain",
340
949
  crowns: 0
341
950
  },
342
951
  number: 7
343
952
  },
344
953
  {
345
954
  left: {
346
- type: "sea",
955
+ type: "plain",
347
956
  crowns: 0
348
957
  },
349
958
  right: {
350
- type: "sea",
959
+ type: "plain",
351
960
  crowns: 0
352
961
  },
353
962
  number: 8
354
963
  },
355
964
  {
356
965
  left: {
357
- type: "sea",
966
+ type: "swamp",
358
967
  crowns: 0
359
968
  },
360
969
  right: {
361
- type: "sea",
970
+ type: "swamp",
362
971
  crowns: 0
363
972
  },
364
973
  number: 9
365
974
  },
366
975
  {
367
976
  left: {
368
- type: "plain",
977
+ type: "swamp",
369
978
  crowns: 0
370
979
  },
371
980
  right: {
372
- type: "plain",
981
+ type: "swamp",
373
982
  crowns: 0
374
983
  },
375
984
  number: 10
376
985
  },
377
986
  {
378
987
  left: {
379
- type: "plain",
988
+ type: "mine",
380
989
  crowns: 0
381
990
  },
382
991
  right: {
383
- type: "plain",
992
+ type: "mine",
384
993
  crowns: 0
385
994
  },
386
995
  number: 11
387
996
  },
388
997
  {
389
998
  left: {
390
- type: "swamp",
999
+ type: "wheat",
391
1000
  crowns: 0
392
1001
  },
393
1002
  right: {
394
- type: "swamp",
1003
+ type: "forest",
395
1004
  crowns: 0
396
1005
  },
397
1006
  number: 12
@@ -399,10 +1008,11 @@ var dominoes_default = {
399
1008
  {
400
1009
  left: {
401
1010
  type: "wheat",
402
- crowns: 0
1011
+ crowns: 0,
1012
+ hasConstructionSquare: true
403
1013
  },
404
1014
  right: {
405
- type: "forest",
1015
+ type: "sea",
406
1016
  crowns: 0
407
1017
  },
408
1018
  number: 13
@@ -413,51 +1023,54 @@ var dominoes_default = {
413
1023
  crowns: 0
414
1024
  },
415
1025
  right: {
416
- type: "sea",
417
- crowns: 0
1026
+ type: "plain",
1027
+ crowns: 0,
1028
+ hasConstructionSquare: true
418
1029
  },
419
1030
  number: 14
420
1031
  },
421
1032
  {
422
1033
  left: {
423
- type: "wheat",
424
- crowns: 0
1034
+ type: "forest",
1035
+ crowns: 0,
1036
+ hasConstructionSquare: true
425
1037
  },
426
1038
  right: {
427
- type: "plain",
1039
+ type: "sea",
428
1040
  crowns: 0
429
1041
  },
430
1042
  number: 15
431
1043
  },
432
1044
  {
433
1045
  left: {
434
- type: "wheat",
1046
+ type: "forest",
435
1047
  crowns: 0
436
1048
  },
437
1049
  right: {
438
- type: "swamp",
1050
+ type: "plain",
439
1051
  crowns: 0
440
1052
  },
441
1053
  number: 16
442
1054
  },
443
1055
  {
444
1056
  left: {
445
- type: "forest",
1057
+ type: "sea",
446
1058
  crowns: 0
447
1059
  },
448
1060
  right: {
449
- type: "sea",
450
- crowns: 0
1061
+ type: "plain",
1062
+ crowns: 0,
1063
+ hasConstructionSquare: true
451
1064
  },
452
1065
  number: 17
453
1066
  },
454
1067
  {
455
1068
  left: {
456
- type: "forest",
1069
+ type: "wheat",
457
1070
  crowns: 0
458
1071
  },
459
1072
  right: {
460
- type: "plain",
1073
+ type: "swamp",
461
1074
  crowns: 0
462
1075
  },
463
1076
  number: 18
@@ -465,7 +1078,8 @@ var dominoes_default = {
465
1078
  {
466
1079
  left: {
467
1080
  type: "wheat",
468
- crowns: 1
1081
+ crowns: 1,
1082
+ hasConstructionSquare: true
469
1083
  },
470
1084
  right: {
471
1085
  type: "forest",
@@ -491,28 +1105,30 @@ var dominoes_default = {
491
1105
  },
492
1106
  right: {
493
1107
  type: "plain",
494
- crowns: 0
1108
+ crowns: 0,
1109
+ hasConstructionSquare: true
495
1110
  },
496
1111
  number: 21
497
1112
  },
498
1113
  {
499
1114
  left: {
500
- type: "wheat",
1115
+ type: "forest",
501
1116
  crowns: 1
502
1117
  },
503
1118
  right: {
504
- type: "swamp",
505
- crowns: 0
1119
+ type: "wheat",
1120
+ crowns: 0,
1121
+ hasConstructionSquare: true
506
1122
  },
507
1123
  number: 22
508
1124
  },
509
1125
  {
510
1126
  left: {
511
- type: "wheat",
1127
+ type: "forest",
512
1128
  crowns: 1
513
1129
  },
514
1130
  right: {
515
- type: "mine",
1131
+ type: "sea",
516
1132
  crowns: 0
517
1133
  },
518
1134
  number: 23
@@ -520,17 +1136,18 @@ var dominoes_default = {
520
1136
  {
521
1137
  left: {
522
1138
  type: "forest",
523
- crowns: 1
1139
+ crowns: 1,
1140
+ hasConstructionSquare: true
524
1141
  },
525
1142
  right: {
526
- type: "wheat",
1143
+ type: "plain",
527
1144
  crowns: 0
528
1145
  },
529
1146
  number: 24
530
1147
  },
531
1148
  {
532
1149
  left: {
533
- type: "forest",
1150
+ type: "sea",
534
1151
  crowns: 1
535
1152
  },
536
1153
  right: {
@@ -541,18 +1158,19 @@ var dominoes_default = {
541
1158
  },
542
1159
  {
543
1160
  left: {
544
- type: "forest",
1161
+ type: "sea",
545
1162
  crowns: 1
546
1163
  },
547
1164
  right: {
548
- type: "wheat",
549
- crowns: 0
1165
+ type: "forest",
1166
+ crowns: 0,
1167
+ hasConstructionSquare: true
550
1168
  },
551
1169
  number: 26
552
1170
  },
553
1171
  {
554
1172
  left: {
555
- type: "forest",
1173
+ type: "plain",
556
1174
  crowns: 1
557
1175
  },
558
1176
  right: {
@@ -563,22 +1181,23 @@ var dominoes_default = {
563
1181
  },
564
1182
  {
565
1183
  left: {
566
- type: "forest",
567
- crowns: 1
1184
+ type: "plain",
1185
+ crowns: 1,
1186
+ hasConstructionSquare: true
568
1187
  },
569
1188
  right: {
570
- type: "sea",
1189
+ type: "forest",
571
1190
  crowns: 0
572
1191
  },
573
1192
  number: 28
574
1193
  },
575
1194
  {
576
1195
  left: {
577
- type: "forest",
1196
+ type: "wheat",
578
1197
  crowns: 1
579
1198
  },
580
1199
  right: {
581
- type: "plain",
1200
+ type: "mine",
582
1201
  crowns: 0
583
1202
  },
584
1203
  number: 29
@@ -589,30 +1208,33 @@ var dominoes_default = {
589
1208
  crowns: 1
590
1209
  },
591
1210
  right: {
592
- type: "wheat",
593
- crowns: 0
1211
+ type: "plain",
1212
+ crowns: 0,
1213
+ hasConstructionSquare: true
594
1214
  },
595
1215
  number: 30
596
1216
  },
597
1217
  {
598
1218
  left: {
599
- type: "sea",
600
- crowns: 1
1219
+ type: "wheat",
1220
+ crowns: 1,
1221
+ hasConstructionSquare: true
601
1222
  },
602
1223
  right: {
603
- type: "wheat",
604
- crowns: 0
1224
+ type: "swamp",
1225
+ crowns: 1
605
1226
  },
606
1227
  number: 31
607
1228
  },
608
1229
  {
609
1230
  left: {
610
- type: "sea",
1231
+ type: "forest",
611
1232
  crowns: 1
612
1233
  },
613
1234
  right: {
614
- type: "forest",
615
- crowns: 0
1235
+ type: "sea",
1236
+ crowns: 1,
1237
+ hasConstructionSquare: true
616
1238
  },
617
1239
  number: 32
618
1240
  },
@@ -622,73 +1244,77 @@ var dominoes_default = {
622
1244
  crowns: 1
623
1245
  },
624
1246
  right: {
625
- type: "forest",
626
- crowns: 0
1247
+ type: "plain",
1248
+ crowns: 1
627
1249
  },
628
1250
  number: 33
629
1251
  },
630
1252
  {
631
1253
  left: {
632
- type: "sea",
633
- crowns: 1
1254
+ type: "plain",
1255
+ crowns: 1,
1256
+ hasConstructionSquare: true
634
1257
  },
635
1258
  right: {
636
- type: "forest",
637
- crowns: 0
1259
+ type: "swamp",
1260
+ crowns: 1
638
1261
  },
639
1262
  number: 34
640
1263
  },
641
1264
  {
642
1265
  left: {
643
- type: "sea",
644
- crowns: 1
1266
+ type: "forest",
1267
+ crowns: 1,
1268
+ hasConstructionSquare: true
645
1269
  },
646
1270
  right: {
647
- type: "forest",
648
- crowns: 0
1271
+ type: "mine",
1272
+ crowns: 1
649
1273
  },
650
1274
  number: 35
651
1275
  },
652
1276
  {
653
1277
  left: {
654
1278
  type: "wheat",
655
- crowns: 0
1279
+ crowns: 2,
1280
+ hasConstructionSquare: true
656
1281
  },
657
1282
  right: {
658
- type: "plain",
659
- crowns: 1
1283
+ type: "forest",
1284
+ crowns: 0
660
1285
  },
661
1286
  number: 36
662
1287
  },
663
1288
  {
664
1289
  left: {
665
1290
  type: "sea",
666
- crowns: 0
1291
+ crowns: 2
667
1292
  },
668
1293
  right: {
669
- type: "plain",
670
- crowns: 1
1294
+ type: "wheat",
1295
+ crowns: 0,
1296
+ hasConstructionSquare: true
671
1297
  },
672
1298
  number: 37
673
1299
  },
674
1300
  {
675
1301
  left: {
676
- type: "wheat",
677
- crowns: 0
1302
+ type: "plain",
1303
+ crowns: 2
678
1304
  },
679
1305
  right: {
680
- type: "swamp",
681
- crowns: 1
1306
+ type: "forest",
1307
+ crowns: 0
682
1308
  },
683
1309
  number: 38
684
1310
  },
685
1311
  {
686
1312
  left: {
687
- type: "plain",
688
- crowns: 0
1313
+ type: "swamp",
1314
+ crowns: 2
689
1315
  },
690
1316
  right: {
691
- type: "swamp",
1317
+ type: "wheat",
692
1318
  crowns: 0
693
1319
  },
694
1320
  number: 39
@@ -696,7 +1322,8 @@ var dominoes_default = {
696
1322
  {
697
1323
  left: {
698
1324
  type: "mine",
699
- crowns: 1
1325
+ crowns: 2,
1326
+ hasConstructionSquare: true
700
1327
  },
701
1328
  right: {
702
1329
  type: "wheat",
@@ -707,7 +1334,7 @@ var dominoes_default = {
707
1334
  {
708
1335
  left: {
709
1336
  type: "wheat",
710
- crowns: 0
1337
+ crowns: 2
711
1338
  },
712
1339
  right: {
713
1340
  type: "plain",
@@ -718,73 +1345,75 @@ var dominoes_default = {
718
1345
  {
719
1346
  left: {
720
1347
  type: "sea",
721
- crowns: 0
1348
+ crowns: 2
722
1349
  },
723
1350
  right: {
724
- type: "plain",
725
- crowns: 2
1351
+ type: "forest",
1352
+ crowns: 1,
1353
+ hasConstructionSquare: true
726
1354
  },
727
1355
  number: 42
728
1356
  },
729
1357
  {
730
1358
  left: {
731
- type: "wheat",
732
- crowns: 0
733
- },
734
- right: {
735
1359
  type: "swamp",
736
1360
  crowns: 2
737
1361
  },
1362
+ right: {
1363
+ type: "plain",
1364
+ crowns: 1
1365
+ },
738
1366
  number: 43
739
1367
  },
740
1368
  {
741
1369
  left: {
742
- type: "plain",
743
- crowns: 0
1370
+ type: "mine",
1371
+ crowns: 2
744
1372
  },
745
1373
  right: {
746
1374
  type: "swamp",
747
- crowns: 2
1375
+ crowns: 1
748
1376
  },
749
1377
  number: 44
750
1378
  },
751
1379
  {
752
1380
  left: {
753
- type: "mine",
1381
+ type: "wheat",
754
1382
  crowns: 2
755
1383
  },
756
1384
  right: {
757
- type: "wheat",
758
- crowns: 0
1385
+ type: "mine",
1386
+ crowns: 2
759
1387
  },
760
1388
  number: 45
761
1389
  },
762
1390
  {
763
1391
  left: {
764
- type: "swamp",
765
- crowns: 0
1392
+ type: "forest",
1393
+ crowns: 2
766
1394
  },
767
1395
  right: {
768
1396
  type: "mine",
769
- crowns: 2
1397
+ crowns: 2,
1398
+ hasConstructionSquare: true
770
1399
  },
771
1400
  number: 46
772
1401
  },
773
1402
  {
774
1403
  left: {
775
1404
  type: "swamp",
776
- crowns: 0
1405
+ crowns: 2
777
1406
  },
778
1407
  right: {
779
1408
  type: "mine",
780
- crowns: 2
1409
+ crowns: 3
781
1410
  },
782
1411
  number: 47
783
1412
  },
784
1413
  {
785
1414
  left: {
786
- type: "wheat",
787
- crowns: 0
1415
+ type: "plain",
1416
+ crowns: 2
788
1417
  },
789
1418
  right: {
790
1419
  type: "mine",
@@ -796,20 +1425,24 @@ var dominoes_default = {
796
1425
  };
797
1426
 
798
1427
  // src/adapterServerside/jsonDominoes.ts
1428
+ var mapTile = (raw) => {
1429
+ const tile = {
1430
+ type: raw.type,
1431
+ crowns: raw.crowns
1432
+ };
1433
+ if (raw.hasConstructionSquare) {
1434
+ tile.hasConstructionSquare = true;
1435
+ }
1436
+ return tile;
1437
+ };
799
1438
  var jsonDominoes = () => {
800
1439
  const dominoes = {};
801
1440
  for (const [key, value] of Object.entries(dominoes_default)) {
802
1441
  const currentDominoes = [];
803
1442
  value.forEach((domino) => {
804
1443
  currentDominoes.push({
805
- left: {
806
- type: domino.left.type,
807
- crowns: domino.left.crowns
808
- },
809
- right: {
810
- type: domino.right.type,
811
- crowns: domino.right.crowns
812
- },
1444
+ left: mapTile(domino.left),
1445
+ right: mapTile(domino.right),
813
1446
  number: domino.number
814
1447
  });
815
1448
  });
@@ -828,6 +1461,10 @@ var modes_default = [
828
1461
  {
829
1462
  name: "Classic",
830
1463
  description: "Original KingDomino rules"
1464
+ },
1465
+ {
1466
+ name: "QueenDomino",
1467
+ description: "Queendomino expansion with buildings, knights, coins, the Queen and the Dragon"
831
1468
  }
832
1469
  ];
833
1470
 
@@ -888,23 +1525,35 @@ var rules_default = {
888
1525
  {
889
1526
  name: "The middle Kingdom",
890
1527
  description: "Gain 10 additional points if your castle is in the middle of the kingdom.",
891
- mode: [{ name: "Classic", description: "King Domino classic mode" }]
1528
+ mode: [
1529
+ { name: "Classic", description: "King Domino classic mode" },
1530
+ { name: "QueenDomino", description: "Queendomino expansion with buildings, knights, coins, the Queen and the Dragon" }
1531
+ ]
892
1532
  },
893
1533
  {
894
1534
  name: "Harmony",
895
1535
  description: "Gain 5 additional points if your kingdom is complete (no discarded dominoes).",
896
- mode: [{ name: "Classic", description: "King Domino classic mode" }]
1536
+ mode: [
1537
+ { name: "Classic", description: "King Domino classic mode" },
1538
+ { name: "QueenDomino", description: "Queendomino expansion with buildings, knights, coins, the Queen and the Dragon" }
1539
+ ]
897
1540
  },
898
1541
  {
899
1542
  name: "The Mighty Duel",
900
1543
  description: "Use all 48 dominoes and build a 7x7 kingdom. For 2 players only.",
901
- mode: [{ name: "Classic", description: "King Domino classic mode" }],
1544
+ mode: [
1545
+ { name: "Classic", description: "King Domino classic mode" },
1546
+ { name: "QueenDomino", description: "Queendomino expansion with buildings, knights, coins, the Queen and the Dragon" }
1547
+ ],
902
1548
  playersLimit: 2
903
1549
  },
904
1550
  {
905
1551
  name: "Dynasty",
906
1552
  description: "Play 3 games in a row. The player with the highest total points wins.",
907
- mode: [{ name: "Classic", description: "King Domino classic mode" }]
1553
+ mode: [
1554
+ { name: "Classic", description: "King Domino classic mode" },
1555
+ { name: "QueenDomino", description: "Queendomino expansion with buildings, knights, coins, the Queen and the Dragon" }
1556
+ ]
908
1557
  }
909
1558
  ]
910
1559
  };
@@ -986,7 +1635,17 @@ var ErrorCode = {
986
1635
  DOMINO_ALREADY_PICKED: "DOMINO_ALREADY_PICKED",
987
1636
  // History errors
988
1637
  UNDO_UNAVAILABLE: "UNDO_UNAVAILABLE",
989
- REDO_UNAVAILABLE: "REDO_UNAVAILABLE"
1638
+ REDO_UNAVAILABLE: "REDO_UNAVAILABLE",
1639
+ // Queendomino errors
1640
+ CANNOT_PLACE_KNIGHT: "CANNOT_PLACE_KNIGHT",
1641
+ MAX_KNIGHTS_REACHED: "MAX_KNIGHTS_REACHED",
1642
+ KNIGHT_TERRITORY_OCCUPIED: "KNIGHT_TERRITORY_OCCUPIED",
1643
+ CANNOT_AFFORD_BUILDING: "CANNOT_AFFORD_BUILDING",
1644
+ NO_CONSTRUCTION_SQUARE: "NO_CONSTRUCTION_SQUARE",
1645
+ DRAGON_UNAVAILABLE: "DRAGON_UNAVAILABLE",
1646
+ QUEEN_HOLDER_CANNOT_USE_DRAGON: "QUEEN_HOLDER_CANNOT_USE_DRAGON",
1647
+ BUILDING_NOT_FOUND: "BUILDING_NOT_FOUND",
1648
+ INVALID_OPTIONAL_ACTION: "INVALID_OPTIONAL_ACTION"
990
1649
  };
991
1650
  var DomainException = class extends Error {
992
1651
  code;
@@ -1084,7 +1743,17 @@ var TranslationKey = {
1084
1743
  // Actions
1085
1744
  ACTION_PICK_DOMINO: "action.pickDomino",
1086
1745
  ACTION_PLACE_DOMINO: "action.placeDomino",
1087
- ACTION_PASS: "action.pass"
1746
+ ACTION_PASS: "action.pass",
1747
+ // Queendomino errors
1748
+ ERROR_CANNOT_PLACE_KNIGHT: "error.cannotPlaceKnight",
1749
+ ERROR_MAX_KNIGHTS_REACHED: "error.maxKnightsReached",
1750
+ ERROR_KNIGHT_TERRITORY_OCCUPIED: "error.knightTerritoryOccupied",
1751
+ ERROR_CANNOT_AFFORD_BUILDING: "error.cannotAffordBuilding",
1752
+ ERROR_NO_CONSTRUCTION_SQUARE: "error.noConstructionSquare",
1753
+ ERROR_DRAGON_UNAVAILABLE: "error.dragonUnavailable",
1754
+ ERROR_QUEEN_HOLDER_CANNOT_USE_DRAGON: "error.queenHolderCannotUseDragon",
1755
+ ERROR_BUILDING_NOT_FOUND: "error.buildingNotFound",
1756
+ ERROR_INVALID_OPTIONAL_ACTION: "error.invalidOptionalAction"
1088
1757
  };
1089
1758
  var defaultTranslations = {
1090
1759
  // Error messages
@@ -1130,7 +1799,17 @@ var defaultTranslations = {
1130
1799
  // Actions
1131
1800
  [TranslationKey.ACTION_PICK_DOMINO]: "Pick Domino",
1132
1801
  [TranslationKey.ACTION_PLACE_DOMINO]: "Place Domino",
1133
- [TranslationKey.ACTION_PASS]: "Pass"
1802
+ [TranslationKey.ACTION_PASS]: "Pass",
1803
+ // Queendomino errors
1804
+ [TranslationKey.ERROR_CANNOT_PLACE_KNIGHT]: "Cannot place knight here",
1805
+ [TranslationKey.ERROR_MAX_KNIGHTS_REACHED]: "Maximum number of knights reached (3)",
1806
+ [TranslationKey.ERROR_KNIGHT_TERRITORY_OCCUPIED]: "This territory already has a knight",
1807
+ [TranslationKey.ERROR_CANNOT_AFFORD_BUILDING]: "Not enough coins to purchase this building",
1808
+ [TranslationKey.ERROR_NO_CONSTRUCTION_SQUARE]: "No open construction square available",
1809
+ [TranslationKey.ERROR_DRAGON_UNAVAILABLE]: "The Dragon is not available this round",
1810
+ [TranslationKey.ERROR_QUEEN_HOLDER_CANNOT_USE_DRAGON]: "The Queen holder cannot use the Dragon",
1811
+ [TranslationKey.ERROR_BUILDING_NOT_FOUND]: "Building not found on the Builders Board",
1812
+ [TranslationKey.ERROR_INVALID_OPTIONAL_ACTION]: "Invalid optional action for this game state"
1134
1813
  };
1135
1814
  var errorCodeToTranslationKey = {
1136
1815
  [ErrorCode.INVALID_STEP]: TranslationKey.ERROR_INVALID_STEP,
@@ -1153,7 +1832,16 @@ var errorCodeToTranslationKey = {
1153
1832
  [ErrorCode.CANNOT_PLACE]: TranslationKey.ERROR_CANNOT_PLACE,
1154
1833
  [ErrorCode.DOMINO_ALREADY_PICKED]: TranslationKey.ERROR_DOMINO_ALREADY_PICKED,
1155
1834
  [ErrorCode.UNDO_UNAVAILABLE]: TranslationKey.ERROR_UNDO_UNAVAILABLE,
1156
- [ErrorCode.REDO_UNAVAILABLE]: TranslationKey.ERROR_REDO_UNAVAILABLE
1835
+ [ErrorCode.REDO_UNAVAILABLE]: TranslationKey.ERROR_REDO_UNAVAILABLE,
1836
+ [ErrorCode.CANNOT_PLACE_KNIGHT]: TranslationKey.ERROR_CANNOT_PLACE_KNIGHT,
1837
+ [ErrorCode.MAX_KNIGHTS_REACHED]: TranslationKey.ERROR_MAX_KNIGHTS_REACHED,
1838
+ [ErrorCode.KNIGHT_TERRITORY_OCCUPIED]: TranslationKey.ERROR_KNIGHT_TERRITORY_OCCUPIED,
1839
+ [ErrorCode.CANNOT_AFFORD_BUILDING]: TranslationKey.ERROR_CANNOT_AFFORD_BUILDING,
1840
+ [ErrorCode.NO_CONSTRUCTION_SQUARE]: TranslationKey.ERROR_NO_CONSTRUCTION_SQUARE,
1841
+ [ErrorCode.DRAGON_UNAVAILABLE]: TranslationKey.ERROR_DRAGON_UNAVAILABLE,
1842
+ [ErrorCode.QUEEN_HOLDER_CANNOT_USE_DRAGON]: TranslationKey.ERROR_QUEEN_HOLDER_CANNOT_USE_DRAGON,
1843
+ [ErrorCode.BUILDING_NOT_FOUND]: TranslationKey.ERROR_BUILDING_NOT_FOUND,
1844
+ [ErrorCode.INVALID_OPTIONAL_ACTION]: TranslationKey.ERROR_INVALID_OPTIONAL_ACTION
1157
1845
  };
1158
1846
  var translateErrorCode = (translator, code, params) => {
1159
1847
  const key = errorCodeToTranslationKey[code];
@@ -1632,47 +2320,191 @@ var deserializeGameHandler = (logger, translator) => {
1632
2320
  };
1633
2321
  };
1634
2322
 
1635
- // src/application/handlers/startGameHandler.ts
1636
- var startGameHandler = (logger, translator, useCase) => (command) => {
1637
- const { game } = command;
1638
- logger.info(`Starting game: ${game.id}`);
1639
- if (!isGameWithNextStep(game)) {
2323
+ // src/application/handlers/startGameHandler.ts
2324
+ var startGameHandler = (logger, translator, useCase) => (command) => {
2325
+ const { game } = command;
2326
+ logger.info(`Starting game: ${game.id}`);
2327
+ if (!isGameWithNextStep(game)) {
2328
+ logger.error(
2329
+ `Invalid game, required nextAction type: 'step' but got: ${game.nextAction.type}`
2330
+ );
2331
+ throw new InvalidStepError(
2332
+ translateErrorCode(translator, ErrorCode.INVALID_STEP),
2333
+ { expected: "step", actual: game.nextAction.type, gameId: game.id }
2334
+ );
2335
+ }
2336
+ if (game.nextAction.step !== "start" && game.nextAction.step !== "options") {
2337
+ logger.error(
2338
+ `Required game with start step or options step but got: ${game.nextAction.step}`
2339
+ );
2340
+ throw new InvalidStepError(
2341
+ translateErrorCode(translator, ErrorCode.INVALID_STEP),
2342
+ {
2343
+ expected: "start|options",
2344
+ actual: game.nextAction.step,
2345
+ gameId: game.id
2346
+ }
2347
+ );
2348
+ }
2349
+ const result = useCase(game);
2350
+ if (isErr(result)) {
2351
+ logger.error(`Error starting game: ${result.error}`);
2352
+ const code = result.error;
2353
+ throw new StepExecutionError(translateErrorCode(translator, code), code, {
2354
+ gameId: game.id
2355
+ });
2356
+ }
2357
+ logger.info(`Game started: ${game.id}`);
2358
+ return result.value;
2359
+ };
2360
+
2361
+ // src/application/handlers/placeKnightHandler.ts
2362
+ var placeKnightHandler = (logger, translator, useCase) => (command) => {
2363
+ const { game, lordId, position } = command;
2364
+ logger.info(
2365
+ `Placing knight for lord: ${lordId} at position: ${JSON.stringify(
2366
+ position
2367
+ )} in game: ${game.id}`
2368
+ );
2369
+ if (game.nextAction.nextAction !== "placeKnight") {
2370
+ logger.error(
2371
+ `Required game with placeKnight action but got: ${game.nextAction.nextAction}`
2372
+ );
2373
+ throw new InvalidStepError(
2374
+ translateErrorCode(translator, ErrorCode.INVALID_STEP),
2375
+ {
2376
+ expected: "placeKnight",
2377
+ actual: game.nextAction.nextAction,
2378
+ gameId: game.id
2379
+ }
2380
+ );
2381
+ }
2382
+ const result = useCase(game, lordId, position);
2383
+ if (isErr(result)) {
2384
+ logger.error(`Error placing knight: ${result.error}`);
2385
+ const code = result.error;
2386
+ throw new ActionExecutionError(
2387
+ translateErrorCode(translator, code),
2388
+ code,
2389
+ {
2390
+ gameId: game.id,
2391
+ lordId: command.lordId,
2392
+ position: command.position
2393
+ }
2394
+ );
2395
+ }
2396
+ logger.info(
2397
+ `Knight placed for lord: ${lordId} at position: ${JSON.stringify(
2398
+ position
2399
+ )} in game: ${game.id}`
2400
+ );
2401
+ return result.value;
2402
+ };
2403
+
2404
+ // src/application/handlers/constructBuildingHandler.ts
2405
+ var constructBuildingHandler = (logger, translator, useCase) => (command) => {
2406
+ const { game, lordId, buildingId, position } = command;
2407
+ logger.info(
2408
+ `Constructing building: ${buildingId} for lord: ${lordId} at position: ${JSON.stringify(
2409
+ position
2410
+ )} in game: ${game.id}`
2411
+ );
2412
+ if (game.nextAction.nextAction !== "constructBuilding") {
1640
2413
  logger.error(
1641
- `Invalid game, required nextAction type: 'step' but got: ${game.nextAction.type}`
2414
+ `Required game with constructBuilding action but got: ${game.nextAction.nextAction}`
1642
2415
  );
1643
2416
  throw new InvalidStepError(
1644
2417
  translateErrorCode(translator, ErrorCode.INVALID_STEP),
1645
- { expected: "step", actual: game.nextAction.type, gameId: game.id }
2418
+ {
2419
+ expected: "constructBuilding",
2420
+ actual: game.nextAction.nextAction,
2421
+ gameId: game.id
2422
+ }
1646
2423
  );
1647
2424
  }
1648
- if (game.nextAction.step !== "start" && game.nextAction.step !== "options") {
2425
+ const result = useCase(game, lordId, buildingId, position);
2426
+ if (isErr(result)) {
2427
+ logger.error(`Error constructing building: ${result.error}`);
2428
+ const code = result.error;
2429
+ throw new ActionExecutionError(
2430
+ translateErrorCode(translator, code),
2431
+ code,
2432
+ {
2433
+ gameId: game.id,
2434
+ lordId: command.lordId,
2435
+ buildingId: command.buildingId,
2436
+ position: command.position
2437
+ }
2438
+ );
2439
+ }
2440
+ logger.info(
2441
+ `Building constructed: ${buildingId} for lord: ${lordId} at position: ${JSON.stringify(
2442
+ position
2443
+ )} in game: ${game.id}`
2444
+ );
2445
+ return result.value;
2446
+ };
2447
+
2448
+ // src/application/handlers/useDragonHandler.ts
2449
+ var useDragonHandler = (logger, translator, useCase) => (command) => {
2450
+ const { game, lordId, buildingId } = command;
2451
+ logger.info(
2452
+ `Using dragon on building: ${buildingId} for lord: ${lordId} in game: ${game.id}`
2453
+ );
2454
+ if (game.nextAction.nextAction !== "useDragon") {
1649
2455
  logger.error(
1650
- `Required game with start step or options step but got: ${game.nextAction.step}`
2456
+ `Required game with useDragon action but got: ${game.nextAction.nextAction}`
1651
2457
  );
1652
2458
  throw new InvalidStepError(
1653
2459
  translateErrorCode(translator, ErrorCode.INVALID_STEP),
1654
2460
  {
1655
- expected: "start|options",
1656
- actual: game.nextAction.step,
2461
+ expected: "useDragon",
2462
+ actual: game.nextAction.nextAction,
1657
2463
  gameId: game.id
1658
2464
  }
1659
2465
  );
1660
2466
  }
1661
- const result = useCase(game);
2467
+ const result = useCase(game, lordId, buildingId);
1662
2468
  if (isErr(result)) {
1663
- logger.error(`Error starting game: ${result.error}`);
2469
+ logger.error(`Error using dragon: ${result.error}`);
1664
2470
  const code = result.error;
1665
- throw new StepExecutionError(translateErrorCode(translator, code), code, {
1666
- gameId: game.id
1667
- });
2471
+ throw new ActionExecutionError(
2472
+ translateErrorCode(translator, code),
2473
+ code,
2474
+ {
2475
+ gameId: game.id,
2476
+ lordId: command.lordId,
2477
+ buildingId: command.buildingId
2478
+ }
2479
+ );
1668
2480
  }
1669
- logger.info(`Game started: ${game.id}`);
2481
+ logger.info(
2482
+ `Dragon used on building: ${buildingId} for lord: ${lordId} in game: ${game.id}`
2483
+ );
1670
2484
  return result.value;
1671
2485
  };
1672
2486
 
1673
- // src/core/domain/types/kingdom.ts
1674
- var GRIDSIZE = 9;
1675
- var MAX_KINGDOM_SIZE = 5;
2487
+ // src/application/handlers/skipOptionalActionHandler.ts
2488
+ var skipOptionalActionHandler = (logger, translator, useCase) => (command) => {
2489
+ const { game, lordId } = command;
2490
+ logger.info(
2491
+ `Skipping optional action for lord: ${lordId} in game: ${game.id}`
2492
+ );
2493
+ const result = useCase(game, lordId);
2494
+ if (isErr(result)) {
2495
+ logger.error(`Error skipping optional action: ${result.error}`);
2496
+ const code = result.error;
2497
+ throw new ActionExecutionError(
2498
+ translateErrorCode(translator, code),
2499
+ code,
2500
+ { gameId: game.id, lordId: command.lordId }
2501
+ );
2502
+ }
2503
+ logger.info(
2504
+ `Optional action skipped for lord: ${lordId} in game: ${game.id}`
2505
+ );
2506
+ return result.value;
2507
+ };
1676
2508
 
1677
2509
  // src/core/domain/types/domino.ts
1678
2510
  var GROUND = [
@@ -1685,6 +2517,10 @@ var GROUND = [
1685
2517
  "mine"
1686
2518
  ];
1687
2519
 
2520
+ // src/core/domain/types/kingdom.ts
2521
+ var GRIDSIZE = 9;
2522
+ var MAX_KINGDOM_SIZE = 5;
2523
+
1688
2524
  // src/core/domain/types/player.ts
1689
2525
  var playerActions = {
1690
2526
  /** Place a previously picked domino on the kingdom */
@@ -1692,7 +2528,15 @@ var playerActions = {
1692
2528
  /** Pick a domino from the revealed set */
1693
2529
  pickDomino: "pickDomino",
1694
2530
  /** Pass/discard when no valid placement exists */
1695
- pass: "pass"
2531
+ pass: "pass",
2532
+ /** Place a knight on the just-placed domino (Queendomino, optional) */
2533
+ placeKnight: "placeKnight",
2534
+ /** Construct a building on a construction square (Queendomino, optional) */
2535
+ constructBuilding: "constructBuilding",
2536
+ /** Use the Dragon to burn a building tile (Queendomino, optional) */
2537
+ useDragon: "useDragon",
2538
+ /** Skip the current optional action (Queendomino) */
2539
+ skipOptionalAction: "skipOptionalAction"
1696
2540
  };
1697
2541
 
1698
2542
  // src/core/domain/entities/rule.ts
@@ -1790,6 +2634,24 @@ var addExtraRulesUseCase = (deps) => (game, rules) => {
1790
2634
  return ok(updatedGame);
1791
2635
  };
1792
2636
 
2637
+ // src/core/domain/entities/economy.ts
2638
+ var STARTING_COINS = 7;
2639
+ var MAX_KNIGHTS = 3;
2640
+ var addCoins = (player, amount) => ({
2641
+ ...player,
2642
+ coins: (player.coins ?? 0) + amount
2643
+ });
2644
+ var removeCoins = (player, amount) => ({
2645
+ ...player,
2646
+ coins: (player.coins ?? 0) - amount
2647
+ });
2648
+ var canAfford = (player, cost) => (player.coins ?? 0) >= cost;
2649
+ var addTowers = (player, amount) => ({
2650
+ ...player,
2651
+ towers: (player.towers ?? 0) + amount
2652
+ });
2653
+ var getTowerCount = (player) => player.towers ?? 0;
2654
+
1793
2655
  // src/core/domain/entities/domino.ts
1794
2656
  var isGround = (ground) => {
1795
2657
  return GROUND.includes(ground);
@@ -2085,6 +2947,12 @@ var addPlayersUseCase = (deps) => (game, players) => {
2085
2947
  if (isErr(newPlayer)) {
2086
2948
  return newPlayer;
2087
2949
  }
2950
+ if (game.mode.name === "QueenDomino") {
2951
+ newPlayer.value.coins = STARTING_COINS;
2952
+ newPlayer.value.towers = 0;
2953
+ newPlayer.value.knights = [];
2954
+ newPlayer.value.buildings = [];
2955
+ }
2088
2956
  newPlayers.push(newPlayer.value);
2089
2957
  }
2090
2958
  const rules = ruleRepository.getAll();
@@ -2231,6 +3099,19 @@ var findNextLord = (lords) => {
2231
3099
  var allLordsHavePlayed = (lords) => {
2232
3100
  return lords.every((lord) => lord.turnEnded);
2233
3101
  };
3102
+ var QUEENDOMINO_ACTION_SEQUENCE = [
3103
+ playerActions.placeKnight,
3104
+ playerActions.constructBuilding,
3105
+ playerActions.useDragon,
3106
+ playerActions.pickDomino
3107
+ ];
3108
+ var nextQueenDominoAction = (currentAction) => {
3109
+ const index = QUEENDOMINO_ACTION_SEQUENCE.indexOf(currentAction);
3110
+ if (index === -1 || index >= QUEENDOMINO_ACTION_SEQUENCE.length - 1) {
3111
+ return playerActions.pickDomino;
3112
+ }
3113
+ return QUEENDOMINO_ACTION_SEQUENCE[index + 1];
3114
+ };
2234
3115
 
2235
3116
  // src/core/useCases/chooseDomino.ts
2236
3117
  var chooseDominoUseCase = (game, lordId, dominoPick) => {
@@ -2301,7 +3182,19 @@ var chooseDominoUseCase = (game, lordId, dominoPick) => {
2301
3182
 
2302
3183
  // src/core/domain/entities/game.ts
2303
3184
  var create = (payload) => {
2304
- const { id, mode, dominoes, seed } = payload;
3185
+ const { id, mode, dominoes, seed, buildings } = payload;
3186
+ let queendomino;
3187
+ if (mode.name === "QueenDomino" && buildings) {
3188
+ queendomino = {
3189
+ buildersBoard: {
3190
+ slots: [],
3191
+ drawPile: buildings
3192
+ },
3193
+ queenHolderId: null,
3194
+ dragonAvailable: true,
3195
+ dragonUsedThisRound: false
3196
+ };
3197
+ }
2305
3198
  return {
2306
3199
  id,
2307
3200
  dominoes,
@@ -2324,7 +3217,8 @@ var create = (payload) => {
2324
3217
  extra: []
2325
3218
  },
2326
3219
  mode,
2327
- ...seed !== void 0 && { seed }
3220
+ ...seed !== void 0 && { seed },
3221
+ ...queendomino !== void 0 && { queendomino }
2328
3222
  };
2329
3223
  };
2330
3224
 
@@ -2342,7 +3236,7 @@ var createMode = (mode, availableMode) => {
2342
3236
 
2343
3237
  // src/core/useCases/createGame.ts
2344
3238
  var createGameUseCase = (deps) => (mode, seed) => {
2345
- const { modeRepository, dominoesRepository, uuidMethod: uuidMethod3 } = deps;
3239
+ const { modeRepository, dominoesRepository, uuidMethod: uuidMethod3, buildingsRepository } = deps;
2346
3240
  const id = uuidMethod3();
2347
3241
  const gameSeed = seed ?? uuidMethod3();
2348
3242
  const availableMode = modeRepository.getAvailables();
@@ -2354,11 +3248,17 @@ var createGameUseCase = (deps) => (mode, seed) => {
2354
3248
  if (!dominoes || dominoes.length === 0) {
2355
3249
  return err(ErrorCode.DOMINO_NOT_FOUND);
2356
3250
  }
3251
+ const isQueenDomino = newMode.value.name === "QueenDomino";
3252
+ let buildings;
3253
+ if (isQueenDomino && buildingsRepository) {
3254
+ buildings = buildingsRepository.getAll();
3255
+ }
2357
3256
  const payload = {
2358
3257
  id,
2359
3258
  mode: newMode.value,
2360
3259
  dominoes,
2361
- seed: gameSeed
3260
+ seed: gameSeed,
3261
+ buildings
2362
3262
  };
2363
3263
  const newGame = create(payload);
2364
3264
  return ok(newGame);
@@ -2651,6 +3551,7 @@ var placeDominoUseCase = (game, lordId, position, rotation) => {
2651
3551
  type: "step",
2652
3552
  step: gameSteps.result
2653
3553
  };
3554
+ const isQueenDomino = game.mode.name === "QueenDomino";
2654
3555
  if (isLastTurn && allLordsHavePlayed(updatedLords)) {
2655
3556
  updatedGame = {
2656
3557
  ...game,
@@ -2658,6 +3559,29 @@ var placeDominoUseCase = (game, lordId, position, rotation) => {
2658
3559
  nextAction: resultStep,
2659
3560
  players: updatedPlayers
2660
3561
  };
3562
+ } else if (isQueenDomino && !isLastTurn) {
3563
+ updatedGame = {
3564
+ ...game,
3565
+ lords: updatedLords,
3566
+ nextAction: {
3567
+ type: "action",
3568
+ nextLord: currentLord.id,
3569
+ nextAction: playerActions.placeKnight
3570
+ },
3571
+ players: updatedPlayers
3572
+ };
3573
+ } else if (isQueenDomino && isLastTurn) {
3574
+ const queenDominoAction = {
3575
+ type: "action",
3576
+ nextLord: currentLord.id,
3577
+ nextAction: playerActions.placeKnight
3578
+ };
3579
+ updatedGame = {
3580
+ ...game,
3581
+ lords: updatedLords,
3582
+ nextAction: queenDominoAction,
3583
+ players: updatedPlayers
3584
+ };
2661
3585
  } else {
2662
3586
  updatedGame = {
2663
3587
  ...game,
@@ -2669,6 +3593,401 @@ var placeDominoUseCase = (game, lordId, position, rotation) => {
2669
3593
  return ok(updatedGame);
2670
3594
  };
2671
3595
 
3596
+ // src/core/domain/entities/knight.ts
3597
+ var countConstructionSquaresInTerritory = (kingdom, position) => {
3598
+ const rows = kingdom.length;
3599
+ const cols = kingdom[0]?.length ?? 0;
3600
+ const startTile = kingdom[position.y]?.[position.x];
3601
+ if (!startTile || startTile.type === "empty" || startTile.type === "castle") {
3602
+ return 0;
3603
+ }
3604
+ const terrainType = startTile.type;
3605
+ const visited = kingdom.map((row) => row.map(() => false));
3606
+ const queue = [[position.x, position.y]];
3607
+ visited[position.y][position.x] = true;
3608
+ let count = 0;
3609
+ const directions = [
3610
+ [-1, 0],
3611
+ [1, 0],
3612
+ [0, -1],
3613
+ [0, 1]
3614
+ ];
3615
+ while (queue.length > 0) {
3616
+ const [cx, cy] = queue.pop();
3617
+ const tile = kingdom[cy][cx];
3618
+ if (tile.type !== "empty" && tile.type !== "castle" && "hasConstructionSquare" in tile && tile.hasConstructionSquare) {
3619
+ count++;
3620
+ }
3621
+ for (const [dx, dy] of directions) {
3622
+ const nx = cx + dx;
3623
+ const ny = cy + dy;
3624
+ if (nx >= 0 && ny >= 0 && nx < cols && ny < rows && !visited[ny][nx] && kingdom[ny][nx].type === terrainType) {
3625
+ visited[ny][nx] = true;
3626
+ queue.push([nx, ny]);
3627
+ }
3628
+ }
3629
+ }
3630
+ return count;
3631
+ };
3632
+ var getTerritoryTerrain = (kingdom, position) => {
3633
+ const tile = kingdom[position.y]?.[position.x];
3634
+ if (!tile || tile.type === "empty" || tile.type === "castle") return null;
3635
+ return tile.type;
3636
+ };
3637
+ var territoryHasKnight = (kingdom, position, knights) => {
3638
+ const terrain = getTerritoryTerrain(kingdom, position);
3639
+ if (!terrain) return false;
3640
+ const rows = kingdom.length;
3641
+ const cols = kingdom[0]?.length ?? 0;
3642
+ const visited = kingdom.map((row) => row.map(() => false));
3643
+ const queue = [[position.x, position.y]];
3644
+ visited[position.y][position.x] = true;
3645
+ const territoryPositions = /* @__PURE__ */ new Set();
3646
+ const directions = [
3647
+ [-1, 0],
3648
+ [1, 0],
3649
+ [0, -1],
3650
+ [0, 1]
3651
+ ];
3652
+ while (queue.length > 0) {
3653
+ const [cx, cy] = queue.pop();
3654
+ territoryPositions.add(`${cx},${cy}`);
3655
+ for (const [dx, dy] of directions) {
3656
+ const nx = cx + dx;
3657
+ const ny = cy + dy;
3658
+ if (nx >= 0 && ny >= 0 && nx < cols && ny < rows && !visited[ny][nx] && kingdom[ny][nx].type === terrain) {
3659
+ visited[ny][nx] = true;
3660
+ queue.push([nx, ny]);
3661
+ }
3662
+ }
3663
+ }
3664
+ return knights.some(
3665
+ (k) => territoryPositions.has(`${k.position.x},${k.position.y}`)
3666
+ );
3667
+ };
3668
+ var canPlaceKnight = (player, kingdom, position) => {
3669
+ const knights = player.knights ?? [];
3670
+ if (knights.length >= MAX_KNIGHTS) return false;
3671
+ const tile = kingdom[position.y]?.[position.x];
3672
+ if (!tile || tile.type === "empty" || tile.type === "castle") return false;
3673
+ if (territoryHasKnight(kingdom, position, knights)) return false;
3674
+ return true;
3675
+ };
3676
+ var placeKnight = (player, kingdom, position) => {
3677
+ const knight = { playerId: player.id, position };
3678
+ const knights = [...player.knights ?? [], knight];
3679
+ const taxAmount = countConstructionSquaresInTerritory(kingdom, position);
3680
+ const updatedPlayer = addCoins({ ...player, knights }, taxAmount);
3681
+ return updatedPlayer;
3682
+ };
3683
+
3684
+ // src/core/useCases/placeKnight.ts
3685
+ var placeKnightUseCase = (game, lordId, position) => {
3686
+ const currentAction = game.nextAction;
3687
+ if (currentAction.nextLord !== lordId) {
3688
+ return err(ErrorCode.NOT_YOUR_TURN);
3689
+ }
3690
+ if (currentAction.nextAction !== playerActions.placeKnight) {
3691
+ return err(ErrorCode.INVALID_OPTIONAL_ACTION);
3692
+ }
3693
+ const currentLord = game.lords.find((l) => l.id === lordId);
3694
+ if (!currentLord) return err(ErrorCode.LORD_NOT_FOUND);
3695
+ const currentPlayer = game.players.find(
3696
+ (p) => p.id === currentLord.playerId
3697
+ );
3698
+ if (!currentPlayer) return err(ErrorCode.PLAYER_NOT_FOUND);
3699
+ if (!canPlaceKnight(currentPlayer, currentPlayer.kingdom, position)) {
3700
+ return err(ErrorCode.CANNOT_PLACE_KNIGHT);
3701
+ }
3702
+ const updatedPlayer = placeKnight(
3703
+ currentPlayer,
3704
+ currentPlayer.kingdom,
3705
+ position
3706
+ );
3707
+ const updatedPlayers = game.players.map(
3708
+ (p) => p.id === currentPlayer.id ? updatedPlayer : p
3709
+ );
3710
+ const nextAction = nextQueenDominoAction(playerActions.placeKnight);
3711
+ return ok({
3712
+ ...game,
3713
+ players: updatedPlayers,
3714
+ nextAction: {
3715
+ type: "action",
3716
+ nextLord: lordId,
3717
+ nextAction
3718
+ }
3719
+ });
3720
+ };
3721
+
3722
+ // src/core/domain/entities/building.ts
3723
+ var BOARD_SLOTS = 4;
3724
+ var createBuildersBoard = (tiles, shuffle) => {
3725
+ const shuffled = shuffle([...tiles]);
3726
+ const slots = shuffled.slice(0, BOARD_SLOTS);
3727
+ const drawPile = shuffled.slice(BOARD_SLOTS);
3728
+ return {
3729
+ slots,
3730
+ drawPile
3731
+ };
3732
+ };
3733
+ var findBuildingOnBoard = (board, buildingId) => {
3734
+ for (let i = 0; i < board.slots.length; i++) {
3735
+ const slot = board.slots[i];
3736
+ if (slot && slot.id === buildingId) {
3737
+ return { building: slot, slotIndex: i };
3738
+ }
3739
+ }
3740
+ return null;
3741
+ };
3742
+ var removeBuildingFromBoard = (board, slotIndex) => {
3743
+ const newSlots = [...board.slots];
3744
+ newSlots[slotIndex] = null;
3745
+ return { ...board, slots: newSlots };
3746
+ };
3747
+ var purchaseBuilding = (board, player, buildingId) => {
3748
+ const found = findBuildingOnBoard(board, buildingId);
3749
+ if (!found) return null;
3750
+ const { building, slotIndex } = found;
3751
+ if (!canAfford(player, building.cost)) return null;
3752
+ let updatedPlayer = removeCoins(player, building.cost);
3753
+ if (building.immediateBonus) {
3754
+ switch (building.immediateBonus.type) {
3755
+ case "coins":
3756
+ updatedPlayer = addCoins(updatedPlayer, building.immediateBonus.amount);
3757
+ break;
3758
+ case "tower":
3759
+ updatedPlayer = addTowers(
3760
+ updatedPlayer,
3761
+ building.immediateBonus.amount
3762
+ );
3763
+ break;
3764
+ }
3765
+ }
3766
+ if (building.towers > 0) {
3767
+ updatedPlayer = addTowers(updatedPlayer, building.towers);
3768
+ }
3769
+ const updatedBoard = removeBuildingFromBoard(board, slotIndex);
3770
+ return { updatedBoard, updatedPlayer, building };
3771
+ };
3772
+ var isValidConstructionPosition = (kingdom, placedBuildings, position) => {
3773
+ const tile = kingdom[position.y]?.[position.x];
3774
+ if (!tile || tile.type === "empty" || tile.type === "castle") return false;
3775
+ if (!("hasConstructionSquare" in tile) || !tile.hasConstructionSquare)
3776
+ return false;
3777
+ const occupied = placedBuildings.some(
3778
+ (b) => b.position.x === position.x && b.position.y === position.y
3779
+ );
3780
+ return !occupied;
3781
+ };
3782
+ var placeBuildingOnKingdom = (kingdom, building, position) => {
3783
+ const newKingdom = kingdom.map((row) => [...row]);
3784
+ const tile = newKingdom[position.y][position.x];
3785
+ if (tile.type !== "empty" && tile.type !== "castle") {
3786
+ newKingdom[position.y][position.x] = {
3787
+ ...tile,
3788
+ crowns: tile.crowns + building.crowns
3789
+ };
3790
+ }
3791
+ return newKingdom;
3792
+ };
3793
+ var destroyWithDragon = (board, buildingId, player) => {
3794
+ const found = findBuildingOnBoard(board, buildingId);
3795
+ if (!found) return null;
3796
+ const { building, slotIndex } = found;
3797
+ if (!canAfford(player, building.cost)) return null;
3798
+ const updatedPlayer = removeCoins(player, building.cost);
3799
+ const updatedBoard = removeBuildingFromBoard(board, slotIndex);
3800
+ return { updatedBoard, updatedPlayer };
3801
+ };
3802
+
3803
+ // src/core/domain/entities/queen.ts
3804
+ var determineQueenHolder = (players, currentHolderId) => {
3805
+ let maxTowers = 0;
3806
+ let leaderId = null;
3807
+ let isTied = false;
3808
+ for (const player of players) {
3809
+ const towers = getTowerCount(player);
3810
+ if (towers > maxTowers) {
3811
+ maxTowers = towers;
3812
+ leaderId = player.id;
3813
+ isTied = false;
3814
+ } else if (towers === maxTowers && towers > 0 && leaderId !== null) {
3815
+ isTied = true;
3816
+ }
3817
+ }
3818
+ if (isTied || maxTowers === 0) {
3819
+ return currentHolderId;
3820
+ }
3821
+ return leaderId;
3822
+ };
3823
+
3824
+ // src/core/useCases/constructBuilding.ts
3825
+ var constructBuildingUseCase = (game, lordId, buildingId, position) => {
3826
+ const currentAction = game.nextAction;
3827
+ if (currentAction.nextLord !== lordId) {
3828
+ return err(ErrorCode.NOT_YOUR_TURN);
3829
+ }
3830
+ if (currentAction.nextAction !== playerActions.constructBuilding) {
3831
+ return err(ErrorCode.INVALID_OPTIONAL_ACTION);
3832
+ }
3833
+ if (!game.queendomino) {
3834
+ return err(ErrorCode.INVALID_OPTIONAL_ACTION);
3835
+ }
3836
+ const currentLord = game.lords.find((l) => l.id === lordId);
3837
+ if (!currentLord) return err(ErrorCode.LORD_NOT_FOUND);
3838
+ const currentPlayer = game.players.find(
3839
+ (p) => p.id === currentLord.playerId
3840
+ );
3841
+ if (!currentPlayer) return err(ErrorCode.PLAYER_NOT_FOUND);
3842
+ if (!isValidConstructionPosition(
3843
+ currentPlayer.kingdom,
3844
+ currentPlayer.buildings ?? [],
3845
+ position
3846
+ )) {
3847
+ return err(ErrorCode.NO_CONSTRUCTION_SQUARE);
3848
+ }
3849
+ const purchaseResult = purchaseBuilding(
3850
+ game.queendomino.buildersBoard,
3851
+ currentPlayer,
3852
+ buildingId
3853
+ );
3854
+ if (!purchaseResult) {
3855
+ return err(ErrorCode.CANNOT_AFFORD_BUILDING);
3856
+ }
3857
+ const { updatedBoard, updatedPlayer, building } = purchaseResult;
3858
+ const updatedKingdom = placeBuildingOnKingdom(
3859
+ updatedPlayer.kingdom,
3860
+ building,
3861
+ position
3862
+ );
3863
+ const placedBuilding = { building, position };
3864
+ const finalPlayer = {
3865
+ ...updatedPlayer,
3866
+ kingdom: updatedKingdom,
3867
+ buildings: [...updatedPlayer.buildings ?? [], placedBuilding]
3868
+ };
3869
+ const updatedPlayers = game.players.map(
3870
+ (p) => p.id === currentPlayer.id ? finalPlayer : p
3871
+ );
3872
+ const newQueenHolder = determineQueenHolder(
3873
+ updatedPlayers,
3874
+ game.queendomino.queenHolderId
3875
+ );
3876
+ const nextAction = nextQueenDominoAction(playerActions.constructBuilding);
3877
+ return ok({
3878
+ ...game,
3879
+ players: updatedPlayers,
3880
+ queendomino: {
3881
+ ...game.queendomino,
3882
+ buildersBoard: updatedBoard,
3883
+ queenHolderId: newQueenHolder
3884
+ },
3885
+ nextAction: {
3886
+ type: "action",
3887
+ nextLord: lordId,
3888
+ nextAction
3889
+ }
3890
+ });
3891
+ };
3892
+
3893
+ // src/core/useCases/useDragon.ts
3894
+ var useDragonUseCase = (game, lordId, buildingId) => {
3895
+ const currentAction = game.nextAction;
3896
+ if (currentAction.nextLord !== lordId) {
3897
+ return err(ErrorCode.NOT_YOUR_TURN);
3898
+ }
3899
+ if (currentAction.nextAction !== playerActions.useDragon) {
3900
+ return err(ErrorCode.INVALID_OPTIONAL_ACTION);
3901
+ }
3902
+ if (!game.queendomino) {
3903
+ return err(ErrorCode.INVALID_OPTIONAL_ACTION);
3904
+ }
3905
+ if (!game.queendomino.dragonAvailable || game.queendomino.dragonUsedThisRound) {
3906
+ return err(ErrorCode.DRAGON_UNAVAILABLE);
3907
+ }
3908
+ const currentLord = game.lords.find((l) => l.id === lordId);
3909
+ if (!currentLord) return err(ErrorCode.LORD_NOT_FOUND);
3910
+ const currentPlayer = game.players.find(
3911
+ (p) => p.id === currentLord.playerId
3912
+ );
3913
+ if (!currentPlayer) return err(ErrorCode.PLAYER_NOT_FOUND);
3914
+ if (game.queendomino.queenHolderId === currentPlayer.id) {
3915
+ return err(ErrorCode.QUEEN_HOLDER_CANNOT_USE_DRAGON);
3916
+ }
3917
+ const result = destroyWithDragon(
3918
+ game.queendomino.buildersBoard,
3919
+ buildingId,
3920
+ currentPlayer
3921
+ );
3922
+ if (!result) {
3923
+ return err(ErrorCode.BUILDING_NOT_FOUND);
3924
+ }
3925
+ const { updatedBoard, updatedPlayer } = result;
3926
+ const updatedPlayers = game.players.map(
3927
+ (p) => p.id === currentPlayer.id ? updatedPlayer : p
3928
+ );
3929
+ const maxTurns = game.rules.basic.maxTurns;
3930
+ const isLastTurn = game.turn === maxTurns;
3931
+ if (isLastTurn && allLordsHavePlayed(game.lords)) {
3932
+ return ok({
3933
+ ...game,
3934
+ players: updatedPlayers,
3935
+ queendomino: {
3936
+ ...game.queendomino,
3937
+ buildersBoard: updatedBoard,
3938
+ dragonUsedThisRound: true
3939
+ },
3940
+ nextAction: { type: "step", step: gameSteps.result }
3941
+ });
3942
+ }
3943
+ return ok({
3944
+ ...game,
3945
+ players: updatedPlayers,
3946
+ queendomino: {
3947
+ ...game.queendomino,
3948
+ buildersBoard: updatedBoard,
3949
+ dragonUsedThisRound: true
3950
+ },
3951
+ nextAction: nextLordWithAction(game.lords)
3952
+ });
3953
+ };
3954
+
3955
+ // src/core/useCases/skipOptionalAction.ts
3956
+ var skipOptionalActionUseCase = (game, lordId) => {
3957
+ const currentAction = game.nextAction;
3958
+ if (currentAction.nextLord !== lordId) {
3959
+ return err(ErrorCode.NOT_YOUR_TURN);
3960
+ }
3961
+ const action = currentAction.nextAction;
3962
+ const isOptional = action === playerActions.placeKnight || action === playerActions.constructBuilding || action === playerActions.useDragon;
3963
+ if (!isOptional) {
3964
+ return err(ErrorCode.INVALID_OPTIONAL_ACTION);
3965
+ }
3966
+ const nextAction = nextQueenDominoAction(action);
3967
+ if (nextAction === playerActions.pickDomino) {
3968
+ const maxTurns = game.rules.basic.maxTurns;
3969
+ const isLastTurn = game.turn === maxTurns;
3970
+ if (isLastTurn && allLordsHavePlayed(game.lords)) {
3971
+ return ok({
3972
+ ...game,
3973
+ nextAction: { type: "step", step: gameSteps.result }
3974
+ });
3975
+ }
3976
+ return ok({
3977
+ ...game,
3978
+ nextAction: nextLordWithAction(game.lords)
3979
+ });
3980
+ }
3981
+ return ok({
3982
+ ...game,
3983
+ nextAction: {
3984
+ type: "action",
3985
+ nextLord: lordId,
3986
+ nextAction
3987
+ }
3988
+ });
3989
+ };
3990
+
2672
3991
  // src/core/useCases/startGame.ts
2673
3992
  var startGameUseCase = (deps) => (game) => {
2674
3993
  const { uuidMethod: uuidMethod3, shuffleMethod: shuffleMethod2 } = deps;
@@ -2697,6 +4016,15 @@ var startGameUseCase = (deps) => (game) => {
2697
4016
  nextLord: shuffledLords[0].id,
2698
4017
  nextAction: playerActions.pickDomino
2699
4018
  };
4019
+ let queendomino = game.queendomino;
4020
+ if (queendomino && game.mode.name === "QueenDomino") {
4021
+ const buildingShuffle = game.seed ? createSeededShuffle(game.seed, "buildings") : shuffleMethod2;
4022
+ const board = createBuildersBoard(
4023
+ queendomino.buildersBoard.drawPile,
4024
+ buildingShuffle
4025
+ );
4026
+ queendomino = { ...queendomino, buildersBoard: board };
4027
+ }
2700
4028
  const newState = {
2701
4029
  ...game,
2702
4030
  lords: shuffledLords,
@@ -2709,7 +4037,8 @@ var startGameUseCase = (deps) => (game) => {
2709
4037
  lordId: null,
2710
4038
  position: index + 1
2711
4039
  };
2712
- })
4040
+ }),
4041
+ ...queendomino !== void 0 && { queendomino }
2713
4042
  };
2714
4043
  return ok(newState);
2715
4044
  };
@@ -2718,6 +4047,7 @@ var startGameUseCase = (deps) => (game) => {
2718
4047
  var configureEngine = (config) => {
2719
4048
  const modeRepository = jsonModes_default();
2720
4049
  const dominoesRepository = jsonDominoes_default();
4050
+ const buildingsRepository = jsonBuildings_default();
2721
4051
  const ruleRepository = jsonRules_default();
2722
4052
  const uuid = config.uuidMethod || uuidMethod;
2723
4053
  const shuffle = config.shuffleMethod || shuffleMethod;
@@ -2730,7 +4060,8 @@ var configureEngine = (config) => {
2730
4060
  createGameUseCase({
2731
4061
  modeRepository,
2732
4062
  dominoesRepository,
2733
- uuidMethod: uuid
4063
+ uuidMethod: uuid,
4064
+ buildingsRepository
2734
4065
  })
2735
4066
  ),
2736
4067
  getModesHandler: getModesHandler(
@@ -2806,6 +4137,26 @@ var configureEngine = (config) => {
2806
4137
  logger,
2807
4138
  translator,
2808
4139
  getDynastyResultUseCase
4140
+ ),
4141
+ placeKnightHandler: placeKnightHandler(
4142
+ logger,
4143
+ translator,
4144
+ placeKnightUseCase
4145
+ ),
4146
+ constructBuildingHandler: constructBuildingHandler(
4147
+ logger,
4148
+ translator,
4149
+ constructBuildingUseCase
4150
+ ),
4151
+ useDragonHandler: useDragonHandler(
4152
+ logger,
4153
+ translator,
4154
+ useDragonUseCase
4155
+ ),
4156
+ skipOptionalActionHandler: skipOptionalActionHandler(
4157
+ logger,
4158
+ translator,
4159
+ skipOptionalActionUseCase
2809
4160
  )
2810
4161
  };
2811
4162
  };
@@ -2833,7 +4184,11 @@ var createGameEngine = (config) => {
2833
4184
  canPlaceDominoHandler: canPlaceDominoHandler2,
2834
4185
  serializeGameHandler: serializeGameHandler2,
2835
4186
  deserializeGameHandler: deserializeGameHandler2,
2836
- getDynastyResultHandler: getDynastyResultHandler2
4187
+ getDynastyResultHandler: getDynastyResultHandler2,
4188
+ placeKnightHandler: placeKnightHandler2,
4189
+ constructBuildingHandler: constructBuildingHandler2,
4190
+ useDragonHandler: useDragonHandler2,
4191
+ skipOptionalActionHandler: skipOptionalActionHandler2
2837
4192
  } = configureEngine(config);
2838
4193
  let engine2 = {
2839
4194
  getModes: (command) => getModesHandler2(command),
@@ -2851,7 +4206,11 @@ var createGameEngine = (config) => {
2851
4206
  canPlaceDomino: (command) => canPlaceDominoHandler2(command),
2852
4207
  serialize: (command) => serializeGameHandler2(command),
2853
4208
  deserialize: (command) => deserializeGameHandler2(command),
2854
- getDynastyResults: (command) => getDynastyResultHandler2(command)
4209
+ getDynastyResults: (command) => getDynastyResultHandler2(command),
4210
+ placeKnight: (command) => placeKnightHandler2(command),
4211
+ constructBuilding: (command) => constructBuildingHandler2(command),
4212
+ useDragon: (command) => useDragonHandler2(command),
4213
+ skipOptionalAction: (command) => skipOptionalActionHandler2(command)
2855
4214
  };
2856
4215
  if (config.events) {
2857
4216
  engine2 = wrapWithEvents(engine2, config.events);