2021-01-04 00:17:22 +01:00
|
|
|
|
import { RdDItemCompetenceCreature } from "./item-competencecreature.js"
|
2021-03-18 23:55:26 +01:00
|
|
|
|
import { RdDCombatManager } from "./rdd-combat.js";
|
2021-01-02 04:28:43 +01:00
|
|
|
|
|
2021-01-05 18:43:13 +01:00
|
|
|
|
const nomCategorieParade = {
|
2021-06-28 15:52:20 +02:00
|
|
|
|
"sans-armes": "Sans arme",
|
|
|
|
|
"armes-naturelles": "Sans arme",
|
2021-01-02 04:28:43 +01:00
|
|
|
|
"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 {
|
|
|
|
|
|
2022-09-07 18:47:56 +02:00
|
|
|
|
static isArme(item) {
|
|
|
|
|
return (item.type == 'competencecreature' && item.system.iscombat) || item.type == 'arme';
|
2021-01-04 00:17:22 +01:00
|
|
|
|
}
|
|
|
|
|
|
2020-12-12 21:58:44 +01:00
|
|
|
|
/* -------------------------------------------- */
|
2022-09-07 18:47:56 +02:00
|
|
|
|
static getArme(arme) {
|
|
|
|
|
switch (arme ? arme.type : '') {
|
|
|
|
|
case 'arme': return arme;
|
2021-01-01 22:25:32 +01:00
|
|
|
|
case 'competencecreature':
|
2022-11-22 02:12:37 +01:00
|
|
|
|
return RdDItemCompetenceCreature.armeNaturelle(arme);
|
2021-01-01 22:25:32 +01:00
|
|
|
|
}
|
|
|
|
|
return RdDItemArme.mainsNues();
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-18 23:55:26 +01:00
|
|
|
|
static computeNiveauArmes(armes, competences) {
|
|
|
|
|
for (const arme of armes) {
|
2022-06-12 08:17:59 +02:00
|
|
|
|
arme.system.niveau = RdDItemArme.niveauCompetenceArme(arme, competences);
|
2021-03-18 23:55:26 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static niveauCompetenceArme(arme, competences) {
|
2022-04-30 23:42:55 +02:00
|
|
|
|
const compArme = competences.find(it => it.name == arme.system.competence);
|
|
|
|
|
return compArme?.system.niveau ?? -8;
|
2021-03-18 23:55:26 +01:00
|
|
|
|
}
|
|
|
|
|
|
2021-01-02 04:28:43 +01:00
|
|
|
|
/* -------------------------------------------- */
|
2021-01-05 18:43:13 +01:00
|
|
|
|
static getNomCategorieParade(arme) {
|
2022-06-12 08:17:59 +02:00
|
|
|
|
const categorie = arme?.system ? RdDItemArme.getCategorieParade(arme) : arme;
|
2021-01-05 18:43:13 +01:00
|
|
|
|
return nomCategorieParade[categorie];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
|
static needArmeResist(armeAttaque, armeParade) {
|
2021-03-18 23:55:26 +01:00
|
|
|
|
if (!armeAttaque || !armeParade) {
|
2021-01-05 18:43:13 +01:00
|
|
|
|
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
|
|
|
|
/* -------------------------------------------- */
|
2021-03-22 20:10:37 +01:00
|
|
|
|
static getCategorieParade(armeData) {
|
2022-06-12 08:17:59 +02:00
|
|
|
|
if (armeData.system.categorie_parade) {
|
|
|
|
|
return armeData.system.categorie_parade;
|
2021-01-01 22:23:58 +01:00
|
|
|
|
}
|
|
|
|
|
// pour compatibilité avec des personnages existants
|
2022-06-12 08:17:59 +02:00
|
|
|
|
if (armeData.type == 'competencecreature' || armeData.system.categorie == 'creature') {
|
|
|
|
|
return armeData.system.categorie_parade || (armeData.system.isparade ? 'armes-naturelles' : '');
|
2021-01-01 22:23:58 +01:00
|
|
|
|
}
|
2021-03-22 20:10:37 +01:00
|
|
|
|
if (!armeData.type.match(/arme|competencecreature/)) {
|
2021-01-01 22:23:58 +01:00
|
|
|
|
return '';
|
|
|
|
|
}
|
2022-06-12 08:17:59 +02:00
|
|
|
|
if (armeData.system.competence == undefined) {
|
2020-12-12 21:58:44 +01:00
|
|
|
|
return 'competencecreature';
|
|
|
|
|
}
|
2022-06-12 08:17:59 +02:00
|
|
|
|
let compname = armeData.system.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')) {
|
2021-03-22 20:10:37 +01:00
|
|
|
|
if (armeData.name.toLowerCase().match(/(gnome)/))
|
2021-01-01 22:23:58 +01:00
|
|
|
|
return 'epees-courtes';
|
2021-03-22 20:10:37 +01:00
|
|
|
|
if (armeData.name.toLowerCase().match(/((e|é)pée dragone|esparlongue|demi-dragonne)/))
|
2021-01-01 22:23:58 +01:00
|
|
|
|
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-03-18 23:55:26 +01:00
|
|
|
|
if (!armeAttaque || !armeParade) {
|
2021-01-05 18:43:13 +01:00
|
|
|
|
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-06-22 23:28:32 +02:00
|
|
|
|
// Parer avec une hache ou une arme d’hast exige toujours une significative
|
2021-01-02 04:28:43 +01:00
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
2021-03-22 20:10:37 +01:00
|
|
|
|
static armeUneOuDeuxMains(armeData, aUneMain) {
|
2022-06-12 08:17:59 +02:00
|
|
|
|
if (armeData && !armeData.system.cac) {
|
|
|
|
|
armeData.system.unemain = armeData.system.unemain || !armeData.system.deuxmains;
|
|
|
|
|
const uneOuDeuxMains = armeData.system.unemain && armeData.system.deuxmains;
|
|
|
|
|
const containsSlash = !Number.isInteger(armeData.system.dommages) && armeData.system.dommages.includes("/");
|
2020-12-16 23:02:15 +01:00
|
|
|
|
if (containsSlash) { // Sanity check
|
2021-03-22 20:10:37 +01:00
|
|
|
|
armeData = duplicate(armeData);
|
2020-12-12 21:58:44 +01:00
|
|
|
|
|
2022-06-12 08:17:59 +02:00
|
|
|
|
const tableauDegats = armeData.system.dommages.split("/");
|
2020-12-16 23:02:15 +01:00
|
|
|
|
if (aUneMain)
|
2022-06-12 08:17:59 +02:00
|
|
|
|
armeData.system.dommagesReels = Number(tableauDegats[0]);
|
2020-12-16 23:02:15 +01:00
|
|
|
|
else // 2 mains
|
2022-06-12 08:17:59 +02:00
|
|
|
|
armeData.system.dommagesReels = Number(tableauDegats[1]);
|
2020-12-16 23:02:15 +01:00
|
|
|
|
}
|
|
|
|
|
else {
|
2022-06-12 08:17:59 +02:00
|
|
|
|
armeData.system.dommagesReels = Number(armeData.system.dommages);
|
2020-12-16 23:02:15 +01:00
|
|
|
|
}
|
2020-12-12 21:58:44 +01:00
|
|
|
|
|
2020-12-16 23:02:15 +01:00
|
|
|
|
if (uneOuDeuxMains != containsSlash) {
|
2021-03-22 20:10:37 +01:00
|
|
|
|
ui.notifications.info("Les dommages de l'arme à 1/2 mains " + armeData.name + " ne sont pas corrects (ie sous la forme X/Y)");
|
2020-12-16 23:02:15 +01:00
|
|
|
|
}
|
2020-12-12 21:58:44 +01:00
|
|
|
|
}
|
2021-03-22 20:10:37 +01:00
|
|
|
|
return armeData;
|
2020-12-12 21:58:44 +01:00
|
|
|
|
}
|
|
|
|
|
|
2022-09-07 18:47:56 +02:00
|
|
|
|
static isArmeUtilisable(arme) {
|
|
|
|
|
return arme.type == 'arme' && arme.system.equipe && (arme.system.resistance > 0 || arme.system.portee_courte > 0);
|
2021-03-18 23:55:26 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static ajoutCorpsACorps(armes, competences, carac) {
|
2022-06-12 08:17:59 +02:00
|
|
|
|
let corpsACorps = competences.find(it => it.name == 'Corps à corps') ?? { system: { niveau: -6 } };
|
|
|
|
|
let init = RdDCombatManager.calculInitiative(corpsACorps.system.niveau, carac['melee'].value);
|
|
|
|
|
armes.push(RdDItemArme.mainsNues({ niveau: corpsACorps.system.niveau, initiative: init }));
|
2022-09-07 18:47:56 +02:00
|
|
|
|
//armes.push(RdDItemArme.empoignade({ niveau: corpsACorps.system.niveau, initiative: init }));
|
2021-01-28 00:27:44 +01:00
|
|
|
|
}
|
2021-01-04 00:17:22 +01:00
|
|
|
|
|
2022-09-07 18:47:56 +02:00
|
|
|
|
static corpsACorps(mainsNuesActor) {
|
2021-06-28 16:08:45 +02:00
|
|
|
|
const corpsACorps = {
|
|
|
|
|
name: 'Corps à corps',
|
2021-11-20 01:19:29 +01:00
|
|
|
|
img: 'systems/foundryvtt-reve-de-dragon/icons/competence_corps_a_corps.webp',
|
2022-05-01 00:38:09 +02:00
|
|
|
|
system: {
|
2021-01-04 00:17:22 +01:00
|
|
|
|
equipe: true,
|
|
|
|
|
rapide: true,
|
|
|
|
|
force: 0,
|
2022-11-18 03:38:17 +01:00
|
|
|
|
dommages: "0",
|
2021-01-04 00:17:22 +01:00
|
|
|
|
dommagesReels: 0,
|
|
|
|
|
mortalite: 'non-mortel',
|
|
|
|
|
competence: 'Corps à corps',
|
|
|
|
|
categorie_parade: 'sans-armes'
|
|
|
|
|
}
|
2020-12-17 00:23:40 +01:00
|
|
|
|
};
|
2022-09-07 18:47:56 +02:00
|
|
|
|
mergeObject(corpsACorps.system, mainsNuesActor ?? {}, { overwrite: false });
|
2021-06-28 16:08:45 +02:00
|
|
|
|
return corpsACorps;
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-07 18:47:56 +02:00
|
|
|
|
static mainsNues(mainsNuesActor) {
|
|
|
|
|
const mainsNues = RdDItemArme.corpsACorps(mainsNuesActor)
|
2022-06-12 08:17:59 +02:00
|
|
|
|
mainsNues.name = 'Mains nues'
|
|
|
|
|
mainsNues.system.cac = 'pugilat'
|
|
|
|
|
mainsNues.system.baseInit = 4
|
2021-05-24 22:12:37 +02:00
|
|
|
|
return mainsNues;
|
2020-12-16 23:02:15 +01:00
|
|
|
|
}
|
2021-06-28 16:08:45 +02:00
|
|
|
|
|
2022-09-07 18:47:56 +02:00
|
|
|
|
static empoignade(mainsNuesActor) {
|
|
|
|
|
const empoignade = RdDItemArme.corpsACorps(mainsNuesActor)
|
2022-06-12 08:17:59 +02:00
|
|
|
|
empoignade.name = 'Empoignade'
|
|
|
|
|
empoignade.system.cac = 'empoignade'
|
|
|
|
|
empoignade.system.baseInit = 3
|
|
|
|
|
empoignade.system.mortalite = 'empoignade'
|
|
|
|
|
return empoignade
|
2021-06-28 16:08:45 +02:00
|
|
|
|
}
|
2021-03-18 23:55:26 +01:00
|
|
|
|
}
|