From aefdb54c857fba6ebbd22545dc5e7aec68bea487 Mon Sep 17 00:00:00 2001 From: LeRatierBretonnien Date: Fri, 20 Jan 2023 15:19:04 +0100 Subject: [PATCH] Update sheet --- modules/heritiers-actor-sheet.js | 37 ++----- modules/heritiers-actor.js | 134 ++++++----------------- modules/heritiers-item-sheet.js | 1 - modules/heritiers-roll-dialog.js | 21 +++- modules/heritiers-utility.js | 41 +++++-- system.json | 4 +- templates/actor-sheet.html | 168 +++++++++++++---------------- templates/roll-dialog-generic.html | 34 ++++-- 8 files changed, 200 insertions(+), 240 deletions(-) diff --git a/modules/heritiers-actor-sheet.js b/modules/heritiers-actor-sheet.js index bb70a33..3402b7d 100644 --- a/modules/heritiers-actor-sheet.js +++ b/modules/heritiers-actor-sheet.js @@ -43,12 +43,13 @@ export class HeritiersActorSheet extends ActorSheet { armes: duplicate(this.actor.getWeapons()), monnaies: duplicate(this.actor.getMonnaies()), protections: duplicate(this.actor.getArmors()), - profils: duplicate(this.actor.getProfils() || []), combat: this.actor.getCombatValues(), equipements: duplicate(this.actor.getEquipments()), - monnaies: duplicate(this.actor.getMonnaies()), - richesse: this.actor.computeRichesse(), - valeurEquipement: this.actor.computeValeurEquipement(), + avantages: duplicate(this.actor.getAvantages()), + atouts: duplicate(this.actor.getAtouts()), + capacites: duplicate(this.actor.getCapacites()), + desavantages: duplicate(this.actor.getDesavantages()), + pvMalus: this.actor.getPvMalus(), initiative: this.actor.getFlag("world", "last-initiative") || -1, description: await TextEditor.enrichHTML(this.object.system.biodata.description, {async: true}), habitat: await TextEditor.enrichHTML(this.object.system.biodata.habitat, {async: true}), @@ -124,26 +125,15 @@ export class HeritiersActorSheet extends ActorSheet { this.actor.rollAttribut("pre", true) }) - html.find('.roll-attribut').click((event) => { - const li = $(event.currentTarget).parents(".item") - let attrKey = li.data("attr-key") - this.actor.rollAttribut(attrKey, false) + html.find('.roll-carac').click((event) => { + const key = $(event.currentTarget).data("key") + this.actor.rollCarac(key, false) }) html.find('.roll-competence').click((event) => { const li = $(event.currentTarget).parents(".item") let compId = li.data("item-id") this.actor.rollCompetence(compId) }) - html.find('.roll-arme-offensif').click((event) => { - const li = $(event.currentTarget).parents(".item") - let armeId = li.data("item-id") - this.actor.rollArmeOffensif(armeId) - }) - html.find('.roll-arme-degats').click((event) => { - const li = $(event.currentTarget).parents(".item") - let armeId = li.data("item-id") - this.actor.rollArmeDegats(armeId) - }) html.find('.item-add').click((event) => { const itemType = $(event.currentTarget).data("type") @@ -173,19 +163,14 @@ export class HeritiersActorSheet extends ActorSheet { } /* -------------------------------------------- */ - async _onDropItem(event, dragData) { + /*async _onDropItem(event, dragData) { let data = event.dataTransfer.getData('text/plain') let dataItem = JSON.parse( data) let item = fromUuidSync(dataItem.uuid) if (item.pack) { item = await HeritiersUtility.searchItem(item) } - let autoresult = HeritiersAutomation.processAutomations("on-drop", item, this.actor) - if ( autoresult.isValid ) { - super._onDropItem(event, dragData) - } else { - ui.notifications.warn( autoresult.warningMessage) - } - } + super._onDropItem(event, dragData) + }*/ } diff --git a/modules/heritiers-actor.js b/modules/heritiers-actor.js index e8baa23..1e0ca32 100644 --- a/modules/heritiers-actor.js +++ b/modules/heritiers-actor.js @@ -106,33 +106,30 @@ export class HeritiersActor extends Actor { getEquipments() { return this.items.filter(item => item.type == "equipement") } - /* ----------------------- --------------------- */ - getArtefacts() { - return this.items.filter(item => item.type == "artefact") + getAvantages() { + return this.items.filter(item => item.type == "avantage") + } + getDesavantages() { + return this.items.filter(item => item.type == "desavantage") } - /* ----------------------- --------------------- */ getMonnaies() { return this.items.filter(item => item.type == "monnaie") } - /* -------------------------------------------- */ getArmors() { return this.items.filter(item => item.type == "protection") } - getHistoriques() { - return this.items.filter(item => item.type == "historique") - } - getProfils() { - return this.items.filter(item => item.type == "profil") - } getTalents() { return this.items.filter(item => item.type == "talent") } - getRessources() { - return this.items.filter(item => item.type == "ressource") - } getContacts() { return this.items.filter(item => item.type == "contact") } + getAtouts() { + return this.items.filter(item => item.type == "atoutfeerique") + } + getCapacites() { + return this.items.filter(item => item.type == "capacitenaturelle") + } /* -------------------------------------------- */ getSkills() { let comp = [] @@ -262,90 +259,17 @@ export class HeritiersActor extends Actor { } /* -------------------------------------------- */ - checkAttribut(attribut, minLevel) { - let attr = this.system.attributs.find(at => at.labelnorm == attribut.toLowerCase()) - if (attr && attr.value >= minLevel) { - return { isValid: true, attr: duplicate(attr) } - } - return { isValid: false } - } - /* -------------------------------------------- */ - checkAttributOrCompetenceLevel(compName, minLevel) { - let comp = this.items.find(i => i.type == "competence" && i.name.toLowerCase() == compName.toLowerCase() && i.system.niveau >= minLevel) - if (comp) { - return { isValid: true, item: duplicate(comp) } - } else { - for (let attrKey in this.system.attributs) { - if (this.system.attributs[attrKey].label.toLowerCase() == compName.toLowerCase() && this.system.attributs[attrKey].value >= minLevel) { - return { isValid: true, item: duplicate(this.system.attributs[attrKey]) } - } + getPvMalus() { + if (this.system.pv.value > 0) { + if (this.system.pv.value < this.system.pv.max / 2) { + return -1 } - } - return { isValid: false, warningMessage: `Prérequis insuffisant : la compétence/attribut ${compName} doit être de niveau ${minLevel} au minimum` } - } - /* -------------------------------------------- */ - addCompetenceBonus(compName, bonus, baCost) { - let comp = this.items.find(i => i.type == "competence" && i.name.toLowerCase() == compName.toLowerCase()) - if (comp) { - comp = duplicate(comp) - comp.system.bonus = bonus - comp.system.baCost = baCost - return { isValid: true, item: comp } - } - return { isValid: false, warningMessage: `Compétence ${compName} non trouvée` } - } - /* -------------------------------------------- */ - checkIfCompetence(compName) { - let comp = this.items.find(i => i.type == "competence" && i.name.toLowerCase() == compName.toLowerCase()) - if (comp) { - return { isValid: true, item: comp } - } - return { isValid: false } - } - /* -------------------------------------------- */ - getVigueur() { - return this.system.sante.vigueur - } - - /* -------------------------------------------- */ - getVigueurBonus() { - let talents = this.items.filter(item => item.type == "talent" && item.system.isautomated) - let bonus = 0 - for (let talent of talents) { - for (let auto of talent.system.automations) { - if (auto.eventtype == "bonus-permanent" && auto.bonusname == "vigueur") { - bonus += Number(auto.bonus || 0) - } + if (this.system.pv.value < 5) { + return -2 } + return 0 } - return bonus - } - - /* -------------------------------------------- */ - getBonneAventure() { - return this.system.bonneaventure.actuelle - } - /* -------------------------------------------- */ - checkBonneAventure(cost) { - return (this.system.bonneaventure.actuelle >= cost) - } - /* -------------------------------------------- */ - changeBonneAventure(value) { - let newBA = this.system.bonneaventure.actuelle - newBA += value - this.update({ 'system.bonneaventure.actuelle': newBA }) - } - - /* -------------------------------------------- */ - getEclat() { - return this.system.eclat.value - } - - /* -------------------------------------------- */ - changeEclat(value) { - let newE = this.system.eclat.value - newE += value - this.update({ 'system.eclat.value': newE }) + return "Moribond(e)" } /* -------------------------------------------- */ @@ -514,6 +438,14 @@ export class HeritiersActor extends Actor { getHeritages() { return this.system.rang.heritage.value } + /* -------------------------------------------- */ + incDecTricherie(value) { + let tricherie = this.system.rang.tricherie + tricherie.value += value + tricherie.value = Math.max(tricherie.value, 0) + tricherie.value = Math.min(tricherie.value, tricherie.max) + this.update({ 'system.rang.tricherie': tricherie }) + } /* -------------------------------------------- */ getCommonRollData(compId = undefined, compName = undefined) { @@ -529,6 +461,7 @@ export class HeritiersActor extends Actor { rollData.heritage = this.getHeritages() rollData.useTricherie = false rollData.useHeritage = false + rollData.pvMalus = this.getPvMalus() if (compId) { rollData.competence = duplicate(this.items.get(compId) || {}) @@ -542,10 +475,11 @@ export class HeritiersActor extends Actor { } /* -------------------------------------------- */ - async rollAttribut(attrKey, isInit = false) { - let rollData = this.getCommonRollData(attrKey) - rollData.multiplier = (isInit) ? 1 : 2 - rollData.isInit = isInit + async rollCarac(key, isInit = false) { + let rollData = this.getCommonRollData() + rollData.mode = "carac" + rollData.carac = this.system.caracteristiques[key] + rollData.caracKey = key let rollDialog = await HeritiersRollDialog.create(this, rollData) rollDialog.render(true) } @@ -553,7 +487,7 @@ export class HeritiersActor extends Actor { /* -------------------------------------------- */ async rollCompetence(compId) { let rollData = this.getCommonRollData(compId) - rollData.multiplier = 1 // Attr multiplier, always 1 in competence mode + rollData.mode = "competence" console.log("RollDatra", rollData) let rollDialog = await HeritiersRollDialog.create(this, rollData) rollDialog.render(true) diff --git a/modules/heritiers-item-sheet.js b/modules/heritiers-item-sheet.js index 61e7628..acb556a 100644 --- a/modules/heritiers-item-sheet.js +++ b/modules/heritiers-item-sheet.js @@ -57,7 +57,6 @@ export class HeritiersItemSheet extends ItemSheet { name: objectData.name, editable: this.isEditable, cssClass: this.isEditable ? "editable" : "locked", - attributs: HeritiersUtility.getAttributs(), system: objectData.system, limited: this.object.limited, options: this.options, diff --git a/modules/heritiers-roll-dialog.js b/modules/heritiers-roll-dialog.js index 19e8b15..4a4241a 100644 --- a/modules/heritiers-roll-dialog.js +++ b/modules/heritiers-roll-dialog.js @@ -16,7 +16,8 @@ export class HeritiersRollDialog extends Dialog { let conf = { title: "Test de Capacité", content: html, - buttons: { + buttons: + { rolld8: { icon: '', label: "Lancer 1d8", @@ -40,7 +41,21 @@ export class HeritiersRollDialog extends Dialog { }, close: close } - + // Overwrite in case of carac only -> 1d10 + if (rollData.mode == "carac") { + conf.buttons = { + rolld8: { + icon: '', + label: "Lancer 1d8", + callback: () => { this.roll("d8") } + }, + cancel: { + icon: '', + label: "Annuler", + callback: () => { this.close() } + } + } + } super(conf, options); this.actor = actor @@ -77,6 +92,6 @@ export class HeritiersRollDialog extends Dialog { }) html.find('#useHeritage').change((event) => { this.rollData.useHeritage = event.currentTarget.checked - }) + }) } } \ No newline at end of file diff --git a/modules/heritiers-utility.js b/modules/heritiers-utility.js index 2ddcc0d..552e7a6 100644 --- a/modules/heritiers-utility.js +++ b/modules/heritiers-utility.js @@ -277,27 +277,55 @@ export class HeritiersUtility { } /* -------------------------------------------- */ - static computeResult(rollData) { + static incDecHeritage() { + + } + + /* -------------------------------------------- */ + static computeResult(actor, rollData) { rollData.diceResult = -1 + let resTab = [] for ( let res of rollData.roll.terms[0].results) { rollData.diceResult = Math.max(res.result, rollData.diceResult) + resTab.push(res.result) } + let isFailure = false if (rollData.mainDice.includes("d10")) { if ( rollData.diceResult == 1) { rollData.finalResult -= 3 + isFailure = true } } if (rollData.mainDice.includes("d12")) { if ( rollData.diceResult == 1 || rollData.diceResult == 2) { rollData.finalResult -= 5 + isFailure = true } } - if (rollData.useHeritage || rollData.useTricherie) { - + // Heritage/Tricherie management + rollData.marge = 0 + if (!isFailure && (rollData.useHeritage || rollData.useTricherie)) { + resTab = resTab.sort() + if ( (resTab[0] == resTab[1]) && (resTab[1] == resTab[2])) { + rollData.marge = 7 + rollData.isSuccess = true + rollData.isCriticalSuccess = true + } + if ((resTab[0]+1 == resTab[1]) && (resTab[1]+1 == resTab[2]) ) { + rollData.marge = 7 + rollData.isSuccess = true + rollData.isCriticalSuccess = true + } + if ( rollData.useTricherie) { + actor.incDecTricherie(-1) + } + if ( rollData.useHeritage) { + this.incDecHeritage() + } } //rollData.finalResult = Math.max(rollData.finalResult, 0) //console.log("Result : ", rollData) - if (rollData.sdValue > 0 ) { + if (rollData.marge == 0 && rollData.sdValue > 0 ) { rollData.marge = rollData.finalResult - rollData.sdValue rollData.isSuccess = (rollData.finalResult >= rollData.sdValue) rollData.isCriticalSuccess = ((rollData.finalResult - rollData.sdValue) >= 7) @@ -319,8 +347,9 @@ export class HeritiersUtility { let compmod = (rollData.competence.system.niveau == 0) ? -3 : 0 rollData.diceFormula += `+${rollData.carac.value}+${rollData.competence.system.niveau}+${rollData.bonusMalusContext}+${compmod}` } else { - rollData.diceFormula += `+${rollData.attr.value}*${rollData.multiplier}+${rollData.modificateur}+${rollData.bonusMalusContext}` + rollData.diceFormula += `+${rollData.carac.value}+${rollData.bonusMalusContext}` } + rollData.diceFormula += `+${rollData.pvMalus}` if (rollData.arme && rollData.arme.type == "arme") { rollData.diceFormula += `+${rollData.arme.system.bonusmaniementoff}` @@ -332,7 +361,7 @@ export class HeritiersUtility { console.log(">>>> ", myRoll) rollData.finalResult = myRoll.total - this.computeResult(rollData) + this.computeResult(actor, rollData) if (rollData.isInit) { actor.setFlag("world", "last-initiative", rollData.finalResult) } diff --git a/system.json b/system.json index 1aa8665..f03e6a1 100644 --- a/system.json +++ b/system.json @@ -1,7 +1,7 @@ { "id": "fvtt-les-heritiers", "description": "Les Héritiers pour FoundryVTT", - "version": "10.0.6", + "version": "10.0.7", "authors": [ { "name": "Uberwald/LeRatierBretonnien", @@ -19,7 +19,7 @@ "gridUnits": "m", "license": "LICENSE.txt", "manifest": "https://www.uberwald.me/gitea/public/fvtt-les-heritiers/raw/branch/master/system.json", - "download": "https://www.uberwald.me/gitea/public/fvtt-les-heritiers/archive/fvtt-les-heritiers-10.0.6.zip", + "download": "https://www.uberwald.me/gitea/public/fvtt-les-heritiers/archive/fvtt-les-heritiers-10.0.7.zip", "languages": [ { "lang": "fr", diff --git a/templates/actor-sheet.html b/templates/actor-sheet.html index be45a9d..ae323e5 100644 --- a/templates/actor-sheet.html +++ b/templates/actor-sheet.html @@ -14,7 +14,7 @@ {{#each system.caracteristiques as |carac key|}} {{#if (eq kind "physical")}}
  • -

    {{carac.label}}

    +

    {{carac.label}}

    -

    {{carac.label}}

    +

    {{carac.label}}

    + +
    + + + + + +    + + + +
    + @@ -51,7 +64,7 @@ Compétences Combat Equipement - Fée + Fée Bio&Notes @@ -245,90 +258,25 @@ - {{!-- Equipement Tab --}} -
    + {{!-- Fee Tab --}} +
    -
    -
    -

    - -

    -
    -
    • -

      -
      - - - - -
       
      -
      - -
      -
    • - {{#each monnaies as |monnaie key|}} -
    • - - {{monnaie.name}} - {{monnaie.system.quantite}} - - - + +

       
      - -
    • - {{/each}} -
    -
    - -
    -
    -

    - -

    -
    - -
    -
      -
    • - -

      -
      - - - - - -
       
      -
      - -
      -
    • - {{#each equipements as |equipement key|}} -
    • - - {{equipement.name}} - {{equipement.system.quantite}} - - - + - + {{#each avantages as |avantage key|}} +
    • + + {{avantage.name}}
       
      @@ -343,27 +291,16 @@
      • -

        +

        - - - - -
         
        -
      • - {{#each artefacts as |artefact key|}} -
      • - - {{artefact.name}} - {{artefact.system.quantite}} - - - + - + {{#each desavantages as |desavantage key|}} +
      • + + {{desavantage.name}}
         
        @@ -374,6 +311,55 @@
      +
      +
        +
      • + +

        +
        +
         
        +
        +
        +
      • + {{#each atouts as |atout key|}} +
      • + + {{atout.name}} +
         
        +
        + + +
        +
      • + {{/each}} +
      +
      + +
      +
        +
      • + +

        +
        +
         
        +
        +
        +
      • + {{#each capacites as |capa key|}} +
      • + + {{capa.name}} +
         
        +
        + + +
        +
      • + {{/each}} +
      +
      + +
    diff --git a/templates/roll-dialog-generic.html b/templates/roll-dialog-generic.html index a460834..8562b50 100644 --- a/templates/roll-dialog-generic.html +++ b/templates/roll-dialog-generic.html @@ -8,16 +8,23 @@
    -
    - Caracteristique - -
    + {{#if (eq mode "carac")}} +
    + Caracteristique + {{carac.label}} ({{carac.value}}) +
    + {{else}} +
    + Caracteristique + +
    + {{/if}} {{#if competence}}
    @@ -25,7 +32,12 @@ {{competence.system.niveau}}
    {{/if}} - + +
    + Malus de Santé + {{pvMalus}} +
    + {{#if tricherie}}
    Utiliser 1 point de Tricherie ({{tricherie}}) ?