Amélioration possession

- Créer la possession lors de la première attaque
- Le personnage ciblé par la possession est affiché
This commit is contained in:
Vincent Vandemeulebrouck 2022-11-23 22:37:16 +01:00
parent c3c0bbc922
commit 97ee5bc331

View File

@ -3,6 +3,7 @@ import { RdDCombat } from "./rdd-combat.js";
import { RdDResolutionTable } from "./rdd-resolution-table.js"; import { RdDResolutionTable } from "./rdd-resolution-table.js";
import { RdDRoll } from "./rdd-roll.js"; import { RdDRoll } from "./rdd-roll.js";
import { RdDItemCompetenceCreature } from "./item-competencecreature.js"; import { RdDItemCompetenceCreature } from "./item-competencecreature.js";
import { Targets } from "./targets.js";
/* -------------------------------------------- */ /* -------------------------------------------- */
/* On part du principe qu'une entité démarre tjs /* On part du principe qu'une entité démarre tjs
@ -27,30 +28,34 @@ export class RdDPossession {
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
static async onAttaquePossession(target, attacker, competence, possession = undefined) { static async onAttaquePossession(target, attacker, competence, suitePossession = undefined) {
const defender = target.actor; const defender = target.actor;
possession = duplicate(possession ?? this.searchPossessionFromEntite(attacker, defender) ?? (await this.createPossession(attacker, defender))); const fromEntite = RdDPossession.searchPossessionFromEntite(attacker, defender);
const isNouvelle = !suitePossession && ! fromEntite;
const possession = (suitePossession ?? fromEntite ?? (await RdDPossession.createPossession(attacker, defender)));
RdDPossession.$updateEtatPossession(possession)
this.$updateEtatPossession(possession)
let rollData = { let rollData = {
mode: "possession", mode: "possession",
isECNIDefender: false, isECNIDefender: false,
competence: competence, competence: competence,
possession: possession, possession: possession,
attacker: attacker, attacker: attacker,
defender: defender defender: defender,
targetToken: Targets.extractTokenData(target)
}; };
if (attacker.isCreature()) { if (attacker.isCreature()) {
RdDItemCompetenceCreature.setRollDataCreature(rollData) RdDItemCompetenceCreature.setRollDataCreature(rollData)
} }
await RdDPossession.$rollAttaquePossession(attacker, rollData); await RdDPossession.$rollAttaquePossession(attacker, rollData, isNouvelle);
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
static async onConjurerPossession(attacker, competence, possession) { static async onConjurerPossession(attacker, competence, possession) {
possession = duplicate(possession); possession = duplicate(possession);
this.$updateEtatPossession(possession) RdDPossession.$updateEtatPossession(possession)
let rollData = { let rollData = {
mode: "possession", mode: "possession",
isECNIDefender: true, isECNIDefender: true,
@ -74,11 +79,12 @@ export class RdDPossession {
ui.notifications.warn("Une erreur s'est produite : Aucune possession trouvée !!") ui.notifications.warn("Une erreur s'est produite : Aucune possession trouvée !!")
return return
} }
possession = duplicate(possession)
// Update for draconic roll // Update for draconic roll
let rollData = { let rollData = {
mode: "conjuration", mode: "conjuration",
isECNIDefender: defender.type == "entite", isECNIDefender: defender.type == "entite",
possession: duplicate(possession), possession: possession,
attacker: attacker, attacker: attacker,
defender: defender, defender: defender,
competence: defender.getDraconicOuPossession(), competence: defender.getDraconicOuPossession(),
@ -87,49 +93,50 @@ export class RdDPossession {
} }
rollData.competence.system.defaut_carac = 'reve-actuel' rollData.competence.system.defaut_carac = 'reve-actuel'
await RdDPossession.$rollDefensePossesion(defender, rollData); await RdDPossession.$rollDefensePossession(defender, rollData);
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
static async $rollAttaquePossession(attacker, rollData) { static async $rollAttaquePossession(attacker, rollData, isNouvelle = false) {
const dialog = await RdDRoll.create(attacker, rollData, const dialog = await RdDRoll.create(attacker, rollData,
{ html: 'systems/foundryvtt-reve-de-dragon/templates/dialog-roll-competence.html' },
{ {
html: 'systems/foundryvtt-reve-de-dragon/templates/dialog-roll-competence.html'
}, {
name: 'jet-possession', name: 'jet-possession',
label: rollData.isECNIDefender ? 'Conjurer la possession' : 'Possession', label: rollData.isECNIDefender ? 'Conjurer la possession' : 'Possession',
callbacks: [ callbacks: [
{ condition: r => (r.rolled.isSuccess), action: async (r) => await this.$onRollPossession(r, true) }, { condition: r => (r.rolled.isSuccess), action: async (r) => await RdDPossession.$onRollPossession(r, true, isNouvelle) },
{ condition: r => (r.rolled.isEchec), action: async (r) => await this.$onRollPossession(r, false) }, { condition: r => (r.rolled.isEchec), action: async (r) => await RdDPossession.$onRollPossession(r, false, isNouvelle) },
] ]
}); });
dialog.render(true); dialog.render(true);
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
static async $rollDefensePossesion(defender, rollData) { static async $onRollPossession(rollData, isSuccess, isNouvelle = false) {
rollData.possession.isSuccess = isSuccess;
RdDPossession.$updateEtatPossession(rollData.possession);
if (isNouvelle) {
// Creer la possession sur le defenseur
rollData.defender.createEmbeddedDocuments('Item', [rollData.possession.toObject()])
}
await RdDResolutionTable.displayRollData(rollData, rollData.attacker, 'chat-resultat-possession.html');
}
/* -------------------------------------------- */
static async $rollDefensePossession(defender, rollData) {
const dialog = await RdDRoll.create(defender, rollData, const dialog = await RdDRoll.create(defender, rollData,
{ { html: 'systems/foundryvtt-reve-de-dragon/templates/dialog-roll-defense-possession.html' },
html: 'systems/foundryvtt-reve-de-dragon/templates/dialog-roll-defense-possession.html'
},
{ {
name: 'conjurer', name: 'conjurer',
label: 'Conjurer une Possession', label: 'Conjurer une Possession',
callbacks: [ callbacks: [
{ action: async (r) => await this.$onRollConjuration(r) } { action: async (r) => await RdDPossession.$onRollConjuration(r) }
] ]
} }
); );
dialog.render(true); dialog.render(true);
} }
/* -------------------------------------------- */
static async $onRollPossession(rollData, isSuccess) {
rollData.possession.isSuccess = isSuccess;
this.$updateEtatPossession(rollData.possession);
await RdDResolutionTable.displayRollData(rollData, this, 'chat-resultat-possession.html');
}
/* -------------------------------------------- */ /* -------------------------------------------- */
static async $onRollConjuration(rollData) { static async $onRollConjuration(rollData) {
let actor = game.actors.get(rollData.possession.system.possedeid) let actor = game.actors.get(rollData.possession.system.possedeid)
@ -143,9 +150,9 @@ export class RdDPossession {
await actor.updateEmbeddedDocuments('Item', [update]) await actor.updateEmbeddedDocuments('Item', [update])
} }
this.$updateEtatPossession(rollData.possession) RdDPossession.$updateEtatPossession(rollData.possession)
await RdDResolutionTable.displayRollData(rollData, this, 'chat-resultat-possession.html') await RdDResolutionTable.displayRollData(rollData,rollData.defender, 'chat-resultat-possession.html')
if (rollData.possession.isPosseder || rollData.possession.isConjurer) { if (rollData.possession.isPosseder || rollData.possession.isConjurer) {
// conjuration // conjuration
actor.deleteEmbeddedDocuments("Item", [rollData.possession._id]) actor.deleteEmbeddedDocuments("Item", [rollData.possession._id])
@ -175,14 +182,14 @@ export class RdDPossession {
/* -------------------------------------------- */ /* -------------------------------------------- */
static async createPossession(attacker, defender) { static async createPossession(attacker, defender) {
let possessionData = { return await Item.create({
name: "Possession en cours de " + attacker.name, type: 'possession', name: "Possession en cours de " + attacker.name, type: 'possession',
img: "systems/foundryvtt-reve-de-dragon/icons/entites/possession2.webp", img: "systems/foundryvtt-reve-de-dragon/icons/entites/possession2.webp",
system: { description: "", typepossession: attacker.name, possede: false, possessionid: randomID(16), possesseurid: attacker.id, possedeid: defender.id, date: 0, compteur: 0 } system: { description: "", typepossession: attacker.name, possede: false, possessionid: randomID(16), possesseurid: attacker.id, possedeid: defender.id, date: 0, compteur: 0 }
} },
// Creates only the possession on the personnage side {
let poss = await defender.createEmbeddedDocuments('Item', [possessionData]) temporary: true
return duplicate(poss[0]) })
} }
} }