Fix creature competence

This commit is contained in:
2020-09-20 19:17:31 +02:00
parent 046e2e97ba
commit ca1a93f9d7
6 changed files with 53 additions and 30 deletions

View File

@ -114,7 +114,7 @@ export class RdDActorCreatureSheet extends ActorSheet {
// On competence change
html.find('.creature-carac').change((event) => {
let compName = event.currentTarget.attributes.compname.value;
this.actor.updateCreatureCompetence( compName, "carac-value", parseInt(event.target.value) );
this.actor.updateCreatureCompetence( compName, "carac_value", parseInt(event.target.value) );
} );
html.find('.creature-niveau').change((event) => {
let compName = event.currentTarget.attributes.compname.value;

View File

@ -307,14 +307,16 @@ export class RdDActor extends Actor {
async updateCreatureCompetence( compName, fieldName, compValue )
{
let comp = RdDUtility.findCompetence( this.data.items, compName);
console.log( comp );
if ( comp ) {
const update = {_id: comp._id }
if (fieldName == "niveau")
update['data.niveau']= compValue;
update['data.niveau'] = compValue;
else if (fieldName == "dommages")
update['data.dommages']= compValue;
update['data.dommages'] = compValue;
else
update['data.cacac-value']= compValue;
update['data.carac_value'] = compValue;
console.log(update);
const updated = await this.updateEmbeddedEntity("OwnedItem", update); // Updates one EmbeddedEntity
}
}
@ -719,10 +721,31 @@ export class RdDActor extends Actor {
}
/* -------------------------------------------- */
rollCreatureCompetence( compName )
async rollCreatureCompetence( compName, armeItem=undefined, attackerRoll=undefined )
{
let compItem = RdDUtility.findCompetence( this.data.items, compName);
//TODO !!!!
if ( compItem.data.iscombat ) {
armeItem = { name: compName, data: { dommages: compItem.data.dommages} };
}
compItem.data.defaut_carac = compName; // Fake default competence
console.log("V:", compItem.data.carac_value, compItem)
let rollData = {
"competence": compItem,
"arme": armeItem,
"carac": { compName: { label: compName, value: compItem.data.carac_value } },
"bonusmalusTable": CONFIG.RDD.bonusmalus,
"etat": this.data.data.compteurs.etat.value,
"bmValue": (attackerRoll) ? attackerRoll.bmValue : 0,
"attackerRoll": attackerRoll,
"finalLevel": 0
}
let html = await renderTemplate('systems/foundryvtt-reve-de-dragon/templates/dialog-competence.html', rollData);
if (armeItem) {
new RdDRollDialog("arme", html, rollData, this ).render(true);
} else {
new RdDRollDialog("competence", html, rollData, this ).render(true);
}
}
/* -------------------------------------------- */