Support de plusieurs actors

This commit is contained in:
Vincent Vandemeulebrouck 2022-12-28 23:36:48 +01:00
parent 6adeb790a0
commit 2062ff0777
11 changed files with 518 additions and 334 deletions

View File

@ -40,11 +40,4 @@ export class RdDActorCreatureSheet extends RdDActorSheet {
this.actor.updateCreatureCompetence(compName, "dommages", parseInt(event.target.value)); this.actor.updateCreatureCompetence(compName, "dommages", parseInt(event.target.value));
}); });
} }
/* -------------------------------------------- */
/** @override */
_updateObject(event, formData) {
// Update the Actor
return this.object.update(formData);
}
} }

View File

@ -12,13 +12,15 @@ import { RdDSheetUtility } from "./rdd-sheet-utility.js";
import { STATUSES } from "./settings/status-effects.js"; import { STATUSES } from "./settings/status-effects.js";
import { Monnaie } from "./item-monnaie.js"; import { Monnaie } from "./item-monnaie.js";
import { MAINS_DIRECTRICES } from "./actor.js"; import { MAINS_DIRECTRICES } from "./actor.js";
import { RdDBaseActorSheet } from "./actor/base-actor-sheet.js";
import { RdDItem } from "./item.js";
/* -------------------------------------------- */ /* -------------------------------------------- */
/** /**
* Extend the basic ActorSheet with some very simple modifications * Extend the basic ActorSheet with some very simple modifications
* @extends {ActorSheet} * @extends {ActorSheet}
*/ */
export class RdDActorSheet extends ActorSheet { export class RdDActorSheet extends RdDBaseActorSheet {
/** @override */ /** @override */
static get defaultOptions() { static get defaultOptions() {
@ -36,42 +38,28 @@ export class RdDActorSheet extends ActorSheet {
/* -------------------------------------------- */ /* -------------------------------------------- */
async getData() { async getData() {
this.timerRecherche = undefined; let formData = await super.getData();
this.actor.computeEtatGeneral(); mergeObject(formData,
{
let formData = {
title: this.title,
id: this.actor.id,
type: this.actor.type,
img: this.actor.img,
name: this.actor.name,
editable: this.isEditable, editable: this.isEditable,
cssClass: this.isEditable ? "editable" : "locked", cssClass: this.isEditable ? "editable" : "locked",
system: foundry.utils.deepClone(this.actor.system),
effects: this.actor.effects.map(e => foundry.utils.deepClone(e)), effects: this.actor.effects.map(e => foundry.utils.deepClone(e)),
limited: this.actor.limited, limited: this.actor.limited,
options: this.options,
owner: this.actor.isOwner, owner: this.actor.isOwner,
description: await TextEditor.enrichHTML(this.object.system.description, { async: true }), description: await TextEditor.enrichHTML(this.object.system.description, { async: true }),
biographie: await TextEditor.enrichHTML(this.object.system.biographie, { async: true }), biographie: await TextEditor.enrichHTML(this.object.system.biographie, { async: true }),
notes: await TextEditor.enrichHTML(this.object.system.notes, { async: true }), notes: await TextEditor.enrichHTML(this.object.system.notes, { async: true }),
notesmj: await TextEditor.enrichHTML(this.object.system.notesmj, { async: true }), notesmj: await TextEditor.enrichHTML(this.object.system.notesmj, { async: true }),
calc: { });
fortune: Monnaie.getFortuneSolsDeniers(this.actor), mergeObject(formData.calc, {
encTotal: await this.actor.computeEncombrementTotalEtMalusArmure(),
surenc: this.actor.computeMalusSurEncombrement(), surenc: this.actor.computeMalusSurEncombrement(),
prixTotalEquipement: this.actor.computePrixTotalEquipement(),
surprise: RdDBonus.find(this.actor.getSurprise(false)).descr, surprise: RdDBonus.find(this.actor.getSurprise(false)).descr,
resumeBlessures: this.actor.computeResumeBlessure(this.actor.system.blessures), resumeBlessures: this.actor.computeResumeBlessure(this.actor.system.blessures),
caracTotal: RdDCarac.computeTotal(this.actor.system.carac, this.actor.system.beaute), caracTotal: RdDCarac.computeTotal(this.actor.system.carac, this.actor.system.beaute),
surEncombrementMessage: this.actor.getMessageSurEncombrement(), surEncombrementMessage: this.actor.getMessageSurEncombrement(),
}, })
}
formData.options.isGM = game.user.isGM;
RdDUtility.filterItemsPerTypeForSheet(formData, this.actor.itemTypes); this.timerRecherche = undefined;
this.objetVersConteneur = RdDUtility.buildArbreDeConteneurs(formData.conteneurs, formData.objets);
formData.conteneurs = RdDUtility.conteneursRacine(formData.conteneurs);
if (formData.type == 'personnage') { if (formData.type == 'personnage') {
formData.options.mainsDirectrices = MAINS_DIRECTRICES; formData.options.mainsDirectrices = MAINS_DIRECTRICES;
@ -125,22 +113,14 @@ export class RdDActorSheet extends ActorSheet {
/* -------------------------------------------- */ /** @override */ /* -------------------------------------------- */ /** @override */
activateListeners(html) { activateListeners(html) {
super.activateListeners(html); super.activateListeners(html);
this.html = html;
HtmlUtility._showControlWhen(this.html.find(".appliquerFatigue"), ReglesOptionelles.isUsing("appliquer-fatigue")); HtmlUtility._showControlWhen(this.html.find(".appliquerFatigue"), ReglesOptionelles.isUsing("appliquer-fatigue"));
// Everything below here is only needed if the sheet is editable // Everything below here is only needed if the sheet is editable
if (!this.options.editable) return; if (!this.options.editable) return;
this.html.find('.item-split').click(async event => {
const item = RdDSheetUtility.getItem(event, this.actor);
RdDSheetUtility.splitItem(item, this.actor);
});
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-vendre').click(async event => RdDSheetUtility.getItem(event, this.actor)?.proposerVente());
this.html.find('.item-montrer').click(async event => RdDSheetUtility.getItem(event, this.actor)?.postItem());
this.html.find('.item-action').click(async event => RdDSheetUtility.getItem(event, this.actor)?.actionPrincipale(this.actor)); this.html.find('.item-action').click(async event => RdDSheetUtility.getItem(event, this.actor)?.actionPrincipale(this.actor));
this.html.find('.subacteur-delete').click(async event => { this.html.find('.subacteur-delete').click(async event => {
const li = RdDSheetUtility.getEventElement(event); const li = RdDSheetUtility.getEventElement(event);
const actorId = li.data("actor-id"); const actorId = li.data("actor-id");
@ -174,14 +154,8 @@ export class RdDActorSheet extends ActorSheet {
this.html.find('.creer-tache').click(async event => { this.html.find('.creer-tache').click(async event => {
this.createEmptyTache(); this.createEmptyTache();
}); });
this.html.find('.creer-un-objet').click(async event => {
RdDUtility.selectObjetType(this);
});
this.html.find('.creer-une-oeuvre').click(async event => { this.html.find('.creer-une-oeuvre').click(async event => {
RdDUtility.selectTypeOeuvre(this); this.selectTypeOeuvreToCreate();
});
this.html.find('.nettoyer-conteneurs').click(async event => {
this.actor.nettoyerConteneurs();
}); });
// Blessure control // Blessure control
@ -325,10 +299,6 @@ export class RdDActorSheet extends ActorSheet {
await this.actor.removeEffects(); await this.actor.removeEffects();
} }
}); });
this.html.find('.conteneur-name a').click(async event => {
RdDUtility.toggleAfficheContenu(RdDSheetUtility.getItemId(event));
this.render(true);
});
this.html.find('.carac-xp-augmenter').click(async event => { this.html.find('.carac-xp-augmenter').click(async event => {
let caracName = event.currentTarget.name.replace("augmenter.", ""); let caracName = event.currentTarget.name.replace("augmenter.", "");
this.actor.updateCaracXPAuto(caracName); this.actor.updateCaracXPAuto(caracName);
@ -418,19 +388,12 @@ export class RdDActorSheet extends ActorSheet {
this.actor.setPointsDeSeuil(event.currentTarget.value); this.actor.setPointsDeSeuil(event.currentTarget.value);
}); });
this.html.find('#attribut-protection-edit').change(async event => {
this.actor.updateAttributeValue(event.currentTarget.attributes.name.value, parseInt(event.target.value));
});
// On stress change // On stress change
this.html.find('.compteur-edit').change(async event => { this.html.find('.compteur-edit').change(async event => {
let fieldName = event.currentTarget.attributes.name.value; let fieldName = event.currentTarget.attributes.name.value;
this.actor.updateCompteurValue(fieldName, parseInt(event.target.value)); this.actor.updateCompteurValue(fieldName, parseInt(event.target.value));
}); });
this.html.find('#ethylisme').change(async event => {
this.actor.setEthylisme(parseInt(event.target.value));
});
this.html.find('.stress-test').click(async event => { this.html.find('.stress-test').click(async event => {
this.actor.transformerStress(); this.actor.transformerStress();
}); });
@ -454,13 +417,6 @@ export class RdDActorSheet extends ActorSheet {
this.actor.jetEndurance(); this.actor.jetEndurance();
}); });
this.html.find('.monnaie-plus').click(async event => {
this.actor.monnaieIncDec(RdDSheetUtility.getItemId(event), 1);
});
this.html.find('.monnaie-moins').click(async event => {
this.actor.monnaieIncDec(RdDSheetUtility.getItemId(event), -1);
});
this.html.find('.vie-plus').click(async event => { this.html.find('.vie-plus').click(async event => {
this.actor.santeIncDec("vie", 1); this.actor.santeIncDec("vie", 1);
}); });
@ -499,25 +455,30 @@ export class RdDActorSheet extends ActorSheet {
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
async _onDropItem(event, dragData) { async selectTypeOeuvreToCreate() {
const destItemId = this.html.find(event.target)?.closest('.item').attr('data-item-id') let typeObjets = RdDItem.getTypesOeuvres();
const dropParams = RdDSheetUtility.prepareItemDropParameters(destItemId, this.actor, dragData, this.objetVersConteneur) let content = `<span class="competence-label">Selectionnez le type d'oeuvre</span><select class="item-type">`;
if (dropParams) { for (let typeName of typeObjets) {
const callSuper = await this.actor.processDropItem(dropParams) content += `<option value="${typeName}">${Misc.typeName('Item', typeName)}</option>`
if (callSuper) { }
await super._onDropItem(event, dragData) content += '</select>';
let dialog = new Dialog({
title: "Créer une oeuvre",
content: content,
buttons: {
create: {
icon: '<i class="fas fa-check"></i>',
label: "Créer l'oeuvre",
callback: () => this.actor.createItem($(".item-type").val())
} }
} }
} });
dialog.render(true);
/* -------------------------------------------- */
async createItem(name, type) {
await this.actor.createEmbeddedDocuments('Item', [{ name: name, type: type }], { renderSheet: true });
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
async createEmptyTache() { async createEmptyTache() {
await this.createItem('Nouvelle tache', 'tache'); await this.actor.createItem('tache', 'Nouvelle tache');
} }
_optionRecherche(target) { _optionRecherche(target) {

View File

@ -34,9 +34,9 @@ import { ENTITE_BLURETTE, ENTITE_INCARNE, ENTITE_NONINCARNE, HIDE_DICE, SHOW_DIC
import { RdDConfirm } from "./rdd-confirm.js"; import { RdDConfirm } from "./rdd-confirm.js";
import { DialogValidationEncaissement } from "./dialog-validation-encaissement.js"; import { DialogValidationEncaissement } from "./dialog-validation-encaissement.js";
import { RdDRencontre } from "./item-rencontre.js"; import { RdDRencontre } from "./item-rencontre.js";
import { SystemCompendiums } from "./settings/system-compendiums.js";
import { Targets } from "./targets.js"; import { Targets } from "./targets.js";
import { DialogRepos } from "./dialog-repos.js"; import { DialogRepos } from "./dialog-repos.js";
import { RdDBaseActor } from "./actor/base-actor.js";
const POSSESSION_SANS_DRACONIC = { const POSSESSION_SANS_DRACONIC = {
img: 'systems/foundryvtt-reve-de-dragon/icons/entites/possession.webp', img: 'systems/foundryvtt-reve-de-dragon/icons/entites/possession.webp',
@ -56,88 +56,7 @@ export const MAINS_DIRECTRICES = ['Droitier', 'Gaucher', 'Ambidextre']
* Extend the base Actor entity by defining a custom roll data structure which is ideal for the Simple system. * Extend the base Actor entity by defining a custom roll data structure which is ideal for the Simple system.
* @extends {Actor} * @extends {Actor}
*/ */
export class RdDActor extends Actor { export class RdDActor extends RdDBaseActor {
/* -------------------------------------------- */
static init() {
Hooks.on("preUpdateItem", (item, change, options, id) => RdDActor.getParentActor(item)?.onPreUpdateItem(item, change, options, id));
// TODO: replace with pre-hooks?
Hooks.on("createItem", (item, options, id) => RdDActor.getParentActor(item)?.onCreateItem(item, options, id));
Hooks.on("deleteItem", (item, options, id) => RdDActor.getParentActor(item)?.onDeleteItem(item, options, id));
Hooks.on("updateActor", (actor, change, options, actorId) => actor.onUpdateActor(change, options, actorId));
}
static onSocketMessage(sockmsg) {
switch (sockmsg.msg) {
case "msg_remote_actor_call":
return RdDActor.onRemoteActorCall(sockmsg.data, sockmsg.userId);
case "msg_reset_nombre_astral":
console.log("RESET ASTRAL", game.user.character);
game.user.character.resetNombreAstral();
return;
}
}
static remoteActorCall(callData, userId = undefined) {
userId = userId ?? Misc.firstConnectedGMId();
if (userId == game.user.id) {
RdDActor.onRemoteActorCall(callData, userId);
return false;
}
else {
game.socket.emit(SYSTEM_SOCKET_ID, { msg: "msg_remote_actor_call", data: callData, userId: userId });
return true;
}
}
static onRemoteActorCall(callData, userId) {
if (userId == game.user.id) {
const actor = game.actors.get(callData?.actorId);
if (Misc.isOwnerPlayerOrUniqueConnectedGM(actor)) { // Seul le joueur choisi effectue l'appel: le joueur courant si propriétaire de l'actor, ou le MJ sinon
const args = callData.args;
console.info(`RdDActor.onRemoteActorCall: pour l'Actor ${callData.actorId}, appel de RdDActor.${callData.method}(`, ...args, ')');
actor[callData.method](...args);
}
}
}
/* -------------------------------------------- */
static getParentActor(document) {
return document?.parent instanceof Actor ? document.parent : undefined
}
/* -------------------------------------------- */
/**
* Override the create() function to provide additional RdD functionality.
*
* This overrided create() function adds initial items
* Namely: Basic skills, money,
*
* @param {Object} actorData Barebones actor template data which this function adds onto.
* @param {Object} options Additional options which customize the creation workflow.
*
*/
static async create(actorData, options) {
// Case of compendium global import
if (actorData instanceof Array) {
return super.create(actorData, options);
}
const isPersonnage = actorData.type == "personnage";
// If the created actor has items (only applicable to duplicated actors) bypass the new actor creation logic
if (actorData.items) {
return await super.create(actorData, options);
}
if (isPersonnage) {
const competences = await SystemCompendiums.getCompetences(actorData.type);
actorData.items = competences.map(i => i.toObject())
.concat(Monnaie.monnaiesStandard());
}
else {
actorData.items = [];
}
return super.create(actorData, options);
}
/* -------------------------------------------- */ /* -------------------------------------------- */
prepareData() { prepareData() {
@ -145,6 +64,8 @@ export class RdDActor extends Actor {
// Dynamic computing fields // Dynamic computing fields
this.encTotal = 0; this.encTotal = 0;
// TODO: separate derived/base data preparation
// TODO: split by actor class
// Make separate methods for each Actor type (character, npc, etc.) to keep // Make separate methods for each Actor type (character, npc, etc.) to keep
// things organized. // things organized.
@ -178,9 +99,9 @@ export class RdDActor extends Actor {
/* -------------------------------------------- */ /* -------------------------------------------- */
async cleanupConteneurs() { async cleanupConteneurs() {
let updates = this.listItemsData('conteneur') let updates = this.listItems('conteneur')
.filter(c => c.system.contenu.filter(id => this.getObjet(id) == undefined).length > 0) .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.getObjet(id) != undefined) } }); .map(c => { return { _id: c._id, 'system.contenu': c.system.contenu.filter(id => this.getItem(id) != undefined) } });
if (updates.length > 0) { if (updates.length > 0) {
await this.updateEmbeddedDocuments("Item", updates) await this.updateEmbeddedDocuments("Item", updates)
} }
@ -206,23 +127,6 @@ export class RdDActor extends Actor {
return false; return false;
} }
/* -------------------------------------------- */
isCreatureEntite() {
return this.type == 'creature' || this.type == 'entite';
}
isCreature() {
return this.type == 'creature';
}
isEntite() {
return this.type == 'entite';
}
/* -------------------------------------------- */
isPersonnage() {
return this.type == 'personnage';
}
isVehicule() {
return this.type == 'vehicule';
}
/* -------------------------------------------- */ /* -------------------------------------------- */
isHautRevant() { isHautRevant() {
return this.isPersonnage() && this.system.attributs.hautrevant.value != "" return this.isPersonnage() && this.system.attributs.hautrevant.value != ""
@ -330,50 +234,33 @@ export class RdDActor extends Actor {
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
getObjet(id) {
return this.getEmbeddedDocument('Item', id);
}
listItemsData(type) {
return this.itemTypes[type];
}
filterItems(filter) {
return this.items.filter(filter);
}
getItemOfType(idOrName, type) {
return this.items.find(it => it.id == idOrName && it.type == type)
?? Misc.findFirstLike(idOrName, this.items, { filter: it => it.type == type, description: type });
}
getMonnaie(id) { getMonnaie(id) {
return this.getItemOfType(id, 'monnaie'); return this.findItemLike(id, 'monnaie');
} }
getTache(id) { getTache(id) {
return this.getItemOfType(id, 'tache'); return this.findItemLike(id, 'tache');
} }
getMeditation(id) { getMeditation(id) {
return this.getItemOfType(id, 'meditation'); return this.findItemLike(id, 'meditation');
} }
getChant(id) { getChant(id) {
return this.getItemOfType(id, 'chant'); return this.findItemLike(id, 'chant');
} }
getDanse(id) { getDanse(id) {
return this.getItemOfType(id, 'danse'); return this.findItemLike(id, 'danse');
} }
getMusique(id) { getMusique(id) {
return this.getItemOfType(id, 'musique'); return this.findItemLike(id, 'musique');
} }
getOeuvre(id, type = 'oeuvre') { getOeuvre(id, type = 'oeuvre') {
return this.getItemOfType(id, type); return this.findItemLike(id, type);
} }
getJeu(id) { getJeu(id) {
return this.getItemOfType(id, 'jeu'); return this.findItemLike(id, 'jeu');
} }
getRecetteCuisine(id) { getRecetteCuisine(id) {
return this.getItemOfType(id, 'recettecuisine'); return this.findItemLike(id, 'recettecuisine');
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
getDraconicList() { getDraconicList() {
@ -476,6 +363,7 @@ export class RdDActor extends Actor {
); );
dialog.render(true); dialog.render(true);
} }
async repos() { async repos() {
await DialogRepos.create(this); await DialogRepos.create(this);
} }
@ -1109,7 +997,7 @@ export class RdDActor extends Actor {
_isConteneurContenu(item, conteneur) { _isConteneurContenu(item, conteneur) {
if (item?.isConteneur()) { // Si c'est un conteneur, il faut vérifier qu'on ne le déplace pas vers un sous-conteneur lui appartenant if (item?.isConteneur()) { // Si c'est un conteneur, il faut vérifier qu'on ne le déplace pas vers un sous-conteneur lui appartenant
for (let id of item.system.contenu) { for (let id of item.system.contenu) {
let subObjet = this.getObjet(id); let subObjet = this.getItem(id);
if (subObjet?.id == conteneur.id) { if (subObjet?.id == conteneur.id) {
return true; // Loop detected ! return true; // Loop detected !
} }
@ -1130,17 +1018,17 @@ export class RdDActor extends Actor {
if (objet.type != 'conteneur') { if (objet.type != 'conteneur') {
return Number(tplData.encombrement) * Number(tplData.quantite); return Number(tplData.encombrement) * Number(tplData.quantite);
} }
const encContenus = tplData.contenu.map(idContenu => this.getRecursiveEnc(this.getObjet(idContenu))); const encContenus = tplData.contenu.map(idContenu => this.getRecursiveEnc(this.getItem(idContenu)));
return encContenus.reduce(Misc.sum(), 0) return encContenus.reduce(Misc.sum(), 0)
+ Number(tplData.encombrement) /* TODO? Number(tplData.quantite) -- on pourrait avoir plusieurs conteneurs...*/ + Number(tplData.encombrement) /* TODO? Number(tplData.quantite) -- on pourrait avoir plusieurs conteneurs...*/
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
buildSubConteneurObjetList(conteneurId, deleteList) { buildSubConteneurObjetList(conteneurId, deleteList) {
let conteneur = this.getObjet(conteneurId); let conteneur = this.getItem(conteneurId);
if (conteneur?.type == 'conteneur') { // Si c'est un conteneur if (conteneur?.type == 'conteneur') { // Si c'est un conteneur
for (let subId of conteneur.system.contenu) { for (let subId of conteneur.system.contenu) {
let subObj = this.getObjet(subId); let subObj = this.getItem(subId);
if (subObj) { if (subObj) {
if (subObj.type == 'conteneur') { if (subObj.type == 'conteneur') {
this.buildSubConteneurObjetList(subId, deleteList); this.buildSubConteneurObjetList(subId, deleteList);
@ -1228,12 +1116,12 @@ export class RdDActor extends Actor {
return false; return false;
} }
let result = true; let result = true;
const item = this.getObjet(itemId); const item = this.getItem(itemId);
if (item?.isInventaire() && sourceActorId == targetActorId) { if (item?.isInventaire() && sourceActorId == targetActorId) {
// rangement // rangement
if (srcId != destId && itemId != destId) { // déplacement de l'objet if (srcId != destId && itemId != destId) { // déplacement de l'objet
const src = this.getObjet(srcId); const src = this.getItem(srcId);
const dest = this.getObjet(destId); const dest = this.getItem(destId);
const cible = this.getContenantOrParent(dest); const cible = this.getContenantOrParent(dest);
const [empilable, message] = item.isInventaireEmpilable(dest); const [empilable, message] = item.isInventaireEmpilable(dest);
if (empilable) { if (empilable) {
@ -1303,7 +1191,7 @@ export class RdDActor extends Actor {
itemsList.push({ id: itemId, conteneurId: undefined }); // Init list itemsList.push({ id: itemId, conteneurId: undefined }); // Init list
sourceActor.buildSubConteneurObjetList(itemId, itemsList); // Get itemId list sourceActor.buildSubConteneurObjetList(itemId, itemsList); // Get itemId list
const itemsDataToCreate = itemsList.map(it => sourceActor.getObjet(it.id)) const itemsDataToCreate = itemsList.map(it => sourceActor.getItem(it.id))
.map(it => duplicate(it)) .map(it => duplicate(it))
.map(it => { it.system.contenu = []; return it; }); .map(it => { it.system.contenu = []; return it; });
let newItems = await this.createEmbeddedDocuments('Item', itemsDataToCreate); let newItems = await this.createEmbeddedDocuments('Item', itemsDataToCreate);
@ -1314,7 +1202,7 @@ export class RdDActor extends Actor {
// gestion conteneur/contenu // gestion conteneur/contenu
if (item.conteneurId) { // l'Objet était dans un conteneur if (item.conteneurId) { // l'Objet était dans un conteneur
let newConteneurId = itemMap[item.conteneurId]; // Get conteneur let newConteneurId = itemMap[item.conteneurId]; // Get conteneur
let newConteneur = this.getObjet(newConteneurId); let newConteneur = this.getItem(newConteneurId);
let newItemId = itemMap[item.id]; // Get newItem let newItemId = itemMap[item.id]; // Get newItem
@ -1377,7 +1265,7 @@ export class RdDActor extends Actor {
hasItemNamed(type, name) { hasItemNamed(type, name) {
name = Grammar.toLowerCaseNoAccent(name); name = Grammar.toLowerCaseNoAccent(name);
return this.listItemsData(type).find(it => Grammar.toLowerCaseNoAccent(it.name) == name); return this.listItems(type).find(it => Grammar.toLowerCaseNoAccent(it.name) == name);
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
@ -1444,6 +1332,10 @@ export class RdDActor extends Actor {
} }
} }
recompute(){
this.computeEtatGeneral();
}
/* -------------------------------------------- */ /* -------------------------------------------- */
computeEtatGeneral() { computeEtatGeneral() {
// Pas d'état général pour les entités forçage à 0 // Pas d'état général pour les entités forçage à 0
@ -2027,7 +1919,7 @@ export class RdDActor extends Actor {
/* -------------------------------------------- */ /* -------------------------------------------- */
async consommerNourritureboisson(itemId, choix = { doses: 1, seForcer: false, supprimerSiZero: false }, userId = undefined) { async consommerNourritureboisson(itemId, choix = { doses: 1, seForcer: false, supprimerSiZero: false }, userId = undefined) {
if (userId != undefined && userId != game.user.id) { if (userId != undefined && userId != game.user.id) {
RdDActor.remoteActorCall({ RdDBaseActor.remoteActorCall({
actorId: this.id, actorId: this.id,
method: 'consommerNourritureboisson', method: 'consommerNourritureboisson',
args: [itemId, choix, userId] args: [itemId, choix, userId]
@ -2035,7 +1927,7 @@ export class RdDActor extends Actor {
userId) userId)
return; return;
} }
const item = this.getObjet(itemId) const item = this.getItem(itemId)
if (!item.isComestible()) { if (!item.isComestible()) {
return; return;
} }
@ -2792,7 +2684,7 @@ export class RdDActor extends Actor {
/* -------------------------------------------- */ /* -------------------------------------------- */
async rollDanse(id) { async rollDanse(id) {
const artData = { art: 'danse', verbe: 'Danser', forceCarac: {} }; const artData = { art: 'danse', verbe: 'Danser', forceCarac: {} };
const oeuvre = duplicate(this.getItemOfType(id, artData.art)); const oeuvre = duplicate(this.findItemLike(id, artData.art));
if (oeuvre.system.agilite) { if (oeuvre.system.agilite) {
artData.forceCarac['agilite'] = duplicate(this.system.carac.agilite); artData.forceCarac['agilite'] = duplicate(this.system.carac.agilite);
} }
@ -2814,7 +2706,7 @@ export class RdDActor extends Actor {
/* -------------------------------------------- */ /* -------------------------------------------- */
async rollMusique(id) { async rollMusique(id) {
const artData = { art: 'musique', verbe: 'Jouer' }; const artData = { art: 'musique', verbe: 'Jouer' };
const oeuvre = this.getItemOfType(id, artData.art); const oeuvre = this.findItemLike(id, artData.art);
await this._rollArt(artData, "ouie", oeuvre); await this._rollArt(artData, "ouie", oeuvre);
} }
@ -2911,7 +2803,7 @@ export class RdDActor extends Actor {
async rollOeuvre(id) { async rollOeuvre(id) {
const artData = { art: 'oeuvre', verbe: 'Interpréter' } const artData = { art: 'oeuvre', verbe: 'Interpréter' }
const oeuvre = duplicate(this.getItemOfType(id, artData.art)) const oeuvre = duplicate(this.findItemLike(id, artData.art))
await this._rollArt(artData, oeuvre.system.default_carac, oeuvre) await this._rollArt(artData, oeuvre.system.default_carac, oeuvre)
} }
@ -2963,7 +2855,7 @@ export class RdDActor extends Actor {
/* -------------------------------------------- */ /* -------------------------------------------- */
_getSignesDraconiques(coord) { _getSignesDraconiques(coord) {
const type = TMRUtility.getTMRType(coord); const type = TMRUtility.getTMRType(coord);
return this.listItemsData("signedraconique").filter(it => it.system.typesTMR.includes(type)); return this.listItems("signedraconique").filter(it => it.system.typesTMR.includes(type));
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
@ -3174,7 +3066,7 @@ export class RdDActor extends Actor {
/* -------------------------------------------- */ /* -------------------------------------------- */
async resetNombreAstral() { async resetNombreAstral() {
let toDelete = this.listItemsData('nombreastral'); let toDelete = this.listItems('nombreastral');
const deletions = toDelete.map(it => it._id); const deletions = toDelete.map(it => it._id);
await this.deleteEmbeddedDocuments("Item", deletions); await this.deleteEmbeddedDocuments("Item", deletions);
} }
@ -3194,7 +3086,7 @@ export class RdDActor extends Actor {
await this.createEmbeddedDocuments("Item", [item]); await this.createEmbeddedDocuments("Item", [item]);
// Suppression des anciens nombres astraux // Suppression des anciens nombres astraux
let toDelete = this.listItemsData('nombreastral').filter(it => it.system.jourindex < game.system.rdd.calendrier.getCurrentDayIndex()); let toDelete = this.listItems('nombreastral').filter(it => it.system.jourindex < game.system.rdd.calendrier.getCurrentDayIndex());
const deletions = toDelete.map(it => it._id); const deletions = toDelete.map(it => it._id);
await this.deleteEmbeddedDocuments("Item", deletions); await this.deleteEmbeddedDocuments("Item", deletions);
@ -3256,7 +3148,7 @@ export class RdDActor extends Actor {
/* -------------------------------------------- */ /* -------------------------------------------- */
getSortList() { getSortList() {
return this.listItemsData("sort"); return this.listItems("sort");
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
@ -3319,7 +3211,7 @@ export class RdDActor extends Actor {
fatigue: RdDUtility.calculFatigueHtml(fatigue, endurance), fatigue: RdDUtility.calculFatigueHtml(fatigue, endurance),
draconic: this.getDraconicList(), draconic: this.getDraconicList(),
sort: this.getSortList(), sort: this.getSortList(),
signes: this.listItemsData("signedraconique"), signes: this.listItems("signedraconique"),
caracReve: this.system.carac.reve.value, caracReve: this.system.carac.reve.value,
pointsReve: this.getReveActuel(), pointsReve: this.getReveActuel(),
isRapide: isRapide, isRapide: isRapide,
@ -3470,7 +3362,7 @@ export class RdDActor extends Actor {
async validerEncaissement(rollData, show) { async validerEncaissement(rollData, show) {
if (ReglesOptionelles.isUsing('validation-encaissement-gr') && !game.user.isGM) { if (ReglesOptionelles.isUsing('validation-encaissement-gr') && !game.user.isGM) {
RdDActor.remoteActorCall({ RdDBaseActor.remoteActorCall({
actorId: this.id, actorId: this.id,
method: 'validerEncaissement', method: 'validerEncaissement',
args: [rollData, show] args: [rollData, show]
@ -3691,7 +3583,7 @@ export class RdDActor extends Actor {
if (depense == 0) { if (depense == 0) {
return; return;
} }
let fortune = Monnaie.getFortune(this); let fortune = super.getFortune();
console.log("payer", game.user.character, depense, fortune); console.log("payer", game.user.character, depense, fortune);
let msg = ""; let msg = "";
if (fortune >= depense) { if (fortune >= depense) {
@ -3710,7 +3602,7 @@ export class RdDActor extends Actor {
} }
async depenserSols(sols) { async depenserSols(sols) {
let reste = Monnaie.getFortune(this) - Number(sols); let reste = super.getFortune() - Number(sols);
if (reste >= 0) { if (reste >= 0) {
await Monnaie.optimiserFortune(this, reste); await Monnaie.optimiserFortune(this, reste);
} }
@ -3727,7 +3619,7 @@ export class RdDActor extends Actor {
return; return;
} }
if (fromActorId && !game.user.isGM) { if (fromActorId && !game.user.isGM) {
RdDActor.remoteActorCall({ RdDBaseActor.remoteActorCall({
userId: Misc.connectedGMOrUser(), userId: Misc.connectedGMOrUser(),
actorId: this.id, actorId: this.id,
method: 'ajouterSols', args: [sols, fromActorId] method: 'ajouterSols', args: [sols, fromActorId]
@ -3735,7 +3627,7 @@ export class RdDActor extends Actor {
} }
else { else {
const fromActor = game.actors.get(fromActorId) const fromActor = game.actors.get(fromActorId)
await Monnaie.optimiserFortune(this, sols + Monnaie.getFortune(this)); await Monnaie.optimiserFortune(this, sols + this.getFortune());
RdDAudio.PlayContextAudio("argent"); // Petit son RdDAudio.PlayContextAudio("argent"); // Petit son
ChatMessage.create({ ChatMessage.create({
@ -3761,7 +3653,7 @@ export class RdDActor extends Actor {
return; return;
} }
if (!Misc.isUniqueConnectedGM()) { if (!Misc.isUniqueConnectedGM()) {
RdDActor.remoteActorCall({ RdDBaseActor.remoteActorCall({
actorId: achat.vendeurId ?? achat.acheteurId, actorId: achat.vendeurId ?? achat.acheteurId,
method: 'achatVente', method: 'achatVente',
args: [achat] args: [achat]
@ -3771,17 +3663,17 @@ export class RdDActor extends Actor {
const cout = Number(achat.prixTotal ?? 0); const cout = Number(achat.prixTotal ?? 0);
const vendeur = achat.vendeurId ? game.actors.get(achat.vendeurId) : undefined; const vendeur = achat.vendeurId ? game.actors.get(achat.vendeurId) : undefined;
const service = achat.serviceId ? (vendeur?.getObjet(achat.serviceId) ?? game.items.get(achat.serviceId)) : undefined; const service = achat.serviceId ? (vendeur?.getItem(achat.serviceId) ?? game.items.get(achat.serviceId)) : undefined;
const acheteur = achat.acheteurId ? game.actors.get(achat.acheteurId) : undefined; const acheteur = achat.acheteurId ? game.actors.get(achat.acheteurId) : undefined;
const vente = achat.vente; const vente = achat.vente;
const quantite = (achat.choix.nombreLots ?? 1) * (vente.tailleLot); const quantite = (achat.choix.nombreLots ?? 1) * (vente.tailleLot);
const itemVendu = vendeur?.getObjet(vente.item._id) ?? (await RdDItem.getCorrespondingItem(vente.item)); const itemVendu = vendeur?.getItem(vente.item._id) ?? (await RdDItem.getCorrespondingItem(vente.item));
if (!this.verifierQuantite(service, vente.serviceSubItem, vendeur, itemVendu, quantite)) { if (!this.verifierQuantite(service, vente.serviceSubItem, vendeur, itemVendu, quantite)) {
ChatUtility.notifyUser(achat.userId, 'warn', `Le vendeur n'a pas assez de ${itemVendu.name} !`); ChatUtility.notifyUser(achat.userId, 'warn', `Le vendeur n'a pas assez de ${itemVendu.name} !`);
return return
} }
if (Monnaie.getFortune(acheteur) < Number(cout)) { if ((acheteur?.getFortune() ?? 0) < Number(cout)) {
ChatUtility.notifyUser(achat.userId, 'warn', `Vous n'avez pas assez d'argent pour payer ${Math.ceil(cout / 100)} sols !`); ChatUtility.notifyUser(achat.userId, 'warn', `Vous n'avez pas assez d'argent pour payer ${Math.ceil(cout / 100)} sols !`);
return; return;
} }
@ -3871,7 +3763,7 @@ export class RdDActor extends Actor {
/* -------------------------------------------- */ /* -------------------------------------------- */
async effectuerTacheAlchimie(recetteId, tacheAlchimie, texteTache) { async effectuerTacheAlchimie(recetteId, tacheAlchimie, texteTache) {
let recetteData = this.getItemOfType(recetteId, 'recettealchimique'); let recetteData = this.findItemLike(recetteId, 'recettealchimique');
if (recetteData) { if (recetteData) {
if (tacheAlchimie != "couleur" && tacheAlchimie != "consistance") { if (tacheAlchimie != "couleur" && tacheAlchimie != "consistance") {
ui.notifications.warn(`L'étape alchimique ${tacheAlchimie} - ${texteTache} est inconnue`); ui.notifications.warn(`L'étape alchimique ${tacheAlchimie} - ${texteTache} est inconnue`);
@ -4141,7 +4033,7 @@ export class RdDActor extends Actor {
/* -------------------------------------------- */ /* -------------------------------------------- */
async diminuerQuantiteObjet(id, nb, options = { supprimerSiZero: false }) { async diminuerQuantiteObjet(id, nb, options = { supprimerSiZero: false }) {
const item = this.getObjet(id); const item = this.getItem(id);
if (item) { if (item) {
await item.diminuerQuantite(nb, options); await item.diminuerQuantite(nb, options);
} }

View File

@ -0,0 +1,243 @@
import { RdDUtility } from "../rdd-utility.js";
import { Misc } from "../misc.js";
import { DialogSplitItem } from "../dialog-split-item.js";
import { RdDSheetUtility } from "../rdd-sheet-utility.js";
import { Monnaie } from "../item-monnaie.js";
import { RdDItem } from "../item.js";
/* -------------------------------------------- */
/**
* Extend the basic ActorSheet with some very simple modifications
* @extends {ActorSheet}
*/
export class RdDBaseActorSheet extends ActorSheet {
/** @override */
static get defaultOptions() {
RdDUtility.initAfficheContenu();
return mergeObject(super.defaultOptions, {
classes: ["rdd", "sheet", "actor"],
template: "systems/foundryvtt-reve-de-dragon/templates/actor-sheet.html",
width: 550,
tabs: [{ navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "carac" }],
dragDrop: [{ dragSelector: ".item-list .item", dropSelector: undefined }],
showCompNiveauBase: false,
vueDetaillee: false
});
}
/* -------------------------------------------- */
async getData() {
Monnaie.validerMonnaies(this.actor.itemTypes['monnaie']);
this.actor.recompute();
const userRightLevel = this.actor.getUserLevel(game.user)
const options = duplicate(this.options);
mergeObject(options, {
isGM: game.user.isGM,
editable: this.isEditable,
cssClass: this.isEditable ? "editable" : "locked",
isLimited: userRightLevel >= CONST.DOCUMENT_OWNERSHIP_LEVELS.LIMITED,
isObserver: userRightLevel >= CONST.DOCUMENT_OWNERSHIP_LEVELS.OBSERVER,
isOwner: userRightLevel >= CONST.DOCUMENT_OWNERSHIP_LEVELS.OWNER,
});
let formData = {
title: this.title,
id: this.actor.id,
type: this.actor.type,
img: this.actor.img,
name: this.actor.name,
system: foundry.utils.deepClone(this.actor.system),
options: options,
}
this.filterItemsPerTypeForSheet(formData, this.actor.itemTypes);
formData.calc = {
fortune: this.toSolsDeniers(this.actor.getFortune()),
prixTotalEquipement: this.actor.computePrixTotalEquipement(),
encTotal: await this.actor.computeEncombrementTotalEtMalusArmure(),
}
this.objetVersConteneur = RdDUtility.buildArbreDeConteneurs(formData.conteneurs, formData.objets);
formData.conteneurs = RdDUtility.conteneursRacine(formData.conteneurs);
return formData;
}
toSolsDeniers(fortune) {
return {
sols: Math.floor(fortune),
deniers: Math.round(100 * (fortune - Math.floor(fortune)))
};
}
/* -------------------------------------------- */
filterItemsPerTypeForSheet(formData, itemTypes) {
formData.services = Misc.arrayOrEmpty(itemTypes['service']);
formData.recettescuisine = Misc.arrayOrEmpty(itemTypes['recettecuisine']);
formData.recettesAlchimiques = Misc.arrayOrEmpty(itemTypes['recettealchimique']);
formData.maladies = Misc.arrayOrEmpty(itemTypes['maladie']);
formData.poisons = Misc.arrayOrEmpty(itemTypes['poison']);
formData.possessions = Misc.arrayOrEmpty(itemTypes['possession']);
formData.maladiesPoisons = formData.maladies.concat(formData.poisons);
formData.competences = (itemTypes['competence'] ?? []).concat(itemTypes['competencecreature'] ?? []);
formData.sortsReserve = Misc.arrayOrEmpty(itemTypes['sortreserve']);
formData.sorts = Misc.arrayOrEmpty(itemTypes['sort']);
formData.rencontres = Misc.arrayOrEmpty(itemTypes['rencontre']);
formData.casestmr = Misc.arrayOrEmpty(itemTypes['casetmr']);
formData.signesdraconiques = Misc.arrayOrEmpty(itemTypes['signedraconique']);
formData.queues = Misc.arrayOrEmpty(itemTypes['queue']);
formData.souffles = Misc.arrayOrEmpty(itemTypes['souffle']);
formData.ombres = Misc.arrayOrEmpty(itemTypes['ombre']);
formData.tetes = Misc.arrayOrEmpty(itemTypes['tete']);
formData.taches = Misc.arrayOrEmpty(itemTypes['tache']);
formData.meditations = Misc.arrayOrEmpty(itemTypes['meditation']);
formData.chants = Misc.arrayOrEmpty(itemTypes['chant']);
formData.danses = Misc.arrayOrEmpty(itemTypes['danse']);
formData.musiques = Misc.arrayOrEmpty(itemTypes['musique']);
formData.oeuvres = Misc.arrayOrEmpty(itemTypes['oeuvre']);
formData.jeux = Misc.arrayOrEmpty(itemTypes['jeu']);
formData.conteneurs = Misc.arrayOrEmpty(itemTypes['conteneur']);
formData.materiel = Misc.arrayOrEmpty(itemTypes['objet']);
formData.armes = Misc.arrayOrEmpty(itemTypes['arme']);
formData.armures = Misc.arrayOrEmpty(itemTypes['armure']);
formData.munitions = Misc.arrayOrEmpty(itemTypes['munition']);
formData.livres = Misc.arrayOrEmpty(itemTypes['livre']);
formData.potions = Misc.arrayOrEmpty(itemTypes['potion']);
formData.ingredients = Misc.arrayOrEmpty(itemTypes['ingredient']);
formData.faunes = Misc.arrayOrEmpty(itemTypes['faune']);
formData.herbes = Misc.arrayOrEmpty(itemTypes['herbe']);
formData.nourritureboissons = Misc.arrayOrEmpty(itemTypes['nourritureboisson']);
formData.gemmes = Misc.arrayOrEmpty(itemTypes['gemme']);
formData.monnaie = Misc.arrayOrEmpty(itemTypes['monnaie']).sort(Monnaie.triValeurEntiere());
formData.objets = formData.conteneurs
.concat(formData.materiel)
.concat(formData.armes)
.concat(formData.armures)
.concat(formData.munitions)
.concat(formData.livres)
.concat(formData.potions)
.concat(formData.ingredients)
.concat(formData.herbes)
.concat(formData.faunes)
.concat(formData.monnaie)
.concat(formData.nourritureboissons)
.concat(formData.gemmes);
}
/* -------------------------------------------- */ /** @override */
activateListeners(html) {
super.activateListeners(html);
this.html = html;
this.html.find('.conteneur-name a').click(async event => {
RdDUtility.toggleAfficheContenu(RdDSheetUtility.getItemId(event));
this.render(true);
});
this.html.find('.item-edit').click(async event => RdDSheetUtility.getItem(event, this.actor)?.sheet.render(true))
this.html.find('.item-montrer').click(async event => RdDSheetUtility.getItem(event, this.actor)?.postItem());
// Everything below here is only needed if the sheet is editable
if (!this.options.editable) return;
this.html.find('.item-split').click(async event => {
const item = RdDSheetUtility.getItem(event, this.actor);
RdDSheetUtility.splitItem(item, 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('.creer-un-objet').click(async event => {
this.selectObjetTypeToCreate();
});
this.html.find('.nettoyer-conteneurs').click(async event => {
this.actor.nettoyerConteneurs();
});
this.html.find('.monnaie-plus').click(async event => {
this.actor.monnaieIncDec(RdDSheetUtility.getItemId(event), 1);
});
this.html.find('.monnaie-moins').click(async event => {
this.actor.monnaieIncDec(RdDSheetUtility.getItemId(event), -1);
});
}
/* -------------------------------------------- */
async _onDropItem(event, dragData) {
const destItemId = this.html.find(event.target)?.closest('.item').attr('data-item-id')
const dropParams = RdDSheetUtility.prepareItemDropParameters(destItemId, this.actor, dragData, this.objetVersConteneur)
if (dropParams) {
const callSuper = await this.actor.processDropItem(dropParams)
if (callSuper) {
await super._onDropItem(event, dragData)
}
}
}
/* -------------------------------------------- */
async selectObjetTypeToCreate() {
let typeObjets = RdDItem.getItemTypesInventaire();
let content = `<span class="competence-label">Selectionnez le type d'équipement</span><select class="item-type">`;
for (let typeName of typeObjets) {
content += `<option value="${typeName}">${Misc.typeName('Item', typeName)}</option>`
}
content += '</select>';
let d = new Dialog({
title: "Créer un équipement",
content: content,
buttons: {
create: {
icon: '<i class="fas fa-check"></i>',
label: "Créer l'objet",
callback: () => this.actor.createItem($(".item-type").val())
}
}
});
d.render(true);
}
/** @override */
setPosition(options = {}) {
const position = super.setPosition(options);
const sheetHeader = this.element.find(".sheet-header");
const sheetTabs = this.element.find(".sheet-tabs");
const sheetBody = this.element.find(".sheet-body");
let bodyHeight = position.height - sheetHeader[0].clientHeight;
if (sheetTabs.length > 0) {
bodyHeight -= sheetTabs[0].clientHeight;
}
sheetBody.css("height", bodyHeight);
return position;
}
/* -------------------------------------------- */
/** @override */
_updateObject(event, formData) {
// Update the Actor
return this.actor.update(formData);
}
async splitItem(item) {
const dialog = await DialogSplitItem.create(item, (item, split) => this._onSplitItem(item, split));
dialog.render(true);
}
async _onSplitItem(item, split) {
if (split >= 1 && split < item.system.quantite) {
await item.diminuerQuantite(split);
const splitItem = duplicate(item);
splitItem.system.quantite = split;
await this.actor.createEmbeddedDocuments('Item', [splitItem])
}
}
}

149
module/actor/base-actor.js Normal file
View File

@ -0,0 +1,149 @@
import { SYSTEM_SOCKET_ID } from "../constants.js";
import { Monnaie } from "../item-monnaie.js";
import { Misc } from "../misc.js";
import { SystemCompendiums } from "../settings/system-compendiums.js";
export class RdDBaseActor extends Actor {
static getDefaultImg(itemType) {
return game.system.rdd.actorClasses[itemType]?.defaultIcon ?? defaultItemImg[itemType];
}
/* -------------------------------------------- */
static init() {
Hooks.on("preUpdateItem", (item, change, options, id) => RdDBaseActor.getParentActor(item)?.onPreUpdateItem(item, change, options, id));
Hooks.on("createItem", (item, options, id) => RdDBaseActor.getParentActor(item)?.onCreateItem(item, options, id));
Hooks.on("deleteItem", (item, options, id) => RdDBaseActor.getParentActor(item)?.onDeleteItem(item, options, id));
Hooks.on("updateActor", (actor, change, options, actorId) => actor.onUpdateActor(change, options, actorId));
}
static onSocketMessage(sockmsg) {
switch (sockmsg.msg) {
case "msg_remote_actor_call":
return RdDBaseActor.onRemoteActorCall(sockmsg.data, sockmsg.userId);
case "msg_reset_nombre_astral":
console.log("RESET ASTRAL", game.user.character);
game.user.character.resetNombreAstral();
return;
}
}
static remoteActorCall(callData, userId = undefined) {
userId = userId ?? Misc.firstConnectedGMId();
if (userId == game.user.id) {
RdDBaseActor.onRemoteActorCall(callData, userId);
return false;
}
else {
game.socket.emit(SYSTEM_SOCKET_ID, { msg: "msg_remote_actor_call", data: callData, userId: userId });
return true;
}
}
static onRemoteActorCall(callData, userId) {
if (userId == game.user.id) {
const actor = game.actors.get(callData?.actorId);
if (Misc.isOwnerPlayerOrUniqueConnectedGM(actor)) { // Seul le joueur choisi effectue l'appel: le joueur courant si propriétaire de l'actor, ou le MJ sinon
const args = callData.args;
console.info(`RdDBaseActor.onRemoteActorCall: pour l'Actor ${callData.actorId}, appel de RdDBaseActor.${callData.method}(`, ...args, ')');
actor[callData.method](...args);
}
}
}
static getParentActor(document) {
return document?.parent instanceof Actor ? document.parent : undefined
}
/**
* Cet methode surcharge Actor.create() pour ajouter si besoin des Items par défaut:
* compétences et monnaies.
*
* @param {Object} actorData template d'acteur auquel ajouter des informations.
* @param {Object} options optionspour customiser la création
*/
static async create(actorData, options) {
// import depuis un compendium
if (actorData instanceof Array) {
return super.create(actorData, options);
}
// Création d'un acteur avec des items (uniquement en cas de duplication): pas besoin d'ajouter d'items
if (actorData.items) {
return await super.create(actorData, options);
}
if (actorData.type == "personnage") {
const competences = await SystemCompendiums.getCompetences(actorData.type);
actorData.items = competences.map(i => i.toObject())
.concat(Monnaie.monnaiesStandard());
}
else {
actorData.items = [];
}
return super.create(actorData, options);
}
constructor(docData, context = {}) {
if (!context.rdd?.ready) {
mergeObject(context, { rdd: { ready: true } });
const ActorConstructor = game.system.rdd.actorClasses[docData.type];
if (ActorConstructor) {
if (!docData.img) {
docData.img = ActorConstructor.defaultIcon;
}
return new ActorConstructor(docData, context);
}
}
super(docData, context);
}
isCreatureEntite() { return this.type == 'creature' || this.type == 'entite'; }
isCreature() { return this.type == 'creature'; }
isEntite() { return this.type == 'entite'; }
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)) {
return item;
}
return undefined;
}
listItems(type = undefined) { return (type ? this.itemTypes[type] : this.items); }
filterItems(filter, type = undefined) { return this.listItems(type)?.filter(filter) ?? []; }
findItemLike(idOrName, type) {
return this.getItem(idOrName, type)
?? Misc.findFirstLike(idOrName, this.listItems(type), { description: Misc.typeName('Item', type) });
}
recompute() { }
/* -------------------------------------------- */
async onPreUpdateItem(item, change, options, id) { }
async onCreateItem(item, options, id) { }
async onDeleteItem(item, options, id) { }
async onUpdateActor(update, options, actorId) { }
getFortune() {
return Monnaie.getFortune(this.itemTypes['monnaie']);
}
async createItem(type, name = undefined) {
if (!name) {
name = 'Nouveau ' + Misc.typeName('Item', type);
}
await this.createEmbeddedDocuments('Item', [{ name: name, type: type }], { renderSheet: true });
}
canReceive(item) {
return false;
}
}

View File

@ -62,29 +62,17 @@ export class Monnaie {
return deniers; return deniers;
} }
static getFortune(actor) { static getFortune(monnaies) {
if (actor) { return (monnaies??[])
Monnaie.validerMonnaies(actor);
return actor.itemTypes['monnaie']
.map(m => Number(m.system.cout) * Number(m.system.quantite)) .map(m => Number(m.system.cout) * Number(m.system.quantite))
.reduce(Misc.sum(), 0); .reduce(Misc.sum(), 0);
} }
return 0;
}
static getFortuneSolsDeniers(actor) {
const fortune = Monnaie.getFortune(actor);
return {
sols: Math.floor(fortune),
deniers: Math.round(100 * (fortune - Math.floor(fortune)))
};
}
static async optimiserFortune(actor, fortune) { static async optimiserFortune(actor, fortune) {
let resteEnDeniers = Math.round(fortune * 100); let resteEnDeniers = Math.round(fortune * 100);
let monnaies = actor.itemTypes['monnaie']; let monnaies = actor.itemTypes['monnaie'];
let updates = []; let updates = [];
Monnaie.validerMonnaies(actor); Monnaie.validerMonnaies(monnaies, actor);
let parValeur = Misc.classifyFirst(monnaies, it => VALEUR_DENIERS(it.system.cout)); let parValeur = Misc.classifyFirst(monnaies, it => VALEUR_DENIERS(it.system.cout));
for (let valeurDeniers of [1000, 100, 10, 1]) { for (let valeurDeniers of [1000, 100, 10, 1]) {
@ -107,9 +95,9 @@ export class Monnaie {
} }
} }
static validerMonnaies(actor) { static validerMonnaies(monnaies, actor = undefined) {
actor.itemTypes['monnaie'].filter(it => VALEUR_DENIERS(it.system.cout) == 0) monnaies.filter(it => VALEUR_DENIERS(it.system.cout) == 0)
.map(it => `La monnaie ${it.name} de l'acteur ${actor.name} a une valeur de 0!`) .map(it => `La monnaie ${it.name} de l'acteur ${actor?.name ?? 'sélectionné'} a une valeur de 0!`)
.forEach(message => { .forEach(message => {
ui.notifications.warn(message); ui.notifications.warn(message);
console.warn(message); console.warn(message);

View File

@ -46,6 +46,9 @@ export class Misc {
: ''; : '';
} }
static arrayOrEmpty(items) {
return items?.length ? items : [];
}
/** /**
* Converts the value to an integer, or to 0 if undefined/null/not representing integer * Converts the value to an integer, or to 0 if undefined/null/not representing integer
* @param {*} value value to convert to an integer using parseInt * @param {*} value value to convert to an integer using parseInt
@ -150,11 +153,11 @@ export class Misc {
return game.users.filter(u => u.isGM && u.active).sort(Misc.ascending(u => u.id)).find(u => u.isGM && u.active); return game.users.filter(u => u.isGM && u.active).sort(Misc.ascending(u => u.id)).find(u => u.isGM && u.active);
} }
static isOwnerPlayer(actor, user=undefined) { static isOwnerPlayer(actor, user = undefined) {
return actor.testUserPermission(user ?? game.user, CONST.DOCUMENT_PERMISSION_LEVELS.OWNER) return actor.testUserPermission(user ?? game.user, CONST.DOCUMENT_PERMISSION_LEVELS.OWNER)
} }
static isOwnerPlayerOrUniqueConnectedGM(actor, user =undefined){ static isOwnerPlayerOrUniqueConnectedGM(actor, user = undefined) {
return Misc.isOwnerPlayer(actor, user) ?? Misc.isUniqueConnectedGM(); return Misc.isOwnerPlayer(actor, user) ?? Misc.isUniqueConnectedGM();
} }

View File

@ -60,7 +60,7 @@ export class RdDAstrologieJoueur extends Dialog {
/* -------------------------------------------- */ /* -------------------------------------------- */
static organizeNombres(actor) { static organizeNombres(actor) {
let itemNombres = actor.listItemsData('nombreastral'); let itemNombres = actor.listItems('nombreastral');
let itemFiltered = {}; let itemFiltered = {};
for (let item of itemNombres) { for (let item of itemNombres) {
if (itemFiltered[item.system.jourindex]) { if (itemFiltered[item.system.jourindex]) {

View File

@ -350,7 +350,7 @@ export class RdDCalendrier extends Application {
} else { } else {
ChatMessage.create({ content: `${actor.name} souffre d'un mal inconnu (${maladie.type}): vérifiez que les effets ne se sont pas aggravés !` }); ChatMessage.create({ content: `${actor.name} souffre d'un mal inconnu (${maladie.type}): vérifiez que les effets ne se sont pas aggravés !` });
} }
let itemMaladie = actor.getObjet(maladie.id) let itemMaladie = actor.getItem(maladie.id)
itemMaladie.postItem( 'gmroll'); itemMaladie.postItem( 'gmroll');
} }
} }

View File

@ -36,6 +36,7 @@ import { RdDFauneItemSheet } from "./item-faune-sheet.js";
import { RdDConteneurItemSheet } from "./item-conteneur-sheet.js"; import { RdDConteneurItemSheet } from "./item-conteneur-sheet.js";
import { RdDServiceItemSheet } from "./item-service-sheet.js"; import { RdDServiceItemSheet } from "./item-service-sheet.js";
import { RdDItemService } from "./item-service.js"; import { RdDItemService } from "./item-service.js";
import { RdDBaseActor } from "./actor/base-actor.js";
/** /**
* RdD system * RdD system
@ -57,6 +58,10 @@ export class SystemReveDeDragon {
service: RdDItemService service: RdDItemService
} }
this.actorClasses = { this.actorClasses = {
creature: RdDActor,
entite: RdDActor,
personnage: RdDActor,
vehicule: RdDActor,
} }
} }
@ -161,7 +166,7 @@ export class SystemReveDeDragon {
RdDUtility.onSocketMessage(sockmsg); RdDUtility.onSocketMessage(sockmsg);
RdDCombat.onSocketMessage(sockmsg); RdDCombat.onSocketMessage(sockmsg);
ChatUtility.onSocketMessage(sockmsg); ChatUtility.onSocketMessage(sockmsg);
RdDActor.onSocketMessage(sockmsg); RdDBaseActor.onSocketMessage(sockmsg);
} catch (e) { } catch (e) {
console.error('game.socket.on(SYSTEM_SOCKET_ID) Exception: ', sockmsg, ' => ', e) console.error('game.socket.on(SYSTEM_SOCKET_ID) Exception: ', sockmsg, ' => ', e)
} }
@ -218,7 +223,7 @@ export class SystemReveDeDragon {
RdDCombat.init(); RdDCombat.init();
RdDCombatManager.init(); RdDCombatManager.init();
RdDTokenHud.init(); RdDTokenHud.init();
RdDActor.init(); RdDBaseActor.init();
RddCompendiumOrganiser.init(); RddCompendiumOrganiser.init();
EffetsDraconiques.init() EffetsDraconiques.init()
TMRUtility.init(); TMRUtility.init();

View File

@ -315,63 +315,13 @@ export class RdDUtility {
} }
static getItem(itemId, actorId = undefined) { static getItem(itemId, actorId = undefined) {
return actorId ? game.actors.get(actorId)?.getObjet(itemId) : game.items.get(itemId); return actorId ? game.actors.get(actorId)?.getItem(itemId) : game.items.get(itemId);
} }
static linkCompendium(pack, id, name) { static linkCompendium(pack, id, name) {
return `@Compendium[${pack}.${id}]{${name}}`; return `@Compendium[${pack}.${id}]{${name}}`;
} }
/* -------------------------------------------- */
static async creerObjet(actorSheet) {
let itemType = $(".item-type").val();
await actorSheet.createItem('Nouveau ' + itemType, itemType);
}
/* -------------------------------------------- */
static async selectObjetType(actorSheet) {
let typeObjets = RdDItem.getItemTypesInventaire();
let options = `<span class="competence-label">Selectionnez le type d'équipement</span><select class="item-type">`;
for (let typeName of typeObjets) {
options += `<option value="${typeName}">${typeName}</option>`
}
options += '</select>';
let d = new Dialog({
title: "Créer un équipement",
content: options,
buttons: {
one: {
icon: '<i class="fas fa-check"></i>',
label: "Créer l'objet",
callback: () => this.creerObjet(actorSheet)
}
}
});
d.render(true);
}
/* -------------------------------------------- */
static async selectTypeOeuvre(actorSheet) {
let typeObjets = RdDItem.getTypesOeuvres();
let options = `<span class="competence-label">Selectionnez le type d'oeuvre</span><select class="item-type">`;
for (let typeName of typeObjets) {
options += `<option value="${typeName}">${typeName}</option>`
}
options += '</select>';
let d = new Dialog({
title: "Créer un équipement",
content: options,
buttons: {
one: {
icon: '<i class="fas fa-check"></i>',
label: "Créer l'objet",
callback: () => this.creerObjet(actorSheet)
}
}
});
d.render(true);
}
/* -------------------------------------------- */ /* -------------------------------------------- */
static buildListOptions(min, max) { static buildListOptions(min, max) {
let options = "" let options = ""