Gestion des signes draconiques #455

Closed
vincent.vandeme wants to merge 233 commits from v1.4-signes-draconiques into master
2 changed files with 39 additions and 37 deletions
Showing only changes of commit 8a95ad6471 - Show all commits

View File

@ -57,33 +57,33 @@ export class RdDActor extends Actor {
* This overrided create() function adds initial items
* Namely: Basic skills, money,
*
* @param {Object} data Barebones actor data which this function adds onto.
* @param {Object} actorData Barebones actor data which this function adds onto.
* @param {Object} options (Unused) Additional options which customize the creation workflow.
*
*/
static async create(data, options) {
static async create(actorData, options) {
// Case of compendium global import
if (data instanceof Array) {
return super.create(data, options);
if (actorData instanceof Array) {
return super.create(actorData, options);
}
const isPersonnage = data.type == "personnage";
const isPersonnage = actorData.type == "personnage";
// If the created actor has items (only applicable to duplicated actors) bypass the new actor creation logic
if (data.items) {
let actor = super.create(data, options);
if (actorData.items) {
let actor = super.create(actorData, options);
if (isPersonnage) {
await actor.checkMonnaiePresence(data.items);
await actor.checkMonnaiePresence(actorData.items);
}
return actor;
}
const competences = await RdDUtility.loadCompendium(RdDItemCompetence.actorCompendium(data.type));
data.items = competences.map(it => Misc.data(it));
const competences = await RdDUtility.loadCompendium(RdDItemCompetence.actorCompendium(actorData.type));
actorData.items = competences.map(it => Misc.data(it));
if (isPersonnage) {
data.items = data.items.concat(Monnaie.monnaiesData());
actorData.items = actorData.items.concat(Monnaie.monnaiesData());
}
return super.create(data, options);
return super.create(actorData, options);
}
/* -------------------------------------------- */
@ -245,8 +245,14 @@ export class RdDActor extends Actor {
getObjet(id) {
return id ? this.data.items.find(it => it.id == id) : undefined;
}
listItemsData(type) {
return this.filterItemsData(it => it.type == type);
}
filterItemsData(filter) {
return this.data.items.map(it => Misc.data(it)).filter(filter);
}
getItemOfType(id, type) {
return id ? this.data.items.find(it => it.id == id && it.type == type) : undefined;
return id ? this.data.items.find(it => it.id == id && Misc.data(it).type == type) : undefined;
}
getMonnaie(id) {
return this.getItemOfType(id, 'monnaie');
@ -344,7 +350,7 @@ export class RdDActor extends Actor {
async _recupereChance() {
// On ne récupère un point de chance que si aucun appel à la chance dans la journée
if (this.getChanceActuel() < this.getChance() && !this.getFlag('foundryvtt-reve-de-dragon', 'utilisationChance')) {
await this.chanceActuelleIncDec(1);
await this.chanceActuelleIncDec(1);
}
// Nouveau jour, suppression du flag
await this.unsetFlag('foundryvtt-reve-de-dragon', 'utilisationChance');
@ -925,7 +931,7 @@ export class RdDActor extends Actor {
// gestion conteneur/contenu
if (item.conteneurId) { // l'Objet était dans un conteneur
let newConteneurId = itemMap[item.conteneurId]; // Get conteneur
let newConteneur = this.data.items.find(subItem => subItem._id == newConteneurId);
let newConteneur = this.getObjet(newConteneurId);
let newItemId = itemMap[item.id]; // Get newItem
@ -955,8 +961,7 @@ export class RdDActor extends Actor {
async computeEncombrementTotalEtMalusArmure() {
let encTotal = 0;
let newMalusArmure = 0;
for (const item of this.data.items.filter(it => Misc.templateData(it).encombrement != undefined)) {
let itemData = item.data; // v0.8 normalization
for (const itemData of this.filterItemsData(it => it.data.encombrement)) {
if (itemData.type == 'armure' && itemData.data.equipe) { // Armure équipée, intégration du malus armure total
newMalusArmure += itemData.data.malus;
}
@ -987,14 +992,10 @@ export class RdDActor extends Actor {
let prixTotalEquipement = 0;
// prix total de l'équipement est la somme du cout de chaque équipement multiplié par sa quantité.
for (const item of this.data.items) {
let itemData = item.data; // v0.8 normalization
if (itemData.data && itemData.data.cout != undefined) {
if (!Number(itemData.data.cout)) itemData.data.cout = 0; // Auto-fix
if (itemData.data.quantite == undefined) itemData.data.quantite = 1; // Auto-fix
if (itemData.data.cout < 0) itemData.data.cout = 0; // Auto-fix
prixTotalEquipement += Number(itemData.data.cout) * Number(itemData.data.quantite);
}
for (const itemData of this.filterItemsData(it => it?.data.cout)) {
const cout = Math.min(Number(itemData.data.cout) ?? 0, 0);
const quantite = Math.min(Number(itemData.data.quantite) ?? 1, 1);
prixTotalEquipement += cout * quantite;
}
// Mise à jour valeur totale de l'équipement
this.prixTotalEquipement = prixTotalEquipement;
@ -1113,7 +1114,7 @@ export class RdDActor extends Actor {
}
buildTMRInnaccessible() {
const tmrInnaccessibles = this.data.items.filter(it => Draconique.isCaseTMR(it) &&
const tmrInnaccessibles = this.filterItemsData(it => Draconique.isCaseTMR(it) &&
EffetsDraconiques.isInnaccessible(it));
return tmrInnaccessibles.map(it => it.data.coord);
}
@ -1664,7 +1665,7 @@ export class RdDActor extends Actor {
/* -------------------------------------------- */
async checkCompetenceXP(compName, newXP = undefined) {
let competence = RdDItemCompetence.findCompetence(this.data.items, compName);
let competence = this.getCompetence(compName);
if (competence && newXP && newXP == competence.data.xp) { // Si édition, mais sans changement XP
return;
}
@ -1831,7 +1832,7 @@ export class RdDActor extends Actor {
let addMsg = "";
let rencSpecial = this.data.items.find(item => EffetsDraconiques.isMauvaiseRencontre(item));
if (rencSpecial) {
rencSpecial = duplicate(rencSpecial); // To keep it
rencSpecial = Misc.data(rencSpecial); // To keep it
if (rencSpecial.type != 'souffle') {
this.deleteEmbeddedDocuments('Item', [rencSpecial._id]); // Suppression dans la liste des queues
addMsg = " La queue a été supprimée de votre fiche automatiquement";
@ -2318,7 +2319,8 @@ export class RdDActor extends Actor {
}
/* -------------------------------------------- */
checkDesirLancinant() {
let queue = this.data.items.filter((item) => item.name.toLowerCase().includes('lancinant'));
let queue = this.filterItemsData(it => it.type == 'queue' || it.type == 'ombre')
.filter(it => Grammar.toLowerCaseNoAccent(it.name).includes('desir lancinant'));
return (queue.length > 0);
}
@ -2368,7 +2370,7 @@ export class RdDActor extends Actor {
/* -------------------------------------------- */
async ajouteNombreAstral(data) {
// Gestion expérience (si existante)
data.competence = RdDItemCompetence.findCompetence(this.data.items, "astrologie");
data.competence = this.getCompetence("astrologie");
data.selectedCarac = Misc.templateData(this).carac["vue"];
this._appliquerAjoutExperience(data);
@ -2380,7 +2382,7 @@ export class RdDActor extends Actor {
await this.createEmbeddedDocuments("Item", [item]);
// Suppression des anciens nombres astraux
let toDelete = this.data.items.filter(it => it.data.jourindex < game.system.rdd.calendrier.getCurrentDayIndex());
let toDelete = this.listItemsData('nombreastral').filter(it => it.data.jourindex < game.system.rdd.calendrier.getCurrentDayIndex());
const deletions = toDelete.map(it => it._id);
await this.deleteEmbeddedDocuments("Item", deletions);
@ -2443,12 +2445,12 @@ export class RdDActor extends Actor {
/* -------------------------------------------- */
getSortList() {
return this.data.items.filter(it => it.data.type == "sort");
return this.listItemsData("sort");
}
/* -------------------------------------------- */
countMonteeLaborieuse() { // Return +1 par queue/ombre/souffle Montée Laborieuse présente
let countMonteeLaborieuse = this.data.items.filter(it => EffetsDraconiques.isMonteeLaborieuse(it)).length;
let countMonteeLaborieuse = this.filterItemsData(it => EffetsDraconiques.isMonteeLaborieuse(it)).length;
if (countMonteeLaborieuse > 0) {
ChatMessage.create({
content: `Vous êtes sous le coup d'une Montée Laborieuse : vos montées en TMR coûtent ${countMonteeLaborieuse} Point de Rêve de plus.`,
@ -2502,7 +2504,7 @@ export class RdDActor extends Actor {
/* -------------------------------------------- */
rollArme(compName, armeName = undefined) {
let arme = armeName ? this.data.items.find(it => it.name == armeName && RdDItemArme.isArme(it)) : undefined;
let arme = armeName ? this.data.items.find(it => Misc.data(it).name == armeName && RdDItemArme.isArme(it)) : undefined;
let competence = this.getCompetence(compName);
if (arme || armeName || (competence.type == 'competencecreature' && competence.data.iscombat)) {
@ -2915,10 +2917,10 @@ export class RdDActor extends Actor {
/* -------------------------------------------- */
async effectuerTacheAlchimie(recetteId, alchimieName, alchimieData) {
let recette = this.data.items.find(item => item.type == 'recettealchimique' && item.id == recetteId);
let recette = this.getItemOfType(recetteId, 'recettealchimique');
const actorData = Misc.data(this);
if (recette) {
let competence = this.data.items.find(item => item.type == 'competence' && item.name.toLowerCase() == "alchimie");
let competence = this.getCompetence("alchimie");
let diffAlchimie = RdDAlchimie.getDifficulte(alchimieData);
let rollData = {
recette: recette,

View File

@ -30,7 +30,7 @@ export class Monnaie {
}
static filtrerMonnaies(items) {
return items.filter(it => it.type == 'monnaie');
return items.filter(it => Misc.data(it).type == 'monnaie');
}
static monnaiesManquantes(items) {