@@ -17,6 +17,20 @@ export function initConfig() {
17
17
return midiAction ;
18
18
} ;
19
19
20
+ const getActivationType = ( item ) => {
21
+ if ( ! item ?. system ?. activities ) {
22
+ return
23
+ }
24
+ return Array . from ( item . system . activities ) [ 0 ] ?. activation ?. type ;
25
+ }
26
+
27
+ const getActionType = ( item ) => {
28
+ if ( ! item ?. system ?. activities ) {
29
+ return
30
+ }
31
+ return Array . from ( item . system . activities ) [ 0 ] ?. actionType ;
32
+ }
33
+
20
34
const actionTypes = {
21
35
action : [ "action" ] ,
22
36
bonus : [ "bonus" ] ,
@@ -72,7 +86,7 @@ export function initConfig() {
72
86
switch ( itemType ) {
73
87
case "weapon" :
74
88
subtitle = CONFIG . DND5E . weaponTypes [ item . system . weaponType ] ;
75
- properties . push ( CONFIG . DND5E . itemActionTypes [ item . system . actionType ] ) ;
89
+ properties . push ( CONFIG . DND5E . itemActionTypes [ getActionType ( item ) ] ) ;
76
90
for ( let [ key , value ] of Object . entries ( item . system . properties ) ) {
77
91
let prop = value && CONFIG . DND5E . weaponProperties [ key ] ? CONFIG . DND5E . weaponProperties [ key ] : undefined ;
78
92
if ( prop ) properties . push ( prop ) ;
@@ -90,11 +104,11 @@ export function initConfig() {
90
104
break ;
91
105
case "consumable" :
92
106
subtitle = CONFIG . DND5E . consumableTypes [ item . system . consumableType ] ;
93
- properties . push ( CONFIG . DND5E . itemActionTypes [ item . system . actionType ] ) ;
107
+ properties . push ( CONFIG . DND5E . itemActionTypes [ getActionType ( item ) ] ) ;
94
108
break ;
95
109
case "feat" :
96
110
subtitle = item . system . requirements ;
97
- properties . push ( CONFIG . DND5E . itemActionTypes [ item . system . actionType ] ) ;
111
+ properties . push ( CONFIG . DND5E . itemActionTypes [ getActionType ( item ) ] ) ;
98
112
break ;
99
113
}
100
114
}
@@ -474,9 +488,9 @@ export function initConfig() {
474
488
}
475
489
476
490
async _getButtons ( ) {
477
- const spellItems = this . actor . items . filter ( ( item ) => itemTypes . spell . includes ( item . type ) && actionTypes . action . includes ( item . system . activation ?. type ) && ! CoreHUD . DND5E . mainBarFeatures . includes ( item . system . type ?. value ) ) ;
478
- const featItems = this . actor . items . filter ( ( item ) => itemTypes . feat . includes ( item . type ) && actionTypes . action . includes ( item . system . activation ?. type ) && ! CoreHUD . DND5E . mainBarFeatures . includes ( item . system . type ?. value ) ) ;
479
- const consumableItems = this . actor . items . filter ( ( item ) => itemTypes . consumable . includes ( item . type ) && actionTypes . action . includes ( item . system . activation ?. type ) && ! CoreHUD . DND5E . mainBarFeatures . includes ( item . system . type ?. value ) ) ;
491
+ const spellItems = this . actor . items . filter ( ( item ) => itemTypes . spell . includes ( item . type ) && actionTypes . action . includes ( getActivationType ( item ) ) && ! CoreHUD . DND5E . mainBarFeatures . includes ( item . system . type ?. value ) ) ;
492
+ const featItems = this . actor . items . filter ( ( item ) => itemTypes . feat . includes ( item . type ) && actionTypes . action . includes ( getActivationType ( item ) ) && ! CoreHUD . DND5E . mainBarFeatures . includes ( item . system . type ?. value ) ) ;
493
+ const consumableItems = this . actor . items . filter ( ( item ) => itemTypes . consumable . includes ( item . type ) && actionTypes . action . includes ( getActivationType ( item ) ) && ! CoreHUD . DND5E . mainBarFeatures . includes ( item . system . type ?. value ) ) ;
480
494
481
495
const spellButton = ! spellItems . length ? [ ] : [ new DND5eButtonPanelButton ( { type : "spell" , items : spellItems , color : 0 } ) ] . filter ( ( button ) => button . hasContents ) ;
482
496
@@ -490,7 +504,7 @@ export function initConfig() {
490
504
buttons . push ( ...[ new DND5eItemButton ( { item : null , isWeaponSet : true , isPrimary : true } ) , ...spellButton , new DND5eButtonPanelButton ( { type : "feat" , items : featItems , color : 0 } ) , new DND5eButtonPanelButton ( { type : "consumable" , items : consumableItems , color : 0 } ) ] ) ;
491
505
}
492
506
493
- const barItems = this . actor . items . filter ( ( item ) => CoreHUD . DND5E . mainBarFeatures . includes ( item . system . type ?. value ) && actionTypes . action . includes ( item . system . activation ?. type ) ) ;
507
+ const barItems = this . actor . items . filter ( ( item ) => CoreHUD . DND5E . mainBarFeatures . includes ( item . system . type ?. value ) && actionTypes . action . includes ( getActivationType ( item ) ) ) ;
494
508
buttons . push ( ...condenseItemButtons ( barItems ) ) ;
495
509
496
510
return buttons . filter ( ( button ) => button . hasContents || button . items == undefined || button . items . length ) ;
@@ -522,13 +536,13 @@ export function initConfig() {
522
536
async _getButtons ( ) {
523
537
const buttons = [ new DND5eItemButton ( { item : null , isWeaponSet : true , isPrimary : false } ) ] ;
524
538
for ( const [ type , types ] of Object . entries ( itemTypes ) ) {
525
- const items = this . actor . items . filter ( ( item ) => types . includes ( item . type ) && actionTypes . bonus . includes ( item . system . activation ?. type ) && ! CoreHUD . DND5E . mainBarFeatures . includes ( item . system . type ?. value ) ) ;
539
+ const items = this . actor . items . filter ( ( item ) => types . includes ( item . type ) && actionTypes . bonus . includes ( getActivationType ( item ) ) && ! CoreHUD . DND5E . mainBarFeatures . includes ( item . system . type ?. value ) ) ;
526
540
if ( ! items . length ) continue ;
527
541
const button = new DND5eButtonPanelButton ( { type, items, color : 1 } ) ;
528
542
if ( button . hasContents ) buttons . push ( button ) ;
529
543
}
530
544
531
- const barItems = this . actor . items . filter ( ( item ) => CoreHUD . DND5E . mainBarFeatures . includes ( item . system . type ?. value ) && actionTypes . bonus . includes ( item . system . activation ?. type ) ) ;
545
+ const barItems = this . actor . items . filter ( ( item ) => CoreHUD . DND5E . mainBarFeatures . includes ( item . system . type ?. value ) && actionTypes . bonus . includes ( getActivationType ( item ) ) ) ;
532
546
buttons . push ( ...condenseItemButtons ( barItems ) ) ;
533
547
534
548
return buttons ;
@@ -561,13 +575,13 @@ export function initConfig() {
561
575
const buttons = [ new DND5eItemButton ( { item : null , isWeaponSet : true , isPrimary : true } ) ] ;
562
576
//buttons.push(new DND5eEquipmentButton({slot: 1}));
563
577
for ( const [ type , types ] of Object . entries ( itemTypes ) ) {
564
- const items = this . actor . items . filter ( ( item ) => types . includes ( item . type ) && actionTypes . reaction . includes ( item . system . activation ?. type ) && ! CoreHUD . DND5E . mainBarFeatures . includes ( item . system . type ?. value ) ) ;
578
+ const items = this . actor . items . filter ( ( item ) => types . includes ( item . type ) && actionTypes . reaction . includes ( getActivationType ( item ) ) && ! CoreHUD . DND5E . mainBarFeatures . includes ( item . system . type ?. value ) ) ;
565
579
if ( ! items . length ) continue ;
566
580
const button = new DND5eButtonPanelButton ( { type, items, color : 3 } ) ;
567
581
if ( button . hasContents ) buttons . push ( button ) ;
568
582
}
569
583
570
- const barItems = this . actor . items . filter ( ( item ) => CoreHUD . DND5E . mainBarFeatures . includes ( item . system . type ?. value ) && actionTypes . reaction . includes ( item . system . activation ?. type ) ) ;
584
+ const barItems = this . actor . items . filter ( ( item ) => CoreHUD . DND5E . mainBarFeatures . includes ( item . system . type ?. value ) && actionTypes . reaction . includes ( getActivationType ( item ) ) ) ;
571
585
buttons . push ( ...condenseItemButtons ( barItems ) ) ;
572
586
573
587
return buttons ;
@@ -600,13 +614,13 @@ export function initConfig() {
600
614
const buttons = [ ] ;
601
615
602
616
for ( const [ type , types ] of Object . entries ( itemTypes ) ) {
603
- const items = this . actor . items . filter ( ( item ) => types . includes ( item . type ) && actionTypes . free . includes ( item . system . activation ?. type ) && ! CoreHUD . DND5E . mainBarFeatures . includes ( item . system . type ?. value ) ) ;
617
+ const items = this . actor . items . filter ( ( item ) => types . includes ( item . type ) && actionTypes . free . includes ( getActivationType ( item ) ) && ! CoreHUD . DND5E . mainBarFeatures . includes ( item . system . type ?. value ) ) ;
604
618
if ( ! items . length ) continue ;
605
619
const button = new DND5eButtonPanelButton ( { type, items, color : 2 } ) ;
606
620
if ( button . hasContents ) buttons . push ( button ) ;
607
621
}
608
622
609
- const barItems = this . actor . items . filter ( ( item ) => CoreHUD . DND5E . mainBarFeatures . includes ( item . system . type ?. value ) && actionTypes . free . includes ( item . system . activation ?. type ) ) ;
623
+ const barItems = this . actor . items . filter ( ( item ) => CoreHUD . DND5E . mainBarFeatures . includes ( item . system . type ?. value ) && actionTypes . free . includes ( getActivationType ( item ) ) ) ;
610
624
buttons . push ( ...condenseItemButtons ( barItems ) ) ;
611
625
612
626
return buttons ;
@@ -632,7 +646,7 @@ export function initConfig() {
632
646
633
647
async _getButtons ( ) {
634
648
const buttons = [ ] ;
635
- const legendary = this . actor . items . filter ( ( item ) => item . system . activation ?. type === "legendary" ) ;
649
+ const legendary = this . actor . items . filter ( ( item ) => getActivationType ( item ) === "legendary" ) ;
636
650
legendary . forEach ( ( item ) => {
637
651
buttons . push ( new DND5eItemButton ( { item, inActionPanel : true } ) ) ;
638
652
} ) ;
@@ -659,7 +673,7 @@ export function initConfig() {
659
673
660
674
async _getButtons ( ) {
661
675
const buttons = [ ] ;
662
- const lair = this . actor . items . filter ( ( item ) => item . system . activation ?. type === "lair" ) ;
676
+ const lair = this . actor . items . filter ( ( item ) => getActivationType ( item ) === "lair" ) ;
663
677
lair . forEach ( ( item ) => {
664
678
buttons . push ( new DND5eItemButton ( { item, inActionPanel : true } ) ) ;
665
679
} ) ;
@@ -686,7 +700,7 @@ export function initConfig() {
686
700
687
701
async _getButtons ( ) {
688
702
const buttons = [ ] ;
689
- const mythic = this . actor . items . filter ( ( item ) => item . system . activation ?. type === "mythic" ) ;
703
+ const mythic = this . actor . items . filter ( ( item ) => getActivationType ( item ) === "mythic" ) ;
690
704
mythic . forEach ( ( item ) => {
691
705
buttons . push ( new DND5eItemButton ( { item, inActionPanel : true } ) ) ;
692
706
} ) ;
@@ -699,26 +713,33 @@ export function initConfig() {
699
713
super ( ...args ) ;
700
714
}
701
715
716
+ get activity ( ) {
717
+ if ( ! this . item ?. system ?. activities ) {
718
+ return
719
+ }
720
+ return Array . from ( this . item . system . activities ) [ 0 ] ;
721
+ }
722
+
702
723
get hasTooltip ( ) {
703
724
return true ;
704
725
}
705
726
706
727
get ranges ( ) {
707
- const item = this . item ;
708
- const touchRange = item . system . range . units == "touch" ? canvas ?. scene ?. grid ?. distance : null ;
728
+ const item = this . activity ;
729
+ const touchRange = item . range . units == "touch" ? canvas ?. scene ?. grid ?. distance : null ;
709
730
return {
710
- normal : item . system ?. range ?. value ?? touchRange ,
711
- long : item . system ?. range ?. long ?? null ,
731
+ normal : item ?. range ?. value ?? touchRange ,
732
+ long : item ?. range ?. long ?? null ,
712
733
} ;
713
734
}
714
735
715
736
get targets ( ) {
716
- const item = this . item ;
737
+ const item = this . activity ;
717
738
const validTargets = [ "creature" , "ally" , "enemy" ] ;
718
- const actionType = item . system . actionType ;
719
- const targetType = item . system . target ?. type ;
720
- if ( ! item . system . target ?. units && validTargets . includes ( targetType ) ) {
721
- return item . system . target ?. value ;
739
+ const actionType = item . actionType ;
740
+ const targetType = item . target ?. type ;
741
+ if ( ! item . target ?. units && validTargets . includes ( targetType ) ) {
742
+ return item . target ?. value ;
722
743
} else if ( actionType === "mwak" || actionType === "rwak" ) {
723
744
return 1 ;
724
745
}
@@ -728,10 +749,10 @@ export function initConfig() {
728
749
get visible ( ) {
729
750
if ( ! this . _isWeaponSet ) return super . visible ;
730
751
const isReaction = this . parent instanceof DND5eReactionActionPanel ;
731
- const isMelee = this . item ?. system ?. actionType === "mwak" ;
752
+ const isMelee = this . activity ?. actionType === "mwak" ;
732
753
if ( isReaction && ! isMelee ) return false ;
733
754
if ( this . _isPrimary ) return super . visible ;
734
- if ( this . item ?. system ?. type ?. value === "shield" ) return false ;
755
+ if ( this . activity ?. type ?. value === "shield" ) return false ;
735
756
return super . visible ;
736
757
}
737
758
@@ -743,18 +764,18 @@ export function initConfig() {
743
764
744
765
async _onLeftClick ( event ) {
745
766
ui . ARGON . interceptNextDialog ( event . currentTarget ) ;
746
- const used = await this . item . use ( { event } , { event } ) ;
767
+ const used = await this . activity . use ( { event } , { event } ) ;
747
768
if ( used ) {
748
- DND5eItemButton . consumeActionEconomy ( this . item ) ;
769
+ DND5eItemButton . consumeActionEconomy ( this . activity ) ;
749
770
}
750
771
}
751
772
752
773
async _onRightClick ( event ) {
753
- this . item ?. sheet ?. render ( true ) ;
774
+ this . activity ?. sheet ?. render ( true ) ;
754
775
}
755
776
756
777
static consumeActionEconomy ( item ) {
757
- const activationType = item . system . activation ?. type ;
778
+ const activationType = getActivationType ( item ) ;
758
779
let actionType = null ;
759
780
for ( const [ type , types ] of Object . entries ( actionTypes ) ) {
760
781
if ( types . includes ( activationType ) ) actionType = type ;
@@ -780,30 +801,30 @@ export function initConfig() {
780
801
781
802
async render ( ...args ) {
782
803
await super . render ( ...args ) ;
783
- if ( this . item ) {
784
- const weapons = this . actor . items . filter ( ( item ) => item . system . consume ?. target === this . item . id ) ;
804
+ if ( this . activity ) {
805
+ const weapons = this . actor . items . filter ( ( item ) => item . consume ?. target === this . activity . id ) ;
785
806
ui . ARGON . updateItemButtons ( weapons ) ;
786
807
}
787
808
}
788
809
789
810
get quantity ( ) {
790
- if ( ! this . item ?. system ) return null ;
811
+ if ( ! this . activity ) return null ;
791
812
const showQuantityItemTypes = [ "consumable" ] ;
792
- const consumeType = this . item . system . consume ?. type ;
813
+ const consumeType = this . activity . consume ?. type ;
793
814
if ( consumeType === "ammo" ) {
794
- const ammoItem = this . actor . items . get ( this . item . system . consume . target ) ;
815
+ const ammoItem = this . actor . items . get ( this . activity . consume . target ) ;
795
816
if ( ! ammoItem ) return null ;
796
- return Math . floor ( ( ammoItem . system . quantity ?? 0 ) / this . item . system . consume . amount ) ;
817
+ return Math . floor ( ( ammoItem . quantity ?? 0 ) / this . activity . consume . amount ) ;
797
818
} else if ( consumeType === "attribute" ) {
798
- return Math . floor ( getProperty ( this . actor . system , this . item . system . consume . target ) / this . item . system . consume . amount ) ;
819
+ return Math . floor ( getProperty ( this . actor , this . activity . consume . target ) / this . activity . consume . amount ) ;
799
820
} else if ( consumeType === "charges" ) {
800
- const chargesItem = this . actor . items . get ( this . item . system . consume . target ) ;
821
+ const chargesItem = this . actor . items . get ( this . activity . consume . target ) ;
801
822
if ( ! chargesItem ) return null ;
802
- return Math . floor ( ( chargesItem . system . uses ?. value ?? 0 ) / this . item . system . consume . amount ) ;
803
- } else if ( showQuantityItemTypes . includes ( this . item . type ) ) {
804
- return this . item . system . uses ?. value ?? this . item . system . quantity ;
805
- } else if ( this . item . system . uses . value !== null && this . item . system . uses . per !== null ) {
806
- return this . item . system . uses . value ;
823
+ return Math . floor ( ( chargesItem . uses ?. value ?? 0 ) / this . activity . consume . amount ) ;
824
+ } else if ( showQuantityItemTypes . includes ( this . activity . type ) ) {
825
+ return this . activity . uses ?. value ?? this . activity . quantity ;
826
+ } else if ( this . activity . uses . value !== null && this . activity . uses . per !== null && this . activity . uses . max ) {
827
+ return this . activity . uses . value ;
807
828
}
808
829
return null ;
809
830
}
@@ -874,7 +895,7 @@ export function initConfig() {
874
895
const spellItems = this . actor . items . filter ( ( item ) => item . flags [ "items-with-spells-5e" ] ?. [ "item-spells" ] ?. length ) ;
875
896
for ( const item of spellItems ) {
876
897
const spellData = item . flags [ "items-with-spells-5e" ] [ "item-spells" ] ;
877
- const itemsInSpell = spellData . map ( ( spell ) => this . actor . items . get ( spell . id ) ) . filter ( ( item ) => item && item . system . activation ?. type === actionType ) ;
898
+ const itemsInSpell = spellData . map ( ( spell ) => this . actor . items . get ( spell . id ) ) . filter ( ( item ) => item && getActivationType ( item ) === actionType ) ;
878
899
if ( ! itemsInSpell . length ) continue ;
879
900
itemsToIgnore . push ( ...itemsInSpell ) ;
880
901
if ( ! IWSAPI . isUsableItem ( item ) ) continue ;
@@ -1039,8 +1060,8 @@ export function initConfig() {
1039
1060
const sets = await super . getDefaultSets ( ) ;
1040
1061
const isTransformed = this . actor . flags ?. dnd5e ?. isPolymorphed ;
1041
1062
if ( this . actor . type !== "npc" && ! isTransformed ) return sets ;
1042
- const actions = this . actor . items . filter ( ( item ) => item . type === "weapon" && item . system . activation ?. type === "action" ) ;
1043
- const bonus = this . actor . items . filter ( ( item ) => item . type === "weapon" && item . system . activation ?. type === "bonus" ) ;
1063
+ const actions = this . actor . items . filter ( ( item ) => item . type === "weapon" && getActivationType ( item ) === "action" ) ;
1064
+ const bonus = this . actor . items . filter ( ( item ) => item . type === "weapon" && getActivationType ( item ) === "bonus" ) ;
1044
1065
return {
1045
1066
1 : {
1046
1067
primary : actions [ 0 ] ?. uuid ?? null ,
0 commit comments