Fix expérience automatique
Ne marchait pas pour caractéristiques avec accents, ni pour rêve/chance actuels
This commit is contained in:
parent
49ad4ff9c8
commit
c7e3c9e2c6
@ -1290,14 +1290,14 @@ export class RdDActor extends Actor {
|
||||
createCallbackExperience() {
|
||||
return {
|
||||
condition: r => r.rolled.isPart && r.finalLevel < 0 && game.settings.get("core", "rollMode") != 'selfroll',
|
||||
action: r => this._appliquerAjoutExperience(r)
|
||||
action: r => this._appliquerAjoutExperience(r, game.settings.get("core", "rollMode") != 'blindroll')
|
||||
};
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async _appliquerAjoutExperience(rollData) {
|
||||
let xpResult = this.appliquerExperience( rollData.rolled, rollData.selectedCarac.label, (rollData.competence) ? rollData.competence.data.name: undefined );
|
||||
if (xpResult.result ) {
|
||||
async _appliquerAjoutExperience(rollData, display=true) {
|
||||
let xpResult = this.appliquerExperience( rollData.rolled, rollData.selectedCarac.label, rollData.competence);
|
||||
if (display && xpResult.result ) {
|
||||
let xpmsg = "<br>Points d'expérience gagnés ! Carac: " + xpResult.xpCarac + ", Comp: " + xpResult.xpCompetence;
|
||||
let message = ChatUtility.prepareChatMessage('gmroll', this.name);
|
||||
message.content = "<strong>" + rollData.selectedCarac.label + "</strong>"
|
||||
@ -1720,7 +1720,7 @@ export class RdDActor extends Actor {
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async appliquerExperience( rolled, caracName, competenceName = undefined ) {
|
||||
async appliquerExperience( rolled, caracName, competence = undefined ) {
|
||||
|
||||
if ( rolled.isPart && rolled.finalLevel < 0) {
|
||||
// Cas de désir lancinant, pas d'expérience sur particulière
|
||||
@ -1731,37 +1731,38 @@ export class RdDActor extends Actor {
|
||||
}
|
||||
|
||||
if (caracName == 'derobee') caracName = 'agilite';
|
||||
let carac = duplicate(this.data.data.carac);
|
||||
|
||||
let xp = Math.abs(rolled.finalLevel);
|
||||
let xpCarac = Math.floor(xp / 2); // impair: arrondi inférieur en carac
|
||||
|
||||
let xpComp = 0;
|
||||
if ( competenceName ) {
|
||||
if ( competence ) {
|
||||
xpComp = xp - xpCarac;
|
||||
let competence = duplicate( RdDUtility.findCompetence( this.data.items, competenceName ) );
|
||||
competence.data.xp += xpComp;
|
||||
competence = duplicate(competence );
|
||||
competence.data.xp = Misc.toInt(competence.data.xp) + xpComp;
|
||||
await this.updateEmbeddedEntity( "OwnedItem", competence);
|
||||
} else {
|
||||
xpCarac = Math.max(xpCarac, 1);
|
||||
}
|
||||
if ( !carac[caracName].isderivee) {
|
||||
carac[caracName].xp += xpCarac;
|
||||
if (xpCarac > 0) {
|
||||
let carac = duplicate(this.data.data.carac);
|
||||
let selectedCarac = RdDActor._findCaracByName(carac, caracName);
|
||||
if ( !selectedCarac.derivee) {
|
||||
selectedCarac.xp = Misc.toInt(selectedCarac.xp) + xpCarac;
|
||||
await this.update( {"data.carac": carac } );
|
||||
} else {
|
||||
ChatMessage.create( { content: `Vous avez ${xpCarac} à répartir pour la caractérisque dérivée ${caracName}. Vous devez le faire manuellement.`,
|
||||
whisper: ChatMessage.getWhisperRecipients(game.user.name) } );
|
||||
}
|
||||
}
|
||||
return { result:true, xpcarac:xpCarac, xpCompetence: xpComp }; //XP
|
||||
}
|
||||
|
||||
return { result:false, xpcarac:0, xpCompetence: 0 }; // Pas d'XP
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async ajouteNombreAstral( data ) {
|
||||
// Gestion expérience (si existante)
|
||||
this.appliquerExperience( data.rolled, "vue", "astrologie");
|
||||
let astrologie = RdDUtility.findCompetence( this.data.items, "astrologie");
|
||||
this.appliquerExperience( data.rolled, "vue", astrologie);
|
||||
|
||||
// Ajout du nombre astral
|
||||
const item = {name: "Nombre Astral", type: "nombreastral", data:
|
||||
@ -1788,23 +1789,39 @@ export class RdDActor extends Actor {
|
||||
getCaracByName(caracName) {
|
||||
switch (caracName)
|
||||
{
|
||||
case 'reve-actuel':
|
||||
case 'reve-actuel': case 'Rêve Actuel':
|
||||
return {
|
||||
label: 'Rêve Actuel',
|
||||
value: this.getReveActuel(),
|
||||
type: "number",
|
||||
ignoreEtatGeneral: true
|
||||
};
|
||||
case 'chance-actuelle':
|
||||
case 'chance-actuelle': case 'Chance actuelle':
|
||||
return {
|
||||
type: "number",
|
||||
value: this.getChanceActuel(),
|
||||
label: 'Chance actuelle',
|
||||
value: this.getChanceActuel(),
|
||||
type: "number",
|
||||
ignoreEtatGeneral: true
|
||||
};
|
||||
default:
|
||||
return this.data.data.carac[caracName]; // Per default
|
||||
}
|
||||
return RdDActor._findCaracByName(this.data.data.carac, caracName);
|
||||
}
|
||||
|
||||
static _findCaracByName(carac, name) {
|
||||
name = name.toLowerCase();
|
||||
switch (name)
|
||||
{
|
||||
case 'reve-actuel': case 'rêve actuel':
|
||||
return carac.reve;
|
||||
case 'chance-actuelle': case 'chance actuelle':
|
||||
return carac.chance;
|
||||
}
|
||||
for (const [key, value] of Object.entries(carac)) {
|
||||
if (name == key || name == value.label.toLowerCase()) {
|
||||
return carac[key];
|
||||
}
|
||||
}
|
||||
return carac[name]; // Per default
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
|
Loading…
Reference in New Issue
Block a user