Manage wounds in fight

This commit is contained in:
2021-02-15 23:21:53 +01:00
parent de104fb386
commit de4bdb2403
10 changed files with 120 additions and 7 deletions

View File

@ -267,4 +267,62 @@ export class SoSActor extends Actor {
let html = await renderTemplate('systems/foundryvtt-shadows-over-sol/templates/dialog-flip.html', flipData);
new SoSFlipDialog(flipData, html).render(true);
}
/* -------------------------------------------- */
async applyConsequenceWound( severity, consequenceName) {
if ( severity == 'none') return; // Nothing !
let wounds = duplicate(this.data.data.wounds);
if (severity == 'light' ) wounds.light += 1;
if (severity == 'moderate' ) wounds.moderate += 1;
if (severity == 'severe' ) wounds.severe += 1;
if (severity == 'critical' ) wounds.critical += 1;
let sumWound = wounds.light + (wounds.moderate*2) + (wounds.severe*3) + (wounds.critical*4);
let currentWounds = duplicate(this.data.data.scores.currentwounds);
currentWounds.value = sumWound;
await this.update( { 'data.scores.currentwounds': currentWounds, 'data.wounds': wounds } );
let woundData = {
name: this.name,
consequenceName: consequenceName,
severity: severity,
wounds: wounds,
currentWounds: sumWound,
totalWounds: this.data.data.scores.wound.value
}
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") ] } );
}
/* -------------------------------------------- */
async applyWounds( flipData ) {
let wounds = duplicate(this.data.data.wounds);
for (let wound of flipData.woundsList ) {
if (wound == 'L' ) wounds.light += 1;
if (wound == 'M' ) wounds.moderate += 1;
if (wound == 'S' ) wounds.severe += 1;
if (wound == 'C' ) wounds.critical += 1;
}
// Compute total
let sumWound = wounds.light + (wounds.moderate*2) + (wounds.severe*3) + (wounds.critical*4);
let currentWounds = duplicate(this.data.data.scores.currentwounds);
currentWounds.value = sumWound;
if ( sumWound >= this.data.data.scores.wound.value) {
let bleeding = this.data.items.find( item => item.type == 'consequence' && item.name == 'Bleeding');
let newSeverity = SoSUtility.increaseConsequenceSeverity( bleeding.severity );
await this.updateOwnedItem( { _id: bleeding._id, 'data.severity': newSeverity});
flipData.isBleeding = newSeverity;
}
await this.update( { 'data.scores.currentwounds': currentWounds, 'data.wounds': wounds } );
flipData.defenderName = this.name;
flipData.wounds = wounds;
flipData.currentWounds = sumWound;
flipData.totalWounds = this.data.data.scores.wound.value;
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") ] } );
}
}