@@ -181,14 +181,18 @@ API_Meta.AttackMaster={offset:Number.MAX_SAFE_INTEGER,lineCount:-1};
181
181
* which are uncharged but allow c: charge comparisons to support enable
182
182
* and disable of weapon attack rows. Reintroduce support for effects on
183
183
* '-inhand' in such a way as not to clash with new dancing weapons type.
184
+ * v3.2.1 11/02/2024 Link weapon tables to InHand table by storing the row number. Use this
185
+ * to reveal hidden weapons on an attack if "reveal on use" set. Improve
186
+ * parseStr() to handle undefined or empty strings without erroring. Fixed
187
+ * ad-hoc dancing weapons.
184
188
*/
185
189
186
190
var attackMaster = ( function ( ) {
187
191
'use strict' ;
188
- var version = '3.2.0 ' ,
192
+ var version = '3.2.1 ' ,
189
193
author = 'Richard @ Damery' ,
190
194
pending = null ;
191
- const lastUpdate = 1707473376 ;
195
+ const lastUpdate = 1708765145 ;
192
196
193
197
/*
194
198
* Define redirections for functions moved to the RPGMaster library
@@ -750,7 +754,7 @@ var attackMaster = (function() {
750
754
const reRangeData = / } } \s * ?r a n g e d a t a \s * ?= .* ?(?: \n .* ?) * { { / im;
751
755
const reACData = / } } \s * a c d a t a \s * = ( .* ?) { { / im;
752
756
const reRingData = / (?: r i n g | a c ) d a t a \s * ?= \s * ?( \[ .* ?\] ) / im;
753
- const reItemData = / } } [ \s \w \- ] * ?(?< ! t o h i t | d m g | a m m o | r a n g e ) d a t a \s * ?= \s * ?\[ [ ^ { ] * ?\] / im;
757
+ const reItemData = / } } [ \s \w \- ] * ?(?< ! t o h i t | d m g | a m m o | r a n g e ) d a t a \s * ?= \s * ?\[ . * ?\] { { / im;
754
758
755
759
const reRangeMods = Object . freeze ( {
756
760
near : { field :'N' , def :'-5' , re :/ [ \[ , \s ] N : ( [ - \+ \d ] + ?) [ , \] ] / i} ,
@@ -932,7 +936,6 @@ var attackMaster = (function() {
932
936
setTimeout ( ( ) => updateHandouts ( handouts , true , findTheGM ( ) ) , 30 ) ;
933
937
setTimeout ( cmdMasterRegister , 40 ) ;
934
938
setTimeout ( ( ) => updateDBindex ( false ) , 90 ) ; // checking the DB indexing
935
- setTimeout ( rebuildDancers , 100 ) ;
936
939
} catch ( e ) {
937
940
log ( 'AttackMaster Initialisation: JavaScript ' + e . name + ': ' + e . message + ' while initialising the API' ) ;
938
941
sendDebug ( 'AttackMaster Initialisation: JavaScript ' + e . name + ': ' + e . message + ' while initialising the API' ) ;
@@ -1125,7 +1128,7 @@ var attackMaster = (function() {
1125
1128
* Function to replace special characters in a string
1126
1129
*/
1127
1130
1128
- var parseStr = function ( str , replaced = replacers ) {
1131
+ var parseStr = function ( str = '' , replaced = replacers ) {
1129
1132
return replaced . reduce ( ( m , rep ) => m . replace ( rep [ 0 ] , rep [ 1 ] ) , str ) ;
1130
1133
}
1131
1134
@@ -1804,34 +1807,6 @@ var attackMaster = (function() {
1804
1807
return true ;
1805
1808
}
1806
1809
1807
- /*
1808
- * Check for any "in-hand" dancing weapons and prompt
1809
- * RoundMaster to rebuild their dancing effects after a
1810
- * campaign restart.
1811
- */
1812
-
1813
- var rebuildDancers = function ( ) {
1814
-
1815
- var charID , dancer , weapon ;
1816
-
1817
- filterObjs ( obj => {
1818
- if ( obj . get ( '_type' ) !== 'graphic' ) return false ;
1819
- if ( ! ( charID = obj . get ( 'represents' ) ) ) return false ;
1820
- let charCS = getObj ( 'character' , charID ) ;
1821
- if ( ! charCS ) return false ;
1822
- let Inhand = getTable ( charCS , fieldGroups . INHAND ) ;
1823
- for ( let i = 0 ; ! _ . isUndefined ( weapon = Inhand . tableLookup ( fields . InHand_name , i , false ) ) ; i ++ ) {
1824
- if ( weapon === '-' ) continue ;
1825
- dancer = Inhand . tableLookup ( fields . InHand_dancer , i ) ;
1826
- if ( dancer . length ) {
1827
- let weapon = Inhand . tableLookup ( fields . InHand_trueName , i ) ,
1828
- type = Inhand . tableLookup ( fields . InHand_type , i ) ;
1829
- sendAPI ( fields . roundMaster + ' --dancer rebuild|' + obj . id + '|' + weapon + '|' + type + '|' + dancer ) ;
1830
- } ;
1831
- } ;
1832
- } ) ;
1833
- } ;
1834
-
1835
1810
/* ----------------------------------------------- Weapon Management Functions ----------------------------------------
1836
1811
1837
1812
/*
@@ -2092,7 +2067,7 @@ var attackMaster = (function() {
2092
2067
if ( weapName && weapName . length && ! sheathed . includes ( weapName ) ) {
2093
2068
sheathed . push ( weapName ) ;
2094
2069
sendAPImacro ( curToken , '' , weapName , '-sheath' ) ;
2095
- let weapData = resolveData ( weapName , fields . MagicItemDB , / w e a p d a t a \s * ? = \s * ? ( \[ . * ? \] ) / im , charCS ) . parsed ;
2070
+ let weapData = resolveData ( weapName , fields . MagicItemDB , reItemData , charCS ) . parsed ;
2096
2071
if ( weapData && weapData . off ) {
2097
2072
sendAPI ( parseStr ( weapData . off ) . replace ( / @ { \s * s e l e c t e d \s * \| \s * t o k e n _ i d \s * } / ig, tokenID )
2098
2073
. replace ( / { \s * s e l e c t e d \s * \| / ig, '{' + charCS . get ( 'name' ) + '|' ) , null , 'attk filterWeapons' ) ;
@@ -2198,8 +2173,10 @@ var attackMaster = (function() {
2198
2173
values [ fields . Ammo_range [ 0 ] ] [ fields . Ammo_range [ 1 ] ] = ( ( rangeDataArray [ w ] || rangeDataArray [ 0 ] ) [ 0 ] . match ( / [ \[ , \s ] r : ( = ? [ + - ] ? [ \s \w \+ \- \d \/ ] + ) [ , \] ] / i) || [ '' , '' ] ) [ 1 ] ;
2199
2174
values [ fields . Ammo_type [ 0 ] ] [ fields . Ammo_type [ 1 ] ] = ammoType ;
2200
2175
values [ fields . Ammo_miName [ 0 ] ] [ fields . Ammo_miName [ 1 ] ] = ammoTrueName ;
2176
+ values [ fields . Ammo_miIndex [ 0 ] ] [ fields . Ammo_miIndex [ 1 ] ] = miIndex ;
2201
2177
2202
- tableInfo . AMMO = tableInfo . AMMO . addTableRow ( tableInfo . AMMO . tableFind ( fields . Ammo_name , [ values [ fields . Ammo_name [ 0 ] ] [ fields . Ammo_name [ 1 ] ] , '-' ] ) , values ) ;
2178
+ ammoRow = tableInfo . AMMO . tableFind ( fields . Ammo_miName , ammoTrueName ) || tableInfo . AMMO . tableFind ( fields . Ammo_name , '-' ) ;
2179
+ tableInfo . AMMO = tableInfo . AMMO . addTableRow ( ammoRow , values ) ;
2203
2180
2204
2181
if ( ! _ . isUndefined ( tableInfo . WEAP ) ) {
2205
2182
dispValues [ fields . Weap_dmgBonus [ 0 ] ] [ fields . Weap_dmgBonus [ 1 ] ] = dispValues [ fields . Weap_adj [ 0 ] ] [ fields . Weap_adj [ 1 ] ] ;
@@ -2350,8 +2327,8 @@ var attackMaster = (function() {
2350
2327
innate = weapon [ 2 ] . toLowerCase ( ) . includes ( 'innate' ) ,
2351
2328
weapData = parseData ( toHit , reWeapSpecs ) ,
2352
2329
attk2H = noOfHands == 2 ? 1 : 0 ,
2353
- weapType = toHit . type || weapon [ 1 ] ,
2354
- weapSuperType = toHit . superType || weapon [ 4 ] ,
2330
+ weapType = weapData . type || weapon [ 1 ] ,
2331
+ weapSuperType = weapData . superType || weapon [ 4 ] ,
2355
2332
proficiency = innate ? 0 : proficient ( charCS , weaponTrueName , weapType , weapSuperType ) ;
2356
2333
2357
2334
if ( ! levelTest ( charCS , weapData ) ) continue ;
@@ -2376,6 +2353,7 @@ var attackMaster = (function() {
2376
2353
values [ fields . MW_superType [ 0 ] ] [ fields . MW_superType [ 1 ] ] = weapSuperType ;
2377
2354
values [ fields . MW_dancing [ 0 ] ] [ fields . MW_dancing [ 1 ] ] = ( dancing ?1 :0 ) ;
2378
2355
values [ fields . MW_attkCount [ 0 ] ] [ fields . MW_attkCount [ 1 ] ] = weaponAttkCount ;
2356
+ values [ fields . MW_hand [ 0 ] ] [ fields . MW_hand [ 1 ] ] = handIndex ;
2379
2357
if ( ! values [ fields . MW_message [ 0 ] ] [ fields . MW_message [ 1 ] ] ) values [ fields . MW_message [ 0 ] ] [ fields . MW_message [ 1 ] ] = weapParsed . message ;
2380
2358
if ( ! values [ fields . MW_cmd [ 0 ] ] [ fields . MW_cmd [ 1 ] ] ) values [ fields . MW_cmd [ 0 ] ] [ fields . MW_cmd [ 1 ] ] = weapParsed . cmd ;
2381
2359
dancingProf = parseInt ( values [ fields . MW_dancingProf [ 0 ] ] [ fields . MW_dancingProf [ 1 ] ] ) ;
@@ -2422,6 +2400,7 @@ var attackMaster = (function() {
2422
2400
values [ fields . RW_superType [ 0 ] ] [ fields . RW_superType [ 1 ] ] = weapSuperType ;
2423
2401
values [ fields . RW_dancing [ 0 ] ] [ fields . RW_dancing [ 1 ] ] = ( dancing ?1 :0 ) ;
2424
2402
values [ fields . RW_attkCount [ 0 ] ] [ fields . RW_attkCount [ 1 ] ] = weaponAttkCount ;
2403
+ values [ fields . RW_hand [ 0 ] ] [ fields . RW_hand [ 1 ] ] = handIndex ;
2425
2404
if ( ! values [ fields . RW_message [ 0 ] ] [ fields . RW_message [ 1 ] ] ) values [ fields . RW_message [ 0 ] ] [ fields . RW_message [ 1 ] ] = weapParsed . message ;
2426
2405
if ( ! values [ fields . RW_cmd [ 0 ] ] [ fields . RW_cmd [ 1 ] ] ) values [ fields . RW_cmd [ 0 ] ] [ fields . RW_cmd [ 1 ] ] = weapParsed . cmd ;
2427
2406
dancingProf = parseInt ( values [ fields . RW_dancingProf [ 0 ] ] [ fields . RW_dancingProf [ 1 ] ] ) ;
@@ -3017,7 +2996,6 @@ var attackMaster = (function() {
3017
2996
return new Promise ( resolve => {
3018
2997
3019
2998
try {
3020
-
3021
2999
var tokenID = args [ 1 ] ,
3022
3000
attkType = args [ 2 ] ,
3023
3001
dmgMsg = parseStr ( args [ 5 ] || attrLookup ( charCS , fields . Dmg_specials ) || '' ) ,
@@ -3032,6 +3010,7 @@ var attackMaster = (function() {
3032
3010
mwNumber = mwIndex + ( fields . MW_table [ 1 ] == 0 ? 1 : 2 ) ,
3033
3011
weaponName = tableInfo . MELEE . tableLookup ( fields . MW_name , mwIndex ) ,
3034
3012
miName = tableInfo . MELEE . tableLookup ( fields . MW_miName , mwIndex ) ,
3013
+ miRowref = attrLookup ( charCS , fields . InHand_index , fields . InHand_table , tableInfo . MELEE . tableLookup ( fields . MW_hand , mwIndex ) ) ,
3035
3014
dancing = tableInfo . MELEE . tableLookup ( fields . MW_dancing , mwIndex ) ,
3036
3015
attkAdj = ( tableInfo . MELEE . tableLookup ( fields . MW_adj , mwIndex ) || '' ) . replace ( / ^ [ + - ] ( [ + - ] ) / , '$1' ) ,
3037
3016
attkStyleAdj = tableInfo . MELEE . tableLookup ( fields . MW_styleAdj , mwIndex ) ,
@@ -3246,6 +3225,7 @@ var attackMaster = (function() {
3246
3225
setAbility ( charCS , 'Do-not-use-DmgL-MW' + mwNumber , ( parseMWattkMacro ( args , charCS , attkType , addDmgMsg ( dmgMacroDef . obj [ 1 ] . body , dmgMsg , weapDmgMsg ) ) + attkMacro ) ) ;
3247
3226
hitCharges = ( hitCharges == '' ? 1 : hitCharges ) ;
3248
3227
attkMacro = weapCharged && hitCharges ? ( '\n!magic --mi-charges ' + tokenID + '|-' + hitCharges + '|' + miName + '||' + weapCharged ) : '' ;
3228
+ attkMacro += ( ( weaponName !== miName ) && attrLookup ( charCS , fields . Items_reveal , fields . Items_table , miRowref ) . toLowerCase ( ) == 'use' ) ? ( '\n!magic --button GM-ResetSingleMI|' + tokenID + '|' + miRowref + '|silent' ) : '' ;
3249
3229
attkMacro += weapCmd ? ( '\n' + weapCmd ) : '' ;
3250
3230
attkMacro += touchWeap ? ( '\n!attk --blank-weapon ' + tokenID + '|' + miName + '|silent' ) : '' ;
3251
3231
if ( abilityType == Attk . TARGET ) {
@@ -3298,6 +3278,7 @@ var attackMaster = (function() {
3298
3278
rwNumber = rwIndex + ( fields . RW_table [ 1 ] == 0 ? 1 : 2 ) ,
3299
3279
weaponName = tableInfo . RANGED . tableLookup ( fields . RW_name , rwIndex ) ,
3300
3280
miName = tableInfo . RANGED . tableLookup ( fields . RW_miName , rwIndex ) ,
3281
+ miRowref = attrLookup ( charCS , fields . InHand_index , fields . InHand_table , tableInfo . RANGED . tableLookup ( fields . RW_hand , rwIndex ) ) ,
3301
3282
dancing = tableInfo . RANGED . tableLookup ( fields . RW_dancing , rwIndex ) ,
3302
3283
attkAdj = tableInfo . RANGED . tableLookup ( fields . RW_adj , rwIndex ) ,
3303
3284
weapDmgAdj = / ^ [ + - ] [ + - ] / . test ( attkAdj ) ,
@@ -3319,6 +3300,7 @@ var attackMaster = (function() {
3319
3300
weapTypeTxt = ( slashWeap ?'S' :'' ) + ( pierceWeap ?'P' :'' ) + ( bludgeonWeap ?'B' :'' ) ,
3320
3301
ammoName = tableInfo . AMMO . tableLookup ( fields . Ammo_name , ammoIndex ) ,
3321
3302
ammoMIname = tableInfo . AMMO . tableLookup ( fields . Ammo_miName , ammoIndex ) ,
3303
+ ammoRowref = tableInfo . AMMO . tableLookup ( fields . Ammo_miIndex , ammoIndex ) ,
3322
3304
dmgAdj = tableInfo . AMMO . tableLookup ( fields . Ammo_adj , ammoIndex ) ,
3323
3305
dmgStyleAdj = tableInfo . AMMO . tableLookup ( fields . Ammo_styleAdj , ammoIndex ) ,
3324
3306
dmgSM = tableInfo . AMMO . tableLookup ( fields . Ammo_dmgSM , ammoIndex ) ,
@@ -3569,6 +3551,8 @@ var attackMaster = (function() {
3569
3551
} ;
3570
3552
attkMacro += ( ( weapCharged && hitCharges ) ? ( '\n!magic --mi-charges ' + tokenID + '|-' + hitCharges + '|' + miName + '|' + weapChgType ) : '' ) ;
3571
3553
if ( abilityType === Attk . TARGET ) weapCmd = weapCmd . replace ( / @ { target\| .* ?\| ? t o k e n _ i d } / igm, '@{target|Select Target|token_id}' ) ;
3554
+ attkMacro += ( ( weaponName !== miName ) && attrLookup ( charCS , fields . Items_reveal , fields . Items_table , miRowref ) . toLowerCase ( ) == 'use' ) ? ( '\n!magic --button GM-ResetSingleMI|' + tokenID + '|' + miRowref + '|silent' ) : '' ;
3555
+ attkMacro += ( ( ammoName !== ammoMIname ) && attrLookup ( charCS , fields . Items_reveal , fields . Items_table , ammoRowref ) . toLowerCase ( ) == 'use' ) ? ( '\n!magic --button GM-ResetSingleMI|' + tokenID + '|' + ammoRowref + '|silent' ) : '' ;
3572
3556
attkMacro += weapCmd ? ( '\n' + weapCmd ) : '' ;
3573
3557
attkMacro += touchWeap ? ( '\n!attk --blank-weapon ' + tokenID + '|' + miName + '|silent' ) : '' ;
3574
3558
setAbility ( charCS , 'Do-not-use-Attk-RW' + rwNumber + '-' + dist , attkMacro ) ;
@@ -3943,7 +3927,8 @@ var attackMaster = (function() {
3943
3927
weapCharged = ! ( [ 'uncharged' , 'cursed' , 'cursed+uncharged' , 'single-uncharged' ] . includes ( weapCharge ) ) ,
3944
3928
enabling = [ 'enable' , 'disable' ] . includes ( weapCharge ) ,
3945
3929
miQty = Items . tableLookup ( fields . Items_qty , itemIndex ) ;
3946
- if ( miQty <= 0 || ( ! _ . isUndefined ( itemIndex ) && weapCharged && ( miQty - ( ! charges ? 1 : charges ) ) < 0 ) ) {
3930
+ // if (miQty <= 0 || (!_.isUndefined(itemIndex) && weapCharged && (miQty - (!charges ? 1 : charges)) < 0)) {
3931
+ if ( ! _ . isUndefined ( itemIndex ) && weapCharged && ( miQty - ( ! charges ? 1 : charges ) ) < 0 ) {
3947
3932
meleeWeaps += '<span style=' + design . grey_button + '>' + ( enabling ? '' : miQty ) + ' ' + weaponName + '</span>' ;
3948
3933
} else {
3949
3934
if ( errFlag = await buildMWattkMacros ( args , senderId , charCS , tableInfo , weaponIndex , backstab ) ) return ;
@@ -4999,7 +4984,7 @@ var attackMaster = (function() {
4999
4984
5000
4985
// Check if this is a dancing weapon
5001
4986
5002
- weapData = resolveData ( trueWeapon , weaponDB , reWeapData , charCS , { on :reWeapSpecs . on , dancer :reWeapSpecs . dancer } , r ) . parsed ;
4987
+ weapData = resolveData ( trueWeapon , weaponDB , reItemData , charCS , { on :reWeapSpecs . on , dancer :reWeapSpecs . dancer } , r ) . parsed ;
5003
4988
5004
4989
// Then add the weapon to the InHand table
5005
4990
@@ -6105,6 +6090,15 @@ var attackMaster = (function() {
6105
6090
6106
6091
silent = silent || _ . isUndefined ( weapTable . INHAND . tableFind ( fields . InHand_name , weapon ) ) || _ . isUndefined ( weapTable . INHAND . tableFind ( fields . InHand_trueName , weapon ) ) ;
6107
6092
6093
+ let inhandRow = weapTable . INHAND . tableFind ( fields . InHand_trueName , weapon ) || weapTable . INHAND . tableFind ( fields . InHand_name , weapon ) ,
6094
+ itemRow = _ . isUndefined ( inhandRow ) ? undefined : weapTable . INHAND . tableLookup ( fields . InHand_index , inhandRow ) ,
6095
+ cmd = resolveData ( weapon , fields . MagicItemDB , reItemData , charCS , { off :reWeapSpecs . off } , itemRow ) . parsed . off ;
6096
+
6097
+ silent = silent || _ . isUndefined ( inhandRow ) ;
6098
+ if ( ! _ . isUndefined ( inhandRow ) && cmd && cmd . length ) {
6099
+ sendAPI ( parseStr ( cmd ) . replace ( / @ { \s * s e l e c t e d \s * \| \s * t o k e n _ i d \s * } / ig, tokenID )
6100
+ . replace ( / { \s * s e l e c t e d \s * \| / ig, '{' + charCS . get ( 'name' ) + '|' ) , null , 'attk doBlankWeapon' ) ;
6101
+ } ;
6108
6102
blankWeapon ( charCS , weapTable , _ . keys ( weapTable ) , weapon ) ;
6109
6103
6110
6104
if ( ! silent ) {
0 commit comments