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

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

View File

@ -44,6 +44,7 @@ export class RdDActorSheet extends ActorSheet {
let competenceXPTotal = 0;
if (data.itemsByType.competence) {
for (const item of data.itemsByType.competence) {
this.actor.checkCompetenceXP( item.name ); // Petite vérification experience
//console.log("Push...", item, item.data.categorie);
let list = data.competenceByCategory[item.data.categorie];
if (!list) {
@ -66,7 +67,12 @@ export class RdDActorSheet extends ActorSheet {
// Compute current carac sum
let sum = 0;
Object.values(data.data.carac).forEach(carac => { if (!carac.derivee) { sum += parseInt(carac.value) } } );
for (let caracName in data.data.carac) {
let carac = data.data.carac[caracName];
if (!carac.derivee) {
sum += parseInt(carac.value);
}
}
data.data.caracSum = sum;
// Force empty arme, at least for Esquive
@ -397,6 +403,11 @@ export class RdDActorSheet extends ActorSheet {
//console.log("Value changed :", event, caracName);
this.actor.updateCarac( caracName, parseInt(event.target.value) );
} );
html.find('.carac-xp').change((event) => {
let caracName = event.currentTarget.name.replace(".xp", "").replace("data.carac.", "");
//console.log("Value changed :", event, caracName);
this.actor.updateCaracXP( caracName, parseInt(event.target.value) );
} );
// On competence change
html.find('.competence-value').change((event) => {
let compName = event.currentTarget.attributes.compname.value;

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:

View File

@ -45,6 +45,8 @@ const carac_array = [ "taille", "apparence", "constitution", "force", "agilite",
const difficultesLibres = [0, -1, -2, -3, -4, -5, -6, -7, -8, -9, -10];
const ajustementsConditions = [-10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0, +1, +2, +3, +4, +5, +6, +7, +8, +9, +10];
const ajustementsEncaissement = [-10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0, +1, +2, +3, +4, +5, +6, +7, +8, +9, +10, +11, +12, +13, +14, +15, +16, +17, +18, +19, +20, +21, +22, +23, +24, +25];
const carac_xp_par_valeur = [6, 6, 7, 7, 8, 8, 9, 9, 10, 20, 30, 40, 50, 60, 70];
const XP_CARAC_OFFSET = 7;
/* -------------------------------------------- */
function _buildAllSegmentsFatigue(max) {
@ -208,7 +210,8 @@ export class RdDUtility {
'systems/foundryvtt-reve-de-dragon/templates/chat-resultat-tache.html',
'systems/foundryvtt-reve-de-dragon/templates/chat-resultat-sort.html',
'systems/foundryvtt-reve-de-dragon/templates/chat-actor-turn-summary.html',
'systems/foundryvtt-reve-de-dragon/templates/chat-actor-competence-xp.html',
'systems/foundryvtt-reve-de-dragon/templates/chat-actor-carac-xp.html'
];
return loadTemplates(templatePaths);
@ -406,6 +409,16 @@ export class RdDUtility {
return false;
}
/* -------------------------------------------- */
static getCaracNextXp( value ) {
return carac_xp_par_valeur[value - XP_CARAC_OFFSET];
}
/* -------------------------------------------- */
static getCompetenceNextXp( niveau ) {
return competence_xp_par_niveau[niveau+10];
}
/* -------------------------------------------- */
static computeCompetenceXPCost( competence )
{

View File

@ -105,16 +105,16 @@
{{#if carac.isTaille}}
<span class="carac-label flexrow" name="data.carac.{{key}}.label">{{carac.label}}</span>
<input class="carac-value flexrow" type="text" name="data.carac.{{key}}.value" value="{{carac.value}}" data-dtype="{{carac.type}}" {{#unless @root.data.editCaracComp}}disabled{{/unless}} />
<label class="competence-xp flexrow"/>
<label class="carac-xp flexrow"/>
{{else}}
{{#if carac.derivee}}
<span class="carac-label flexrow" name="data.carac.{{key}}.label">{{carac.label}}</span>
<label class="competence-value flexrow">{{carac.value}}</label>
<label class="competence-xp flexrow"/>
<label class="carac-xp flexrow"/>
{{else}}
<span class="carac-label flexrow" name="data.carac.{{key}}.label"><a name={{key}}>{{carac.label}}</a></span>
<input class="carac-value flexrow" type="text" name="data.carac.{{key}}.value" value="{{carac.value}}" data-dtype="{{carac.type}}" {{#unless @root.data.editCaracComp}}disabled{{/unless}} />
<input class="competence-xp flexrow" type="text" name="data.carac.{{key}}.xp" value="{{carac.xp}}" data-dtype="number" {{#unless @root.data.editCaracComp}}disabled{{/unless}} />
<input class="carac-xp flexrow" type="text" name="data.carac.{{key}}.xp" value="{{carac.xp}}" data-dtype="number" {{#unless @root.data.editCaracComp}}disabled{{/unless}} />
{{/if}}
{{/if}}
</li>

View File

@ -0,0 +1,3 @@
<h4>{{alias}} a progressé dans sa caractéristique {{carac}} ! </h4>
<div>Sa {{carac}} est désormais de {{value}} ! </div>
<div>Son experience dans cette caractéristique est de {{xp}} </div>

View File

@ -0,0 +1,6 @@
<h4>{{alias}} a progressé dans sa compétence {{competence}} ! </h4>
<div>Son niveau en {{competence}} est désormais de {{niveau}} pour un archétype de {{archetype}} ! </div>
<div>Son experience dans cette compétence est de {{xp}} </div>
{{#if archetypeWarning}}
<div><strong>ATTENTION !!</strong> Votre compétence a dépassé l'archétype. Veuillez contrôler que votre archétype est à jour, ou bien réduire le niveau de cette compétence.</div>
{{/if}}