foundryvtt-reve-de-dragon/module/rdd-alchimie.js

64 lines
2.5 KiB
JavaScript
Raw Normal View History

2021-01-07 20:04:10 +01:00
/* -------------------------------------------- */
import { Misc } from "./misc.js";
2021-03-31 22:50:58 +02:00
const matchOperations = new RegExp(/@(\w*){([\w\-]+)}/ig);
const matchOperationTerms = new RegExp(/@(\w*){([\w\-]+)}/i);
2021-01-07 20:04:10 +01:00
/* -------------------------------------------- */
export class RdDAlchimie {
/* -------------------------------------------- */
2021-03-31 22:50:58 +02:00
static processManipulation(recetteData, actorId = undefined) {
2021-01-07 20:04:10 +01:00
//console.log("CALLED", recette, recette.isOwned, actorId );
2021-03-31 22:50:58 +02:00
let manip = recetteData.data.manipulation;
let matchArray = manip.match(matchOperations);
if (matchArray) {
for (let matchStr of matchArray) {
let result = matchStr.match(matchOperationTerms);
2021-01-07 22:29:43 +01:00
//console.log("RESULT ", result);
2021-03-31 22:50:58 +02:00
if (result[1] && result[2]) {
let commande = Misc.upperFirst(result[1]);
let replacement = this[`_alchimie${commande}`](recetteData, result[2], actorId);
manip = manip.replace(result[0], replacement);
2021-01-07 22:29:43 +01:00
}
2021-01-07 20:04:10 +01:00
}
}
2021-03-31 22:50:58 +02:00
recetteData.data.manipulation_update = manip;
2021-01-07 20:04:10 +01:00
}
/* -------------------------------------------- */
2021-03-31 22:50:58 +02:00
static _alchimieCouleur(recette, couleurs, actorId) {
if (actorId) {
return `<span class="alchimie-tache"><a data-recette-id="${recette._id}" data-actor-id="${actorId}" data-alchimie-tache="couleur" data-alchimie-data="${couleurs}">couleur ${couleurs}</a></span>`;
2021-01-07 20:04:10 +01:00
} else {
2021-03-31 22:50:58 +02:00
return `<span class="alchimie-tache">couleur ${couleurs} </span>`;
2021-01-07 20:04:10 +01:00
}
}
/* -------------------------------------------- */
2021-03-31 22:50:58 +02:00
static _alchimieConsistance(recette, consistances, actorId) {
if (actorId) {
return `<span class="alchimie-tache"><a data-recette-id="${recette._id}" data-actor-id="${actorId}" data-alchimie-tache="consistance" data-alchimie-data="${consistances}">consistance ${consistances}</a></span>`;
2021-01-07 20:04:10 +01:00
} else {
2021-03-31 22:50:58 +02:00
return `<span class="alchimie-tache">consistance ${consistances} </span>`;
2021-01-07 20:04:10 +01:00
}
}
/* -------------------------------------------- */
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
}
}