@@ -61,15 +61,17 @@ Hooks.on(CheckHooks.renderCheck, onRenderAccuracyCheck);
6161/**
6262 * @type RenderCheckHook
6363 */
64- let onRenderAttributeCheck = ( sections , check , actor , item ) => {
64+ let onRenderAttributeCheck = ( sections , check , actor , item , flags ) => {
6565 if ( check . type === 'attribute' && check . additionalData [ skillForAttributeCheck ] ) {
6666 const skill = fromUuidSync ( check . additionalData [ skillForAttributeCheck ] ) ;
67+ const inspector = CheckConfiguration . inspect ( check ) ;
6768 CommonSections . itemFlavor ( sections , skill ) ;
6869 CommonSections . tags ( sections , getTags ( skill ) , CHECK_DETAILS ) ;
6970 if ( skill . system . hasResource . value ) {
7071 CommonSections . resource ( sections , skill . system . rp , CHECK_DETAILS ) ;
7172 }
7273 CommonSections . description ( sections , skill . system . description , skill . system . summary . value , CHECK_DETAILS ) ;
74+ CommonSections . actions ( sections , actor , item , [ ] , flags , inspector ) ;
7375 }
7476} ;
7577Hooks . on ( CheckHooks . renderCheck , onRenderAttributeCheck ) ;
@@ -115,7 +117,7 @@ function getTags(skill) {
115117 * @property {string } class.value
116118 * @property {UseWeaponDataModelV2 } useWeapon
117119 * @property {ItemAttributesDataModelV2 } attributes
118- * @property {number } accuracy
120+ * @property {String } accuracy A number or expression for the accuracy to be used.
119121 * @property {Defense } defense
120122 * @property {DamageDataModelV2 } damage
121123 * @property {ResourceDataModel } resource
@@ -160,7 +162,7 @@ export class SkillDataModel extends FUStandardItemDataModel {
160162 secondary : 'ins' ,
161163 } ,
162164 } ) ,
163- accuracy : new NumberField ( { initial : 0 , integer : true , nullable : false } ) ,
165+ accuracy : new StringField ( { initial : '' , blank : true , nullable : false } ) ,
164166 defense : new StringField ( { initial : 'def' , choices : Object . keys ( FU . defenses ) , blank : true } ) ,
165167 damage : new EmbeddedDataField ( DamageDataModelV2 , { } ) ,
166168 resource : new EmbeddedDataField ( ResourceDataModel , { } ) ,
@@ -212,7 +214,7 @@ export class SkillDataModel extends FUStandardItemDataModel {
212214 secondary : this . attributes . secondary ,
213215 } ,
214216 this . parent ,
215- this . #initializeAttributeCheck( ) ,
217+ this . #initializeAttributeCheck( modifiers ) ,
216218 ) ;
217219 }
218220 }
@@ -236,6 +238,44 @@ export class SkillDataModel extends FUStandardItemDataModel {
236238 } ;
237239 }
238240
241+ /**
242+ * @return {CheckCallback }
243+ */
244+ #initializeAttributeCheck( modifiers ) {
245+ return async ( check , actor , item ) => {
246+ /** @type SkillDataModel **/
247+ const skill = item . system ;
248+ const config = CheckConfiguration . configure ( check ) ;
249+ const targets = config . getTargets ( ) ;
250+ const context = ExpressionContext . fromTargetData ( actor , item , targets ) ;
251+
252+ if ( skill . defense && targets . length === 1 ) {
253+ let dl ;
254+ switch ( skill . defense ) {
255+ case 'def' :
256+ dl = targets [ 0 ] . def ;
257+ break ;
258+
259+ case 'mdef' :
260+ dl = targets [ 0 ] . mdef ;
261+ break ;
262+ }
263+ config . setDifficulty ( dl ) ;
264+ }
265+
266+ if ( this . accuracy ) {
267+ const calculatedAccuracyBonus = await Expressions . evaluateAsync ( this . accuracy , context ) ;
268+ if ( calculatedAccuracyBonus > 0 ) {
269+ check . modifiers . push ( {
270+ label : 'FU.CheckBonus' ,
271+ value : calculatedAccuracyBonus ,
272+ } ) ;
273+ }
274+ }
275+ check . additionalData [ skillForAttributeCheck ] = this . parent . uuid ;
276+ } ;
277+ }
278+
239279 /**
240280 * @param {KeyboardModifiers } modifiers
241281 * @return {CheckCallback }
@@ -264,6 +304,8 @@ export class SkillDataModel extends FUStandardItemDataModel {
264304 /** @type SkillDataModel **/
265305 const skill = item . system ;
266306 const config = CheckConfiguration . configure ( check ) ;
307+ const targets = config . getTargets ( ) ;
308+ const context = ExpressionContext . fromTargetData ( actor , item , targets ) ;
267309
268310 config . addTraits ( 'skill' ) ;
269311 config . addTraitsFromItemModel ( this . traits ) ;
@@ -273,10 +315,13 @@ export class SkillDataModel extends FUStandardItemDataModel {
273315 config . setWeaponTraits ( config . getWeaponTraits ( ) ) ;
274316
275317 if ( this . accuracy ) {
276- check . modifiers . push ( {
277- label : 'FU.CheckBonus' ,
278- value : this . accuracy ,
279- } ) ;
318+ const calculatedAccuracyBonus = await Expressions . evaluateAsync ( this . accuracy , context ) ;
319+ if ( calculatedAccuracyBonus > 0 ) {
320+ check . modifiers . push ( {
321+ label : 'FU.CheckBonus' ,
322+ value : calculatedAccuracyBonus ,
323+ } ) ;
324+ }
280325 }
281326
282327 if ( skill . resource . enabled ) {
@@ -307,8 +352,6 @@ export class SkillDataModel extends FUStandardItemDataModel {
307352
308353 const onRoll = this . damage . onRoll ;
309354 if ( onRoll ) {
310- const targets = config . getTargets ( ) ;
311- const context = ExpressionContext . fromTargetData ( actor , item , targets ) ;
312355 const extraDamage = await Expressions . evaluateAsync ( onRoll , context ) ;
313356 if ( extraDamage > 0 ) {
314357 config . addDamageBonus ( 'FU.DamageOnRoll' , extraDamage ) ;
@@ -325,19 +368,6 @@ export class SkillDataModel extends FUStandardItemDataModel {
325368 } ;
326369 }
327370
328- /**
329- * @return {CheckCallback }
330- */
331- #initializeAttributeCheck( ) {
332- return ( check ) => {
333- check . modifiers . push ( {
334- label : 'FU.CheckBonus' ,
335- value : this . accuracy ,
336- } ) ;
337- check . additionalData [ skillForAttributeCheck ] = this . parent . uuid ;
338- } ;
339- }
340-
341371 shouldApplyEffect ( effect ) {
342372 return this . level . value > 0 ;
343373 }
0 commit comments