forked from public/foundryvtt-reve-de-dragon
Gestion de la périodicité/temporalité
This commit is contained in:
@ -152,17 +152,20 @@ export class RdDItem extends Item {
|
||||
isCompetenceCreature() { return this.type == 'competencecreature' }
|
||||
isConteneur() { return this.type == 'conteneur'; }
|
||||
isMonnaie() { return this.type == 'monnaie'; }
|
||||
isPotion() { return this.type == 'potion'; }
|
||||
isNourritureBoisson() { return this.type == 'nourritureboisson'; }
|
||||
isService() { return this.type == 'service'; }
|
||||
|
||||
isCompetence() { return typesObjetsCompetence.includes(this.type) }
|
||||
isTemporel() { return typesObjetsTemporels.includes(this.type) }
|
||||
|
||||
isOeuvre() { return typesObjetsOeuvres.includes(this.type) }
|
||||
isDraconique() { return typesObjetsDraconiques.includes(this.type) }
|
||||
isEffet() { return typesObjetsEffet.includes(this.type) }
|
||||
isConnaissance() { return typesObjetsConnaissance.includes(this.type) }
|
||||
|
||||
isInventaire(mode = 'materiel') { return RdDItem.getItemTypesInventaire(mode).includes(this.type); }
|
||||
isAlcool() { return this.isNourritureBoisson() && this.system.boisson && this.system.alcoolise; }
|
||||
isHerbeAPotion() { return this.type == 'herbe' && (this.system.categorie == 'Soin' || this.system.categorie == 'Repos'); }
|
||||
|
||||
getItemGroup() {
|
||||
if (this.isInventaire()) return "equipement";
|
||||
@ -174,16 +177,43 @@ export class RdDItem extends Item {
|
||||
return "autres";
|
||||
}
|
||||
|
||||
isConteneurNonVide() {
|
||||
return this.isConteneur() && (this.system.contenu?.length ?? 0) > 0;
|
||||
isConteneurNonVide() { return this.isConteneur() && (this.system.contenu?.length ?? 0) > 0; }
|
||||
isConteneurVide() { return this.isConteneur() && (this.system.contenu?.length ?? 0) == 0; }
|
||||
isVideOuNonConteneur() { return !this.isConteneur() || (this.system.contenu?.length ?? 0) == 0; }
|
||||
|
||||
isFinPeriode(oldTimestamp, newTimestamp) {
|
||||
if (!this.isTemporel()) {
|
||||
return false;
|
||||
}
|
||||
const finPeriode = new RdDTimestamp(this.system.temporel.fin);
|
||||
return oldTimestamp.compare(finPeriode) < 0 && finPeriode.compare(newTimestamp) <= 0
|
||||
}
|
||||
|
||||
isConteneurVide() {
|
||||
return this.isConteneur() && (this.system.contenu?.length ?? 0) == 0;
|
||||
async onCreateItemTemporel(actor) {
|
||||
if (this.isTemporel()) {
|
||||
const timestampDebut = game.system.rdd.calendrier.timestamp;
|
||||
const timestampFin = await this.calculerFinPeriodeTemporel(timestampDebut);
|
||||
await actor.updateEmbeddedDocuments('Item', [{
|
||||
_id: this.id,
|
||||
'system.temporel.debut': duplicate(timestampDebut),
|
||||
'system.temporel.fin': duplicate(timestampFin),
|
||||
}])
|
||||
}
|
||||
}
|
||||
|
||||
isVideOuNonConteneur() {
|
||||
return !this.isConteneur() || (this.system.contenu?.length ?? 0) == 0;
|
||||
async calculerFinPeriodeTemporel(timestampDebut) {
|
||||
return timestampDebut;
|
||||
}
|
||||
|
||||
async onFinPeriodeTemporel(oldTimestamp, newTimestamp) {
|
||||
if (this.isTemporel() && this.actor) {
|
||||
await this.onFinPeriode(oldTimestamp, newTimestamp);
|
||||
}
|
||||
}
|
||||
|
||||
async onFinPeriode(oldTimestamp, newTimestamp) {
|
||||
console.log(`${this.actor.name}: l'objet ${this.name} a expiré et été supprimé`);
|
||||
await this.actor?.deleteEmbeddedDocuments('Item', [this.id]);
|
||||
}
|
||||
|
||||
isComestible() {
|
||||
@ -197,16 +227,6 @@ export class RdDItem extends Item {
|
||||
return '';
|
||||
}
|
||||
|
||||
isAlcool() {
|
||||
return this.isNourritureBoisson() && this.system.boisson && this.system.alcoolise;
|
||||
}
|
||||
|
||||
isHerbeAPotion() {
|
||||
return this.type == 'herbe' && (this.system.categorie == 'Soin' || this.system.categorie == 'Repos');
|
||||
}
|
||||
isPotion() {
|
||||
return this.type == 'potion';
|
||||
}
|
||||
isCristalAlchimique() {
|
||||
return this.type == 'objet' && Grammar.toLowerCaseNoAccent(this.name) == 'cristal alchimique' && this.system.quantite > 0;
|
||||
}
|
||||
@ -215,6 +235,10 @@ export class RdDItem extends Item {
|
||||
return this.system.magique
|
||||
}
|
||||
|
||||
isItemCommerce() {
|
||||
return this.parent?.type == 'commerce';
|
||||
}
|
||||
|
||||
getQuantite() {
|
||||
return this.isService() ? undefined : Math.round(this.system.quantite ?? 0)
|
||||
}
|
||||
@ -252,10 +276,6 @@ export class RdDItem extends Item {
|
||||
return this.system.cout ?? 0
|
||||
}
|
||||
|
||||
isItemCommerce() {
|
||||
return this.parent?.type == 'commerce';
|
||||
}
|
||||
|
||||
calculerPrixCommercant() {
|
||||
if (this.isItemCommerce()) {
|
||||
// appliquer le pourcentage
|
||||
@ -376,40 +396,6 @@ export class RdDItem extends Item {
|
||||
await item.delete();
|
||||
}
|
||||
|
||||
async onCreateItemTemporel(actor) {
|
||||
if (this.isTemporel()) {
|
||||
const timestampDebut = game.system.rdd.calendrier.timestamp;
|
||||
const timestampFin = await this.calculerFinPeriodeTemporel(timestampDebut);
|
||||
await actor.updateEmbeddedDocuments('Item', [{
|
||||
_id: this.id,
|
||||
'system.temporel.debut': duplicate(timestampDebut),
|
||||
'system.temporel.fin': duplicate(timestampFin),
|
||||
}])
|
||||
}
|
||||
}
|
||||
|
||||
async calculerFinPeriodeTemporel(timestampDebut) {
|
||||
return timestampDebut;
|
||||
}
|
||||
|
||||
async prolongerPeriode() {
|
||||
if (this.actor) {
|
||||
const current = game.system.rdd.calendrier.timestamp;
|
||||
const finPeriode = new RdDTimestamp(this.system.temporel.fin)
|
||||
const periodeSuivante = (finPeriode.compare(current)>0 ? finPeriode : current);
|
||||
const timestampFin = await this.calculerFinPeriodeTemporel(periodeSuivante);
|
||||
|
||||
await this.actor.updateEmbeddedDocuments('Item', [{
|
||||
_id: this.id,
|
||||
'system.temporel.fin': duplicate(timestampFin),
|
||||
}])
|
||||
}
|
||||
}
|
||||
|
||||
async onFinTemporel() {
|
||||
await this.actor?.deleteEmbeddedDocuments('Item', [this.id]);
|
||||
}
|
||||
|
||||
async quantiteIncDec(nombre, options = { supprimerSiZero: false }) {
|
||||
const quantite = Number(this.system.quantite ?? -1);
|
||||
if (quantite >= 0) {
|
||||
|
Reference in New Issue
Block a user