|
1 | 1 | import { RollableClassFeatureDataModel } from '../class-feature-data-model.mjs'; |
2 | | -import { Flags } from '../../../../helpers/flags.mjs'; |
| 2 | +import { Flags, FlagUtility } from '../../../../helpers/flags.mjs'; |
3 | 3 | import { SYSTEM } from '../../../../helpers/config.mjs'; |
4 | 4 | import { CommonEvents } from '../../../../checks/common-events.mjs'; |
5 | 5 | import { TextEditor } from '../../../../helpers/text-editor.mjs'; |
6 | | -import FoundryUtils from '../../../../helpers/foundry-utils.mjs'; |
| 6 | +import { FeatureTraits } from '../../../../pipelines/traits.mjs'; |
| 7 | +import { CommonSections } from '../../../../checks/common-sections.mjs'; |
| 8 | +import { FUChatBuilder } from '../../../../helpers/chat-builder.mjs'; |
| 9 | +import { StringUtils } from '../../../../helpers/string-utils.mjs'; |
| 10 | +import { Effects } from '../../../../pipelines/effects.mjs'; |
| 11 | +import { systemId } from '../../../../helpers/system-utils.mjs'; |
7 | 12 |
|
8 | 13 | const durations = { |
9 | 14 | instant: 'FU.ClassFeatureDanceDurationInstant', |
@@ -44,21 +49,58 @@ export class DanceDataModel extends RollableClassFeatureDataModel { |
44 | 49 | } |
45 | 50 |
|
46 | 51 | static async roll(model, item, isShift) { |
47 | | - const data = { |
48 | | - duration: durations[model.duration], |
49 | | - description: await TextEditor.enrichHTML(model.description), |
| 52 | + /** @type FURenderData **/ |
| 53 | + const renderData = { |
| 54 | + sections: [], |
| 55 | + postRenderActions: [], |
| 56 | + tags: [ |
| 57 | + { |
| 58 | + tag: `${StringUtils.localize('FU.ClassFeatureDanceDuration')}:`, |
| 59 | + value: StringUtils.localize(durations[model.duration]), |
| 60 | + }, |
| 61 | + ], |
50 | 62 | }; |
51 | | - const speaker = ChatMessage.implementation.getSpeaker({ actor: item.actor }); |
52 | | - const chatMessage = { |
53 | | - speaker, |
54 | | - flavor: await FoundryUtils.renderTemplate('chat/chat-check-flavor-item-v2', { item: item }), |
55 | | - content: await foundry.applications.handlebars.renderTemplate('systems/projectfu/templates/feature/dancer/feature-dance-chat-message.hbs', data), |
56 | | - flags: { |
57 | | - [SYSTEM]: { [Flags.ChatMessage.Item]: item.uuid }, |
58 | | - }, |
| 63 | + |
| 64 | + const actor = item.parent; |
| 65 | + CommonSections.itemFlavor(renderData.sections, item); |
| 66 | + const description = await TextEditor.enrichHTML(model.description); |
| 67 | + CommonSections.genericText(renderData.sections, description); |
| 68 | + const flags = { |
| 69 | + [SYSTEM]: { [Flags.ChatMessage.Item]: item.uuid }, |
59 | 70 | }; |
60 | 71 |
|
| 72 | + /** @type ResourceExpense **/ |
| 73 | + const expense = { |
| 74 | + source: 'skill', |
| 75 | + resource: 'mp', |
| 76 | + amount: 10, |
| 77 | + }; |
| 78 | + |
| 79 | + const currentDance = item.system.fuid; |
| 80 | + const previousDance = actor?.getFlag(systemId, Flags.State.PreviousDance); |
| 81 | + if (previousDance && currentDance !== previousDance) { |
| 82 | + expense.amount = 5; |
| 83 | + } |
| 84 | + |
| 85 | + CommonSections.expense(renderData, actor, item, [], flags, expense); |
| 86 | + await CommonEvents.feature(actor, item, [FeatureTraits.Dance], renderData); |
| 87 | + |
| 88 | + Effects.createTemporaryEffect(actor, 'temporary', 'Previous Dance', { |
| 89 | + img: item.img, |
| 90 | + system: { |
| 91 | + duration: { |
| 92 | + event: 'endOfTurn', |
| 93 | + interval: 1, |
| 94 | + }, |
| 95 | + }, |
| 96 | + changes: [FlagUtility.getEffectChange(Flags.State.PreviousDance, currentDance)], |
| 97 | + }); |
| 98 | + |
| 99 | + const builder = new FUChatBuilder(actor, item); |
| 100 | + builder.withFlags(flags); |
| 101 | + builder.withData(renderData); |
| 102 | + await builder.create(); |
| 103 | + |
61 | 104 | CommonEvents.skill(item.actor, item); |
62 | | - ChatMessage.create(chatMessage); |
63 | 105 | } |
64 | 106 | } |
0 commit comments