12.0.36 - L'alchimie d'Astrobazzarh #740

Merged
uberwald merged 16 commits from VincentVk/foundryvtt-reve-de-dragon:v11 into v11 2025-01-19 09:50:20 +01:00
3 changed files with 113 additions and 89 deletions
Showing only changes of commit 4281f76dfb - Show all commits

View File

@ -1200,22 +1200,27 @@ export class RdDActor extends RdDBaseActorSang {
async actionPrincipale(item, onActionItem = async () => { }) { async actionPrincipale(item, onActionItem = async () => { }) {
let result = await super.actionPrincipale(item, onActionItem) let result = await super.actionPrincipale(item, onActionItem)
if (result) { return result } if (!result){
result = await this.actionNourritureboisson(item)
result = await this.actionNourritureboisson(item, onActionItem) }
if (result) { return result } if (!result){
result = await this.itemActionPrincipale(item)
}
await onActionItem()
return result
}
async itemActionPrincipale(item) {
switch (item.type) { switch (item.type) {
case ITEM_TYPES.potion: return await this.consommerPotion(item, onActionItem); case ITEM_TYPES.potion: return await this.consommerPotion(item);
case ITEM_TYPES.livre: return await this.actionLire(item); case ITEM_TYPES.livre: return await this.actionLire(item);
case ITEM_TYPES.conteneur: return await item.sheet.render(true); case ITEM_TYPES.conteneur: return await item.sheet.render(true);
case ITEM_TYPES.herbe: return await this.actionHerbe(item, onActionItem); case ITEM_TYPES.herbe: return await this.actionHerbe(item);
case ITEM_TYPES.queue: case ITEM_TYPES.ombre: return await this.actionRefoulement(item); case ITEM_TYPES.queue: case ITEM_TYPES.ombre: return await this.actionRefoulement(item);
} }
return undefined
} }
async actionNourritureboisson(item, onActionItem) { async actionNourritureboisson(item) {
switch (item.getUtilisationCuisine()) { switch (item.getUtilisationCuisine()) {
case 'brut': { case 'brut': {
const utilisation = new Dialog({ const utilisation = new Dialog({
@ -1223,19 +1228,19 @@ export class RdDActor extends RdDBaseActorSang {
content: `Que faire de votre ${item.name}`, content: `Que faire de votre ${item.name}`,
buttons: { buttons: {
'cuisiner': { icon: '<i class="fa-solid fa-utensils"></i>', label: 'Cuisiner', callback: async () => await this.preparerNourriture(item) }, '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); return utilisation.render(true);
} }
case 'pret': case 'pret':
return await this.mangerNourriture(item, onActionItem); return await this.mangerNourriture(item);
} }
return undefined; return undefined;
} }
async mangerNourriture(item, onActionItem) { async mangerNourriture(item) {
return (await DialogConsommer.create(this, item, onActionItem)).render(true); return (await DialogConsommer.create(this, item)).render(true);
} }
async actionLire(item) { async actionLire(item) {
@ -2829,6 +2834,59 @@ export class RdDActor extends RdDBaseActorSang {
return guerisonData; 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) { async consommerPotionSoin(potionData) {
potionData.alias = this.name; potionData.alias = this.name;
@ -2890,77 +2948,22 @@ export class RdDActor extends RdDBaseActorSang {
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
async fabriquerPotion(herbeData) { async consommerPotionGenerique(potion) {
let newPotion = { potion.alias = this.name;
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 });
let newQuantite = herbeData.system.quantite - herbeData.nbBrins; if (potion.system.magique) {
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: // Gestion de la résistance:
potionData.rolled = await RdDResolutionTable.roll(this.getReveActuel(), -8); potion.rolled = await RdDResolutionTable.roll(this.getReveActuel(), -8);
if (potionData.rolled.isEchec) { if (potion.rolled.isEchec) {
await this.reveActuelIncDec(-1); await this.reveActuelIncDec(-1);
} }
} }
ChatMessage.create({ ChatMessage.create({
whisper: ChatUtility.getOwners(this), 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) { async onUpdateActor(update, options, actorId) {
const updatedEndurance = update?.system?.sante?.endurance const updatedEndurance = update?.system?.sante?.endurance

View File

@ -192,7 +192,6 @@ export class RdDItemSheet extends ItemSheet {
}) })
this.html.find('.creer-tache-livre').click((event) => this._getEventActor(event).creerTacheDepuisLivre(this.item)); this.html.find('.creer-tache-livre').click((event) => this._getEventActor(event).creerTacheDepuisLivre(this.item));
this.html.find('.consommer-potion').click((event) => this._getEventActor(event).consommerPotion(this.item, this.getActionRenderItem()));
this.html.find('.creer-potion-base').click((event) => this._getEventActor(event).actionHerbe(this.item)); this.html.find('.creer-potion-base').click((event) => this._getEventActor(event).actionHerbe(this.item));
this.html.find('input[name="system.cacher_points_de_tache"]').change(async event => await this.item.update({ 'system.cacher_points_de_tache': event.currentTarget.checked })); this.html.find('input[name="system.cacher_points_de_tache"]').change(async event => await this.item.update({ 'system.cacher_points_de_tache': event.currentTarget.checked }));
@ -200,12 +199,13 @@ export class RdDItemSheet extends ItemSheet {
this.html.find('.chat-roll-text').click(async event => await RdDTextEditor.chatRollText(event)) this.html.find('.chat-roll-text').click(async event => await RdDTextEditor.chatRollText(event))
if (this.actor) { if (this.actor) {
this.html.find('.item-split').click(async event => RdDSheetUtility.splitItem(RdDSheetUtility.getItem(event, this.actor), this.actor, this.getActionRenderItem())); this.html.find('.consommer-potion').click(event => this.itemActionConsommer(event))
this.html.find('.item-action').click(event => this.itemAction(event))
this.html.find('.item-split').click( event => this.itemActionSplit(event))
this.html.find('.item-edit').click(async event => RdDSheetUtility.getItem(event, this.actor)?.sheet.render(true)); this.html.find('.item-edit').click(async event => RdDSheetUtility.getItem(event, this.actor)?.sheet.render(true));
this.html.find('.item-delete').click(async event => RdDUtility.confirmActorItemDelete(this, RdDSheetUtility.getItem(event, this.actor))); this.html.find('.item-delete').click(async event => RdDUtility.confirmActorItemDelete(this, RdDSheetUtility.getItem(event, this.actor)));
this.html.find('.item-vendre').click(async event => RdDSheetUtility.getItem(event, this.actor)?.proposerVente()); this.html.find('.item-vendre').click(async event => RdDSheetUtility.getItem(event, this.actor)?.proposerVente());
this.html.find('.item-montrer').click(async event => RdDSheetUtility.getItem(event, this.actor)?.postItemToChat()); this.html.find('.item-montrer').click(async event => RdDSheetUtility.getItem(event, this.actor)?.postItemToChat());
this.html.find('.item-action').click(async event => RdDSheetUtility.getItem(event, this.actor)?.actionPrincipale(this.actor, this.getActionRenderItem()));
this.html.find('.item-quantite-plus').click(async event => { this.html.find('.item-quantite-plus').click(async event => {
await this.actor.itemQuantiteIncDec(RdDSheetUtility.getItemId(event), 1) await this.actor.itemQuantiteIncDec(RdDSheetUtility.getItemId(event), 1)
@ -223,14 +223,28 @@ export class RdDItemSheet extends ItemSheet {
RdDTimestamp.handleTimestampEditor(this.html, 'system.temporel.fin', updateItemTimestamp); RdDTimestamp.handleTimestampEditor(this.html, 'system.temporel.fin', updateItemTimestamp);
} }
getActionRenderItem() { async itemActionConsommer(event) {
return async () => { const item = RdDSheetUtility.getItem(event, this.actor)
let item = this.item; if (item) {
while (item) { await actor.consommerPotion(item)
await item.sheet?.render() await RdDSheetUtility.renderItemBranch(this.actor, item)
item = this.actor.getContenant(item)
} }
} }
async itemActionSplit(event) {
const item = RdDSheetUtility.getItem(event, this.actor)
if (item) {
await RdDSheetUtility.splitItem(item, this.actor)
await RdDSheetUtility.renderItemBranch(this.actor, item)
}
}
async itemAction(event) {
const item = RdDSheetUtility.getItem(event, this.actor);
if (item) {
await item.actionPrincipale(this.actor)
await RdDSheetUtility.renderItemBranch(this.actor, item)
}
} }
_getEventActor(event) { _getEventActor(event) {

View File

@ -70,7 +70,7 @@ export class RdDSheetUtility {
await RdDSheetUtility._onSplitItem(item, split, actor); await RdDSheetUtility._onSplitItem(item, split, actor);
onSplit(); onSplit();
}); });
dialog.render(true); dialog.render(true)
} }
static async _onSplitItem(item, split, actor) { static async _onSplitItem(item, split, actor) {
@ -82,4 +82,11 @@ export class RdDSheetUtility {
await actor.createEmbeddedDocuments('Item', [splitItem]) await actor.createEmbeddedDocuments('Item', [splitItem])
} }
} }
static async renderItemBranch(actor, item) {
while (item) {
await item.sheet?.render()
item = actor.getContenant(item)
}
}
} }