Adaptation Feuilles Acteurs

This commit is contained in:
Vincent Vandemeulebrouck
2021-03-25 03:18:27 +01:00
parent 5fb8d22a7a
commit 43cf091345
25 changed files with 277 additions and 237 deletions

View File

@ -72,7 +72,8 @@ export class RdDActor extends Actor {
return actor;
}
data.items = await RdDUtility.loadCompendium(RdDItemCompetence.actorCompendium(data.type));
const competences = await RdDUtility.loadCompendium(RdDItemCompetence.actorCompendium(data.type));
data.items = competences.map(it => Misc.data(it));
if (isPersonnage) {
data.items = data.items.concat(Monnaie.monnaiesData());
}
@ -143,7 +144,7 @@ export class RdDActor extends Actor {
if (!items) return; // Sanity check during import
let manquantes = Monnaie.monnaiesManquantes(items);
if (manquantes.length > 0) {
await this.createOwnedItem(manquantes);
await this.createEmbeddedDocuments('Item', manquantes, { renderSheet: false });
}
}
@ -231,10 +232,6 @@ export class RdDActor extends Actor {
return Misc.toInt(Misc.templateData(this).compteurs.surenc?.value);
}
/* -------------------------------------------- */
loadCompendiumNames() {
return this.data.items.filter(item => item.type == 'competence');
}
/* -------------------------------------------- */
getCompetence(name) {
return RdDItemCompetence.findCompetence(this.data.items, name);
}
@ -913,7 +910,7 @@ export class RdDActor extends Actor {
let itemMap = {};
for (let item of itemsList) {
let srcItem = sourceActor.data.items.find(subItem => subItem._id == item.id);
let newItem = await this.createOwnedItem(duplicate(srcItem));
let newItem = await this.createEmbeddedDocuments('Item', [duplicate(srcItem)]);
console.log('New object', newItem, srcItem);
itemMap[srcItem._id] = newItem._id; // Pour garder le lien ancien / nouveau
}
@ -943,7 +940,7 @@ export class RdDActor extends Actor {
maxEnc = Misc.templateData(this).capacite_encombrement;
else
maxEnc = Misc.templateData(this).attributs.encombrement.value;
let diffEnc = Number(this.encTotal) - Number(maxEnc);
let diffEnc = Number(this.data.encTotal) - Number(maxEnc);
return Math.max(0, Math.ceil(diffEnc));
}
@ -951,7 +948,7 @@ export class RdDActor extends Actor {
async computeEncombrementTotalEtMalusArmure() {
let encTotal = 0;
let newMalusArmure = 0;
for (const itemData of this.data.items) {
for (const itemData of this.data.items.filter(it => Misc.templateData(it).encombrement != undefined)) {
if (itemData.type == 'armure' && itemData.data.equipe) { // Armure équipée, intégration du malus armure total
newMalusArmure += itemData.data.malus;
}
@ -967,7 +964,7 @@ export class RdDActor extends Actor {
}
}
// Mise à jour valeur totale et états
this.encTotal = encTotal;
this.data.encTotal = encTotal;
this.detectSurEncombrement();
// Mise à jour éventuelle du malus armure
@ -1064,7 +1061,7 @@ export class RdDActor extends Actor {
/* -------------------------------------------- */
async ajouterSouffle(options = { chat: false }) {
let souffle = await RdDRollTables.getSouffle();
await this.createOwnedItem(souffle);
await this.createEmbeddedDocuments('Item', [souffle]);
if (options.chat) {
ChatMessage.create({
whisper: ChatUtility.getWhisperRecipientsAndGMs(game.user.name),
@ -1084,7 +1081,7 @@ export class RdDActor extends Actor {
else {
queue = await RdDRollTables.getQueue();
}
await this.createOwnedItem(queue);
await this.createEmbeddedDocuments('Item', [queue]);
if (options.chat) {
ChatMessage.create({
whisper: ChatUtility.getWhisperRecipientsAndGMs(game.user.name),
@ -1960,7 +1957,7 @@ export class RdDActor extends Actor {
ui.notifications.warn(`${this.name} n'a pas de caractéristique correspondant à ${caracName}`)
return;
}
const competence = this.getCompetence(compName);
const competence = this.getCompetence(compName);
if (compName && !competence) {
ui.notifications.warn(`${this.name} n'a pas de compétence correspondant à ${compName}`)
return;
@ -1970,14 +1967,14 @@ export class RdDActor extends Actor {
caracValue: Number(carac.value),
selectedCarac: carac,
competence: competence,
finalLevel: (competence?.data.niveau??0) + diff,
finalLevel: (competence?.data.niveau ?? 0) + diff,
diffLibre: diff,
showDice: true,
show: { title: "Jets multiples" }
};
await RdDResolutionTable.rollData(rollData);
this.appliquerExperience(rollData);
RdDResolutionTable.displayRollData( rollData, this )
RdDResolutionTable.displayRollData(rollData, this)
}
/* -------------------------------------------- */
@ -2026,7 +2023,7 @@ export class RdDActor extends Actor {
description: "Lecture du livre " + item.name + " - XP : " + itemData.data.xp + " - Compétences : " + itemData.data.competence
}
}
await this.createOwnedItem(tache, { renderSheet: true });
await this.createEmbeddedDocuments('Item', [tache], { renderSheet: true });
}
/* -------------------------------------------- */
@ -2294,7 +2291,7 @@ export class RdDActor extends Actor {
if (destinee > 0) {
ChatMessage.create({ content: `<span class="rdd-roll-part">${this.name} a fait appel à la Destinée !</span>` });
destinee--;
await this.updateCompteurValue( "destinee", destinee);
await this.updateCompteurValue("destinee", destinee);
onSuccess();
}
else {
@ -2422,11 +2419,11 @@ export class RdDActor extends Actor {
const keys = Object.entries(carac)
.filter(it => it[0].includes(name) || Grammar.toLowerCaseNoAccent(it[1].label).includes(name))
.map(it => it[0]);
if (keys.length>1){
if (keys.length > 1) {
const names = keys.reduce((a, b) => `${a}<br>${b}`);
ui.notifications.info(`Plusieurs caractéristiques possibles:<br>${names}<br>La première sera choisie.`);
}
if (keys.length>0){
if (keys.length > 0) {
return carac[keys[0]];
}
// for (const [key, value] of Object.entries(carac)) {
@ -2890,7 +2887,7 @@ export class RdDActor extends Actor {
if (dataObj) {
dataObj.payload.data.cout = sumDenier / 100; // Mise à jour du prix en sols , avec le prix acheté
dataObj.payload.data.quantite = quantite;
await this.createOwnedItem(dataObj.payload);
await this.createEmbeddedDocuments('Item',[dataObj.payload]);
msg += `<br>Et l'objet <strong>${dataObj.payload.name}</strong> a été ajouté à votre inventaire.`;
}
} else {