@@ -5,27 +5,10 @@ import Rollable from "./rollable.mjs";
55/**
66 * @typedef {object } KnockdownWorkflowOptions
77 * @property {object } [knockdownAbility] - The ability used for the knockdown test (optional).
8- * @property {number } [difficulty ] - The difficulty for the knockdown test (optional).
8+ * @property {number } [damageTaken ] - The amount of damage taken (optional).
99 */
1010
1111export default class KnockdownWorkflow extends Rollable ( ActorWorkflow ) {
12- /**
13- * The step used to withstand the knockdown.
14- * @type {number }
15- */
16- _knockdownStep ;
17-
18- /**
19- * The wound threshold of the Actor.
20- * @type {number }
21- */
22- _woundThreshold ;
23-
24- /**
25- * Knockdown test difficulty.
26- * @type {number }
27- */
28- _difficulty ;
2912
3013 /**
3114 * Damage taken.
@@ -39,68 +22,42 @@ export default class KnockdownWorkflow extends Rollable( ActorWorkflow ) {
3922 */
4023 _knockdownAbility ;
4124
42- /**
43- * Knockdown strain.
44- * @type {number }
45- */
46- _strain ;
47-
4825 /**
4926 * @param {foundry.documents.Actor } actor - The actor that is performing the knockdown.
5027 * @param {KnockdownWorkflowOptions } [options] - The options for the knockdown workflow.
5128 */
5229 constructor ( actor , options = { } ) {
5330 super ( actor , options ) ;
5431 this . _damageTaken = options . damageTaken || 0 ;
55- this . _woundThreshold = actor . system . characteristics . health . woundThreshold ;
56- this . _strain = options . knockdownAbility ?. system ?. strain || 0 ;
57- this . _knockdownStep = this . _knockdownAbility ? this . _knockdownAbility . system . rankFinal : actor . system . knockdownStep ;
58- // include option to set difficulty to full damage taken
59- this . _difficulty = options . difficulty || game . settings . get ( "ed4e" , "minimumDifficulty" ) ;
32+ this . _knockdownAbility = options . knockdownAbility || null ;
33+ this . _rollToMessage = options . rollToMessage ?? true ;
6034
61- this . _steps = [
62- this . _checkKnockdownStatus . bind ( this ) ,
63- this . getKnockdownAbility . bind ( this ) ,
64- this . _prepareKnockdownRollOptions . bind ( this ) ,
65- this . _createRoll . bind ( this ) ,
66- this . _evaluateResultRoll . bind ( this ) ,
67- this . _processRoll . bind ( this ) ,
68- this . _rollToChat . bind ( this ) ,
69- ] ;
35+ this . _steps . push (
36+ this . #validate. bind ( this ) ,
37+ this . #chooseKnockdownAbility. bind ( this ) ,
38+ ) ;
39+ this . _initRollableSteps ( ) ;
7040 }
7141
72- /**
73- * Check if the actor is already knocked down.
74- * @returns {Promise<void> }
75- * @private
76- */
77- async _checkKnockdownStatus ( ) {
42+ async #validate( ) {
7843 if ( this . _actor . statuses . has ( "knockedDown" ) ) {
79- ui . notifications . info ( _loc ( "ED.Notifications.Info.alreadyKnockedDown" ) ) ;
44+ ui . notifications . info (
45+ "ED.Notifications.Info.alreadyKnockedDown" ,
46+ { localize : true } ,
47+ ) ;
8048 this . cancel ( ) ;
8149 }
8250 }
8351
84- /**
85- * Fetch the knockdown ability item for the actor.
86- * @returns {Promise<void> }
87- * @private
88- */
89- async getKnockdownAbility ( ) {
90- this . _knockdownAbility = await this . _actor . knockdownAbility ( ) ;
52+ async #chooseKnockdownAbility( ) {
53+ if ( this . _knockdownAbility ) return ;
54+
55+ const abilityUuid = await this . _actor . getPrompt ( "knockdown" ) ;
56+ this . _knockdownAbility = await fromUuid ( abilityUuid ) ?? null ;
9157 }
9258
93- /**
94- * Prepare the roll options for the knockdown test.
95- * @returns {Promise<void> }
96- * @private
97- */
98- async _prepareKnockdownRollOptions ( ) {
99- const stepModifiers = { } ;
100- const knockdownModifier = this . _actor . system . globalModifiers ?. allKnockdownTests . value ?? 0 ;
101- if ( knockdownModifier ) {
102- stepModifiers . knockdown = knockdownModifier ;
103- }
59+ /** @inheritDoc */
60+ async _prepareRollOptions ( ) {
10461 this . _rollOptions = KnockdownRollOptions . fromActor (
10562 {
10663 knockdownAbility : this . _knockdownAbility ,
@@ -109,4 +66,4 @@ export default class KnockdownWorkflow extends Rollable( ActorWorkflow ) {
10966 this . _actor ,
11067 ) ;
11168 }
112- }
69+ }
0 commit comments