forked from public/foundryvtt-reve-de-dragon
Allow comp. saves
This commit is contained in:
@ -45,7 +45,7 @@ export class RdDActorSheet extends ActorSheet {
|
||||
data.competenceByCategory = {};
|
||||
if (data.itemsByType.competence) {
|
||||
for (const item of data.itemsByType.competence) {
|
||||
//console.log("Push...", item, item.data.categorie);
|
||||
console.log("Push...", item, item.data.categorie);
|
||||
let list = data.competenceByCategory[item.data.categorie];
|
||||
if (!list) {
|
||||
list = [];
|
||||
@ -99,11 +99,17 @@ export class RdDActorSheet extends ActorSheet {
|
||||
});
|
||||
|
||||
// On carac change
|
||||
$(".competence-value").change((event) => {
|
||||
$(".carac-value").change((event) => {
|
||||
let caracName = event.currentTarget.name.replace(".value", "").replace("data.carac.", "");
|
||||
console.log("Value changed :", event, caracName);
|
||||
this.actor.updateCarac( caracName, parseInt(event.target.value) );
|
||||
} );
|
||||
// On competence change
|
||||
$(".competence-value").change((event) => {
|
||||
let compName = event.currentTarget.attributes.compname.value;
|
||||
console.log("Competence changed :", compName);
|
||||
this.actor.updateCompetence( compName, parseInt(event.target.value) );
|
||||
} );
|
||||
|
||||
$("#vie-plus").click((event) => {
|
||||
this.actor.santeIncDec("vie", 1);
|
||||
|
120
module/actor.js
120
module/actor.js
@ -49,15 +49,21 @@ export class RdDActor extends Actor {
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
performRoll( html, rollData ) {
|
||||
performRoll( rollData ) {
|
||||
let myroll = new Roll("d100");
|
||||
myroll.roll();
|
||||
let quality = "Echec";
|
||||
let xpmsg = "";
|
||||
let tache = 0;
|
||||
//console.log(">>> ROLL", rollData.selectedCarac.label, rollData.rollTarget.score, myroll.total );
|
||||
let result = myroll.total;
|
||||
if (result <= rollData.rollTarget.part) {
|
||||
quality = "Réussite Particulière!";
|
||||
if ( rollData.finalLevel < 0 ) {
|
||||
let xpcarac = Math.floor( Math.abs(rollData.finalLevel) / 2);
|
||||
let xpcomp = (Math.abs(rollData.finalLevel) % 2 == 1) ? xpcarac+1 : xpcarac;
|
||||
xpmsg = "<br>Points d'expérience gagné ! " + xpcarac + " - " + xpcomp;
|
||||
}
|
||||
tache = 4;
|
||||
} else if (result <= (rollData.rollTarget.score /2) ) {
|
||||
quality = "Réussite Significative";
|
||||
@ -76,9 +82,9 @@ export class RdDActor extends Actor {
|
||||
tache = -4;
|
||||
}
|
||||
|
||||
let chatOptions = { "content": "<strong>Test : " + rollData.selectedCarac.label + " / " + rollData.competence.name + "</strong><br>Modificateur : " + rollData.bmValue + " - " +
|
||||
rollData.selectedCarac.value + " / " + rollData.finalLevelStr + "<br><strong>Résutat : </strong>" + myroll.total + "<br>" +
|
||||
"<strong>" + quality + "</strong><br>Points de taches : " + tache ,
|
||||
let chatOptions = { "content": "<strong>Test : " + rollData.selectedCarac.label + " / " + rollData.competence.name + "</strong><br>Jet : " +
|
||||
rollData.selectedCarac.value + " / " + rollData.finalLevelStr + " - " + rollData.rollTarget.score + "%<br><strong>Résutat : </strong>" + myroll.total + "<br>" +
|
||||
"<strong>" + quality + "</strong><br>Points de taches : " + tache + xpmsg,
|
||||
"title": "Test"
|
||||
}
|
||||
ChatMessage.create( chatOptions );
|
||||
@ -92,6 +98,21 @@ export class RdDActor extends Actor {
|
||||
RdDUtility.computeCarac( data );
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async updateCompetence( compName, compValue )
|
||||
{
|
||||
let comp = RdDUtility.findCompetence( this.data.items, compName);
|
||||
if ( comp ) {
|
||||
//console.log("ACTOR", this);
|
||||
//comp.data.niveau = compValue;
|
||||
const update = {_id: comp._id, 'data.niveau': compValue };
|
||||
const updated = await this.updateEmbeddedEntity("OwnedItem", update); // Updates one EmbeddedEntity
|
||||
//console.log("UP", updated);
|
||||
} else {
|
||||
console.log("Competence not found", compName);
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
computeEtatGeneral( )
|
||||
{
|
||||
@ -128,18 +149,15 @@ export class RdDActor extends Actor {
|
||||
|
||||
if (name == "endurance") {
|
||||
if ( inc < 0 ) // Each endurance lost -> fatigue lost
|
||||
this.data.data.sante.fatigue = this.data.data.sante.fatigue + inc
|
||||
let diffEndurance = data.max - data.value;
|
||||
if ( this.data.data.sante.fatigue < diffEndurance) // If endurance lost, then the same amount of fatigue cannot be recovered
|
||||
this.data.data.sante.fatigue = diffEndurance;
|
||||
this.data.data.sante.fatigue.value = this.data.data.sante.fatigue.value - inc
|
||||
|
||||
// If endurance is 0 -> -1 vie
|
||||
if ( data.value == 0 ) {
|
||||
this.data.data.sante.vie.value = this.data.data.sante.vie.value - 1;
|
||||
}
|
||||
let diffVie = this.data.data.sante.vie.max - this.data.data.sante.vie.value;
|
||||
if ( data.value > data.max - (diffvie*2) ) {
|
||||
data.value = data.max - (diffvie*2);
|
||||
if ( data.value > data.max - (diffVie*2) ) {
|
||||
data.value = data.max - (diffVie*2);
|
||||
}
|
||||
|
||||
let blessures = this.data.data.blessures;
|
||||
@ -149,26 +167,41 @@ export class RdDActor extends Actor {
|
||||
|
||||
if (lastValue - data.value > 1) this.testSiSonne(data); // Peut-être sonné si 2 points d'endurance perdus d'un coup
|
||||
}
|
||||
|
||||
let diffEndurance = this.data.data.sante.endurance.max - this.data.data.sante.endurance.value;
|
||||
if ( this.data.data.sante.fatigue.value < diffEndurance) // If endurance lost, then the same amount of fatigue cannot be recovered
|
||||
this.data.data.sante.fatigue.value = diffEndurance;
|
||||
|
||||
console.log(">>>> NEW VI", name, data.value);
|
||||
this.computeEtatGeneral();
|
||||
}
|
||||
|
||||
|
||||
/* -------------------------------------------- */
|
||||
rollCompetence( compName ) {
|
||||
rollArme( armeName ) {
|
||||
// TODO : Search the weapon in the items
|
||||
|
||||
// TODO : Get the associated compentence
|
||||
|
||||
// TODO call rollCompetence with the comp+arme
|
||||
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async rollCompetence( compName, arme ) {
|
||||
|
||||
let compItem = RdDUtility.findCompetence( this.data.items, compName);
|
||||
let rollData = {
|
||||
"competence": compItem,
|
||||
"carac": this.data.data.carac,
|
||||
"bonusmalusTable": CONFIG.RDD.bonusmalus,
|
||||
"etat": this.data.data.compteurs.etat.value,
|
||||
"bmValue": 0,
|
||||
"arme": arme,
|
||||
"finalLevel": 0
|
||||
}
|
||||
CONFIG.currentRollData = rollData;
|
||||
renderTemplate('systems/foundryvtt-reve-de-dragon/templates/dialog-competence.html', rollData).then(dlg =>
|
||||
{
|
||||
new Dialog(
|
||||
|
||||
let dlg = await renderTemplate('systems/foundryvtt-reve-de-dragon/templates/dialog-competence.html', rollData);
|
||||
let mydialog = new Dialog(
|
||||
{
|
||||
title: "Test de compétence",
|
||||
content: dlg,
|
||||
@ -177,16 +210,65 @@ export class RdDActor extends Actor {
|
||||
rollButton:
|
||||
{
|
||||
label: "Lancer",
|
||||
callback: html => this.performRoll(html, rollData)
|
||||
callback: html => this.performRoll(html)
|
||||
}
|
||||
},
|
||||
default: "rollButton"
|
||||
}, {
|
||||
classes: ["rdddialog"],
|
||||
width: 600,
|
||||
height: 320
|
||||
} ).render(true);
|
||||
height: 360
|
||||
} );
|
||||
|
||||
mydialog.data.rollData = rollData;
|
||||
mydialog.data.actor = this;
|
||||
mydialog.activateListeners = function(html) {
|
||||
// Get the rollData stuff
|
||||
var rollData = this.data.rollData;
|
||||
|
||||
function updateRollResult( rollData ) {
|
||||
rollData.finalLevel = parseInt(rollData.competence.data.niveau) + parseInt(rollData.bmValue) + parseInt(rollData.etat);
|
||||
rollData.finalLevelStr = (rollData.finalLevel >= 0 ) ? "+" + rollData.finalLevel : rollData.finalLevel;
|
||||
$("#roll-param").text( rollData.selectedCarac.value + " / " + rollData.finalLevelStr );
|
||||
rollData.rollTarget = game.data.RdDUtility.getResolutionField( rollData.selectedCarac.value, rollData.finalLevel);
|
||||
let niveauStr = (rollData.competence.data.niveau >= 0) ? "+" + rollData.competence.data.niveau : rollData.competence.data.niveau;
|
||||
$("#compdialogTitle").text( rollData.competence.name + " - " + niveauStr + " - " + rollData.selectedCarac.label );
|
||||
$(".table-resolution").remove();
|
||||
game.data.RdDUtility.makeHTMLResolutionTable( $("#resolutionTable"), rollData.selectedCarac.value-2, parseInt(rollData.selectedCarac.value) + 2, -10, 11,
|
||||
rollData.selectedCarac.value, rollData.finalLevel );
|
||||
}
|
||||
|
||||
// Setup everything onload
|
||||
$(function() {
|
||||
// Set the default carac from the competence item
|
||||
rollData.selectedCarac = rollData.carac[rollData.competence.data.carac_defaut];
|
||||
// Update html, according to data
|
||||
$("#carac").val( rollData.competence.data.carac_defaut );
|
||||
$("#bonusmalus").val( rollData.bmValue );
|
||||
updateRollResult(rollData);
|
||||
});
|
||||
|
||||
|
||||
// Replace again the button action, as i overwritten it
|
||||
$('button').click((event) => {
|
||||
mydialog.data.actor.performRoll(rollData);
|
||||
});
|
||||
|
||||
// Update !
|
||||
$('#bonusmalus').click((event) => {
|
||||
rollData.bmValue = event.currentTarget.value; // Update the selected bonus/malus
|
||||
//console.log("BM CLICKED !!!", rollData.bmValue, rollData.competence.data.niveau, parseInt(rollData.competence.data.niveau) + parseInt(rollData.bmValue) );
|
||||
updateRollResult(rollData);
|
||||
});
|
||||
$('#carac').click((event) => {
|
||||
let caracKey = event.currentTarget.value;
|
||||
rollData.selectedCarac = rollData.carac[caracKey]; // Update the selectedCarac
|
||||
//console.log("CARAC CLICKED !!!", rollData.selectedCarac, rollData.competence.data.niveau, rollData.bmValue);
|
||||
updateRollResult(rollData);
|
||||
});
|
||||
}
|
||||
|
||||
mydialog.render(true);
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
|
Reference in New Issue
Block a user