Gestion plus fines des entites et corrections sur initiative #915

This commit is contained in:
sladecraven 2021-11-11 09:37:00 +01:00
parent 35cd13f53e
commit 8f890dad66

93
module/rdd-possession.js Normal file
View File

@ -0,0 +1,93 @@
/* -------------------------------------------- */
import { Misc } from "./misc.js";
import { RdDDice } from "./rdd-dice.js";
import { RdDUtility } from "./rdd-utility.js";
import { RdDCombat } from "./rdd-combat.js";
import { RdDResolutionTable } from "./rdd-resolution-table.js";
import { RdDRoll } from "./rdd-roll.js";
import { RdDRollTables } from "./rdd-rolltables.js";
import { RdDItemCompetenceCreature } from "./item-competencecreature.js";
/* -------------------------------------------- */
/* On part du principe qu'une entité démarre tjs
une possession via le MJ (ie un joueur ne controle pas une entité)
Donc la compétence Possession ne peut être démarrée que par le MJ.
*/
/* -------------------------------------------- */
export class RdDPossession {
/* -------------------------------------------- */
static init() {
this.possessionList = [];
}
/* -------------------------------------------- */
static searchPossessionFromEntite( attacker, target) {
let poss = this.possessionList.find( poss => poss.entiteId == attacker.data._id && poss.pjId == defender.data._id);
return poss;
}
/* -------------------------------------------- */
static _onReussitePossession( r ) {
console.log("Success", r);
ui.notifications.warn("Succès du jet de Possession ! Mais La gestion des possessions n'est pas encore disponible, merci de la gérer manuellement");
}
/* -------------------------------------------- */
static _onEchecPossession( r ) {
console.log("Echec", r);
ui.notifications.warn("Echec du jet de Possession ! Mais La gestion des possessions n'est pas encore disponible, merci de la gérer manuellement");
}
/* -------------------------------------------- */
static async managePosession(attacker, competence ) {
const target = RdDCombat.getTarget();
if (target == undefined) {
ui.notifications.warn((game.user.targets?.size ?? 0) > 1
? "Vous devez choisir <strong>une seule</strong> cible à posséder!"
: "Vous devez choisir une cible à posséder!");
return;
}
const defender = target.actor;
let possession = this.searchPossessionFromEntite( attacker, defender);
if ( possession) {
// Manage ongoing possession
} else {
this.createPossession(attacker, defender);
}
console.log("Creation de possession", attacker, defender, competence);
let rollData = {
competence: competence,
};
if ( attacker.isCreature()) {
RdDItemCompetenceCreature.setRollDataCreature(rollData);
}
const dialog = await RdDRoll.create( attacker, rollData,
{
html: 'systems/foundryvtt-reve-de-dragon/templates/dialog-roll-competence.html',
options: { height: 540 }
}, {
name: 'jet-possession',
label: 'Possession: ',
callbacks: [
{ condition: r => (r.rolled.isSuccess), action: r => this._onReussitePossession(r) },
{ condition: r => (r.rolled.isEchec), action: r => this._onEchecPossession(r) },
]
});
dialog.render(true);
}
/* -------------------------------------------- */
static createPossession( attacker, defender ) {
let poss = { entiteid: attacker.data._id,
pjId: defender.data._id,
possessionCount: 0, // Negative : conjuration, Positif : possession
}
this.possessionList.push( poss);
}
}