Simplification des actionPrincipales

Préparation pour supporter une liste d'actions sur les items
This commit is contained in:
2025-01-15 19:12:39 +01:00
parent 8ebd6ec771
commit 4281f76dfb
3 changed files with 113 additions and 89 deletions

View File

@ -1200,22 +1200,27 @@ export class RdDActor extends RdDBaseActorSang {
async actionPrincipale(item, onActionItem = async () => { }) {
let result = await super.actionPrincipale(item, onActionItem)
if (result) { return result }
result = await this.actionNourritureboisson(item, onActionItem)
if (result) { return result }
switch (item.type) {
case ITEM_TYPES.potion: return await this.consommerPotion(item, onActionItem);
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, onActionItem);
case ITEM_TYPES.queue: case ITEM_TYPES.ombre: return await this.actionRefoulement(item);
if (!result){
result = await this.actionNourritureboisson(item)
}
return undefined
if (!result){
result = await this.itemActionPrincipale(item)
}
await onActionItem()
return result
}
async actionNourritureboisson(item, onActionItem) {
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({
@ -1223,19 +1228,19 @@ export class RdDActor extends RdDBaseActorSang {
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, onActionItem) }
'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, onActionItem);
return await this.mangerNourriture(item);
}
return undefined;
}
async mangerNourriture(item, onActionItem) {
return (await DialogConsommer.create(this, item, onActionItem)).render(true);
async mangerNourriture(item) {
return (await DialogConsommer.create(this, item)).render(true);
}
async actionLire(item) {
@ -2829,6 +2834,59 @@ 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;
@ -2890,77 +2948,22 @@ export class RdDActor extends RdDBaseActorSang {
}
/* -------------------------------------------- */
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 });
async consommerPotionGenerique(potion) {
potion.alias = this.name;
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) {
if (potion.system.magique) {
// Gestion de la résistance:
potionData.rolled = await RdDResolutionTable.roll(this.getReveActuel(), -8);
if (potionData.rolled.isEchec) {
potion.rolled = await RdDResolutionTable.roll(this.getReveActuel(), -8);
if (potion.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`, potionData)
content: await renderTemplate(`systems/foundryvtt-reve-de-dragon/templates/chat-consommer-potion-generique.html`, potion)
});
}
/* -------------------------------------------- */
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