diff --git a/lang/en.json b/lang/en.json index 37e94d9..55816fb 100644 --- a/lang/en.json +++ b/lang/en.json @@ -10,7 +10,7 @@ "SCORES.Lifestyle": "Lifestyle", "SCORES.Defense": "Defense", "SCORES.DR": "DR", - "SCORES.Totalwounds": "Totalwounds", + "SCORES.Currentwounds": "Current Wounds", "SCORES.Shock": "Shock", "SCORES.Wounds": "Wounds", "SCORES.Encumbrance": "Encumbrance", diff --git a/module/actor.js b/module/actor.js index 6c2fd52..74954f2 100644 --- a/module/actor.js +++ b/module/actor.js @@ -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") ] } ); + + } + } diff --git a/module/sos-card-deck.js b/module/sos-card-deck.js index e33ebfb..80ebbfd 100644 --- a/module/sos-card-deck.js +++ b/module/sos-card-deck.js @@ -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 ); diff --git a/module/sos-combat.js b/module/sos-combat.js index 27389c1..4fe7172 100644 --- a/module/sos-combat.js +++ b/module/sos-combat.js @@ -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(); diff --git a/module/sos-utility.js b/module/sos-utility.js index 5a4bc08..f3870be 100644 --- a/module/sos-utility.js +++ b/module/sos-utility.js @@ -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 ); + } + } \ No newline at end of file diff --git a/styles/simple.css b/styles/simple.css index 19cb29b..ea7a96c 100644 --- a/styles/simple.css +++ b/styles/simple.css @@ -819,7 +819,7 @@ ul, li { .chat-message { background: rgba(220,220,210,0.5); - font-size: 1rem; + font-size: 0.8rem; } .chat-message.whisper { diff --git a/system.json b/system.json index 70d75e7..32e1554 100644 --- a/system.json +++ b/system.json @@ -2,7 +2,7 @@ "name": "foundryvtt-shadows-over-sol", "title": "Shadows over Sol", "description": "Shadows over Sol for FoundryVTT", - "version": "0.0.21", + "version": "0.0.22", "manifestPlusVersion": "1.0.0", "minimumCoreVersion": "0.7.5", "compatibleCoreVersion": "0.7.9", diff --git a/template.json b/template.json index c9d705f..2dc3668 100644 --- a/template.json +++ b/template.json @@ -104,8 +104,8 @@ "label": "SCORES.Shock", "value": 0 }, - "totalwounds": { - "label": "SCORES.Totalwounds", + "currentwounds": { + "label": "SCORES.Currentwounds", "value": 0 }, "wound": { diff --git a/templates/chat-damage-consequence.html b/templates/chat-damage-consequence.html new file mode 100644 index 0000000..a142dc7 --- /dev/null +++ b/templates/chat-damage-consequence.html @@ -0,0 +1,9 @@ +

{{name}} has taken a new {{severity}} wound, due to the {{consequenceName}} consequence !

+
+ + + + + + +
diff --git a/templates/chat-damage-taken.html b/templates/chat-damage-taken.html new file mode 100644 index 0000000..19013c8 --- /dev/null +++ b/templates/chat-damage-taken.html @@ -0,0 +1,13 @@ +

{{defenderName}} has taken damages !

+
+ + + + + + + {{#if isBleeding}} + + {{/if}} + +