foundryvtt-reve-de-dragon/module/settings/status-effects.js

155 lines
5.4 KiB
JavaScript
Raw Permalink Normal View History

2022-11-06 21:39:03 +01:00
import { SYSTEM_RDD } from "../constants.js";
export const STATUSES = {
StatusStunned: 'stun',
StatusBleeding: 'bleeding',
StatusProne: 'prone',
StatusGrappling: 'grappling',
StatusGrappled: 'grappled',
StatusRestrained: 'restrain',
StatusUnconscious: 'unconscious',
StatusBlind: 'blind',
StatusComma: 'comma',
StatusDead: 'dead',
StatusDemiReve: 'demi-reve',
}
const rddStatusEffects = [
2024-11-14 22:36:57 +01:00
{ rdd: true, id: STATUSES.StatusStunned, name: 'EFFECT.StatusStunned', img: 'icons/svg/stoned.svg', "duration.rounds": 1 },
{ rdd: true, id: STATUSES.StatusBleeding, name: 'EFFECT.StatusBleeding', img: 'icons/svg/blood.svg' },
{ rdd: true, id: STATUSES.StatusProne, name: 'EFFECT.StatusProne', img: 'icons/svg/falling.svg' },
{ rdd: true, id: STATUSES.StatusGrappling, tint: '#33cc33', name: 'EFFECT.StatusGrappling', img: 'systems/foundryvtt-reve-de-dragon/icons/empoignade.webp' },
{ rdd: true, id: STATUSES.StatusGrappled, tint: '#ff9900', name: 'EFFECT.StatusGrappled', img: 'systems/foundryvtt-reve-de-dragon/icons/empoignade.webp' },
{ rdd: true, id: STATUSES.StatusRestrained, name: 'EFFECT.StatusRestrained', img: 'icons/svg/net.svg' },
{ rdd: true, id: STATUSES.StatusUnconscious, name: 'EFFECT.StatusUnconscious', img: 'icons/svg/unconscious.svg' },
{ rdd: true, id: STATUSES.StatusBlind, name: 'EFFECT.StatusBlind', img: 'icons/svg/blind.svg' },
{ rdd: true, id: STATUSES.StatusComma, name: 'EFFECT.StatusComma', img: 'icons/svg/skull.svg' },
{ rdd: true, id: STATUSES.StatusDead, name: 'EFFECT.StatusDead', img: 'icons/svg/skull.svg' },
{ rdd: true, id: STATUSES.StatusDemiReve, name: 'EFFECT.StatusDemiReve', img: 'systems/foundryvtt-reve-de-dragon/icons/heures/hd12.svg' }
];
const demiReveStatusEffect = rddStatusEffects.find(it => it.id == STATUSES.StatusDemiReve);
2021-06-29 00:56:25 +02:00
const statusDemiSurprise = new Set([STATUSES.StatusStunned, STATUSES.StatusProne, STATUSES.StatusRestrained])
const statusSurpriseTotale = new Set([STATUSES.StatusUnconscious, STATUSES.StatusBlind, STATUSES.StatusComma])
2022-11-06 21:39:03 +01:00
export class StatusEffects extends FormApplication {
static onReady() {
const rddEffectIds = rddStatusEffects.map(it => it.id);
rddStatusEffects.forEach(it => {
it.statuses = new Set()
it.statuses.add(it.id)
})
2021-06-29 00:56:25 +02:00
const defaultStatusEffectIds = CONFIG.statusEffects.map(it => it.id);
game.settings.register(SYSTEM_RDD, "use-status-effects", {
name: "use-status-effects",
scope: "world",
config: false,
2021-06-29 00:56:25 +02:00
default: defaultStatusEffectIds.join(),
type: String
});
game.settings.registerMenu(SYSTEM_RDD, "select-status-effect", {
name: "Choisir les effets disponibles",
label: "Choix des effets",
hint: "Ouvre la fenêtre de sélection des effets/status appliqués aux acteurs",
icon: "fas fa-bars",
2022-11-06 21:39:03 +01:00
type: StatusEffects,
restricted: true
});
2021-06-29 00:56:25 +02:00
2024-11-14 22:36:57 +01:00
CONFIG.RDD.allEffects = rddStatusEffects.concat(CONFIG.statusEffects.filter(it => !rddEffectIds.includes(it.id)))
2021-06-29 00:56:25 +02:00
StatusEffects._setUseStatusEffects(StatusEffects._getUseStatusEffects());
console.log('statusEffects', CONFIG.statusEffects);
}
static valeurSurprise(effect, isCombat) {
if (statusSurpriseTotale.intersects(effect.statuses)) {
2024-05-26 22:16:42 +02:00
return 2
}
if (statusDemiSurprise.intersects(effect.statuses)) {
return 1
}
2024-01-02 18:43:42 +01:00
if (isCombat && effect.statuses.find(e => e == STATUSES.StatusDemiReve)) {
return 1
}
return 0
}
static _getUseStatusEffects() {
return game.settings.get(SYSTEM_RDD, "use-status-effects")?.split(',') ?? [];
}
static _setUseStatusEffects(effectIds) {
if (game.user.isGM) {
game.settings.set(SYSTEM_RDD, "use-status-effects", effectIds.join());
}
for (let effect of CONFIG.RDD.allEffects) {
effect.active = effect.rdd || effectIds.includes(effect.id);
}
CONFIG.statusEffects = CONFIG.RDD.allEffects.filter(it => it.active);
}
static prepareActiveEffect(effectId) {
let status = rddStatusEffects.find(it => it.id == effectId)
if (status) {
2024-05-02 14:08:02 +02:00
status = foundry.utils.duplicate(status)
status.statuses = [effectId]
}
return status;
2021-06-29 00:56:25 +02:00
}
static demiReve() {
return demiReveStatusEffect;
}
constructor(...args) {
super(...args);
}
static get defaultOptions() {
const options = super.defaultOptions;
2024-05-26 22:16:42 +02:00
foundry.utils.mergeObject(options, {
2022-11-06 21:39:03 +01:00
id: "status-effects",
template: "systems/foundryvtt-reve-de-dragon/templates/settings/status-effects.html",
height: 800,
width: 350,
minimizable: false,
closeOnSubmit: true,
title: "Choix des status/effets"
});
return options;
}
getData() {
const used = StatusEffects._getUseStatusEffects();
2021-03-16 22:56:57 +01:00
let formData = super.getData();
2024-05-02 14:08:02 +02:00
formData.effects = foundry.utils.duplicate(CONFIG.RDD.allEffects);
formData.effects.forEach(it => it.active = used.includes(it.id))
2021-03-16 22:56:57 +01:00
return formData;
}
activateListeners(html) {
html.find(".select-effect").click((event) => {
let id = event.currentTarget.attributes.name?.value;
if (id) {
let selected = StatusEffects._getUseStatusEffects();
let isChecked = event.currentTarget.checked;
if (isChecked) {
selected.push(id);
}
else {
selected = selected.filter(it => it != id)
}
StatusEffects._setUseStatusEffects(selected);
}
});
}
async _updateObject(event, formData) {
this.close();
}
}