@@ -9,6 +9,9 @@ import { CheckHooks } from '../checks/check-hooks.mjs';
99import { CHECK_FLAVOR } from '../checks/default-section-order.mjs' ;
1010import { CheckConfiguration } from '../checks/check-configuration.mjs' ;
1111import { StringUtils } from './string-utils.mjs' ;
12+ import { WeaponResolver } from '../documents/items/skill/weapon-resolver.mjs' ;
13+ import FoundryUtils from './foundry-utils.mjs' ;
14+ import { EquipmentHandlerDialog } from './equipment-handler.mjs' ;
1215
1316const actionKey = 'ruleDefinedAction' ;
1417
@@ -48,7 +51,8 @@ const onRenderCheck = (data, check, actor) => {
4851Hooks . on ( CheckHooks . renderCheck , onRenderCheck ) ;
4952
5053/**
51- * @desc Encapsulates basic character actions.\
54+ * @desc Encapsulates basic character actions.
55+ * @property {FUActor } actor
5256 * @property {Number } bonus
5357 */
5458export class ActionHandler {
@@ -65,19 +69,27 @@ export class ActionHandler {
6569 return this ;
6670 }
6771
72+ /**
73+ *
74+ * @param {FUActionType } actionType
75+ * @param isShift
76+ * @returns {Promise<void> }
77+ */
6878 async handleAction ( actionType , isShift = false ) {
6979 if ( ! isShift ) {
7080 switch ( actionType ) {
81+ case 'attack' :
82+ return this . attack ( ) ;
7183 case 'equipment' :
72- return this . createActionMessage ( actionType ) ;
84+ return this . equipment ( ) ;
7385 case 'guard' :
7486 return this . toggleGuardEffect ( this . actor ) ;
7587 case 'hinder' :
7688 return this . promptHinderCheck ( ) ;
7789 case 'inventory' :
7890 return this . createActionMessage ( actionType ) ;
7991 case 'objective' :
80- return this . createActionMessage ( actionType ) ;
92+ return this . objective ( ) ;
8193 case 'spell' :
8294 return this . createActionMessage ( actionType ) ;
8395 case 'study' :
@@ -123,6 +135,35 @@ export class ActionHandler {
123135 } ) ;
124136 }
125137
138+ /**
139+ * @desc Performs an attack with one of the equipped weapons or attacks.
140+ * @returns {Promise<void> }
141+ */
142+ async attack ( ) {
143+ const resolution = await WeaponResolver . prompt ( this . actor , true ) ;
144+ if ( resolution ?. item ) {
145+ resolution . item . roll ( ) ;
146+ }
147+ }
148+
149+ /**
150+ * @desc Attempts to roll a check for one of the existing clocks.
151+ * @returns {Promise<void> }
152+ */
153+ async objective ( ) {
154+ // TODO: Look at active clocks in party/scene and roll a check to advance them
155+ return CheckPrompt . attributeCheck ( this . actor ) ;
156+ }
157+
158+ /**
159+ * @desc Opens a dialog to swap the current equipment.
160+ * @returns {Promise<void> }
161+ */
162+ async equipment ( ) {
163+ const dialog = new EquipmentHandlerDialog ( this . actor ) ;
164+ dialog . render ( true ) ;
165+ }
166+
126167 /**
127168 * Create a chat message for a given action.
128169 * @param {string } action - The type of action to create a message for.
@@ -155,4 +196,37 @@ export class ActionHandler {
155196 await this . createActionMessage ( 'guard' ) ;
156197 }
157198 }
199+
200+ static skillsWithApps = [ 'invocations' , 'verse' ] ;
201+
202+ /**
203+ * @param {FUActor } actor
204+ * @param element
205+ */
206+ static setupMenu ( actor , element ) {
207+ // ATTACKS
208+ const attacks = WeaponResolver . getEquippedWeapons ( actor , true ) ;
209+ FoundryUtils . itemContextMenu ( element , '[data-context-menu="attack"]' , attacks ) ;
210+ // SPELLS
211+ const spells = [ 'spell' ] . map ( ( t ) => actor . getItemsByType ( t ) ) . flat ( ) ;
212+ FoundryUtils . itemContextMenu ( element , '[data-context-menu="spell"]' , spells ) ;
213+ // INVENTORY
214+ const consumables = [ 'consumable' ] . map ( ( t ) => actor . getItemsByType ( t ) ) . flat ( ) ;
215+ FoundryUtils . itemContextMenu ( element , '[data-context-menu="inventory"]' , consumables ) ;
216+ // SKILLS
217+ /** @type {FUItem[] } **/
218+ let skills = [ 'skill' , 'miscAbility' ]
219+ . map ( ( t ) => actor . getItemsByType ( t ) )
220+ . flat ( )
221+ . filter ( ( s ) => {
222+ return ! s . system . passive ;
223+ } ) ;
224+ for ( const fuid of ActionHandler . skillsWithApps ) {
225+ const skill = actor . getItemsByFuid ( fuid ) ;
226+ if ( skill ) {
227+ skills . push ( ...skill ) ;
228+ }
229+ }
230+ FoundryUtils . itemContextMenu ( element , '[data-context-menu="skill"]' , skills ) ;
231+ }
158232}
0 commit comments