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() {
|
createCallbackExperience() {
|
||||||
return {
|
return {
|
||||||
condition: r => r.rolled.isPart && r.finalLevel < 0 && game.settings.get("core", "rollMode") != 'selfroll',
|
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) {
|
async _appliquerAjoutExperience(rollData, display=true) {
|
||||||
let xpResult = this.appliquerExperience( rollData.rolled, rollData.selectedCarac.label, (rollData.competence) ? rollData.competence.data.name: undefined );
|
let xpResult = this.appliquerExperience( rollData.rolled, rollData.selectedCarac.label, rollData.competence);
|
||||||
if (xpResult.result ) {
|
if (display && xpResult.result ) {
|
||||||
let xpmsg = "<br>Points d'expérience gagnés ! Carac: " + xpResult.xpCarac + ", Comp: " + xpResult.xpCompetence;
|
let xpmsg = "<br>Points d'expérience gagnés ! Carac: " + xpResult.xpCarac + ", Comp: " + xpResult.xpCompetence;
|
||||||
let message = ChatUtility.prepareChatMessage('gmroll', this.name);
|
let message = ChatUtility.prepareChatMessage('gmroll', this.name);
|
||||||
message.content = "<strong>" + rollData.selectedCarac.label + "</strong>"
|
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) {
|
if ( rolled.isPart && rolled.finalLevel < 0) {
|
||||||
// Cas de désir lancinant, pas d'expérience sur particulière
|
// 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';
|
if (caracName == 'derobee') caracName = 'agilite';
|
||||||
let carac = duplicate(this.data.data.carac);
|
|
||||||
|
|
||||||
let xp = Math.abs(rolled.finalLevel);
|
let xp = Math.abs(rolled.finalLevel);
|
||||||
let xpCarac = Math.floor(xp / 2); // impair: arrondi inférieur en carac
|
let xpCarac = Math.floor(xp / 2); // impair: arrondi inférieur en carac
|
||||||
|
|
||||||
let xpComp = 0;
|
let xpComp = 0;
|
||||||
if ( competenceName ) {
|
if ( competence ) {
|
||||||
xpComp = xp - xpCarac;
|
xpComp = xp - xpCarac;
|
||||||
let competence = duplicate( RdDUtility.findCompetence( this.data.items, competenceName ) );
|
competence = duplicate(competence );
|
||||||
competence.data.xp += xpComp;
|
competence.data.xp = Misc.toInt(competence.data.xp) + xpComp;
|
||||||
await this.updateEmbeddedEntity( "OwnedItem", competence);
|
await this.updateEmbeddedEntity( "OwnedItem", competence);
|
||||||
} else {
|
} else {
|
||||||
xpCarac = Math.max(xpCarac, 1);
|
xpCarac = Math.max(xpCarac, 1);
|
||||||
}
|
}
|
||||||
if ( !carac[caracName].isderivee) {
|
if (xpCarac > 0) {
|
||||||
carac[caracName].xp += xpCarac;
|
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 } );
|
await this.update( {"data.carac": carac } );
|
||||||
} else {
|
} else {
|
||||||
ChatMessage.create( { content: `Vous avez ${xpCarac} à répartir pour la caractérisque dérivée ${caracName}. Vous devez le faire manuellement.`,
|
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) } );
|
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 ) {
|
async ajouteNombreAstral( data ) {
|
||||||
// Gestion expérience (si existante)
|
// 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
|
// Ajout du nombre astral
|
||||||
const item = {name: "Nombre Astral", type: "nombreastral", data:
|
const item = {name: "Nombre Astral", type: "nombreastral", data:
|
||||||
@ -1788,23 +1789,39 @@ export class RdDActor extends Actor {
|
|||||||
getCaracByName(caracName) {
|
getCaracByName(caracName) {
|
||||||
switch (caracName)
|
switch (caracName)
|
||||||
{
|
{
|
||||||
case 'reve-actuel':
|
case 'reve-actuel': case 'Rêve Actuel':
|
||||||
return {
|
return {
|
||||||
label: 'Rêve Actuel',
|
label: 'Rêve Actuel',
|
||||||
value: this.getReveActuel(),
|
value: this.getReveActuel(),
|
||||||
type: "number",
|
type: "number",
|
||||||
ignoreEtatGeneral: true
|
ignoreEtatGeneral: true
|
||||||
};
|
};
|
||||||
case 'chance-actuelle':
|
case 'chance-actuelle': case 'Chance actuelle':
|
||||||
return {
|
return {
|
||||||
type: "number",
|
|
||||||
value: this.getChanceActuel(),
|
|
||||||
label: 'Chance actuelle',
|
label: 'Chance actuelle',
|
||||||
|
value: this.getChanceActuel(),
|
||||||
|
type: "number",
|
||||||
ignoreEtatGeneral: true
|
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