2022-11-06 21:39:03 +01:00
|
|
|
import { SYSTEM_RDD } from "../constants.js";
|
2021-01-13 03:42:13 +01:00
|
|
|
|
2022-09-17 22:36:43 +02:00
|
|
|
export const STATUSES = {
|
2023-12-08 23:50:16 +01:00
|
|
|
StatusStunned: 'stun',
|
2022-09-17 22:36:43 +02:00
|
|
|
StatusBleeding: 'bleeding',
|
|
|
|
StatusProne: 'prone',
|
|
|
|
StatusGrappling: 'grappling',
|
|
|
|
StatusGrappled: 'grappled',
|
|
|
|
StatusRestrained: 'restrain',
|
2023-12-08 23:50:16 +01:00
|
|
|
StatusUnconscious: 'unconscious',
|
2022-09-17 22:36:43 +02:00
|
|
|
StatusBlind: 'blind',
|
|
|
|
StatusComma: 'comma',
|
|
|
|
StatusDead: 'dead',
|
|
|
|
StatusDemiReve: 'demi-reve',
|
|
|
|
}
|
|
|
|
|
2021-01-13 03:42:13 +01:00
|
|
|
const rddStatusEffects = [
|
2022-09-17 22:36:43 +02:00
|
|
|
{ rdd: true, id: STATUSES.StatusStunned, label: 'EFFECT.StatusStunned', icon: 'icons/svg/stoned.svg', "duration.rounds": 1 },
|
|
|
|
{ rdd: true, id: STATUSES.StatusBleeding, label: 'EFFECT.StatusBleeding', icon: 'icons/svg/blood.svg' },
|
|
|
|
{ rdd: true, id: STATUSES.StatusProne, label: 'EFFECT.StatusProne', icon: 'icons/svg/falling.svg' },
|
2023-12-09 15:25:36 +01:00
|
|
|
{ rdd: true, id: STATUSES.StatusGrappling, tint: '#33cc33', label: 'EFFECT.StatusGrappling', icon: 'systems/foundryvtt-reve-de-dragon/icons/empoignade.svg' },
|
|
|
|
{ rdd: true, id: STATUSES.StatusGrappled, tint: '#ff9900', label: 'EFFECT.StatusGrappled', icon: 'systems/foundryvtt-reve-de-dragon/icons/empoignade.svg' },
|
2022-09-17 22:36:43 +02:00
|
|
|
{ rdd: true, id: STATUSES.StatusRestrained, label: 'EFFECT.StatusRestrained', icon: 'icons/svg/net.svg' },
|
|
|
|
{ rdd: true, id: STATUSES.StatusUnconscious, label: 'EFFECT.StatusUnconscious', icon: 'icons/svg/unconscious.svg' },
|
|
|
|
{ rdd: true, id: STATUSES.StatusBlind, label: 'EFFECT.StatusBlind', icon: 'icons/svg/blind.svg' },
|
|
|
|
{ rdd: true, id: STATUSES.StatusComma, label: 'EFFECT.StatusComma', icon: 'icons/svg/skull.svg' },
|
|
|
|
{ rdd: true, id: STATUSES.StatusDead, label: 'EFFECT.StatusDead', icon: 'icons/svg/skull.svg' },
|
|
|
|
{ rdd: true, id: STATUSES.StatusDemiReve, label: 'EFFECT.StatusDemiReve', icon: 'systems/foundryvtt-reve-de-dragon/icons/heures/hd12.svg' }
|
2021-01-13 03:42:13 +01:00
|
|
|
];
|
2022-09-17 22:36:43 +02:00
|
|
|
const demiReveStatusEffect = rddStatusEffects.find(it => it.id == STATUSES.StatusDemiReve);
|
2021-06-29 00:56:25 +02:00
|
|
|
|
2023-12-08 23:50:16 +01:00
|
|
|
const statusDemiSurprise = new Set([STATUSES.StatusStunned, STATUSES.StatusProne, STATUSES.StatusRestrained])
|
|
|
|
const statusSurpriseTotale = new Set([STATUSES.StatusUnconscious, STATUSES.StatusBlind, STATUSES.StatusComma])
|
2021-01-13 03:42:13 +01:00
|
|
|
|
2022-11-06 21:39:03 +01:00
|
|
|
export class StatusEffects extends FormApplication {
|
2021-01-22 02:00:04 +01:00
|
|
|
static onReady() {
|
2023-12-08 23:50:16 +01:00
|
|
|
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);
|
2021-11-11 02:43:38 +01:00
|
|
|
game.settings.register(SYSTEM_RDD, "use-status-effects", {
|
2021-01-13 03:42:13 +01:00
|
|
|
name: "use-status-effects",
|
|
|
|
scope: "world",
|
|
|
|
config: false,
|
2021-06-29 00:56:25 +02:00
|
|
|
default: defaultStatusEffectIds.join(),
|
2021-01-13 03:42:13 +01:00
|
|
|
type: String
|
|
|
|
});
|
|
|
|
|
2021-11-11 02:43:38 +01:00
|
|
|
game.settings.registerMenu(SYSTEM_RDD, "select-status-effect", {
|
2021-01-13 03:42:13 +01:00
|
|
|
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,
|
2021-01-13 03:42:13 +01:00
|
|
|
restricted: true
|
|
|
|
});
|
2021-06-29 00:56:25 +02:00
|
|
|
|
2023-12-08 23:50:16 +01:00
|
|
|
CONFIG.RDD.allEffects = rddStatusEffects.concat(CONFIG.statusEffects.filter(it => !rddEffectIds.includes(it.id)));
|
2021-06-29 00:56:25 +02:00
|
|
|
|
2021-01-13 03:42:13 +01:00
|
|
|
StatusEffects._setUseStatusEffects(StatusEffects._getUseStatusEffects());
|
|
|
|
console.log('statusEffects', CONFIG.statusEffects);
|
|
|
|
}
|
|
|
|
|
|
|
|
static valeurSurprise(effect, isCombat) {
|
2023-12-08 23:50:16 +01:00
|
|
|
if (statusSurpriseTotale.intersects(effect.statuses)) {
|
2021-01-13 03:42:13 +01:00
|
|
|
return 2;
|
|
|
|
}
|
2023-12-08 23:50:16 +01:00
|
|
|
if (statusDemiSurprise.intersects(effect.statuses)) {
|
|
|
|
return 1
|
|
|
|
}
|
2024-01-02 18:43:42 +01:00
|
|
|
if (isCombat && effect.statuses.find(e => e == STATUSES.StatusDemiReve)) {
|
2023-12-08 23:50:16 +01:00
|
|
|
return 1
|
|
|
|
}
|
|
|
|
return 0
|
2021-01-13 16:32:25 +01:00
|
|
|
}
|
2021-01-13 03:42:13 +01:00
|
|
|
|
|
|
|
static _getUseStatusEffects() {
|
2023-12-08 23:50:16 +01:00
|
|
|
return game.settings.get(SYSTEM_RDD, "use-status-effects")?.split(',') ?? [];
|
2021-01-13 03:42:13 +01:00
|
|
|
}
|
|
|
|
|
2023-12-08 23:50:16 +01:00
|
|
|
static _setUseStatusEffects(effectIds) {
|
2021-01-19 22:51:09 +01:00
|
|
|
if (game.user.isGM) {
|
2023-12-08 23:50:16 +01:00
|
|
|
game.settings.set(SYSTEM_RDD, "use-status-effects", effectIds.join());
|
2021-01-19 22:51:09 +01:00
|
|
|
}
|
2021-01-13 03:42:13 +01:00
|
|
|
|
|
|
|
for (let effect of CONFIG.RDD.allEffects) {
|
2023-12-08 23:50:16 +01:00
|
|
|
effect.active = effect.rdd || effectIds.includes(effect.id);
|
2021-01-13 03:42:13 +01:00
|
|
|
}
|
|
|
|
CONFIG.statusEffects = CONFIG.RDD.allEffects.filter(it => it.active);
|
|
|
|
}
|
|
|
|
|
2023-12-08 23:50:16 +01:00
|
|
|
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)
|
2023-12-08 23:50:16 +01:00
|
|
|
status.statuses = [effectId]
|
|
|
|
}
|
|
|
|
return status;
|
2021-06-29 00:56:25 +02:00
|
|
|
}
|
2022-09-17 22:36:43 +02:00
|
|
|
|
2021-01-13 03:42:13 +01:00
|
|
|
static demiReve() {
|
|
|
|
return demiReveStatusEffect;
|
|
|
|
}
|
|
|
|
|
|
|
|
constructor(...args) {
|
|
|
|
super(...args);
|
|
|
|
}
|
|
|
|
|
|
|
|
static get defaultOptions() {
|
|
|
|
const options = super.defaultOptions;
|
|
|
|
mergeObject(options, {
|
2022-11-06 21:39:03 +01:00
|
|
|
id: "status-effects",
|
|
|
|
template: "systems/foundryvtt-reve-de-dragon/templates/settings/status-effects.html",
|
2022-11-16 02:46:26 +01:00
|
|
|
height: 800,
|
2021-01-13 03:42:13 +01:00
|
|
|
width: 350,
|
|
|
|
minimizable: false,
|
|
|
|
closeOnSubmit: true,
|
|
|
|
title: "Choix des status/effets"
|
|
|
|
});
|
|
|
|
return options;
|
|
|
|
}
|
|
|
|
|
|
|
|
getData() {
|
2022-09-17 22:36:43 +02:00
|
|
|
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);
|
2022-09-17 22:36:43 +02:00
|
|
|
formData.effects.forEach(it => it.active = used.includes(it.id))
|
2021-03-16 22:56:57 +01:00
|
|
|
return formData;
|
2021-01-13 03:42:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
2022-09-17 22:36:43 +02:00
|
|
|
selected.push(id);
|
2021-01-13 03:42:13 +01:00
|
|
|
}
|
|
|
|
else {
|
2022-09-17 22:36:43 +02:00
|
|
|
selected = selected.filter(it => it != id)
|
2021-01-13 03:42:13 +01:00
|
|
|
}
|
|
|
|
StatusEffects._setUseStatusEffects(selected);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async _updateObject(event, formData) {
|
|
|
|
this.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|