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 = {}) {
|
getCompetence(idOrName, options = {}) {
|
||||||
|
if (idOrName instanceof Item) {
|
||||||
|
return idOrName.isCompetence() ? idOrName : undefined
|
||||||
|
}
|
||||||
return RdDItemCompetence.findCompetence(this.items, idOrName, options)
|
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} !`);
|
ui.notifications.info(`Aucun sort disponible en ${TMRUtility.getTMR(coord).label} !`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const draconicList = this.computeDraconicAndSortIndex(sorts);
|
const draconicList = this.computeDraconicAndSortIndex(sorts);
|
||||||
const reve = duplicate(this.system.carac.reve);
|
const reve = duplicate(this.system.carac.reve);
|
||||||
@ -3073,24 +3076,35 @@ export class RdDActor extends RdDBaseActor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------------------------------- */
|
/* -------------------------------------------- */
|
||||||
getArmeCompetence(arme, competenceName) {
|
getCompetenceArme(arme, competenceName) {
|
||||||
let comp = arme.system[competenceName]
|
switch (arme.type) {
|
||||||
if (!comp || comp.name == "") {
|
case TYPES.competencecreature:
|
||||||
comp = arme.system[competenceName]
|
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 == "") {
|
return undefined
|
||||||
comp = arme.system[competenceName]
|
|
||||||
}
|
|
||||||
return comp
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------------------------------- */
|
/* -------------------------------------------- */
|
||||||
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()) {
|
if (!Targets.hasTargets()) {
|
||||||
RdDConfirm.confirmer({
|
RdDConfirm.confirmer({
|
||||||
settingConfirmer: "confirmer-combat-sans-cible",
|
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
|
<br>Tous les jets de combats devront être gérés à la main
|
||||||
</p>`,
|
</p>`,
|
||||||
title: 'Ne pas utiliser les automatisation de combat',
|
title: 'Ne pas utiliser les automatisation de combat',
|
||||||
|
@ -157,6 +157,13 @@ export class RdDItemArme extends Item {
|
|||||||
}
|
}
|
||||||
return armeData;
|
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) {
|
static isArmeUtilisable(arme) {
|
||||||
return arme.type == 'arme' && arme.system.equipe && (arme.system.resistance > 0 || arme.system.portee_courte > 0);
|
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) {
|
static corpsACorps(mainsNuesActor) {
|
||||||
const corpsACorps = {
|
const corpsACorps = {
|
||||||
name: 'Corps à corps',
|
name: 'Corps à corps',
|
||||||
|
type: 'arme',
|
||||||
img: 'systems/foundryvtt-reve-de-dragon/icons/competence_corps_a_corps.webp',
|
img: 'systems/foundryvtt-reve-de-dragon/icons/competence_corps_a_corps.webp',
|
||||||
system: {
|
system: {
|
||||||
equipe: true,
|
equipe: true,
|
||||||
@ -181,6 +189,7 @@ export class RdDItemArme extends Item {
|
|||||||
dommagesReels: 0,
|
dommagesReels: 0,
|
||||||
mortalite: 'non-mortel',
|
mortalite: 'non-mortel',
|
||||||
competence: 'Corps à corps',
|
competence: 'Corps à corps',
|
||||||
|
deuxmains: true,
|
||||||
categorie_parade: 'sans-armes'
|
categorie_parade: 'sans-armes'
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -195,7 +204,7 @@ export class RdDItemArme extends Item {
|
|||||||
mainsNues.system.baseInit = 4
|
mainsNues.system.baseInit = 4
|
||||||
return mainsNues;
|
return mainsNues;
|
||||||
}
|
}
|
||||||
|
|
||||||
static empoignade(mainsNuesActor) {
|
static empoignade(mainsNuesActor) {
|
||||||
const empoignade = RdDItemArme.corpsACorps(mainsNuesActor)
|
const empoignade = RdDItemArme.corpsACorps(mainsNuesActor)
|
||||||
empoignade.name = 'Empoignade'
|
empoignade.name = 'Empoignade'
|
||||||
|
@ -171,8 +171,7 @@ export class RdDCombatManager extends Combat {
|
|||||||
if (arme.system.unemain && arme.system.deuxmains && !dommages.includes("/")) {
|
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)");
|
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) ||
|
if (arme.system.unemain && arme.system.competence) {
|
||||||
(arme.system.competence.toLowerCase().includes("corps à corps"))) {
|
|
||||||
actions.push(RdDCombatManager.$prepareAttaqueArme({
|
actions.push(RdDCombatManager.$prepareAttaqueArme({
|
||||||
arme: arme,
|
arme: arme,
|
||||||
infoMain: "(1 main)",
|
infoMain: "(1 main)",
|
||||||
@ -187,7 +186,7 @@ export class RdDCombatManager extends Combat {
|
|||||||
arme: arme,
|
arme: arme,
|
||||||
infoMain: "(2 mains)",
|
infoMain: "(2 mains)",
|
||||||
dommagesReel: Number(tableauDommages[1]),
|
dommagesReel: Number(tableauDommages[1]),
|
||||||
competence: arme.system.competence.replace(" 1 main", " 2 mains"),
|
competence: RdDItemArme.competence2Mains(arme),
|
||||||
carac: carac,
|
carac: carac,
|
||||||
competences: competences
|
competences: competences
|
||||||
}));
|
}));
|
||||||
|
@ -1,13 +1,17 @@
|
|||||||
|
import { RdDItemCompetence } from "./item-competence.js";
|
||||||
|
import { RdDItemCompetenceCreature } from "./item-competencecreature.js";
|
||||||
import { TYPES } from "./item.js";
|
import { TYPES } from "./item.js";
|
||||||
|
|
||||||
export class RdDHotbar {
|
export class RdDHotbar {
|
||||||
|
|
||||||
static async createItemMacro(item, slot, armeCompetence = undefined) {
|
static async createItemMacro(item, slot, armeCompetence = undefined) {
|
||||||
let command = `game.system.rdd.RdDHotbar.rollMacro("${item.name}", "${item.type}"` + ((armeCompetence) ? `, "${armeCompetence}");` : `);`);
|
const itemName = item.name;
|
||||||
let macro = game.macros.contents.find(m => (m.name === item.name) && (m.command === command));
|
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) {
|
if (!macro) {
|
||||||
macro = await Macro.create({
|
macro = await Macro.create({
|
||||||
name: item.name,
|
name: macroName,
|
||||||
type: "script",
|
type: "script",
|
||||||
img: item.img,
|
img: item.img,
|
||||||
command: command
|
command: command
|
||||||
@ -16,29 +20,51 @@ export class RdDHotbar {
|
|||||||
await game.user.assignHotbarMacro(macro, slot);
|
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) {
|
static async addToHotbar(item, slot) {
|
||||||
switch (item?.type ?? "") {
|
switch (item?.type ?? '') {
|
||||||
case TYPES.arme:
|
case TYPES.arme:
|
||||||
{
|
{
|
||||||
// Les armes peuvent avoir plusieurs usages
|
// Les armes peuvent avoir plusieurs usages
|
||||||
if (item.system.competence != "") {
|
if (item.system.competence != '') {
|
||||||
await this.createItemMacro(item, slot, "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++
|
slot++
|
||||||
}
|
}
|
||||||
if (item.system.lancer != "") {
|
if (item.system.tir != '') {
|
||||||
await this.createItemMacro(item, slot, "lancer")
|
await this.createItemMacro(item, slot, 'lancer')
|
||||||
slot++
|
|
||||||
}
|
|
||||||
if (item.system.tir != "") {
|
|
||||||
await this.createItemMacro(item, slot, "lancer")
|
|
||||||
slot++
|
slot++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
case TYPES.competence:
|
|
||||||
case TYPES.competencecreature:
|
case TYPES.competencecreature:
|
||||||
|
const categorie = RdDItemCompetenceCreature.getCategorieAttaque(item) ?? 'competence';
|
||||||
|
await this.createItemMacro(item, slot, categorie)
|
||||||
|
return
|
||||||
default:
|
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
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -51,14 +77,13 @@ export class RdDHotbar {
|
|||||||
*/
|
*/
|
||||||
static initDropbar() {
|
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
|
// 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)
|
const item = fromUuidSync(documentData.uuid) ?? this.actor.items.get(documentData.uuid)
|
||||||
console.log("DROP", documentData, item)
|
console.log('DROP', documentData, item)
|
||||||
switch (item?.type ?? "")
|
switch (item?.type) {
|
||||||
{
|
|
||||||
case TYPES.arme:
|
case TYPES.arme:
|
||||||
case TYPES.competence:
|
case TYPES.competence:
|
||||||
case TYPES.competencecreature:
|
case TYPES.competencecreature:
|
||||||
@ -72,7 +97,7 @@ export class RdDHotbar {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Roll macro */
|
/** Roll macro */
|
||||||
static rollMacro(itemName, itemType, competenceName) {
|
static rollMacro(itemName, itemType, categorieArme = 'competence') {
|
||||||
const speaker = ChatMessage.getSpeaker();
|
const speaker = ChatMessage.getSpeaker();
|
||||||
let actor;
|
let actor;
|
||||||
if (speaker.token) actor = game.actors.tokens[speaker.token];
|
if (speaker.token) actor = game.actors.tokens[speaker.token];
|
||||||
@ -88,10 +113,14 @@ export class RdDHotbar {
|
|||||||
// Trigger the item roll
|
// Trigger the item roll
|
||||||
switch (item.type) {
|
switch (item.type) {
|
||||||
case TYPES.arme:
|
case TYPES.arme:
|
||||||
return actor.rollArme(item, competenceName);
|
return actor.rollArme(item, categorieArme);
|
||||||
case TYPES.competence:
|
case TYPES.competence:
|
||||||
|
return actor.rollCompetence(item);
|
||||||
case TYPES.competencecreature:
|
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