2021-01-04 00:17:22 +01:00
|
|
|
|
import { RdDItemCompetenceCreature } from "./item-competencecreature.js"
|
2021-01-02 04:28:43 +01:00
|
|
|
|
|
2021-01-05 18:43:13 +01:00
|
|
|
|
const nomCategorieParade = {
|
2021-01-02 04:28:43 +01:00
|
|
|
|
"sans-armes": "Sans arme / armes naturelles",
|
|
|
|
|
"hast": "Armes d'hast",
|
|
|
|
|
"batons": "Bâtons",
|
|
|
|
|
"boucliers": "Boucliers",
|
|
|
|
|
"dagues": "Dagues",
|
|
|
|
|
"epees-courtes": "Epées courtes",
|
|
|
|
|
"epees-longues": "Epées longues",
|
|
|
|
|
"epees-lourdes": "Epées lourdes",
|
|
|
|
|
"haches": "Haches",
|
|
|
|
|
"lances": "Lances",
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-04 00:17:22 +01:00
|
|
|
|
/* -------------------------------------------- */
|
2020-12-12 21:58:44 +01:00
|
|
|
|
export class RdDItemArme extends Item {
|
|
|
|
|
|
2021-01-04 00:17:22 +01:00
|
|
|
|
static isArme(item) {
|
|
|
|
|
return (item.type == 'competencecreature' && item.data.iscombat) || item.type == 'arme';
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-12 21:58:44 +01:00
|
|
|
|
/* -------------------------------------------- */
|
2021-01-01 22:25:32 +01:00
|
|
|
|
static getArmeData(item) {
|
|
|
|
|
switch (item ? item.data.type : '') {
|
|
|
|
|
case 'arme': return item.data;
|
|
|
|
|
case 'competencecreature':
|
2021-01-14 00:35:55 +01:00
|
|
|
|
return RdDItemCompetenceCreature.toArme(item.data);
|
2021-01-01 22:25:32 +01:00
|
|
|
|
}
|
|
|
|
|
return RdDItemArme.mainsNues();
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-02 04:28:43 +01:00
|
|
|
|
/* -------------------------------------------- */
|
2021-01-05 18:43:13 +01:00
|
|
|
|
static getNomCategorieParade(arme) {
|
|
|
|
|
const categorie = arme?.data ? RdDItemArme.getCategorieParade(arme) : arme;
|
|
|
|
|
return nomCategorieParade[categorie];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
|
static needArmeResist(armeAttaque, armeParade) {
|
|
|
|
|
if (!armeAttaque || !armeParade){
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
// Epées parant une arme de bois (cf. page 115 ), une résistance est nécessaire
|
|
|
|
|
let attCategory = RdDItemArme.getCategorieParade(armeAttaque);
|
|
|
|
|
let defCategory = RdDItemArme.getCategorieParade(armeParade);
|
|
|
|
|
|
|
|
|
|
return attCategory.match(/epees-/) && defCategory.match(/(haches|lances)/);
|
2021-01-02 04:28:43 +01:00
|
|
|
|
}
|
2021-01-04 00:17:22 +01:00
|
|
|
|
|
2021-01-01 22:23:58 +01:00
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
|
static getCategorieParade(arme) {
|
|
|
|
|
if (arme.data.categorie_parade) {
|
|
|
|
|
return arme.data.categorie_parade;
|
|
|
|
|
}
|
|
|
|
|
// pour compatibilité avec des personnages existants
|
2021-01-23 17:23:56 +01:00
|
|
|
|
if (arme.type == 'competencecreature' || arme.data.categorie == 'creature' ) {
|
2021-01-01 22:23:58 +01:00
|
|
|
|
return arme.data.categorie_parade || (arme.data.isparade ? 'sans-armes' : '');
|
|
|
|
|
}
|
|
|
|
|
if (!arme.type.match(/arme|competencecreature/)) {
|
|
|
|
|
return '';
|
|
|
|
|
}
|
2020-12-12 21:58:44 +01:00
|
|
|
|
if (arme.data.competence == undefined) {
|
|
|
|
|
return 'competencecreature';
|
|
|
|
|
}
|
|
|
|
|
let compname = arme.data.competence.toLowerCase();
|
2021-01-01 22:23:58 +01:00
|
|
|
|
if (compname.match(/^(dague de jet|javelot|fouet|arc|arbalête|fronde|hache de jet|fléau)$/)) return '';
|
2020-12-12 21:58:44 +01:00
|
|
|
|
|
2021-01-01 22:23:58 +01:00
|
|
|
|
if (compname.match('hache')) return 'haches';
|
|
|
|
|
if (compname.match('hast')) return 'hast';
|
|
|
|
|
if (compname.match('lance')) return 'lances';
|
|
|
|
|
if (compname.match('bouclier')) return 'boucliers';
|
|
|
|
|
if (compname.match('masse')) return 'masses';
|
|
|
|
|
if (compname.match('epée') || compname.match('épée')) {
|
|
|
|
|
if (arme.name.toLowerCase().match(/(gnome)/))
|
|
|
|
|
return 'epees-courtes';
|
|
|
|
|
if (arme.name.toLowerCase().match(/((e|é)pée dragone|esparlongue|demi-dragonne)/))
|
|
|
|
|
return 'epees-longues';
|
|
|
|
|
return 'epees-lourdes';
|
2020-12-12 21:58:44 +01:00
|
|
|
|
}
|
2021-01-01 22:23:58 +01:00
|
|
|
|
if (compname.match('dague')) {
|
|
|
|
|
return 'dagues';
|
2020-12-12 21:58:44 +01:00
|
|
|
|
}
|
2021-01-01 22:23:58 +01:00
|
|
|
|
return 'sans-armes';
|
2020-12-12 21:58:44 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
|
static needParadeSignificative(armeAttaque, armeParade) {
|
2021-01-05 18:43:13 +01:00
|
|
|
|
if (!armeAttaque || !armeParade){
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2021-01-02 04:28:43 +01:00
|
|
|
|
// categories d'armes à la parade (cf. page 115 )
|
2021-01-01 22:23:58 +01:00
|
|
|
|
let attCategory = RdDItemArme.getCategorieParade(armeAttaque);
|
|
|
|
|
let defCategory = RdDItemArme.getCategorieParade(armeParade);
|
|
|
|
|
// bouclier et mêmes catégorie: peuvent se parer sans difficulté
|
2021-01-02 04:28:43 +01:00
|
|
|
|
if (defCategory == 'boucliers') {
|
2021-01-01 22:23:58 +01:00
|
|
|
|
return false;
|
|
|
|
|
}
|
2021-01-02 04:28:43 +01:00
|
|
|
|
// Parer avec une hache ou une arme d’hast exige toujours une signi$cative
|
|
|
|
|
if (defCategory.match(/(hast|haches)/)) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
if (defCategory == attCategory) {
|
2021-01-01 22:23:58 +01:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
// les épées se parent entre elles
|
2021-01-02 04:28:43 +01:00
|
|
|
|
if (defCategory.match(/epees-/) && attCategory.match(/epees-/)) {
|
2021-01-01 22:23:58 +01:00
|
|
|
|
return false;
|
|
|
|
|
}
|
2021-01-02 04:28:43 +01:00
|
|
|
|
// l'épée gnome pare la dague
|
|
|
|
|
if (defCategory == 'epees-courtes' && attCategory == 'dagues') {
|
2020-12-12 21:58:44 +01:00
|
|
|
|
return false;
|
|
|
|
|
}
|
2021-01-02 04:28:43 +01:00
|
|
|
|
// la dague pare les épées courtes et légères
|
|
|
|
|
if (defCategory == 'dagues' && attCategory.match(/epees-(courtes|legeres)/)) {
|
2020-12-12 21:58:44 +01:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
|
static armeUneOuDeuxMains(arme, aUneMain) {
|
2020-12-16 23:02:15 +01:00
|
|
|
|
if (arme) {
|
|
|
|
|
arme.data.unemain = arme.data.unemain || !arme.data.deuxmains;
|
|
|
|
|
const uneOuDeuxMains = arme.data.unemain && arme.data.deuxmains;
|
|
|
|
|
const containsSlash = !Number.isInteger(arme.data.dommages) && arme.data.dommages.includes("/");
|
|
|
|
|
if (containsSlash) { // Sanity check
|
|
|
|
|
arme = duplicate(arme);
|
2020-12-12 21:58:44 +01:00
|
|
|
|
|
2020-12-16 23:02:15 +01:00
|
|
|
|
const tableauDegats = arme.data.dommages.split("/");
|
|
|
|
|
if (aUneMain)
|
|
|
|
|
arme.data.dommagesReels = Number(tableauDegats[0]);
|
|
|
|
|
else // 2 mains
|
|
|
|
|
arme.data.dommagesReels = Number(tableauDegats[1]);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
arme.data.dommagesReels = Number(arme.data.dommages);
|
|
|
|
|
}
|
2020-12-12 21:58:44 +01:00
|
|
|
|
|
2020-12-16 23:02:15 +01:00
|
|
|
|
if (uneOuDeuxMains != containsSlash) {
|
|
|
|
|
ui.notifications.info("Les dommages de l'arme à 1/2 mains " + arme.name + " ne sont pas corrects (ie sous la forme X/Y)");
|
|
|
|
|
}
|
2020-12-12 21:58:44 +01:00
|
|
|
|
}
|
|
|
|
|
return arme;
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-04 00:17:22 +01:00
|
|
|
|
|
|
|
|
|
static mainsNues(actorData={}) {
|
2020-12-17 00:23:40 +01:00
|
|
|
|
const mainsNues = {
|
2021-01-01 22:23:58 +01:00
|
|
|
|
name: 'Mains nues',
|
2021-01-04 00:17:22 +01:00
|
|
|
|
data: {
|
|
|
|
|
equipe: true,
|
|
|
|
|
rapide: true,
|
|
|
|
|
force: 0,
|
|
|
|
|
dommages: 0,
|
|
|
|
|
dommagesReels: 0,
|
|
|
|
|
mortalite: 'non-mortel',
|
|
|
|
|
competence: 'Corps à corps',
|
|
|
|
|
categorie_parade: 'sans-armes'
|
|
|
|
|
}
|
2020-12-17 00:23:40 +01:00
|
|
|
|
};
|
2021-01-04 00:17:22 +01:00
|
|
|
|
if (actorData) {
|
|
|
|
|
mergeObject( mainsNues.data, actorData, {overwrite:false});
|
|
|
|
|
}
|
2020-12-17 00:23:40 +01:00
|
|
|
|
return mainsNues
|
2020-12-16 23:02:15 +01:00
|
|
|
|
}
|
2020-12-12 21:58:44 +01:00
|
|
|
|
}
|