Recettes Alchimiques
+-
+ {{#each data.recettesAlchimiques as |recette id|}}
+
- {{recette.name}} + + + {{/each}} +
+
diff --git a/module/actor.js b/module/actor.js index 20386f1c..4f39d196 100644 --- a/module/actor.js +++ b/module/actor.js @@ -17,6 +17,7 @@ import { DeDraconique } from "./de-draconique.js"; import { RdDAudio } from "./rdd-audio.js"; import { RdDItemCompetence } from "./item-competence.js"; import { RdDItemArme } from "./item-arme.js"; +import { RdDAlchimie } from "./rdd-alchimie.js"; /* -------------------------------------------- */ /** @@ -2369,6 +2370,46 @@ export class RdDActor extends Actor { } } + /* -------------------------------------------- */ + async effectuerTacheAlchimie( recetteId, alchimieName, alchimieData) { + let recette = this.data.items.find( item => item.type =='recettealchimique' && item._id == recetteId ); + if ( recette) { + let competence = this.data.items.find( item => item.type =='competence' && item.name.toLowerCase() == "alchimie" ); + let diffAlchimie = RdDAlchimie.getDifficulte(alchimieData); + let rollData = { + recetteName: recette.name, + competence: competence, + diffLibre: diffAlchimie // Per default at startup + } + if ( alchimieName == "couleur") { + rollData.selectedCarac = this.data.data.carac.vue, + rollData.alchimieTexte = `Couleurs ${alchimieData} (${diffAlchimie}) (Malus de -4 si vous ne possédez pas de Cristal Alchimique)`; + } else { + rollData.selectedCarac = this.data.data.carac.dexterite, + rollData.alchimieTexte = `Consistances ${alchimieData} (${diffAlchimie})`; + } + + const dialog = await RdDRoll.create(this, rollData, + { html: 'systems/foundryvtt-reve-de-dragon/templates/dialog-roll-alchimie.html', + }, + { + name: 'tache-alchimique', + label: 'Tache Alchimique', + callbacks: [ + this.createCallbackExperience(), + { action: r => this._alchimieResult(r, false) } + ] + } + ); + dialog.render(true); + } + } + + + /* -------------------------------------------- */ + _alchimieResult( rollData ) { + RdDResolutionTable.displayRollData(rollData, this, 'chat-resultat-alchimie.html'); + } } diff --git a/module/item-sheet.js b/module/item-sheet.js index de108e25..124c00a6 100644 --- a/module/item-sheet.js +++ b/module/item-sheet.js @@ -1,6 +1,7 @@ import { RdDItemSort } from "./item-sort.js"; import { RdDUtility } from "./rdd-utility.js"; import { RdDItem } from "./item-rdd.js"; +import { RdDAlchimie } from "./rdd-alchimie.js"; /** * Extend the basic ItemSheet with some very simple modifications @@ -51,6 +52,9 @@ export class RdDItemSheet extends ItemSheet { data.caracList = duplicate(game.system.model.Actor.personnage.carac); data.competenceList = await RdDUtility.getCompetenceList( 'foundryvtt-reve-de-dragon.competences' ); } + if ( data.item.type == 'recettealchimique' ) { + RdDAlchimie.processManipulation(data.item, this.actor && this.actor._id ); + } if ( this.actor ) { data.isOwned = true; data.actorId = this.actor._id; @@ -77,6 +81,20 @@ export class RdDItemSheet extends ItemSheet { let actor = game.actors.get( actorId ); actor.creerTacheDepuisLivre( this.item ); }); + + html.find('.alchimie-tache a').click((event) => { + let actorId = event.currentTarget.attributes['data-actor-id'].value; + let recetteId = event.currentTarget.attributes['data-recette-id'].value; + let tacheName = event.currentTarget.attributes['data-alchimie-tache'].value; + let tacheData = event.currentTarget.attributes['data-alchimie-data'].value; + let actor = game.actors.get( actorId ); + if ( actor ) { + actor.effectuerTacheAlchimie(recetteId, tacheName, tacheData); + } else { + ui.notifications.info("Impossible trouver un actur pour réaliser cette tache Alchimique."); + } + }); + } /* -------------------------------------------- */ diff --git a/module/rdd-alchimie.js b/module/rdd-alchimie.js new file mode 100644 index 00000000..1029f0f1 --- /dev/null +++ b/module/rdd-alchimie.js @@ -0,0 +1,66 @@ +/* -------------------------------------------- */ +import { Misc } from "./misc.js"; + +/* -------------------------------------------- */ +export class RdDAlchimie { + + /* -------------------------------------------- */ + static processManipulation( recette, actorId = undefined ) { + //console.log("CALLED", recette, recette.isOwned, actorId ); + let manip = duplicate(recette.data.manipulation); + let reg1 = new RegExp(/@(\w*){([\w\-]+)}/ig); + let matchArray = manip.match( reg1 ); + for( let matchStr of matchArray) { + let reg2 = new RegExp(/@(\w*){([\w\-]+)}/i); + let result = matchStr.match(reg2); + //console.log("RESULT ", result); + if ( result[1] && result[2]) { + let commande = Misc.upperFirst( result[1] ); + let replacement = this[`_alchimie${commande}`](recette, result[2], actorId); + manip = manip.replace( result[0], replacement); + } + } + recette.data.manipulation_update = manip; + } + + /* -------------------------------------------- */ + static _alchimieCouleur( recette, couleurs, actorId ) { + let replacement + if ( actorId ) { + replacement = `couleur ${couleurs}`; + } else { + replacement = `couleur ${couleurs} `; + } + return replacement; + } + + /* -------------------------------------------- */ + static _alchimieConsistance( recette, consistances, actorId ) { + let replacement + if ( actorId ) { + replacement = `consistance ${consistances}`; + } else { + replacement = `consistance ${consistances} `; + } + return replacement; + + } + + /* -------------------------------------------- */ + static getDifficulte( aspects ) { + let aspectsArray = aspects.split('-'); + let diff = 0; + let nbDifferent = 0; + let aspectsHash = {} + for (let colconst of aspectsArray) { + if ( aspectsHash[colconst] ){ // Deja present, augmente difficulté de 1 + diff -= 1; + } else { + nbDifferent++; + aspectsHash[colconst] = colconst; // Keep track + } + } + diff = diff - ((nbDifferent>1) ? nbDifferent : 0); // Ca doit marcher .... + return Math.min(0, diff); // Pour être sur + } +} diff --git a/module/rdd-utility.js b/module/rdd-utility.js index bdc45ae2..4982dd9a 100644 --- a/module/rdd-utility.js +++ b/module/rdd-utility.js @@ -191,6 +191,7 @@ export class RdDUtility { 'systems/foundryvtt-reve-de-dragon/templates/dialog-tmr.html', 'systems/foundryvtt-reve-de-dragon/templates/dialog-roll-surenc.html', 'systems/foundryvtt-reve-de-dragon/templates/dialog-roll-enctotal.html', + 'systems/foundryvtt-reve-de-dragon/templates/dialog-roll-alchimie.html', 'systems/foundryvtt-reve-de-dragon/templates/dialog-astrologie-joueur.html', // Calendrier 'systems/foundryvtt-reve-de-dragon/templates/calendar-template.html', @@ -215,6 +216,7 @@ export class RdDUtility { 'systems/foundryvtt-reve-de-dragon/templates/chat-resultat-general.html', 'systems/foundryvtt-reve-de-dragon/templates/chat-resultat-tache.html', 'systems/foundryvtt-reve-de-dragon/templates/chat-resultat-sort.html', + 'systems/foundryvtt-reve-de-dragon/templates/chat-resultat-alchimie.html', 'systems/foundryvtt-reve-de-dragon/templates/chat-actor-turn-summary.html', 'systems/foundryvtt-reve-de-dragon/templates/chat-actor-competence-xp.html', 'systems/foundryvtt-reve-de-dragon/templates/chat-actor-carac-xp.html' @@ -270,6 +272,7 @@ export class RdDUtility { data.data.taches = this.checkNull(data.itemsByType['tache']); data.data.monnaie = this.checkNull(data.itemsByType['monnaie']); data.data.meditations = this.checkNull(data.itemsByType['meditation']); + data.data.recettesAlchimiques = this.checkNull(data.itemsByType['recettealchimique']); data.data.objets = data.data.conteneurs.concat(data.data.materiel).concat(data.data.armes).concat(data.data.armures).concat(data.data.munitions).concat(data.data.livres).concat(data.data.potions).concat(data.data.herbes).concat(data.data.ingredients); } diff --git a/styles/simple.css b/styles/simple.css index ddcafc22..11736fa2 100644 --- a/styles/simple.css +++ b/styles/simple.css @@ -296,6 +296,12 @@ table {border: 1px solid #7a7971;} padding: 0 3px; } +.small-editor { + border: 2; + height: 150px; + padding: 0 3px; +} + .foundryvtt-reve-de-dragon .tox .tox-editor-container { background: #fff; } @@ -503,6 +509,14 @@ section.sheet-body:after { color: rgba(255, 255, 255, 0.5); } +.alchimie-tache { + font-weight: bold; + background: rgb(182, 180, 179); + border: 1px solid rgba(72, 46, 28, 1); + border-radius: 0.25rem; + color: rgba(212, 27, 27, 0.5); +} + .window-app.sheet .window-content .tooltip:hover .tooltiptext { top: 2rem; left: 2rem; diff --git a/system.json b/system.json index 2d5dc3d5..81f3a4ba 100644 --- a/system.json +++ b/system.json @@ -2,10 +2,10 @@ "name": "foundryvtt-reve-de-dragon", "title": "Rêve de Dragon", "description": "Rêve de Dragon RPG for FoundryVTT", - "version": "1.2.2", + "version": "1.2.4", "minimumCoreVersion": "0.7.5", "compatibleCoreVersion": "0.7.8", - "templateVersion": 79, + "templateVersion": 80, "author": "LeRatierBretonnien", "esmodules": [ "module/rdd-main.js", "module/hook-renderChatLog.js" ], "styles": ["styles/simple.css"], diff --git a/template.json b/template.json index af355f3d..f33ac642 100644 --- a/template.json +++ b/template.json @@ -541,7 +541,8 @@ } }, "Item": { - "types": ["objet", "arme", "armure", "conteneur", "competence", "sort", "herbe", "ingredient", "livre", "potion", "munition", "rencontresTMR", "queue", "ombre", "souffle", "tete", "competencecreature", "tarot", "monnaie", "nombreastral", "tache", "meditation", "casetmr" ], + "types": ["objet", "arme", "armure", "conteneur", "competence", "sort", "herbe", "ingredient", "livre", "potion", "munition", "rencontresTMR", "queue", "ombre", "souffle", + "tete", "competencecreature", "tarot", "monnaie", "nombreastral", "tache", "meditation", "casetmr", "recettealchimique" ], "objet": { "description": "", "quantite": 1, @@ -738,6 +739,14 @@ "label": "", "specific": "", "description": "" + }, + "recettealchimique": { + "but": "", + "utilisation": "", + "enchantement": "", + "sureffet": "", + "manipulation": "", + "description": "" } } } diff --git a/templates/actor-sheet.html b/templates/actor-sheet.html index a84a634b..a1c5581b 100644 --- a/templates/actor-sheet.html +++ b/templates/actor-sheet.html @@ -781,6 +781,21 @@