Paste #10234: Edit of P#10232 - Untitled Paste

Date: 2014/10/02 21:35:32 UTC-07:00
Type: Denizen Script

View Raw Paste Download This Paste
Copy Link


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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398


################################################################################
#
#                         d  R  e  s  t  a  u  r  a  n  t
#                       For the real Restaurant experience!
#
#
#   Authors: |Anthony| calico-kid
#   Version: 0.1
#   dScript Version: 0.9.5-b1522
#
#
#
#--- About
#
#  The dRestarunt system brings realistic NPC animated restaurants to Minecraft.
# Those with permissions can create new restaurants. Restaurants can be bought
# and sold, and Waitresses and Chefs can be employed and fired.
#
#  Restaurants must have properly built equipment for the NPCs to be able to do
# their jobs. NPCs will automagically navigate their environment. A list of
# equipment and building instructions will follow. Adding more equipment to your
# restaurant will unlock additional menu items.
#
#  You can create new menu items by creating a new dRestaurant_item script. Copy
# the provided template and build your "recipe" using the provided animations. 
# dRestaurant will keep track of ingredient stock and equipment. If a menu item
# can't be made for whatever reason, it will be removed from the menu for that
# specific restaurant.
#
#  Each restaurant can have it's own menu. Restaurant owners are responsible for
# hiring chefs and waitresses, keeping raw materials stocked, building kitchen
# equipment, and creating their menus. Players can learn new menu items by
# buying a menu item from an existing restaurant and adding it to their menu.
# Server owned restaurants can add any menu item to any restaurant provided it
# has the correct equipment.
#
#
#--- Permissions
#
#
#
#--- Ticket System
#
#  The Ticket System is a single flag that holds all the ticket information for
# all restaurants. We're using <util.random.duuid> for our %ticketNumber% to
# avoid some silly incremental indexing method. The only piece of info you need
# to make available in the custom actions is the %ticketNumber%.
#   Notify the Waitress that an order is ready:
#     - ^action "order up" context:ticket|%ticket%
#   Notify the Chef that an order has been placed:
#     - ^action "order in" context:ticket|%ticket%
#
#  It contains a list of lists and is structured like this:
#   - %ticketNumber%/%chef%/%waitress%/<player>/%foodItems%|...
#
#  To get a list of all ticket numbers:
#   - define ticketList <server.flag[dRestaurantTickets].get_sub_items[1].split_by[/]>
#
#  To get a specific ticket object all you need is the %ticketNumber%
#   - define tickets '<server.flag[dRestaurantTickets].as_list>'
#   - define ticket '<def[tickets].get[<def[tickets].get_sub_items[1].split_by[/].find[%ticketNumber%]>]>'
#
#  To get ticket details
#   - define ticketNumber '<def[ticket].split_by[/].get[1]>'
#   - define chef '<def[ticket].split_by[/].get[2].as_npc>'
#   - define waitress '<def[ticket].split_by[/].get[3].as_npc>'
#   - define player '<def[ticket].split_by[/].get[4].as_player>'
#   - define foodItems '<def[ticket].split_by[/].get[5]>'
#
#  To add a new ticket
#   - define ticketNumber '<util.random.duuid>'
#   - define chef ''
#   - define waitress ''
#   - define player ''
#   - define foodItems ''
#   - flag server dRestaurantTickets:->:%ticketNumber%/%chef%/%waitress%/<player>/%foodItems%
#
#
#  To remove an existing ticket use the %ticket% object as defined above
#   - flag server dRestaurantTickets:<-:%ticket% 
#
#
################################################################################
#
#  dRestaurant World Script
#
#  This should cover all restaurant related world events. This is also the house
# for all of the equipment locators and the animations.
#
dRestaurant:
  type: world
  debug: false

  events:
#--------------------------------------
#  dRestaurant NPC events
#  when player sits down they should be flagged restaurant
    on player right clicks with i@menu:
      - if !<player.flag[ordered]> == true {
        - inventory open d:<player.flag[restaurant].as_npc.inventory>
        }

    on player clicks in inventory:
      - if <c.inventory> == <player.flag[restaurant].as_npc.inventory> {
        - if <player> == <player.flag[restaurant].as_npc.owner> {
          - queue clear
          }
        - if <player.flag[order].as_list.size> >= 9 {
          - narrate "your order size is maxed out"
          - determine passively cancelled
          - inventory update  
          }
          else {
          - narrate "<red><c.item.display> added to your ticket!"
          - flag player order:->:<c.item.full>
          - determine passively cancelled
          - inventory update
          }
        }
        - if <c.item> == i@order {
          - note in@restaurantinventory as:<player.name>_restaurant
          - foreach <player.flag[order].as_list> {
            - adjust %value% lore:"click to remove item" save:item
            - give <entry[item].result> to:in@<player.name>_restaurant 
            - give i@back to:in@<player.name>_restaurant slot:10
            - give i@order_accept to:in@<player.name>_restaurant slot:18
            }
          - inventory open in@<player.name>_restaurant
          - determine passively cancelled
          - inventory update
          }
      - if <c.inventory> == in@<player.name>_restaurant {
        - if <c.item> == i@order_accept {
          - inventory close d:<player.inventory>
          - note remove as:in@<player.name>_restaurant
          - flag player ordered
          - determine passively cancelled
          - inventory update
          - action "on order placed" 
          # make waitress walk to player and take the menu
          - take i@menu
          - narrate "<green>Al-right ill have that out when its ready!"
          - flag player ordered:!
          - ~walk <player.flag[restaurant].as_npc> <player.flag[restaurant].as_npc.flag[chef].location>
          - foreach <player.flag[order].as_list> {
          # at this point we need to foreach this list into the list of lists for the npc to have on the ticket or somehow add it in.
            - ~run MasterChefNPC as:<player.flag[chef]> path:%value%
            }
          - flag player order:!
          }
        - if <c.item> == i@back {
          - inventory open d:<player.flag[restaurant].as_npc.inventory>
          - determine passively cancelled
          - inventory update
          }
        - take <c.item>
        - determine passively cancelled
        - inventory update
        }


    on player right clicks with i@chefegg:
      - create player chef712 <player.location.cursor_on.add[0.5,1,0.5]>
      - execute as_op "npc select"
      - assignment set script:MasterChefNPC npc:<player.selected_npc>
      - take i@chefegg
      - give i@waitressegg
      - flag player chef:<player.selected_npc>

    on player right clicks with i@waitressegg:
      - create player waitress <player.location.cursor_on.add[0.5,1,0.5]>
      - execute as_op "npc select"
      - assignment set script:waitress npc:<player.selected_npc>
      - take i@waitressegg
      - flag <player.selected_npc> chef:<player.flag[chef]>

#
#  END dRestaurant NPC events
#--------------------------------------
#  Cuboid Selection
#
    on player right clicks block with dRestaurantTool:
    - determine passively CANCELLED
    - if !<player.has_permission[dRestaurant.create]> {
      - take i@dRestaurantTool
      - narrate "<&4><&l>ERROR<&co><&r> <&a>You should not have this!"
      - queue stop
      }
    - narrate "<&b><&l>dRestaurant<&co><&r> <&a>Set POS1 to <context.location.simple>"
    - flag player dRestaurantToolPOS1:<context.location>

    on player left clicks block with dRestaurantTool:
    - determine passively CANCELLED
    - if !<player.has_permission[dRestaurant.create]> {
      - take i@dRestaurantTool
      - narrate "<&4><&l>ERROR<&co><&r> <&a>You should not have this!"
      - queue stop
      }
    - narrate "<&b><&l>dRestaurant<&co><&r> <&a>Set POS2 to <context.location.simple>"
    - flag player dRestaurantToolPOS2:<context.location>

#
#  END Cuboid Selection
#--------------------------------------
#
#  Kitchen Equipment Locators
#
# These are the mechanics we use to find the various kitchen equipment
# End users don't need to concern themselves with this.
#
#  TODO
#
#    - Pantry
#    - Walkin Freezer
#    - Various Bar stuffs
#    - Frying station
#    - Fancy Grill?
#
#
  findBasicFridge:
  # The BasicFridge is 2 ironblocks tall with a stone button on the front of the top block
    - define ironBlocks <npc.location.find.blocks[iron_block].within[%range%]||null>
    - if <def[ironBlocks].is[!=].to[null]>
      && !<def[ironBlocks].is_empty> {
      - define locations li@
      - foreach %ironBlocks% {
        - define iron '%value%'
        - if <def[iron].below.material.name.is[!=].to[iron_block]||true> foreach next

        - define east '<def[iron].add[1,0,0]>'
        - define west '<def[iron].add[-1,0,0]>'
        - define north '<def[iron].add[0,0,1]>'
        - define south '<def[iron].add[0,0,-1]>'
        - define cardinals li@east|west|north|south

        - foreach %cardinals% {
          - define location '<def[%value%]>'

          - if <def[location].material.name.is[==].to[stone_button]>
            && <def[location].sub[0,1,0].material.name.is[==].to[air]>
            && <def[location].sub[0,2,0].material.is_solid> {
            - define locations <def[locations].include[%iron%/<def[location].below>]>
            }
          }
        }
      }

  findFancyFridge:
  # The FancyFridge is 2 ironblocks tall with an iron door on the front
    - define ironBlocks <npc.location.find.blocks[iron_block].within[%range%]||null>
    - if <def[ironBlocks].is[!=].to[null]>
      && !<def[ironBlocks].is_empty> {
      - define locations li@
      - foreach %ironBlocks% {
        - define iron '%value%'
        - if <def[iron].below.material.name.is[!=].to[iron_block]||true> foreach next

        - define east '<def[iron].add[1,0,0]>'
        - define west '<def[iron].add[-1,0,0]>'
        - define north '<def[iron].add[0,0,1]>'
        - define south '<def[iron].add[0,0,-1]>'
        - define cardinals li@east|west|north|south

        - foreach %cardinals% {
          - define location '<def[%value%]>'

          - if <def[location].material.name.is[==].to[iron_door_block]>
            && <def[location].sub[0,1,0].material.name.is[==].to[iron_door_block]>
            && <def[location].sub[0,2,0].material.is_solid> {
            - define locations <def[locations].include[%iron%/<def[location].below>]>
            }
          }
        }
      }

  findGrill:
  # The Grill is a trapdoor over fire
  # This currently sets the location to walk to as the solid block the player
  #  would stand on. This differs from all of the other equipment search
  #  functions since they all return the air block in front of the equipment.
  #  I want to keep this just to see if there is a noticeable difference. As in
  #  does the NPC get closer to the target block.
    - define fireBlocks <npc.location.find.blocks[fire].within[%range%]||null>
    - if <def[fireBlocks].is[!=].to[null]>
      && !<def[fireBlocks].is_empty> {
      - define locations li@
      - foreach %fireBlocks% {
        - define fire '%value%'
        - if <def[fire].above.material.name.is[!=].to[trap_door]||true> foreach next

        - define east '<def[fire].add[1,0,0]>'
        - define west '<def[fire].add[-1,0,0]>'
        - define north '<def[fire].add[0,0,1]>'
        - define south '<def[fire].add[0,0,-1]>'
        - define cardinals li@east|west|north|south

        - foreach %cardinals% {
          - define location '<def[%value%]>'

          - if <def[location].material.is_solid>
            && <def[location].above.material.name.is[==].to[air]>
            && <def[location].add[0,2,0].material.name.is[==].to[air]> {
            - define locations <def[locations].include[<def[fire].above>/%location%]>
            }
          }
        }
      }

  findSink:
  # The sink is a Cauldron full of water with a tripwire hook above
    - define cauldronBlocks <npc.location.find.blocks[cauldron,3].within[%range%]||null>
    - if <def[cauldronBlocks].is[!=].to[null]>
      && !<def[cauldronBlocks].is_empty> {
      - define locations li@
      - foreach %cauldronBlocks% {
        - define cauldron '%value%'
        - if <def[cauldron].above.material.name.is[!=].to[tripwire_hook]||true> foreach next

        - define east '<def[cauldron].add[1,0,0]>'
        - define west '<def[cauldron].add[-1,0,0]>'
        - define north '<def[cauldron].add[0,0,1]>'
        - define south '<def[cauldron].add[0,0,-1]>'
        - define cardinals li@east|west|north|south

        - foreach %cardinals% {
          - define location '<def[%value%]>'

          - if <def[location].material.name.is[==].to[air]>
            && <def[location].above.material.name.is[==].to[air]>
            && <def[location].below.material.is_solid> {
            - define locations <def[locations].include[%cauldron%/%location%]>
            }
          }
        }
      }

  findPrep:
  # The Prep station is the top half stone slab with a wood pressure plate on top
    - define prepBlocks <npc.location.find.blocks[stone_slab_up].within[%range%]||null>
    - if <def[prepBlocks].is[!=].to[null]>
      && !<def[prepBlocks].is_empty> {
      - define locations li@
      - foreach %prepBlocks% {
        - define prep '%value%'
        - if <def[prep].above.material.name.is[!=].to[wood_plate]||true> foreach next

        - define east '<def[prep].add[1,0,0]>'
        - define west '<def[prep].add[-1,0,0]>'
        - define north '<def[prep].add[0,0,1]>'
        - define south '<def[prep].add[0,0,-1]>'
        - define cardinals li@east|west|north|south

        - foreach %cardinals% {
          - define location '<def[%value%]>'

          - if <def[location].material.name.is[==].to[air]>
            && <def[location].above.material.name.is[==].to[air]>
            && <def[location].below.material.is_solid> {
            - define locations <def[locations].include[%prep%/%location%]>
            }
          }
        }
      }

  findOven:
  # The oven is a 2 tall by 2 wide set of furnaces.
  # We will accept furnaces that are on or off
  # For some reason i'm getting duplicate results, so for now i'm purging the
  #  dupes with:    - define locations '<def[locations].deduplicate>'
    - define furnaceBlocks <npc.location.find.blocks[furnace|burning_furnace].within[%range%]||null>
    - if <def[furnaceBlocks].is[!=].to[null]>
      && !<def[furnaceBlocks].is_empty> {
      - define locations li@
      - foreach %furnaceBlocks% {
        - define furnace1 '%value%'
        - if <def[furnace1].below.material.name.is[!=].to[furnace]||true>
          && <def[furnace1].below.material.name.is[!=].to[burning_furnace]||true> foreach next

        - define east '<def[furnace1].add[1,0,0]>'
        - define west '<def[furnace1].add[-1,0,0]>'
        - define north '<def[furnace1].add[0,0,1]>'
        - define south '<def[furnace1].add[0,0,-1]>'
        - define cardinals li@east|west|north|south

        - foreach %cardinals% {
          - define furnace2 '<def[%value%]>'

          - if <el@val[<def[furnace2].material.name.is[!=].to[furnace]>].and[<def[furnace2].material.name.is[!=].to[burning_furnace]>]>
            && <el@val[<def[furnace2].below.material.name.is[!=].to[furnace]>].and[<def[furnace2].below.material.name.is[!=].to[burning_furnace]>]> foreach next

          - define east '<def[furnace2].add[1,0,0]>'
          - define west '<def[furnace2].add[-1,0,0]>'
          - define north '<def[furnace2].add[0,0,1]>'
          - define south '<def[furnace2].add[0,0,-1]>'
          - define cardinals li@east|west|north|south

          - foreach %cardinals% {
            - define location '<def[%value%]>'

            - if <def[location].material.name.is[==].to[air]>
              && <def[location].sub[0,1,0].material.name.is[==].to[air]>
              && <def[location].sub[0,2,0].material.is_solid> {
              - define locations <def[locations].include[%furnace2%/<def[location].sub[0,1,0]>]>
              - define locations <def[locations].include[<def[furnace2].sub[0,1,0]>/<def[location].sub[0,1,0]>]>
              }
            }
          }
        }
      }
    - define locations '<def[locations].deduplicate>'

  findStove:
  # The Stove is a furnace with a stone pressure plate on top
    - define stoveBlocks <npc.location.find.blocks[furnace|burning_furnace].within[%range%]||null>
    - if <def[stoveBlocks].is[!=].to[null]>
      && !<def[stoveBlocks].is_empty> {
      - define locations li@
      - foreach %stoveBlocks% {
        - define stove '%value%'
        - if <def[stove].above.material.name.is[!=].to[stone_plate]||true> foreach next

        - define east '<def[stove].add[1,0,0]>'
        - define west '<def[stove].add[-1,0,0]>'
        - define north '<def[stove].add[0,0,1]>'
        - define south '<def[stove].add[0,0,-1]>'
        - define cardinals li@east|west|north|south

        - foreach %cardinals% {
          - define location '<def[%value%]>'

          - if <def[location].material.name.is[==].to[air]>
            && <def[location].above.material.name.is[==].to[air]>
            && <def[location].below.material.is_solid> {
            - define locations <def[locations].include[%stove%/%location%]>
            }
          }
        }
      }

  findtap:
  # The tap is a tripwire hook under a lever
    - define range 15
    - define tap <npc.location.find.blocks[tripwire_hook].within[%range%]||null>
    - if <def[tap].is[!=].to[null]>
      && !<def[tap].is_empty> {
      - define locations li@
      - foreach %tap% {
        - define tap '%value%'
        - if <def[tap].above.material.name.is[!=].to[lever]||true> foreach next

        - define east '<def[tap].add[1,0,0]>'
        - define west '<def[tap].add[-1,0,0]>'
        - define north '<def[tap].add[0,0,1]>'
        - define south '<def[tap].add[0,0,-1]>'
        - define cardinals li@east|west|north|south

        - foreach %cardinals% {
          - define location '<def[%value%]>'

          - if <def[location].material.name.is[==].to[air]>
            && <def[location].above.material.name.is[==].to[air]>
            && <def[location].sub[0,1,0].material.name.is[==].to[air]>
            && <def[location].sub[0,2,0].material.is_solid> {
            - define locations <def[locations].include[%tap%/<def[location].below>]>
            }
          }
        }
      }

  findWindow_chef:
  # The Window is an upside down stair block with a carpet on top and a
  # redstone_lamp_on above that. It must have an air block in front of it.
  # This is the same window that the Waitress picks up food from. The chef
  # delivers cooked food to the side of the window inside the kitchen. Be sure
  # to have carpet on the floor in front of the window (outside the kitchen) so
  # the chef and waitress are finding the same windows!
    - define stairs 'li@acacia_stairs,4|birch_wood_stairs,4|brick_stairs,4|cobblestone_stairs,4|dark_oak_stairs,4|jungle_wood_stairs,4|nether_brick_stairs,4|quartz_stairs,4|sandstone_stairs,4|smooth_stairs,4|spruce_wood_stairs,4|wood_stairs,4|acacia_stairs,5|birch_wood_stairs,5|brick_stairs,5|cobblestone_stairs,5|dark_oak_stairs,5|jungle_wood_stairs,5|nether_brick_stairs,5|quartz_stairs,5|sandstone_stairs,5|smooth_stairs,5|spruce_wood_stairs,5|wood_stairs,5|acacia_stairs,6|birch_wood_stairs,6|brick_stairs,6|cobblestone_stairs,6|dark_oak_stairs,6|jungle_wood_stairs,6|nether_brick_stairs,6|quartz_stairs,6|sandstone_stairs,6|smooth_stairs,6|spruce_wood_stairs,6|wood_stairs,6|acacia_stairs,7|birch_wood_stairs,7|brick_stairs,7|cobblestone_stairs,7|dark_oak_stairs,7|jungle_wood_stairs,7|nether_brick_stairs,7|quartz_stairs,7|sandstone_stairs,7|smooth_stairs,7|spruce_wood_stairs,7|wood_stairs,7'
    - define windowBlocks '<npc.location.find.blocks[%stairs%].within[%range%]||null>'
    - if <def[windowBlocks].is[!=].to[null]>
      && !<def[windowBlocks].is_empty> {
      - define locations li@
      - foreach %windowBlocks% {
        - define window '%value%'
        - if <def[window].above.material.bukkit_enum.is[!=].to[CARPET]||true> foreach next
        - if <def[window].add[0,2,0].material.name.is[!=].to[redstone_lamp_on]||true> foreach next

        - define east '<def[window].add[1,0,0]>'
        - define west '<def[window].add[-1,0,0]>'
        - define north '<def[window].add[0,0,1]>'
        - define south '<def[window].add[0,0,-1]>'
        - define cardinals li@east|west|north|south

        - foreach %cardinals% {
          - define location '<def[%value%]>'

          - if <def[location].material.name.is[==].to[air]>
            && <def[location].above.material.name.is[==].to[air]>
            && <def[location].below.material.is_solid> {
            - define locations <def[locations].include[%window%/%location%]>
            }
          }
        }
      }

  findWindow_waitress:
  # The Window is an upside down stair block with a carpet on top and a
  # redstone_lamp_on above that. It must have a carpet block in front of it.
  # This is the same window that the Chef places food on. The Waitress picks up
  # the cooked food from outside the kitchen.
  # Be sure to have an air block on the side of the window opposite the carpet 
  # (outside the kitchen) so the chef and waitress are finding the same windows!
    - define stairs 'li@acacia_stairs,4|birch_wood_stairs,4|brick_stairs,4|cobblestone_stairs,4|dark_oak_stairs,4|jungle_wood_stairs,4|nether_brick_stairs,4|quartz_stairs,4|sandstone_stairs,4|smooth_stairs,4|spruce_wood_stairs,4|wood_stairs,4|acacia_stairs,5|birch_wood_stairs,5|brick_stairs,5|cobblestone_stairs,5|dark_oak_stairs,5|jungle_wood_stairs,5|nether_brick_stairs,5|quartz_stairs,5|sandstone_stairs,5|smooth_stairs,5|spruce_wood_stairs,5|wood_stairs,5|acacia_stairs,6|birch_wood_stairs,6|brick_stairs,6|cobblestone_stairs,6|dark_oak_stairs,6|jungle_wood_stairs,6|nether_brick_stairs,6|quartz_stairs,6|sandstone_stairs,6|smooth_stairs,6|spruce_wood_stairs,6|wood_stairs,6|acacia_stairs,7|birch_wood_stairs,7|brick_stairs,7|cobblestone_stairs,7|dark_oak_stairs,7|jungle_wood_stairs,7|nether_brick_stairs,7|quartz_stairs,7|sandstone_stairs,7|smooth_stairs,7|spruce_wood_stairs,7|wood_stairs,7'
    - define windowBlocks '<npc.location.find.blocks[%stairs%].within[%range%]||null>'
    - if <def[windowBlocks].is[!=].to[null]>
      && !<def[windowBlocks].is_empty> {
      - define locations li@
      - foreach %windowBlocks% {
        - define window '%value%'
        - if <def[window].above.material.bukkit_enum.is[!=].to[CARPET]||true> foreach next
        - if <def[window].add[0,2,0].material.name.is[!=].to[redstone_lamp_on]||true> foreach next

        - define east '<def[window].add[1,0,0]>'
        - define west '<def[window].add[-1,0,0]>'
        - define north '<def[window].add[0,0,1]>'
        - define south '<def[window].add[0,0,-1]>'
        - define cardinals li@east|west|north|south

        - foreach %cardinals% {
          - define location '<def[%value%]>'

          - if <def[location].material.name.is[==].to[air]>
            && <def[location].above.material.name.is[==].to[air]>
            && <def[location].below.material.is_solid> {
            - define locations <def[locations].include[%window%/%location%]>
            }
          }
        }
      }

#
#  END Kitchen Equipment Locators
#--------------------------------------
#
#  Animations
#
# These are the animations we provide to the end users. All they have to do is
# inject them from their recipe scripts and have the right definitions available
#
#  TODO
#
#    - Figure out a way to have unattended cooking operations
#    - Add a cookTime option to baking
#    - Animations for any new equipment
#
#
#-----------------------
#  Chef Specific Animations
#
  getFood_FancyFridge:
  # Walk to the FancyFridge and get the %foodItems%
    - ^inject locally findFancyFridge instantly
    - ^define destination '<def[locations].random>'
    - ^define door '<def[destination].split[/].get[2].as_location>'
    - ~walkto %door% speed:0.7
    - ^look <npc> '<def[destination].split[/].get[1].as_location>'
    - ^playsound %door% sound:door_open
    - ^animate <npc> animation:ARM_SWING
    - ^switch %door% state:toggle
    - ^wait 15t
    - foreach %foodItems% {
      - animate <npc> animation:ARM_SWING
      - ~equip <npc> hand:<def[value].as_item>
      - wait 15t
      }
    - ^animate <npc> animation:ARM_SWING
    - ^switch %door% state:toggle
    - ^playsound %door% sound:door_close
    - ^wait 10t

  getFood_BasicFridge:
  # Walk to the BancyFridge and get the %foodItems%
    - ^inject locally findBasicFridge instantly
    - ^define destination '<def[locations].random>'
    - ^define door '<def[destination].split[/].get[2].as_location>'
    - ~walkto %door% speed:0.7
    - ^look <npc> '<def[destination].split[/].get[1].as_location>'
    - ^playsound %door% sound:door_open
    - ^animate <npc> animation:ARM_SWING
    - ^switch %door% state:toggle
    - ^wait 15t
    - foreach %foodItems% {
      - animate <npc> animation:ARM_SWING
      - ~equip <npc> hand:<def[value].as_item>
      - wait 15t
      }
    - ^animate <npc> animation:ARM_SWING
    - ^switch %door% state:toggle
    - ^playsound %door% sound:door_close
    - ^wait 10t

  washFood:
  # Walk to sink and wash the %foodItems%
    - ^inject locally findSink instantly
    - ^define destination '<def[locations].random>'
    - ^define sinkLoc '<def[destination].split[/].get[1].as_location>'
    - ~walkto '<def[destination].split[/].get[2].as_location>' speed:0.7
    - ^look <npc> %sinkLoc%
    - ^wait 5t
    - ~equip <npc> hand:<i@air>
    - ^animate <npc> animation:SNEAK
    - ^animate <npc> animation:ARM_SWING
    - ^playsound %sinkLoc% sound:splash2
    - ^define displayItems li@
    - ^foreach %foodItems% {
      - displayitem <def[value].as_item> '%sinkLoc%' save:displayItem_%loop_index%
      - define displayItems '<def[displayItems].include[<entry[displayItem_%loop_index%].dropped>]>'
      }
    - ^foreach %foodItems% {
      - define food <def[value].as_item>
      - ^repeat 5 {
        - ~equip <npc> hand:%food%
        - animate <npc> animation:ARM_SWING
        - playsound %sinkLoc% sound:swim
        - wait <util.random.int[5].to[15]>t
        }
      }
    - ^playsound %sinkLoc% sound:splash2
    - ^animate <npc> animation:STOP_SNEAKING
    - ^remove %displayItems%
    - ^animate <npc> animation:ARM_SWING
    - ~equip <npc> hand:<def[foodItems].random.as_item>
    - ^wait 10t

  prepFood:
  # Walk to prep area and prep the %foodItems%
    - ^inject locally findPrep instantly
    - ^define destination '<def[locations].random>'
    - ^define prepLoc '<def[destination].split[/].get[1].as_location>'
    - ~walkto '<def[destination].split[/].get[2].as_location>' speed:0.7
    - ^look <npc> %prepLoc%
    - ^animate <npc> animation:SNEAK
    - ^animate <npc> animation:ARM_SWING
    - ~equip <npc> hand:<i@air>
    - ^define displayItems li@
    - ^foreach %foodItems% {
      - displayitem <def[value].as_item> '%prepLoc%' save:displayItem_%loop_index%
      - define displayItems '<def[displayItems].include[<entry[displayItem_%loop_index%].dropped>]>'
      }
    - ^repeat 5 {
      - animate <npc> animation:ARM_SWING
      - ^define sound 'li@step_ladder|lava_pop'
      - playsound %prepLoc% sound:<def[sound].random>
      - wait 5t
      }
    - ^remove %displayItems%
    - ^animate <npc> animation:STOP_SNEAKING
    - ~equip <npc> hand:<def[foodItems].random.as_item>
    - ^wait 10t

  bakeFood_Attended:
  # Walk to oven and bake the %foodItem%
  # Items should be baked one at a time in my opinion, but idk.
    - ^inject locally findOven instantly
    - ^define destination '<def[locations].random>'
    - ~walkto '<def[destination].split[/].get[2].as_location>' speed:0.7
    - ^define furnace '<def[destination].split[/].get[1].as_location>'
    - ^look <npc> %furnace%
    - ~equip <npc> hand:<i@air>
    - ^animate <npc> animation:ARM_SWING
    - ^wait 5t
    - ^playsound %furnace% sound:ghast_fireball
    - ^showfake m@burning_furnace,<def[furnace].material.data> %furnace% to:<def[furnace].find.players.within[10]> d:200t
    - ^repeat 20 {
      - ^define sound 'li@fuse|fire.random|fire.random|fire.random'
      - ^playsound %furnace% sound:<def[sound].random>
      - ^wait 5t
      }
    - ^animate <npc> animation:ARM_SWING
    - ~equip <npc> hand:%foodItem%
    - ^wait 10t

  bakeFood_Unattended:
  # I have to figure out a method for making some cook processes be unattended
    - ^inject locally findOven instantly
    - ^define destination '<def[locations].random>'
    - ~walkto '<def[destination].split[/].get[2].as_location>' speed:0.7
    - ^define furnace '<def[destination].split[/].get[1].as_location>'
    - ^look <npc> %furnace%
    - ~equip <npc> hand:<i@air>
    - ^animate <npc> animation:ARM_SWING
    - ^wait 5t
    - ^playsound %furnace% sound:ghast_fireball
    - ^showfake m@burning_furnace,<def[furnace].material.data> %furnace% to:<def[furnace].find.players.within[10]> d:200t
    # The script should break away here so the chef can go do other stuff while
    # the oven continues to animate.
    - ^repeat 20 {
      - ^define sound 'li@fuse|fire.random'
      - ^playsound %furnace% sound:<def[sound].random>
      - ^wait 5t
      }
    - ^animate <npc> animation:ARM_SWING
    - ~equip <npc> hand:%foodItem%
    - ^wait 10t

  grillFood_Attended:
  # Walk to grill and cook %rawFood% into %cookedFood%
    - ^inject locally findGrill instantly
    - ^define destination '<def[locations].random>'
    - ~walkto '<def[destination].split[/].get[2].as_location>' speed:0.7
    - ^define grill '<def[destination].split[/].get[1].as_location>'
    - ^look <npc> %grill%
    - ~equip <npc> hand:<i@air>
    - ^animate <npc> animation:ARM_SWING
    - ^wait 5t
    - ^playsound %grill% sound:ghast_fireball
    - ^displayitem <def[rawFood].as_item> '%grill%' d:300s save:rawFood
    # Default (fallback) cook time of 30 seconds
    - ^define finishTime <def[cookTime].mul[1000].add_int[<server.current_time_millis>]||<server.current_time_millis.add_int[30000]>>
    # This method provides AT LEAST a 90 second max cook time. The longest
    # possible cook time is 270 seconds. There's a bit of randomness to this
    # though since the wait time between iterations is random. Animation will
    # stop regardless of the actual cook time after 360 iterations.
    - ^repeat 360 {
      - if <def[finishTime].is[LESS].than[<server.current_time_millis>]> repeat stop
      - ^define sound 'li@fuse|fuse|fire.random'
      - ^playsound %grill% sound:<def[sound].random>
      - ^if <util.random.int[1].to[10].is[OR_MORE].than[7]> animate <npc> animation:ARM_SWING
      - ^if <util.random.int[1].to[10].is[OR_MORE].than[4]> playeffect %grill% effect:smoke qty:1 data:4
      - ^wait <util.random.int[5].to[15]>t
      }
    - ^animate <npc> animation:ARM_SWING
    - ^remove <entry[rawFood].dropped>
    - ^displayitem <def[cookedFood].as_item> '%grill%' d:30s save:cookedFood
    - ^repeat 3 {
      - ^define sound 'li@fuse|fuse|fire.random'
      - ^playsound %grill% sound:<def[sound].random>
      - ^playeffect %grill% effect:smoke qty:1 data:4
      - ^wait 15t
      }
    - ^animate <npc> animation:ARM_SWING
    - ^remove <entry[cookedFood].dropped>
    - ~equip <npc> hand:%cookedFood%
    - ^wait 10t

  boilFood_Attended:
  # Walk to stove and cook %rawFood% into %cookedFood%
    - ^inject locally findStove instantly
    - ^define destination '<def[locations].random>'
    - ~walkto '<def[destination].split[/].get[2].as_location>' speed:0.7
    - ^define stove '<def[destination].split[/].get[1].as_location>'
    - ^look <npc> %stove%
    - ~equip <npc> hand:<i@air>
    - ^animate <npc> animation:ARM_SWING
    - ^wait 5t
    - ^playsound %stove% sound:ghast_fireball
    - ^modifyblock %stove% m@burning_furnace,<def[stove].material.data>
    - ^displayitem <def[rawFood].as_item> '%stove%' d:300s save:rawFood
    # Default (fallback) cook time of 30 seconds
    - ^define finishTime <def[cookTime].mul[1000].add_int[<server.current_time_millis>]||<server.current_time_millis.add_int[30000]>>
    # This method provides AT LEAST a 90 second max cook time. The longest
    # possible cook time is 270 seconds. There's a bit of randomness to this
    # though since the wait time between iterations is random. Animation will
    # stop regardless of the actual cook time after 360 iterations.
    - ^repeat 360 {
      - if <def[finishTime].is[LESS].than[<server.current_time_millis>]> repeat stop
      - ^define sound 'li@fuse|lava|fire.random'
      - ^playsound %stove% sound:<def[sound].random>
      - ^if <util.random.int[1].to[10].is[OR_MORE].than[7]> animate <npc> animation:ARM_SWING
      - ^if <util.random.int[1].to[10].is[OR_MORE].than[4]> playeffect %stove% effect:mob_spell qty:10 data:0.2 offset:0.2
      - ^wait <util.random.int[5].to[15]>t
      }
    - ^animate <npc> animation:ARM_SWING
    - ^remove <entry[rawFood].dropped>
    - ^displayitem <def[cookedFood].as_item> '%stove%' d:30s save:cookedFood
    - ^repeat 3 {
      - ^define sound 'li@fuse|lava|fire.random'
      - ^playsound %stove% sound:<def[sound].random>
      - ^playeffect %stove% effect:smoke qty:1 data:4
      - ^wait 15t
      }
    - ^animate <npc> animation:ARM_SWING
    - ^remove <entry[cookedFood].dropped>
    - ~equip <npc> hand:%cookedFood%
    - ^modifyblock %stove% m@furnace,<def[stove].material.data>
    - ^wait 10t

  deliverFood_chef:
  # Walk to the window and deliver the %foodItems%
    - ^inject locally findWindow_chef instantly
    - ^define destination '<def[locations].random>'
    - ^define windowLoc '<def[destination].split[/].get[1].as_location>'
    - ~walkto '<def[destination].split[/].get[2].as_location>' speed:0.7
    - ^look <npc> %windowLoc%
    - ~equip <npc> hand:<i@air>
    - ^define displayItems li@
    - ^foreach %foodItems% {
      - displayitem <def[value].as_item> '%windowLoc%' d:30s save:displayItem_%loop_index%
      - define displayItems '<def[displayItems].include[<entry[displayItem_%loop_index%].dropped>]>'
      }
    - ^action "order up" context:ticket|%ticket%


#-----------------------
#  Waitress Specific Animations
#
  deliverFood_waitress:
  # Walk to window, collect the %foodItems%, and deliver them to the player.
  # Currently using a simple walkto command. This may lead to table dancers.
    # Find the window and walk to it
    - ^inject locally findWindow_waitress instantly
    - ^define destination '<def[locations].random>'
    - ^define windowLoc '<def[destination].split[/].get[1].as_location>'
    - ~walkto '<def[destination].split[/].get[2].as_location>' speed:0.7
    - ^look <npc> %windowLoc%
    - ^wait 10t
    # Pickup the food. This means we need to store the entity id for the display items
    - ^remove %foodItems%
    - ~equip <npc> hand:<def[foodItems].split_by[\].random.as_item>
    - ^wait 10t
    # Really should have a method to ensure that the player is still online and
    # still in the restaurant before we proceed.
    - ^if <def[player].location.distance[<npc.location>].is[OR_LESS].than[30]> {
      - ~walkto %player%
      - ^wait 10t
# Not sure if this is sane without a table locator or if it's needed at all.
#      - ^foreach %foodItems% {
#        - displayitem <def[value].as_item> '<def[player].location.add[1,0,0]>' d:10s
#        - give player:%player% <def[value].as_item>
#        }
      - ^give player:%player% %foodItems%
      }
      else give player:%player% %foodItems%

#
#  END Animations
#--------------------------------------
#
#
#  END DRESTAURANT WORLD SCRIPT
#
################################################################################
#
#  Restaurant Command Script Container
#
# This script covers all dRestaurant commands
#
#
#  DATA STORAGE
#   - Currently using flags. Might convert to yaml.
#
#
#
#
#--------------------------------------
#
#  dRestaurant Command Script Basics
#
# The basic stuff required in a command script container
#
dRestaurantCommand:
  type: command
  debug: false
  name: drestaurant
  description: Commands to create and manage dRestaurants.
  usage: <&nl>/drestaurant <&lt>tool<&gt><&nl>/drestaurant <&lt>create<&gt> <&lt>name<&gt><&nl>/drestaurant <&lt>edit<&gt> <&lt>name<&gt><&nl>/drestaurant <&lt>delete<&gt> <&lt>name<&gt><&nl>/drestaurant <&lt>hire<&gt> <&lt>waitress/chef<&gt><&nl>/drestaurant <&lt>fire<&gt> <&lt>waitress/chef<&gt><&nl>/drestaurant <&lt>buy<&gt> <&lt>restaurant<&gt><&nl>/drestaurant <&lt>sell<&gt> <&lt>restaurant<&gt>
  aliases:
  - restaurant
  - dr
  - drest
  allowed help:
  - determine <player.has_permission[dRestaurant.user]>
# This is what is run when someone types the root command. This subscript
# quickly passes the command on to the command argument handlers below. If the
# argument doesn't exist, or is not specified, it runs the help subscript.
  script:
    - define arg1 '<c.args.get[1].escaped||help>'
    - define args 'li@help|tool|create|edit|delete|buy|sell|hire|fire'
    - if !<def[args].contains[%arg1%]> inject locally help
      else inject locally %arg1%

#
#  END dRestaurant Command Script Basics
#--------------------------------------
#
#  dRestaurant Command Arguments
#
# Each of these subscripts is an argument for the root command.
#
  help:
    - if <player.has_permission[dRestaurant.create]> inject locally msgsHelpAdmin instantly
      else inject locally msgsHelpUser instantly
    - define footerText '<&f><&sp><&sp>Authors<&co> <&7>|Anthony| <&7>calico-kid'
    - inject locally msgsFooter instantly
    - queue stop

  tool:
    - if <player.has_permission[dRestaurant.create]> {
      - give i@dRestaurantTool
      - narrate "<&b><&l>dRestaurant<&co><&r> <&a>Right click to select pos1"
      - narrate "<&b><&l>dRestaurant<&co><&r> <&a>Left click to select pos2"
      - queue stop
      }

  create:
    - if <player.has_permission[dRestaurant.create]> {
      - define name '<c.args.get[2].escaped||null>'
      - if <def[name].is[==].to[null]> {
        - narrate "<&4><&l>ERROR<&co><&r> <&a>You must specify a name!"
        - queue stop
        }
      - if <cu@restaurant_%name%||null> != null {
        - narrate "<&4><&l>ERROR<&co><&r> <&a>There is already a restaurant by this name!"
        - queue stop
        }
      - define pos1 <player.flag[dRestaurantToolPOS1]||null>
      - define pos2 <player.flag[dRestaurantToolPOS2]||null>
      - if <def[pos1].is[==].to[null]>
        || <def[pos2].is[==].to[null]> {
        - narrate "<&4><&l>ERROR<&co><&r> <&a>You must use the dRestaurant region tool to select 2 locations!"
        - queue stop
        }
      - take i@dRestaurantTool
      - note cu@%pos1%|%pos2% 'as:restaurant_%name%'
      - flag server dRestaurant.%name%.Owner:<player>
      - flag player dRestaurantToolPOS1:!
      - flag player dRestaurantToolPOS2:!
      }

  edit:
    - define name '<c.args.get[2].escaped||null>'
    - if <player.has_permission[dRestaurant.admin]>
      || <el@val[<player.has_permission[dRestaurant.edit]>].and[<server.flag[dRestaurant.%name%.Owner].is[==].to[<player>]>]> {
      - if <def[name].is[==].to[null]> {
        - narrate "<&4><&l>ERROR<&co><&r> <&a>You must specify a name!"
        - queue stop
        }
      - if <cu@restaurant_%name%||null> == null {
        - narrate "<&4><&l>ERROR<&co><&r> <&a>There is no restaurant by this name!"
        - queue stop
        }
      - define pos1 <player.flag[dRestaurantToolPOS1]||null>
      - define pos2 <player.flag[dRestaurantToolPOS2]||null>
      - if <def[pos1].is[==].to[null]>
        || <def[pos2].is[==].to[null]> {
        - narrate "<&4><&l>ERROR<&co><&r> <&a>You must use the dRestaurant region tool to select 2 locations!"
        - queue stop
        }
      - take i@dRestaurantTool
      - note cu@%pos1%|%pos2% 'as:restaurant_%name%'
      - flag player dRestaurantToolPOS1:!
      - flag player dRestaurantToolPOS2:!
      }

  delete:
    - define name '<c.args.get[2].escaped||null>'
    - if <player.has_permission[dRestaurant.admin]>
      || <el@val[<player.has_permission[dRestaurant.create]>].and[<server.flag[dRestaurant.%name%.Owner].is[==].to[<player>]>]> {
      - if <def[name].is[==].to[null]> {
        - narrate "<&4><&l>ERROR<&co><&r> <&a>You must specify a name!"
        - queue stop
        }
      - if <cu@restaurant_%name%||null> == null {
        - narrate "<&4><&l>ERROR<&co><&r> <&a>There is no restaurant by this name!"
        - queue stop
        }
      - note remove 'as:restaurant_%name%'
      - flag server dRestaurant.%name%:!
      }

  hire:
    - stub

  fire:
    - stub

  buy:
    - stub

  sell:
    - stub

#
#  END dRestaurant Command Arguments
#--------------------------------------
#
#  dRestaurant Command Messages
#
# These are not complete! They are mostly just stubs till the rest is fleshed out!
#
  msgsHeader:
    - ^narrate "<&5>|----------------------------------------|"
    - ^narrate "<&5>|<&sp><&sp><&sp><&6>dRestaurant   <&7>%msgsHeaderTitle%"
    - ^narrate "<&5>|<&sp><&sp><&sp><&e>MineConomy    <&f>Exclusive"
    - ^narrate "<&5>|<&f>"

  msgsFooter:
    - ^narrate "<&5>|<def[footerText]||>"
    - ^narrate "<&d>|-----------S-c-r-o-l-l---U-p-------------|"

  msgsHelpAdmin:
    - define msgsHeaderTitle 'Admin Help'
    - inject locally msgsHeader instantly
    - ^narrate "<&5>|<&sp><&sp><&sp><&sp><&f>You can create restaurants and staff them"
    - ^narrate "<&5>|<&sp><&sp><&f>with chefs and waitresses that will automagically"
    - ^narrate "<&5>|<&sp><&sp><&f>tend to your guests. Just keep your restaurant"
    - ^narrate "<&5>|<&sp><&sp><&f>stocked with the materials for your menu and have"
    - ^narrate "<&5>|<&sp><&sp><&f>the proper kitchen equipment."
    - ^narrate "<&5>|<&sp><&f>"

  msgsHelpUser:
    - define msgsHeaderTitle 'User Help'
    - inject locally msgsHeader instantly
    - ^narrate "<&5>|<&sp><&sp><&sp><&sp><&f>dRestaurant brings a realistic restaurant"
    - ^narrate "<&5>|<&sp><&sp><&f>experience to Minecraft. Fully automated NPCs will"
    - ^narrate "<&5>|<&sp><&sp><&f>serve your customers and prepare their food."
    - ^narrate "<&5>|<&sp><&f>"

#
#  END dRestaurant Command Messages
#--------------------------------------
#
#
#  END DRESTAURANT COMMAND SCRIPT
#
################################################################################
#
#  Master Waitress Assignment Script
#
# The Waitress will greet players, deliver menus, take orders, and deliver food.
#
MasterWaitress:
  type: assignment
  speed: 1t
  debug: true

  actions:
    on assignment:
      - run locally assignment instantly
    on spawn:
      - run locally spawn instantly
    on despawn:
      - run locally despawn instantly delay:5s
    on click:
      - run locally click_<npc.flag[status]||drunk> instantly
    # Custom event fired by the chef when an order is complete
    on order up:
      # take a snapshot of all current tickets so we aren't effected by any list
      # changes that could happen during processing and get the ticket object.
      - define ticketNumber '<c.ticket>'
      - define tickets '<server.flag[dRestaurantTickets].as_list||null>'
      - define ticket '<def[tickets].get[<def[tickets].get_sub_items[1].split_by[/].find[%ticketNumber%]>]||null>'
      - if <def[ticket].is[==].to[null]> {
        - announce "<&b>dRestaurant<&co> <&c>Something went wrong!" to_console
        - announce "<&b>dRestaurant<&co> <&3>Ticket <&b>%ticketNumber%<&3> was not found in dRestaurantTickets" to_console
        - queue clear
        }
      # Let the waitress decide what to do based on status
      - define waitress '<def[ticket].split_by[/].get[3].as_npc>'
      - inject locally orderup_<def[waitress].flag[Status]||drunk> as:%waitress%
    # Custom event fired by the world script when a player places an order
    on order placed:
      # take a snapshot of all current tickets so we aren't effected by any list
      # changes that could happen during processing and get the ticket object.
      - define restaurant '<c.restaurant>'
      - define player '<c.player>'
      - define waitress '<c.waitress>'


  assignment:
  # What happens on assignment. We want this as a subscript so we can run it
  # outside the on assignment action if needed.
    - trigger name:chat state:true radius:5 cooldown:5s
    - trigger name:click state:true radius:5 cooldown:5s
    - trigger name:proximity state:false
    - trigger name:damage state:true radius:5 cooldown:5s
    - vulnerable state:false
    - lookclose true range:5 realistic
    - flag npc respawn_location:<npc.location>
    - flag npc Pathfind.FidgetRadius:15
    - flag npc Pathfind.FidgetSpeed:0.7
    - flag npc Pathfind.FidgetWait:5
    - flag npc Pathfind.FidgetLocation:<npc.location>
    - flag npc Pathfind.FidgetHeight:1
    - flag npc Pathfind.FidgetPathMaterial:<npc.location.standing_on.material.name>
    - inject locally spawn instantly

  spawn:
    - chat "Alright, time to start work..." no_target
    - if <queue.exists[fidgetQueue_<npc.id>]> queue queue:fidgetQueue_<npc.id> stop
    - inject locally processTicketQueue
    - run s@Fidget id:fidgetQueue_<npc.id>

  despawn:
  # Just a code stub
    - chat "Phew... I<&sq>m glad to be done work for the day!" no_target

  damage:
  # Just a code stub
    - chat "Why would you do that?" no_target

#
#--------------------------------------
#
#  Logic Utilities
#
#
  processTicketQueue:
  # Run through a list of orders waiting to be delivered. Rinse and repeat until
  # the queue is cleared.
    - if !<npc.flag[TicketQueue].as_list.is_empty> {
      - flag npc Status:deliver
      - foreach <npc.flag[TicketQueue].as_list> {
        - define tickets '<server.flag[dRestaurantTickets].as_list>'
        - define ticket '<def[tickets].get[<def[tickets].get_sub_items[1].split_by[/].find[%ticketNumber%]>]>'
        - define player '<def[ticket].split_by[/].get[4].as_player>'
        - define foodItems '<def[ticket].split_by[/].get[5].split_by[\]>'
        - inject s@dRestaurant p:deliverFood_waitress
        - flag npc TicketQueue:<-:%ticketNumber%
        - flag server dRestaurantTickets:<-:%ticket%
        }
      - inject processTicketQueue locally
      }
    - flag npc Status:available

  placeOrder:
  # We could remove the cuboid search if we have the restaurant name when the order is placed
    # The Waitress will determine a list of possible restaurants based on
    # npc.owner and restaurant region owner.
    - define restaurants li@
    - foreach <npc.location.cuboids> {
      - if <def[value].notable_name.split[_].get[1].is[==].to[Restaurant]> {
        - define restaurant '<def[value].notable_name.split[_].get[2]>'
        - define owner '<server.flag[dRestaurant.%restaurant%.Owner].as_player>'
        - if <def[owner].is[==].to[<npc.owner>]> {
          - define restaurants '<def[restaurants].include[%restaurant%]>'
          }
        }
      }
    # Now the Waitress looks for all chefs in these valid restaurant regions
    - define chefs li@
    - foreach %restaurants% {
      - define restaurant %value%
      - foreach <el@val[Restaurant_%restaurant%].as_cuboid.list_npcs> {
        - define npc %value%
        - if <def[npc].owner.is[==].to[<npc.owner>]>
          && <def[npc].script.is[==].to[MasterChefNPC]> {
          - define chefs '<def[chefs].include[%npc%]>'
          }
        }
      }
    # Now the Waitress has a list of chefs, let's find the least busy
    - define chef <def[chefs].get[1]>
    - foreach <def[chefs].get[2].to[<def[chefs].size>]> {
      - if <def[value].flag[OrderQueue].size.is[LESS].than[<def[chef].flag[OrderQueue].size>]> {
        - define chef %value%
        }
      }
    # Let's try to get a valid ticket number
    - repeat 20 {
      - define ticketNumber <util.random.duuid>
      - define ticketList <server.flag[dRestaurantTickets].get_sub_items[1].split_by[/]>
      - if !<def[ticketList].contains[%ticketNumber%]> repeat stop
      - if <def[value].is[OR_MORE].than[20]> {
        - define ticketNumber "LastLostTicketDetails"
        - announce "<&b>dRestaurant<&co> <&c>Order Lost - Couldn<&sq>t get a valid ticket number!" to_console
        - announce "<&b>dRestaurant<&co> <&c>%ticketNumber%" to_console
        - announce "<&b>dRestaurant<&co> <&c>Chef<&co> %chef%" to_console
        - announce "<&b>dRestaurant<&co> <&c>Waitress<&co> %waitress%" to_console
        - announce "<&b>dRestaurant<&co> <&c>Player<&co> <player>" to_console
        - announce "<&b>dRestaurant<&co> <&c>foodItems<&co> %foodItems%" to_console
        }
      }
    # Finally let's place the order
    - flag server dRestaurantTickets:->:%ticketNumber%/%chef%/%waitress%/<player>/%foodItems%
    - action "order in" context:ticket|%ticket%

#
#  END Logic Utilities
#
#--------------------------------------
#
#  MasterWaitress Status Actions
#
# We're using an NPC status system for action responses. This is a low latency
# and low load method that allows for very fast NPC reactions since they do not
# have to do ANY comparisons. They just run the correct subscript based on the
# action and their current status.
#
#
#--------------------------------------
#  Click Responses
#
  click_drunk:
  # A catchall if something derps
    - flag npc status:drunk
    - if <queue.exists[fidgetQueue_<npc.id>]> queue queue:fidgetQueue_<npc.id> stop
    - chat "I<&sq>m not feeling well... I have to go." no_target
    - wait 2s
    - despawn <npc>

  click_available:
  # When the Waitress is available for whatever
    - flag npc status:order
    - if <queue.exists[fidgetQueue_<npc.id>]> queue queue:fidgetQueue_<npc.id> stop
    - define loc <player.location.find.surface_blocks[<npc.flag[Pathfind.FidgetPathMaterial].as_list>].within[5]||<npc.location>>
    - ~walk %loc% 'speed:<npc.flag[Pathfind.FidgetSpeed].as_money.add[0.1]>'
    - look <player.eye_location> d:5s
    - wait 10t
    - chat "Here you go. Take a look through our menu and choose what you would like."
    - give i@menu
    - wait 30t
    - chat "I<&sq>ll come grab the menu when you are ready."
    - wait 30t
    # Now the waitress can go back to what she was doing

  click_order:
  # When the Waitress is taking an order
    - wait 15t
    - chat "I<&sq>ll be right with you <player.name>."

  click_deliver:
  # When the Waitress is delivering food
    - wait 15t
    - chat "We<&sq>re a little busy right now <player.name>."
    - wait 15t
    - chat "Please have a seat and a Waitress will be right with you."

#
#--------------------------------------
#  Order Up Responses
#
  orderup_drunk:
  # A catchall if something derps
    - flag npc status:drunk
    - if <queue.exists[fidgetQueue_<npc.id>]> queue queue:fidgetQueue_<npc.id> stop
    - chat "I<&sq>m not feeling well... I have to go." no_target
    - wait 2s
    - despawn <npc>

  orderup_available:
  # When the Waitress is available for whatever
    - flag npc status:deliver
    - if <queue.exists[fidgetQueue_<npc.id>]> queue queue:fidgetQueue_<npc.id> stop
    - flag npc TicketQueue:->:%ticketNumber%
    - inject locally processTicketQueue

  orderup_order:
  # When the Waitress is taking an order
    - flag npc TicketQueue:->:%ticketNumber%

  orderup_deliver:
  # When the Waitress is delivering food
    - flag npc TicketQueue:->:%ticketNumber%

#
#  END MasterWaitress Status Actions
#--------------------------------------
#
#
#  END MASTERWAITRESS ASSIGNMENT SCRIPT CONTAINER
#
################################################################################
#
#  dRestaurant Custom Items
#
# dRestaurant uses a lot of custom items to do different things.
#
#
#--------------------------------------
#
#  Menu items
#
menu:
  type: item
  material: i@book
  display name: menu

dRestaurant_potato:
  type: item
  material: i@baked_potato
  display name: Baked Potato
  lore:
    - A tasty Baked Potato
    - prepared by a Master Chef

  potato:
    - ^lookclose <npc> state:false
    - ^define foodItems li@potato_item
    - ^inject s@dRestaurant p:getFood_FancyFridge
    - ^inject s@dRestaurant p:washFood
    - ^inject s@dRestaurant p:prepFood
    - ^define foodItem baked_potato
    - ^inject s@dRestaurant p:bakeFood_Attended
    - ^lookclose <npc> state:true
    - ^define foodItems li@baked_potato
    - ^inject s@dRestaurant p:deliverFood_chef

dRestaurant_steak:
  type: item
  material: i@cooked_beef
  display name: Steak
  lore:
    - A tasty Steak prepared
    - by a Master Chef

  steak:
    - ^lookclose <npc> state:false
    - ^define foodItems li@raw_beef
    - ^inject s@dRestaurant p:getFood_FancyFridge
    - ^inject s@dRestaurant p:prepFood
    - ^define rawFood raw_beef
    - ^define cookedFood cooked_beef
    - ^define cookTime 30
    - ^inject s@dRestaurant p:grillFood_Attended
    - ^lookclose <npc> state:true
    - ^define foodItems li@cooked_beef
    - ^inject s@dRestaurant p:deliverFood_chef

dRestaurant_stew:
  type: item
  material: i@mushroom_soup
  display name: Mushroom Stew
  lore:
    - A tasty Mushroom Stew
    - prepared by a Master Chef

  stew:
    - ^lookclose <npc> state:false
    - ^define foodItems li@brown_mushroom|red_mushroom
    - ^inject s@dRestaurant p:getFood_FancyFridge
    - ^inject s@dRestaurant p:washFood
    - ^inject s@dRestaurant p:prepFood
    - ^define rawFood bowl
    - ^define cookedFood mushroom_soup
    - ^define cookTime 30
    - ^inject s@dRestaurant p:boilFood_Attended
#    - run s@dRestaurant p:boilFood_Unattended def:%rawFood%|%cookedFood%|%cookTime%
#    - action "complete cook" context:ticketNumber|%ticketNumber%|
    - ^lookclose <npc> state:true
    - ^define foodItems li@mushroom_soup
    - ^inject s@dRestaurant p:deliverFood_chef


beefstew:
  type: item
  material: mushroom_soup
  display name: "beef stew"

mushroomstew:
  type: item
  material: mushroom_soup
  display name: "mushroom stew"

#
#  END Menu Items
#--------------------------------------
#
#  Other items
#
waitressegg:
  type: item
  material: m@monster_egg
  display name: waitress

chefegg:
  type: item
  material: m@monster_egg
  display name: chef

dRestaurantTool:
  type: item
  material: stick
  display name: <&3>Restaurant Region Tool
  lore:
  - <&f>Right click to set pos1
  - <&f>Left click to set pos2
restaurantinventory:
  type: inventory
  size: 18
back:
  type: item
  material: i@red_wool
  display name: "back to menu"
  lore:
  - click to return to menu
order_accept:
  material: i@green_wool
  display name: "accept order"
  lore:
  - click to accept this order
#
#  END Other Items
#--------------------------------------
#
#
#  END DRESTAURANT CUSTOM ITEMS
#
################################################################################