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 {
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
2022-09-07 09:01:23 +02:00
|
|
|
static processManipulation(recette, actorId = undefined) {
|
|
|
|
let manip = recette.system.manipulation;
|
2021-03-31 22:50:58 +02:00
|
|
|
let matchArray = manip.match(matchOperations);
|
|
|
|
if (matchArray) {
|
|
|
|
for (let matchStr of matchArray) {
|
|
|
|
let result = matchStr.match(matchOperationTerms);
|
|
|
|
if (result[1] && result[2]) {
|
|
|
|
let commande = Misc.upperFirst(result[1]);
|
2022-09-07 18:47:56 +02:00
|
|
|
let replacement = this[`_alchimie${commande}`](recette, result[2], actorId);
|
2021-03-31 22:50:58 +02:00
|
|
|
manip = manip.replace(result[0], replacement);
|
2021-01-07 22:29:43 +01:00
|
|
|
}
|
2021-01-07 20:04:10 +01:00
|
|
|
}
|
|
|
|
}
|
2022-09-07 18:47:56 +02:00
|
|
|
recette.system.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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
2021-03-31 22:51:32 +02:00
|
|
|
static getDifficulte(aspects) {
|
|
|
|
let elements = aspects.split('-');
|
|
|
|
let composantes = elements.length;
|
|
|
|
let distincts = Object.keys(Misc.classifyFirst(elements, it => it)).length;
|
|
|
|
if (distincts == 1) {
|
|
|
|
composantes--;
|
2021-01-07 20:04:10 +01:00
|
|
|
}
|
2021-03-31 22:51:32 +02:00
|
|
|
return Math.min(0, -composantes);
|
2021-01-07 20:04:10 +01:00
|
|
|
}
|
2021-04-20 23:16:18 +02:00
|
|
|
|
|
|
|
static getCaracTache(tache) {
|
|
|
|
switch (tache) {
|
|
|
|
case "consistance": return 'dexterite';
|
|
|
|
case "couleur": return 'vue';
|
|
|
|
}
|
|
|
|
return 'intellect';
|
|
|
|
}
|
|
|
|
|
2021-01-07 20:04:10 +01:00
|
|
|
}
|