34 Jet de rêve pour entités

gestion du jet de rêve pour s'accorder aux entités de cauchemar
This commit is contained in:
Vincent Vandemeulebrouck 2020-12-01 17:36:13 +01:00
parent 82b0ec1015
commit cd434ae5dd
6 changed files with 159 additions and 42 deletions

View File

@ -31,8 +31,9 @@ export class RdDActor extends Actor {
static async create(data, options) { static async create(data, options) {
// Case of compendium global import // Case of compendium global import
if (data instanceof Array) if (data instanceof Array) {
return super.create(data, options); return super.create(data, options);
}
// If the created actor has items (only applicable to duplicated actors) bypass the new actor creation logic // If the created actor has items (only applicable to duplicated actors) bypass the new actor creation logic
if (data.items) { if (data.items) {
return super.create(data, options); return super.create(data, options);
@ -126,15 +127,18 @@ export class RdDActor extends Actor {
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
async performRoll(rollData) { async performRoll(rollData, attacker = undefined) {
let rolled = await RdDResolutionTable.roll(rollData.caracValue, rollData.finalLevel);
//rolled.isPart = true; // Pour tester le particulières
rollData.rolled = rolled; // garder le résultat
//console.log("performRoll", rollData, rolled)
if ( !rollData.attackerRoll) // Store in the registry if not a defense roll
game.system.rdd.rollDataHandler[this.data._id] = rollData;
if (rolled.isPart && rollData.arme && !rollData.attackerRoll) { // Réussite particulière avec attaque -> choix ! // garder le résultat
rollData.rolled = await RdDResolutionTable.roll(rollData.caracValue, rollData.finalLevel);
//console.log("performRoll", rollData)
if ( !rollData.attackerRoll) {// Store in the registry if not a defense roll
game.system.rdd.rollDataHandler[this.data._id] = rollData;
}
if (rollData.rolled.isPart && rollData.arme && !rollData.attackerRoll) { // Réussite particulière avec attaque -> choix !
let message = "<strong>Réussite particulière en attaque</strong>"; let message = "<strong>Réussite particulière en attaque</strong>";
message = message + "<br><a class='chat-card-button' id='particuliere-attaque' data-mode='force' data-attackerid='" + this.data._id + "'>Attaquer en Force</a>"; message = message + "<br><a class='chat-card-button' id='particuliere-attaque' data-mode='force' data-attackerid='" + this.data._id + "'>Attaquer en Force</a>";
// Finesse et Rapidité seulement en mêlée et si la difficulté libre est de -1 minimum // Finesse et Rapidité seulement en mêlée et si la difficulté libre est de -1 minimum
@ -144,19 +148,18 @@ export class RdDActor extends Actor {
} }
ChatMessage.create( {content : message, whisper: ChatMessage.getWhisperRecipients( this.name ) } ); ChatMessage.create( {content : message, whisper: ChatMessage.getWhisperRecipients( this.name ) } );
} else { } else {
this.continueRoll(rollData); this.continueRoll(rollData, attacker);
} }
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
async continueRoll(rollData) { async continueRoll(rollData, attacker = undefined) {
let rolled = rollData.rolled; let rolled = rollData.rolled;
let result = rolled.roll;
let quality = rolled.quality let quality = rolled.quality
// Manage weapon categories when parrying (cf. page 115 ) // Manage weapon categories when parrying (cf. page 115 )
let need_resist = false; // Do we need to make resistance roll for defender ? let need_resist = false; // Do we need to make resistance roll for defender ?
if (rollData.arme && rollData.attackerRoll) { // Manage parade depeding on weapon type, and change roll results if (rollData.arme && rollData.attackerRoll) { // Manage parade depending on weapon type, and change roll results
let attCategory = RdDUtility.getArmeCategory(rollData.attackerRoll.arme); let attCategory = RdDUtility.getArmeCategory(rollData.attackerRoll.arme);
let defCategory = RdDUtility.getArmeCategory(rollData.arme); let defCategory = RdDUtility.getArmeCategory(rollData.arme);
if (defCategory == "bouclier") if (defCategory == "bouclier")
@ -166,7 +169,7 @@ export class RdDActor extends Actor {
if (attCategory.match("epee") && (defCategory == "hache" || defCategory == "lance")) if (attCategory.match("epee") && (defCategory == "hache" || defCategory == "lance"))
need_resist = true; need_resist = true;
} }
if (this.data.type != 'entite' && (this.data.data.sante.sonne.value || rollData.particuliereAttaque == "finesse")) { if (!this.isEntiteCauchemar() && (this.data.data.sante.sonne.value || rollData.particuliereAttaque == "finesse")) {
rollData.needSignificative = true; rollData.needSignificative = true;
} }
@ -183,18 +186,21 @@ export class RdDActor extends Actor {
explications = "" explications = ""
// In case of fight, replace the message per dommages + localization. it indicates if result is OK or not // In case of fight, replace the message per dommages + localization. it indicates if result is OK or not
if (rollData.attackerRoll) { // Defense case ! if (rollData.attackerRoll) { // Defense case !
if (rollData.needSignificative && rolled.isSign ) { if (rolled.isSign || (!rollData.needSignificative && rolled.isSuccess)) {
explications += "<br><strong>Attaque parée/esquivée !</strong>";
} else if ( !rollData.needSignificative && rolled.isSuccess) {
explications += "<br><strong>Attaque parée/esquivée !</strong>"; explications += "<br><strong>Attaque parée/esquivée !</strong>";
} else { } else {
explications += "<br><strong>Esquive/Parade échouée, encaissement !</strong>"; explications += "<br><strong>Esquive/Parade échouée, encaissement !</strong>";
if (rollData.needSignificative) if (rollData.needSignificative)
explications += "Significative nécessaire!"; explications += " Significative nécessaire!";
encaisser = true;
} }
encaisser = rollData.needSignificative ? !rolled.isSign : !rolled.isSuccess;
} else { // This is the attack roll! } else { // This is the attack roll!
if (rolled.isSuccess) { if (rolled.isSuccess) {
let target = this.getTarget();
if (await this.targetEntiteNonAccordee(target, 'avant-defense')) {
return;
}
// Message spécial pour la rapidité, qui reste difficile à gérer automatiquement // Message spécial pour la rapidité, qui reste difficile à gérer automatiquement
if ( rollData.particuliereAttaque == 'rapidite') { if ( rollData.particuliereAttaque == 'rapidite') {
ChatMessage.create( { content: "Vous avez attaqué en Rapidité. Ce cas n'est pas géré autmatiquement, donc suivez les directives de votre MJ pour gérer ce cas.", ChatMessage.create( { content: "Vous avez attaqué en Rapidité. Ce cas n'est pas géré autmatiquement, donc suivez les directives de votre MJ pour gérer ce cas.",
@ -203,14 +209,14 @@ export class RdDActor extends Actor {
rollData.domArmePlusDom = this._calculBonusDommages(rollData.selectedCarac, rollData.arme, rollData.particuliereAttaque == 'force' ); rollData.domArmePlusDom = this._calculBonusDommages(rollData.selectedCarac, rollData.arme, rollData.particuliereAttaque == 'force' );
rollData.degats = new Roll("2d10").roll().total + rollData.domArmePlusDom; rollData.degats = new Roll("2d10").roll().total + rollData.domArmePlusDom;
rollData.loc = RdDUtility.getLocalisation(); rollData.loc = RdDUtility.getLocalisation();
for (let target of game.user.targets) {
rollData.mortalite = (rollData.mortalite) ? rollData.mortalite : "mortel";// Force default if (target)
rollData.mortalite = (target.actor.data.type == 'entite') ? "cauchemar" : rollData.mortalite; {
console.log("Mortalité : ", rollData.mortalite, target.actor.data.type); rollData.mortalite = RdDActor._calculMortaliteEncaissement(rollData, target);
defenseMsg = RdDUtility.buildDefenseChatCard(this, target, rollData); defenseMsg = RdDUtility.buildDefenseChatCard(this, target, rollData);
explications += "<br><strong>Cible</strong> : " + target.actor.data.name; explications += "<br><strong>Cible</strong> : " + target.actor.data.name;
} }
explications += "<br>Dégâts : " + rollData.degats + "<br>Localisation : " + rollData.loc.label; explications += "<br>Encaissement : " + rollData.degats + "<br>Localisation : " + rollData.loc.label;
} else { } else {
explications = "<br>Echec ! Pas de dégâts"; explications = "<br>Echec ! Pas de dégâts";
} }
@ -256,10 +262,16 @@ export class RdDActor extends Actor {
// Get damages! // Get damages!
if (encaisser) { if (encaisser) {
this.encaisserDommages(rollData.attackerRoll); this.encaisserDommages(rollData.attackerRoll, attacker);
} }
} }
static _calculMortaliteEncaissement(rollData, target) {
const mortalite = target.actor.isEntiteCauchemar() ? "cauchemar" : (rollData.mortalite ? rollData.mortalite : "mortel");
console.log("Mortalité : ", mortalite, target.actor.data.type);
return mortalite;
}
/* -------------------------------------------- */ /* -------------------------------------------- */
_calculBonusDommages(carac, arme, isForce=false) { _calculBonusDommages(carac, arme, isForce=false) {
if ( arme.name.toLowerCase() == "esquive") return 0; // Specific case management if ( arme.name.toLowerCase() == "esquive") return 0; // Specific case management
@ -919,6 +931,9 @@ export class RdDActor extends Actor {
async santeIncDec(name, inc, isCritique = false) { async santeIncDec(name, inc, isCritique = false) {
const sante = duplicate(this.data.data.sante); const sante = duplicate(this.data.data.sante);
let data = sante[name]; let data = sante[name];
if (data==undefined) {
return;
}
let minValue = 0; let minValue = 0;
if (this.type == 'personnage') { if (this.type == 'personnage') {
// TODO: les animaux/humanoïdes on théoriquement aussi un sconst, mais la SPA n'est pas passé par là // TODO: les animaux/humanoïdes on théoriquement aussi un sconst, mais la SPA n'est pas passé par là
@ -1221,7 +1236,7 @@ export class RdDActor extends Actor {
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
async rollCompetence( name, armeItem=undefined, attackerRoll=undefined ) { async rollCompetence( name, armeItem=undefined, attackerRoll=undefined, attacker = undefined) {
let competence = RdDUtility.findCompetence( this.data.items, name); let competence = RdDUtility.findCompetence( this.data.items, name);
console.log("rollCompetence !!!", competence, armeItem, attackerRoll); console.log("rollCompetence !!!", competence, armeItem, attackerRoll);
// Common rollData values // Common rollData values
@ -1275,12 +1290,24 @@ export class RdDActor extends Actor {
let html = await renderTemplate('systems/foundryvtt-reve-de-dragon/templates/dialog-competence.html', rollData); let html = await renderTemplate('systems/foundryvtt-reve-de-dragon/templates/dialog-competence.html', rollData);
if (rollData.arme) { if (rollData.arme) {
new RdDRollDialog("arme", html, rollData, this ).render(true); if (await this.targetEntiteNonAccordee(this.getTarget(), 'avant-attaque')) {
return;
}
new RdDRollDialog("arme", html, rollData, this, attacker).render(true);
} else { } else {
new RdDRollDialog("competence", html, rollData, this ).render(true); new RdDRollDialog("competence", html, rollData, this, attacker).render(true);
} }
} }
getTarget() {
if (game.user.targets && game.user.targets.size == 1) {
for (let target of game.user.targets) {
return target;
}
}
return undefined;
}
/* -------------------------------------------- */ /* -------------------------------------------- */
async equiperObjet( itemID ) async equiperObjet( itemID )
{ {
@ -1321,7 +1348,13 @@ export class RdDActor extends Actor {
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
async encaisserDommages( attackerRoll ) { async encaisserDommages( attackerRoll, attacker = undefined ) {
if (attacker && !await attacker.accorder(this, 'avant-encaissement')) {
return;
}
console.log("encaisserDommages", attackerRoll ) console.log("encaisserDommages", attackerRoll )
const armure = this.computeArmure( attackerRoll.loc, attackerRoll.domArmePlusDom); const armure = this.computeArmure( attackerRoll.loc, attackerRoll.domArmePlusDom);
let degatsReel = attackerRoll.degats - armure; let degatsReel = attackerRoll.degats - armure;
@ -1356,17 +1389,17 @@ export class RdDActor extends Actor {
/* -------------------------------------------- */ /* -------------------------------------------- */
parerAttaque( attackerRoll, armeId ) parerAttaque( attackerRoll, armeId, attacker = undefined )
{ {
let armeItem = this.getOwnedItem(armeId); // Item.data.data ! let armeItem = this.getOwnedItem(armeId); // Item.data.data !
console.log("Going to PARY !!!!!!!!!", armeItem, attackerRoll.diffLibre); console.log("Going to PARY !!!!!!!!!", armeItem, attackerRoll.diffLibre);
this.rollCompetence( armeItem.data.data.competence, armeItem.data, attackerRoll ); this.rollCompetence( armeItem.data.data.competence, armeItem.data, attackerRoll, attacker);
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
esquiverAttaque( attackerRoll ) esquiverAttaque( attackerRoll, attacker = undefined )
{ {
this.rollCompetence( "esquive", undefined, attackerRoll ); this.rollCompetence( "esquive", undefined, attackerRoll, attacker );
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
@ -1377,6 +1410,72 @@ export class RdDActor extends Actor {
return data; return data;
} }
/* -- entites -- */
/* retourne true si on peut continuer, false si on ne peut pas continuer */
async targetEntiteNonAccordee(target, when='avant-encaissement')
{
if (target)
{
return !await this.accorder(target.actor, when);
}
return false;
}
async accorder(entite, when = 'avant-encaissement')
{
if (when != game.settings.get("foundryvtt-reve-de-dragon", "accorder-entite-cauchemar")
|| !entite.isEntiteCauchemar()
|| entite.isEntiteCauchemarAccordee(this)) {
return true;
}
let rolled = await RdDResolutionTable.roll( this.getReveActuel(), - Number(entite.data.data.carac.niveau.value));
let message = {
content: "Jet de points actuels de rêve à " + rolled.finalLevel + RdDResolutionTable.explain(rolled) + "<br>",
whisper: ChatMessage.getWhisperRecipients(this.name)
};
if (rolled.isSuccess) {
await entite.setEntiteReveAccordee(this);
message.content += this.name + " s'est accordé avec " + entite.name;
}
else {
message.content+= this.name + " n'est pas accordé avec " + entite.name;
}
ChatMessage.create( message );
return rolled.isSuccess;
}
isEntiteCauchemar()
{
return this.data.type == 'entite';
}
isEntiteCauchemarAccordee(attaquant)
{
if (!this.isEntiteCauchemar()) { return true; }
let resonnance = this.data.data.sante.resonnance;
return (resonnance.actors.find(it => it == attaquant._id));
}
async setEntiteReveAccordee(attaquant)
{
if (!this.isEntiteCauchemar()) {
ui.notifications.error("Impossible de s'accorder à " + this.name + ": ce n'est pas une entite de cauchemer/rêve");
return;
}
let resonnance = duplicate(this.data.data.sante.resonnance);
if (resonnance.actors.find(it => it == attaquant._id)){
// déjà accordé
return;
}
resonnance.actors.push(attaquant._id);
await this.update( {"data.sante.resonnance": resonnance});
return;
}
} }

View File

@ -105,6 +105,20 @@ Hooks.once("init", async function() {
rollDataHandler: {}, rollDataHandler: {},
TMRUtility: TMRUtility TMRUtility: TMRUtility
} }
game.settings.register("foundryvtt-reve-de-dragon", "accorder-entite-cauchemar", {
name: "Accorder le rêve aux entités",
hint: "A quel moment les personnages doivent accorder leur rêve aux entités de cauchemar",
scope: "world",
config: true,
type: String,
choices: { // If choices are defined, the resulting setting will be a select menu
"avant-attaque": "Avant l'attaque",
"avant-defense": "Avant la défense",
"avant-encaissement": "Avant l'encaissement",
},
default: "avant-encaissement"
});
// Create specific settings // Create specific settings
// game.settings.register("foundryvtt-reve-de-dragon", "configuration", { // game.settings.register("foundryvtt-reve-de-dragon", "configuration", {
// name: "configuration", // name: "configuration",

View File

@ -9,7 +9,7 @@ import { RdDResolutionTable } from "./rdd-resolution-table.js";
export class RdDRollDialog extends Dialog { export class RdDRollDialog extends Dialog {
/* -------------------------------------------- */ /* -------------------------------------------- */
constructor(mode, html, rollData, actor) { constructor(mode, html, rollData, actor, attacker = undefined) {
let myButtons let myButtons
if (mode == "sort") { if (mode == "sort") {
@ -47,12 +47,13 @@ export class RdDRollDialog extends Dialog {
this.mode = mode this.mode = mode
this.rollData = rollData this.rollData = rollData
this.actor = actor this.actor = actor
this.attacker = attacker
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
performRollSort(html, isSortReserve = false) { performRollSort(html, isSortReserve = false) {
this.rollData.isSortReserve = isSortReserve; this.rollData.isSortReserve = isSortReserve;
this.actor.performRoll(this.rollData); this.actor.performRoll(this.rollData, attacker);
} }
/* -------------------------------------------- */ /* -------------------------------------------- */

View File

@ -809,7 +809,7 @@ export class RdDUtility {
rollData.attackerid = attackerid; rollData.attackerid = attackerid;
rollData.defenderTokenId = defenderTokenId; rollData.defenderTokenId = defenderTokenId;
let defenderToken = canvas.tokens.get( defenderTokenId ); let defenderToken = canvas.tokens.get( defenderTokenId );
defenderToken.actor.encaisserDommages( rollData ); defenderToken.actor.encaisserDommages( rollData, game.actors.get(attackerid));
} else { // Emit message for GM } else { // Emit message for GM
game.socket.emit("system.foundryvtt-reve-de-dragon", { game.socket.emit("system.foundryvtt-reve-de-dragon", {
msg: "msg_encaisser", msg: "msg_encaisser",
@ -824,7 +824,7 @@ export class RdDUtility {
let defenderToken = canvas.tokens.get(event.currentTarget.attributes['data-defenderTokenId'].value ); let defenderToken = canvas.tokens.get(event.currentTarget.attributes['data-defenderTokenId'].value );
let armeId = event.currentTarget.attributes['data-armeid'].value; let armeId = event.currentTarget.attributes['data-armeid'].value;
let rollData = game.system.rdd.rollDataHandler[attackerid]; let rollData = game.system.rdd.rollDataHandler[attackerid];
defenderToken.actor.parerAttaque( rollData, armeId ); defenderToken.actor.parerAttaque( rollData, armeId, game.actors.get(attackerid));
}); });
html.on("click", '#esquiver-button', event => { html.on("click", '#esquiver-button', event => {
@ -833,7 +833,7 @@ export class RdDUtility {
let defenderToken = canvas.tokens.get(event.currentTarget.attributes['data-defenderTokenId'].value ); let defenderToken = canvas.tokens.get(event.currentTarget.attributes['data-defenderTokenId'].value );
let rollData = game.system.rdd.rollDataHandler[attackerid]; let rollData = game.system.rdd.rollDataHandler[attackerid];
//console.log("Esquive !", rollData, defenderActor); //console.log("Esquive !", rollData, defenderActor);
defenderToken.actor.esquiverAttaque( rollData ); defenderToken.actor.esquiverAttaque( rollData, game.actors.get(attackerid));
}); });
html.on("click", '#particuliere-attaque', event => { html.on("click", '#particuliere-attaque', event => {

View File

@ -5,7 +5,7 @@
"version": "1.1.0", "version": "1.1.0",
"minimumCoreVersion": "0.7.5", "minimumCoreVersion": "0.7.5",
"compatibleCoreVersion": "0.7.7", "compatibleCoreVersion": "0.7.7",
"templateVersion": 52, "templateVersion": 53,
"author": "LeRatierBretonnien", "author": "LeRatierBretonnien",
"esmodules": [ "module/rdd-main.js", "module/hook-renderChatLog.js" ], "esmodules": [ "module/rdd-main.js", "module/hook-renderChatLog.js" ],
"styles": ["styles/simple.css"], "styles": ["styles/simple.css"],

View File

@ -50,6 +50,9 @@
"value": 10, "value": 10,
"label": "Endurance", "label": "Endurance",
"derivee": false "derivee": false
},
"resonnance": {
"actors" : []
} }
}, },
"compteurs": { "compteurs": {