Manage wounds

This commit is contained in:
sladecraven 2021-02-16 22:04:59 +01:00
parent cfcc3b3201
commit fb0eb9dcc8
9 changed files with 137 additions and 27 deletions

View File

@ -26,6 +26,8 @@ export class SoSActorSheet extends ActorSheet {
let data = super.getData(); let data = super.getData();
data.data.edgecard = this.actor.getEdgesCard(); data.data.edgecard = this.actor.getEdgesCard();
data.data.deckSize = this.actor.getDeckSize();
data.data.skills = this.actor.data.items.filter( item => item.type == 'skill').sort( (a, b) => { data.data.skills = this.actor.data.items.filter( item => item.type == 'skill').sort( (a, b) => {
if ( a.name > b.name ) return 1; if ( a.name > b.name ) return 1;
return -1; return -1;

View File

@ -59,6 +59,12 @@ export class SoSActor extends Actor {
} }
this.controlScores(); this.controlScores();
} }
/* -------------------------------------------- */
getDeckSize() {
return this.cardDeck.getDeckSize();
}
/* -------------------------------------------- */ /* -------------------------------------------- */
getEdgesCard( ) { getEdgesCard( ) {
let edgesCard = duplicate(this.cardDeck.data.cardEdge); let edgesCard = duplicate(this.cardDeck.data.cardEdge);

View File

@ -94,6 +94,11 @@ export class SoSCardDeck {
} }
} }
/* -------------------------------------------- */
getDeckSize() {
return this.data.deck.length;
}
/* -------------------------------------------- */ /* -------------------------------------------- */
getCardSuit( cardName ) { getCardSuit( cardName ) {
if ( cardName[0] == 'c') return 'club'; if ( cardName[0] == 'c') return 'club';

View File

@ -139,6 +139,18 @@ export class SoSCombat extends Combat {
return 0; return 0;
} }
/* -------------------------------------------- */
decreaseAPFromActor( actorId ) {
for( let combatant of this.combatants) {
//console.log(combatant);
if ( combatant.actor.data._id == actorId ) {
let phase = this.phaseSetup[combatant._id];
phase.remainingAP -= 1;
if ( phase.remainingAP < 0 ) phase.remainingAP = 0;
}
}
}
/* -------------------------------------------- */ /* -------------------------------------------- */
async setupActorActions(actionConf) { async setupActorActions(actionConf) {
console.log("Setting combat for phase : ", actionConf); console.log("Setting combat for phase : ", actionConf);

View File

@ -35,19 +35,21 @@ export class SoSUtility {
/* -------------------------------------------- */ /* -------------------------------------------- */
onSocketMesssage( msg ) { onSocketMesssage( msg ) {
if( !game.user.isGM ) return; // Only GM
if (msg.name == 'msg_declare_actions' ) { if (msg.name == 'msg_declare_actions' ) {
if (game.user.isGM) {
let combat = game.combats.get( msg.data.combatId); // Get the associated combat let combat = game.combats.get( msg.data.combatId); // Get the associated combat
combat.setupActorActions( msg.data ); combat.setupActorActions( msg.data );
}
} else if (msg.name == 'msg_close_action') { } else if (msg.name == 'msg_close_action') {
if (game.user.isGM) {
game.combat.closeAction( msg.data.uniqId ); game.combat.closeAction( msg.data.uniqId );
}
} else if (msg.name == 'msg_request_defense') { } else if (msg.name == 'msg_request_defense') {
if (game.user.isGM) {
SoSUtility.applyDamage( msg.data ); SoSUtility.applyDamage( msg.data );
} } else if (msg.name == 'msg_reaction_cover') {
SoSUtility.reactionCover( msg.data.uniqId );
} else if (msg.name == 'msg_reaction_melee') {
SoSUtility.reactionMelee( msg.data.uniqId );
} else if (msg.name == 'msg_reaction_hit') {
SoSUtility.reactionHit( msg.data.uniqId );
} }
} }
@ -119,7 +121,7 @@ export class SoSUtility {
if ( game.user.isGM ) { if ( game.user.isGM ) {
game.combat.closeAction( uniqId ); game.combat.closeAction( uniqId );
} else { } else {
game.socket.emit("system.foundryvtt-reve-de-dragon", { game.socket.emit("system.foundryvtt-shadows-over-sol", {
name: "msg_close_action", data: { uniqId: uniqId} } ); name: "msg_close_action", data: { uniqId: uniqId} } );
} }
} }
@ -132,6 +134,32 @@ export class SoSUtility {
html.on("click", '#button-end-action', event => { html.on("click", '#button-end-action', event => {
SoSUtility.closeAction( event ); SoSUtility.closeAction( event );
}); });
html.on("click", '#button-reaction-cover', event => {
let uniqId = event.currentTarget.attributes['data-uniq-id'].value;
if ( game.user.isGM ) {
SoSUtility.reactionCover( uniqId );
} else {
game.socket.emit("system.foundryvtt-shadows-over-sol", { name: "msg_reaction_cover", data: { uniqId: uniqId} } );
}
});
html.on("click", '#button-reaction-melee', event => {
let uniqId = event.currentTarget.attributes['data-uniq-id'].value;
if ( game.user.isGM ) {
SoSUtility.reactionMelee( uniqId );
} else {
game.socket.emit("system.foundryvtt-shadows-over-sol", { name: "msg_reaction_melee", data: { uniqId: uniqId} } );
}
});
html.on("click", '#button-reaction-hit', event => {
let uniqId = event.currentTarget.attributes['data-uniq-id'].value;
if ( game.user.isGM ) {
SoSUtility.reactionHit( uniqId );
} else {
game.socket.emit("system.foundryvtt-shadows-over-sol", { name: "msg_reaction_hit", data: { uniqId: uniqId} } );
}
});
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
@ -153,6 +181,16 @@ export class SoSUtility {
return 'critical'; return 'critical';
} }
/* -------------------------------------------- */
static getConsequenceSeverityLevel( severity) {
if ( severity == 'none') return 0;
if ( severity == 'light') return 1;
if ( severity == 'moderate') return 2;
if ( severity == 'severe') return 3;
if ( severity == 'critical') return 4;
return 0;
}
/* -------------------------------------------- */ /* -------------------------------------------- */
static increaseSeverity( severity ) { static increaseSeverity( severity ) {
if ( severity == 'L') return 'M'; if ( severity == 'L') return 'M';
@ -180,6 +218,17 @@ export class SoSUtility {
/* -------------------------------------------- */ /* -------------------------------------------- */
static async applyDamage( flipData ) { static async applyDamage( flipData ) {
if (!this.registry) this.registry = {};
if ( flipData.isReaction) {
flipData.magnitude = flipData.finalScore - flipData.tn; // Update magnitude
if ( flipData.magnitude < 0 ) {
let html = await renderTemplate('systems/foundryvtt-shadows-over-sol/templates/chat-reaction-result.html', flipData );
ChatMessage.create( { content: html });
return;
}
}
let dr = flipData.target.actor.data.data.scores.dr.value; let dr = flipData.target.actor.data.data.scores.dr.value;
let shock = flipData.target.actor.data.data.scores.shock.value; let shock = flipData.target.actor.data.data.scores.shock.value;
let defenseCritical = flipData.target.actor.data.data.scores.defense.critical; let defenseCritical = flipData.target.actor.data.data.scores.defense.critical;
@ -228,22 +277,50 @@ export class SoSUtility {
flipData.coverConsequence = defender.data.items.find( item => item.type == 'consequence' && item.name == 'Cover'); flipData.coverConsequence = defender.data.items.find( item => item.type == 'consequence' && item.name == 'Cover');
flipData.APavailable = game.combat.getAPFromActor( defender.data._id ); flipData.APavailable = game.combat.getAPFromActor( defender.data._id );
console.log("FLIPDATE : ", flipData); console.log("FLIPDATE : ", flipData);
if ( flipData.APavailable > 0) { if ( !flipData.isReaction && flipData.APavailable > 0) {
if ( (flipData.weapon.data.category == 'melee' ) || ( (flipData.weapon.data.category == 'laser' || flipData.weapon.data.category == 'ballistic') && if ( (flipData.weapon.data.category == 'melee' ) || ( (flipData.weapon.data.category == 'laser' || flipData.weapon.data.category == 'ballistic') &&
flipData.coverConsequence.data.severity != 'none') ) { flipData.coverConsequence.data.severity != 'none') ) {
flipData.coverSeverityLevel = this.getSeverityLevel( flipData.coverConsequence.data.severity ) * 2; flipData.coverSeverityLevel = this.getConsequenceSeverityLevel( flipData.coverConsequence.data.severity ) * 2;
flipData.coverSeverityFlag = (flipData.coverSeverityLevel > 0); flipData.coverSeverityFlag = (flipData.coverSeverityLevel > 0);
flipData.isMelee = (flipData.weapon.data.category == 'melee' ); flipData.isMelee = (flipData.weapon.data.category == 'melee' );
let melee = defender.data.items.find( item => item.type == 'skill' && item.name == 'Melee'); let melee = defender.data.items.find( item => item.type == 'skill' && item.name == 'Melee');
flipData.defenderMelee = melee.data.value; flipData.defenderMelee = melee.data.value;
flipData.uniqId = randomID(16);
this.registry[flipData.uniqId] = flipData;
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 return; // Wait message response
} }
} }
flipData.isReaction = false;
this.takeWounds( flipData); this.takeWounds( flipData);
} }
/* -------------------------------------------- */
static reactionCover( uniqId) {
let flipData = this.registry[uniqId];
flipData.tn += flipData.coverSeverityLevel;
flipData.isReaction = true;
game.combat.decreaseAPFromActor( flipData.target.actor._id );
SoSUtility.applyDamage( flipData);
}
/* -------------------------------------------- */
static reactionMelee( uniqId) {
let flipData = this.registry[uniqId];
flipData.tn += flipData.defenderMelee;
flipData.isReaction = true;
game.combat.decreaseAPFromActor( flipData.target.actor._id );
SoSUtility.applyDamage( flipData);
}
/* -------------------------------------------- */
static reactionHit( uniqId) {
let flipData = this.registry[uniqId];
flipData.isReaction = true;
SoSUtility.takeWounds( flipData);
}
/* -------------------------------------------- */ /* -------------------------------------------- */
static takeWounds( flipData ) { static takeWounds( flipData ) {
let defender = game.actors.get( flipData.target.actor._id); let defender = game.actors.get( flipData.target.actor._id);

View File

@ -1032,7 +1032,7 @@ ul, li {
cursor: pointer; cursor: pointer;
color: #ffffff; color: #ffffff;
font-family: Neuropol; font-family: Neuropol;
font-size: 14px; font-size: 0.9rem;
padding: 4px 12px 0px 12px; padding: 4px 12px 0px 12px;
text-decoration: none; text-decoration: none;
text-shadow: 0px 1px 0px #4d3534; text-shadow: 0px 1px 0px #4d3534;

View File

@ -73,12 +73,13 @@
<div class="flexrow"> <div class="flexrow">
<span class="flexcol"> <span class="flexcol">
<h3 class="edge-name">Edge cards : </h3> <h3 class="edge-name">Current deck size : {{data.deckSize}} cards</h3>
<span class="edge-name"><a class="reset-deck-full">Reset full deck and edges</a></span> <span class="edge-name"><a class="reset-deck-full">Reset full deck and edges</a></span>
<span class="edge-name"><a class="draw-new-edge">Draw a new Edge card</a></span> <span class="edge-name"><a class="draw-new-edge">Draw a new Edge card</a></span>
<span class="edge-name"><a class="reset-deck">Reset deck only (ie after a Joker)</a></span> <span class="edge-name"><a class="reset-deck">Reset deck only (ie after a Joker)</a></span>
</span> </span>
<span class="edge-name"> <span class="edge-name">
<h3 class="edge-name">Edge cards : </h3>
{{#each data.edgecard as |card key|}} {{#each data.edgecard as |card key|}}
<img class="card-img" src="{{card.path}}" data-edit="img" title="{{card.cardName}}" /> <img class="card-img" src="{{card.path}}" data-edit="img" title="{{card.cardName}}" />
{{/each}} {{/each}}

View File

@ -1,10 +1,13 @@
<h4>{{target.actor.name}} has {{remainingAP}} AP and can react to the attack from {{actor.name}} !</h4> <h4>{{target.actor.name}} has {{APavailable}} AP and can react to the attack from {{actor.name}} !</h4>
<div class="flexcol"> <div class="flexcol">
{{#if coverSeverityFlag}} {{#if coverSeverityFlag}}
<label>Add cover consequence bonus * 2 to your defense : {{coverSeverityLevel}}</label> <a class='chat-card-button' id='button-reaction-cover' data-uniq-id='{{uniqId}}' data-actor-id='{{target.actor._id}}'>
Add cover consequence bonus x 2 to your defense : {{coverSeverityLevel}}</a>`
{{/if}} {{/if}}
{{#if isMelee}} {{#if isMelee}}
<label>Add Melee level to your defense : {{defenderMelee}}</label> <a class='chat-card-button' id='button-reaction-melee' data-uniq-id='{{uniqId}}' data-actor-id='{{target.actor._id}}'>
Add Melee level to your defense : {{defenderMelee}}</a>`
{{/if}} {{/if}}
<label>Do not dodge and get the hit ! </label> <a class='chat-card-button' id='button-reaction-hit' data-uniq-id='{{uniqId}}' data-actor-id='{{target.actor._id}}'>
Do not dodge and get the hit !</a>`
</div> </div>

View File

@ -0,0 +1,4 @@
<h4>{{target.actor.name}} reacted and has avoided damages !</h4>
<div class="flexcol">
<label>Score : {{finalScore}} - Target defense : {{tn}} / {{targetCritical}}</label>
</div>