Manage wounds

This commit is contained in:
2021-02-16 21:14:13 +01:00
parent de4bdb2403
commit cfcc3b3201
8 changed files with 119 additions and 34 deletions

View File

@ -175,6 +175,13 @@ export class SoSActor extends Actor {
}
}
/* -------------------------------------------- */
async updateWound(woundName, value) {
let wounds = duplicate(this.data.data.wounds)
wounds[woundName] = value;
await this.update( { 'data.wounds': wounds } );
}
/* -------------------------------------------- */
async updateSkill(skillName, value) {
let skill = this.data.items.find( item => item.name == skillName);
@ -268,6 +275,26 @@ export class SoSActor extends Actor {
new SoSFlipDialog(flipData, html).render(true);
}
/* -------------------------------------------- */
async checkDeath( ) {
if ( this.data.data.scores.currentwounds.value >= this.data.data.scores.wound.value*2) {
let woundData = {
name: this.name,
wounds: this.data.data.wounds,
currentWounds: this.data.data.scores.currentwounds.value,
totalWounds: this.data.data.scores.wound.value
}
let html = await renderTemplate('systems/foundryvtt-shadows-over-sol/templates/chat-character-death.html', woundData );
ChatMessage.create( { content: html, whisper: [ChatMessage.getWhisperRecipients(this.name), ChatMessage.getWhisperRecipients("GM") ] } );
}
}
/* -------------------------------------------- */
computeCurrentWounds( ) {
let wounds = this.data.data.wounds;
return wounds.light + (wounds.moderate*2) + (wounds.severe*3) + (wounds.critical*4);
}
/* -------------------------------------------- */
async applyConsequenceWound( severity, consequenceName) {
if ( severity == 'none') return; // Nothing !
@ -293,6 +320,8 @@ export class SoSActor extends Actor {
}
let html = await renderTemplate('systems/foundryvtt-shadows-over-sol/templates/chat-damage-consequence.html', woundData );
ChatMessage.create( { content: html, whisper: [ChatMessage.getWhisperRecipients(this.name), ChatMessage.getWhisperRecipients("GM") ] } );
this.checkDeath();
}
/* -------------------------------------------- */
@ -315,7 +344,7 @@ export class SoSActor extends Actor {
flipData.isBleeding = newSeverity;
}
await this.update( { 'data.scores.currentwounds': currentWounds, 'data.wounds': wounds } );
flipData.defenderName = this.name;
flipData.wounds = wounds;
flipData.currentWounds = sumWound;
@ -323,6 +352,7 @@ export class SoSActor extends Actor {
let html = await renderTemplate('systems/foundryvtt-shadows-over-sol/templates/chat-damage-taken.html', flipData );
ChatMessage.create( { content: html, whisper: [ChatMessage.getWhisperRecipients(this.name), ChatMessage.getWhisperRecipients("GM") ] } );
this.checkDeath();
}
}