Le coeur s'applique à ChâteauDormant

This commit is contained in:
2023-11-27 23:45:33 +01:00
parent 50db9ba709
commit 33ced5715d
9 changed files with 74 additions and 35 deletions

View File

@ -53,22 +53,46 @@ export class RdDCoeur {
static async toggleSubActeurCoeur(actorId, subActorId, toggleCoeur) {
const actor = game.actors.get(actorId)
if (ReglesOptionnelles.isUsing("chateau-dormant-gardien") && !actor.system.sommeil.nouveaujour) {
ui.notifications.warn(`Les changements de points de coeur se font juste avant de gérer Château Dormant, juste avant de passer à un nouveau jour`)
return
const amoureux = actor.getSuivant(subActorId)
if (toggleCoeur <= amoureux.coeur) {
if (toggleCoeur > amoureux.prochainCoeur) {
toggleCoeur = amoureux.coeur
}
else {
toggleCoeur = amoureux.coeur - 1
}
}
const coeur = actor.getPointsCoeur(subActorId);
if (toggleCoeur <= coeur) {
// TODO: validation?
await actor.moralIncDec(-4);
actor.setPointsCoeur(subActorId, Math.max(0, coeur - 1));
ChatMessage.create({
whisper: ChatUtility.getWhisperRecipientsAndGMs(actor.name),
content: `Perte de points de coeur arbitraire: ${actor.name} perd 4 points de moral, pour finir à ${actor.getMoralTotal()}.`
});
else if (toggleCoeur <= amoureux.prochainCoeur) {
toggleCoeur = Math.max(amoureux.coeur, toggleCoeur - 1)
}
else {
actor.setPointsCoeur(subActorId, Math.min(4, toggleCoeur));
actor.setPointsCoeur(subActorId, Math.max(0, Math.min(toggleCoeur, 4)))
}
static async applyCoeurChateauDormant(actor, message) {
const newSuivants = duplicate(actor.system.subacteurs.suivants)
let count = 0
newSuivants.forEach(async link => {
const suivant = game.actors.get(link.id)
const prochainCoeur = link.prochainCoeur ?? 0;
const coeurCourant = link.coeur ?? 0;
const diff = prochainCoeur - coeurCourant
if (diff < 0) {
await actor.moralIncDec(-4);
link.coeur = Math.max(0, coeurCourant - 1)
link.prochainCoeur = link.coeur
message.content += `<br>Votre c&oelig;ur brisé pour ${suivant.name} vous fait perdre 4 points de moral, il vous reste ${link.coeur} points de C&oelig;ur.`
count++
}
else if (diff > 0) {
link.coeur = Math.min(prochainCoeur, 4)
message.content += `<br>Votre c&oelig;ur bat fort, vous avez maintenant ${link.coeur} points de C&oelig;ur pour ${suivant.name}.`
link.prochainCoeur = link.coeur
count++
}
}
)
if (count > 0) {
await actor.update({ 'system.subacteurs.suivants': newSuivants });
}
}
@ -130,14 +154,13 @@ export class RdDCoeur {
? [infoCoeur.target, infoCoeur.source]
: [undefined, undefined]))
const subActorId = partenaire?.actor.id;
if (amoureux.perteCoeur) {
ui.notifications.warn(`Un point de coeur a déjà été perdu`)
ui.notifications.warn(`Le point de c&oelig;ur a déjà été perdu`)
}
else if (amoureux.coeur > 0) {
const actor = game.actors.get(actorId)
if (actor.isOwner) {
await actor.setPointsCoeur(subActorId, amoureux.coeur - 1)
await actor.setPointsCoeur(partenaire?.actor.id, amoureux.coeur - 1, { immediat: true })
amoureux.perteCoeur = true
RdDCoeur.addTagsInfoCoeur(infoCoeur)
}