2020-05-21 21:48:20 +02:00
|
|
|
/**
|
|
|
|
* Extend the base Actor entity by defining a custom roll data structure which is ideal for the Simple system.
|
|
|
|
* @extends {Actor}
|
|
|
|
*/
|
2020-05-22 22:37:02 +02:00
|
|
|
|
|
|
|
import { RdDUtility } from "./rdd-utility.js";
|
|
|
|
|
2020-05-22 00:48:43 +02:00
|
|
|
export class RdDActor extends Actor {
|
2020-05-22 22:37:02 +02:00
|
|
|
|
2020-05-24 20:19:57 +02:00
|
|
|
/* -------------------------------------------- */
|
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
}
|
|
|
|
|
2020-05-22 22:37:02 +02:00
|
|
|
/* -------------------------------------------- */
|
|
|
|
|
2020-05-22 00:48:43 +02:00
|
|
|
prepareData() {
|
|
|
|
super.prepareData();
|
2020-05-21 21:48:20 +02:00
|
|
|
|
2020-05-22 00:48:43 +02:00
|
|
|
const actorData = this.data;
|
|
|
|
const data = actorData.data;
|
|
|
|
const flags = actorData.flags;
|
2020-05-22 19:28:01 +02:00
|
|
|
|
2020-05-22 00:48:43 +02:00
|
|
|
// Make separate methods for each Actor type (character, npc, etc.) to keep
|
|
|
|
// things organized.
|
|
|
|
if (actorData.type === 'personnage') this._prepareCharacterData(actorData);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Prepare Character type specific data
|
|
|
|
*/
|
|
|
|
_prepareCharacterData(actorData) {
|
2020-05-24 20:19:57 +02:00
|
|
|
// Initialize empty items
|
|
|
|
RdDUtility.computeCarac(actorData.data);
|
2020-05-22 00:48:43 +02:00
|
|
|
}
|
2020-05-24 20:19:57 +02:00
|
|
|
|
2020-05-22 22:37:02 +02:00
|
|
|
/* -------------------------------------------- */
|
2020-05-24 20:19:57 +02:00
|
|
|
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 );
|
|
|
|
}
|
2020-05-22 22:37:02 +02:00
|
|
|
|
2020-05-24 20:19:57 +02:00
|
|
|
/* -------------------------------------------- */
|
|
|
|
updateCarac( caracName, caracValue )
|
|
|
|
{
|
|
|
|
let data = this.data.data;
|
|
|
|
data.carac[caracName].value = caracValue; // Force update ?
|
|
|
|
RdDUtility.computeCarac( data );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
2020-05-22 22:37:02 +02:00
|
|
|
rollCompetence( compName ) {
|
|
|
|
|
|
|
|
let compItem = RdDUtility.findCompetence( this.data.items, compName);
|
2020-05-24 20:19:57 +02:00
|
|
|
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 =>
|
2020-05-22 22:37:02 +02:00
|
|
|
{
|
|
|
|
new Dialog(
|
|
|
|
{
|
|
|
|
title: "Test de compétence",
|
|
|
|
content: dlg,
|
|
|
|
buttons:
|
|
|
|
{
|
|
|
|
rollButton:
|
|
|
|
{
|
2020-05-24 20:19:57 +02:00
|
|
|
label: "Lancer",
|
|
|
|
callback: html => this.performRoll(html, rollData)
|
2020-05-22 22:37:02 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
default: "rollButton"
|
2020-05-27 21:09:37 +02:00
|
|
|
}, {
|
|
|
|
classes: ["rdddialog"],
|
|
|
|
width: 600,
|
|
|
|
height: 320
|
|
|
|
} ).render(true);
|
2020-05-22 22:37:02 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-05-24 20:19:57 +02:00
|
|
|
/* -------------------------------------------- */
|
2020-05-21 21:48:20 +02:00
|
|
|
/** @override */
|
|
|
|
getRollData() {
|
|
|
|
const data = super.getRollData();
|
2020-05-22 00:48:43 +02:00
|
|
|
const shorthand = game.settings.get("foundryvtt-reve-de-dragon", "macroShorthand");
|
2020-05-21 21:48:20 +02:00
|
|
|
|
|
|
|
// Re-map all attributes onto the base roll data
|
|
|
|
if ( !!shorthand ) {
|
|
|
|
for ( let [k, v] of Object.entries(data.attributes) ) {
|
|
|
|
if ( !(k in data) ) data[k] = v.value;
|
|
|
|
}
|
|
|
|
delete data.attributes;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Map all items data using their slugified names
|
|
|
|
data.items = this.data.items.reduce((obj, i) => {
|
|
|
|
let key = i.name.slugify({strict: true});
|
|
|
|
let itemData = duplicate(i.data);
|
|
|
|
if ( !!shorthand ) {
|
|
|
|
for ( let [k, v] of Object.entries(itemData.attributes) ) {
|
|
|
|
if ( !(k in itemData) ) itemData[k] = v.value;
|
|
|
|
}
|
|
|
|
delete itemData["attributes"];
|
|
|
|
}
|
|
|
|
obj[key] = itemData;
|
|
|
|
return obj;
|
|
|
|
}, {});
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
}
|