From b44ac05b1e634366fb4f1f20de83dcb9e9460724 Mon Sep 17 00:00:00 2001 From: LeRatierBretonnien Date: Sat, 4 Jan 2025 22:24:39 +0100 Subject: [PATCH] Initial release --- cthulhu-eternal.mjs | 1 - lang/en.json | 5 +++ .../applications/sheets/protagonist-sheet.mjs | 12 +++-- module/documents/roll.mjs | 45 ++++++++++++++++--- module/models/protagonist.mjs | 18 ++------ module/models/skill.mjs | 1 + templates/chat-message.hbs | 6 +++ templates/protagonist-equipment.hbs | 4 +- templates/roll-dialog.hbs | 6 +++ templates/skill.hbs | 1 + 10 files changed, 73 insertions(+), 26 deletions(-) diff --git a/cthulhu-eternal.mjs b/cthulhu-eternal.mjs index c2fa9ed..b42b630 100644 --- a/cthulhu-eternal.mjs +++ b/cthulhu-eternal.mjs @@ -98,7 +98,6 @@ Hooks.once("init", function () { const type = anchor.dataset.rollType const target = anchor.dataset.rollTarget const title = anchor.dataset.rollTitle - const avantage = anchor.dataset.rollAvantage }) console.info("CTHULHU ETERNAL | System Initialized") diff --git a/lang/en.json b/lang/en.json index 0b5e617..2c276a2 100644 --- a/lang/en.json +++ b/lang/en.json @@ -92,6 +92,9 @@ "RangedWeapons": "Ranged Weapons", "FirearmsBeams": "Firearms / Beam Weapons", "FIELDS": { + "isAdversary": { + "label": "Adversary" + }, "settings": { "label": "Settings era" }, @@ -253,6 +256,8 @@ "veryHarsh": "Very Harsh" }, "Label": { + "titleSkill": "Skill", + "titleWeapon": "Weapon", "biodata": "Biodata", "skill": "Skill", "modifier": "Modifier", diff --git a/module/applications/sheets/protagonist-sheet.mjs b/module/applications/sheets/protagonist-sheet.mjs index b08a9a9..33884a1 100644 --- a/module/applications/sheets/protagonist-sheet.mjs +++ b/module/applications/sheets/protagonist-sheet.mjs @@ -53,7 +53,7 @@ export default class CthulhuEternalProtagonistSheet extends CthulhuEternalActorS /** * Prepare an array of form header tabs. * @returns {Record>} - */ + */ #getTabs() { const tabs = { skills: { id: "skills", group: "sheet", icon: "fa-solid fa-shapes", label: "CTHULHUETERNAL.Label.skills" }, @@ -185,9 +185,10 @@ export default class CthulhuEternalProtagonistSheet extends CthulhuEternalActorS async _onRoll(event, target) { const rollType = $(event.currentTarget).data("roll-type") let item + let li // Debug : console.log(">>>>", event, target, rollType) // Deprecated : if (this.isEditMode) return - switch(rollType) { + switch (rollType) { case "char": let charId = $(event.currentTarget).data("char-id") item = foundry.utils.duplicate(this.actor.system.characteristics[charId]) @@ -195,7 +196,12 @@ export default class CthulhuEternalProtagonistSheet extends CthulhuEternalActorS item.targetScore = item.value * 5 break case "skill": - const li = $(event.currentTarget).parents(".item"); + li = $(event.currentTarget).parents(".item"); + item = this.actor.items.get(li.data("item-id")); + break + case "weapon": + case "damage": + li = $(event.currentTarget).parents(".item"); item = this.actor.items.get(li.data("item-id")); break default: diff --git a/module/documents/roll.mjs b/module/documents/roll.mjs index 0fb8cde..3802592 100644 --- a/module/documents/roll.mjs +++ b/module/documents/roll.mjs @@ -1,4 +1,5 @@ +import { SYSTEM } from "../config/system.mjs" export default class CthulhuEternalRoll extends Roll { /** * The HTML template path used to render dice checks of this type @@ -74,6 +75,10 @@ export default class CthulhuEternalRoll extends Roll { return this.options.realDamage } + get weapon() { + return this.options.weapon + } + /** * Prompt the user with a dialog to configure and execute a roll. * @@ -98,6 +103,32 @@ export default class CthulhuEternalRoll extends Roll { case "char": options.initialScore = options.rollItem.targetScore break + case "damage": + let formula = options.rollItem.system.damage + let damageRoll = new Roll(formula) + await damageRoll.evaluate() + await damageRoll.toMessage({ + flavor: `${options.rollItem.name} - Damage Roll` + }); + let isLethal = false + if (options.rollItem.system.lethality > 0 ) { + let lethalityRoll = new Roll("1d100") + await lethalityRoll.evaluate() + isLethal = (lethalityRoll.total <= options.rollItem.system.lethality) + await lethalityRoll.toMessage({ + flavor: `${options.rollItem.name} - Lethality Roll : ${lethalityRoll.total} <= ${options.rollItem.system.lethality} => ${isLethal}` + }); + } + return + case "weapon": + let era = game.settings.get("fvtt-cthulhu-eternal", "settings-era") + let skillName = game.i18n.localize(SYSTEM.WEAPON_SKILL_MAPPING[era][options.rollItem.system.weaponType]) + let actor = game.actors.get(options.actorId) + options.weapon = options.rollItem + options.rollItem = actor.items.find(i => i.type === "skill" && i.name.toLowerCase() === skillName.toLowerCase()) + options.initialScore = options.rollItem.system.computeScore() + console.log("WEAPON", skillName, era, options.rollItem) + break default: options.initialScore = 50 break @@ -114,7 +145,7 @@ export default class CthulhuEternalRoll extends Roll { "-10": "-10", "-20": "-20", "-40": "-40", - 0: "0", + "0": "0", "+10": "+10", "+20": "+20", "+40": "+40", @@ -128,6 +159,7 @@ export default class CthulhuEternalRoll extends Roll { let dialogContext = { rollType: options.rollType, rollItem: foundry.utils.duplicate(options.rollItem), // Object only, no class + weapon: options?.weapon, initialScore: options.initialScore, targetScore: options.initialScore, isLowWP: options.isLowWP, @@ -201,12 +233,12 @@ export default class CthulhuEternalRoll extends Roll { if (roll.total <= rollData.targetScore) { resultType = "success" // Detect if decimal == unit in the dire total result - if (dec === unit || roll.total == 1) { + if (dec === unit || roll.total === 1) { resultType = "successCritical" } } else { // Detect if decimal == unit in the dire total result - if (dec === unit || roll.total == 100) { + if (dec === unit || roll.total === 100) { resultType = "failureCritical" } } @@ -234,9 +266,11 @@ export default class CthulhuEternalRoll extends Roll { static createTitle(type, target) { switch (type) { case "skill": - return `${game.i18n.localize("CTHULHUETERNAL.Dialog.titleSkill")}` + return `${game.i18n.localize("CTHULHUETERNAL.Label.titleSkill")}` + case "weapon": + return `${game.i18n.localize("CTHULHUETERNAL.Label.titleWeapon")}` default: - return game.i18n.localize("CTHULHUETERNAL.Dialog.titleStandard") + return game.i18n.localize("CTHULHUETERNAL.Label.titleStandard") } } @@ -287,6 +321,7 @@ export default class CthulhuEternalRoll extends Roll { cardData.targetArmor = this.targetArmor cardData.realDamage = this.realDamage cardData.isPrivate = isPrivate + cardData.weapon = this.weapon console.log(cardData) diff --git a/module/models/protagonist.mjs b/module/models/protagonist.mjs index 1671ab3..c4242a1 100644 --- a/module/models/protagonist.mjs +++ b/module/models/protagonist.mjs @@ -155,25 +155,13 @@ export default class CthulhuEternalProtagonist extends foundry.abstract.TypeData /** * Rolls a dice for a character. * @param {("save"|"resource|damage")} rollType The type of the roll. - * @param {number} rollTarget The target value for the roll. Which caracteristic or resource. If the roll is a damage roll, this is the id of the item. - * @param {"="|"+"|"++"|"-"|"--"} rollAdvantage If there is an avantage (+), a disadvantage (-), a double advantage (++), a double disadvantage (--) or a normal roll (=). + * @param {number} rollItem The target value for the roll. Which caracteristic or resource. If the roll is a damage roll, this is the id of the item. * @returns {Promise} - A promise that resolves to null if the roll is cancelled. */ - async roll(rollType, rollTarget, rollAdvantage = "=") { - let rollValue + async roll(rollType, rollItem) { let opponentTarget - switch (rollType) { - default: - // Handle other cases or do nothing - break - } - await this._roll(rollType, rollTarget, rollValue, opponentTarget, rollAdvantage) - } - - /** Main roll function - */ - async _roll(rollType, rollItem, opponentTarget = undefined) { const hasTarget = opponentTarget !== undefined + let roll = await CthulhuEternalRoll.prompt({ rollType, rollItem, diff --git a/module/models/skill.mjs b/module/models/skill.mjs index 1f893ef..a3a4276 100644 --- a/module/models/skill.mjs +++ b/module/models/skill.mjs @@ -12,6 +12,7 @@ export default class CthulhuEternalSkill extends foundry.abstract.TypeDataModel schema.bonus = new fields.NumberField({ ...requiredInteger, required: true, initial: 0, min: 0 }) schema.diceEvolved = new fields.BooleanField({ required: true, initial: true }) schema.rollFailed = new fields.BooleanField({ required: true, initial: false }) + schema.isAdversary = new fields.BooleanField({ required: true, initial: false }) return schema } diff --git a/templates/chat-message.hbs b/templates/chat-message.hbs index 4ba4065..8a683ae 100644 --- a/templates/chat-message.hbs +++ b/templates/chat-message.hbs @@ -9,9 +9,15 @@ {{#if (eq rollType "char")}}
  • {{localize "CTHULHUETERNAL.Label.charRoll"}}
  • {{/if}} + {{#if (eq rollType "skill")}}
  • {{localize "CTHULHUETERNAL.Label.skillRoll"}}
  • {{/if}} + + {{#if weapon}} +
  • Weapon : {{weapon.name}}
  • + {{/if}} +
  • {{rollItem.name}} : {{initialScore}}%
  • {{localize "CTHULHUETERNAL.Label.modifier"}} : {{modifier}}%
  • {{localize "CTHULHUETERNAL.Label.targetScore"}} : {{targetScore}}%
  • diff --git a/templates/protagonist-equipment.hbs b/templates/protagonist-equipment.hbs index ac70548..c75139b 100644 --- a/templates/protagonist-equipment.hbs +++ b/templates/protagonist-equipment.hbs @@ -6,9 +6,9 @@
    {{#each weapons as |item|}} {{!log 'weapon' this}} -
    +
    -
    +
    {{item.name}}
    {{localize "CTHULHUETERNAL.Label.damageShort"}} : {{item.system.damage}} diff --git a/templates/roll-dialog.hbs b/templates/roll-dialog.hbs index 3676fb5..8262b7a 100644 --- a/templates/roll-dialog.hbs +++ b/templates/roll-dialog.hbs @@ -7,7 +7,13 @@ {{#if (eq rollType "char")}} {{localize "CTHULHUETERNAL.Label.characteristic"}} {{/if}} +
    {{rollItem.name}} : {{initialScore}}%
    + + {{#if weapon}} +
    Weapon : {{weapon.name}}
    + {{/if}} + {{#if isZeroWP}}
    Zero WP : Automatic failure (ie 0%)
    {{else}} diff --git a/templates/skill.hbs b/templates/skill.hbs index 7624e96..659037e 100644 --- a/templates/skill.hbs +++ b/templates/skill.hbs @@ -13,6 +13,7 @@ {{localize "CTHULHUETERNAL.Label.totalScore"}} {{system.skillTotal}}
    + {{formField systemFields.isAdversary value=system.isAdversary}} {{formField systemFields.diceEvolved value=system.diceEvolved}} {{#if system.diceEvolved}} {{formField systemFields.rollFailed value=system.rollFailed}}