Paste #12957: BOSS FIGHT CHECK

Date: 2015/01/14 23:58:46 UTC-08: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


# Adjust coords on lines
 # You can use this command to see the location of the cuboid
  # With the NPC selected:
  # /ex showfake glass <<npc.flag[cuboid]>.get_outline> duration:10s
# 17
# 30
# 38
# 39
# 173


"Pitboss":
  type: assignment
  debug: false

  default constants:
    World Name: worldname
    Boss Entity Type: player
    Boss Skin: Romaji    
    Boss Age: adult
    Boss Zombiemod: "none"
    Boss Weapon: DIAMOND_SPADE
    Boss Health: 500
    Boss Strength: 3
    Boss Armour: 40
    Boss Attack Range: 20
    Boss Movement Speed: 1
    Boss Attack Rate: 10
    Boss Self Healing: "Yes"
    Boss Spawn Location: "x,y,z,world"
    Boss Respawn Delay: 1600
    Boss Reset Timer: 180
    Drop Loot on Death: "Yes"
    Loot Quantity: 1
    Loot Distribution: chest
    Loot Chest Expiry: 300
    Scoreboard: minionkills
    Cuboid Spawn Area Poss 1: "x,y,z,world"
    Cuboid Spawn Area Poss 2: "x,y,z,world"
    Bossfight Activator: proximity 
    Boss Awareness Range: 55
    Enabled Boss Stages: One|Two|Three|Four
    # Boss Fight - Stage One
     Stage One Boss Health Percentage: 100
     Stage One Boss Aura: smoke
     Stage One Special Attack: "Slowness Arrow"
     Stage One Special Attack Quantity: 0
     Stage One Special Attack Delay: 20s
     Stage One Spawn Minions: "Yes"
     Minion One Type: cave_spider
     Minion One Skin: none
     Minion One Age: adult
     Minion One Zombiemod: none         
     Minion One Name: Hex
     Minion One Weapon: none
     Minion One Health: 10
     Minion One Quantity: 40
     Minion One Attack Range: 20
     Minion One Strength: 1
     Minion One Armour: 20
     Minion One Speed: 1.5
     Minion One Attack Rate: 20
     Minion One Guardmode: lookout
     Minion One Spawn Effect: lightning
     Minion One Spawn Location: cuboid

    # Boss Fight - Stage Two
     Stage Two Boss Health Percentage: 75
     Stage Two Boss Aura: ender
     Stage Two Special Attack: "Wither Arrow"
     Stage Two Special Attack Quantity: 0
     Stage Two Special Attack Delay: 30s
     Stage Two Spawn Minions: "Yes"
     Minion Two Type: zombie
     Minion Two Skin: none
     Minion Two Age: adult
     Minion Two Zombiemod: "-b"
     Minion Two Name: Hex
     Minion Two Weapon: none
     Minion Two Health: 20
     Minion Two Quantity: 30
     Minion Two Attack Range: 10
     Minion Two Strength: 2
     Minion Two Armour: 20
     Minion Two Speed: 1.4
     Minion Two Attack Rate: 10
     Minion Two Guardmode: bodyguard
     Minion Two Spawn Effect: lightning
     Minion Two Spawn Location: boss

    # Boss Fight - Stage Three
     Stage Three Boss Health Percentage: 60
     Stage Three Boss Aura: flame
     Stage Three Special Attack: "TNT Drop"
     Stage Three Special Attack Quantity: 40
     Stage Three Special Attack Delay: 20s
     Stage Three Spawn Minions: "Yes"
     Minion Three Type: blaze
     Minion Three Skin: none
     Minion Three Age: adult
     Minion Three Zombiemod: none 
     Minion Three Name: Hex
     Minion Three Weapon: none
     Minion Three Health: 20
     Minion Three Quantity: 15
     Minion Three Attack Range: 30
     Minion Three Strength: 2
     Minion Three Armour: 40
     Minion Three Speed: 1
     Minion Three Attack Rate: 20
     Minion Three Guardmode: bodyguard
     Minion Three Spawn Effect: explode
     Minion Three Spawn Location: boss

    # Boss Fight - Stage Four
     Stage Four Boss Health Percentage: 40
     Stage Four Boss Aura: flame
     Stage Four Special Attack: Firestarter
     Stage Four Special Attack Quantity: 40
     Stage Four Special Attack Delay: 10s
     Stage Four Spawn Minions: "Yes"
     Minion Four Type: iron_golem
     Minion Four Skin: none
     Minion Four Age: adult
     Minion Four Zombiemod: none 
     Minion Four Name: Hex Giant
     Minion Four Weapon: none
     Minion Four Health: 50
     Minion Four Quantity: 10
     Minion Four Attack Range: 20
     Minion Four Strength: 3
     Minion Four Armour: 60
     Minion Four Speed: 2
     Minion Four Attack Rate: 40
     Minion Four Guardmode: bodyguard
     Minion Four Spawn Effect: lightning
     Minion Four Spawn Location: cuboid   
  actions:
    on assignment:
     - if !<npc.has_flag[ActionActive]> flag npc ActionActive duration:2s
     - flag npc PreventImmediateDespawn duration:2s
     - trigger name:proximity state:true 'radius:<npc.constant[Boss Awareness Range]>'
     - trigger name:damage state:true
     - flag npc 'cuboid:<el@val[<npc.constant[Cuboid Spawn Area Poss 1]>|<npc.constant[Cuboid Spawn Area Poss 2]>].as_cuboid>'
     - adjust <npc> 'set_entity_type:<npc.constant[Boss Entity Type]>'
     - if '<npc.constant[Boss Age]>' == baby {
      - age <npc> baby lock }
     - if '<npc.constant[Boss Entity Type]>' == player {
      - adjust <npc> 'skin:<npc.constant[Boss Skin]>' }
      else if '<npc.constant[Boss Entity Type]>' == zombie && '<npc.constant[Boss Zombiemod]>' != none {
        - execute as_server "npc select <npc.id>" silent
        - execute as_server "npc zombiemod <npc.constant[Boss Zombiemod]>" silent }
     - anchor id:BossSpawn add 'location:<npc.constant[Boss Spawn Location]>'
     - lookclose state:true 'range:<npc.constant[Boss Attack Range]>'
     - trait state:true pushable
     - flag npc jsentry.is_jsentry
     - flag npc jsentry.logic_group_<server.get_npcs_flagged[jsentry.is_jsentry].size.mod[10]||1>
     - flag npc 'jsentry.attackrate:<npc.constant[Boss Attack Rate]>'
     - flag npc 'jsentry.walkspeed:<npc.constant[Boss Movement Speed]>'
     - flag npc 'jsentry.damage:<npc.constant[Boss Strength]>'
     - flag npc 'jsentry.armour:<npc.constant[Boss Armour].div[100]>'
     - flag npc 'jsentry.range:<npc.constant[Boss Attack Range]>'
     - if '<npc.constant[Boss Weapon]>' != none {
      - equip <npc> 'hand:<npc.constant[Boss Weapon]>' }
     - flag npc jsentry.targets:player
     - flag npc 'Enabled Boss Stages:<npc.constant[Enabled Boss Stages]>'
     - flag npc ActionActive:!    
     - inject locally 'actions.on spawn' 
    on spawn:
     - if <npc.has_flag[ActionActive]> queue clear
     - flag npc PreventImmediateDespawn duration:2s

     - if !<el@val[l@x,y,z,world|l@x,y,z,world].as_cuboid.get_blocks[fire].is_empty> {
      - modifyblock <el@val[l@x,y,z,world|l@x,y,z,world].as_cuboid.get_blocks[fire]> air }

     - teleport <npc> 'location:<npc.constant[Boss Spawn Location]>'
     - flag global NewMoonBossID:<npc> 
     - if <global.flag[ListOfBosses].as_list||li@> !contain <npc> flag global ListOfBosses:->:<npc>
     - health state:true
     - vulnerable state:true
     - adjust <npc> 'max_health:<npc.constant[Boss Health]>'
     - adjust <npc> 'health:<npc.constant[Boss Health]>'
     - flag <npc> jsentry.target:!
     - if <npc.has_flag[BossDied]> {
      - flag npc BossDied:!
      - foreach <global.flag[AllMinions].as_list||li@> {
        - if !<util.npc_is_valid[%value%]> flag global AllMinions:<-:<util.as_element[%value%]>
          else if <%value%.flag[MinionCreator]||null> == <npc> {
          - flag global AllMinions:<-:%value%
          - remove %value% }
        }
      - define deathlocation <npc.flag[DeathLocation].as_location||null>
      - if <%deathlocation%.block.sign_contents||null> contains <npc.name> modifyblock %deathlocation% air
      - run "Pitboss Loot Chest Expiry"
     }
     - if <npc.constant[Scoreboard]> != none && !<npc.has_flag[Scoreboard]> {
      - flag npc Scoreboard:<npc.constant[Scoreboard]>
      - if <npc.flag[Scoreboard]> == "bosshealth" {
        - execute as_server "scoreboard objectives add <npc.name.substring[1,9]>.Damage dummy" silent
        - execute as_server "scoreboard objectives setDisplay sidebar <npc.name.substring[1,9]>.Damage" silent
        - queue clear }
      - if <npc.flag[Scoreboard]> == "minionkills" {
        - execute as_server "scoreboard objectives add <npc.name.substring[1,5]>.MinionKills dummy" silent
        - execute as_server "scoreboard objectives setDisplay sidebar <npc.name.substring[1,5]>.MinionKills" silent
        - queue clear }
      - if <npc.flag[Scoreboard]> == "minionhealth" {
        - execute as_server "scoreboard objectives add <npc.name.substring[1,6]>.MinionDmg dummy" silent
        - execute as_server "scoreboard objectives setDisplay sidebar <npc.name.substring[1,6]>.MinionDmg" silent 
        - queue clear }
     }
    on remove:
     - inject locally 'actions.on despawn'
    on death:
     - flag npc BossDied
     - if <queue.exists[<npc.name>SpecialAttack]> queue 'queue:<npc.name>SpecialAttack' clear 
     - foreach '<npc.flag[Enabled Boss Stages].as_list>' {
      - foreach '<npc.flag[Stage%value%Minions].as_list>' {  
        - flag global AllMinions:<-:%value%
        - if <npc> != %value% remove %value% 
      }                
     }
     - foreach '<npc.flag[Enabled Boss Stages].as_list>' {
      - flag npc 'Stage%value%Minions:!' 
      }
     - foreach <npc.flag[BossPlayerList].as_list||li@> {
      - if <def[value].is_online> adjust %value% show_boss_bar
      }
     - flag npc DeathLocation:<npc.location.simple>
     - sign <npc.flag[DeathLocation]> "<npc.name>|was defeated|here."
     - if <npc.has_flag[BossHitList]> {
      - announce "<green>-----------------------------------------------"
      - announce "<red>BOSS EVENT<&co> <white><npc.name><red> has been killed by <yellow><npc.flag[BossHitList].formatted>"
      - announce "<green>-----------------------------------------------"
      - announce "<green><underline>Battle Stats<&co><&r>  <red><npc.name> Total Health<&co> <npc.health.max.as_int>"
      - define maxHealth <npc.health.max>
      - define BossDamage '<npc.name>TotalDamage'
      - foreach <npc.flag[BossHitList].as_list> {
        - define PlayerBossDamage <%value%.flag[%BossDamage%].as_int||0>
        - define DamagePercent <el@val[<m:%PlayerBossDamage%/%maxHealth%*100>].as_int>
        - announce "<yellow><%value%.name>"
        - announce "<aqua>Boss Damage <gold>%PlayerBossDamage% (%DamagePercent%<&pc>) <aqua>- Hits <gold><%value%.flag[<npc.name>HitCount].as_int>"
        - define MinsDamage '<npc.name>MinsDamage'
        - if <%value%.flag[%MinsDamage%]||null> != null {
          - define MinsKilled <npc.name>MinsKilled
          - define MinsHit <npc.name>MinsHit
          - announce "<aqua>Combined Minion Damage <gold><%value%.flag[%MinsDamage%].as_int||0> <aqua>- Hits <gold><%value%.flag[%MinsHit%].as_int||0> <aqua>- Minions Killed <gold><%value%.flag[%MinsKilled%].as_int||0>" }
        - flag %value% <npc.name>TotalDamage:!
        - flag %value% <npc.name>HitCount:!
        - flag %value% <npc.name>MinsKilled:!
        - flag %value% <npc.name>MinsHit:!
        - flag %value% <npc.name>MinsDamage:! }
      - announce "<green>-----------------------------------------------" }
     - if <npc.has_flag[BossSpectatorList]> {
      - foreach <npc.flag[BossSpectatorList].as_list||li@> {
        - if <npc.flag[BossHitList].as_list> contains %value% flag npc BossSpectatorList:<-:%value% }
      - if <npc.flag[BossSpectatorList].size> >= 1 announce "Spectators <npc.flag[BossSpectatorList].formatted||none>" }
     - if '<npc.constant[Drop Loot on Death]>' == "Yes" run "Pitboss Drop the Loot" instantly
     - execute as_server "npc sel <npc.id>" silent
     - execute as_server "npc effect --play none" silent
     - flag <npc> jsentry.target:!
     - if <npc.has_flag[Scoreboard]> {
      - if <npc.flag[Scoreboard]> == "bosshealth" execute as_server "scoreboard objectives remove <npc.name.substring[1,9]>.Damage" silent
        else if <npc.flag[Scoreboard]> == "minionkills" execute as_server "scoreboard objectives remove <npc.name.substring[1,5]>.MinionKills" silent
        else if <npc.flag[Scoreboard]> == "minionhealth" execute as_server "scoreboard objectives remove <npc.name.substring[1,6]>.MinionDmg" silent
      - flag npc Scoreboard:!
     }
     - flag npc PreviousHealth:!
     - flag npc BossHitList:!
     - flag npc BossSpectatorList:!
     - flag npc BossStage:!
     - flag npc BossPlayerList:!
     - flag npc ActiveSpecialAttackStage:!
     - flag global ListOfBosses:<-:<npc>
     - flag npc MinionSpawnedStage:!
     - flag npc AllMyMinions:!
     - flag npc BossResetTimer:!
     - flag npc HealActive:!
    on despawn:
     - if <npc.has_flag[PreventImmediateDespawn]> queue clear
     - if <npc.has_flag[BossDied]||null> queue clear
     - define SpecialAttackQueue '<npc.name>SpecialAttack'
     - if <queue.exists[%SpecialAttackQueue%]> queue 'queue:%SpecialAttackQueue%' clear
     - define BossHealQueue <npc.name>_BossHeal
     - if <queue.exists[%BossHealQueue%]> queue 'queue:%BossHealQueue%' clear 
     - foreach '<npc.flag[Enabled Boss Stages].as_list>' {
      - if <npc.has_flag[Stage%value%Minions]> {
        - foreach <npc.flag[Stage%value%Minions].as_list> {
          - flag global AllMinions:<-:%value%
          - if <npc> != %value% remove %value% 
        }
      }
     }
     - foreach '<npc.flag[Enabled Boss Stages].as_list>' {
      - flag npc 'Stage%value%Minions:!' }
     - flag npc MinionSpawnedStage:!
     - foreach <npc.flag[BossPlayerList].as_list||li@> {
      - adjust %value% show_boss_bar
      }
     - if <npc.flag[BossHitList].size> >= 1 {
      - foreach <npc.flag[BossHitList].as_list> {
        - flag %value% <npc.name>TotalDamage:!
        - flag %value% <npc.name>HitCount:!
        - flag %value% <npc.name>MinsKilled:!
        - flag %value% <npc.name>MinsHit:!
        - flag %value% <npc.name>MinsDamage:! 
      }
     }
     - execute as_server "npc sel <npc.id>" silent
     - execute as_server "npc effect --play none" silent
     - flag <npc> jsentry.target:!
     - if <npc.has_flag[Scoreboard]> {
      - if <npc.flag[Scoreboard]> == bosshealth execute as_server "scoreboard objectives remove <npc.name.substring[1,9]>.Damage" silent
        else if <npc.flag[Scoreboard]> == minionkills execute as_server "scoreboard objectives remove <npc.name.substring[1,5]>.MinionKills" silent
        else if <npc.flag[Scoreboard]> == minionhealth execute as_server "scoreboard objectives remove <npc.name.substring[1,6]>.MinionDmg" silent
      - flag npc Scoreboard:!
     }
     - flag npc PreviousHealth:!
     - flag npc BossHitList:!
     - flag npc BossSpectatorList:!
     - flag npc BossStage:!
     - flag npc BossPlayerList:!
     - flag npc ActiveSpecialAttackStage:!
     - flag global ListOfBosses:<-:<npc>
     - flag npc AllMyMinions:!
     - flag npc BossResetTimer:!
     - flag npc HealActive:!   
    on damaged:
     - wait 1t
     - if <npc.has_flag[Died]> queue clear
     - if <context.damager> !matches player queue clear
     - if <npc.has_flag[DamageScriptActive]> determine cancelled else flag npc DamageScriptActive duration:1s
     - if <npc.flag[BossPlayerList].as_list||li@> !contains <context.damager> flag npc BossPlayerList:->:<context.damager>
     - if <npc.flag[BossHitList].as_list||li@> !contains <context.damager> flag npc BossHitList:->:<context.damager>
     - flag <context.damager> <npc.name>HitCount:++
     - define MaxHealth '<npc.constant[Boss Health]>'
     - define pHealth <npc.flag[PreviousHealth]||%MaxHealth%>
     - define cHealth <npc.health||0>
     - define DamageDealt <m:%pHealth%-%cHealth%>
     - if %DamageDealt% > 0 flag <context.damager> <npc.name>TotalDamage:+:%DamageDealt%
     - flag npc PreviousHealth:<npc.health||0>
     - flag npc DamageScriptActive:!
     - if <npc.flag[Scoreboard]||null> contains bosshealth { 
       - execute as_server "scoreboard players add <context.damager.name> <npc.name.substring[1,9]>.Damage <def[DamageDealt].as_int>" silent 
       }
     - foreach <npc.flag[BossPlayerList].as_list||li@> {
       - adjust %value% show_boss_bar:<npc.health.percentage.mul[2].as_int||0>|<npc.name>
       } 
     - if '<npc.health.percentage.as_int||0>' < 1 queue clear
     - define BossStage <npc.flag[BossStage]||null>
     - define BossHealth <npc.health.percentage.as_int||0>
     - define EnabledStages '<npc.flag[Enabled Boss Stages].as_list>'
     - if %EnabledStages% contains One && %BossStage% contains null && %BossHealth% <= '<npc.constant[Stage One Boss Health Percentage]>' {
         - flag npc BossStage:One
         - run "Pitboss Fight" 
         }
     - if %EnabledStages% contains Two && %BossStage% contains One && %BossHealth% <= '<npc.constant[Stage Two Boss Health Percentage]>' {
         - flag npc BossStage:Two
         - run "Pitboss Fight" 
         }
     - if %EnabledStages% contains Three && %BossStage% contains Two && %BossHealth% <= '<npc.constant[Stage Three Boss Health Percentage]>' {
         - flag npc BossStage:Three
         - run "Pitboss Fight" 
         }
     - if %EnabledStages% contains Four && %BossStage% contains Three && %BossHealth% <= '<npc.constant[Stage Four Boss Health Percentage]>' {
         - flag npc BossStage:Four
         - run "Pitboss Fight" 
         }         
    on push:
     - if '<npc.location.distance[<npc.constant[Boss Spawn Location]>]>' > '<npc.constant[Boss Attack Range]>' {
       - flag npc jsentry.target:!
       - flag npc jsentry.targets:!
       - anchor id:BossSpawn walknear r:10
       - flag npc jsentry.targets:player
       }
    on enter proximity:
     - if <player.flag[PlayerBossList].as_list||li@> !contains <npc> && <player.name> != <npc.name> flag player PlayerBossList:->:<npc>
     - if <npc.flag[BossPlayerList].as_list||li@> !contains <player> && <player.name> != <npc.name> flag npc BossPlayerList:->:<player>
     - if <npc.flag[BossSpectatorList].as_list||li@> !contains <player> && <player.name> != <npc.name> flag npc BossSpectatorList:->:<player>
     - adjust <player> show_boss_bar:<npc.health.percentage.mul[2].as_int||0>|<npc.name> 
     - if '<npc.constant[Bossfight Activator]>' == "proximity" && !<npc.has_flag[BossStage]> && !<npc.has_flag[BossDied]> {
       - flag npc BossStage:One
       - run "Pitboss Fight" 
       } 
     - if <queue.exists[<npc.name>_BossHeal]> queue 'queue:<npc.name>_BossHeal' clear
     - flag npc BossResetTimer:!
    on exit proximity:
     - define BossRange '<npc.constant[Boss Awareness Range]>'
     - adjust <player> show_boss_bar
     - flag player PlayerBossList:<-:<npc>    
     - wait 10s
     - define NearbyPlayersSize <npc.location.find.players.within[%BossRange%].size||0>
     - if %NearbyPlayersSize% < 1 && <npc.has_flag[BossStage]> && '<npc.constant[Boss Self Healing]>' == "Yes" {
       - run "Pitboss Self Heal" id:<npc.name>_BossHeal 
       }
     - if %NearbyPlayersSize% < 1 && <npc.has_flag[BossStage]> && '<npc.constant[Boss Reset Timer]>' >= 1 && !<npc.has_flag[BossResetTimer]> {
       - flag npc BossResetTimer
       - run "Pitboss Reset" id:<npc.name>_ResetTimer 'delay:<npc.constant[Boss Reset Timer]>'
       }
"Pitboss Fight":
   type: task
   debug: false
   script:
   - if <npc.has_flag[BossDied]||null> queue clear
   - define BossStage <npc.flag[BossStage]||none>
   - define SpecialAttack '<npc.constant[Stage %BossStage% Special Attack]||null>'
   - narrate "<red>Boss Stage %BossStage% - Health <npc.health.percentage.as_int><&pc>" targets:<npc.flag[BossPlayerList].as_list||null>
   - flag npc "CurrentSpecialAttack:%SpecialAttack%"
   - if flame|heart|smoke|ender|potbreak|explosion contains "<npc.constant[Stage %BossStage% Boss Aura]||none>" {
       - execute as_server "npc sel <npc.id>" silent
       - execute as_server "npc effect --play none" silent
       - execute as_server "npc effect --play <npc.constant[Stage %BossStage% Boss Aura]>" silent }
       else {
         - execute as_server "npc sel <npc.id>" silent
         - execute as_server "npc effect --play none" silent }
   - if '<npc.constant[Stage %BossStage% Spawn Minions]>' == "Yes" && <npc.flag[MinionSpawnedStage]||none> != %BossStage% {
     - flag npc MinionSpawnedStage:%BossStage%
     - define MinionSpawn '<npc.constant[Minion %BossStage% Spawn Location]>'
     - if %MinionSpawn% == cuboid define cuboid <npc.flag[cuboid]>
       else if %MinionSpawn% == boss {
         - define location <npc.location.simple>
         - define cuboid <el@val[<l@%location%.add[l@-5,0,-5]>|<l@%location%.add[l@5,1,5]>].as_cuboid> 
       }
     - repeat '<npc.constant[Minion %BossStage% Quantity]>' {
       - if %MinionSpawn% == player {
         - define selplayer <npc.flag[BossPlayerList].as_list.random||null>
         - define location <player[%selplayer%].location.simple>
         - define cuboid <el@val[<l@%location%.add[l@-3,0,-3]>|<l@%location%.add[l@3,1,3]>].as_cuboid> }
       - flag npc SpawnLocation:<%cuboid%.get_spawnable_blocks.random>
       - if '<npc.constant[Minion %BossStage% Type]>' != 'blaze' {
         - flag npc SpawnLocation:<%cuboid%.get_spawnable_blocks.random> }
         else {
           - flag npc flag npc SpawnLocation:<%cuboid%.get_spawnable_blocks.random.add[l@0,5,0]> }
       - run "Pitboss Spawn Minion" instantly 
     }
   }
   - if "Poison Arrow|Wither Arrow|Weakness Arrow|Slowness Arrow" contains %SpecialAttack% {
     - flag npc ActiveSpecialAttackStage:Arrows
     - run "Pitboss Special Attack - Arrows" id:<npc.name>SpecialAttack instantly
     }
     else if "Rain Arrows|Lightning Bolt|Lightning Storm|TNT|TNT Drop|Throw|Firestarter" contains %SpecialAttack% {
       - flag npc ActiveSpecialAttackStage:%SpecialAttack%
       - run "Pitboss Special Attack - %SpecialAttack%" id:<npc.name>SpecialAttack instantly
       }
     else flag npc ActiveSpecialAttackStage:!
"Pitboss Spawn Minion":
     type: task
     debug: false
     script:
     - define BossID <global.flag[NewMoonBossID]>
     - define BossStage <%BossID%.flag[BossStage]>
     - if "<%BossID%.constant[Minion %BossStage% Spawn Effect]>" == lightning strike no_damage location:<%BossID%.flag[SpawnLocation]>
       else if "<%BossID%.constant[Minion %BossStage% Spawn Effect]>" == explode explode power:1 location:<%BossID%.flag[SpawnLocation]>
     - create '<%BossID%.constant[Minion %BossStage% Type]>' '<%BossID%.constant[Minion %BossStage% Name]>' '<%BossID%.flag[SpawnLocation]>' save:Minion
     - execute as_server "npc select <entry[Minion].created_npc.id>" silent
     - execute as_server "npc assign --set 'Pitboss Minion Actions'" silent
"Pitboss Minion Actions":
  type: assignment
  debug: false
  actions:
    on assignment:
     - trigger name:click state:true
     - trigger name:damage state:true
     - define BossID <global.flag[NewMoonBossID]>
     - define BossStage <def[BossID].flag[BossStage]>
     - flag global AllMinions:->:<npc>
     - flag npc MinionCreator:%BossID%
     - flag npc 'MaxHealth:<def[BossID].constant[Minion %BossStage% Health]>'
     - flag %BossID% Stage%BossStage%Minions:->:<npc>
     - flag %BossID% AllMyMinions:->:<npc>
     - if '<def[BossID].constant[Minion %BossStage% Type]>' == zombie && '<def[BossID].constant[Minion %BossStage% Zombiemod]>' != none {
         - execute as_server "npc select <npc.id>" silent    
         - execute as_server "npc zombiemod <def[BossID].constant[Minion %BossStage% Zombiemod]>" silent }
         else {
         - if '<def[BossID].constant[Minion %BossStage% Type]>' contains player {
           - adjust <npc> 'skin:<def[BossID].constant[Minion %BossStage% Skin]>' }
         - if '<def[BossID].constant[Minion %BossStage% Age]>' == baby {
           - age <npc> baby lock }
         }
     - health state:true
     - vulnerable state:true
     - adjust <npc> 'max_health:<def[BossID].constant[Minion %BossStage% Health]>'
     - adjust <npc> 'health:<def[BossID].constant[Minion %BossStage% Health]>'
     - trait state:true pushable
     - flag npc jsentry.is_jsentry
     - flag npc jsentry.logic_group_<server.get_npcs_flagged[jsentry.is_jsentry].size.mod[10]>
     - flag npc 'jsentry.attackrate:<def[BossID].constant[Minion %BossStage% Attack Rate]>'
     - flag npc 'jsentry.walkspeed:<def[BossID].constant[Minion %BossStage% Speed]>'
     - flag npc 'jsentry.damage:<def[BossID].constant[Minion %BossStage% Strength]>'
     - flag npc 'jsentry.armour:<def[BossID].constant[Minion %BossStage% Armour].div[100]>'
     - flag npc 'jsentry.range:<def[BossID].constant[Minion %BossStage% Attack Range]>'
     - if '<def[BossID].constant[Minion %BossStage% Weapon]>' != none {
       - equip <npc> 'hand:<def[BossID].constant[Minion %BossStage% Weapon]>' }
     - if '<def[BossID].constant[Minion %BossStage% Guardmode]>' contains bodyguard {
       - flag npc 'jsentry.guard_target:%BossID%'
       - flag npc 'jsentry.follow_range:8'
       }
     - flag npc jsentry.targets:|:player|zombie|creeper|spider|skeleton|witch
    on death:
     - flag global AllMinions:<-:<npc>
     - flag <npc.flag[MinionCreator]> AllMyMinions:<-:<npc>
    on death by player:
     - define Boss <npc.flag[MinionCreator]>
     - flag player <def[Boss].name>MinsKilled:++
     - if <def[Boss].flag[Scoreboard]||null> == minionkills execute as_server "scoreboard players add <player.name> <def[Boss].name.substring[1,5]>.MinionKills 1" silent
    on click:
     - run "Health Status Bar"
    on damaged:
     - wait 1t
     - if <context.damager> matches player {
       - define player <context.damager> 
       }
       else determine cancelled
     - if <npc.has_flag[DamageScriptActive]> determine cancelled else flag npc DamageScriptActive duration:1s
     - define Boss <npc.flag[MinionCreator]>
     - if <def[Boss].is_spawned> {
       - if <def[Boss].flag[BossPlayerList].as_list||li@> !contains %player% && %player% != %Boss% {
         - flag %Boss% BossPlayerList:->:%player% }
       - if <def[Boss].flag[BossHitList].as_list||li@> !contains %player% && %player% != %Boss% {
         - flag %Boss% BossHitList:->:%player% }      
       - define MaxHealth <npc.flag[MaxHealth]>
       - define pHealth <npc.flag[PreviousHealth]||%MaxHealth%>
       - define cHealth <npc.health||0>
       - define DamageDealt <m:%pHealth%-%cHealth%>
       - if %DamageDealt% > 0 flag %player% <def[Boss].name>MinsDamage:+:%DamageDealt%
       - flag %player% <def[Boss].name>MinsHit:++
       - if <def[Boss].flag[Scoreboard]> == 'minionhealth' && %DamageDealt% > 0 { 
         - execute as_server "scoreboard players add <context.damager.name> <def[Boss].name.substring[1,6]>.MinionDmg %DamageDealt% silent
         }
       }    
     - flag npc PreviousHealth:<npc.health||0> 
     - flag npc DamageScriptActive:! 
"Pitboss Self Heal":
    type: task
    debug: false
    script:
    - define BossRange '<npc.constant[Boss Awareness Range]>'
    - if <npc.health> < <npc.health.max> && '<npc.location.find.players.within[%BossRange%].size||0>' < 1 && !<npc.has_flag[HealActive]> {
      - flag npc HealActive
      - adjust <npc> 'health:<npc.health.add[1]>'
      - wait 5
      - flag npc HealActive:!
      - run "Pitboss Self Heal" id:<npc.name>_BossHeal }
"Pitboss Reset":
  type: task
  debug: false
  script:
  - ^if <npc.has_flag[BossResetTimer]> {
    - define SpecialAttackQueue '<npc.name>SpecialAttack'
    - if <queue.exists[%SpecialAttackQueue%]> queue 'queue:%SpecialAttackQueue%' clear
    - foreach '<npc.flag[Enabled Boss Stages].as_list>' {
      - if <npc.has_flag[Stage%value%Minions]> {
        - foreach <npc.flag[Stage%value%Minions].as_list> {
          - if <npc> != %value% remove %value% 
        }
      }
    }
    - foreach '<npc.flag[Enabled Boss Stages].as_list>' {
      - flag npc Stage%value%Minions:! }

    - narrate "<red>BOSS EVENT<&co> <white><npc.name><red> has been reset." targets:<npc.flag[BossPlayerList].as_list>
    - if <npc.flag[BossHitList].size> >= 1 {
      - foreach <npc.flag[BossHitList].as_list> {
        - flag %value% <npc.name>TotalDamage:!
        - flag %value% <npc.name>HitCount:!
        - flag %value% <npc.name>MinsKilled:!
        - flag %value% <npc.name>MinsHit:!
        - flag %value% <npc.name>MinsDamage:! }
    }
    - execute as_server "npc sel <npc.id>" silent
    - execute as_server "npc effect --play none" silent
    - execute as_server "sentry target clear" silent
    - if <npc.has_flag[Scoreboard]> {
      - if <npc.flag[Scoreboard]> == bosshealth execute as_server "scoreboard objectives remove <npc.name.substring[1,9]>.Damage" silent
        else if <npc.flag[Scoreboard]> == minionkills execute as_server "scoreboard objectives remove <npc.name.substring[1,5]>.MinionKills" silent
        else if <npc.flag[Scoreboard]> == minionhealth execute as_server "scoreboard objectives remove <npc.name.substring[1,6]>.MinionDmg" silent
    }
    - teleport <npc> "location:<npc.constant[Boss Spawn Location]>"
    - adjust <npc> 'health:<npc.constant[Boss Health]>'
    - flag npc PreviousHealth:!
    - flag npc BossHitList:!
    - flag npc BossSpectatorList:!
    - flag npc BossStage:!
    - flag npc BossPlayerList:!
    - flag npc ActiveSpecialAttackStage:!
    - flag npc MinionSpawnedStage:!
    - flag npc Scoreboard:!
    - flag npc AllMyMinions:!
    - flag npc BossResetTimer:!
    - flag npc HealActive:!
  }

"Pitboss Special Attack - Arrows":
  type: task
  debug: false
  script:
  - if <npc.has_flag[PreventDoubleAttack]> && <npc.flag[ActiveSpecialAttackStage]||null> == "Arrows" {
    - wait 5s
    - if <npc.flag[ActiveSpecialAttackStage]||null> == "Arrows" {
      - run "Pitboss Special Attack - Arrows" id:<npc.name>SpecialAttack
    }
  }
    else if !<npc.has_flag[ActiveSpecialAttackStage]> || <npc.flag[ActiveSpecialAttackStage]||null> == "Arrows" {
      - define BossStage <npc.flag[BossStage]||null>
      - define NearbyPlayers '<npc.location.find.players.within[<npc.constant[Boss Awareness Range]>].as_list||null>'
      - if <def[NearbyPlayers].size> >= 1 && %BossStage% != null {
        - flag npc ActiveSpecialAttackStage:Arrows
        - flag npc PreventDoubleAttack "duration:<npc.constant[Stage %BossStage% Special Attack Delay]>"
        - define arrowplayer <def[NearbyPlayers].random>
        - narrate "<yellow><npc.name><red> shoots a <npc.flag[CurrentSpecialAttack]> towards <yellow><def[arrowplayer].name.display.replace[~]><red>..." targets:<npc.flag[BossPlayerList].as_list>
        - shoot arrow origin:<npc> destination:<def[arrowplayer].location> speed:50 lead:<def[arrowplayer].as_entity.velocity> 'script:Pitboss Special Arrow Handler'
        - wait '<npc.constant[Stage %BossStage% Special Attack Delay]>'
        - if <npc.flag[ActiveSpecialAttackStage]||null> == "Arrows" {
          - run "Pitboss Special Attack - Arrows" id:<npc.name>SpecialAttack
        }
      }
    }    
"Pitboss Special Attack - Rain Arrows":
  type: task
  debug: true
  script:
  - if <npc.has_flag[PreventDoubleAttack]> && <npc.flag[ActiveSpecialAttackStage]||null>> == "Rain Arrows" {
    - wait 5s
    - if <npc.flag[ActiveSpecialAttackStage]||null> == "Rain Arrows" {
      - run "Pitboss Special Attack - Rain Arrows" id:<npc.name>SpecialAttack
    }
  }
    else if !<npc.has_flag[ActiveSpecialAttackStage]> || <npc.flag[ActiveSpecialAttackStage]||null> == "Rain Arrows" {
      - define BossStage <npc.flag[BossStage]||null>
      - if '<npc.location.find.players.within[<npc.constant[Boss Awareness Range]>].as_list.size||0>' >= 1 && %BossStage% != null {
        - flag npc "ActiveSpecialAttackStage:Rain Arrows"
        - flag npc PreventDoubleAttack "duration:<npc.constant[Stage %BossStage% Special Attack Delay]>"
        - narrate "<yellow><npc.name><red> causes it to Rain Arrows..." targets:<npc.flag[BossPlayerList].as_list>
        - define roof <npc.flag[cuboid].max.y.add[-1]>
        - define minX <npc.flag[cuboid].min.x.add[+1].as_int>
        - define maxX <npc.flag[cuboid].max.x.add[-1].as_int>
        - define minZ <npc.flag[cuboid].min.z.add[+1].as_int>
        - define maxZ <npc.flag[cuboid].max.z.add[-1].as_int>
        - repeat '<npc.constant[Stage %BossStage% Special Attack Quantity]||200>' {  
          - define XinRange <util.random.int[%minX%].to[%maxX%]>
          - define ZinRange <util.random.int[%minZ%].to[%maxZ%]>
          - spawn i@arrow 'origin:%XinRange%,%roof%,%ZinRange%,<npc.constant[World Name]>' }
        - wait '<npc.constant[Stage %BossStage% Special Attack Delay]>'
        - if <npc.flag[ActiveSpecialAttackStage]||null>> == "Rain Arrows" {
          - run "Pitboss Special Attack - Rain Arrows" id:<npc.name>SpecialAttack
        }
      }
    }
"Pitboss Special Attack - Lightning Bolt":
  type: task
  debug: true
  script:
  - if <npc.has_flag[PreventDoubleAttack]> && <npc.flag[ActiveSpecialAttackStage]||null> == "Lightning Bolt" {
    - wait 5s
    - if <npc.flag[ActiveSpecialAttackStage]||null> == "Lightning Bolt" {
      - run "Pitboss Special Attack - Lightning Bolt" id:<npc.name>SpecialAttack
    }
  }
    else if !<npc.has_flag[ActiveSpecialAttackStage]> || <npc.flag[ActiveSpecialAttackStage]||null> == "Lightning Bolt" {
      - define BossStage <npc.flag[BossStage]||null>
      - define NearbyPlayers '<npc.location.find.players.within[<npc.constant[Boss Awareness Range]>].as_list||null>'
      - if <def[NearbyPlayers].size> >= 1 && %BossStage% != null {
        - flag npc "ActiveSpecialAttackStage:Lightning Bolt"
        - flag npc PreventDoubleAttack "duration:<npc.constant[Stage %BossStage% Special Attack Delay]>"
        - define lightningplayer <def[NearbyPlayers].random>
        - narrate "<yellow><npc.name><red> calls a Lightning Bolt to hit <yellow><def[lightningplayer].name.display.replace[~]><red>..." targets:<npc.flag[BossPlayerList].as_list>
        - strike destination:<def[lightningplayer].location>
        - wait '<npc.constant[Stage %BossStage% Special Attack Delay]>'
        - if <npc.flag[ActiveSpecialAttackStage]||null> == "Lightning Bolt" {
          - run "Pitboss Special Attack - Lightning Bolt" id:<npc.name>SpecialAttack
        }
      }
    }
"Pitboss Special Attack - Lightning Storm":
  type: task
  debug: true
  script:
  - if <npc.has_flag[PreventDoubleAttack]> && <npc.flag[ActiveSpecialAttackStage]||null> == "Lightning Storm" {
    - wait 5s
    - if <npc.flag[ActiveSpecialAttackStage]||null> == "Lightning Storm" {
      - run "Pitboss Special Attack - Lightning Storm" id:<npc.name>SpecialAttack
    }
  }
    else if !<npc.has_flag[ActiveSpecialAttackStage]> || <npc.flag[ActiveSpecialAttackStage]||null> == "Lightning Storm" {
      - define BossStage <npc.flag[BossStage]>
      - if '<npc.location.find.players.within[<npc.constant[Boss Awareness Range]>].as_list.size||0>' >= 1 && %BossStage% != null {
        - flag npc "ActiveSpecialAttackStage:Lightning Storm"
        - flag npc PreventDoubleAttack "duration:<npc.constant[Stage %BossStage% Special Attack Delay]>"
        - narrate "<yellow><npc.name><red> calls a Lightning Storm!" targets:<npc.flag[BossPlayerList].as_list>
        - define floor <npc.flag[cuboid].min.y>
        - define minX <npc.flag[cuboid].min.x.add[+1].as_int>
        - define maxX <npc.flag[cuboid].max.x.add[-1].as_int>
        - define minZ <npc.flag[cuboid].min.z.add[+1].as_int>
        - define maxZ <npc.flag[cuboid].max.z.add[-1].as_int>
        - repeat '<npc.constant[Stage %BossStage% Special Attack Quantity]||20>' { 
          - define Xrange <util.random.int[%minX%].to[%maxX%]>
          - define Zrange <util.random.int[%minZ%].to[%maxZ%]>
          - strike 'destination:%Xrange%,%floor%,%Zrange%,<npc.constant[World Name]>' }
        - wait '<npc.constant[Stage %BossStage% Special Attack Delay]>'
        - if <npc.flag[ActiveSpecialAttackStage]||null> == "Lightning Storm" {
          - run "Pitboss Special Attack - Lightning Storm" id:<npc.name>SpecialAttack
        }
      }
    }
"Pitboss Special Attack - TNT":
  type: task
  debug: true
  script:
  - if <npc.has_flag[PreventDoubleAttack]> && <npc.flag[ActiveSpecialAttackStage]||null> == "TNT" {
    - wait 5s
    - if <npc.flag[ActiveSpecialAttackStage]||null> == "TNT" {
      - run "Pitboss Special Attack - TNT" id:<npc.name>SpecialAttack
    }
  }
    else if !<npc.has_flag[ActiveSpecialAttackStage]> || <npc.flag[ActiveSpecialAttackStage]||null> == "TNT" {
      - define BossStage <npc.flag[BossStage]>
      - define NearbyPlayers '<npc.location.find.players.within[<npc.constant[Boss Awareness Range]>].as_list||null>'
      - if <def[NearbyPlayers].size> >= 1 && %BossStage% != null {
        - flag npc ActiveSpecialAttackStage:TNT
        - flag npc PreventDoubleAttack 'duration:<npc.constant[Stage %BossStage% Special Attack Delay]>'
        - define targetplayer <def[NearbyPlayers].random>
        - narrate "<yellow><npc.name><red> lobs TNT at <yellow><def[targetplayer].name.display.replace[~]><red>..." targets:<npc.flag[BossPlayerList].as_list>
        - playsound <def[targetplayer].location> sound:fuse
        - shoot e@primed_tnt origin:<npc> destination:<def[targetplayer].location.simple> Height:0.5
        - wait <npc.constant[Stage %BossStage% Special Attack Delay]>'
        - if <npc.flag[ActiveSpecialAttackStage]||null> == "TNT"  {
          - run "Pitboss Special Attack - TNT" id:<npc.name>SpecialAttack
        }
      }
    }
"Pitboss Special Attack - TNT Drop":
  type: task
  debug: false
  script:
  - if <npc.has_flag[PreventDoubleAttack]> && <npc.flag[ActiveSpecialAttackStage]||null> == "TNT Drop" {
    - wait 5s
    - if <npc.flag[ActiveSpecialAttackStage]||null> == "TNT Drop" {
      - run "Pitboss Special Attack - TNT Drop" id:<npc.name>SpecialAttack
    }
  }
    else if !<npc.has_flag[ActiveSpecialAttackStage]> || <npc.flag[ActiveSpecialAttackStage]||null> == "TNT Drop" {
      - define BossStage <npc.flag[BossStage]>
      - if '<npc.location.find.players.within[<npc.constant[Boss Awareness Range]>].as_list.size||0>' >= 1 && %BossStage% != null {
        - flag npc 'ActiveSpecialAttackStage:TNT Drop'
        - flag npc PreventDoubleAttack 'duration:<npc.constant[Stage %BossStage% Special Attack Delay]>'
        - narrate "<yellow><npc.name><red> drops primed TNT.. TAKE COVER!" targets:<npc.flag[BossPlayerList].as_list>
        - define roof <npc.flag[cuboid].max.y.add[-1]>
        - define minX <npc.flag[cuboid].min.x.add[+1].as_int>
        - define maxX <npc.flag[cuboid].max.x.add[-1].as_int>
        - define minZ <npc.flag[cuboid].min.z.add[+1].as_int>
        - define maxZ <npc.flag[cuboid].max.z.add[-1].as_int>
        - repeat '<npc.constant[Stage %BossStage% Special Attack Quantity]||25>' {
          - define Xrange <util.random.int[%minX%].to[%maxX%]>
          - define Zrange <util.random.int[%minZ%].to[%maxZ%]>
          - spawn e@primed_tnt 'origin:%Xrange%,%roof%,%Zrange%,<npc.constant[World Name]>' 
        }
        - wait '<npc.constant[Stage %BossStage% Special Attack Delay]>'
        - if <npc.flag[ActiveSpecialAttackStage]||null> == "TNT Drop" {
          - run "Pitboss Special Attack - TNT Drop" id:<npc.name>SpecialAttack
        }
      }
    }
"Pitboss Special Attack - Throw":
  type: task
  debug: true
  script:
  - if <npc.has_flag[PreventDoubleAttack]> && <npc.flag[ActiveSpecialAttackStage]||null> == "Throw" {
    - wait 5s
    - if <npc.flag[ActiveSpecialAttackStage]||null> == "Throw" {
      - run "Pitboss Special Attack - Throw" id:<npc.name>SpecialAttack
    }
  }
    else if !<npc.has_flag[ActiveSpecialAttackStage]> || <npc.flag[ActiveSpecialAttackStage]||null> == "Throw" {
      - define BossStage <npc.flag[BossStage]>
      - define NearbyPlayers '<npc.location.find.players.within[<npc.constant[Boss Awareness Range]>].as_list||null>'
      - if <def[NearbyPlayers].size> >= 1 && %BossStage% != null {
        - flag npc PreventDoubleAttack "duration:<npc.constant[Stage %BossStage% Special Attack Delay]>"
        - flag npc ActiveSpecialAttackStage:Throw
        - flag npc 'ThrowList:|:<def[NearbyPlayers].random[<def[NearbyPlayers].size.div[2].as_int||1>]>'
        - narrate "<yellow><npc.name><red> throws <npc.flag[Throwlist].formatted>..." targets:<npc.flag[BossPlayerList].as_list>
        - define cuboid <npc.flag[cuboid]>
        - define roof <%cuboid%.max.y.add[-1]>
        - define minX <%cuboid%.min.x.as_int>
        - define maxX <%cuboid%.max.x.as_int>
        - define minZ <%cuboid%.min.z.as_int>
        - define maxZ <%cuboid%.max.z.as_int>
        - foreach <npc.flag[Throwlist].as_list> {
          - define Xrange <util.random.int[%minX%].to[%maxX%]>
          - define Zrange <util.random.int[%minZ%].to[%maxZ%]>
          - shoot %value% origin:<%value%.location.simple> 'destination:%Xrange%,%roof%,%Zrange%,<npc.constant[World Name]>' height:1.8 gravity:0.32 }
        - flag npc ThrowList:!
        - wait '<npc.constant[Stage %BossStage% Special Attack Delay]>'
        - if <npc.flag[ActiveSpecialAttackStage]||null> == "Throw" {
          - run "Pitboss Special Attack - Throw" id:<npc.name>SpecialAttack
        }
      }
    }
"Pitboss Special Attack - Firestarter":
  type: task
  debug: false
  script:
  - if <npc.has_flag[PreventDoubleAttack]> && <npc.flag[ActiveSpecialAttackStage]||null> == "Firestarter" {
    - wait 5s
    - if <npc.flag[ActiveSpecialAttackStage]||null> == Firestarter {
      - run "Pitboss Special Attack - Firestarter" 'id:<npc.name>SpecialAttack'
    }
  }
    else if !<npc.has_flag[ActiveSpecialAttackStage]> || <npc.flag[ActiveSpecialAttackStage]||null> == Firestarter {
      - define BossStage <npc.flag[BossStage]>
      - if <npc.location.find.players.within[<npc.constant[Boss Awareness Range]>].as_list.size||0>' >= 1 && %BossStage% != null {
        - flag npc PreventDoubleAttack 'duration:<npc.constant[Stage %BossStage% Special Attack Delay]>'
        - flag npc ActiveSpecialAttackStage:Firestarter
        - narrate "<yellow><npc.name><red> sets the place on fire..." targets:<npc.flag[BossPlayerList].as_list>
        - repeat '<npc.constant[Stage %BossStage% Special Attack Quantity]||20>' {
          - modifyblock location:<npc.flag[cuboid].get_spawnable_blocks.random> fire }
        - wait '<npc.constant[Stage %BossStage% Special Attack Delay]>'
        - if <npc.flag[ActiveSpecialAttackStage]||null> == "Firestarter" {
          - run "Pitboss Special Attack - Firestarter" 'id:<npc.name>SpecialAttack'
        } 
      }
    }    
"Pitboss Special Arrow Handler":
  type: task
  debug: true
  script:
  - if %hit_entities% == li@ remove %shot_entities%
  - define location %location%
  - define hearers <npc.flag[BossPlayerList].as_list||li@>
  - define startMsg '<red>...and hits <yellow><%hit_entities%.name||noone><red>,'
  - inject locally <npc.flag[CurrentSpecialAttack]>
   'Poison Arrow': 
     - cast poison duration:3 power:1 %hit_entities%
     - random {
       - narrate "%StartMsg% causing them to bleed from the ears." 'targets:%hearers%'
       - narrate "%StartMsg% causing agonising pain and loss of health." 'targets:%hearers%'
       - narrate "%StartMsg% causing itchy and burning skin blisters." 'targets:%hearers%' 
     }      
   'Wither Arrow':
     - cast wither duration:3 power:1 %hit_entities%
     - random {
       - narrate "%StartMsg% causing their skin to peel off." 'targets:%hearers%'
       - narrate "%StartMsg% causing their limbs to decay." 'targets:%hearers%'
       - narrate "%StartMsg% causing their skin to ooze." 'targets:%hearers%'
     }
   'Weakness Arrow':
     - cast weakness duration:3 power:1 %hit_entities%
     - random {
       - narrate "%StartMsg% causing them to become weak and tired." 'targets:%hearers%'
       - narrate "%StartMsg% causing them to deal less damage." 'targets:%hearers%'
       - narrate "%StartMsg% causing them to hit like a little girl." 'targets:%hearers%'
     }
   'Slowness Arrow':
     - cast slow duration:10 power:3 %hit_entities%
     - random {
       - narrate "%StartMsg% causing them to become slow and lazy." 'targets:%hearers%'
       - narrate "%StartMsg% causing them to walk at a snails pace." 'targets:%hearers%'
       - narrate "%StartMsg% making them slower than a speeding microorganism." 'targets:%hearers%'
       - narrate "%StartMsg% making them slower than a 1 legged dog on tranquilizers." 'targets:%hearers%'
       - narrate "%StartMsg% making them slower than a geriatric slug on a salted snowed-in street." 'targets:%hearers%'
       - narrate "%StartMsg% making them slower than a snail traveling through peanut butter." 'targets:%hearers%'
       - narrate "%StartMsg% causing them to be slower than Java." 'targets:%hearers%'
     }
"Pitboss Drop the Loot":
    type: task
    debug: true
    script:
    - if '<npc.constant[Loot Distribution]>' == player {
      - foreach <npc.flag[BossHitList].as_list> {
        - repeat '<npc.constant[Loot Quantity]>' {
          - give to:<%value%.inventory> 'i@<proc:Bossfight Determine Loot>' }
      }
      - queue clear }

    - if '<npc.constant[Loot Distribution]>' == boss {
      - foreach <npc.flag[BossHitList].as_list> {
        - repeat '<npc.constant[Loot Quantity]>' {
          - drop 'i@<proc:Bossfight Determine Loot>' location:<npc.flag[DeathLocation]> }
        }
      - queue clear }

    - if '<npc.constant[Loot Distribution]>' == chest {
      - define location <npc.location.simple>
      - define cuboid <el@val[<l@%location%.add[l@-2,0,-2]>|<l@%location%.add[l@2,1,2]>].as_cuboid>
      - define chestlocation <%cuboid%.get_spawnable_blocks.random.block.as_location.block>
      - flag npc LootChestLocationList:->:%chestlocation% 
      - define signlocation <%chestlocation%.add[l@0,1,0]>
      - modifyblock location:%chestlocation% chest
      - sign %signlocation% "Loot Chest|for|all warriors|to share"
      - foreach <npc.flag[BossHitList].as_list> {
        - repeat '<npc.constant[Loot Quantity]>' {
          - give "i@<proc:Bossfight Determine Loot>" to:<%chestlocation%.inventory> 
          }
        }
      }  
      else if '<npc.constant[Loot Distribution]>' == playerchest {
        - flag npc PlayersGettingChest:<npc.flag[BossHitList]>
        - foreach <npc.flag[BossHitList].as_list> {
          - define location <%value%.location.simple>
          - define cuboid <el@val[<l@%location%.add[l@-2,0,-2]>|<l@%location%.add[l@2,1,2]>].as_cuboid>
          - define chestlocation <%cuboid%.get_spawnable_blocks.random.as_location.block>
          - flag %value% LootChestLocation:%chestlocation%
          - flag npc LootChestLocationList:->:%chestlocation%
          - flag global LootChestList:->:%chestlocation%
          - modifyblock location:%chestlocation% chest
          - sign <%chestlocation%.add[l@0,1,0]> "Loot Chest|for|<%value%.name.display.replace[~]>"
          - repeat '<npc.constant[Loot Quantity]>' {
            - give 'i@<proc:Bossfight Determine Loot>' to:<%chestlocation%.inventory> 
            }
          }
        }
    - if <npc.flag[LootChestLocationList].size||0> >= 1 && '<npc.constant[Loot Chest Expiry]>' >= 1 {
      - run "Pitboss Loot Chest Expiry" 'delay:<npc.constant[Loot Chest Expiry]>'
      }
"Pitboss Loot Chest Expiry":
    type: task
    debug: false
    script:
    - ^foreach <npc.flag[LootChestLocationList].as_list||li@> {
      - if <location[%value%].block.material||null> == 'm@chest,3' {
        - flag global LootChestList:<-:%value%
        - modifyblock <%value%.add[l@0,1,0]> air 
        - modifyblock %value% air 
      }
    }
    - ^foreach <npc.flag[PlayersGettingChest].as_list||li@> {
      - flag %value% LootChestLocation:! }
    - ^flag npc PlayersGettingChest:!
    - ^flag npc LootChestLocationList:!