forked from public/foundryvtt-reve-de-dragon
Nettoyage des status effects
* Recherche et suppression toujours par flags.core.statusId * l'ajout d'un status depuis le token est maintenant équivallent à l'ajout par le code * Correction des demi-surprises * Correction du Demi-rêve (qui ne disparaissait pas) * fix de la selection dans la configuration système
This commit is contained in:
@ -17,7 +17,7 @@ import { RdDAudio } from "./rdd-audio.js";
|
||||
import { RdDItemCompetence } from "./item-competence.js";
|
||||
import { RdDItemArme } from "./item-arme.js";
|
||||
import { RdDAlchimie } from "./rdd-alchimie.js";
|
||||
import { StatusEffects } from "./status-effects.js";
|
||||
import { STATUSES, StatusEffects } from "./status-effects.js";
|
||||
import { RdDItemCompetenceCreature } from "./item-competencecreature.js";
|
||||
import { RdDItemSigneDraconique } from "./item-signedraconique.js";
|
||||
import { ReglesOptionelles } from "./regles-optionelles.js";
|
||||
@ -52,8 +52,6 @@ const POSSESSION_SANS_DRACONIC = {
|
||||
export class RdDActor extends Actor {
|
||||
/* -------------------------------------------- */
|
||||
static init() {
|
||||
Hooks.on("deleteActiveEffect", (effect, options, userId) => RdDActor.getParentActor(effect)?.onDeleteActiveEffect(effect, options));
|
||||
|
||||
Hooks.on("preUpdateItem", (item, change, options, id) => RdDActor.getParentActor(item)?.onPreUpdateItem(item, change, options, id));
|
||||
Hooks.on("createItem", (item, options, id) => RdDActor.getParentActor(item)?.onCreateItem(item, options, id));
|
||||
Hooks.on("deleteItem", (item, options, id) => RdDActor.getParentActor(item)?.onDeleteItem(item, options, id));
|
||||
@ -420,7 +418,7 @@ export class RdDActor extends Actor {
|
||||
|
||||
/* -------------------------------------------- */
|
||||
getSurprise(isCombat = undefined) {
|
||||
let niveauSurprise = this.getActiveEffects()
|
||||
let niveauSurprise = this.getEffects()
|
||||
.map(effect => StatusEffects.valeurSurprise(effect, isCombat))
|
||||
.reduce(Misc.sum(), 0);
|
||||
if (niveauSurprise > 1) {
|
||||
@ -1587,12 +1585,12 @@ export class RdDActor extends Actor {
|
||||
|
||||
/* -------------------------------------------- */
|
||||
getSonne() {
|
||||
return this.getEffectByLabel("EFFECT.StatusStunned");
|
||||
return this.getEffect(STATUSES.StatusStunned);
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async finDeRound(options = { terminer: false }) {
|
||||
for (let effect of this.getActiveEffects()) {
|
||||
for (let effect of this.getEffects()) {
|
||||
if (effect.duration.type !== 'none' && (effect.duration.remaining <= 0 || options.terminer)) {
|
||||
if (effect.system.origin) {
|
||||
await effect.update({ 'disabled': true });
|
||||
@ -1621,7 +1619,7 @@ export class RdDActor extends Actor {
|
||||
ui.notifications.info("Le personnage est hors combat, il ne reste donc pas sonné");
|
||||
return;
|
||||
}
|
||||
await this.setStatusEffect("EFFECT.StatusStunned", sonne);
|
||||
await this.setEffect(STATUSES.StatusStunned, sonne);
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
@ -1774,7 +1772,7 @@ export class RdDActor extends Actor {
|
||||
}
|
||||
await this.update({ "system.sante": sante })
|
||||
if (this.isDead()) {
|
||||
await this.setStatusEffect("EFFECT.StatusComma", true);
|
||||
await this.setEffect(STATUSES.StatusComma, true);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@ -3158,8 +3156,7 @@ export class RdDActor extends Actor {
|
||||
ui.notifications.warn("Vous êtes déja dans les TMR....");
|
||||
return
|
||||
}
|
||||
let demiReve = this.getActiveEffects(it => it.label == "Demi-rêve");
|
||||
if (mode != 'visu' && demiReve.length > 0) {
|
||||
if (mode != 'visu' && this.getEffect(STATUSES.StatusDemiReve)) {
|
||||
ui.notifications.warn("Le joueur ou le MJ est déja dans les Terres Médianes avec ce personnage ! Visualisation uniquement");
|
||||
mode = "visu"; // bascule le mode en visu automatiquement
|
||||
}
|
||||
@ -3174,7 +3171,7 @@ export class RdDActor extends Actor {
|
||||
});
|
||||
return;
|
||||
}
|
||||
await this.setStatusEffect("EFFECT.StatusDemiReve", true);
|
||||
await this.setEffect(STATUSES.StatusDemiReve, true);
|
||||
}
|
||||
|
||||
const fatigue = this.system.sante.fatigue.value;
|
||||
@ -3464,7 +3461,7 @@ export class RdDActor extends Actor {
|
||||
count--;
|
||||
} else {
|
||||
// TODO: status effect dead
|
||||
this.setStatusEffect("EFFECT.StatusComma", true);
|
||||
this.setEffect(STATUSES.StatusComma, true);
|
||||
ChatMessage.create({
|
||||
content: `<img class="chat-icon" src="icons/svg/skull.svg" alt="charge" />
|
||||
<strong>${this.name} vient de succomber à une seconde blessure critique ! Que les Dragons gardent son Archétype en paix !</strong>`
|
||||
@ -4099,61 +4096,44 @@ export class RdDActor extends Actor {
|
||||
async onUpdateActor(update, options, actorId) {
|
||||
const updatedEndurance = update?.system?.sante?.endurance
|
||||
if (updatedEndurance && options.diff) {
|
||||
await this.setStatusEffect("EFFECT.StatusUnconscious", updatedEndurance.value == 0)
|
||||
await this.setEffect(STATUSES.StatusUnconscious, updatedEndurance.value == 0)
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async onDeleteActiveEffect(effect, options) {
|
||||
switch (effect.label) {
|
||||
case 'EFFECT.StatusStunned':
|
||||
return;
|
||||
}
|
||||
getEffects() {
|
||||
return this.getEmbeddedCollection("ActiveEffect");
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
getActiveEffects(matching = it => true) {
|
||||
return Array.from(this.getEmbeddedCollection("ActiveEffect").values()).filter(it => matching(it));
|
||||
getEffect(statusId) {
|
||||
return this.getEmbeddedCollection("ActiveEffect").find(it => it.flags?.core?.statusId == statusId);
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
getEffectByLabel(label) {
|
||||
return this.getActiveEffects().find(it => it.system?.label == label);
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
getEffectById(id) {
|
||||
return this.getActiveEffects().find(it => it.id == id);
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async setStatusEffect(label, status, updates = {}) {
|
||||
async setEffect(statusId, status) {
|
||||
if (this.isEntite() || this.type == 'vehicule') {
|
||||
return;
|
||||
}
|
||||
console.log("setStatusEffect", label, status, updates)
|
||||
const existing = this.getEffectByLabel(label);
|
||||
if (existing) {
|
||||
existing.delete();
|
||||
}
|
||||
if (status) {
|
||||
const statusEffect = mergeObject(duplicate(StatusEffects.status(label)), updates);
|
||||
await this.createEmbeddedDocuments("ActiveEffect", [statusEffect]);
|
||||
console.log("setEffect", statusId, status)
|
||||
await this.removeEffect(statusId);
|
||||
const effect = StatusEffects.status(statusId);
|
||||
if (effect) {
|
||||
await this.createEmbeddedDocuments("ActiveEffect", [effect]);
|
||||
}
|
||||
}
|
||||
|
||||
enleverActiveEffectById(id) {
|
||||
if (game.user.isGM) {
|
||||
const existing = this.getEffectById(id);
|
||||
if (existing) {
|
||||
existing.delete();
|
||||
}
|
||||
async removeEffect(statusId) {
|
||||
const effect = this.getEffect(statusId);
|
||||
if (effect) {
|
||||
await this.deleteEmbeddedDocuments('ActiveEffect', [effect.id]);
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
enleverTousLesEffets() {
|
||||
if (game.user.isGM) {
|
||||
this.deleteEmbeddedDocuments('ActiveEffect', this.getActiveEffects().map(it => it.id));
|
||||
this.deleteEmbeddedDocuments('ActiveEffect', this.getEffects().map(it => it.id));
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user