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-06-03 21:35:18 +02:00
|
|
|
import { RdDRollDialog } from "./rdd-roll-dialog.js";
|
2020-05-22 22:37:02 +02:00
|
|
|
|
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.
|
|
|
|
*
|
|
|
|
*/
|
2020-06-10 08:23:58 +02:00
|
|
|
|
2020-05-24 20:19:57 +02:00
|
|
|
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);
|
|
|
|
}
|
2020-06-22 10:18:03 +02:00
|
|
|
|
|
|
|
data.items = [];
|
|
|
|
if (data.type == "personnage")
|
|
|
|
{
|
|
|
|
let competences = [];
|
|
|
|
const pack = game.packs.get("foundryvtt-reve-de-dragon.competences");
|
|
|
|
await pack.getIndex().then(index => competences = index);
|
|
|
|
for (let comp of competences)
|
|
|
|
{
|
|
|
|
let compItem = undefined;
|
|
|
|
await pack.getEntity(comp._id).then(skill => compItem = skill);
|
|
|
|
data.items.push(compItem);
|
|
|
|
}
|
|
|
|
}
|
2020-05-24 20:19:57 +02:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2020-06-03 21:35:18 +02:00
|
|
|
/* -------------------------------------------- */
|
2020-05-22 00:48:43 +02:00
|
|
|
/**
|
|
|
|
* Prepare Character type specific data
|
|
|
|
*/
|
|
|
|
_prepareCharacterData(actorData) {
|
2020-05-24 20:19:57 +02:00
|
|
|
// Initialize empty items
|
|
|
|
RdDUtility.computeCarac(actorData.data);
|
2020-06-07 23:16:29 +02:00
|
|
|
this.computeEtatGeneral();
|
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-06-07 23:16:29 +02:00
|
|
|
async performRoll( rollData ) {
|
|
|
|
|
2020-05-24 20:19:57 +02:00
|
|
|
let myroll = new Roll("d100");
|
|
|
|
myroll.roll();
|
|
|
|
let quality = "Echec";
|
2020-06-01 23:50:10 +02:00
|
|
|
let xpmsg = "";
|
2020-05-24 20:19:57 +02:00
|
|
|
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!";
|
2020-06-01 23:50:10 +02:00
|
|
|
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;
|
|
|
|
}
|
2020-06-07 23:16:29 +02:00
|
|
|
rollData.pointsDeTache = 4;
|
2020-06-10 08:23:58 +02:00
|
|
|
rollData.qualite = 2;
|
2020-05-24 20:19:57 +02:00
|
|
|
} else if (result <= (rollData.rollTarget.score /2) ) {
|
|
|
|
quality = "Réussite Significative";
|
2020-06-07 23:16:29 +02:00
|
|
|
rollData.pointsDeTache = 2;
|
2020-06-10 08:23:58 +02:00
|
|
|
rollData.qualite = 1;
|
2020-05-24 20:19:57 +02:00
|
|
|
} else if (result <= (rollData.rollTarget.score) ) {
|
|
|
|
quality = "Réussite Normale";
|
2020-06-07 23:16:29 +02:00
|
|
|
rollData.pointsDeTache = 1;
|
2020-06-10 08:23:58 +02:00
|
|
|
rollData.qualite = 0;
|
2020-05-24 20:19:57 +02:00
|
|
|
} else if (result < (rollData.rollTarget.epart) ) {
|
|
|
|
quality = "Echec Normal";
|
2020-06-07 23:16:29 +02:00
|
|
|
rollData.pointsDeTache = 0;
|
2020-06-10 08:23:58 +02:00
|
|
|
rollData.qualite = -2;
|
2020-05-24 20:19:57 +02:00
|
|
|
} else if (result < (rollData.rollTarget.etotal) ) {
|
|
|
|
quality = "Echec Particulier";
|
2020-06-07 23:16:29 +02:00
|
|
|
rollData.pointsDeTache = -2;
|
2020-06-10 08:23:58 +02:00
|
|
|
rollData.qualite = -4;
|
2020-05-24 20:19:57 +02:00
|
|
|
} else if (result >= (rollData.rollTarget.etotal) ) {
|
|
|
|
quality = "Echec Total";
|
2020-06-07 23:16:29 +02:00
|
|
|
rollData.pointsDeTache = -4;
|
2020-06-10 08:23:58 +02:00
|
|
|
rollData.qualite = -6;
|
2020-05-24 20:19:57 +02:00
|
|
|
}
|
|
|
|
|
2020-06-12 11:47:41 +02:00
|
|
|
// Manage weapon categories when parrying (cf. page 115 )
|
|
|
|
let need_significative = false; // Do we need to have a sgnificative ?
|
|
|
|
let need_resist = false; // Do we need to have a sgnificative ?
|
|
|
|
if ( rollData.arme && rollData.attackerRoll ) { // Manage parade depeding on weapon type, and change roll results
|
|
|
|
let attCategory = RdDUtility.getArmeCategory( rollData.attackerRoll.arme );
|
|
|
|
let defCategory = RdDUtility.getArmeCategory( rollData.arme );
|
|
|
|
if ( defCategory == "bouclier" )
|
|
|
|
need_significative = true;
|
|
|
|
else if ( attCategory != defCategory )
|
|
|
|
need_significative = true;
|
|
|
|
if ( attCategory.match("epee") && ( defCategory == "hache" || defCategory == "lance") )
|
|
|
|
need_resist = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sonne management or if need_significative is set
|
|
|
|
if ( this.data.data.sante.sonne.value || need_significative) {
|
|
|
|
if (rollData.pointsDeTache >= 2 ) { // Reussite normale dès que significative
|
|
|
|
quality = "Réussite Normale";
|
|
|
|
rollData.pointsDeTache = 1;
|
|
|
|
rollData.qualite = 0;
|
|
|
|
} else if (rollData.pointsDeTache < 2 ) { // Not a "significative"
|
|
|
|
quality = "Echec Normal";
|
|
|
|
rollData.pointsDeTache = 0;
|
|
|
|
rollData.qualite = -2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-10 08:23:58 +02:00
|
|
|
// Fight management !
|
2020-06-07 23:16:29 +02:00
|
|
|
let defenseMsg;
|
2020-06-11 00:29:32 +02:00
|
|
|
let encaisser = false;
|
2020-06-07 23:16:29 +02:00
|
|
|
let specialStr = "<br>Points de taches : " + rollData.pointsDeTache; // Per default
|
2020-06-12 11:47:41 +02:00
|
|
|
if ( rollData.arme ) { // In case of fight, replace the "tache" message per dommages + localization. "tache" indicates if result is OK or not
|
|
|
|
if ( rollData.attackerRoll) { // Defense case !
|
2020-06-11 00:29:32 +02:00
|
|
|
if ( rollData.pointsDeTache > 0 ) { // Réussite !
|
|
|
|
specialStr = "<br><strong>Attaque parée/esquivée !</strong>";
|
|
|
|
} else {
|
|
|
|
specialStr = "<br><strong>Esquive/Parade échouée, encaissement !</strong>";
|
|
|
|
encaisser = true;
|
|
|
|
}
|
2020-06-17 20:31:43 +02:00
|
|
|
} else { // This is the attack roll!
|
2020-06-11 00:29:32 +02:00
|
|
|
if ( rollData.pointsDeTache > 0 ) {
|
|
|
|
let myroll = new Roll("2d10");
|
|
|
|
myroll.roll();
|
2020-06-24 00:22:40 +02:00
|
|
|
rollData.domArmePlusDom = parseInt(rollData.arme.data.dommages);
|
2020-06-17 20:31:43 +02:00
|
|
|
if ( rollData.selectedCarac.label == "Mêlée" ) // +dom only for Melee
|
2020-06-24 00:22:40 +02:00
|
|
|
rollData.domArmePlusDom += parseInt(this.data.data.attributs.plusdom.value);
|
2020-06-17 20:31:43 +02:00
|
|
|
if ( rollData.selectedCarac.label == "Lancer" ) { // +dom only for Melee/Lancer
|
|
|
|
let bdom = parseInt(this.data.data.attributs.plusdom.value);
|
|
|
|
if ( bdom > parseInt(rollData.arme.data.dommages)*2 )
|
|
|
|
bdom = parseInt(rollData.arme.data.dommages)*2;
|
2020-06-24 00:22:40 +02:00
|
|
|
rollData.domArmePlusDom += bdom
|
2020-06-17 20:31:43 +02:00
|
|
|
}
|
2020-06-24 00:22:40 +02:00
|
|
|
rollData.degats = parseInt(myroll.result) + rollData.domArmePlusDom;
|
2020-06-11 00:29:32 +02:00
|
|
|
rollData.loc = RdDUtility.getLocalisation();
|
|
|
|
for (let target of game.user.targets) {
|
|
|
|
defenseMsg = RdDUtility.buildDefenseChatCard(this, target, rollData );
|
|
|
|
specialStr = "<br><strong>Cible</strong> : " + target.actor.data.name;
|
|
|
|
}
|
|
|
|
specialStr += "<br>Dommages : " + rollData.degats + "<br>Localisation : " + rollData.loc.label;
|
|
|
|
} else {
|
|
|
|
specialStr = "<br>Echec ! Pas de dommages";
|
2020-06-07 23:16:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-06-11 00:29:32 +02:00
|
|
|
|
2020-06-07 23:16:29 +02:00
|
|
|
// Save it for fight
|
|
|
|
await this.setFlag( "foundryvtt-reve-de-dragon", "rollData", undefined );
|
|
|
|
await this.setFlag( "foundryvtt-reve-de-dragon", "rollData", rollData );
|
|
|
|
|
2020-06-12 22:46:04 +02:00
|
|
|
let lvl = (rollData.competence) ? rollData.competence.name : rollData.bmValue;
|
|
|
|
let chatOptions = { content: "<strong>Test : " + rollData.selectedCarac.label + " / " + lvl + "</strong><br>Jet : " +
|
2020-06-17 20:31:43 +02:00
|
|
|
rollData.selectedCarac.value + " / " + rollData.finalLevelStr + " -> " + rollData.rollTarget.score + "%<br><strong>Résutat : </strong>" + myroll.total + "<br>" +
|
2020-06-07 23:16:29 +02:00
|
|
|
"<strong>" + quality + "</strong>" + specialStr + xpmsg,
|
|
|
|
user: game.user._id,
|
|
|
|
title: "Résultat du test"
|
2020-05-24 20:19:57 +02:00
|
|
|
}
|
|
|
|
ChatMessage.create( chatOptions );
|
2020-06-07 23:16:29 +02:00
|
|
|
|
2020-06-11 00:29:32 +02:00
|
|
|
// This an attack, generate the defense message
|
2020-06-07 23:16:29 +02:00
|
|
|
if ( defenseMsg ) { // target hit !
|
2020-06-22 10:18:03 +02:00
|
|
|
ChatMessage.create( defenseMsg );
|
2020-06-11 00:29:32 +02:00
|
|
|
}
|
|
|
|
// Get damages!
|
|
|
|
if ( encaisser ) {
|
2020-06-22 10:18:03 +02:00
|
|
|
this.encaisserDommages( rollData.attackerRoll );
|
2020-06-11 00:29:32 +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
|
|
|
/* -------------------------------------------- */
|
|
|
|
updateCarac( caracName, caracValue )
|
|
|
|
{
|
2020-06-07 23:16:29 +02:00
|
|
|
let caracpath = "data.carac." + caracName + ".value"
|
|
|
|
this.update( { caracpath: caracValue } );
|
2020-05-24 20:19:57 +02:00
|
|
|
}
|
2020-05-28 23:36:09 +02:00
|
|
|
|
2020-06-01 23:50:10 +02:00
|
|
|
/* -------------------------------------------- */
|
|
|
|
async updateCompetence( compName, compValue )
|
|
|
|
{
|
|
|
|
let comp = RdDUtility.findCompetence( this.data.items, compName);
|
|
|
|
if ( comp ) {
|
|
|
|
const update = {_id: comp._id, 'data.niveau': compValue };
|
|
|
|
const updated = await this.updateEmbeddedEntity("OwnedItem", update); // Updates one EmbeddedEntity
|
2020-06-12 22:46:04 +02:00
|
|
|
} else {
|
|
|
|
console.log("Competence not found", compName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
async updateCompetenceXP( compName, compValue )
|
|
|
|
{
|
|
|
|
let comp = RdDUtility.findCompetence( this.data.items, compName);
|
|
|
|
if ( comp ) {
|
|
|
|
const update = {_id: comp._id, 'data.xp': compValue };
|
|
|
|
const updated = await this.updateEmbeddedEntity("OwnedItem", update); // Updates one EmbeddedEntity
|
2020-06-01 23:50:10 +02:00
|
|
|
} else {
|
|
|
|
console.log("Competence not found", compName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-29 00:43:16 +02:00
|
|
|
/* -------------------------------------------- */
|
|
|
|
computeEtatGeneral( )
|
|
|
|
{
|
|
|
|
let data = this.data.data;
|
|
|
|
let state = 0;
|
|
|
|
state = state - (data.sante.vie.max - data.sante.vie.value);
|
|
|
|
state = state + RdDUtility.currentFatigueMalus(data.sante.fatigue.value, data.sante.endurance.max);
|
|
|
|
data.compteurs.etat.value = state;
|
|
|
|
}
|
|
|
|
|
2020-05-31 23:06:25 +02:00
|
|
|
/* -------------------------------------------- */
|
2020-06-07 23:16:29 +02:00
|
|
|
testSiSonne( sante, endurance )
|
2020-05-31 23:06:25 +02:00
|
|
|
{
|
|
|
|
let myroll = new Roll("d20");
|
|
|
|
myroll.roll();
|
|
|
|
let result = myroll.total;
|
|
|
|
if ( result <= endurance.value)
|
2020-06-07 23:16:29 +02:00
|
|
|
sante.sonne.value = false;
|
2020-05-31 23:06:25 +02:00
|
|
|
if ( result > endurance.value || result == 20) // 20 is always a failure
|
2020-06-07 23:16:29 +02:00
|
|
|
sante.sonne.value = true;
|
2020-05-31 23:06:25 +02:00
|
|
|
if (result == 1) {
|
2020-06-07 23:16:29 +02:00
|
|
|
sante.sonne.value = false;
|
|
|
|
let xp = parseInt(this.data.data.carac.constitution.xp) + parseInt(1);
|
|
|
|
this.update( {"data.carac.constitution.xp": xp } ); // +1 XP !
|
|
|
|
// TODO : Output to chat
|
2020-05-31 23:06:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-28 23:36:09 +02:00
|
|
|
/* -------------------------------------------- */
|
2020-06-07 23:16:29 +02:00
|
|
|
async santeIncDec(name, inc ) {
|
|
|
|
const sante = duplicate(this.data.data.sante);
|
|
|
|
let data = sante[name];
|
2020-05-31 23:06:25 +02:00
|
|
|
let lastValue = data.value; // Useful for Endurance and Sonné
|
2020-05-28 23:36:09 +02:00
|
|
|
data.value = data.value + inc;
|
|
|
|
if ( data.value > data.max ) data.value = data.max;
|
|
|
|
if ( data.value < 0 ) data.value = 0;
|
2020-05-31 23:06:25 +02:00
|
|
|
|
|
|
|
if (name == "endurance") {
|
|
|
|
if ( inc < 0 ) // Each endurance lost -> fatigue lost
|
2020-06-07 23:16:29 +02:00
|
|
|
sante.fatigue.value = sante.fatigue.value - inc
|
2020-05-31 23:06:25 +02:00
|
|
|
|
|
|
|
// If endurance is 0 -> -1 vie
|
2020-06-12 11:47:41 +02:00
|
|
|
if ( data.value == 0 && sante.vie.value > 0) {
|
2020-06-07 23:16:29 +02:00
|
|
|
sante.vie.value = sante.vie.value - 1;
|
2020-05-31 23:06:25 +02:00
|
|
|
}
|
2020-06-07 23:16:29 +02:00
|
|
|
let diffVie = sante.vie.max - sante.vie.value;
|
2020-06-01 23:50:10 +02:00
|
|
|
if ( data.value > data.max - (diffVie*2) ) {
|
|
|
|
data.value = data.max - (diffVie*2);
|
2020-05-31 23:06:25 +02:00
|
|
|
}
|
2020-06-12 11:47:41 +02:00
|
|
|
if ( data.value < 0 ) data.value = 0; // Security
|
2020-05-31 23:06:25 +02:00
|
|
|
|
|
|
|
let blessures = this.data.data.blessures;
|
|
|
|
let maxEnd = Math.floor( data.max / blessures.graves.nombre);
|
|
|
|
if (data.value > maxEnd ) data.value = maxEnd;
|
|
|
|
if ( blessures.critiques.nombre > 0 && data.value > 1) data.value = 1;
|
|
|
|
|
2020-06-07 23:16:29 +02:00
|
|
|
if (lastValue - data.value > 1) this.testSiSonne(sante, data); // Peut-être sonné si 2 points d'endurance perdus d'un coup
|
2020-05-31 23:06:25 +02:00
|
|
|
}
|
2020-06-12 11:47:41 +02:00
|
|
|
console.log(name, inc, data.value);
|
2020-06-01 23:50:10 +02:00
|
|
|
|
2020-06-07 23:16:29 +02:00
|
|
|
let diffEndurance = sante.endurance.max - this.data.data.sante.endurance.value;
|
|
|
|
if ( sante.fatigue.value < diffEndurance) // If endurance lost, then the same amount of fatigue cannot be recovered
|
|
|
|
sante.fatigue.value = diffEndurance;
|
2020-06-12 11:47:41 +02:00
|
|
|
console.log("SANTE::::", sante);
|
2020-06-07 23:16:29 +02:00
|
|
|
|
|
|
|
await this.update( {"data.sante": sante } );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
manageBlessures( blessuresData )
|
|
|
|
{
|
2020-06-22 10:18:03 +02:00
|
|
|
if ( blessuresData.legeres > 0 || blessuresData.graves > 0 || blessuresData.critiques > 0 ) {
|
|
|
|
let blessures = duplicate(this.data.data.blessures);
|
|
|
|
while ( blessuresData.legeres > 0 ) {
|
|
|
|
let nLegeres = 0;
|
|
|
|
for (let k=0; k<blessures.legeres.liste.length; k++) {
|
|
|
|
let bless = blessures.legeres.liste[k];
|
|
|
|
if ( !bless.active ) {
|
|
|
|
bless.active = true;
|
|
|
|
bless.loc = blessuresData.locName;
|
|
|
|
blessuresData.legeres--;
|
|
|
|
} else {
|
|
|
|
nLegeres++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( nLegeres == 5) break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( blessuresData.legeres > 0 )
|
2020-06-07 23:16:29 +02:00
|
|
|
blessuresData.graves += 1;
|
2020-06-22 10:18:03 +02:00
|
|
|
|
|
|
|
|
|
|
|
while ( blessuresData.graves > 0) {
|
|
|
|
let nGraves = 0;
|
|
|
|
for (let k=0; k<blessures.graves.liste.length; k++) {
|
|
|
|
let bless = blessures.graves.liste[k];
|
|
|
|
if ( !bless.active ) {
|
|
|
|
bless.active = true;
|
|
|
|
bless.loc = blessuresData.locName;
|
|
|
|
blessuresData.graves--;
|
|
|
|
} else {
|
|
|
|
nGraves++;
|
|
|
|
}
|
|
|
|
}
|
2020-06-24 00:22:40 +02:00
|
|
|
if ( nGraves == 2) break;
|
2020-06-22 10:18:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( blessuresData.graves > 0 )
|
|
|
|
blessuresData.critiques = 1;
|
|
|
|
|
|
|
|
if ( blessuresData.critiques > 0 ) {
|
|
|
|
blessuresData.endurance = this.data.data.sante.endurance.value; // Patch with real endurance current value (ie end -> 0 when critique)
|
|
|
|
blessures.critiques.liste[0].active = true;
|
|
|
|
blessures.critiques.liste[0].loc = blessuresData.locName;
|
|
|
|
}
|
|
|
|
|
2020-06-07 23:16:29 +02:00
|
|
|
this.update( { "data.blessures": blessures } );
|
2020-06-22 10:18:03 +02:00
|
|
|
}
|
2020-05-28 23:36:09 +02:00
|
|
|
}
|
2020-06-22 10:18:03 +02:00
|
|
|
|
2020-06-12 22:46:04 +02:00
|
|
|
/* -------------------------------------------- */
|
|
|
|
async rollCarac( caracName )
|
|
|
|
{
|
|
|
|
let rollData = {
|
|
|
|
"selectedCarac": this.data.data.carac[caracName],
|
|
|
|
"bonusmalusTable": CONFIG.RDD.bonusmalus,
|
|
|
|
"etat": this.data.data.compteurs.etat.value,
|
|
|
|
"finalLevel": 0,
|
|
|
|
"bmValue": 0
|
|
|
|
}
|
|
|
|
console.log(caracName, rollData);
|
|
|
|
let html = await renderTemplate('systems/foundryvtt-reve-de-dragon/templates/dialog-roll-carac.html', rollData);
|
|
|
|
new RdDRollDialog("carac", html, rollData, this ).render(true);
|
|
|
|
}
|
|
|
|
|
2020-06-01 23:50:10 +02:00
|
|
|
/* -------------------------------------------- */
|
2020-06-10 08:23:58 +02:00
|
|
|
rollArme( armeName )
|
|
|
|
{
|
2020-06-07 23:16:29 +02:00
|
|
|
let armeItem = RdDUtility.findCompetence( this.data.items, armeName );
|
2020-06-10 08:23:58 +02:00
|
|
|
if ( armeItem && armeItem.data.competence )
|
|
|
|
this.rollCompetence( armeItem.data.competence, armeItem );
|
|
|
|
else
|
|
|
|
this.rollCompetence( armeName ); //Bypass mode!
|
2020-06-01 23:50:10 +02:00
|
|
|
}
|
|
|
|
|
2020-05-24 20:19:57 +02:00
|
|
|
/* -------------------------------------------- */
|
2020-06-11 00:29:32 +02:00
|
|
|
async rollCompetence( compName, armeItem=undefined, attackerRoll=undefined )
|
2020-06-10 08:23:58 +02:00
|
|
|
{
|
|
|
|
console.log("!!!!!!", compName, armeItem);
|
2020-05-22 22:37:02 +02:00
|
|
|
let compItem = RdDUtility.findCompetence( this.data.items, compName);
|
2020-05-24 20:19:57 +02:00
|
|
|
let rollData = {
|
|
|
|
"competence": compItem,
|
2020-06-03 21:35:18 +02:00
|
|
|
"arme": armeItem,
|
2020-05-24 20:19:57 +02:00
|
|
|
"carac": this.data.data.carac,
|
|
|
|
"bonusmalusTable": CONFIG.RDD.bonusmalus,
|
2020-06-01 23:50:10 +02:00
|
|
|
"etat": this.data.data.compteurs.etat.value,
|
2020-06-12 11:47:41 +02:00
|
|
|
"bmValue": (attackerRoll) ? attackerRoll.bmValue : 0,
|
2020-06-11 00:29:32 +02:00
|
|
|
"attackerRoll": attackerRoll,
|
2020-05-24 20:19:57 +02:00
|
|
|
"finalLevel": 0
|
|
|
|
}
|
2020-06-07 23:16:29 +02:00
|
|
|
|
2020-06-03 21:35:18 +02:00
|
|
|
let html = await renderTemplate('systems/foundryvtt-reve-de-dragon/templates/dialog-competence.html', rollData);
|
2020-06-07 23:16:29 +02:00
|
|
|
if (armeItem) {
|
|
|
|
new RdDRollDialog("arme", html, rollData, this ).render(true);
|
|
|
|
} else {
|
|
|
|
new RdDRollDialog("competence", html, rollData, this ).render(true);
|
|
|
|
}
|
2020-05-22 22:37:02 +02:00
|
|
|
}
|
2020-06-07 23:16:29 +02:00
|
|
|
|
2020-06-23 23:34:12 +02:00
|
|
|
/* -------------------------------------------- */
|
|
|
|
equiperObjet( itemID )
|
|
|
|
{
|
|
|
|
let item = this.getOwnedItem(itemID);
|
2020-06-24 00:22:40 +02:00
|
|
|
if ( item && item.data.data ) {
|
|
|
|
let update = duplicate(item);
|
|
|
|
update.data.equipe = !update.data.equipe;
|
|
|
|
this.updateEmbeddedEntity("OwnedItem", update);
|
|
|
|
}
|
2020-06-23 23:34:12 +02:00
|
|
|
}
|
|
|
|
|
2020-06-07 23:16:29 +02:00
|
|
|
/* -------------------------------------------- */
|
2020-06-24 00:22:40 +02:00
|
|
|
computeArmure( locData, domArmePlusDom )
|
2020-06-07 23:16:29 +02:00
|
|
|
{
|
2020-06-23 23:34:12 +02:00
|
|
|
let protection = 0;
|
|
|
|
for (const item of this.data.items) {
|
|
|
|
if (item.type == "armure" && item.data.equipe) {
|
2020-06-24 00:22:40 +02:00
|
|
|
let update = duplicate(item);
|
|
|
|
let myroll = new Roll(update.data.protection.toString());
|
|
|
|
myroll.roll();
|
|
|
|
protection += myroll.total;
|
|
|
|
update.data.deterioration += domArmePlusDom;
|
|
|
|
domArmePlusDom = 0; // Reset it
|
|
|
|
if ( update.data.deterioration >= 10) {
|
|
|
|
update.data.deterioration = 0;
|
|
|
|
if ( update.data.protection.toString().length == 1 )
|
|
|
|
update.data.protection = "d"+update.data.protection+"-0";
|
|
|
|
else {
|
|
|
|
let regex = /d\(d+)\-(\d+)/g;
|
|
|
|
let res = regex.exec( update.data.protection );
|
|
|
|
update.data.protection = "d"+res[1]+"-"+(parseInt(res[2])+1);
|
|
|
|
}
|
|
|
|
/* TODO - POST chat message */
|
|
|
|
}
|
|
|
|
this.updateEmbeddedEntity("OwnedItem", update);
|
2020-06-23 23:34:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
console.log("Final protect", protection);
|
|
|
|
return protection;
|
2020-06-07 23:16:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
2020-06-22 10:18:03 +02:00
|
|
|
encaisserDommages( attackerRoll )
|
2020-06-11 00:29:32 +02:00
|
|
|
{
|
2020-06-22 10:18:03 +02:00
|
|
|
//let attackerRoll = rollData.attackerRoll;
|
2020-06-24 00:22:40 +02:00
|
|
|
let degatsReel = attackerRoll.degats - this.computeArmure(attackerRoll.loc, attackerRoll.domArmePlusDom);
|
2020-06-22 10:18:03 +02:00
|
|
|
console.log("RollData from attacker!", attackerRoll, degatsReel);
|
|
|
|
|
2020-06-07 23:16:29 +02:00
|
|
|
let result = RdDUtility.computeBlessuresSante(degatsReel);
|
|
|
|
this.santeIncDec("vie", result.vie);
|
2020-06-22 10:18:03 +02:00
|
|
|
this.santeIncDec("endurance", result.endurance);
|
2020-06-07 23:16:29 +02:00
|
|
|
|
|
|
|
result.locName = attackerRoll.loc.label; // Add the localisation namme
|
|
|
|
this.manageBlessures( result ); // Will upate the result table
|
|
|
|
ChatMessage.create( {title: "Blessures !", content: this.data.name + " a encaissé : " +
|
|
|
|
"<br>" + result.legeres + " légères, " + result.graves + " graves et " +
|
|
|
|
result.critiques + " critique." +
|
|
|
|
"<br>Et perdu : " +
|
|
|
|
"<br>" + result.endurance + " Endurance et " + result.vie + " Points de Vie" } );
|
|
|
|
|
|
|
|
this.computeEtatGeneral();
|
|
|
|
this.sheet.render(true);
|
|
|
|
}
|
|
|
|
|
2020-06-10 08:23:58 +02:00
|
|
|
/* -------------------------------------------- */
|
2020-06-11 00:29:32 +02:00
|
|
|
parerAttaque( attackerRoll, armeId )
|
2020-06-10 08:23:58 +02:00
|
|
|
{
|
2020-06-11 00:29:32 +02:00
|
|
|
let armeItem = this.getOwnedItem(armeId); // Item.data.data !
|
|
|
|
console.log("Going to PARY !!!!!!!!!", armeItem, attackerRoll.bmValue);
|
|
|
|
this.rollCompetence( armeItem.data.data.competence, armeItem.data, attackerRoll );
|
2020-06-10 08:23:58 +02:00
|
|
|
}
|
|
|
|
|
2020-05-24 20:19:57 +02:00
|
|
|
/* -------------------------------------------- */
|
2020-05-21 21:48:20 +02:00
|
|
|
/** @override */
|
|
|
|
getRollData() {
|
|
|
|
const data = super.getRollData();
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
}
|