Fix Macros de combat et corps à corps
- gestion des armes à 1/2 mains depuis les armes / le combat - gestion correcte des compétences d'attaques de créatures - message pour les macros de compétence d'arme
This commit is contained in:
parent
e61417c44e
commit
a65d4511c5
@ -232,6 +232,9 @@ export class RdDActor extends RdDBaseActor {
|
||||
|
||||
/* -------------------------------------------- */
|
||||
getCompetence(idOrName, options = {}) {
|
||||
if (idOrName instanceof Item) {
|
||||
return idOrName.isCompetence() ? idOrName : undefined
|
||||
}
|
||||
return RdDItemCompetence.findCompetence(this.items, idOrName, options)
|
||||
}
|
||||
|
||||
@ -2139,7 +2142,7 @@ export class RdDActor extends RdDBaseActor {
|
||||
ui.notifications.info(`Aucun sort disponible en ${TMRUtility.getTMR(coord).label} !`);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
const draconicList = this.computeDraconicAndSortIndex(sorts);
|
||||
const reve = duplicate(this.system.carac.reve);
|
||||
@ -3073,24 +3076,35 @@ export class RdDActor extends RdDBaseActor {
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
getArmeCompetence(arme, competenceName) {
|
||||
let comp = arme.system[competenceName]
|
||||
if (!comp || comp.name == "") {
|
||||
comp = arme.system[competenceName]
|
||||
getCompetenceArme(arme, competenceName) {
|
||||
switch (arme.type) {
|
||||
case TYPES.competencecreature:
|
||||
return arme.name
|
||||
case TYPES.arme:
|
||||
switch (competenceName) {
|
||||
case 'competence': return arme.system.competence;
|
||||
case 'unemain': return RdDItemArme.competence1Mains(arme);
|
||||
case 'deuxmains': return RdDItemArme.competence2Mains(arme);
|
||||
case 'tir': return arme.system.tir;
|
||||
case 'lancer': return arme.system.lancer;
|
||||
}
|
||||
}
|
||||
if ( !comp || comp.name == "") {
|
||||
comp = arme.system[competenceName]
|
||||
}
|
||||
return comp
|
||||
return undefined
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
rollArme(arme, competenceName = "competence") {
|
||||
let compToUse = this.getArmeCompetence(arme, competenceName)
|
||||
/**
|
||||
*
|
||||
* @param {*} arme item d'arme/compétence de créature
|
||||
* @param {*} categorieArme catégorie d'attaque à utiliser: competence (== melee), lancer, tir; naturelle, possession
|
||||
* @returns
|
||||
*/
|
||||
rollArme(arme, categorieArme = "competence") {
|
||||
let compToUse = this.getCompetenceArme(arme, categorieArme)
|
||||
if (!Targets.hasTargets()) {
|
||||
RdDConfirm.confirmer({
|
||||
settingConfirmer: "confirmer-combat-sans-cible",
|
||||
content: `<p>Voulez vous faire un jet de compétence ${competenceName} sans choisir de cible valide?
|
||||
content: `<p>Voulez vous faire un jet de ${compToUse} sans choisir de cible valide?
|
||||
<br>Tous les jets de combats devront être gérés à la main
|
||||
</p>`,
|
||||
title: 'Ne pas utiliser les automatisation de combat',
|
||||
|
@ -157,6 +157,13 @@ export class RdDItemArme extends Item {
|
||||
}
|
||||
return armeData;
|
||||
}
|
||||
static competence2Mains(arme) {
|
||||
return arme.system.competence.replace(" 1 main", " 2 mains");
|
||||
}
|
||||
|
||||
static competence1Mains(arme) {
|
||||
return arme.system.competence.replace(" 2 mains", " 1 main");
|
||||
}
|
||||
|
||||
static isArmeUtilisable(arme) {
|
||||
return arme.type == 'arme' && arme.system.equipe && (arme.system.resistance > 0 || arme.system.portee_courte > 0);
|
||||
@ -172,6 +179,7 @@ export class RdDItemArme extends Item {
|
||||
static corpsACorps(mainsNuesActor) {
|
||||
const corpsACorps = {
|
||||
name: 'Corps à corps',
|
||||
type: 'arme',
|
||||
img: 'systems/foundryvtt-reve-de-dragon/icons/competence_corps_a_corps.webp',
|
||||
system: {
|
||||
equipe: true,
|
||||
@ -181,6 +189,7 @@ export class RdDItemArme extends Item {
|
||||
dommagesReels: 0,
|
||||
mortalite: 'non-mortel',
|
||||
competence: 'Corps à corps',
|
||||
deuxmains: true,
|
||||
categorie_parade: 'sans-armes'
|
||||
}
|
||||
};
|
||||
@ -195,7 +204,7 @@ export class RdDItemArme extends Item {
|
||||
mainsNues.system.baseInit = 4
|
||||
return mainsNues;
|
||||
}
|
||||
|
||||
|
||||
static empoignade(mainsNuesActor) {
|
||||
const empoignade = RdDItemArme.corpsACorps(mainsNuesActor)
|
||||
empoignade.name = 'Empoignade'
|
||||
|
@ -171,8 +171,7 @@ export class RdDCombatManager extends Combat {
|
||||
if (arme.system.unemain && arme.system.deuxmains && !dommages.includes("/")) {
|
||||
ui.notifications.info("Les dommages de l'arme à 1/2 mains " + arme.name + " ne sont pas corrects (ie sous la forme X/Y)");
|
||||
}
|
||||
if ((arme.system.unemain && arme.system.competence) ||
|
||||
(arme.system.competence.toLowerCase().includes("corps à corps"))) {
|
||||
if (arme.system.unemain && arme.system.competence) {
|
||||
actions.push(RdDCombatManager.$prepareAttaqueArme({
|
||||
arme: arme,
|
||||
infoMain: "(1 main)",
|
||||
@ -187,7 +186,7 @@ export class RdDCombatManager extends Combat {
|
||||
arme: arme,
|
||||
infoMain: "(2 mains)",
|
||||
dommagesReel: Number(tableauDommages[1]),
|
||||
competence: arme.system.competence.replace(" 1 main", " 2 mains"),
|
||||
competence: RdDItemArme.competence2Mains(arme),
|
||||
carac: carac,
|
||||
competences: competences
|
||||
}));
|
||||
|
@ -1,13 +1,17 @@
|
||||
import { RdDItemCompetence } from "./item-competence.js";
|
||||
import { RdDItemCompetenceCreature } from "./item-competencecreature.js";
|
||||
import { TYPES } from "./item.js";
|
||||
|
||||
export class RdDHotbar {
|
||||
|
||||
static async createItemMacro(item, slot, armeCompetence = undefined) {
|
||||
let command = `game.system.rdd.RdDHotbar.rollMacro("${item.name}", "${item.type}"` + ((armeCompetence) ? `, "${armeCompetence}");` : `);`);
|
||||
let macro = game.macros.contents.find(m => (m.name === item.name) && (m.command === command));
|
||||
const itemName = item.name;
|
||||
let command = `game.system.rdd.RdDHotbar.rollMacro("${itemName}", "${item.type}", "${armeCompetence}");`
|
||||
let macro = game.macros.contents.find(m => (m.name === itemName) && (m.command === command));
|
||||
let macroName = itemName + RdDHotbar.$macroNameSuffix(armeCompetence);
|
||||
if (!macro) {
|
||||
macro = await Macro.create({
|
||||
name: item.name,
|
||||
name: macroName,
|
||||
type: "script",
|
||||
img: item.img,
|
||||
command: command
|
||||
@ -16,29 +20,51 @@ export class RdDHotbar {
|
||||
await game.user.assignHotbarMacro(macro, slot);
|
||||
}
|
||||
|
||||
static $macroNameSuffix(armeCompetence){
|
||||
switch(armeCompetence) {
|
||||
case 'unemain': return ' (1 main)';
|
||||
case 'deuxmains': return ' (2 main)';
|
||||
case 'tir': return ' (tir)';
|
||||
case 'lancer': return ' (lancer)';
|
||||
}
|
||||
return ''
|
||||
}
|
||||
|
||||
static async addToHotbar(item, slot) {
|
||||
switch (item?.type ?? "") {
|
||||
switch (item?.type ?? '') {
|
||||
case TYPES.arme:
|
||||
{
|
||||
// Les armes peuvent avoir plusieurs usages
|
||||
if (item.system.competence != "") {
|
||||
await this.createItemMacro(item, slot, "competence")
|
||||
if (item.system.competence != '') {
|
||||
if (item.system.unemain) {
|
||||
await this.createItemMacro(item, slot, 'unemain')
|
||||
slot++
|
||||
}
|
||||
if (item.system.deuxmains) {
|
||||
await this.createItemMacro(item, slot, 'deuxmains')
|
||||
slot++
|
||||
}
|
||||
}
|
||||
if (item.system.lancer != '') {
|
||||
await this.createItemMacro(item, slot, 'lancer')
|
||||
slot++
|
||||
}
|
||||
if (item.system.lancer != "") {
|
||||
await this.createItemMacro(item, slot, "lancer")
|
||||
slot++
|
||||
}
|
||||
if (item.system.tir != "") {
|
||||
await this.createItemMacro(item, slot, "lancer")
|
||||
if (item.system.tir != '') {
|
||||
await this.createItemMacro(item, slot, 'lancer')
|
||||
slot++
|
||||
}
|
||||
}
|
||||
return
|
||||
case TYPES.competence:
|
||||
case TYPES.competencecreature:
|
||||
const categorie = RdDItemCompetenceCreature.getCategorieAttaque(item) ?? 'competence';
|
||||
await this.createItemMacro(item, slot, categorie)
|
||||
return
|
||||
default:
|
||||
await this.createItemMacro(item, slot)
|
||||
case TYPES.competence:
|
||||
if (RdDItemCompetence.isCompetenceArme(item)) {
|
||||
ui.notifications.info(`La compétence de ${item.name} est une compétence d'arme, choisissez plutôt de créer la macro depuis l'onglet combat`);
|
||||
}
|
||||
await this.createItemMacro(item, slot, 'competence')
|
||||
return
|
||||
}
|
||||
}
|
||||
@ -51,14 +77,13 @@ export class RdDHotbar {
|
||||
*/
|
||||
static initDropbar() {
|
||||
|
||||
Hooks.on("hotbarDrop", (bar, documentData, slot) => {
|
||||
Hooks.on('hotbarDrop', (bar, documentData, slot) => {
|
||||
|
||||
// Create item macro if rollable item - weapon, spell, prayer, trait, or skill
|
||||
if (documentData.type == "Item") {
|
||||
if (documentData.type == 'Item') {
|
||||
const item = fromUuidSync(documentData.uuid) ?? this.actor.items.get(documentData.uuid)
|
||||
console.log("DROP", documentData, item)
|
||||
switch (item?.type ?? "")
|
||||
{
|
||||
console.log('DROP', documentData, item)
|
||||
switch (item?.type) {
|
||||
case TYPES.arme:
|
||||
case TYPES.competence:
|
||||
case TYPES.competencecreature:
|
||||
@ -72,7 +97,7 @@ export class RdDHotbar {
|
||||
}
|
||||
|
||||
/** Roll macro */
|
||||
static rollMacro(itemName, itemType, competenceName) {
|
||||
static rollMacro(itemName, itemType, categorieArme = 'competence') {
|
||||
const speaker = ChatMessage.getSpeaker();
|
||||
let actor;
|
||||
if (speaker.token) actor = game.actors.tokens[speaker.token];
|
||||
@ -88,10 +113,14 @@ export class RdDHotbar {
|
||||
// Trigger the item roll
|
||||
switch (item.type) {
|
||||
case TYPES.arme:
|
||||
return actor.rollArme(item, competenceName);
|
||||
return actor.rollArme(item, categorieArme);
|
||||
case TYPES.competence:
|
||||
return actor.rollCompetence(item);
|
||||
case TYPES.competencecreature:
|
||||
return actor.rollCompetence(itemName);
|
||||
return item.system.iscombat && !item.system.isparade
|
||||
? actor.rollArme(item, categorieArme)
|
||||
: actor.rollCompetence(item);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user