2023-10-23 23:40:03 +02:00
|
|
|
import { RdDItemArme } from "./item-arme.js";
|
2023-10-23 22:04:45 +02:00
|
|
|
import { RdDItemCompetenceCreature } from "./item-competencecreature.js";
|
2023-10-18 21:08:01 +02:00
|
|
|
import { TYPES } from "./item.js";
|
2021-02-08 22:51:31 +01:00
|
|
|
|
|
|
|
export class RdDHotbar {
|
|
|
|
|
2023-10-04 09:33:24 +02:00
|
|
|
static async createItemMacro(item, slot, armeCompetence = undefined) {
|
2023-10-23 22:04:45 +02:00
|
|
|
const itemName = item.name;
|
2023-10-23 23:40:03 +02:00
|
|
|
let macroName = itemName + RdDHotbar.$macroNameSuffix(armeCompetence);
|
2023-10-23 22:04:45 +02:00
|
|
|
let command = `game.system.rdd.RdDHotbar.rollMacro("${itemName}", "${item.type}", "${armeCompetence}");`
|
|
|
|
let macro = game.macros.contents.find(m => (m.name === itemName) && (m.command === command));
|
2022-09-25 21:21:28 +02:00
|
|
|
if (!macro) {
|
|
|
|
macro = await Macro.create({
|
2023-10-23 22:04:45 +02:00
|
|
|
name: macroName,
|
2022-09-25 21:21:28 +02:00
|
|
|
type: "script",
|
|
|
|
img: item.img,
|
|
|
|
command: command
|
|
|
|
}, { displaySheet: false })
|
|
|
|
}
|
|
|
|
await game.user.assignHotbarMacro(macro, slot);
|
|
|
|
}
|
|
|
|
|
2023-10-23 23:40:03 +02:00
|
|
|
static $macroNameSuffix(armeCompetence) {
|
|
|
|
switch (armeCompetence) {
|
2023-10-23 22:04:45 +02:00
|
|
|
case 'unemain': return ' (1 main)';
|
2023-10-23 23:40:03 +02:00
|
|
|
case 'deuxmains': return ' (2 main)';
|
2023-10-23 22:04:45 +02:00
|
|
|
case 'tir': return ' (tir)';
|
|
|
|
case 'lancer': return ' (lancer)';
|
2023-10-23 23:40:03 +02:00
|
|
|
case 'pugilat': return ' (pugilat)';
|
|
|
|
case 'empoignade': return ' (empoignade)';
|
|
|
|
|
2023-10-23 22:04:45 +02:00
|
|
|
}
|
|
|
|
return ''
|
|
|
|
}
|
|
|
|
|
2023-10-04 09:33:24 +02:00
|
|
|
static async addToHotbar(item, slot) {
|
2023-10-23 22:04:45 +02:00
|
|
|
switch (item?.type ?? '') {
|
2023-10-18 21:08:01 +02:00
|
|
|
case TYPES.arme:
|
|
|
|
{
|
|
|
|
// Les armes peuvent avoir plusieurs usages
|
2023-10-23 22:04:45 +02:00
|
|
|
if (item.system.competence != '') {
|
|
|
|
if (item.system.unemain) {
|
2023-10-23 23:40:03 +02:00
|
|
|
await this.createItemMacro(item, slot++, 'unemain')
|
2023-10-23 22:04:45 +02:00
|
|
|
}
|
|
|
|
if (item.system.deuxmains) {
|
2023-10-23 23:40:03 +02:00
|
|
|
await this.createItemMacro(item, slot++, 'deuxmains')
|
2023-10-23 22:04:45 +02:00
|
|
|
}
|
2023-10-18 21:08:01 +02:00
|
|
|
}
|
2023-10-23 22:04:45 +02:00
|
|
|
if (item.system.lancer != '') {
|
2023-10-23 23:40:03 +02:00
|
|
|
await this.createItemMacro(item, slot++, 'lancer')
|
2023-10-18 21:08:01 +02:00
|
|
|
}
|
2023-10-23 22:04:45 +02:00
|
|
|
if (item.system.tir != '') {
|
2023-10-23 23:40:03 +02:00
|
|
|
await this.createItemMacro(item, slot++, 'lancer')
|
2023-10-18 21:08:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
case TYPES.competencecreature:
|
2023-10-23 22:04:45 +02:00
|
|
|
const categorie = RdDItemCompetenceCreature.getCategorieAttaque(item) ?? 'competence';
|
|
|
|
await this.createItemMacro(item, slot, categorie)
|
|
|
|
return
|
2023-10-18 21:08:01 +02:00
|
|
|
default:
|
2023-10-23 22:04:45 +02:00
|
|
|
case TYPES.competence:
|
2023-10-23 23:40:03 +02:00
|
|
|
await this.createItemMacro(item, slot++, 'competence')
|
|
|
|
if (item.isCorpsACorps()) {
|
|
|
|
await this.createItemMacro(item, slot++, 'pugilat')
|
|
|
|
await this.createItemMacro(item, slot++, 'empoignade')
|
|
|
|
}
|
|
|
|
if (item.isCompetenceArme()) {
|
|
|
|
ui.notifications.info(`${item.name} est une compétence d'arme, la macro n'est pas liée à un arme.<br>
|
|
|
|
Créez la macro depuis l'arme ou l'onglet combat pour garder les automatisations de combat.`);
|
2023-10-23 22:04:45 +02:00
|
|
|
}
|
2023-10-18 21:08:01 +02:00
|
|
|
return
|
2023-10-04 09:33:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-08 22:51:31 +01:00
|
|
|
/**
|
|
|
|
* Create a macro when dropping an entity on the hotbar
|
|
|
|
* Item - open roll dialog for item
|
|
|
|
* Actor - open actor sheet
|
|
|
|
* Journal - open journal sheet
|
|
|
|
*/
|
2022-09-07 09:14:42 +02:00
|
|
|
static initDropbar() {
|
2021-02-08 22:51:31 +01:00
|
|
|
|
2023-10-23 22:04:45 +02:00
|
|
|
Hooks.on('hotbarDrop', (bar, documentData, slot) => {
|
2022-09-06 23:52:21 +02:00
|
|
|
|
2022-09-07 09:14:42 +02:00
|
|
|
// Create item macro if rollable item - weapon, spell, prayer, trait, or skill
|
2023-10-23 22:04:45 +02:00
|
|
|
if (documentData.type == 'Item') {
|
2023-10-18 21:08:01 +02:00
|
|
|
const item = fromUuidSync(documentData.uuid) ?? this.actor.items.get(documentData.uuid)
|
2023-10-23 22:04:45 +02:00
|
|
|
console.log('DROP', documentData, item)
|
|
|
|
switch (item?.type) {
|
2023-10-18 21:08:01 +02:00
|
|
|
case TYPES.arme:
|
|
|
|
case TYPES.competence:
|
|
|
|
case TYPES.competencecreature:
|
|
|
|
this.addToHotbar(item, slot)
|
|
|
|
return false
|
2022-09-07 09:14:42 +02:00
|
|
|
}
|
2021-02-08 22:51:31 +01:00
|
|
|
}
|
2022-09-06 23:52:21 +02:00
|
|
|
|
2022-09-25 21:17:47 +02:00
|
|
|
return true
|
2022-09-25 21:21:28 +02:00
|
|
|
})
|
|
|
|
}
|
2021-02-08 22:51:31 +01:00
|
|
|
|
|
|
|
/** Roll macro */
|
2023-10-23 22:04:45 +02:00
|
|
|
static rollMacro(itemName, itemType, categorieArme = 'competence') {
|
2022-09-25 21:21:28 +02:00
|
|
|
const speaker = ChatMessage.getSpeaker();
|
|
|
|
let actor;
|
|
|
|
if (speaker.token) actor = game.actors.tokens[speaker.token];
|
|
|
|
if (!actor) actor = game.actors.get(speaker.actor);
|
2023-10-18 21:08:01 +02:00
|
|
|
if (!actor) {
|
|
|
|
return ui.notifications.warn(`Impossible de trouver le personnage concerné`);
|
|
|
|
}
|
2022-09-25 21:21:28 +02:00
|
|
|
let item = actor?.items.find(it => it.name === itemName && it.type == itemType) ?? undefined;
|
|
|
|
if (!item) {
|
|
|
|
return ui.notifications.warn(`Impossible de trouver l'objet de cette macro`);
|
|
|
|
}
|
2021-02-08 22:51:31 +01:00
|
|
|
|
2022-09-25 21:21:28 +02:00
|
|
|
// Trigger the item roll
|
|
|
|
switch (item.type) {
|
2023-10-18 21:08:01 +02:00
|
|
|
case TYPES.arme:
|
2023-10-23 22:04:45 +02:00
|
|
|
return actor.rollArme(item, categorieArme);
|
2023-10-18 21:08:01 +02:00
|
|
|
case TYPES.competence:
|
2023-10-23 23:40:03 +02:00
|
|
|
if (item.isCorpsACorps()) {
|
|
|
|
switch (categorieArme) {
|
|
|
|
case 'pugilat':
|
|
|
|
return actor.rollArme(RdDItemArme.mainsNues(actor), 'competence');
|
|
|
|
case 'empoignade':
|
|
|
|
return actor.rollArme(RdDItemArme.empoignade(actor), 'competence');
|
|
|
|
}
|
|
|
|
}
|
2023-10-23 22:04:45 +02:00
|
|
|
return actor.rollCompetence(item);
|
2023-10-18 21:08:01 +02:00
|
|
|
case TYPES.competencecreature:
|
2023-10-23 22:04:45 +02:00
|
|
|
return item.system.iscombat && !item.system.isparade
|
|
|
|
? actor.rollArme(item, categorieArme)
|
|
|
|
: actor.rollCompetence(item);
|
|
|
|
|
2022-09-25 21:21:28 +02:00
|
|
|
}
|
2021-02-08 22:51:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|