diff --git a/source/module/rolls/M5Roll.ts b/source/module/rolls/M5Roll.ts index 460c8b6..00e47b9 100644 --- a/source/module/rolls/M5Roll.ts +++ b/source/module/rolls/M5Roll.ts @@ -1,6 +1,6 @@ import { Evaluated } from "@league-of-foundry-developers/foundry-vtt-types/src/foundry/client/dice/roll"; import { M5Character } from "../actors/M5Character"; -import { M5EwResult, M5RollData, M5RollResult } from "../M5Base"; +import { M5EwResult, M5RollData, M5RollResult, M5SkillUnlearned } from "../M5Base"; export class M5Roll { // extends Roll static readonly TEMPLATE_PATH = "systems/midgard5/templates/chat/roll-m5.hbs" @@ -158,6 +158,28 @@ export class M5Roll { // extends Roll return new M5Roll(rollData, actor, (game as Game).i18n.localize(`midgard5.actor-${attributeKey}-long`)) } + static fromUnlearnedSkill(actor: any, skill: M5SkillUnlearned, skillName: string) { + const rollData = actor.getRollData() as M5RollData + rollData.i = { + fw: skill.fw, + bonus: actor.system.calc?.attributes[skill.attribute]?.bonus ?? 0 + } + rollData.iType = "skill" + + rollData.rolls["0"] = { + formula: "1d20 + @i.fw + @i.bonus", + enabled: true, + label: (game as Game).i18n.localize("midgard5.pw"), + result: "", + total: 0, + totalStr: "", + dice: {}, + css: "" + } as M5RollResult + + return new M5Roll(rollData, actor, (game as Game).i18n.localize(`midgard5.${skillName}`)) + } + static brawl(actor: any) { const rollData = actor.getRollData() as M5RollData rollData.i = { diff --git a/source/module/sheets/M5CharacterSheet.ts b/source/module/sheets/M5CharacterSheet.ts index e2e1193..54886aa 100644 --- a/source/module/sheets/M5CharacterSheet.ts +++ b/source/module/sheets/M5CharacterSheet.ts @@ -129,28 +129,11 @@ export default class M5CharacterSheet extends ActorSheet { const row = event.target.parentElement.parentElement let skillName = row.dataset["skill"] - const actor = this.actor as M5Character - const context = this.actor as any - const data = context.system + const data = this.actor.system + const unlearnedSkill = data.skills.general[skillName] as M5SkillUnlearned - const skill = data.skills.general[skillName] - const attribute = data.attributes[skill.attribute] - //console.log(skill, attribute) - - const r = new Roll("1d20 + @fw + @bonus", { - fw: skill.fw, - bonus: M5Character.attributeBonus(attribute) - }) - await r.evaluate().then(value => { - const skillLocalized = (game as Game).i18n.localize("midgard5." + skillName) - const chatString = skillLocalized + ": " + value.result + " = " + value.total - //console.log(chatString) - - const speaker = ChatMessage.getSpeaker({actor: actor}) - let chatData = { content: (game as Game).i18n.format(chatString, {name: (actor as any).name}), speaker } - ChatMessage.applyRollMode(chatData, (r.options as any).rollMode) - return ChatMessage.create(chatData) - }) + const roll = M5Roll.fromUnlearnedSkill(this.actor, unlearnedSkill, skillName) + await roll.toMessage() }) html.find(".learn-button").on("click", async (event) => {