Support recherche compétence par id

This commit is contained in:
Vincent Vandemeulebrouck
2021-11-23 02:04:00 +01:00
parent 9848e1a8af
commit b57b02b3ff
2 changed files with 66 additions and 76 deletions

View File

@ -904,8 +904,8 @@ export class RdDActor extends Actor {
}
/* -------------------------------------------- */
async updateCompetenceXPAuto(compName) {
let competence = this.getCompetence(compName);
async updateCompetenceXPAuto(idOrName) {
let competence = this.getCompetence(idOrName);
if (competence) {
let compData = Misc.data(competence);
let xp = Number(compData.data.xp);
@ -914,35 +914,35 @@ export class RdDActor extends Actor {
xp -= RdDItemCompetence.getCompetenceNextXp(niveau);
niveau++;
}
competence.update({
await competence.update({
"data.xp": xp,
"data.niveau": niveau,
});
this.updateExperienceLog("Compétence +", xp, compName + " passée à " + niveau);
this.updateExperienceLog("Compétence +", xp, competence.name + " passée à " + niveau);
}
}
/* -------------------------------------------- */
async updateCreatureCompetence(compName, fieldName, compValue) {
let comp = this.getCompetence(compName);
if (comp) {
const update = { _id: comp.id }
async updateCreatureCompetence(idOrName, fieldName, compValue) {
let competence = this.getCompetence(idOrName);
if (competence) {
const update = { _id: competence.id }
if (fieldName == "niveau")
update['data.niveau'] = compValue;
else if (fieldName == "dommages")
update['data.dommages'] = compValue;
else
update['data.carac_value'] = compValue;
const updated = await this.updateEmbeddedDocuments('Item', [update]); // pdates one EmbeddedEntity
await this.updateEmbeddedDocuments('Item', [update]); // updates one EmbeddedEntity
}
}
/* -------------------------------------------- */
async updateCompetence(compName, compValue) {
let comp = this.getCompetence(compName);
if (comp) {
let troncList = RdDItemCompetence.isTronc(compName);
let nouveauNiveau = compValue ?? RdDItemCompetence.getNiveauBase(Misc.data(comp).data.categorie);
async updateCompetence(idOrName, compValue) {
let competence = this.getCompetence(idOrName);
if (competence) {
let troncList = RdDItemCompetence.isTronc(competence.name);
let nouveauNiveau = compValue ?? RdDItemCompetence.getNiveauBase(Misc.data(competence).data.categorie);
if (troncList) {
let message = "Vous avez modifié une compétence 'tronc'. Vérifiez que les compétences suivantes évoluent ensemble jusqu'au niveau 0 : ";
for (let troncName of troncList) {
@ -953,50 +953,50 @@ export class RdDActor extends Actor {
content: message
});
}
const update = { _id: comp.id, 'data.niveau': nouveauNiveau };
const update = { _id: competence.id, 'data.niveau': nouveauNiveau };
await this.updateEmbeddedDocuments('Item', [update]); // Updates one EmbeddedEntity
} else {
console.log("Competence not found", compName);
console.log("Competence not found", idOrName);
}
}
/* -------------------------------------------- */
async updateCompetenceXP(compName, newXp) {
let comp = this.getCompetence(compName);
if (comp) {
async updateCompetenceXP(idOrName, newXp) {
let competence = this.getCompetence(idOrName);
if (competence) {
if (isNaN(newXp) || typeof (newXp) != 'number') newXp = 0;
this.checkCompetenceXP(compName, newXp);
const update = { _id: comp.id, 'data.xp': newXp };
this.checkCompetenceXP(idOrName, newXp);
const update = { _id: competence.id, 'data.xp': newXp };
await this.updateEmbeddedDocuments('Item', [update]); // Updates one EmbeddedEntity
this.updateExperienceLog("XP", newXp, "XP modifié en " + compName);
this.updateExperienceLog("XP", newXp, "XP modifié en " + competence.name);
} else {
console.log("Competence not found", compName);
console.log("Competence not found", idOrName);
}
RdDUtility.checkThanatosXP(compName);
RdDUtility.checkThanatosXP(idOrName);
}
/* -------------------------------------------- */
async updateCompetenceXPSort(compName, compValue) {
let comp = this.getCompetence(compName);
if (comp) {
async updateCompetenceXPSort(idOrName, compValue) {
let competence = this.getCompetence(idOrName);
if (competence) {
if (isNaN(compValue) || typeof (compValue) != 'number') compValue = 0;
const update = { _id: comp.id, 'data.xp_sort': compValue };
const update = { _id: competence.id, 'data.xp_sort': compValue };
await this.updateEmbeddedDocuments('Item', [update]); // Updates one EmbeddedEntity
this.updateExperienceLog("XP Sort", compValue, "XP modifié en sort de " + compName);
this.updateExperienceLog("XP Sort", compValue, "XP modifié en sort de " + competence.name);
} else {
console.log("Competence not found", compName);
console.log("Competence not found", idOrName);
}
}
/* -------------------------------------------- */
async updateCompetenceArchetype(compName, compValue) {
let comp = this.getCompetence(compName);
if (comp) {
async updateCompetenceArchetype(idOrName, compValue) {
let competence = this.getCompetence(idOrName);
if (competence) {
compValue = compValue ?? 0;
const update = { _id: comp.id, 'data.niveau_archetype': compValue };
const update = { _id: competence.id, 'data.niveau_archetype': compValue };
await this.updateEmbeddedDocuments('Item', [update]); // Updates one EmbeddedEntity
} else {
console.log("Competence not found", compName);
console.log("Competence not found", idOrName);
}
}
@ -2489,8 +2489,8 @@ export class RdDActor extends Actor {
}
/* -------------------------------------------- */
async rollCompetence(name) {
let rollData = { competence: Misc.data(this.getCompetence(name)) }
async rollCompetence(idOrName) {
let rollData = { competence: Misc.data(this.getCompetence(idOrName)) }
//console.log("COMP CREATURE", name, rollData, name);
if (rollData.competence.type == 'competencecreature') {
@ -2510,7 +2510,7 @@ export class RdDActor extends Actor {
const dialog = await RdDRoll.create(this, rollData, { html: 'systems/foundryvtt-reve-de-dragon/templates/dialog-roll-competence.html' }, {
name: 'jet-competence',
label: 'Jet ' + Grammar.apostrophe('de', name),
label: 'Jet ' + Grammar.apostrophe('de', rollData.competence.name),
callbacks: [
this.createCallbackExperience(),
this.createCallbackAppelAuMoral(),