#103 : Gerer les augmentations de niveaux en comp et carac

This commit is contained in:
2021-01-03 18:19:18 +01:00
parent 969291a526
commit e18b5ad192
6 changed files with 113 additions and 13 deletions

View File

@ -540,7 +540,7 @@ export class RdDActor extends Actor {
}
/* -------------------------------------------- */
updateCarac( caracName, caracValue )
async updateCarac( caracName, caracValue )
{
let caracpath = "data.carac." + caracName + ".value"
if (caracName == "reve") {
@ -548,9 +548,17 @@ export class RdDActor extends Actor {
this.setPointsDeSeuil(caracValue);
}
}
this.update( { caracpath: caracValue } );
await this.update( { [caracpath]: caracValue } );
}
/* -------------------------------------------- */
async updateCaracXP( caracName, caracXP )
{
let caracpath = "data.carac."+caracName+".xp";
await this.update( { [caracpath]: caracXP } );
this.checkCaracXP( caracName );
}
/* -------------------------------------------- */
async updateCreatureCompetence( compName, fieldName, compValue )
{
@ -1160,6 +1168,7 @@ export class RdDActor extends Actor {
return ajustementMoral;
}
/* -------------------------------------------- */
async moralIncDec(ajustementMoral) {
let compteurs = duplicate(this.data.data.compteurs);
compteurs.moral.value = Misc.toInt(compteurs.moral.value);;
@ -1190,8 +1199,9 @@ export class RdDActor extends Actor {
if (!succes && moral > 0) return -1;
}
return 0;
}
/* -------------------------------------------- */
async setEthylisme(degre) {
let ethylisme = duplicate(this.data.data.compteurs.ethylisme);
ethylisme.value = degre;
@ -1347,6 +1357,56 @@ export class RdDActor extends Actor {
};
}
/* -------------------------------------------- */
async checkCaracXP( caracName ) {
let carac = this.data.data.carac[caracName];
console.log("XP chek", carac, caracName);
if (carac && carac.xp > 0) {
let xpNeeded = RdDUtility.getCaracNextXp( carac.value );
if ( carac.xp >= xpNeeded ) {
carac = duplicate(carac);
carac.value = Number(carac.value) + 1;
await this.updateCarac( caracName, carac.value );
carac.xp -= xpNeeded;
await this.updateCaracXP( caracName, carac.xp );
let xpData = {
alias: this.name,
carac: caracName,
value: carac.value,
xp: carac.xp
}
let content = await renderTemplate(`systems/foundryvtt-reve-de-dragon/templates/chat-actor-carac-xp.html`, xpData);
ChatUtility.createChatMessage({ content: content }, "default", this.name);
}
}
}
/* -------------------------------------------- */
async checkCompetenceXP( compName ) {
let competence = RdDUtility.findCompetence( this.data.items, compName);
if ( competence && competence.data.xp > 0) {
let xpNeeded = RdDUtility.getCompetenceNextXp( competence.data.niveau );
if ( competence.data.xp >= xpNeeded ) {
competence.data.xp -= xpNeeded;
competence.data.niveau += 1;
let update = {_id: competence._id, "data.xp": competence.data.xp, "data.niveau": competence.data.niveau};
await this.updateEmbeddedEntity( "OwnedItem", update );
let xpData = {
alias: this.name,
competence: competence.name,
niveau: competence.data.niveau,
xp: competence.data.xp,
archetype: competence.data.niveau_archetype,
archetypeWarning: competence.data.niveau > competence.data.niveau_archetype
}
let content = await renderTemplate(`systems/foundryvtt-reve-de-dragon/templates/chat-actor-competence-xp.html`, xpData);
ChatUtility.createChatMessage({ content: content }, "default", this.name);
}
}
}
/* -------------------------------------------- */
async _appliquerAjoutExperience(rollData, display=true) {
let xpResult = this.appliquerExperience( rollData.rolled, rollData.selectedCarac.label, rollData.competence);
@ -1357,6 +1417,12 @@ export class RdDActor extends Actor {
+ xpmsg;
ChatMessage.create(message);
}
if ( xpResult && xpResult.xpComp > 0 && rollData.competence) {
this.checkCompetenceXP( rollData.competence.name );
}
if ( xpResult && xpResult.xpCarac > 0 && rollData.selectedCarac) {
this.checkCaracXP( rollData.selectedCarac.name );
}
}
/* -------------------------------------------- */
@ -1765,16 +1831,17 @@ export class RdDActor extends Actor {
whisper: ChatMessage.getWhisperRecipients(game.user.name) } );
}
}
return { result:true, xpcarac:xpCarac, xpCompetence: xpComp }; //XP
return { result:true, xpCarac:xpCarac, xpCompetence: xpComp }; //XP
}
return { result:false, xpcarac:0, xpCompetence: 0 }; // Pas d'XP
return { result:false, xpCarac:0, xpCompetence: 0 }; // Pas d'XP
}
/* -------------------------------------------- */
async ajouteNombreAstral( data ) {
// Gestion expérience (si existante)
let astrologie = RdDUtility.findCompetence( this.data.items, "astrologie");
this.appliquerExperience( data.rolled, "vue", astrologie);
data.competence = RdDUtility.findCompetence( this.data.items, "astrologie");
data.selectedCarac = this.data.data.carac["vue"];
this._appliquerAjoutExperience( data );
// Ajout du nombre astral
const item = {name: "Nombre Astral", type: "nombreastral", data: