diff --git a/module/actor.js b/module/actor.js index 6ded414d..648b725e 100644 --- a/module/actor.js +++ b/module/actor.js @@ -33,7 +33,8 @@ import { RollDataAjustements } from "./rolldata-ajustements.js"; import { DialogItemAchat } from "./dialog-item-achat.js"; import { RdDItem } from "./item.js"; import { RdDPossession } from "./rdd-possession.js"; -import { SYSTEM_RDD, SYSTEM_SOCKET_ID } from "./constants.js"; +import { ENTITE_BLURETTE, ENTITE_INCARNE, ENTITE_NONINCARNE, SYSTEM_RDD, SYSTEM_SOCKET_ID } from "./constants.js"; + /* -------------------------------------------- */ /** @@ -98,7 +99,6 @@ export class RdDActor extends Actor { * @param {Object} options (Unused) Additional options which customize the creation workflow. * */ - static async create(actorData, options) { // Case of compendium global import if (actorData instanceof Array) { @@ -134,13 +134,6 @@ export class RdDActor extends Actor { this.encTotal = 0; this.prixTotalEquipement = 0; - /* - // Auto-resize token - if (this.isToken) { - let tokenSize = actorData.data.carac.taille.value/10; - this.token.update({height: tokenSize, width: tokenSize } ); - }*/ - // Make separate methods for each Actor type (character, npc, etc.) to keep // things organized. if (this.type === 'personnage') this._prepareCharacterData(this) @@ -245,7 +238,7 @@ export class RdDActor extends Actor { } /* -------------------------------------------- */ getForce() { - if (this.isEntiteCauchemar()) { + if (this.isEntite()) { return Misc.toInt(this.system.carac.reve?.value); } return Misc.toInt(this.system.carac.force?.value); @@ -323,7 +316,7 @@ export class RdDActor extends Actor { return this.filterItemsData(it => it.type == type); } filterItemsData(filter) { - return this.items.map( it => it).filter(filter) + return this.items.map(it => it).filter(filter) } filterItems(filter) { return this.items.filter(it => filter(it)) @@ -375,11 +368,11 @@ export class RdDActor extends Actor { getDraconicOuPossession() { const possessions = this.items.filter(it => it.type == 'competencecreature' && it.system.ispossession) .sort(Misc.descending(it => it.system.niveau)); - if (possessions.length>0) { + if (possessions.length > 0) { return duplicate(possessions[0]); } const draconics = this.getDraconicList().filter(it => it.system.niveau >= 0); - if (draconics.length> 0) { + if (draconics.length > 0) { return duplicate(draconics[0]); } return { @@ -616,7 +609,11 @@ export class RdDActor extends Actor { whisper: ChatUtility.getWhisperRecipientsAndGMs(this.name), content: "Remise à neuf de " + this.name }; - if (this.isEntiteCauchemar()) { + const actorData = Misc.data(this); + if (this.isEntite([ENTITE_NONINCARNE])) { + return; + } + if (this.isEntite([ENTITE_INCARNE, ENTITE_BLURETTE])) { await this.santeIncDec("endurance", this.system.sante.endurance.max - this.system.sante.endurance.value); } else { @@ -831,7 +828,7 @@ export class RdDActor extends Actor { async resultCombatReveDeDragon(rollData) { rollData.queues = []; if (rollData.rolled.isEchec) { - rollData.queues.push( await this.ajouterQueue()); + rollData.queues.push(await this.ajouterQueue()); } if (rollData.rolled.isETotal) { rollData.queues.push(await this.ajouterQueue()); @@ -981,7 +978,7 @@ export class RdDActor extends Actor { let nouveauNiveau = compValue ?? RdDItemCompetence.getNiveauBase(competence.system.categorie); const tronc = RdDItemCompetence.getListTronc(competence.name).filter(it => { const comp = this.getCompetence(it); - const niveauTr = competence? competence.system.niveau : 0; + const niveauTr = competence ? competence.system.niveau : 0; return niveauTr < 0 && niveauTr < nouveauNiveau; }); if (tronc.length > 0) { @@ -1310,17 +1307,17 @@ export class RdDActor extends Actor { } return Math.min(0, this.getEncombrementMax() - Math.ceil(Number(this.getEncTotal()))); } - getMessageSurEncombrement(){ - return this.computeMalusSurEncombrement() <0 ? "Sur-Encombrement!" : ""; + getMessageSurEncombrement() { + return this.computeMalusSurEncombrement() < 0 ? "Sur-Encombrement!" : ""; } /* -------------------------------------------- */ getEncombrementMax() { - switch (this.type){ - case 'vehicule': + switch (this.type) { + case 'vehicule': return this.system.capacite_encombrement; case 'entite': - return 0; + return 0; default: return this.system.attributs.encombrement.value } @@ -1342,7 +1339,7 @@ export class RdDActor extends Actor { /* -------------------------------------------- */ async computeEncombrementTotalEtMalusArmure() { - if ( !this.pack ) { + if (!this.pack) { await this.computeMalusArmure(); return this.computeEncombrement(); } @@ -1620,7 +1617,7 @@ export class RdDActor extends Actor { /* -------------------------------------------- */ async setSonne(sonne = true) { - if (this.isEntiteCauchemar()) { + if (this.isEntite()) { return; } if (!game.combat && sonne) { @@ -1632,7 +1629,7 @@ export class RdDActor extends Actor { /* -------------------------------------------- */ getSConst() { - if (this.isEntiteCauchemar()) { + if (this.isEntite()) { return 0; } return RdDCarac.calculSConst(this.system.carac.constitution.value) @@ -1747,7 +1744,7 @@ export class RdDActor extends Actor { result.newValue = Math.max(minValue, Math.min(compteur.value + inc, compteur.max)); //console.log("New value ", inc, minValue, result.newValue); let fatigue = 0; - if (name == "endurance" && !this.isEntiteCauchemar()) { + if (name == "endurance" && !this.isEntite()) { if (result.newValue == 0 && inc < 0 && !isCritique) { // perte endurance et endurance devient 0 (sauf critique) -> -1 vie sante.vie.value--; result.perteVie = true; @@ -1784,7 +1781,7 @@ export class RdDActor extends Actor { } isDead() { - return !this.isEntiteCauchemar() && this.system.sante.vie.value < -this.getSConst() + return !this.isEntite() && this.system.sante.vie.value < -this.getSConst() } /* -------------------------------------------- */ @@ -1913,7 +1910,7 @@ export class RdDActor extends Actor { } /* -------------------------------------------- */ - async actionItem(item, onActionItem = async ()=>{}) { + async actionItem(item, onActionItem = async () => { }) { if (!item.getActionPrincipale()) return; switch (item.type) { case 'nourritureboisson': return await this.actionNourritureboisson(item, onActionItem); @@ -1921,7 +1918,7 @@ export class RdDActor extends Actor { case 'livre': return await this.actionLire(item); case 'conteneur': return await item.sheet.render(true); case 'herbe': { - if (item.isHerbeAPotion()){ + if (item.isHerbeAPotion()) { return this.dialogFabriquerPotion(item); } return; @@ -2668,7 +2665,7 @@ export class RdDActor extends Actor { selectedCarac: duplicate(this.system.carac[selected]) }, { overwrite: false }); - artData.competence.system.defaut_carac = selected; + artData.competence.system.defaut_carac = selected; if (!artData.forceCarac) { artData.forceCarac = {}; artData.forceCarac[selected] = duplicate(this.system.carac[selected]); @@ -3289,10 +3286,10 @@ export class RdDActor extends Actor { if (res) { let malus = Misc.toInt(res[3]) - 1; let armure = Misc.toInt(res[2]); - if (armure+malus <= 0){ + if (armure + malus <= 0) { itemData.system.protection = 0; } else { - itemData.system.protection = '' + (res[1]??'1') + 'd' + armure + malus; + itemData.system.protection = '' + (res[1] ?? '1') + 'd' + armure + malus; } } else if (/\d+/.exec(itemData.system.protection)) { @@ -3325,7 +3322,7 @@ export class RdDActor extends Actor { let encaissement = await this.jetEncaissement(rollData); this.ajouterBlessure(encaissement); // Will upate the result table - const perteVie = this.isEntiteCauchemar() + const perteVie = this.isEntite() ? { newValue: 0 } : await this.santeIncDec("vie", - encaissement.vie); const perteEndurance = await this.santeIncDec("endurance", -encaissement.endurance, encaissement.critiques > 0); @@ -3339,7 +3336,7 @@ export class RdDActor extends Actor { sonne: perteEndurance.sonne, jetEndurance: perteEndurance.jetEndurance, endurance: santeOrig.endurance.value - perteEndurance.newValue, - vie: this.isEntiteCauchemar() ? 0 : (santeOrig.vie.value - perteVie.newValue), + vie: this.isEntite() ? 0 : (santeOrig.vie.value - perteVie.newValue), show: defenderRoll?.show ?? {} }); @@ -3528,8 +3525,8 @@ export class RdDActor extends Actor { /* -------------------------------------------- */ async accorder(entite, when = 'avant-encaissement') { if (when != game.settings.get(SYSTEM_RDD, "accorder-entite-cauchemar") - || !entite.isEntiteCauchemar() - || entite.isEntiteCauchemarAccordee(this)) { + || !entite.isEntite([ENTITE_INCARNE]) + || entite.isEntiteAccordee(this)) { return true; } const tplData = this.system; @@ -3553,29 +3550,29 @@ export class RdDActor extends Actor { } /* -------------------------------------------- */ - isEntiteCauchemar() { - return this.type == 'entite'; + isEntite(typeentite = []) { + return this.type == 'entite' && (typeentite.length == 0 || typeentite.includes(this.system.typeentite)); } /* -------------------------------------------- */ - isEntiteCauchemarAccordee(attaquant) { - if (!this.isEntiteCauchemar()) { return true; } + isEntiteAccordee(attaquant) { + if (!this.isEntite([ENTITE_INCARNE])) { return true; } let resonnance = this.system.sante.resonnance; - return (resonnance.actors.find(it => it == attaquant._id)); + return (resonnance.actors.find(it => it == attaquant.id)); } /* -------------------------------------------- */ async setEntiteReveAccordee(attaquant) { - if (!this.isEntiteCauchemar()) { + if (!this.isEntite([ENTITE_INCARNE])) { ui.notifications.error("Impossible de s'accorder à " + this.name + ": ce n'est pas une entite de cauchemer/rêve"); return; } let resonnance = duplicate(this.system.sante.resonnance); - if (resonnance.actors.find(it => it == attaquant._id)) { + if (resonnance.actors.find(it => it == attaquant.id)) { // déjà accordé return; } - resonnance.actors.push(attaquant._id); + resonnance.actors.push(attaquant.id); await this.update({ "system.sante.resonnance": resonnance }); return; } @@ -3602,7 +3599,7 @@ export class RdDActor extends Actor { 10: Math.floor(fortuneTotale / 10) % 10, // bronze 1: fortuneTotale % 10 // étain } - console.log('RdDActor.optimizeArgent', fortuneTotale, 'nouvelleFortune', nouvelleFortune, 'monnaie_par_valeur',parValeur); + console.log('RdDActor.optimizeArgent', fortuneTotale, 'nouvelleFortune', nouvelleFortune, 'monnaie_par_valeur', parValeur); let updates = []; for (const [valeur, nombre] of Object.entries(nouvelleFortune)) { updates.push({ _id: parValeur[valeur].id, 'system.quantite': nombre }); @@ -3671,7 +3668,8 @@ export class RdDActor extends Actor { RdDActor.remoteActorCall({ userId: Misc.connectedGMOrUser(), actorId: this.id, - method: 'ajouterDeniers', args: [gain, fromActorId] }); + method: 'ajouterDeniers', args: [gain, fromActorId] + }); } else { const fromActor = game.actors.get(fromActorId) @@ -3706,8 +3704,9 @@ export class RdDActor extends Actor { RdDActor.remoteActorCall({ actorId: achat.vendeurId ?? achat.acheteurId, method: 'achatVente', - args: [achat] }, - ); + args: [achat] + }, + ); return; } @@ -4078,7 +4077,7 @@ export class RdDActor extends Actor { } /* -------------------------------------------- */ - async consommerPotion(potion, onActionItem = async () => {}) { + async consommerPotion(potion, onActionItem = async () => { }) { const potionData = potion if (potionData.system.categorie.includes('Soin')) { @@ -4114,7 +4113,7 @@ export class RdDActor extends Actor { } /* -------------------------------------------- */ - getEffectByLabel(label) { + getEffectByLabel(label) { return this.getActiveEffects().find(it => it.system?.label == label); } @@ -4125,7 +4124,7 @@ export class RdDActor extends Actor { /* -------------------------------------------- */ async setStatusEffect(label, status, updates = {}) { - if (this.isEntiteCauchemar() || this.type == 'vehicule') { + if (this.isEntite() || this.type == 'vehicule') { return; } console.log("setStatusEffect", label, status, updates) diff --git a/module/constants.js b/module/constants.js index 865a0559..675749ed 100644 --- a/module/constants.js +++ b/module/constants.js @@ -3,3 +3,7 @@ export const SYSTEM_SOCKET_ID = 'system.foundryvtt-reve-de-dragon'; export const HIDE_DICE = 'hide'; export const SHOW_DICE = 'show'; + +export const ENTITE_INCARNE = 'incarne'; +export const ENTITE_NONINCARNE = 'nonincarne'; +export const ENTITE_BLURETTE = 'blurette'; diff --git a/module/dialog-item-achat.js b/module/dialog-item-achat.js index 9541bd49..8b6ba515 100644 --- a/module/dialog-item-achat.js +++ b/module/dialog-item-achat.js @@ -55,7 +55,7 @@ export class DialogItemAchat extends Dialog { static prepareVenteData(buttonAcheter, vendeurId, vendeur, acheteur) { const jsondata = buttonAcheter.attributes['data-jsondata']?.value; - const prixLot = buttonAcheter.attributes['data-prixLot']?.value ?? 0; + const prixLot = parseInt(buttonAcheter.attributes['data-prixLot']?.value ?? 0); let venteData = { item: JSON.parse(jsondata), vendeurId: vendeurId, diff --git a/module/rdd-combat.js b/module/rdd-combat.js index 681a5f1c..f62a9a8e 100644 --- a/module/rdd-combat.js +++ b/module/rdd-combat.js @@ -1,5 +1,5 @@ import { ChatUtility } from "./chat-utility.js"; -import { HIDE_DICE, SYSTEM_RDD, SYSTEM_SOCKET_ID } from "./constants.js"; +import { ENTITE_INCARNE, ENTITE_NONINCARNE, HIDE_DICE, SYSTEM_RDD, SYSTEM_SOCKET_ID } from "./constants.js"; import { Grammar } from "./grammar.js"; import { RdDItemArme } from "./item-arme.js"; import { RdDItemCompetence } from "./item-competence.js"; @@ -320,7 +320,7 @@ export class RdDCombatManager extends Combat { initOffset = 10; caracForInit = combatant.actor.getReveActuel(); initInfo = "Possession" - } else if (action.name == 'autre') { + } else if (action.action == 'autre') { initOffset = 2; initInfo = "Autre Action" } else if (action.action == 'haut-reve') { @@ -455,9 +455,9 @@ export class RdDCombat { : "Vous devez choisir une cible à attaquer!"); } else { - const defender = target?.actor - const defenderTokenId = target?.id - if ( defender.type == 'entite' && defender.system.definition.typeentite == 'nonincarne') { + const defender = target?.actor; + const defenderTokenId = target?.id; + if ( defender.type == 'entite' && defender.system.definition.typeentite == ENTITE_NONINCARNE) { ui.notifications.warn("Vous ne pouvez pas cibler une entité non incarnée !!!!"); } else { return this.create(attacker, defender, defenderTokenId, target) @@ -799,7 +799,7 @@ export class RdDCombat { async _onAttaqueNormale(attackerRoll) { console.log("RdDCombat.onAttaqueNormale >>>", attackerRoll); - attackerRoll.dmg = RdDBonus.dmg(attackerRoll, this.attacker.getBonusDegat(), this.defender.isEntiteCauchemar()); + attackerRoll.dmg = RdDBonus.dmg(attackerRoll, this.attacker.getBonusDegat(), this.defender.isEntite()); let defenderRoll = { attackerRoll: attackerRoll, passeArme: attackerRoll.passeArme, show: {} } attackerRoll.show = { cible: this.target ? this.defender.system.name : 'la cible', @@ -1248,8 +1248,8 @@ export class RdDCombat { async accorderEntite(when = 'avant-encaissement') { if (when != game.settings.get(SYSTEM_RDD, "accorder-entite-cauchemar") || this.defender == undefined - || !this.defender.isEntiteCauchemar() - || this.defender.isEntiteCauchemarAccordee(this.attacker)) { + || !this.defender.isEntite([ENTITE_INCARNE]) + || this.defender.isEntiteAccordee(this.attacker)) { return true; } diff --git a/module/rdd-namegen.js b/module/rdd-namegen.js index 52713906..f054f435 100644 --- a/module/rdd-namegen.js +++ b/module/rdd-namegen.js @@ -1,19 +1,29 @@ +import { RdDActor } from "./actor.js"; import { Misc } from "./misc.js"; import { RdDDice } from "./rdd-dice.js"; -const words = [ 'pore', 'pre', 'flor', 'lane', 'turlu', 'pin', 'a', 'alph', 'i', 'onse', 'iane', 'ane', 'zach', 'arri', 'ba', 'bo', 'bi', - 'alta', 'par', 'pir', 'zor', 'zir', 'de', 'pol', 'tran', 'no', 'la', 'al' , 'pul', 'one', 'ner', 'nur', 'mac', 'mery', - 'cat', 'do', 'di', 'der', 'er', 'el', 'far', 'fer', 'go', 'guer', 'hot', 'jor', 'jar', 'ji', 'kri', 'ket', 'lor', 'hur', - 'lar', 'lir', 'lu', 'pot', 'pro', 'pra', 'pit', 'qua', 'qui', 're', 'ral', 'sal', 'sen', 'ted', 'to', 'ta', 'lars', 'ver', - 'vin', 'ov', 'wal', 'ry', 'ly', '' ]; +const words = ['pore', 'pre', 'flor', 'lane', 'turlu', 'pin', 'a', 'alph', 'i', 'onse', 'iane', 'ane', 'zach', 'arri', 'ba', 'bo', 'bi', + 'alta', 'par', 'pir', 'zor', 'zir', 'de', 'pol', 'tran', 'no', 'la', 'al', 'pul', 'one', 'ner', 'nur', 'mac', 'mery', + 'cat', 'do', 'di', 'der', 'er', 'el', 'far', 'fer', 'go', 'guer', 'hot', 'jor', 'jar', 'ji', 'kri', 'ket', 'lor', 'hur', + 'lar', 'lir', 'lu', 'pot', 'pro', 'pra', 'pit', 'qua', 'qui', 're', 'ral', 'sal', 'sen', 'ted', 'to', 'ta', 'lars', 'ver', + 'vin', 'ov', 'wal', 'ry', 'ly', '']; /* -------------------------------------------- */ export class RdDNameGen { - static async getName( msg, params ) { - let name = Misc.upperFirst( await RdDDice.rollOneOf(words) + await RdDDice.rollOneOf(words) ) - //console.log(name); - ChatMessage.create( { content: `Nom : ${name}`, whisper: ChatMessage.getWhisperRecipients("GM") } ); + static async getName(msg, params) { + const html = await renderTemplate(`systems/foundryvtt-reve-de-dragon/templates/chat-command-nom.html`, { + nom: Misc.upperFirst(await RdDDice.rollOneOf(words) + await RdDDice.rollOneOf(words)) + }); + ChatMessage.create({ content: html, whisper: ChatMessage.getWhisperRecipients("GM") }); } + static async onCreerActeur(event) { + const button = event.currentTarget; + await RdDActor.create({ + name: button.attributes['data-nom'].value, + type: button.attributes['data-type'].value + }, + {renderSheet: true}); + } } \ No newline at end of file diff --git a/module/rdd-roll-encaisser.js b/module/rdd-roll-encaisser.js index 55f2b8f5..8c8d8971 100644 --- a/module/rdd-roll-encaisser.js +++ b/module/rdd-roll-encaisser.js @@ -1,3 +1,5 @@ +import { ENTITE_BLURETTE, ENTITE_INCARNE, ENTITE_NONINCARNE } from "./constants"; + /** * Extend the base Dialog entity by defining a custom window to perform roll. * @extends {Dialog} @@ -7,15 +9,19 @@ export class RdDEncaisser extends Dialog { /* -------------------------------------------- */ constructor(html, actor) { // Common conf - const buttonsCreatures = { - "mortel": { label: "Mortel", callback: html => this.performEncaisser("mortel") }, - "non-mortel": { label: "Non-mortel", callback: html => this.performEncaisser("non-mortel") }, - "sonne": { label: "Sonné", callback: html => this.actor.setSonne() }, - }; - const buttonsEntitesCauchemar = { - "cauchemar": { label: "cauchemar", callback: html => this.performEncaisser("cauchemar") } - }; - const buttons = actor.isEntiteCauchemar() ? buttonsEntitesCauchemar : buttonsCreatures; + let buttons = {}; + if (!actor.isEntite()){ + buttons = { + "mortel": { label: "Mortel", callback: html => this.performEncaisser("mortel") }, + "non-mortel": { label: "Non-mortel", callback: html => this.performEncaisser("non-mortel") }, + "sonne": { label: "Sonné", callback: html => this.actor.setSonne() }, + }; + } + else if (actor.isEntite([ENTITE_BLURETTE, ENTITE_INCARNE])){ + buttons = { + "cauchemar": { label: "cauchemar", callback: html => this.performEncaisser("cauchemar") } + } + } let dialogConf = { title: "Jet d'Encaissement", diff --git a/module/rdd-utility.js b/module/rdd-utility.js index 5c5d6583..b2301a4b 100644 --- a/module/rdd-utility.js +++ b/module/rdd-utility.js @@ -11,6 +11,7 @@ import { RdDDice } from "./rdd-dice.js"; import { RdDItem } from "./item.js"; import { Monnaie } from "./item-monnaie.js"; import { RdDPossession } from "./rdd-possession.js"; +import { RdDNameGen } from "./rdd-namegen.js"; /* -------------------------------------------- */ // This table starts at 0 -> niveau -10 @@ -703,6 +704,7 @@ export class RdDUtility { // gestion bouton tchat Acheter html.on("click", '.button-acheter', event => DialogItemAchat.onButtonAcheter(event)); + html.on("click", '.button-creer-acteur', event => RdDNameGen.onCreerActeur(event)); // Gestion du bouton payer html.on("click", '.payer-button', event => { diff --git a/system.json b/system.json index 2c3d2050..478e3eb1 100644 --- a/system.json +++ b/system.json @@ -32,7 +32,7 @@ "url": "https://www.uberwald.me/gitea/public/foundryvtt-reve-de-dragon/", "license": "LICENSE.txt", "flags": {}, - "version": "10.0.5", + "version": "10.0.6", "scripts": [], "esmodules": [ "module/rdd-main.js" @@ -500,7 +500,7 @@ "relationships": {}, "socket": true, "manifest": "https://www.uberwald.me/gitea/public/foundryvtt-reve-de-dragon/raw/v10/system.json", - "download": "https://www.uberwald.me/gitea/public/foundryvtt-reve-de-dragon/archive/foundryvtt-reve-de-dragon-10.0.5.zip", + "download": "https://www.uberwald.me/gitea/public/foundryvtt-reve-de-dragon/archive/foundryvtt-reve-de-dragon-10.0.6.zip", "protected": false, "gridDistance": 1, "gridUnits": "m", diff --git a/templates/actor-entite-sheet.html b/templates/actor-entite-sheet.html index 16598403..e250d17c 100644 --- a/templates/actor-entite-sheet.html +++ b/templates/actor-entite-sheet.html @@ -65,6 +65,7 @@ {{#select data.definition.typeentite}} + {{/select}} diff --git a/templates/chat-command-nom.html b/templates/chat-command-nom.html new file mode 100644 index 00000000..8467fe6e --- /dev/null +++ b/templates/chat-command-nom.html @@ -0,0 +1,16 @@ + +

Proposition de nom: {{nom}}

+ + + Créer un Personnage + + + + Créer une créature + +