Enchantement des gemmes et potions
This commit is contained in:
@ -1,32 +1,18 @@
|
||||
import { ITEM_TYPES } from "../constants.js";
|
||||
import { Grammar } from "../grammar.js";
|
||||
import { RdDItem } from "../item.js";
|
||||
import { SystemCompendiums } from "../settings/system-compendiums.js";
|
||||
import { DialogEnchanter } from "./potion/dialog-enchanter.js";
|
||||
|
||||
const POTION_MAGIQUE = ['AlchimieEnchante', 'ReposEnchante', 'SoinEnchante', 'AutreEnchante']
|
||||
const POTION_ENCHANTABLE = ['Alchimie', 'Repos', 'Soin', 'Autre']
|
||||
.concat(POTION_MAGIQUE)
|
||||
|
||||
const MAP_CATEGORIE_ENCHANTEMENT = [
|
||||
{ basique: 'Alchimie', enchante: 'AlchimieEnchante' },
|
||||
{ basique: 'Repos', enchante: 'ReposEnchante' },
|
||||
{ basique: 'Soin', enchante: 'SoinEnchante' },
|
||||
{ basique: 'Autre', enchante: 'AutreEnchante' }]
|
||||
import { ACTION_ITEM_ENCHANTER } from "../enchantement/dialog-enchanter.js";
|
||||
|
||||
// --- Actions sur les "potions"
|
||||
const _CONSOMMER_POTION = {
|
||||
code: 'item-potion-consommer', label: 'Consommer', icon: it => 'fa-solid fa-vial',
|
||||
optionsFilter: options => options.editable,
|
||||
action: (item, actor) => actor.consommerPotion(item)
|
||||
}
|
||||
|
||||
const _ENCHANTER = {
|
||||
code: 'item-enchanter', label: 'Enchanter', icon: it => 'fa-solid fa-sparkles',
|
||||
filter: it => game.user.isGM || it.isEnchantable(),
|
||||
optionsFilter: options => options.editable,
|
||||
action: (item, actor) => item.enchanterPotion()
|
||||
}
|
||||
|
||||
/**
|
||||
* Item pour gérer les potions
|
||||
*/
|
||||
export class RdDItemPotion extends RdDItem {
|
||||
|
||||
static async herbesSoins() {
|
||||
@ -45,114 +31,67 @@ export class RdDItemPotion extends RdDItem {
|
||||
return "systems/foundryvtt-reve-de-dragon/icons/objets/liqueur_de_bagdol.webp"
|
||||
}
|
||||
|
||||
get isEnchantementPossible() {
|
||||
return this.system.etat == 'Liquide'
|
||||
}
|
||||
|
||||
itemSpecificActions() {
|
||||
return [_CONSOMMER_POTION, ACTION_ITEM_ENCHANTER]
|
||||
}
|
||||
|
||||
prepareDerivedData() {
|
||||
super.prepareDerivedData()
|
||||
this.system.puissance = this.system.magique ? this.calculPuissance() : 0
|
||||
}
|
||||
|
||||
isPotion() { return true }
|
||||
isEnchantable() { return POTION_ENCHANTABLE.includes(this.system.categorie) }
|
||||
isMagique() { return POTION_MAGIQUE.includes(this.system.categorie) }
|
||||
|
||||
itemSpecificActions() {
|
||||
return [_CONSOMMER_POTION, _ENCHANTER]
|
||||
}
|
||||
|
||||
getActions(options = { warnIfNot: true }) {
|
||||
const actionConsommer = this.prepareAction('Consommer', options.warnIfNot);
|
||||
if (this.isEnchantable()) {
|
||||
return [
|
||||
actionConsommer,
|
||||
this.prepareAction('Enchanter', options.warnIfNot)
|
||||
]
|
||||
}
|
||||
return [
|
||||
actionConsommer
|
||||
]
|
||||
}
|
||||
// TDOD: purifier?
|
||||
getUtilisation() {
|
||||
switch (this.system.categorie) {
|
||||
case 'Alchimie': case 'AlchimieEnchante':
|
||||
case 'AlchimieAutre':
|
||||
case 'Alchimie': case 'Autre': case 'AlchimieAutre':
|
||||
// TODO: distinguer les remèdes alchimiques enchantables/non
|
||||
return 'alchimie'
|
||||
case 'Cuisine': return 'cuisine'
|
||||
case 'Remede': case 'Repos': case 'ReposEnchante': case 'Soin': case 'SoinEnchante':
|
||||
case 'Cuisine':
|
||||
return 'cuisine'
|
||||
case 'Remede': case 'Repos': case 'Soin':
|
||||
return 'soins'
|
||||
}
|
||||
return ''
|
||||
}
|
||||
|
||||
_potionChatData() {
|
||||
return [
|
||||
`<b>Rareté</b>: ${this.system.rarete}`,
|
||||
getProprietes() {
|
||||
const proprietes = [
|
||||
`<b>Rareté</b>: ${this.system.rarete} `,
|
||||
`<b>Catégorie</b>: ${this.system.categorie}`,
|
||||
...this._inventaireTemplateChatData()
|
||||
`<b>Etat</b>: ${this.system.etat}`
|
||||
]
|
||||
const proprietesMagiques = this.system.magique ? [
|
||||
`<b>Enchantée</b> <i class="fa-solid fa-sparkles"></i> ${this.system.purifie ? ', purifiée' : ''} ${this.system.prpermanent ? 'permanente' : ''} `,
|
||||
`<b>Points de rêve</b>: ${this.system.pr}`,
|
||||
] : []
|
||||
return proprietes
|
||||
.concat(proprietesMagiques)
|
||||
.concat(this._inventaireTemplateChatData())
|
||||
.filter(it => it != undefined)
|
||||
}
|
||||
|
||||
async enchanterPotion() {
|
||||
const actor = this.parent;
|
||||
if (actor && (!actor.isPersonnage() || !actor.isHautRevant())) {
|
||||
ui.notifications.info('Seul un haut rêvant peut enchanter une potion')
|
||||
return
|
||||
}
|
||||
const dailog = await DialogEnchanter.create(this, actor, (updates) => this.$onEnchanterPotion(updates));
|
||||
dailog.render(true)
|
||||
}
|
||||
|
||||
perteRevePotion() {
|
||||
perteReveChateauDormant() {
|
||||
if (this.system.magique && !this.system.prpermanent && this.system.pr > 0) {
|
||||
const nouveauReve = Math.max(this.system.pr - 1, 0)
|
||||
const nouveaupr = Math.max(this.system.pr - 1, 0)
|
||||
return {
|
||||
_id: this.id,
|
||||
'system.pr': nouveauReve,
|
||||
'system.quantite': nouveauReve > 0 ? this.system.quantite : 0,
|
||||
'system.magique': nouveauReve > 0
|
||||
alias: this.parent.getAlias(),
|
||||
item: this,
|
||||
nouveaupr: nouveaupr,
|
||||
update: {
|
||||
_id: this.id,
|
||||
'system.pr': nouveaupr,
|
||||
'system.magique': nouveaupr > 0
|
||||
}
|
||||
}
|
||||
}
|
||||
return undefined
|
||||
}
|
||||
|
||||
async $onEnchanterPotion(enchanter) {
|
||||
if (enchanter.nouveaupr == 0) {
|
||||
await this.update({
|
||||
name: this.name, // TODO: enlever "enchantée" ?
|
||||
'system.pr': 0,
|
||||
'system.purifie': false,
|
||||
'system.magique': false,
|
||||
'system.categorie': this.categorieEnchantement().basique,
|
||||
'system.prpermanent': false,
|
||||
'system.prdate': 0,
|
||||
'system.quantite': this.parent ? 0 : this.system.quantite
|
||||
})
|
||||
}
|
||||
else {
|
||||
await this.update({
|
||||
name: this.name, // TODO: ajout "enchantée" ?
|
||||
'system.pr': enchanter.nouveaupr,
|
||||
'system.purifie': enchanter.purifier,
|
||||
'system.magique': true,
|
||||
'system.categorie': this.categorieEnchantement().enchante,
|
||||
'system.prpermanent': enchanter.prpermanent,
|
||||
'system.prdate': RdDItemPotion.dateEnchantement()
|
||||
})
|
||||
}
|
||||
this.sheet?.render(true)
|
||||
}
|
||||
|
||||
calculPuissance() { return this.system.herbebonus * this.system.pr }
|
||||
|
||||
categorieEnchantement() {
|
||||
const categorie = this.system.categorie
|
||||
const categorieEnchantement = MAP_CATEGORIE_ENCHANTEMENT.find(it => [it.basique, it.enchante].includes(categorie))
|
||||
return categorieEnchantement ?? { basique: categorie, enchante: categorie }
|
||||
}
|
||||
|
||||
static dateEnchantement() {
|
||||
return game.system.rdd.calendrier.getTimestamp().debutJournee().indexDate
|
||||
}
|
||||
|
||||
static buildHerbesList(listeHerbes, max) {
|
||||
let list = {}
|
||||
for (let herbe of listeHerbes) {
|
||||
|
Reference in New Issue
Block a user