Séparation compétences/combat

This commit is contained in:
Vincent Vandemeulebrouck 2020-12-08 03:04:00 +01:00
parent 399a7b2d30
commit 468c699f70
7 changed files with 114 additions and 29 deletions

View File

@ -128,7 +128,7 @@ export class RdDActorCreatureSheet extends ActorSheet {
// Roll Skill
html.find('.competence-label a').click((event) => {
let compName = event.currentTarget.text;
this.actor.rollCompetence( compName );
this.actor.rollCompetenceCreature( compName );
});
html.find('#vie-plus').click((event) => {

View File

@ -95,7 +95,7 @@ export class RdDActorEntiteSheet extends ActorSheet {
// Roll Skill
html.find('.competence-label a').click((event) => {
let compName = event.currentTarget.text;
this.actor.rollCompetence( compName );
this.actor.rollCompetenceCreature( compName );
});
html.find('#endurance-plus').click((event) => {

View File

@ -286,7 +286,7 @@ export class RdDActorSheet extends ActorSheet {
html.find('.arme-label a').click((event) => {
let armeName = event.currentTarget.text;
let competenceName = event.currentTarget.attributes['data-competence-name'].value;
this.actor.rollArme( armeName, competenceName);
this.actor.rollArme(competenceName, armeName);
});
// Initiative pour l'arme
html.find('.arme-initiative a').click((event) => {

View File

@ -16,6 +16,7 @@ import { RdDDice } from "./rdd-dice.js";
import { RdDRollTables } from "./rdd-rolltables.js";
import { ChatUtility } from "./chat-utility.js";
import { RdDItemSort } from "./item-sort.js";
import { Grammar } from "./grammar.js";
export class RdDActor extends Actor {
@ -1375,15 +1376,17 @@ export class RdDActor extends Actor {
}
/* -------------------------------------------- */
async rollCarac( caracName )
{
let rollData = { selectedCarac: this.getCaracByName(caracName) };
async rollCarac( caracName ) {
let rollData = {
selectedCarac: this.getCaracByName(caracName),
needSignificative : !this.isEntiteCauchemar() && this.data.data.sante.sonne.value
};
const dialog = await RdDRoll.create(this, rollData,
{html: 'systems/foundryvtt-reve-de-dragon/templates/dialog-roll-carac.html'},
{
name: 'jet-'+caracName,
label: 'Lancer : '+rollData.selectedCarac.label,
label: 'Jet ' + Grammar.apostrophe('de', rollData.selectedCarac.label),
callbacks: [
this._createCallbackExperience(),
{ action: this._rollCaracResult }
@ -1410,6 +1413,45 @@ export class RdDActor extends Actor {
ChatUtility.chatWithRollMode(chatOptions, this.name)
}
/* -------------------------------------------- */
async rollCompetence( name ) {
let rollData = {
competence: duplicate(RdDUtility.findCompetence( this.data.items, name)),
needSignificative : !this.isEntiteCauchemar() && this.data.data.sante.sonne.value
}
if (rollData.competence.type == 'competencecreature') {
// Fake competence pour créature
mergeObject(rollData.competence, { data : { defaut_carac: "carac_creature", categorie: "creature" } });
rollData.carac = { carac_creature: { label: competence.name, value: competence.data.carac_value } };
}
else{
rollData.carac = this.data.data.carac;
}
console.log("rollCompetence !!!", rollData.competence);
const dialog = await RdDRoll.create(this, rollData,
{html: 'systems/foundryvtt-reve-de-dragon/templates/dialog-competence.html'},
{
name: 'jet-competence',
label: 'Jet ' +Grammar.apostrophe('de', name),
callbacks: [
this._createCallbackExperience(),
{ action: this._competenceResult }
]
}
);
dialog.render(true);
}
_competenceResult(rollData) {
ChatUtility.chatWithRollMode({
content: "<strong>Test : " + rollData.selectedCarac.label + " / " + rollData.competence.name + "</strong>"
+ "<br>Difficultés <strong>libre : " + rollData.diffLibre + "</strong> / conditions : " + Misc.toSignedString(rollData.diffConditions) +" / état : " + rollData.etat
+ RdDResolutionTable.explain(rollData.rolled)
+ "<br>Points de taches : " + rollData.rolled.ptTache + ", ajustement qualité: " + rollData.rolled.ptQualite
}, this.name)
}
/* -------------------------------------------- */
async rollAppelChance( )
@ -1525,29 +1567,52 @@ export class RdDActor extends Actor {
this.currentTMR = new RdDTMRDialog(html, this, data, mode);
this.currentTMR.render(true);
}
/* -------------------------------------------- */
rollArme( armeName, competenceName=undefined ) {
let armeItem = this.data.items.find(item=>item.type==="arme" && (item.name === armeName));
if (armeItem ) {
if ( competenceName == undefined) competenceName = armeItem.data.competence;
this.rollCompetence( competenceName, armeItem );
} else {
this.rollCompetence( armeName ); //Bypass mode!
async rollCompetenceCreature( compName ) {
let competence = RdDUtility.findCompetence( this.data.items, compName);
if ( competence.type == 'competencecreature' && competence.data.iscombat ) {
armeItem = { name: compName, data: { dommages: competence.data.dommages, dommagesReels: competence.data.dommages} };
this.rollCompetenceCombat(competence, armeItem);
}
else {
this.rollCompetence(name);
}
}
/* -------------------------------------------- */
async rollCompetence( name, armeItem=undefined, attackerRoll=undefined, attacker = undefined) {
rollArme(competenceName, armeName) {
let armeItem = this.data.items.find(item=>item.type==="arme" && (item.name === armeName));
if (armeItem && competenceName == undefined) competenceName = armeItem.data.competence;
let competence = RdDUtility.findCompetence(this.data.items, competenceName == undefined? armeName : competenceName);
if (armeItem==undefined && competence.type == 'competencecreature' && competence.data.iscombat ) {
armeItem = { name: name, data: { dommages: competence.data.dommages, dommagesReels: competence.data.dommages} };
}
if (armeItem || armeName) {
this.rollCompetenceCombat( competenceName, armeItem );
} else {
this.rollCompetence( competence.name );
}
}
/* -------------------------------------------- */
async rollCompetenceCombat( name, armeItem=undefined, attackerRoll=undefined, attacker = undefined) {
let competence = RdDUtility.findCompetence( this.data.items, name);
console.log("rollCompetence !!!", competence, armeItem, attackerRoll);
if ( competence.type == 'competencecreature' && competence.data.iscombat ) {
armeItem = { name: name, data: { dommages: competence.data.dommages, dommagesReels: competence.data.dommages} };
}
console.log("rollCompetenceCombat !!!", competence, armeItem, attackerRoll);
// Common rollData values
let rollData = {
ajustementsConditions: CONFIG.RDD.ajustementsConditions,
difficultesLibres: CONFIG.RDD.difficultesLibres,
etat: this.data.data.compteurs.etat.value,
diffConditions: 0,
forceValue : (this.data.data.carac.force) ? this.data.data.carac.force.value : 0, // Utilisé pour le jet de recul
forceValue : attackerRoll ? (this.data.data.carac.force ? this.data.data.carac.force.value : this.data.data.carac.reve.value) : 0, // Utilisé pour le jet de recul
diffLibre: (attackerRoll) ? attackerRoll.diffLibre : 0,
attackerRoll: attackerRoll,
finalLevel: 0,
@ -1561,7 +1626,7 @@ export class RdDActor extends Actor {
encValueForNatation: 0
}
if ( this.type == 'personnage ') {
rollData.malusArmureValue = (this.data.data.attributs) ? this.data.data.attributs.malusarmure.value : 0;
rollData.malusArmureValue = (this.data.data.attributs && this.data.data.attributs.malusarmure) ? this.data.data.attributs.malusarmure.value : 0,
rollData.surencMalusFlag = (this.data.data.compteurs.surenc.value < 0);
rollData.surencMalusValue = this.data.data.compteurs.surenc.value;
rollData.surencMalusApply = false;
@ -1571,9 +1636,6 @@ export class RdDActor extends Actor {
}
if ( competence.type == 'competencecreature') { // Specific case for Creatures
if ( competence.data.iscombat ) {
armeItem = { name: name, data: { dommages: competence.data.dommages, dommagesReels: competence.data.dommages} };
}
competence.data.defaut_carac = "carac_creature"; // Fake default competence
competence.data.categorie = "creature"; // Fake default competence
rollData.competence = competence;
@ -1705,17 +1767,21 @@ export class RdDActor extends Actor {
{
let armeItem = this.getOwnedItem(armeId); // Item.data.data !
console.log("Going to PARY !!!!!!!!!", armeItem, attackerRoll.diffLibre);
<<<<<<< HEAD
if (armeItem.type == 'competencecreature') {
this.rollCompetence( armeItem.name, armeItem.data, attackerRoll, attacker);
} else {
this.rollCompetence( armeItem.data.data.competence, armeItem.data, attackerRoll, attacker);
}
=======
this.rollCompetenceCombat( armeItem.data.data.competence, armeItem.data, attackerRoll, attacker);
>>>>>>> e2644f1 (Séparation compétences/combat)
}
/* -------------------------------------------- */
esquiverAttaque( attackerRoll, attacker = undefined )
{
this.rollCompetence( "esquive", undefined, attackerRoll, attacker );
this.rollCompetenceCombat( "esquive", undefined, attackerRoll, attacker );
}
/* -------------------------------------------- */

18
module/grammar.js Normal file
View File

@ -0,0 +1,18 @@
const articlesApostrophes = {
'de' : 'd\'',
'le' : 'l\'',
'la' : 'l\''
}
export class Grammar {
static apostrophe(article, word) {
if (articlesApostrophes[article] && Grammar.startsWithVoyel(word)) {
return articlesApostrophes[article] + word
}
return article + ' ' + word;
}
static startsWithVoyel(word) {
return word.match(/^[aeiouy]/i)
}
}

View File

@ -34,12 +34,13 @@ export class RdDRoll extends Dialog {
finalLevel: 0,
diffConditions: 0,
diffLibre: 0,
malusArmureValue: actor.data.data.attributs ? actor.data.data.attributs.malusarmure.value : 0,
surencMalusFlag: (actor.data.data.compteurs.surenc.value < 0),
surencMalusValue: actor.data.data.compteurs.surenc.value,
malusArmureValue: (actor.type == 'personnage ' && actor.data.data.attributs && actor.data.data.attributs.malusarmure) ? actor.data.data.attributs.malusarmure.value : 0,
surencMalusFlag: actor.type == 'personnage ' ? (actor.data.data.compteurs.surenc.value < 0) : false,
surencMalusValue: actor.type == 'personnage ' ? actor.data.data.compteurs.surenc.value : 0,
surencMalusApply: false,
isNatation: false,
useEncForNatation: false
isNatation: rollData.competence ? rollData.competence.name.toLowerCase().includes("natation") : false,
useEncForNatation: false,
encValueForNatation: actor.encombrementTotal ? Math.floor(actor.encombrementTotal) : 0
},
{ overwrite: false });
}

View File

@ -55,7 +55,7 @@ export class RdDTokenHud {
hudCombat.find('label').click(async (event) => {
let armeIndex = event.currentTarget.attributes['data-arme-id'].value;
let arme = armesList[armeIndex];
actor.rollArme( arme.name, arme.data.competence);
actor.rollArme( arme.data.competence, arme.name);
});
}
}