|
|
|
@ -35,19 +35,21 @@ export class SoSUtility {
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
|
onSocketMesssage( msg ) {
|
|
|
|
|
if( !game.user.isGM ) return; // Only GM
|
|
|
|
|
|
|
|
|
|
if (msg.name == 'msg_declare_actions' ) {
|
|
|
|
|
if (game.user.isGM) {
|
|
|
|
|
let combat = game.combats.get( msg.data.combatId); // Get the associated combat
|
|
|
|
|
combat.setupActorActions( msg.data );
|
|
|
|
|
}
|
|
|
|
|
let combat = game.combats.get( msg.data.combatId); // Get the associated combat
|
|
|
|
|
combat.setupActorActions( msg.data );
|
|
|
|
|
} 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') {
|
|
|
|
|
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 ) {
|
|
|
|
|
game.combat.closeAction( uniqId );
|
|
|
|
|
} else {
|
|
|
|
|
game.socket.emit("system.foundryvtt-reve-de-dragon", {
|
|
|
|
|
game.socket.emit("system.foundryvtt-shadows-over-sol", {
|
|
|
|
|
name: "msg_close_action", data: { uniqId: uniqId} } );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -132,6 +134,32 @@ export class SoSUtility {
|
|
|
|
|
html.on("click", '#button-end-action', 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} } );
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
@ -144,14 +172,24 @@ 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 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 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 ) {
|
|
|
|
@ -180,6 +218,17 @@ export class SoSUtility {
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
|
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 shock = flipData.target.actor.data.data.scores.shock.value;
|
|
|
|
|
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.APavailable = game.combat.getAPFromActor( defender.data._id );
|
|
|
|
|
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') &&
|
|
|
|
|
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.isMelee = (flipData.weapon.data.category == 'melee' );
|
|
|
|
|
let melee = defender.data.items.find( item => item.type == 'skill' && item.name == 'Melee');
|
|
|
|
|
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 );
|
|
|
|
|
ChatMessage.create( { content: html, whisper: [ChatMessage.getWhisperRecipients(flipData.target.actor.name), ChatMessage.getWhisperRecipients("GM") ] } );
|
|
|
|
|
return; // Wait message response
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
flipData.isReaction = false;
|
|
|
|
|
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 ) {
|
|
|
|
|
let defender = game.actors.get( flipData.target.actor._id);
|
|
|
|
|