Gestion preliminaire de l'XP

This commit is contained in:
2020-08-13 22:28:56 +02:00
parent d215629c9b
commit 5fa82a5ee7
10 changed files with 92 additions and 5 deletions

View File

@ -272,6 +272,7 @@ export class RdDActor extends Actor {
data: defenseMsg
} );
} else {
defenseMsg.whisper = [ game.user];
ChatMessage.create( defenseMsg );
}
}
@ -294,7 +295,26 @@ export class RdDActor extends Actor {
{
let comp = RdDUtility.findCompetence( this.data.items, compName);
if ( comp ) {
const update = {_id: comp._id, 'data.niveau': compValue };
let troncList = RdDUtility.isTronc( compName );
let maxNiveau = compValue;
if ( troncList ) {
let troncCompValue = (compValue > 0) ? 0 : compValue; // Clamp it to 0
for(let troncName of troncList) {
if ( troncName != compName) {
console.log("Update competence tronc", troncName, compValue);
let comp2 = RdDUtility.findCompetence( this.data.items, troncName);
if (comp2.data.niveau > maxNiveau) maxNiveau = comp2.data.niveau;
if ( comp2.data.niveau <= 0 && comp2.data.niveau < troncCompValue ) { // Update only of below 0
const update = {_id: comp2._id, 'data.niveau': compValue };
const updated = await this.updateEmbeddedEntity("OwnedItem", update); // Updates one EmbeddedEntity
}
}
}
if ( compValue < maxNiveau) { // Manage case when someone set a value below
compValue = (maxNiveau > 0) ? 0 : maxNiveau;
}
}
const update = {_id: comp._id, 'data.niveau': maxNiveau };
const updated = await this.updateEmbeddedEntity("OwnedItem", update); // Updates one EmbeddedEntity
} else {
console.log("Competence not found", compName);