2023-11-04 03:42:39 +01:00
|
|
|
import { ENTITE_INCARNE, ENTITE_NONINCARNE } from "../constants.js";
|
2024-09-25 22:56:24 +02:00
|
|
|
import { ITEM_TYPES } from "../item.js";
|
2023-11-04 03:42:39 +01:00
|
|
|
import { Misc } from "../misc.js";
|
2024-12-18 17:26:28 +01:00
|
|
|
import { RdDCarac } from "../rdd-carac.js";
|
2023-11-04 03:42:39 +01:00
|
|
|
import { RdDEncaisser } from "../rdd-roll-encaisser.js";
|
|
|
|
import { STATUSES } from "../settings/status-effects.js";
|
|
|
|
import { RdDBaseActorReve } from "./base-actor-reve.js";
|
|
|
|
|
|
|
|
export class RdDEntite extends RdDBaseActorReve {
|
|
|
|
|
|
|
|
static get defaultIcon() {
|
|
|
|
return "systems/foundryvtt-reve-de-dragon/icons/entites/darquoine.webp";
|
|
|
|
}
|
|
|
|
|
|
|
|
canReceive(item) {
|
2024-09-25 22:56:24 +02:00
|
|
|
return item.type == ITEM_TYPES.competencecreature
|
2023-11-04 03:42:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
isEntite(typeentite = []) {
|
|
|
|
return (typeentite.length == 0 || typeentite.includes(this.system.definition.typeentite));
|
|
|
|
}
|
2024-12-18 17:26:28 +01:00
|
|
|
|
2023-11-04 03:42:39 +01:00
|
|
|
isNonIncarnee() { return this.isEntite([ENTITE_NONINCARNE]) }
|
|
|
|
|
|
|
|
getReveActuel() {
|
|
|
|
return Misc.toInt(this.system.carac.reve?.value)
|
|
|
|
}
|
|
|
|
|
2024-12-18 17:26:28 +01:00
|
|
|
getCarac() {
|
|
|
|
const carac = super.getCarac()
|
|
|
|
delete carac.niveau
|
|
|
|
return carac
|
|
|
|
}
|
|
|
|
|
|
|
|
getNiveau() {
|
|
|
|
const reve = this.getReve()
|
|
|
|
return RdDCarac.getCaracDerivee(reve).niveau
|
|
|
|
}
|
2023-11-04 03:42:39 +01:00
|
|
|
getForce() { return this.getReve() }
|
|
|
|
getAgilite() { return this.getReve() }
|
|
|
|
getChance() { return this.getReve() }
|
2024-12-04 15:55:09 +01:00
|
|
|
getEnduranceMax() { return Math.max(1, this.getTaille() + this.getReve()) }
|
2023-11-04 03:42:39 +01:00
|
|
|
|
|
|
|
getDraconicOuPossession() {
|
2024-09-25 22:56:24 +02:00
|
|
|
return this.itemTypes[ITEM_TYPES.competencecreature]
|
2023-11-04 03:42:39 +01:00
|
|
|
.filter(it => it.system.categorie == 'possession')
|
|
|
|
.sort(Misc.descending(it => it.system.niveau))
|
|
|
|
.find(it => true);
|
|
|
|
}
|
|
|
|
|
|
|
|
async remiseANeuf() {
|
|
|
|
await this.removeEffects(e => true);
|
|
|
|
if (!this.isNonIncarnee()) {
|
|
|
|
await this.update({
|
|
|
|
'system.sante.endurance.value': this.system.sante.endurance.max
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
isDead() {
|
|
|
|
return this.isNonIncarnee() ? false : this.system.sante.endurance.value <= 0
|
|
|
|
}
|
|
|
|
|
|
|
|
async santeIncDec(name, inc, isCritique = false) {
|
|
|
|
if (name == 'endurance' && !this.isNonIncarnee()) {
|
|
|
|
const oldValue = this.system.sante.endurance.value;
|
|
|
|
const endurance = Math.max(0,
|
|
|
|
Math.min(oldValue + inc,
|
|
|
|
this.system.sante.endurance.max));
|
|
|
|
await this.update({ "system.sante.endurance.value": endurance })
|
|
|
|
await this.setEffect(STATUSES.StatusComma, endurance <= 0);
|
|
|
|
return {
|
|
|
|
perte: oldValue - endurance,
|
|
|
|
newValue: endurance
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return {}
|
|
|
|
}
|
2024-12-18 17:26:28 +01:00
|
|
|
|
2023-11-04 03:42:39 +01:00
|
|
|
async encaisser() {
|
|
|
|
if (this.isNonIncarnee()) {
|
|
|
|
return
|
|
|
|
}
|
2024-08-31 00:21:24 +02:00
|
|
|
await RdDEncaisser.encaisser(this)
|
2023-11-04 03:42:39 +01:00
|
|
|
}
|
|
|
|
|
2023-12-08 23:50:16 +01:00
|
|
|
isEffectAllowed(effectId) {
|
|
|
|
return [STATUSES.StatusComma].includes(effectId);
|
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
|
|
|
const perteEndurance = await this.santeIncDec("endurance", -encaissement.endurance);
|
2024-05-01 09:13:21 +02:00
|
|
|
foundry.utils.mergeObject(encaissement, {
|
2023-11-04 03:42:39 +01:00
|
|
|
resteEndurance: perteEndurance.newValue,
|
|
|
|
endurance: perteEndurance.perte
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
isEntiteAccordee(attacker) {
|
|
|
|
if (this.isEntite([ENTITE_INCARNE])) {
|
|
|
|
let resonnance = this.system.sante.resonnance
|
|
|
|
return (resonnance.actors.find(it => it == attacker.id))
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
2024-08-31 00:21:24 +02:00
|
|
|
async setEntiteReveAccordee(actor) {
|
2023-11-04 03:42:39 +01:00
|
|
|
if (this.isEntite([ENTITE_INCARNE])) {
|
2024-08-31 00:21:24 +02:00
|
|
|
if (this.system.sante.resonnance.actors.find(it => it == actor.id)) {
|
2023-11-04 03:42:39 +01:00
|
|
|
// déjà accordé
|
2024-08-31 00:21:24 +02:00
|
|
|
return
|
2023-11-04 03:42:39 +01:00
|
|
|
}
|
2024-08-31 00:21:24 +02:00
|
|
|
await this.update({ "system.sante.resonnance.actors": [...this.system.sante.resonnance.actors, actor.id] })
|
2023-11-04 03:42:39 +01:00
|
|
|
}
|
|
|
|
else {
|
2024-08-31 00:21:24 +02:00
|
|
|
super.setEntiteReveAccordee(actor)
|
2023-11-04 03:42:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|