Fix: niveau de compétence dans dialog roll

This commit is contained in:
Vincent Vandemeulebrouck 2021-04-20 00:52:06 +02:00
parent 77f0a93eb6
commit f0b042626f
2 changed files with 36 additions and 37 deletions

View File

@ -786,7 +786,7 @@ export class RdDActor extends Actor {
let comp = this.getCompetence(compName);
if (comp) {
let troncList = RdDItemCompetence.isTronc(compName);
let nouveauNiveau = compValue ?? RdDItemCompetence.getNiveauBase(comp.data.categorie);
let nouveauNiveau = compValue ?? RdDItemCompetence.getNiveauBase(Misc.data(comp).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) {
@ -1068,7 +1068,7 @@ export class RdDActor extends Actor {
}
/* -------------------------------------------- */
async computeIsHautRevant() {
computeIsHautRevant() {
const tplData = Misc.templateData(this);
tplData.attributs.hautrevant.value = this.listItemsData('tete').find(it => Grammar.toLowerCaseNoAccent(it.name) == 'don de haut-reve')
? "Haut rêvant"
@ -1893,25 +1893,25 @@ export class RdDActor extends Actor {
/* -------------------------------------------- */
async checkCompetenceXP(compName, newXP = undefined) {
let competence = this.getCompetence(compName);
if (competence && newXP && newXP == competence.data.xp) { // Si édition, mais sans changement XP
let compData = Misc.data(this.getCompetence(compName));
if (compData && newXP && newXP == compData.data.xp) { // Si édition, mais sans changement XP
return;
}
newXP = (newXP) ? newXP : competence.data.xp;
if (competence && newXP > 0) {
let xpNeeded = RdDItemCompetence.getCompetenceNextXp(competence.data.niveau + 1);
newXP = (newXP) ? newXP : compData.data.xp;
if (compData && newXP > 0) {
let xpNeeded = RdDItemCompetence.getCompetenceNextXp(compData.data.niveau + 1);
if (newXP >= xpNeeded) {
let newCompetence = duplicate(competence);
newCompetence.data.niveau += 1;
newCompetence.data.xp = newXP;
let newCompData = duplicate(compData);
newCompData.data.niveau += 1;
newCompData.data.xp = newXP;
let xpData = {
alias: this.name,
competence: newCompetence.name,
niveau: newCompetence.data.niveau,
xp: newCompetence.data.xp,
archetype: newCompetence.data.niveau_archetype,
archetypeWarning: newCompetence.data.niveau > competence.data.niveau_archetype
competence: newCompData.name,
niveau: newCompData.data.niveau,
xp: newCompData.data.xp,
archetype: newCompData.data.niveau_archetype,
archetypeWarning: newCompData.data.niveau > compData.data.niveau_archetype
}
ChatUtility.createChatMessage(this.name, "default", {
content: await renderTemplate(`systems/foundryvtt-reve-de-dragon/templates/chat-actor-competence-xp.html`, xpData)
@ -2196,7 +2196,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 = Misc.data(this.getCompetence(compName));
if (compName && !competence) {
ui.notifications.warn(`${this.name} n'a pas de compétence correspondant à ${compName}`)
return;
@ -2219,7 +2219,7 @@ export class RdDActor extends Actor {
/* -------------------------------------------- */
async rollCompetence(name) {
let rollData = { competence: this.getCompetence(name) }
let rollData = { competence: Misc.data(this.getCompetence(name)) }
if (rollData.competence.type == 'competencecreature') {
if (rollData.competence.data.iscombat) {
@ -2270,7 +2270,7 @@ export class RdDActor extends Actor {
async rollTache(id) {
const actorData = Misc.data(this);
const tacheData = Misc.data(this.getTache(id));
const compData = duplicate(Misc.data(this.getCompetence(tacheData.data.competence)));
const compData = Misc.data(this.getCompetence(tacheData.data.competence));
compData.data.defaut_carac = tacheData.data.carac; // Patch !
let rollData = {
@ -2319,7 +2319,7 @@ export class RdDActor extends Actor {
mergeObject(artData, {
oeuvre: oeuvre,
art: oeuvre.type,
competence: duplicate(this.getCompetence(oeuvre.data.competence ?? artData.art)),
competence: Misc.data(this.getCompetence(oeuvre.data.competence ?? artData.art)),
diffLibre: - (oeuvre.data.niveau ?? 0),
diffConditions: 0,
use: { libre: false, conditions: true },
@ -2381,14 +2381,14 @@ export class RdDActor extends Actor {
_getCaracDanse(oeuvre) {
if (oeuvre.data.agilite) { return "agilite"; }
else if (oeuvre.data.apparence) { return "apparence"; }
const competence = this.getCompetence(oeuvre.data.competence);
return competence.data.defaut_carac;
const compData = Misc.data(this.getCompetence(oeuvre.data.competence));
return compData.data.defaut_carac;
}
/* -------------------------------------------- */
async rollMusique(id) {
const artData = { art: 'musique', verbe: 'Jouer' };
const oeuvre = duplicate(this.getItemOfType(id, artData.art));
const oeuvre = Misc.data(this.getItemOfType(id, artData.art));
await this._rollArt(artData, "ouie", oeuvre);
}
@ -2400,7 +2400,7 @@ export class RdDActor extends Actor {
proportions: 1,
ajouterEquipement: false
};
const oeuvre = duplicate(this.getRecetteCuisine(id));
const oeuvre = Misc.data(this.getRecetteCuisine(id));
await this._rollArt(artData, 'odoratgout', oeuvre, r => this._resultRecetteCuisine(r));
}
@ -2451,8 +2451,8 @@ export class RdDActor extends Actor {
/* -------------------------------------------- */
async rollMeditation(id) {
let meditation = duplicate(this.getMeditation(id));
let competence = duplicate(this.getCompetence(meditation.data.competence));
let meditation = Misc.data(this.getMeditation(id));
let competence = Misc.data(this.getCompetence(meditation.data.competence));
competence.data.defaut_carac = "intellect"; // Meditation = tjs avec intellect
let meditationData = {
competence: competence,
@ -2467,7 +2467,7 @@ export class RdDActor extends Actor {
use: { libre: false, conditions: true, },
carac: {}
};
meditationData.carac["intellect"] = duplicate(Misc.templateData(this).carac["intellect"]);
meditationData.carac["intellect"] = Misc.templateData(this).carac["intellect"];
console.log("rollMeditation !!!", meditationData);
@ -2625,7 +2625,7 @@ export class RdDActor extends Actor {
/* -------------------------------------------- */
async ajouteNombreAstral(data) {
// Gestion expérience (si existante)
data.competence = this.getCompetence("astrologie");
data.competence = Misc.data(this.getCompetence("astrologie"));
data.selectedCarac = Misc.templateData(this).carac["vue"];
this._appliquerAjoutExperience(data);
@ -2760,7 +2760,7 @@ export class RdDActor extends Actor {
/* -------------------------------------------- */
rollArme(compName, armeName = undefined) {
let arme = armeName ? this.data.items.find(it => Misc.data(it).name == armeName && RdDItemArme.isArme(it)) : undefined;
let competence = this.getCompetence(compName);
let competence = Misc.data(this.getCompetence(compName));
if (arme || armeName || (competence.type == 'competencecreature' && competence.data.iscombat)) {
RdDCombat.createUsingTarget(this)?.attaque(competence, arme);
@ -3207,7 +3207,7 @@ export class RdDActor extends Actor {
let recette = this.getItemOfType(recetteId, 'recettealchimique');
const actorData = Misc.data(this);
if (recette) {
let competence = this.getCompetence("alchimie");
let competence = Misc.data(this.getCompetence("alchimie"));
let diffAlchimie = RdDAlchimie.getDifficulte(alchimieData);
let rollData = {
recette: recette,

View File

@ -796,11 +796,9 @@ export class RdDCombat {
}
// # utilisation esquive
let esquiveUsage = 0;
let esquive = this.defender.getCompetence("esquive");
if (esquive) {
esquiveUsage = this.defender.getItemUse(esquive._id);
}
const esquive = Misc.data(this.defender.getCompetence("esquive"));
const corpsACorps = Misc.data(this.defender.getCompetence("Corps à corps"));
const esquiveUsage = esquive ? this.defender.getItemUse(esquive._id) : 0;
const paramChatDefense = {
passeArme: attackerRoll.passeArme,
@ -810,7 +808,7 @@ export class RdDCombat {
attackerId: this.attackerId,
esquiveUsage: esquiveUsage,
defenderTokenId: this.defenderTokenId,
mainsNues: attackerRoll.dmg.mortalite != 'mortel' && this.defender.getCompetence("Corps à corps"),
mainsNues: attackerRoll.dmg.mortalite != 'mortel' && corpsACorps,
armes: this._filterArmesParade(this.defender, attackerRoll.competence, attackerRoll.arme),
diffLibre: attackerRoll.ajustements?.diffLibre?.value ?? 0,
attaqueParticuliere: attackerRoll.particuliere,
@ -955,12 +953,13 @@ export class RdDCombat {
_prepareParade(attackerRoll, armeParade) {
const compName = armeParade.data.competence;
const armeAttaque = attackerRoll.arme;
const parade = Misc.data(this.defender.getCompetence(compName));
let defenderRoll = {
passeArme: attackerRoll.passeArme,
diffLibre: attackerRoll.diffLibre,
attackerRoll: attackerRoll,
competence: this.defender.getCompetence(compName),
competence: parade,
arme: armeParade,
surprise: this.defender.getSurprise(true),
needParadeSignificative: ReglesOptionelles.isUsing('categorieParade') && RdDItemArme.needParadeSignificative(armeAttaque, armeParade),
@ -1011,7 +1010,7 @@ export class RdDCombat {
/* -------------------------------------------- */
async esquive(attackerRoll) {
let esquive = this.defender.getCompetence("esquive");
const esquive = Misc.data(this.defender.getCompetence("esquive"));
if (esquive == undefined) {
ui.notifications.error(this.defender.name + " n'a pas de compétence 'esquive'");
return;