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") ] } );
}
}

View File

@ -266,7 +266,7 @@ export class SoSCardDeck {
SoSUtility.applyDamage( flipData );
} else {
game.socket.emit("system.foundryvtt-shadows-over-sol", {
msg: "msg_defense", data: flipData } );
msg: "msg_request_defense", data: flipData } );
}
} else {
let html = await renderTemplate('systems/foundryvtt-shadows-over-sol/templates/chat-damage-only.html', flipData );

View File

@ -39,6 +39,7 @@ export class SoSCombat extends Combat {
gotoNextTurn() {
this.phaseNumber -= 1;
if ( this.phaseNumber <= 0) {
this.applyConsequences();
this.nextRound(); // Auto-switch to next round
} else {
this.nextTurn();
@ -91,6 +92,16 @@ export class SoSCombat extends Combat {
this.currentActions = actionList;
}
/* -------------------------------------------- */
applyConsequences( ) {
if (game.user.isGM ) {
for( let combatant of this.combatants) {
let bleeding = combatant.actor.data.items.find( item => item.type == 'consequence' && item.name == 'Bleeding');
combatant.actor.applyConsequenceWound( bleeding.severity, "bleeding" );
}
}
}
/* -------------------------------------------- */
closeAction( uniqId) {
let action = this.currentActions.find( _action => _action.uniqId == uniqId );
@ -146,7 +157,7 @@ export class SoSCombat extends Combat {
}
if ( actionsDone ) {
this.actionsRequested = false;
ChatMessage.create( { content: `Action phase has been completed ! Now proceeding with actions.`,
ChatMessage.create( { content: `Action declaration phase has been completed ! Now proceeding with actions.`,
whisper: [ ChatMessage.getWhisperRecipients("GM") ] } );
this.phaseNumber = 3;
this.nextTurn();

View File

@ -44,6 +44,10 @@ export class SoSUtility {
if (game.user.isGM) {
game.combat.closeAction( msg.data.uniqId );
}
} else if (msg.name == 'msg_request_defense') {
if (game.user.isGM) {
SoSUtility.applyDamage( msg.data );
}
}
}
@ -140,6 +144,15 @@ export class SoSUtility {
return undefined;
}
/* -------------------------------------------- */
static increaseConsequenceSeverity( severity ) {
if ( severity == 'none') return 'light';
if ( severity == 'light') return 'moderate';
if ( severity == 'moderate') return 'severe';
if ( severity == 'severe') return 'critical';
return 'critical';
}
/* -------------------------------------------- */
static increaseSeverity( severity ) {
if ( severity == 'L') return 'M';
@ -225,7 +238,16 @@ export class SoSUtility {
flipData.defenderMelee = melee.data.value;
let html = await renderTemplate('systems/foundryvtt-shadows-over-sol/templates/chat-damage-request-dodge.html', flipData );
ChatMessage.create( { content: html, whisper: [ChatMessage.getWhisperRecipients(flipData.target.actor.name), ChatMessage.getWhisperRecipients("GM") ] } );
return; // Wait message response
}
}
this.takeWounds( flipData);
}
/* -------------------------------------------- */
static takeWounds( flipData ) {
let defender = game.actors.get( flipData.target.actor._id);
defender.applyWounds( flipData );
}
}