2021-01-04 00:17:22 +01:00
|
|
|
|
import { RdDItemCompetenceCreature } from "./item-competencecreature.js"
|
2021-03-22 20:10:37 +01:00
|
|
|
|
import { Misc } from "./misc.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 {
|
|
|
|
|
|
2021-03-22 20:10:37 +01:00
|
|
|
|
static isArme(itemData) {
|
|
|
|
|
itemData = Misc.data(itemData);
|
|
|
|
|
return (itemData.type == 'competencecreature' && itemData.data.iscombat) || itemData.type == 'arme';
|
2021-01-04 00:17:22 +01:00
|
|
|
|
}
|
|
|
|
|
|
2020-12-12 21:58:44 +01:00
|
|
|
|
/* -------------------------------------------- */
|
2021-03-22 20:10:37 +01:00
|
|
|
|
static getArmeData(armeData) {
|
|
|
|
|
armeData = Misc.data(armeData);
|
|
|
|
|
switch (armeData ? armeData.type : '') {
|
|
|
|
|
case 'arme': return armeData;
|
2021-01-01 22:25:32 +01:00
|
|
|
|
case 'competencecreature':
|
2021-03-22 20:10:37 +01:00
|
|
|
|
return RdDItemCompetenceCreature.toArme(armeData);
|
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-04-30 23:42:55 +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) {
|
|
|
|
|
const categorie = arme?.data ? RdDItemArme.getCategorieParade(arme) : arme;
|
|
|
|
|
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) {
|
|
|
|
|
armeData = Misc.data(armeData);
|
|
|
|
|
if (armeData.data.categorie_parade) {
|
|
|
|
|
return armeData.data.categorie_parade;
|
2021-01-01 22:23:58 +01:00
|
|
|
|
}
|
|
|
|
|
// pour compatibilité avec des personnages existants
|
2021-03-22 20:10:37 +01:00
|
|
|
|
if (armeData.type == 'competencecreature' || armeData.data.categorie == 'creature') {
|
2021-06-28 15:52:20 +02:00
|
|
|
|
return armeData.data.categorie_parade || (armeData.data.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 '';
|
|
|
|
|
}
|
2021-03-22 20:10:37 +01:00
|
|
|
|
if (armeData.data.competence == undefined) {
|
2020-12-12 21:58:44 +01:00
|
|
|
|
return 'competencecreature';
|
|
|
|
|
}
|
2021-03-22 20:10:37 +01:00
|
|
|
|
let compname = armeData.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')) {
|
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) {
|
|
|
|
|
armeData = Misc.data(armeData);
|
2021-06-28 16:08:45 +02:00
|
|
|
|
if (armeData && !armeData.data.cac) {
|
2021-03-22 20:10:37 +01:00
|
|
|
|
armeData.data.unemain = armeData.data.unemain || !armeData.data.deuxmains;
|
|
|
|
|
const uneOuDeuxMains = armeData.data.unemain && armeData.data.deuxmains;
|
|
|
|
|
const containsSlash = !Number.isInteger(armeData.data.dommages) && armeData.data.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
|
|
|
|
|
2021-03-22 20:10:37 +01:00
|
|
|
|
const tableauDegats = armeData.data.dommages.split("/");
|
2020-12-16 23:02:15 +01:00
|
|
|
|
if (aUneMain)
|
2021-03-22 20:10:37 +01:00
|
|
|
|
armeData.data.dommagesReels = Number(tableauDegats[0]);
|
2020-12-16 23:02:15 +01:00
|
|
|
|
else // 2 mains
|
2021-03-22 20:10:37 +01:00
|
|
|
|
armeData.data.dommagesReels = Number(tableauDegats[1]);
|
2020-12-16 23:02:15 +01:00
|
|
|
|
}
|
|
|
|
|
else {
|
2021-03-22 20:10:37 +01:00
|
|
|
|
armeData.data.dommagesReels = Number(armeData.data.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
|
|
|
|
}
|
|
|
|
|
|
2021-03-22 20:10:37 +01:00
|
|
|
|
static isArmeUtilisable(itemData) {
|
|
|
|
|
itemData = Misc.data(itemData);
|
|
|
|
|
return itemData.type == 'arme' && itemData.data.equipe && (itemData.data.resistance > 0 || itemData.data.portee_courte > 0);
|
2021-03-18 23:55:26 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static ajoutCorpsACorps(armes, competences, carac) {
|
2022-05-01 00:38:09 +02:00
|
|
|
|
let corpsACorps = competences.find(it => it.name == 'Corps à corps') ?? { data: { niveau: -6 } }
|
|
|
|
|
let init = RdDCombatManager.calculInitiative(corpsACorps.system.niveau, carac['melee'].value)
|
|
|
|
|
armes.push(RdDItemArme.mainsNues({ niveau: corpsACorps.system.niveau, initiative: init }))
|
2021-11-20 00:42:04 +01:00
|
|
|
|
//armes.push(RdDItemArme.empoignade({ niveau: corpsACorps.data.niveau, initiative: init }));
|
2021-01-28 00:27:44 +01:00
|
|
|
|
}
|
2021-01-04 00:17:22 +01:00
|
|
|
|
|
2021-06-28 16:08:45 +02:00
|
|
|
|
static corpsACorps(actorData) {
|
|
|
|
|
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,
|
|
|
|
|
dommages: 0,
|
|
|
|
|
dommagesReels: 0,
|
|
|
|
|
mortalite: 'non-mortel',
|
|
|
|
|
competence: 'Corps à corps',
|
|
|
|
|
categorie_parade: 'sans-armes'
|
|
|
|
|
}
|
2020-12-17 00:23:40 +01:00
|
|
|
|
};
|
2022-05-01 00:38:09 +02:00
|
|
|
|
mergeObject(corpsACorps.system, actorData ??{}, { overwrite: false });
|
2021-06-28 16:08:45 +02:00
|
|
|
|
return corpsACorps;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static mainsNues(actorData) {
|
|
|
|
|
const mainsNues = RdDItemArme.corpsACorps(actorData);
|
|
|
|
|
mainsNues.name = 'Mains nues';
|
2022-05-01 00:38:09 +02:00
|
|
|
|
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
|
|
|
|
|
|
|
|
|
static empoignade(actorData) {
|
|
|
|
|
const empoignade = RdDItemArme.corpsACorps(actorData);
|
|
|
|
|
empoignade.name = 'Empoignade';
|
2022-05-01 00:38:09 +02:00
|
|
|
|
empoignade.system.cac = 'empoignade';
|
|
|
|
|
empoignade.system.baseInit = 3;
|
|
|
|
|
empoignade.system.mortalite = 'empoignade';
|
2021-06-28 16:08:45 +02:00
|
|
|
|
return empoignade;
|
|
|
|
|
}
|
2021-03-18 23:55:26 +01:00
|
|
|
|
}
|