Skip to content

Commit

Permalink
WIP! Begins work on processing the rolls returned by the action activ…
Browse files Browse the repository at this point in the history
…ation dialog. Makes the various default roll data methods in the actor class public so that they can be used for item activation. Fixes a bug in the action activation dialog related to selected prompts and roles.
  • Loading branch information
Pjb518 committed Mar 9, 2023
1 parent 3f6ed27 commit 6da8557
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 23 deletions.
2 changes: 0 additions & 2 deletions src/apps/components/pages/ActionsDescriptionTab.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
["item", "A5E.Item"],
];
console.log($item.system.actions[actionId]);
$: content = $item.system.actions[actionId]?.description;
$: descriptionOutputs =
$item.system.actions[actionId]?.descriptionOutputs ?? [];
Expand Down
1 change: 0 additions & 1 deletion src/apps/components/pages/BackgroundEquipmentTab.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
const { uuid } = JSON.parse(
dragEvent.dataTransfer.getData("text/plain")
);
console.log(uuid);
linkedEquipment.add({ uuid });
} catch (err) {
Expand Down
4 changes: 1 addition & 3 deletions src/apps/dialogs/ActionActivationDialog.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
["generic", "healing", "damage"].includes(value.type) &&
!value.formula
) {
acc.push(key);
return acc;
}
if (value.default ?? true) acc.push(key);
Expand Down Expand Up @@ -124,8 +124,6 @@
let selectedPrompts = getDefaultSelections(prompts);
let situationalMods = "";
console.log(selectedPrompts);
$: rollFormula = constructD20RollFormula({
actor: $actor,
rollMode,
Expand Down
34 changes: 17 additions & 17 deletions src/documents/actor.js
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,7 @@ export default class ActorA5e extends Actor {
async rollAbilityCheck(abilityKey, options = {}) {
let dialogData;

if (options.skipRollDialog) dialogData = this.#getDefaultAbilityCheckData(abilityKey, options);
if (options.skipRollDialog) dialogData = this.getDefaultAbilityCheckData(abilityKey, options);
else dialogData = await this.#showAbilityCheckPrompt(abilityKey, options);

if (!dialogData) return;
Expand Down Expand Up @@ -730,12 +730,12 @@ export default class ActorA5e extends Actor {
ChatMessage.create(chatData);
}

#getDefaultAbilityCheckData(abilityKey, options) {
getDefaultAbilityCheckData(abilityKey, options = {}) {
const ability = this.system.abilities[abilityKey];

const rollFormula = constructD20RollFormula({
actor: this,
rollMode: options.rollMode ?? CONFIG.A5E.ROLL_MODE.NORMAL,
rollMode: options?.rollMode ?? CONFIG.A5E.ROLL_MODE.NORMAL,
modifiers: [
{
label: `${game.i18n.localize(CONFIG.A5E.abilities[abilityKey])} Mod`,
Expand All @@ -753,10 +753,10 @@ export default class ActorA5e extends Actor {
},
{
label: 'Expertise Die',
value: getExpertiseDieSize(options.expertiseDice ?? ability.expertiseDice)
value: getExpertiseDieSize(options?.expertiseDice ?? ability.expertiseDice)
},
{
value: options.situationalMods
value: options?.situationalMods
}
]
});
Expand Down Expand Up @@ -828,7 +828,7 @@ export default class ActorA5e extends Actor {
async rollSavingThrow(abilityKey, options = {}) {
let dialogData;

if (options.skipRollDialog) dialogData = this.#getDefaultSavingThrowData(abilityKey, options);
if (options.skipRollDialog) dialogData = this.getDefaultSavingThrowData(abilityKey, options);
else dialogData = await this.#showSavingThrowPrompt(abilityKey, options);

if (dialogData === null) return;
Expand Down Expand Up @@ -866,12 +866,12 @@ export default class ActorA5e extends Actor {
ChatMessage.create(chatData);
}

#getDefaultSavingThrowData(abilityKey, options) {
getDefaultSavingThrowData(abilityKey, options = {}) {
const ability = this.system.abilities[abilityKey];

const rollFormula = constructD20RollFormula({
actor: this,
rollMode: options.rollMode ?? CONFIG.A5E.ROLL_MODE.NORMAL,
rollMode: options?.rollMode ?? CONFIG.A5E.ROLL_MODE.NORMAL,
modifiers: [
{
label: `${game.i18n.localize(CONFIG.A5E.abilities[abilityKey])} Mod`,
Expand All @@ -896,10 +896,10 @@ export default class ActorA5e extends Actor {
},
{
label: 'Expertise Die',
value: getExpertiseDieSize(options.expertiseDice ?? ability?.expertiseDice)
value: getExpertiseDieSize(options?.expertiseDice ?? ability?.expertiseDice)
},
{
value: options.situationalMods
value: options?.situationalMods
}
]
});
Expand Down Expand Up @@ -929,7 +929,7 @@ export default class ActorA5e extends Actor {
async rollSkillCheck(skillKey, options = {}) {
let rollData;

if (options.skipRollDialog) rollData = this.#getDefaultSkillRollData(skillKey, options);
if (options.skipRollDialog) rollData = this.getDefaultSkillCheckData(skillKey, options);
else rollData = await this.#showSkillCheckPrompt(skillKey, options);

if (!rollData) return;
Expand Down Expand Up @@ -964,17 +964,17 @@ export default class ActorA5e extends Actor {
ChatMessage.create(chatData);
}

#getDefaultSkillRollData(skillKey, options) {
getDefaultSkillCheckData(skillKey, options = {}) {
const skill = this.system.skills[skillKey];
const abilityKey = options.abilityKey ?? skill.ability;
const abilityKey = options?.abilityKey ?? skill.ability;
const ability = this.system.abilities[abilityKey];

// TODO: Update the keys below to use format and proper localisations.

const rollFormula = constructD20RollFormula({
actor: this,
rollMode: options.rollMode ?? CONFIG.A5E.ROLL_MODE.NORMAL,
minRoll: options.minRoll ?? skill.minRoll,
rollMode: options?.rollMode ?? CONFIG.A5E.ROLL_MODE.NORMAL,
minRoll: options?.minRoll ?? skill.minRoll,
modifiers: [
{
label: `${game.i18n.localize(CONFIG.A5E.skills[skillKey])} Mod`,
Expand Down Expand Up @@ -1002,10 +1002,10 @@ export default class ActorA5e extends Actor {
},
{
label: 'Expertise Die',
value: getExpertiseDieSize(options.expertiseDice ?? skill.expertiseDice)
value: getExpertiseDieSize(options?.expertiseDice ?? skill.expertiseDice)
},
{
value: options.situationalMods
value: options?.situationalMods
}
]
});
Expand Down
14 changes: 14 additions & 0 deletions src/documents/item.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ export default class ItemA5e extends Item {

if (!promise) return;

const rolls = promise?.rolls?.map(([_, roll]) => this.#prepareItemRoll(roll)).filter(Boolean);

// TODO: Add template validation and extract template placement to its own function
if (promise.placeTemplate) {
// const templateDocument = createTemplateDocument(this);
Expand Down Expand Up @@ -155,6 +157,18 @@ export default class ItemA5e extends Item {
ChatMessage.create(chatData);
}

#prepareItemRoll(roll) {
switch (roll.type) {
case 'abilityCheck':
return this.actor.getDefaultAbilityCheckData(roll.ability);
case 'savingThrow':
return this.actor.getDefaultSavingThrowData(roll.ability);
case 'skillCheck':
return this.actor.getDefaultSkillCheckData(roll.skill, roll.ability);
default: return null;
}
}

async shareItemDescription() {
const chatData = {
user: game.user?.id,
Expand Down

0 comments on commit 6da8557

Please sign in to comment.