Gestion des actions sur les items

- dans la liste d'équipement, liste d'actions fournie par code
- support d'actions multiples
- listener générique

Utilisation du mécanisme pour tous les items, standardisation de
l'apparence des boutons d'items
This commit is contained in:
2025-01-15 19:13:32 +01:00
parent ce7f5381ca
commit 9fc21e6d97
60 changed files with 560 additions and 601 deletions

View File

@ -167,8 +167,7 @@ export class RdDActor extends RdDBaseActorSang {
/* -------------------------------------------- */
async $perteRevePotionsEnchantees() {
const potionUpdates = this.itemTypes[ITEM_TYPES.potion].map(
it.perteRevePotion())
const potionUpdates = this.itemTypes[ITEM_TYPES.potion].map(it => it.perteRevePotion())
.filter(it => it != undefined)
if (potionUpdates.length > 0) {
console.log('perte rêve de potions', potionUpdates)
@ -987,13 +986,10 @@ export class RdDActor extends RdDBaseActorSang {
}
}
async addSortReserve(itemId) {
if (itemId) {
const item = this.items.get(itemId)
if (item.type == ITEM_TYPES.sort && !item.system.isrituel) {
this.$createSortReserve(item)
return
}
async addSortReserve(item) {
if (item?.type == ITEM_TYPES.sort && !item.system.isrituel) {
this.$createSortReserve(item)
return
}
const selectSortReserve = {
title: "Créer un sort en réserve",
@ -1197,49 +1193,8 @@ export class RdDActor extends RdDBaseActorSang {
new RdDRollDialogEthylisme(html, rollData, this, r => this.saouler(r.forceAlcool)).render(true);
}
async actionPrincipale(item, onActionItem = async () => { }) {
let result = await super.actionPrincipale(item, onActionItem)
if (!result){
result = await this.actionNourritureboisson(item)
}
if (!result){
result = await this.itemActionPrincipale(item)
}
await onActionItem()
return result
}
async itemActionPrincipale(item) {
switch (item.type) {
case ITEM_TYPES.potion: return await this.consommerPotion(item);
case ITEM_TYPES.livre: return await this.actionLire(item);
case ITEM_TYPES.conteneur: return await item.sheet.render(true);
case ITEM_TYPES.herbe: return await this.actionHerbe(item);
case ITEM_TYPES.queue: case ITEM_TYPES.ombre: return await this.actionRefoulement(item);
}
}
async actionNourritureboisson(item) {
switch (item.getUtilisationCuisine()) {
case 'brut': {
const utilisation = new Dialog({
title: "Nourriture brute",
content: `Que faire de votre ${item.name}`,
buttons: {
'cuisiner': { icon: '<i class="fa-solid fa-utensils"></i>', label: 'Cuisiner', callback: async () => await this.preparerNourriture(item) },
'manger': { icon: '<i class="fa-solid fa-drumstick-bite"></i>', label: 'Manger cru', callback: async () => await this.mangerNourriture(item) }
}
});
return utilisation.render(true);
}
case 'pret':
return await this.mangerNourriture(item);
}
return undefined;
}
async mangerNourriture(item) {
return (await DialogConsommer.create(this, item)).render(true);
async mangerNourriture(item, onActionItem) {
return (await DialogConsommer.create(this, item, onActionItem)).render(true);
}
async actionLire(item) {
@ -2569,8 +2524,7 @@ export class RdDActor extends RdDBaseActorSang {
}
/* -------------------------------------------- */
async equiperObjet(itemID) {
let item = this.getEmbeddedDocument('Item', itemID);
async equiperObjet(item) {
if (item?.isEquipable()) {
const isEquipe = !item.system.equipe;
await item.update({ "system.equipe": isEquipe });
@ -2833,59 +2787,6 @@ export class RdDActor extends RdDBaseActorSang {
return guerisonData;
}
/* -------------------------------------------- */
async fabriquerPotion(herbeData) {
let newPotion = {
name: `Potion de ${herbeData.system.categorie} (${herbeData.name})`, type: 'potion',
img: "systems/foundryvtt-reve-de-dragon/icons/objets/fiole_verre.webp",
system: {
quantite: 1, cout: 0, encombrement: 0.1,
categorie: herbeData.system.categorie,
herbe: herbeData.name,
rarete: herbeData.system.rarete,
herbebrins: herbeData.nbBrins,
herbebonus: herbeData.herbebonus,
description: ""
}
}
await this.createEmbeddedDocuments('Item', [newPotion]);
let newQuantite = herbeData.system.quantite - herbeData.nbBrins;
let messageData = {
alias: this.getAlias(),
nbBrinsReste: newQuantite,
potion: newPotion,
herbe: herbeData
}
this.diminuerQuantiteObjet(herbeData._id, herbeData.nbBrins);
ChatMessage.create({
whisper: ChatUtility.getOwners(this),
content: await renderTemplate(`systems/foundryvtt-reve-de-dragon/templates/chat-fabriquer-potion-base.html`, messageData)
});
}
/* -------------------------------------------- */
async diminuerQuantiteObjet(id, nb, options = { supprimerSiZero: false }) {
const item = this.getItem(id);
if (item) {
await item.diminuerQuantite(nb, options);
}
}
/* -------------------------------------------- */
async consommerPotion(potion) {
if (potion.system.categorie.includes('Soin')) {
await this.consommerPotionSoin(potion);
} else if (potion.system.categorie.includes('Repos')) {
await this.consommerPotionRepos(potion);
} else {
await this.consommerPotionGenerique(potion);
}
await this.diminuerQuantiteObjet(potion.id, 1, { supprimerSiZero: potion.supprimer });
}
/* -------------------------------------------- */
async consommerPotionSoin(potionData) {
potionData.alias = this.name;
@ -2947,22 +2848,77 @@ export class RdDActor extends RdDBaseActorSang {
}
/* -------------------------------------------- */
async consommerPotionGenerique(potion) {
potion.alias = this.name;
async fabriquerPotion(herbeData) {
let newPotion = {
name: `Potion de ${herbeData.system.categorie} (${herbeData.name})`, type: 'potion',
img: "systems/foundryvtt-reve-de-dragon/icons/objets/fiole_verre.webp",
system: {
quantite: 1, cout: 0, encombrement: 0.1,
categorie: herbeData.system.categorie,
herbe: herbeData.name,
rarete: herbeData.system.rarete,
herbebrins: herbeData.nbBrins,
herbebonus: herbeData.herbebonus,
description: ""
}
}
await this.createEmbeddedDocuments('Item', [newPotion], { renderSheet: true });
if (potion.system.magique) {
let newQuantite = herbeData.system.quantite - herbeData.nbBrins;
let messageData = {
alias: this.getAlias(),
nbBrinsReste: newQuantite,
potion: newPotion,
herbe: herbeData
}
this.diminuerQuantiteObjet(herbeData._id, herbeData.nbBrins);
ChatMessage.create({
whisper: ChatUtility.getOwners(this),
content: await renderTemplate(`systems/foundryvtt-reve-de-dragon/templates/chat-fabriquer-potion-base.html`, messageData)
});
}
/* -------------------------------------------- */
async diminuerQuantiteObjet(id, nb, options = { supprimerSiZero: false }) {
const item = this.getItem(id);
if (item) {
await item.diminuerQuantite(nb, options);
}
}
/* -------------------------------------------- */
async consommerPotionGenerique(potionData) {
potionData.alias = this.name;
if (potionData.system.magique) {
// Gestion de la résistance:
potion.rolled = await RdDResolutionTable.roll(this.getReveActuel(), -8);
if (potion.rolled.isEchec) {
potionData.rolled = await RdDResolutionTable.roll(this.getReveActuel(), -8);
if (potionData.rolled.isEchec) {
await this.reveActuelIncDec(-1);
}
}
ChatMessage.create({
whisper: ChatUtility.getOwners(this),
content: await renderTemplate(`systems/foundryvtt-reve-de-dragon/templates/chat-consommer-potion-generique.html`, potion)
content: await renderTemplate(`systems/foundryvtt-reve-de-dragon/templates/chat-consommer-potion-generique.html`, potionData)
});
}
/* -------------------------------------------- */
async consommerPotion(potion, onActionItem = async () => { }) {
const potionData = potion
if (potionData.system.categorie.includes('Soin')) {
this.consommerPotionSoin(potionData);
} else if (potionData.system.categorie.includes('Repos')) {
this.consommerPotionRepos(potionData);
} else {
this.consommerPotionGenerique(potionData);
}
await this.diminuerQuantiteObjet(potion.id, 1, { supprimerSiZero: potionData.supprimer });
await onActionItem()
}
/* -------------------------------------------- */
async onUpdateActor(update, options, actorId) {
const updatedEndurance = update?.system?.sante?.endurance