From 6497369d7f269583691703d1a53f81b2d54784f6 Mon Sep 17 00:00:00 2001 From: LeRatierBretonnien Date: Sun, 9 Apr 2023 21:45:46 +0200 Subject: [PATCH] Gestion assommer/charge --- modules/heritiers-actor-sheet.js | 16 +++ modules/heritiers-actor.js | 150 +++++++++++++++++++--------- modules/heritiers-item-sheet.js | 1 + modules/heritiers-roll-dialog.js | 6 -- modules/heritiers-utility.js | 51 +++++++--- styles/simple.css | 5 +- system.json | 4 +- templates/actor-sheet.html | 35 ++++--- templates/chat-assommer-result.html | 30 ++++++ templates/chat-generic-result.html | 3 + templates/roll-dialog-generic.html | 13 +++ 11 files changed, 226 insertions(+), 88 deletions(-) create mode 100644 templates/chat-assommer-result.html diff --git a/modules/heritiers-actor-sheet.js b/modules/heritiers-actor-sheet.js index d059541..809ae2a 100644 --- a/modules/heritiers-actor-sheet.js +++ b/modules/heritiers-actor-sheet.js @@ -158,6 +158,22 @@ export class HeritiersActorSheet extends ActorSheet { let armeId = li.data("item-id") this.actor.rollAttaqueArme(armeId) }) + html.find('.roll-attaque-brutale-arme').click((event) => { + const li = $(event.currentTarget).parents(".item") + let armeId = li.data("item-id") + this.actor.rollAttaqueBrutaleArme(armeId) + }) + html.find('.roll-attaque-charge-arme').click((event) => { + const li = $(event.currentTarget).parents(".item") + let armeId = li.data("item-id") + this.actor.rollAttaqueChargeArme(armeId) + }) + html.find('.roll-assomer-arme').click((event) => { + const li = $(event.currentTarget).parents(".item") + let armeId = li.data("item-id") + this.actor.rollAssomerArme(armeId) + }) + html.find('.roll-pouvoir').click((event) => { const li = $(event.currentTarget).parents(".item") let pouvoirId = li.data("item-id") diff --git a/modules/heritiers-actor.js b/modules/heritiers-actor.js index cf0001e..dec0a5c 100644 --- a/modules/heritiers-actor.js +++ b/modules/heritiers-actor.js @@ -55,25 +55,7 @@ export class HeritiersActor extends Actor { /* -------------------------------------------- */ prepareArme(arme) { arme = duplicate(arme) - let combat = this.getCombatValues() - if (arme.system.typearme == "contact" || arme.system.typearme == "contactjet") { - let bonusDefense = 0 - arme.system.competence = duplicate(this.items.find(item => item.type == "competence" && item.name.toLowerCase() == "mêlée")) - arme.system.attrKey = "pui" - arme.system.totalDegats = arme.system.degats + "+" + combat.bonusDegatsTotal - arme.system.totalOffensif = this.system.attributs.pui.value + arme.system.competence.system.niveau + arme.system.bonusmaniementoff - arme.system.totalDefensif = combat.defenseTotal + arme.system.competence.system.niveau + arme.system.seuildefense + bonusDefense - arme.system.isdefense = true - } - if (arme.system.typearme == "jet" || arme.system.typearme == "tir") { - arme.system.competence = duplicate(this.items.find(item => item.type == "competence" && item.name.toLowerCase() == "armes à distance")) - arme.system.attrKey = "adr" - arme.system.totalOffensif = this.system.attributs.adr.value + arme.system.competence.system.niveau + arme.system.bonusmaniementoff - arme.system.totalDegats = arme.system.degats - if (arme.system.isdefense) { - arme.system.totalDefensif = combat.defenseTotal + arme.system.competence.system.niveau + arme.system.seuildefense - } - } + arme.system.isMelee = HeritiersUtility.isArmeMelee(arme) return arme } @@ -104,46 +86,46 @@ export class HeritiersActor extends Actor { } /* ----------------------- --------------------- */ - getItemSorted( types) { - let items = this.items.filter(item => types.includes(item.type )) || [] + getItemSorted(types) { + let items = this.items.filter(item => types.includes(item.type)) || [] HeritiersUtility.sortArrayObjectsByName(items) return items } getEquipments() { - return this.getItemSorted( ["equipement", "accessoire"] ) + return this.getItemSorted(["equipement", "accessoire"]) } getAvantages() { - return this.getItemSorted( ["avantage"]) + return this.getItemSorted(["avantage"]) } getDesavantages() { - return this.getItemSorted( ["desavantage"]) + return this.getItemSorted(["desavantage"]) } getMonnaies() { - return this.getItemSorted( ["monnaie"]) + return this.getItemSorted(["monnaie"]) } getArmors() { - return this.getItemSorted( ["protection"]) + return this.getItemSorted(["protection"]) } getTalents() { - return this.getItemSorted( ["talent"]) + return this.getItemSorted(["talent"]) } getContacts() { - return this.getItemSorted( ["contact"]) + return this.getItemSorted(["contact"]) } getAtouts() { - return this.getItemSorted( ["atoutfeerique"]) + return this.getItemSorted(["atoutfeerique"]) } getCapacites() { - return this.getItemSorted( ["capacitenaturelle"]) + return this.getItemSorted(["capacitenaturelle"]) } getFee() { - return this.items.find(item => item.type =="fee") + return this.items.find(item => item.type == "fee") } getProfils() { - return this.getItemSorted( ["profil"]) + return this.getItemSorted(["profil"]) } getPouvoirs() { - return this.getItemSorted( ["pouvoir"]) + return this.getItemSorted(["pouvoir"]) } /* -------------------------------------------- */ getSkills() { @@ -173,8 +155,8 @@ export class HeritiersActor extends Actor { organizeUtileSkills(kind = "mental") { let comp = {} for (let key in game.system.lesheritiers.config.competenceProfil) { - if ( game.system.lesheritiers.config.competenceProfil[key].kind == kind) - comp[key] = { skills: [], niveau: this.system.competences[key].niveau } + if (game.system.lesheritiers.config.competenceProfil[key].kind == kind) + comp[key] = { skills: [], niveau: this.system.competences[key].niveau } } for (let item of this.items) { if (item.type == "competence") { @@ -297,7 +279,7 @@ export class HeritiersActor extends Actor { let item = this.items.find(item => item.id == itemId) if (item) { console.log("Item ", item, itemField, dataType, value) - if (dataType) { + if (dataType) { if (dataType.toLowerCase() == "number") { value = Number(value) } else { @@ -313,14 +295,14 @@ export class HeritiersActor extends Actor { getPvMalus() { if (this.system.pv.value > 0) { if (this.system.pv.value < this.system.pv.max / 2) { - return -1 + return { name: "Santé", value: -1 } } if (this.system.pv.value < 5) { - return -2 + return { name: "Santé", value: -2 } } - return 0 + return { name: "Santé", value: 0 } } - return "Moribond(e)" + return { name: "Moribond(e)", value: -50 } } /* -------------------------------------------- */ @@ -482,19 +464,21 @@ export class HeritiersActor extends Actor { } /* -------------------------------------------- */ getCurrentParade() { - if ( this.system.statutmasque == "masque") { + if (this.system.statutmasque == "masque") { return this.system.combat.parade.masquee } return this.system.combat.parade.demasquee } /* -------------------------------------------- */ getCurrentEsquive() { - if ( this.system.statutmasque == "masque") { + if (this.system.statutmasque == "masque") { return this.system.combat.esquive.masquee } return this.system.combat.esquive.demasquee } - + getCurrentResistancePhysique() { + return this.system.combat.resistancephysique.value + } /* -------------------------------------------- */ getTricherie() { return this.system.rang.tricherie.value @@ -511,7 +495,19 @@ export class HeritiersActor extends Actor { tricherie.value = Math.min(tricherie.value, tricherie.max) this.update({ 'system.rang.tricherie': tricherie }) } - + /* -------------------------------------------- */ + getPireCompetence(compName1, compName2) { + let comp1 = this.items.find( it => it.name == compName1) + let comp2 = this.items.find( it => it.name == compName2) + if ( comp1 && comp2 ) { + if (comp1.system.niveau > comp2.system.niveau) { + return comp1 + } else { + return comp2 + } + } + return undefined + } /* -------------------------------------------- */ getCommonRollData(compId = undefined, compName = undefined) { let rollData = HeritiersUtility.getBasicRollData() @@ -527,7 +523,7 @@ export class HeritiersActor extends Actor { rollData.useTricherie = false rollData.useSpecialite = false rollData.useHeritage = false - rollData.pvMalus = this.getPvMalus() + rollData.rulesMalus.push(this.getPvMalus()) if (compId) { rollData.competence = duplicate(this.items.get(compId) || {}) @@ -538,7 +534,7 @@ export class HeritiersActor extends Actor { rollData.competence = duplicate(this.items.find(item => item.name.toLowerCase() == compName.toLowerCase()) || {}) if (rollData.competence && rollData.competence.name) { this.prepareUtileSkill(rollData.competence) - rollData.actionImg = rollData.competence?.img + rollData.actionImg = rollData.competence?.img } else { rollData.competence = undefined } @@ -585,7 +581,7 @@ export class HeritiersActor extends Actor { let rollData = this.getCommonRollData() rollData.mode = "competence" console.log("Compkey", compKey) - rollData.competence = {name: this.system.competences[compKey].label, system: { niveau: this.system.competences[compKey].niveau }} + rollData.competence = { name: this.system.competences[compKey].label, system: { niveau: this.system.competences[compKey].niveau } } console.log("RollDatra", rollData) let rollDialog = await HeritiersRollDialog.create(this, rollData) rollDialog.render(true) @@ -599,13 +595,15 @@ export class HeritiersActor extends Actor { let rollDialog = await HeritiersRollDialog.create(this, rollData) rollDialog.render(true) } + /* -------------------------------------------- */ async rollAttaqueArme(armeId) { let arme = this.items.get(armeId) if (arme) { let competenceName = "Tir" let key = "prec" - if (arme.system.categorie == "blanche" || arme.system.categorie == "improvise") { + arme.system.isMelee = HeritiersUtility.isArmeMelee(arme) + if ( arme.system.isMelee) { competenceName = "Mêlée" key = "agi" } @@ -614,16 +612,70 @@ export class HeritiersActor extends Actor { rollData.caracKey = key rollData.arme = duplicate(arme) rollData.mode = "arme" + if (rollData.defenderTokenId && arme.system.isMelee ) { + rollData.cacheDifficulte = true + } + let rollDialog = await HeritiersRollDialog.create(this, rollData) + rollDialog.render(true) + } + } + + /* -------------------------------------------- */ + async rollAttaqueBrutaleArme(armeId) { + let arme = this.items.get(armeId) + if (arme) { + let key = "for" + let competenceName = "Mêlée" + let rollData = this.getCommonRollData(undefined, competenceName) + rollData.carac = this.system.caracteristiques[key] + rollData.caracKey = key + rollData.arme = duplicate(arme) + rollData.mode = "attaquebrutale" + rollData.rulesMalus.push({ name: "Attaque brutale", value: -2 } ) let rollDialog = await HeritiersRollDialog.create(this, rollData) rollDialog.render(true) } } + /* -------------------------------------------- */ + async rollAttaqueChargeArme(armeId) { + let arme = this.items.get(armeId) + if (arme) { + let key = "agi" + let pireCompetence = this.getPireCompetence("Mêlée", "Mouvement") + let rollData = this.getCommonRollData(undefined, pireCompetence.name) + rollData.carac = this.system.caracteristiques[key] + rollData.caracKey = key + rollData.arme = duplicate(arme) + rollData.mode = "attaquecharge" + let rollDialog = await HeritiersRollDialog.create(this, rollData) + rollDialog.render(true) + } + } + + /* -------------------------------------------- */ + async rollAssomerArme(armeId) { + let arme = this.items.get(armeId) + if (arme) { + let competenceName = "Mêlée" + let rollData = this.getCommonRollData(undefined, competenceName) + rollData.carac = this.system.caracteristiques["agi"] + rollData.caracKey = "agi" + rollData.arme = duplicate(arme) + rollData.mode = "assommer" + if (rollData.defenderTokenId) { + rollData.cacheDifficulte = true + } + let rollDialog = await HeritiersRollDialog.create(this, rollData) + rollDialog.render(true) + } + } + /* -------------------------------------------- */ async rollPouvoir(pouvoirId) { let pouvoir = this.items.get(pouvoirId) if (pouvoir) { let rollData = this.getCommonRollData(undefined, undefined) - if ( pouvoir.system.feeriemasque != "autre") { + if (pouvoir.system.feeriemasque != "autre") { rollData.pouvoirBase = duplicate(this.system.rang[pouvoir.system.feeriemasque.toLowerCase()]) rollData.pouvoirBase.label = "Féerie" rollData.carac = duplicate(this.system.caracteristiques[pouvoir.system.carac]) diff --git a/modules/heritiers-item-sheet.js b/modules/heritiers-item-sheet.js index acb556a..4afe221 100644 --- a/modules/heritiers-item-sheet.js +++ b/modules/heritiers-item-sheet.js @@ -62,6 +62,7 @@ export class HeritiersItemSheet extends ItemSheet { options: this.options, owner: this.document.isOwner, config: game.system.lesheritiers.config, + isArmeMelee: HeritiersUtility.isArmeMelee(this.object), description: await TextEditor.enrichHTML(this.object.system.description, {async: true}), mr: (this.object.type == 'specialisation'), isGM: game.user.isGM diff --git a/modules/heritiers-roll-dialog.js b/modules/heritiers-roll-dialog.js index d4555dc..e8f5ebf 100644 --- a/modules/heritiers-roll-dialog.js +++ b/modules/heritiers-roll-dialog.js @@ -110,14 +110,8 @@ export class HeritiersRollDialog extends Dialog { html.find('#bonus-malus-context').change((event) => { this.rollData.bonusMalusContext = Number(event.currentTarget.value) }) - html.find('#useTricherie').change((event) => { - this.rollData.useTricherie = event.currentTarget.checked - }) html.find('#useSpecialite').change((event) => { this.rollData.useSpecialite = event.currentTarget.checked }) - 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 a34f2da..8b9f3f1 100644 --- a/modules/heritiers-utility.js +++ b/modules/heritiers-utility.js @@ -290,11 +290,11 @@ export class HeritiersUtility { if (isTricherieHeritage) { let resTab = [rollData.roll.terms[0].results[0].result, rollData.roll.terms[0].results[1].result, rollData.roll.terms[0].results[2].result] rollData.diceResult = resTab[0] + "," + resTab[1] + "," + resTab[2] - let subResult = Math.max(Math.max(resTab[0], resTab[1]), resTab[2]) + let foundryTotal = resTab[0] + resTab[1] + resTab[2] if (resTab[1] == 1) { resTab[1] -= 4 } if (resTab[2] == 1) { resTab[2] -= 6 } if (resTab[2] == 2) { resTab[2] -= 7 } - rollData.finalResult = rollData.roll.total - subResult + Math.max(Math.max(resTab[0], resTab[1]), resTab[2]) + rollData.finalResult = rollData.roll.total - foundryTotal + Math.max(Math.max(resTab[0], resTab[1]), resTab[2]) // Gestion des résultats spéciaux resTab = resTab.sort() @@ -344,6 +344,9 @@ export class HeritiersUtility { if (rollData.arme.system.categorie == "blanche" || rollData.arme.system.categorie == "improvise") { rollData.degatsArme += Math.max(0, actor.system.caracteristiques.for.value - 2) } + if (rollData.mode == "attaquecharge") { + rollData.degatsArme += 3 + } } /* -------------------------------------------- */ @@ -368,19 +371,24 @@ export class HeritiersUtility { this.createChatWithRollMode(rollData.alias, { content: await renderTemplate(`systems/fvtt-les-heritiers/templates/chat-cc-result.html`, rollData) }, rollData, "selfroll") - } - + /* -------------------------------------------- */ + static async displayAsssomer(rollData, actor, nomAttaque, etatAssomer, valeurDefense) { + rollData.defenderMode = nomAttaque + rollData.etatAssommer = etatAssomer + rollData.defenderValue = valeurDefense + rollData.marge = 0 + this.computeMarge(rollData, valeurDefense) + rollData.dureeAssommer = (rollData.marge) ? rollData.marge*2 : 1 + this.createChatWithRollMode(rollData.alias, { + content: await renderTemplate(`systems/fvtt-les-heritiers/templates/chat-assommer-result.html`, rollData) + }, rollData, "selfroll") + } /* -------------------------------------------- */ static async rollHeritiers(rollData) { let actor = this.getActorFromRollData(rollData) - if (typeof (rollData.pvMalus) != "number") { - ui.notifications.warn("Votre personnage est Moribond(e). Aucun jet autorisé") - return - } - //rollData.actionImg = "systems/fvtt-les-heritiers/assets/icons/" + actor.system.attributs[rollData.attrKey].labelnorm + ".webp" rollData.carac = duplicate(actor.system.caracteristiques[rollData.caracKey]) @@ -403,7 +411,11 @@ export class HeritiersUtility { } else { rollData.diceFormula += `+${rollData.carac.value}+${rangValue}+${rollData.bonusMalusContext}` } - rollData.diceFormula += `+${rollData.pvMalus}` + let ruleMalus = 0 + for (let malus of rollData.rulesMalus) { + ruleMalus += malus.value + } + rollData.diceFormula += `+${ruleMalus}` let myRoll = new Roll(rollData.diceFormula).roll({ async: false }) await this.showDiceSoNice(myRoll, game.settings.get("core", "rollMode")) @@ -420,7 +432,9 @@ export class HeritiersUtility { content: await renderTemplate(`systems/fvtt-les-heritiers/templates/chat-generic-result.html`, rollData) }, rollData) - if (rollData.defenderTokenId && rollData.arme) { + // Gestion attaque standard + if ( (rollData.mode == "arme" || rollData.mode == "attaquebrutale" || rollData.mode == "attaquecharge") && + rollData.defenderTokenId && rollData.arme) { if (rollData.arme.system.categorie != "trait" && rollData.arme.system.categorie != "poing" && rollData.arme.system.categorie != "epaule" ) { await this.displayUneDefense(rollData, actor, "Parade", rollData.defenderParade) await this.displayUneDefense(rollData, actor, "Esquive", rollData.defenderEsquive) @@ -430,6 +444,13 @@ export class HeritiersUtility { ui.notifications.warn("Pas de difficulté positionnée pour l'attaque à distance.") } } + // Gestion assomer + if (rollData.mode == "assommer" && rollData.defenderTokenId && rollData.arme) { + await this.displayAsssomer(rollData, actor, "Assommer", "Surprise", rollData.defenderResistancePhysique) + await this.displayAsssomer(rollData, actor, "Assommer", "Conscient, Résistance+6", rollData.defenderResistancePhysique+6) + await this.displayAsssomer(rollData, actor, "Assommer", "Conscient, Parade", rollData.defenderParade) + await this.displayAsssomer(rollData, actor, "Assommer", "Conscient, Esquive", rollData.defenderEsquive+6) + } } @@ -456,6 +477,10 @@ export class HeritiersUtility { return game.users.filter(filter).map(user => user._id); } + /* -------------------------------------------- */ + static isArmeMelee(arme) { + return (arme.type == "arme" && (arme.system.categorie == "lourde" || arme.system.categorie == "blanche" || arme.system.categorie == "improvise")) ? true : false + } /* -------------------------------------------- */ static getWhisperRecipients(rollMode, name) { switch (rollMode) { @@ -541,7 +566,8 @@ export class HeritiersUtility { rollMode: game.settings.get("core", "rollMode"), sdList: game.system.lesheritiers.config.seuilsDifficulte, sdValue: -1, - bonusMalusContext: 0 + bonusMalusContext: 0, + rulesMalus : [] } return rollData } @@ -555,6 +581,7 @@ export class HeritiersUtility { rollData.defenderName = defender.name rollData.defenderParade = defender.getCurrentParade() rollData.defenderEsquive = defender.getCurrentEsquive() + rollData.defenderResistancePhysique = defender.getCurrentResistancePhysique() } } diff --git a/styles/simple.css b/styles/simple.css index 70504ae..f0bd2f7 100644 --- a/styles/simple.css +++ b/styles/simple.css @@ -1245,7 +1245,10 @@ ul, li { position:relative; top:1px; } - +.button-sheet-roll-long1 { + max-width: 6.1rem; + min-width: 6.1rem; +} .defense-sheet { border-radius: 4px; text-align: center; diff --git a/system.json b/system.json index d1bfe82..ace267a 100644 --- a/system.json +++ b/system.json @@ -1,7 +1,7 @@ { "id": "fvtt-les-heritiers", "description": "Les Héritiers pour FoundryVTT", - "version": "10.0.35", + "version": "10.0.36", "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.35.zip", + "download": "https://www.uberwald.me/gitea/public/fvtt-les-heritiers/archive/fvtt-les-heritiers-10.0.36.zip", "languages": [ { "lang": "fr", diff --git a/templates/actor-sheet.html b/templates/actor-sheet.html index 18839cd..0009cea 100644 --- a/templates/actor-sheet.html +++ b/templates/actor-sheet.html @@ -176,20 +176,6 @@ -
@@ -201,10 +187,10 @@

- + - +