2024-12-08 23:46:22 +01:00
|
|
|
import { ENTITE_INCARNE, SHOW_DICE, SYSTEM_RDD } from "../constants.js";
|
2023-11-04 03:42:39 +01:00
|
|
|
import { Grammar } from "../grammar.js";
|
|
|
|
import { Misc } from "../misc.js";
|
|
|
|
import { RdDResolutionTable } from "../rdd-resolution-table.js";
|
|
|
|
import { RdDEncaisser } from "../rdd-roll-encaisser.js";
|
|
|
|
import { RdDRoll } from "../rdd-roll.js";
|
|
|
|
import { RdDUtility } from "../rdd-utility.js";
|
|
|
|
import { ReglesOptionnelles } from "../settings/regles-optionnelles.js";
|
|
|
|
import { RdDBaseActor } from "./base-actor.js";
|
2024-12-08 23:46:22 +01:00
|
|
|
import { ITEM_TYPES } from "../item.js";
|
|
|
|
import { RdDItemCompetence } from "../item-competence.js";
|
2023-11-04 03:42:39 +01:00
|
|
|
import { RdDItemCompetenceCreature } from "../item-competencecreature.js";
|
2024-12-08 23:46:22 +01:00
|
|
|
import { RdDItemArme } from "../item-arme.js";
|
2023-11-04 03:42:39 +01:00
|
|
|
import { StatusEffects } from "../settings/status-effects.js";
|
|
|
|
import { Targets } from "../targets.js";
|
|
|
|
import { RdDConfirm } from "../rdd-confirm.js";
|
2024-12-04 15:55:09 +01:00
|
|
|
import { RdDCarac } from "../rdd-carac.js";
|
2023-11-04 03:42:39 +01:00
|
|
|
|
2024-12-08 23:46:22 +01:00
|
|
|
import { ChatUtility } from "../chat-utility.js";
|
|
|
|
import { DialogValidationEncaissement } from "../dialog-validation-encaissement.js";
|
|
|
|
import { RdDCombat } from "../rdd-combat.js";
|
|
|
|
import { RdDEmpoignade } from "../rdd-empoignade.js";
|
|
|
|
import { RdDPossession } from "../rdd-possession.js";
|
|
|
|
import { BASE_CORPS_A_CORPS, BASE_ESQUIVE, POSSESSION_SANS_DRACONIC } from "../item/base-items.js";
|
2023-11-04 03:42:39 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Classe de base pour les acteurs disposant de rêve (donc, pas des objets)
|
|
|
|
* - Entités de rêve
|
|
|
|
* - Créatures de "sang": créatures et humanoides
|
|
|
|
*/
|
|
|
|
export class RdDBaseActorReve extends RdDBaseActor {
|
|
|
|
|
2024-12-04 15:55:09 +01:00
|
|
|
prepareActorData() {
|
|
|
|
super.prepareActorData()
|
|
|
|
this.system.attributs.plusdom.value = this.getBonusDegat()
|
|
|
|
this.system.sante.endurance.max = this.getEnduranceMax()
|
|
|
|
this.system.sante.endurance.value = Math.min(this.system.sante.endurance.value, this.system.sante.endurance.max)
|
|
|
|
}
|
|
|
|
|
2024-12-18 17:26:28 +01:00
|
|
|
getCarac() {
|
|
|
|
return foundry.utils.mergeObject(this.system.carac,
|
|
|
|
{
|
|
|
|
'reve-actuel': this.getCaracReveActuel(),
|
|
|
|
'chance-actuelle': this.getCaracChanceActuelle()
|
|
|
|
},
|
|
|
|
{ inplace: false })
|
|
|
|
}
|
|
|
|
|
2023-11-04 03:42:39 +01:00
|
|
|
getCaracChanceActuelle() {
|
|
|
|
return {
|
|
|
|
label: 'Chance actuelle',
|
|
|
|
value: this.getChanceActuel(),
|
|
|
|
type: "number"
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
getCaracReveActuel() {
|
|
|
|
return {
|
|
|
|
label: 'Rêve actuel',
|
|
|
|
value: this.getReveActuel(),
|
|
|
|
type: "number"
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2024-12-04 15:55:09 +01:00
|
|
|
getTaille() { return Misc.toInt(this.system.carac.taille?.value) }
|
|
|
|
getConstitution() { return this.getReve() }
|
2023-11-04 03:42:39 +01:00
|
|
|
getForce() { return this.getReve() }
|
|
|
|
getAgilite() { return this.getForce() }
|
2024-12-04 15:55:09 +01:00
|
|
|
getReve() { return Misc.toInt(this.system.carac.reve?.value) }
|
2023-11-04 03:42:39 +01:00
|
|
|
getChance() { return this.getReve() }
|
2024-12-04 15:55:09 +01:00
|
|
|
|
|
|
|
getReveActuel() { return this.getReve() }
|
|
|
|
getChanceActuel() { return this.getChance() }
|
|
|
|
|
|
|
|
getEnduranceMax() { return Math.max(1, this.getTaille() + this.getConstitution()) }
|
|
|
|
getEncombrementMax() { return (this.getForce() + this.getTaille()) / 2 }
|
|
|
|
getBonusDegat() { return RdDCarac.getCaracDerivee(this.getEncombrementMax()).plusdom }
|
|
|
|
|
2023-11-04 03:42:39 +01:00
|
|
|
getMoralTotal() { return 0 }
|
|
|
|
getProtectionNaturelle() { return Number(this.system.attributs?.protection?.value ?? 0) }
|
|
|
|
getSConst() { return 0 }
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
isSurenc() { return false }
|
|
|
|
computeMalusSurEncombrement() { return 0 }
|
|
|
|
|
|
|
|
ajustementAstrologique() { return 0 }
|
|
|
|
getMalusArmure() { return 0 }
|
|
|
|
|
|
|
|
getEnduranceActuelle() {
|
|
|
|
return Number(this.system.sante?.endurance?.value ?? 0);
|
|
|
|
}
|
|
|
|
async jetEndurance(resteEndurance = undefined) { return { jetEndurance: 0, sonne: false } }
|
|
|
|
isDead() { return false }
|
2024-11-03 23:31:56 +01:00
|
|
|
isSonne() { return false }
|
2023-11-04 03:42:39 +01:00
|
|
|
blessuresASoigner() { return [] }
|
|
|
|
getEtatGeneral(options = { ethylisme: false }) { return 0 }
|
2024-11-03 23:31:56 +01:00
|
|
|
isActorCombat() { return true }
|
2023-11-04 03:42:39 +01:00
|
|
|
|
2024-11-06 23:24:53 +01:00
|
|
|
getCaracInit(competence) {
|
2024-12-04 15:55:09 +01:00
|
|
|
if (!competence) {
|
2024-11-06 23:24:53 +01:00
|
|
|
return 0
|
|
|
|
}
|
|
|
|
if (competence.type == ITEM_TYPES.competencecreature) {
|
|
|
|
return competence.system.carac_value
|
|
|
|
}
|
|
|
|
return this.system.carac[competence.system.defaut_carac].value;
|
|
|
|
}
|
|
|
|
listActionsCombat() {
|
|
|
|
return this.itemTypes[ITEM_TYPES.competencecreature]
|
|
|
|
.filter(it => RdDItemCompetenceCreature.isAttaque(it))
|
|
|
|
.map(it => RdDItemCompetenceCreature.armeCreature(it))
|
|
|
|
.filter(it => it != undefined);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-11-04 03:42:39 +01:00
|
|
|
async computeArmure(attackerRoll) { return this.getProtectionNaturelle() }
|
|
|
|
async remiseANeuf() { }
|
|
|
|
async appliquerAjoutExperience(rollData, hideChatMessage = 'show') { }
|
|
|
|
|
|
|
|
async santeIncDec(name, inc, isCritique = false) { }
|
|
|
|
|
|
|
|
async finDeRound(options = { terminer: false }) {
|
|
|
|
await this.$finDeRoundSuppressionEffetsTermines(options);
|
|
|
|
await this.finDeRoundBlessures();
|
|
|
|
await this.$finDeRoundSupprimerObsoletes();
|
|
|
|
await this.$finDeRoundEmpoignade();
|
|
|
|
}
|
|
|
|
|
|
|
|
async $finDeRoundSuppressionEffetsTermines(options) {
|
|
|
|
for (let effect of this.getEffects()) {
|
|
|
|
if (effect.duration.type !== 'none' && (effect.duration.remaining <= 0 || options.terminer)) {
|
|
|
|
await effect.delete();
|
2024-11-15 00:01:55 +01:00
|
|
|
ChatMessage.create({ content: `${this.getAlias()} n'est plus ${Misc.lowerFirst(game.i18n.localize(effect.system.label))} !` });
|
2023-11-04 03:42:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async finDeRoundBlessures() {
|
|
|
|
}
|
|
|
|
|
|
|
|
async $finDeRoundSupprimerObsoletes() {
|
|
|
|
const obsoletes = []
|
2024-09-25 22:56:24 +02:00
|
|
|
.concat(this.itemTypes[ITEM_TYPES.empoignade].filter(it => it.system.pointsemp <= 0))
|
|
|
|
.concat(this.itemTypes[ITEM_TYPES.possession].filter(it => it.system.compteur < -2 || it.system.compteur > 2))
|
2023-11-04 03:42:39 +01:00
|
|
|
.map(it => it.id);
|
|
|
|
await this.deleteEmbeddedDocuments('Item', obsoletes);
|
|
|
|
}
|
|
|
|
|
|
|
|
async $finDeRoundEmpoignade() {
|
2024-09-25 22:56:24 +02:00
|
|
|
const immobilisations = this.itemTypes[ITEM_TYPES.empoignade].filter(it => it.system.pointsemp >= 2 && it.system.empoigneurid == this.id);
|
2023-11-04 03:42:39 +01:00
|
|
|
immobilisations.forEach(emp => RdDEmpoignade.onImmobilisation(this,
|
|
|
|
game.actors.get(emp.system.empoigneid),
|
|
|
|
emp
|
|
|
|
))
|
|
|
|
}
|
|
|
|
|
|
|
|
async setSonne(sonne = true) { }
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
getCompetence(idOrName, options = {}) {
|
|
|
|
if (idOrName instanceof Item) {
|
|
|
|
return idOrName.isCompetence() ? idOrName : undefined
|
|
|
|
}
|
|
|
|
return RdDItemCompetence.findCompetence(this.items, idOrName, options)
|
|
|
|
}
|
2024-12-08 23:46:22 +01:00
|
|
|
|
|
|
|
getCompetences(name, options = { onMessage: message => { } }) {
|
|
|
|
return RdDItemCompetence.findCompetences(this.items, name, options)
|
2023-11-04 03:42:39 +01:00
|
|
|
}
|
2024-12-08 23:46:22 +01:00
|
|
|
|
|
|
|
getCompetenceCorpsACorps(options = { onMessage: message => { } }) {
|
|
|
|
return this.getCompetence(BASE_CORPS_A_CORPS.name, options) ?? BASE_CORPS_A_CORPS
|
2023-11-04 03:42:39 +01:00
|
|
|
}
|
2024-12-08 23:46:22 +01:00
|
|
|
|
|
|
|
getCompetencesEsquive(options = { onMessage: message => { } }) {
|
|
|
|
return this.getCompetences(BASE_ESQUIVE.name, options) ?? [BASE_ESQUIVE]
|
2023-11-04 03:42:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
getArmeParade(armeParadeId) {
|
2024-12-08 23:46:22 +01:00
|
|
|
return RdDItemArme.getArme(armeParadeId ? this.getEmbeddedDocument('Item', armeParadeId) : undefined)
|
2023-11-04 03:42:39 +01:00
|
|
|
}
|
|
|
|
|
2024-12-08 23:46:22 +01:00
|
|
|
getDraconicOuPossession() { return POSSESSION_SANS_DRACONIC }
|
2023-11-04 03:42:39 +01:00
|
|
|
|
|
|
|
getPossession(possessionId) {
|
2024-09-25 22:56:24 +02:00
|
|
|
return this.itemTypes[ITEM_TYPES.possession].find(it => it.system.possessionid == possessionId);
|
2023-11-04 03:42:39 +01:00
|
|
|
}
|
|
|
|
getEmpoignades() {
|
2024-09-25 22:56:24 +02:00
|
|
|
return this.itemTypes[ITEM_TYPES.empoignade];
|
2023-11-04 03:42:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
async updateCreatureCompetence(idOrName, fieldName, value) {
|
|
|
|
let competence = this.getCompetence(idOrName);
|
|
|
|
if (competence) {
|
|
|
|
function getFieldPath(fieldName) {
|
|
|
|
switch (fieldName) {
|
|
|
|
case "niveau": return 'system.niveau';
|
|
|
|
case "dommages": return 'system.dommages';
|
|
|
|
case "carac_value": return 'system.carac_value';
|
|
|
|
}
|
|
|
|
return undefined
|
|
|
|
}
|
|
|
|
const path = getFieldPath(fieldName);
|
|
|
|
if (path) {
|
2023-11-21 16:03:26 +01:00
|
|
|
await competence.update({ [path]: value });
|
2023-11-04 03:42:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
2024-05-26 22:43:07 +02:00
|
|
|
isEffectAllowed(effectId) { return false }
|
2023-11-04 03:42:39 +01:00
|
|
|
|
|
|
|
getEffects(filter = e => true) {
|
|
|
|
return this.getEmbeddedCollection("ActiveEffect").filter(filter);
|
|
|
|
}
|
|
|
|
|
2023-12-08 23:50:16 +01:00
|
|
|
getEffect(effectId) {
|
|
|
|
return this.getEmbeddedCollection("ActiveEffect").find(it => it.statuses?.has(effectId));
|
2023-11-04 03:42:39 +01:00
|
|
|
}
|
2024-10-16 23:18:15 +02:00
|
|
|
|
2023-12-08 23:50:16 +01:00
|
|
|
async setEffect(effectId, status) {
|
|
|
|
if (this.isEffectAllowed(effectId)) {
|
|
|
|
const effect = this.getEffect(effectId);
|
2023-11-04 03:42:39 +01:00
|
|
|
if (!status && effect) {
|
|
|
|
await this.deleteEmbeddedDocuments('ActiveEffect', [effect.id]);
|
|
|
|
}
|
|
|
|
if (status && !effect) {
|
2023-12-08 23:50:16 +01:00
|
|
|
await this.createEmbeddedDocuments("ActiveEffect", [StatusEffects.prepareActiveEffect(effectId)]);
|
2023-11-04 03:42:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-10-16 23:18:15 +02:00
|
|
|
|
2023-12-08 23:50:16 +01:00
|
|
|
async removeEffect(id) {
|
|
|
|
const effect = this.getEmbeddedCollection("ActiveEffect").find(it => it.id == id);
|
2023-11-04 03:42:39 +01:00
|
|
|
if (effect) {
|
2023-12-08 23:50:16 +01:00
|
|
|
await this.deleteEmbeddedDocuments('ActiveEffect', [id]);
|
2023-11-04 03:42:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async removeEffects(filter = e => true) {
|
|
|
|
if (game.user.isGM) {
|
|
|
|
const ids = this.getEffects(filter).map(it => it.id);
|
|
|
|
await this.deleteEmbeddedDocuments('ActiveEffect', ids);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
getSurprise(isCombat = undefined) {
|
|
|
|
let niveauSurprise = this.getEffects()
|
|
|
|
.map(effect => StatusEffects.valeurSurprise(effect, isCombat))
|
|
|
|
.reduce(Misc.sum(), 0);
|
|
|
|
if (niveauSurprise > 1) {
|
|
|
|
return 'totale';
|
|
|
|
}
|
|
|
|
if (niveauSurprise == 1) {
|
|
|
|
return 'demi';
|
|
|
|
}
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
async computeEtatGeneral() {
|
|
|
|
// Par défaut, on ne calcule pas d'état général, seuls les personnages/créatures sont affectés
|
|
|
|
this.system.compteurs.etat.value = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
async openRollDialog({ name, label, template, rollData, callbackAction }) {
|
|
|
|
const dialog = await RdDRoll.create(this, rollData,
|
|
|
|
{ html: template, close: async html => await this._onCloseRollDialog(html) },
|
|
|
|
{
|
|
|
|
name: name,
|
|
|
|
label: label,
|
|
|
|
callbacks: [
|
|
|
|
this.createCallbackExperience(),
|
|
|
|
this.createCallbackAppelAuMoral(),
|
|
|
|
{ action: callbackAction }
|
|
|
|
]
|
|
|
|
});
|
|
|
|
dialog.render(true);
|
|
|
|
return dialog
|
|
|
|
}
|
|
|
|
|
|
|
|
createEmptyCallback() {
|
|
|
|
return {
|
|
|
|
condition: r => false,
|
|
|
|
action: r => { }
|
|
|
|
};
|
|
|
|
}
|
|
|
|
createCallbackExperience() { return this.createEmptyCallback(); }
|
|
|
|
createCallbackAppelAuMoral() { return this.createEmptyCallback(); }
|
|
|
|
async _onCloseRollDialog(html) { }
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
async roll() {
|
|
|
|
RdDEmpoignade.checkEmpoignadeEnCours(this)
|
|
|
|
|
|
|
|
const carac = this.getCarac()
|
|
|
|
const selectedCaracName = ['apparence', 'perception', 'force', 'reve'].find(it => carac[it] != undefined)
|
|
|
|
|
|
|
|
await this.openRollDialog({
|
|
|
|
name: `jet-${this.id}`,
|
2024-11-15 00:01:55 +01:00
|
|
|
label: `Jet de ${this.getAlias()}`,
|
2023-11-04 03:42:39 +01:00
|
|
|
template: 'systems/foundryvtt-reve-de-dragon/templates/dialog-roll.html',
|
|
|
|
rollData: {
|
|
|
|
carac: carac,
|
|
|
|
selectedCarac: carac[selectedCaracName],
|
|
|
|
selectedCaracName: selectedCaracName,
|
|
|
|
competences: this.itemTypes['competence']
|
|
|
|
},
|
|
|
|
callbackAction: r => this.$onRollCaracResult(r)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
async rollCarac(caracName, jetResistance = undefined) {
|
2024-10-16 23:18:15 +02:00
|
|
|
if (Grammar.equalsInsensitive(caracName, 'taille')) {
|
2024-10-05 12:41:28 +02:00
|
|
|
return
|
|
|
|
}
|
2023-11-04 03:42:39 +01:00
|
|
|
RdDEmpoignade.checkEmpoignadeEnCours(this)
|
|
|
|
let selectedCarac = this.getCaracByName(caracName)
|
2024-10-10 23:17:55 +02:00
|
|
|
console.log("selectedCarac", selectedCarac)
|
2023-11-04 03:42:39 +01:00
|
|
|
await this.openRollDialog({
|
|
|
|
name: 'jet-' + caracName,
|
|
|
|
label: 'Jet ' + Grammar.apostrophe('de', selectedCarac.label),
|
|
|
|
template: 'systems/foundryvtt-reve-de-dragon/templates/dialog-roll-carac.html',
|
|
|
|
rollData: {
|
|
|
|
selectedCarac: selectedCarac,
|
|
|
|
competences: this.itemTypes['competence'],
|
|
|
|
jetResistance: jetResistance ? caracName : undefined
|
|
|
|
},
|
|
|
|
callbackAction: r => this.$onRollCaracResult(r)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
async $onRollCaracResult(rollData) {
|
|
|
|
// Final chat message
|
|
|
|
await RdDResolutionTable.displayRollData(rollData, this, 'chat-resultat-general.html');
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
2024-09-06 00:45:49 +02:00
|
|
|
async rollCompetence(idOrName, options = { tryTarget: true, arme: undefined }) {
|
2023-11-04 03:42:39 +01:00
|
|
|
RdDEmpoignade.checkEmpoignadeEnCours(this)
|
|
|
|
const competence = this.getCompetence(idOrName);
|
2024-09-06 00:45:49 +02:00
|
|
|
let rollData = { carac: this.system.carac, competence: competence, arme: options.arme }
|
2024-09-25 22:56:24 +02:00
|
|
|
if (competence.type == ITEM_TYPES.competencecreature) {
|
2024-10-25 23:28:09 +02:00
|
|
|
const token = RdDUtility.getSelectedToken(this)
|
2023-11-04 03:42:39 +01:00
|
|
|
const arme = RdDItemCompetenceCreature.armeCreature(competence)
|
|
|
|
if (arme && options.tryTarget && Targets.hasTargets()) {
|
2024-10-25 23:28:09 +02:00
|
|
|
Targets.selectOneTargetToken(target => {
|
2023-11-04 03:42:39 +01:00
|
|
|
if (arme.action == "possession") {
|
|
|
|
RdDPossession.onAttaquePossession(target, this, competence)
|
|
|
|
}
|
|
|
|
else {
|
2024-10-25 23:28:09 +02:00
|
|
|
RdDCombat.rddCombatTarget(target, this, token).attaque(competence, arme)
|
2023-11-04 03:42:39 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Transformer la competence de créature
|
|
|
|
RdDItemCompetenceCreature.setRollDataCreature(rollData)
|
|
|
|
}
|
|
|
|
|
|
|
|
await this.openRollDialog({
|
|
|
|
name: 'jet-competence',
|
|
|
|
label: 'Jet ' + Grammar.apostrophe('de', competence.name),
|
|
|
|
template: 'systems/foundryvtt-reve-de-dragon/templates/dialog-roll-competence.html',
|
|
|
|
rollData: rollData,
|
|
|
|
callbackAction: r => this.$onRollCompetence(r, options)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async $onRollCompetence(rollData, options) {
|
|
|
|
await RdDResolutionTable.displayRollData(rollData, this, 'chat-resultat-competence.html')
|
|
|
|
if (options?.onRollAutomate) {
|
|
|
|
options.onRollAutomate(rollData);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** --------------------------------------------
|
|
|
|
* @param {*} arme item d'arme/compétence de créature
|
|
|
|
* @param {*} categorieArme catégorie d'attaque à utiliser: competence (== melee), lancer, tir; naturelle, possession
|
|
|
|
* @returns
|
|
|
|
*/
|
2024-10-25 23:28:09 +02:00
|
|
|
rollArme(arme, categorieArme, token) {
|
|
|
|
token = token ?? RdDUtility.getSelectedToken(this)
|
2024-09-06 00:45:49 +02:00
|
|
|
const compToUse = this.$getCompetenceArme(arme, categorieArme)
|
2024-11-06 23:24:53 +01:00
|
|
|
if (!RdDItemArme.isUtilisable(arme)) {
|
2023-11-20 17:19:52 +01:00
|
|
|
ui.notifications.warn(`Arme inutilisable: ${arme.name} a une résistance de 0 ou moins`)
|
|
|
|
return
|
|
|
|
}
|
2023-11-04 03:42:39 +01:00
|
|
|
if (!Targets.hasTargets()) {
|
|
|
|
RdDConfirm.confirmer({
|
|
|
|
settingConfirmer: "confirmer-combat-sans-cible",
|
|
|
|
content: `<p>Voulez vous faire un jet de ${compToUse} sans choisir de cible valide?
|
|
|
|
<br>Tous les jets de combats devront être gérés à la main
|
|
|
|
</p>`,
|
|
|
|
title: 'Ne pas utiliser les automatisation de combat',
|
|
|
|
buttonLabel: "Pas d'automatisation",
|
|
|
|
onAction: async () => {
|
2024-09-06 00:45:49 +02:00
|
|
|
this.rollCompetence(compToUse, { tryTarget: false, arme: arme })
|
2023-11-04 03:42:39 +01:00
|
|
|
}
|
|
|
|
});
|
2023-11-20 17:19:52 +01:00
|
|
|
return
|
2023-11-04 03:42:39 +01:00
|
|
|
}
|
|
|
|
|
2024-10-25 23:28:09 +02:00
|
|
|
Targets.selectOneTargetToken(target => {
|
2023-11-04 03:42:39 +01:00
|
|
|
if (Targets.isTargetEntite(target)) {
|
|
|
|
ui.notifications.warn(`Vous ne pouvez pas attaquer une entité non incarnée avec votre ${arme.name}!!!!`);
|
2023-11-20 17:19:52 +01:00
|
|
|
return
|
2023-11-04 03:42:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const competence = this.getCompetence(compToUse)
|
|
|
|
if (competence.isCompetencePossession()) {
|
|
|
|
return RdDPossession.onAttaquePossession(target, this, competence);
|
|
|
|
}
|
2024-10-25 23:28:09 +02:00
|
|
|
RdDCombat.rddCombatTarget(target, this, token).attaque(competence, arme);
|
2023-11-04 03:42:39 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
$getCompetenceArme(arme, competenceName) {
|
2024-09-25 22:56:24 +02:00
|
|
|
return RdDItemArme.getCompetenceArme(arme, competenceName)
|
2023-11-04 03:42:39 +01:00
|
|
|
}
|
|
|
|
|
2024-11-03 23:31:56 +01:00
|
|
|
verifierForceMin(item) { }
|
2023-11-04 03:42:39 +01:00
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
async encaisser() { await RdDEncaisser.encaisser(this) }
|
|
|
|
|
2024-10-26 01:38:36 +02:00
|
|
|
async encaisserDommages(rollData, attacker = undefined, show = undefined, attackerToken = undefined, defenderToken = undefined) {
|
2023-11-04 03:42:39 +01:00
|
|
|
if (attacker && !await attacker.accorder(this, 'avant-encaissement')) {
|
|
|
|
return;
|
|
|
|
}
|
2024-05-12 21:37:12 +02:00
|
|
|
const armure = await this.computeArmure(rollData);
|
2024-10-16 23:18:15 +02:00
|
|
|
if (ReglesOptionnelles.isUsing('validation-encaissement-gr')) {
|
2024-10-26 01:38:36 +02:00
|
|
|
await this.encaisserDommagesValidationGR(rollData, armure, show, attackerToken, defenderToken);
|
2024-10-16 23:18:15 +02:00
|
|
|
}
|
2024-05-12 21:37:12 +02:00
|
|
|
else {
|
2024-10-26 01:33:20 +02:00
|
|
|
const jet = await RdDUtility.jetEncaissement(this, rollData, armure, { showDice: SHOW_DICE });
|
2024-10-26 01:38:36 +02:00
|
|
|
await this.$onEncaissement(jet, show, attackerToken, defenderToken)
|
2024-05-12 21:37:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-10-26 01:38:36 +02:00
|
|
|
async encaisserDommagesValidationGR(rollData, armure, show, attackerToken, defenderToken) {
|
2024-05-12 21:37:12 +02:00
|
|
|
if (!game.user.isGM) {
|
2023-11-04 03:42:39 +01:00
|
|
|
RdDBaseActor.remoteActorCall({
|
|
|
|
tokenId: this.token?.id,
|
|
|
|
actorId: this.id,
|
2024-12-04 18:55:34 +01:00
|
|
|
method: 'encaisserDommagesValidationGR', args: [rollData, armure, show, attackerToken, defenderToken]
|
2024-10-26 01:33:20 +02:00
|
|
|
})
|
2024-05-12 21:37:12 +02:00
|
|
|
} else {
|
2023-11-04 03:42:39 +01:00
|
|
|
DialogValidationEncaissement.validerEncaissement(this, rollData, armure,
|
2024-10-26 01:38:36 +02:00
|
|
|
jet => this.$onEncaissement(jet, show, attackerToken, defenderToken));
|
2023-11-04 03:42:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-10-26 01:38:36 +02:00
|
|
|
async $onEncaissement(jet, show, attackerToken, defenderToken) {
|
2024-10-26 01:33:20 +02:00
|
|
|
await this.onAppliquerJetEncaissement(jet, attackerToken);
|
2024-10-26 01:38:36 +02:00
|
|
|
await this.$afficherEncaissement(jet, show, defenderToken);
|
2023-11-04 03:42:39 +01:00
|
|
|
}
|
|
|
|
|
2024-10-26 01:33:20 +02:00
|
|
|
async onAppliquerJetEncaissement(encaissement, attackerToken) { }
|
2023-11-04 03:42:39 +01:00
|
|
|
|
2024-10-26 01:38:36 +02:00
|
|
|
async $afficherEncaissement(encaissement, show, defenderToken) {
|
2024-05-01 09:13:21 +02:00
|
|
|
foundry.utils.mergeObject(encaissement, {
|
2024-11-15 00:01:55 +01:00
|
|
|
alias: defenderToken?.name ?? this.getAlias(),
|
2023-11-04 03:42:39 +01:00
|
|
|
hasPlayerOwner: this.hasPlayerOwner,
|
|
|
|
show: show ?? {}
|
2024-11-06 23:24:53 +01:00
|
|
|
}, { overwrite: false });
|
2023-11-04 03:42:39 +01:00
|
|
|
|
2024-10-16 23:18:15 +02:00
|
|
|
await ChatUtility.createChatWithRollMode(
|
|
|
|
{
|
|
|
|
roll: encaissement.roll,
|
|
|
|
content: await renderTemplate('systems/foundryvtt-reve-de-dragon/templates/chat-resultat-encaissement.html', encaissement)
|
|
|
|
},
|
|
|
|
this
|
|
|
|
)
|
2023-11-04 03:42:39 +01:00
|
|
|
|
|
|
|
if (!encaissement.hasPlayerOwner && encaissement.endurance != 0) {
|
2024-10-16 23:18:15 +02:00
|
|
|
encaissement = foundry.utils.duplicate(encaissement)
|
|
|
|
encaissement.isGM = true
|
2023-11-04 03:42:39 +01:00
|
|
|
ChatMessage.create({
|
2024-10-16 23:18:15 +02:00
|
|
|
whisper: ChatUtility.getGMs(),
|
2023-11-04 03:42:39 +01:00
|
|
|
content: await renderTemplate('systems/foundryvtt-reve-de-dragon/templates/chat-resultat-encaissement.html', encaissement)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
async accorder(entite, when = 'avant-encaissement') {
|
|
|
|
if (when != game.settings.get(SYSTEM_RDD, "accorder-entite-cauchemar")
|
|
|
|
|| entite == undefined
|
|
|
|
|| !entite.isEntite([ENTITE_INCARNE])
|
|
|
|
|| entite.isEntiteAccordee(this)) {
|
|
|
|
return true;
|
|
|
|
}
|
2024-12-18 17:26:28 +01:00
|
|
|
const rolled = await RdDResolutionTable.roll(this.getReveActuel(), - Number(entite.getNiveau()));
|
2023-11-04 03:42:39 +01:00
|
|
|
const rollData = {
|
2024-11-15 00:01:55 +01:00
|
|
|
alias: this.getAlias(),
|
2023-11-04 03:42:39 +01:00
|
|
|
rolled: rolled,
|
|
|
|
entite: entite.name,
|
|
|
|
selectedCarac: this.system.carac.reve
|
|
|
|
};
|
|
|
|
|
|
|
|
if (rolled.isSuccess) {
|
|
|
|
await entite.setEntiteReveAccordee(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
await RdDResolutionTable.displayRollData(rollData, this, 'chat-resultat-accorder-cauchemar.html');
|
|
|
|
if (rolled.isPart) {
|
|
|
|
await this.appliquerAjoutExperience(rollData, true);
|
|
|
|
}
|
|
|
|
return rolled.isSuccess;
|
|
|
|
}
|
|
|
|
|
|
|
|
isEntiteAccordee(attacker) { return true }
|
|
|
|
|
2024-08-31 00:21:24 +02:00
|
|
|
async setEntiteReveAccordee(actor) {
|
2024-11-15 00:01:55 +01:00
|
|
|
ui.notifications.error("Impossible de s'accorder à " + this.getAlias() + ": ce n'est pas une entité incarnée");
|
2023-11-04 03:42:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|