Merge branch 'resonnance' into 'dev_1.1'

#34 Jet de rêve pour entités

See merge request LeRatierBretonnien/foundryvtt-reve-de-dragon!47
This commit is contained in:
Leratier Bretonnien 2020-12-02 08:48:49 +00:00
commit d614206859
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) {
// Case of compendium global import
if (data instanceof Array)
if (data instanceof Array) {
return super.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);
@ -126,15 +127,18 @@ export class RdDActor extends Actor {
}
/* -------------------------------------------- */
async performRoll(rollData) {
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;
async performRoll(rollData, attacker = undefined) {
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>";
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
@ -144,19 +148,18 @@ export class RdDActor extends Actor {
}
ChatMessage.create( {content : message, whisper: ChatMessage.getWhisperRecipients( this.name ) } );
} else {
this.continueRoll(rollData);
this.continueRoll(rollData, attacker);
}
}
/* -------------------------------------------- */
async continueRoll(rollData) {
async continueRoll(rollData, attacker = undefined) {
let rolled = rollData.rolled;
let result = rolled.roll;
let quality = rolled.quality
// Manage weapon categories when parrying (cf. page 115 )
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 defCategory = RdDUtility.getArmeCategory(rollData.arme);
if (defCategory == "bouclier")
@ -166,7 +169,7 @@ export class RdDActor extends Actor {
if (attCategory.match("epee") && (defCategory == "hache" || defCategory == "lance"))
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;
}
@ -183,18 +186,21 @@ export class RdDActor extends Actor {
explications = ""
// 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.needSignificative && rolled.isSign ) {
explications += "<br><strong>Attaque parée/esquivée !</strong>";
} else if ( !rollData.needSignificative && rolled.isSuccess) {
if (rolled.isSign || (!rollData.needSignificative && rolled.isSuccess)) {
explications += "<br><strong>Attaque parée/esquivée !</strong>";
} else {
explications += "<br><strong>Esquive/Parade échouée, encaissement !</strong>";
if (rollData.needSignificative)
explications += "Significative nécessaire!";
encaisser = true;
explications += " Significative nécessaire!";
}
encaisser = rollData.needSignificative ? !rolled.isSign : !rolled.isSuccess;
} else { // This is the attack roll!
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
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.",
@ -203,14 +209,14 @@ export class RdDActor extends Actor {
rollData.domArmePlusDom = this._calculBonusDommages(rollData.selectedCarac, rollData.arme, rollData.particuliereAttaque == 'force' );
rollData.degats = new Roll("2d10").roll().total + rollData.domArmePlusDom;
rollData.loc = RdDUtility.getLocalisation();
for (let target of game.user.targets) {
rollData.mortalite = (rollData.mortalite) ? rollData.mortalite : "mortel";// Force default
rollData.mortalite = (target.actor.data.type == 'entite') ? "cauchemar" : rollData.mortalite;
console.log("Mortalité : ", rollData.mortalite, target.actor.data.type);
if (target)
{
rollData.mortalite = RdDActor._calculMortaliteEncaissement(rollData, target);
defenseMsg = RdDUtility.buildDefenseChatCard(this, target, rollData);
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 {
explications = "<br>Echec ! Pas de dégâts";
}
@ -256,10 +262,16 @@ export class RdDActor extends Actor {
// Get damages!
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) {
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) {
const sante = duplicate(this.data.data.sante);
let data = sante[name];
if (data==undefined) {
return;
}
let minValue = 0;
if (this.type == 'personnage') {
// 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);
console.log("rollCompetence !!!", competence, armeItem, attackerRoll);
// Common rollData values
@ -1275,10 +1290,22 @@ export class RdDActor extends Actor {
let html = await renderTemplate('systems/foundryvtt-reve-de-dragon/templates/dialog-competence.html', rollData);
if (rollData.arme) {
new RdDRollDialog("arme", html, rollData, this ).render(true);
} else {
new RdDRollDialog("competence", html, rollData, this ).render(true);
if (await this.targetEntiteNonAccordee(this.getTarget(), 'avant-attaque')) {
return;
}
new RdDRollDialog("arme", html, rollData, this, attacker).render(true);
} else {
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;
}
/* -------------------------------------------- */
@ -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 )
const armure = this.computeArmure( attackerRoll.loc, attackerRoll.domArmePlusDom);
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 !
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;
}
/* -- 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: {},
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
// game.settings.register("foundryvtt-reve-de-dragon", "configuration", {
// name: "configuration",

View File

@ -9,7 +9,7 @@ import { RdDResolutionTable } from "./rdd-resolution-table.js";
export class RdDRollDialog extends Dialog {
/* -------------------------------------------- */
constructor(mode, html, rollData, actor) {
constructor(mode, html, rollData, actor, attacker = undefined) {
let myButtons
if (mode == "sort") {
@ -47,12 +47,13 @@ export class RdDRollDialog extends Dialog {
this.mode = mode
this.rollData = rollData
this.actor = actor
this.attacker = attacker
}
/* -------------------------------------------- */
performRollSort(html, isSortReserve = false) {
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.defenderTokenId = defenderTokenId;
let defenderToken = canvas.tokens.get( defenderTokenId );
defenderToken.actor.encaisserDommages( rollData );
defenderToken.actor.encaisserDommages( rollData, game.actors.get(attackerid));
} else { // Emit message for GM
game.socket.emit("system.foundryvtt-reve-de-dragon", {
msg: "msg_encaisser",
@ -824,7 +824,7 @@ export class RdDUtility {
let defenderToken = canvas.tokens.get(event.currentTarget.attributes['data-defenderTokenId'].value );
let armeId = event.currentTarget.attributes['data-armeid'].value;
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 => {
@ -833,7 +833,7 @@ export class RdDUtility {
let defenderToken = canvas.tokens.get(event.currentTarget.attributes['data-defenderTokenId'].value );
let rollData = game.system.rdd.rollDataHandler[attackerid];
//console.log("Esquive !", rollData, defenderActor);
defenderToken.actor.esquiverAttaque( rollData );
defenderToken.actor.esquiverAttaque( rollData, game.actors.get(attackerid));
});
html.on("click", '#particuliere-attaque', event => {

View File

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

View File

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