forked from public/foundryvtt-reve-de-dragon
Séparation de l'Actor Entités
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
import { ChatUtility } from "../chat-utility.js";
|
||||
import { SYSTEM_SOCKET_ID } from "../constants.js";
|
||||
import { Grammar } from "../grammar.js";
|
||||
import { Monnaie } from "../item-monnaie.js";
|
||||
import { Misc } from "../misc.js";
|
||||
import { RdDAudio } from "../rdd-audio.js";
|
||||
@ -9,6 +10,33 @@ import { SystemCompendiums } from "../settings/system-compendiums.js";
|
||||
import { APP_ASTROLOGIE_REFRESH } from "../sommeil/app-astrologie.js";
|
||||
|
||||
export class RdDBaseActor extends Actor {
|
||||
/* -------------------------------------------- */
|
||||
static _findCaracByName(carac, name) {
|
||||
name = Grammar.toLowerCaseNoAccent(name);
|
||||
switch (name) {
|
||||
case 'reve-actuel': case 'reve actuel':
|
||||
return carac.reve;
|
||||
case 'chance-actuelle': case 'chance actuelle':
|
||||
return carac.chance;
|
||||
}
|
||||
|
||||
const caracList = Object.entries(carac);
|
||||
let entry = Misc.findFirstLike(name, caracList, { mapper: it => it[0], description: 'caractéristique' });
|
||||
if (!entry || entry.length == 0) {
|
||||
entry = Misc.findFirstLike(name, caracList, { mapper: it => it[1].label, description: 'caractéristique' });
|
||||
}
|
||||
return entry && entry.length > 0 ? carac[entry[0]] : undefined;
|
||||
}
|
||||
|
||||
getCaracByName(name) {
|
||||
switch (Grammar.toLowerCaseNoAccent(name)) {
|
||||
case 'reve-actuel': case 'reve actuel':
|
||||
return this.getCaracReveActuel();
|
||||
case 'chance-actuelle': case 'chance-actuelle':
|
||||
return this.getCaracChanceActuelle();
|
||||
}
|
||||
return RdDBaseActor._findCaracByName(this.system.carac, name);
|
||||
}
|
||||
|
||||
static getDefaultImg(itemType) {
|
||||
return game.system.rdd.actorClasses[itemType]?.defaultIcon ?? defaultItemImg[itemType];
|
||||
@ -124,11 +152,24 @@ export class RdDBaseActor extends Actor {
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
prepareData() {
|
||||
super.prepareData()
|
||||
this.prepareActorData()
|
||||
this.cleanupConteneurs()
|
||||
this.computeEtatGeneral()
|
||||
this.computeEncTotal()
|
||||
}
|
||||
|
||||
async prepareActorData() { }
|
||||
async computeEtatGeneral() { }
|
||||
/* -------------------------------------------- */
|
||||
|
||||
isCreatureEntite() { return this.type == 'creature' || this.type == 'entite'; }
|
||||
isCreature() { return this.type == 'creature'; }
|
||||
isEntite() { return this.type == 'entite'; }
|
||||
isEntite(typeentite = []) { return false }
|
||||
isPersonnage() { return this.type == 'personnage'; }
|
||||
isVehicule() { return this.type == 'vehicule'; }
|
||||
|
||||
getItem(id, type = undefined) {
|
||||
const item = this.items.get(id);
|
||||
if (type == undefined || (item?.type == type)) {
|
||||
@ -145,12 +186,7 @@ export class RdDBaseActor extends Actor {
|
||||
}
|
||||
|
||||
getMonnaie(id) { return this.findItemLike(id, 'monnaie'); }
|
||||
getReveActuel() { return 0 }
|
||||
computeMalusSurEncombrement() { return 0 }
|
||||
getEncombrementMax() { return 0 }
|
||||
recompute() { }
|
||||
async setEffect(statusId, status) { }
|
||||
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async onPreUpdateItem(item, change, options, id) { }
|
||||
@ -179,6 +215,16 @@ export class RdDBaseActor extends Actor {
|
||||
await this.createEmbeddedDocuments('Item', [object])
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async cleanupConteneurs() {
|
||||
let updates = this.itemTypes['conteneur']
|
||||
.filter(c => c.system.contenu.filter(id => this.getItem(id) == undefined).length > 0)
|
||||
.map(c => { return { _id: c._id, 'system.contenu': c.system.contenu.filter(id => this.getItem(id) != undefined) } });
|
||||
if (updates.length > 0) {
|
||||
await this.updateEmbeddedDocuments("Item", updates)
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
getFortune() {
|
||||
return Monnaie.getFortune(this.itemTypes['monnaie']);
|
||||
@ -399,6 +445,10 @@ export class RdDBaseActor extends Actor {
|
||||
return 0;
|
||||
}
|
||||
|
||||
getEncTotal() {
|
||||
return Math.floor(this.encTotal ?? 0);
|
||||
}
|
||||
|
||||
async createItem(type, name = undefined) {
|
||||
if (!name) {
|
||||
name = 'Nouveau ' + Misc.typeName('Item', type);
|
||||
@ -627,5 +677,12 @@ export class RdDBaseActor extends Actor {
|
||||
.then(html => ChatMessage.create(RdDUtility.chatDataSetup(html, modeOverride)));
|
||||
}
|
||||
|
||||
actionImpossible(action) {
|
||||
ui.notifications.info(`${this.name} ne peut pas faire cette action: ${action}`)
|
||||
|
||||
}
|
||||
async roll() { this.actionImpossible("jet de caractéristiques") }
|
||||
async jetEthylisme() { this.actionImpossible("jet d'éthylisme") }
|
||||
async rollAppelChance() { this.actionImpossible("appel à la chance") }
|
||||
async jetDeMoral() { this.actionImpossible("jet de moral") }
|
||||
}
|
Reference in New Issue
Block a user