Adds proper roll message to unlearned skills.

This commit is contained in:
Michael Stein 2023-04-18 22:47:33 +02:00
parent 81b326e1ee
commit 5de5e043ae
2 changed files with 27 additions and 22 deletions

View File

@ -1,6 +1,6 @@
import { Evaluated } from "@league-of-foundry-developers/foundry-vtt-types/src/foundry/client/dice/roll"; import { Evaluated } from "@league-of-foundry-developers/foundry-vtt-types/src/foundry/client/dice/roll";
import { M5Character } from "../actors/M5Character"; import { M5Character } from "../actors/M5Character";
import { M5EwResult, M5RollData, M5RollResult } from "../M5Base"; import { M5EwResult, M5RollData, M5RollResult, M5SkillUnlearned } from "../M5Base";
export class M5Roll { // extends Roll<M5RollData> export class M5Roll { // extends Roll<M5RollData>
static readonly TEMPLATE_PATH = "systems/midgard5/templates/chat/roll-m5.hbs" static readonly TEMPLATE_PATH = "systems/midgard5/templates/chat/roll-m5.hbs"
@ -158,6 +158,28 @@ export class M5Roll { // extends Roll<M5RollData>
return new M5Roll(rollData, actor, (game as Game).i18n.localize(`midgard5.actor-${attributeKey}-long`)) 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) { static brawl(actor: any) {
const rollData = actor.getRollData() as M5RollData const rollData = actor.getRollData() as M5RollData
rollData.i = { rollData.i = {

View File

@ -129,28 +129,11 @@ export default class M5CharacterSheet extends ActorSheet {
const row = event.target.parentElement.parentElement const row = event.target.parentElement.parentElement
let skillName = row.dataset["skill"] let skillName = row.dataset["skill"]
const actor = this.actor as M5Character const data = this.actor.system
const context = this.actor as any const unlearnedSkill = data.skills.general[skillName] as M5SkillUnlearned
const data = context.system
const skill = data.skills.general[skillName] const roll = M5Roll.fromUnlearnedSkill(this.actor, unlearnedSkill, skillName)
const attribute = data.attributes[skill.attribute] await roll.toMessage()
//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)
})
}) })
html.find(".learn-button").on("click", async (event) => { html.find(".learn-button").on("click", async (event) => {