Manage wounds in fight

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

View File

@ -10,7 +10,7 @@
"SCORES.Lifestyle": "Lifestyle", "SCORES.Lifestyle": "Lifestyle",
"SCORES.Defense": "Defense", "SCORES.Defense": "Defense",
"SCORES.DR": "DR", "SCORES.DR": "DR",
"SCORES.Totalwounds": "Totalwounds", "SCORES.Currentwounds": "Current Wounds",
"SCORES.Shock": "Shock", "SCORES.Shock": "Shock",
"SCORES.Wounds": "Wounds", "SCORES.Wounds": "Wounds",
"SCORES.Encumbrance": "Encumbrance", "SCORES.Encumbrance": "Encumbrance",

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); let html = await renderTemplate('systems/foundryvtt-shadows-over-sol/templates/dialog-flip.html', flipData);
new SoSFlipDialog(flipData, html).render(true); 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 ); SoSUtility.applyDamage( flipData );
} else { } else {
game.socket.emit("system.foundryvtt-shadows-over-sol", { game.socket.emit("system.foundryvtt-shadows-over-sol", {
msg: "msg_defense", data: flipData } ); msg: "msg_request_defense", data: flipData } );
} }
} else { } else {
let html = await renderTemplate('systems/foundryvtt-shadows-over-sol/templates/chat-damage-only.html', flipData ); 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() { gotoNextTurn() {
this.phaseNumber -= 1; this.phaseNumber -= 1;
if ( this.phaseNumber <= 0) { if ( this.phaseNumber <= 0) {
this.applyConsequences();
this.nextRound(); // Auto-switch to next round this.nextRound(); // Auto-switch to next round
} else { } else {
this.nextTurn(); this.nextTurn();
@ -91,6 +92,16 @@ export class SoSCombat extends Combat {
this.currentActions = actionList; 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) { closeAction( uniqId) {
let action = this.currentActions.find( _action => _action.uniqId == uniqId ); let action = this.currentActions.find( _action => _action.uniqId == uniqId );
@ -146,7 +157,7 @@ export class SoSCombat extends Combat {
} }
if ( actionsDone ) { if ( actionsDone ) {
this.actionsRequested = false; 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") ] } ); whisper: [ ChatMessage.getWhisperRecipients("GM") ] } );
this.phaseNumber = 3; this.phaseNumber = 3;
this.nextTurn(); this.nextTurn();

View File

@ -44,6 +44,10 @@ export class SoSUtility {
if (game.user.isGM) { if (game.user.isGM) {
game.combat.closeAction( msg.data.uniqId ); 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; 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 ) { static increaseSeverity( severity ) {
if ( severity == 'L') return 'M'; if ( severity == 'L') return 'M';
@ -225,7 +238,16 @@ export class SoSUtility {
flipData.defenderMelee = melee.data.value; flipData.defenderMelee = melee.data.value;
let html = await renderTemplate('systems/foundryvtt-shadows-over-sol/templates/chat-damage-request-dodge.html', flipData ); 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") ] } ); 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 );
}
} }

View File

@ -819,7 +819,7 @@ ul, li {
.chat-message { .chat-message {
background: rgba(220,220,210,0.5); background: rgba(220,220,210,0.5);
font-size: 1rem; font-size: 0.8rem;
} }
.chat-message.whisper { .chat-message.whisper {

View File

@ -2,7 +2,7 @@
"name": "foundryvtt-shadows-over-sol", "name": "foundryvtt-shadows-over-sol",
"title": "Shadows over Sol", "title": "Shadows over Sol",
"description": "Shadows over Sol for FoundryVTT", "description": "Shadows over Sol for FoundryVTT",
"version": "0.0.21", "version": "0.0.22",
"manifestPlusVersion": "1.0.0", "manifestPlusVersion": "1.0.0",
"minimumCoreVersion": "0.7.5", "minimumCoreVersion": "0.7.5",
"compatibleCoreVersion": "0.7.9", "compatibleCoreVersion": "0.7.9",

View File

@ -104,8 +104,8 @@
"label": "SCORES.Shock", "label": "SCORES.Shock",
"value": 0 "value": 0
}, },
"totalwounds": { "currentwounds": {
"label": "SCORES.Totalwounds", "label": "SCORES.Currentwounds",
"value": 0 "value": 0
}, },
"wound": { "wound": {

View File

@ -0,0 +1,9 @@
<h4>{{name}} has taken a new {{severity}} wound, due to the {{consequenceName}} consequence !</h4>
<div class="flexcol">
<label>Light Wounds : {{wounds.light}}</label>
<label>Moderate Wounds : {{wounds.moderate}}</label>
<label>Severe Wounds : {{wounds.severe}}</label>
<label>Critical Wounds : {{wounds.critical}}</label>
<label>Current wounds value : {{currentWounds}}</label>
<label>Total wounds : {{totalWounds}}</label>
</div>

View File

@ -0,0 +1,13 @@
<h4>{{defenderName}} has taken damages !</h4>
<div class="flexcol">
<label>Light Wounds : {{wounds.light}}</label>
<label>Moderate Wounds : {{wounds.moderate}}</label>
<label>Severe Wounds : {{wounds.severe}}</label>
<label>Critical Wounds : {{wounds.critical}}</label>
<label>Current wounds value : {{currentWounds}}</label>
<label>Total wounds : {{totalWounds}}</label>
{{#if isBleeding}}
<label>{{defenderName}} is bleeding with severity {{isBleeding}}. He will have a new {{isBleeding}} wound at the end of the round !</label>
{{/if}}
</div>