On ne peut pas tout donner

Limitation des types d'objets pouvant être donnés à différents acteurs
This commit is contained in:
Vincent Vandemeulebrouck
2022-12-03 15:33:16 +01:00
parent eaac9564b4
commit b1e27a9597
10 changed files with 116 additions and 76 deletions

View File

@ -1,10 +1,9 @@
import { DialogItemVente } from "./dialog-item-vente.js";
import { Grammar } from "./grammar.js";
import { Monnaie } from "./item-monnaie.js";
import { RdDHerbes } from "./rdd-herbes.js";
import { RdDUtility } from "./rdd-utility.js";
const typesObjetsEquipement = [
const typesObjetsInventaire = [
"arme",
"armure",
"conteneur",
@ -70,7 +69,11 @@ export class RdDItem extends Item {
return defaultItemImg[itemType];
}
static isEquipementFieldEditable(type, field) {
static isItemInventaire(newLocal) {
return typesObjetsInventaire.includes(newLocal.type);
}
static isFieldInventaireModifiable(type, field) {
switch (field) {
case 'quantite':
if (['conteneur'].includes(type)) {
@ -78,8 +81,8 @@ export class RdDItem extends Item {
}
break;
case 'cout':
if(['monnaie'].includes(type)){
return game.user.isGM;
if (['monnaie'].includes(type)) {
return game.user.isGM;
}
break;
}
@ -98,12 +101,12 @@ export class RdDItem extends Item {
constructor(itemData, context) {
if (!itemData.img) {
itemData.img = RdDItem.getDefaultImg(itemData.type);
}
}
super(itemData, context);
}
}
static getTypesObjetsEquipement() {
return typesObjetsEquipement
static getItemTypesInventaire() {
return typesObjetsInventaire
}
static getTypesOeuvres() {
@ -113,11 +116,14 @@ export class RdDItem extends Item {
isCompetencePersonnage() {
return this.type == 'competence'
}
isCompetenceCreature() {
return this.type == 'competencecreature'
}
isCompetence() {
return typesObjetsCompetence.includes(this.type)
}
isEquipement() {
return typesObjetsEquipement.includes(this.type)
isInventaire() {
return RdDItem.isItemInventaire(this)
}
isOeuvre() {
return typesObjetsOeuvres.includes(this.type)
@ -136,7 +142,7 @@ export class RdDItem extends Item {
}
getItemGroup() {
if (this.isEquipement()) return "equipement";
if (this.isInventaire()) return "equipement";
if (this.isOeuvre()) return "oeuvre";
if (this.isDraconique()) return "draconique";
if (this.isConnaissance()) return "connaissance";
@ -180,7 +186,7 @@ export class RdDItem extends Item {
getEncTotal() {
return this.getEnc() * this.getQuantite();
}
}
getEnc() {
switch (this.type) {
@ -202,7 +208,7 @@ export class RdDItem extends Item {
prepareDerivedData() {
super.prepareDerivedData();
if (this.isEquipement()) {
if (this.isInventaire()) {
this.system.encTotal = this.getEncTotal();
if (this.isPotion()) {
this.prepareDataPotion()
@ -229,13 +235,13 @@ export class RdDItem extends Item {
case 'potion': return this._actionOrWarnQuantiteZero('Boire', warn);
case 'livre': return this._actionOrWarnQuantiteZero('Lire', warn);
case 'conteneur': return 'Ouvrir';
case 'herbe': return this.isHerbeAPotion() ? this._actionOrWarnQuantiteZero('Décoction', warn) : undefined;
case 'queue': case 'ombre': return this.system.refoulement>0 ? 'Refouler' : undefined;
case 'herbe': return this.isHerbeAPotion() ? this._actionOrWarnQuantiteZero('Décoction', warn) : undefined;
case 'queue': case 'ombre': return this.system.refoulement > 0 ? 'Refouler' : undefined;
}
return undefined;
}
_actionOrWarnQuantiteZero(actionName, warn){
_actionOrWarnQuantiteZero(actionName, warn) {
if ((this.system.quantite ?? 0) <= 0) {
if (warn) {
ui.notifications.warn(`Vous n'avez plus de ${this.name}.`);
@ -275,14 +281,14 @@ export class RdDItem extends Item {
/* -------------------------------------------- */
// détermine si deux équipements sont similaires: de même type, et avec les même champs hormis la quantité
isEquipementEmpilable(other) {
if (!other || !this.isEquipement()) {
isInventaireEmpilable(other) {
if (!other || !this.isInventaire()) {
return [false, undefined];
}
if (this.system.quantite == undefined) {
return [false, `Impossible de regrouper des ${this.type}, ils ne sont pas empilables`];
}
}
else if (this.type != other.type) {
return [false, `Impossible de regrouper des ${this.type} avec des ${other.type}`];
}
@ -309,7 +315,7 @@ export class RdDItem extends Item {
ui.notifications.warn(`Votre ${this.name} n'est pas vide, pas possible de le proposer`);
return;
}
await DialogItemVente.display(this, async (vente) => {
await DialogItemVente.display(this, async (vente) => {
vente["properties"] = this.getProprietes();
if (vente.isOwned) {
if (vente.quantiteNbLots * vente.tailleLot > vente.quantiteMax) {
@ -318,7 +324,7 @@ export class RdDItem extends Item {
}
}
vente.jsondata = JSON.stringify(vente.item);
console.log(vente);
let html = await renderTemplate('systems/foundryvtt-reve-de-dragon/templates/chat-vente-item.html', vente);
ChatMessage.create(RdDUtility.chatDataSetup(html));
@ -459,7 +465,7 @@ export class RdDItem extends Item {
`<b>Fatigue</b>: ${this.system.fatigue}`,
`<b>Difficulté</b>: ${this.system.difficulte}`
].concat([
this.system.cacher_points_de_tache ? [] :`<b>Points de Tâche</b>: ${this.system.points_de_tache}`
this.system.cacher_points_de_tache ? [] : `<b>Points de Tâche</b>: ${this.system.points_de_tache}`
]).concat([
`<b>Points de Tâche atteints</b>: ${this.system.points_de_tache_courant}`]
);
@ -563,10 +569,10 @@ export class RdDItem extends Item {
return [`<b>Inconnue</b>`]
}
let properties = [
`<b>Malignité</b>: ${this.system.malignite}`,
`<b>Périodicité</b>: ${this.system.periodicite}`,
`<b>Dommages</b>: ${this.system.dommages}`
]
`<b>Malignité</b>: ${this.system.malignite}`,
`<b>Périodicité</b>: ${this.system.periodicite}`,
`<b>Dommages</b>: ${this.system.dommages}`
]
if (this.system.remedesconnus) {
properties.push(`<b>Remedes</b>: ${this.system.remedes}`)
}