Sync with head

This commit is contained in:
2020-05-24 20:19:57 +02:00
parent c144b2473c
commit 003d548f1f
10 changed files with 754 additions and 175 deletions

View File

@ -93,7 +93,12 @@ export class RdDActorSheet extends ActorSheet {
let compName = event.currentTarget.text;
this.actor.rollCompetence( compName);
});
// On carac change
$(".competence-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) );
} );
}
/* -------------------------------------------- */

View File

@ -7,6 +7,25 @@ import { RdDUtility } from "./rdd-utility.js";
export class RdDActor extends Actor {
/* -------------------------------------------- */
/**
* Override the create() function to provide additional RdD functionality.
*
* This overrided create() function adds initial items
* Namely: Basic skills, money,
*
* @param {Object} data Barebones actor data which this function adds onto.
* @param {Object} options (Unused) Additional options which customize the creation workflow.
*
*/
static async create(data, options) {
// If the created actor has items (only applicable to duplicated actors) bypass the new actor creation logic
if (data.items) {
return super.create(data, options);
}
super.create(data, options);
}
/* -------------------------------------------- */
prepareData() {
@ -25,16 +44,67 @@ export class RdDActor extends Actor {
* Prepare Character type specific data
*/
_prepareCharacterData(actorData) {
// Initialize empty items
RdDUtility.computeCarac(actorData.data);
}
/* -------------------------------------------- */
performRoll( html, rollData ) {
let myroll = new Roll("d100");
myroll.roll();
let quality = "Echec";
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!";
tache = 4;
} else if (result <= (rollData.rollTarget.score /2) ) {
quality = "Réussite Significative";
tache = 2;
} else if (result <= (rollData.rollTarget.score) ) {
quality = "Réussite Normale";
tache = 1;
} else if (result < (rollData.rollTarget.epart) ) {
quality = "Echec Normal";
tache = 0;
} else if (result < (rollData.rollTarget.etotal) ) {
quality = "Echec Particulier";
tache = -2;
} else if (result >= (rollData.rollTarget.etotal) ) {
quality = "Echec Total";
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 ,
"title": "Test"
}
ChatMessage.create( chatOptions );
}
/* -------------------------------------------- */
updateCarac( caracName, caracValue )
{
let data = this.data.data;
data.carac[caracName].value = caracValue; // Force update ?
RdDUtility.computeCarac( data );
}
/* -------------------------------------------- */
/* -------------------------------------------- */
rollCompetence( compName ) {
let compItem = RdDUtility.findCompetence( this.data.items, compName);
console.log("Roll !", compItem );
renderTemplate('systems/foundryvtt-reve-de-dragon/templates/dialog-competence.html', compItem).then(dlg =>
let rollData = {
"competence": compItem,
"carac": this.data.data.carac,
"bonusmalusTable": CONFIG.RDD.bonusmalus,
"bmValue": 0,
"finalLevel": 0
}
CONFIG.currentRollData = rollData;
renderTemplate('systems/foundryvtt-reve-de-dragon/templates/dialog-competence.html', rollData).then(dlg =>
{
new Dialog(
{
@ -44,8 +114,8 @@ export class RdDActor extends Actor {
{
rollButton:
{
label: "Lancer"
//callback: html => dialogOptions.callback(html, roll)
label: "Lancer",
callback: html => this.performRoll(html, rollData)
}
},
default: "rollButton"
@ -53,8 +123,7 @@ export class RdDActor extends Actor {
});
}
/* -------------------------------------------- */
/* -------------------------------------------- */
/** @override */
getRollData() {
const data = super.getRollData();

View File

@ -1,7 +1,207 @@
/* Common useful functions shared between objects */
const level_category = {
"generale": "-4",
"particuliere": "-8",
"speciale": "-11",
"connaissance": "-11",
"draconic": "-11",
"melee": "-6",
"tir": "-8",
"lancer": "-8"
}
const carac_array = [ "taille", "apparence", "constitution", "force", "agilite", "dexterite", "vue", "ouie", "odoratgout", "volonte", "intellect", "empathie", "reve", "chance", "melee", "tir", "lancer", "derobee"];
const bonusmalus = [-10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0, +1, +2, +3, +4, +5, +6, +7, +8, +9, +10];
const specialResults = [ { "part": 0, "epart": 0, "etotal": 0 }, // 0
{ "part": 1, "epart": 81, "etotal": 92 }, // 01-05
{ "part": 2, "epart": 82, "etotal": 92 }, // 06-10
{ "part": 3, "epart": 83, "etotal": 93 }, // 11-15
{ "part": 4, "epart": 84, "etotal": 93 }, // 16-20
{ "part": 5, "epart": 85, "etotal": 94 }, // 21-25
{ "part": 6, "epart": 86, "etotal": 94 }, // 26-30
{ "part": 7, "epart": 87, "etotal": 95 }, // 31-35
{ "part": 8, "epart": 88, "etotal": 95 }, // 36-40
{ "part": 9, "epart": 89, "etotal": 96 }, // 41-45
{ "part": 10, "epart": 90, "etotal": 96 }, // 46-50
{ "part": 11, "epart": 91, "etotal": 97 }, // 51-55
{ "part": 12, "epart": 92, "etotal": 97 }, // 56-60
{ "part": 13, "epart": 93, "etotal": 98 }, // 61-65
{ "part": 14, "epart": 94, "etotal": 98 }, // 65-70
{ "part": 15, "epart": 95, "etotal": 99 }, // 71-75
{ "part": 16, "epart": 96, "etotal": 99 }, // 76-80
{ "part": 17, "epart": 97, "etotal": 100 }, // 81-85
{ "part": 18, "epart": 98, "etotal": 100 }, // 86-90
{ "part": 19, "epart": 99, "etotal": 100 }, // 81-95
{ "part": 20, "epart": 100, "etotal": 100 } // 96-00
];
const levelDown = [ { "level": -11, "score": 1, "part": 0, "epart": 2, "etotal": 90 },
{ "level": -12, "score": 1, "part": 0, "epart": 2, "etotal": 70 },
{ "level": -13, "score": 1, "part": 0, "epart": 2, "etotal": 50 },
{ "level": -14, "score": 1, "part": 0, "epart": 2, "etotal": 30 },
{ "level": -15, "score": 1, "part": 0, "epart": 2, "etotal": 10 },
{ "level": -16, "score": 1, "part": 0, "epart": 2, "etotal": 2 },
];
export class RdDUtility {
/* -------------------------------------------- */
static async preloadHandlebarsTemplates( ) {
const templatePaths = [
//Character Sheets
'systems/foundryvtt-reve-de-dragon/templates/actor-sheet.html',
//Items
'systems/foundryvtt-reve-de-dragon/templates/item-competence-sheet.html',
'systems/foundryvtt-reve-de-dragon/templates/competence-categorie.html',
'systems/foundryvtt-reve-de-dragon/templates/competence-carac-defaut.html',
'systems/foundryvtt-reve-de-dragon/templates/competence-base.html',
// Dialogs
'systems/foundryvtt-reve-de-dragon/templates/dialog-competence.html'
];
return loadTemplates(templatePaths);
}
/* -------------------------------------------- */
static buildResolutionTable( ) {
let tableRes = []
for (var j=0; j<=21; j++) {
let subtab = [];
for (var i=-10; i<=22; i++) {
var m = (i + 10) * 0.5;
var v;
if (i == -9) {
v = Math.floor(j / 2);
} else if (i == -10) {
v = Math.floor(j / 4);
} else {
if (j % 2 == 0) {
var v = Math.ceil(j * m);
} else {
var v = Math.floor(j * m);
}
}
if (v < 1) v = 1;
let specResults
if ( v > 100 )
specResults = { "part": Math.ceil(v / 5), "epart": 1000, "etotal": 1000 };
else
specResults = specialResults[Math.ceil(v / 5 )];
let tabIndex = i+10;
subtab[tabIndex] = { "niveau": i, "score": v, "part": specResults.part, "epart": specResults.epart, "etotal": specResults.etotal }
}
tableRes[j] = subtab;
}
return tableRes;
}
/* -------------------------------------------- */
static getLevelCategory( )
{
return level_category;
}
static getCaracArray()
{
return carac_array;
}
static getBonusMalus()
{
return bonusmalus;
}
/* -------------------------------------------- */
static __buildHTMLResolutionHead( dataRow ) {
let r = dataRow;
var row = $("<tr/>");
$.each(r, function(colIndex, c) {
let txt = (c.niveau > 0) ? "+"+c.niveau : c.niveau;
row.append($("<th class='table-resolution-level'/>").text(txt) );
});
return row;
}
/* -------------------------------------------- */
static __buildHTMLResolutionRow( dataRow ) {
let r = dataRow;
var row = $("<tr/>");
$.each(r, function(colIndex, c) {
if ( colIndex == 2 )
row.append($("<td class='table-resolution-carac'/>").text(c.score));
else
row.append($("<td/>").text(c.score));
});
return row;
}
/* -------------------------------------------- */
static makeHTMLResolutionTable(container, minCarac = 1, maxCarac = 21) {
minCarac = (minCarac < 1) ? 1 : minCarac;
maxCarac = (maxCarac > 21) ? 21 : maxCarac;
let data = CONFIG.RDD.resolutionTable;
var table = $("<table/>").addClass('table-resolution');
// Build first row of levels
let row = this.__buildHTMLResolutionHead( data[0] );
table.append(row);
// Then the rest...
for (var rowIndex=minCarac; rowIndex <= maxCarac; rowIndex++) {
let row = this.__buildHTMLResolutionRow( data[rowIndex] );
table.append(row);
}
return container.append(table);
}
/* -------------------------------------------- */
static getResolutionField(caracValue, levelValue )
{
if ( levelValue < -16 ) {
return { "score": 0, "part": 0, "epart": 1, "etotal": 1};
} if ( levelValue < -10 ) {
return levelDown.find(levelData => levelData.level == levelValue);
}
return CONFIG.RDD.resolutionTable[caracValue][levelValue+10];
}
/* -------------------------------------------- */
static computeCarac( data)
{
let fmax = parseInt(data.carac.taille.value) + 4;
if ( data.carac.force.value > fmax )
data.carac.force.value = fmax;
data.carac.derobee.value = Math.floor(parseInt(((21 - data.carac.taille.value)) + parseInt(data.carac.agilite.value)) / 2);
let bonusDomKey = Math.floor( (parseInt(data.carac.force.value) + parseInt(data.carac.taille.value)) / 2);
data.attributs.plusdom.value = 2
if (bonusDomKey < 8)
data.attributs.plusdom.value = -1;
else if (bonusDomKey < 12)
data.attributs.plusdom.value = 0;
else if (bonusDomKey < 14)
data.attributs.plusdom.value = 1;
data.attributs.encombrement.value = (parseInt(data.carac.force.value) + parseInt(data.carac.taille.value)) / 2;
data.carac.melee.value = Math.floor( (parseInt(data.carac.force.value) + parseInt(data.carac.agilite.value)) / 2);
data.carac.tir.value = Math.floor( (parseInt(data.carac.vue.value) + parseInt(data.carac.dexterite.value)) / 2);
data.carac.lancer.value = Math.floor( (parseInt(data.carac.tir.value) + parseInt(data.carac.force.value)) / 2);
data.sante.vie.max = Math.ceil( parseInt(data.carac.taille.value) + parseInt(data.carac.constitution.value) /2 );
let endurance = Math.max( parseInt(data.carac.taille.value) + parseInt(data.carac.constitution.value), parseInt(data.sante.vie.max) + parseInt(data.carac.volonte.value) );
data.sante.endurance.max = endurance;
data.attributs.sconst.value = 5; // Max !
if ( data.carac.constitution.value < 9 )
data.attributs.sconst.value = 2;
else if (data.carac.constitution.value < 12 )
data.attributs.sconst.value = 3;
else if (data.carac.constitution.value < 15 )
data.attributs.sconst.value = 4;
data.attributs.sust.value = 4; // Max !
if ( data.carac.constitution.value < 10 )
data.attributs.sconst.value = 2;
else if (data.carac.constitution.value < 14 )
data.attributs.sconst.value = 3;
}
/* -------------------------------------------- */
static findCompetence(compList, compName)
{
for (const item of compList) {
@ -12,6 +212,4 @@ export class RdDUtility {
}
}
}

View File

@ -5,17 +5,6 @@
*/
/* -------------------------------------------- */
const RDD = {}
RDD.level_category = {
"generale": "-4",
"particuliere": "-8",
"speciale": "-11",
"connaissance": "-11",
"draconic": "-11",
"melee": "-6",
"tir": "-8",
"lancer": "-8"
}
/* -------------------------------------------- */
// Import Modules
@ -24,33 +13,16 @@ import { RdDItemSheet } from "./item-sheet.js";
import { RdDActorSheet } from "./actor-sheet.js";
import { RdDUtility } from "./rdd-utility.js";
/* -------------------------------------------- */
// Handlers management
const preloadHandlebarsTemplates = async function () {
const templatePaths = [
//Character Sheets
'systems/foundryvtt-reve-de-dragon/templates/actor-sheet.html',
//Items
'systems/foundryvtt-reve-de-dragon/templates/item-competence-sheet.html',
'systems/foundryvtt-reve-de-dragon/templates/competence-categorie.html',
'systems/foundryvtt-reve-de-dragon/templates/competence-carac-defaut.html',
'systems/foundryvtt-reve-de-dragon/templates/competence-base.html',
// Dialogs
'systems/foundryvtt-reve-de-dragon/templates/dialog-competence.html'
];
return loadTemplates(templatePaths);
}
/* -------------------------------------------- */
/* Foundry VTT Initialization */
/* -------------------------------------------- */
Hooks.once("init", async function() {
console.log(`Initializing Reve de Dragon System`);
// preload handlebars templates
preloadHandlebarsTemplates();
// preload handlebars templates
RdDUtility.preloadHandlebarsTemplates();
/**
* Set an initiative formula for the system
* @type {String}
@ -62,7 +34,12 @@ Hooks.once("init", async function() {
// Define custom Entity classes
CONFIG.Actor.entityClass = RdDActor;
CONFIG.RDD = RDD;
CONFIG.RDD = {}
CONFIG.RDD.resolutionTable = RdDUtility.buildResolutionTable();
CONFIG.RDD.level_category = RdDUtility.getLevelCategory();
CONFIG.RDD.carac_array = RdDUtility.getCaracArray();
CONFIG.RDD.bonusmalus = RdDUtility.getBonusMalus();
game.data.RdDUtility = RdDUtility;
// Register sheet application classes
Actors.unregisterSheet("core", ActorSheet);