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

@ -277,52 +277,34 @@ export class RdDActorSheet extends ActorSheet {
// Roll Skill
html.find('a.competence-label').click(async event => {
let compName = event.currentTarget.name;
this.actor.rollCompetence(compName);
this.actor.rollCompetence(this._getItemId(event));
});
html.find('.tache-label a').click(async event => {
const li = $(event.currentTarget).parents(".item");
let tacheId = li.data('item-id');
this.actor.rollTache(tacheId);
this.actor.rollTache(this._getItemId(event));
});
html.find('.meditation-label a').click(async event => {
const li = $(event.currentTarget).parents(".item");
let meditationId = li.data('item-id');
this.actor.rollMeditation(meditationId);
this.actor.rollMeditation(this._getItemId(event));
});
html.find('.chant-label a').click(async event => {
const li = $(event.currentTarget).parents(".item");
let chantId = li.data('item-id');
this.actor.rollChant(chantId);
this.actor.rollChant(this._getItemId(event));
});
html.find('.danse-label a').click(async event => {
const li = $(event.currentTarget).parents(".item");
let danseId = li.data('item-id');
this.actor.rollDanse(danseId);
this.actor.rollDanse(this._getItemId(event));
});
html.find('.musique-label a').click(async event => {
const li = $(event.currentTarget).parents(".item");
let musiqueId = li.data('item-id');
this.actor.rollMusique(musiqueId);
this.actor.rollMusique(this._getItemId(event));
});
html.find('.oeuvre-label a').click(async event => {
const li = $(event.currentTarget).parents(".item");
let oeuvreId = li.data('item-id');
this.actor.rollOeuvre(oeuvreId);
this.actor.rollOeuvre(this._getItemId(event));
});
html.find('.jeu-label a').click(async event => {
const li = $(event.currentTarget).parents(".item");
let jeuId = li.data('item-id');
this.actor.rollJeu(jeuId);
this.actor.rollJeu(this._getItemId(event));
});
html.find('.recettecuisine-label a').click(async event => {
const li = $(event.currentTarget).parents(".item");
let recetteId = li.data('item-id');
this.actor.rollRecetteCuisine(recetteId);
this.actor.rollRecetteCuisine(this._getItemId(event));
});
html.find('.subacteur-label a').click(async event => {
const li = $(event.currentTarget).parents(".item");
let actorId = li.data('actor-id');
let actorId = this._getEventItemData(event, 'actor-id');
let actor = game.actors.get(actorId);
if (actor) {
actor.sheet.render(true);
@ -344,16 +326,14 @@ export class RdDActorSheet extends ActorSheet {
// Roll Weapon1
html.find('.arme-label a').click(async event => {
const li = $(event.currentTarget).parents(".item");
let arme = this._getArmeCombat(li);
let arme = this._getEventArmeCombat(event);
this.actor.rollArme( duplicate(arme) );
});
// Initiative pour l'arme
html.find('.arme-initiative a').click(async event => {
let combatant = game.combat.data.combatants.find(c => c.actor.data._id == this.actor.data._id);
if (combatant) {
const li = $(event.currentTarget).parents(".item");
let arme = this._getArmeCombat(li);
let arme = this._getEventArmeCombat(event);
RdDCombatManager.rollInitiativeCompetence(combatant._id, arme);
} else {
ui.notifications.info("Impossible de lancer l'initiative sans être dans un combat.");
@ -385,8 +365,7 @@ export class RdDActorSheet extends ActorSheet {
this.actor.enleverTousLesEffets();
});
html.find('.conteneur-name a').click(async event => {
let myID = event.currentTarget.attributes['data-item-id'].value;
RdDUtility.toggleAfficheContenu(myID);
RdDUtility.toggleAfficheContenu(this._getItemId(event));
this.render(true);
});
html.find('.carac-xp-augmenter').click(async event => {
@ -394,10 +373,12 @@ export class RdDActorSheet extends ActorSheet {
this.actor.updateCaracXPAuto(caracName);
});
html.find('.competence-xp-augmenter').click(async event => {
let compName = event.currentTarget.attributes.compname.value;
this.actor.updateCompetenceXPAuto(compName);
this.actor.updateCompetenceXPAuto(this._getItemId(event));
});
html.find('.competence-stress-augmenter').click(async event => {
this.actor.updateCompetenceStress(this._getItemId(event));
});
if (this.options.editCaracComp) {
// On carac change
html.find('.carac-value').change(async event => {
@ -534,8 +515,17 @@ export class RdDActorSheet extends ActorSheet {
});
}
_getItemId(event) {
return this._getEventItemData(event, "item-id");
}
_getArmeCombat(li) {
_getEventItemData(event, property) {
const li = $(event.currentTarget)?.parents(".item");
return li?.data(property);
}
_getEventArmeCombat(event) {
const li = $(event.currentTarget)?.parents(".item");
let armeName = li.data("arme-name");
let compName = li.data('competence-name');
const arme = this.armesList.find(a => a.name == armeName && a.data.competence == compName);

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(),