Opposed tests, ongoing process

This commit is contained in:
2021-02-11 00:07:13 +01:00
parent 42af291a7c
commit de104fb386
12 changed files with 264 additions and 25 deletions

View File

@ -1,4 +1,5 @@
/* -------------------------------------------- */
import { SoSCombat } from "./sos-combat.js";
import { SoSDialogCombatActions } from "./sos-dialog-combat-actions.js";
/* -------------------------------------------- */
@ -129,4 +130,102 @@ export class SoSUtility {
});
}
/* -------------------------------------------- */
static getTarget() {
if (game.user.targets && game.user.targets.size == 1) {
for (let target of game.user.targets) {
return target;
}
}
return undefined;
}
/* -------------------------------------------- */
static increaseSeverity( severity ) {
if ( severity == 'L') return 'M';
if ( severity == 'M') return 'S';
if ( severity == 'S') return 'C';
if ( severity == 'C') return 'F';
}
/* -------------------------------------------- */
static decreaseSeverity( severity ) {
if ( severity == 'C') return 'S';
if ( severity == 'S') return 'M';
if ( severity == 'M') return 'L';
if ( severity == 'L') return 'N';
}
/* -------------------------------------------- */
static getSeverityLevel( severity) {
if ( severity == 'C') return 4;
if ( severity == 'S') return 3;
if ( severity == 'M') return 2;
if ( severity == 'L') return 1;
return 0;
}
/* -------------------------------------------- */
static async applyDamage( flipData ) {
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;
flipData.damageStatus = 'apply_damage';
flipData.targetShock = shock;
flipData.targetDR = dr;
flipData.targetCritical = defenseCritical;
// DR management
if ( flipData.damageValue < dr) {
if (flipData.damageValue < dr / 2) {
flipData.damageStatus = "no_damage";
// TODO : No damage !
} else {
flipData.damageSeverity = this.decreaseSeverity(flipData.damageSeverity );
if ( flipData.damageSeverity == 'N') {
flipData.damageStatus = "no_damage";
}
}
}
// Shock management
flipData.woundsList = [];
if ( flipData.damageValue >= shock) {
let incSeverity = Math.floor(flipData.damageValue / shock);
for (let i=0; i<incSeverity; i++) {
if ( flipData.damageSeverity == 'C') {
flipData.woundsList.push( flipData.damageSeverity );
flipData.damageSeverity = 'L';
} else {
flipData.damageSeverity = this.increaseSeverity( flipData.damageSeverity );
}
}
}
flipData.woundsList.push( flipData.damageSeverity );
flipData.nbWounds = flipData.woundsList.length;
// Critical management
flipData.isCritical = ( flipData.cardTotal >= defenseCritical);
let html = await renderTemplate('systems/foundryvtt-shadows-over-sol/templates/chat-damage-target.html', flipData );
ChatMessage.create( { content: html });
// Is target able to dodge ??
let defender = game.actors.get( flipData.target.actor._id);
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.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.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;
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") ] } );
}
}
}
}