Enhance and bugfixes for combat

This commit is contained in:
sladecraven 2022-01-01 23:32:48 +01:00
parent 5915b4a0ac
commit 721cb08059
6 changed files with 425 additions and 330 deletions

View File

@ -217,7 +217,7 @@ export class BoLActor extends Actor {
for (let protect of protectWorn) { for (let protect of protectWorn) {
if ( protect.data.subtype == 'helm') { if ( protect.data.subtype == 'helm') {
formula += "+1" formula += "+1"
} else { } else if ( protect.data.subtype == 'armor') {
formula += "+" + protect.data.properties.soak.formula; formula += "+" + protect.data.properties.soak.formula;
} }
} }

View File

@ -1,356 +1,365 @@
import { BoLUtility } from "../system/bol-utility.js"; import { BoLUtility } from "../system/bol-utility.js";
export class BoLRoll { export class BoLRoll {
static options() { static options() {
return { classes: ["bol", "dialog"] }; return { classes: ["bol", "dialog"] };
}
static attributeCheck(actor, actorData, dataset, event) {
// const elt = $(event.currentTarget)[0];
// let key = elt.attributes["data-rolling"].value;
const key = dataset.key;
const adv = dataset.adv;
let attribute = eval(`actor.data.data.attributes.${key}`);
let label = (attribute.label) ? game.i18n.localize(attribute.label) : null;
let description = actor.name + " - " + game.i18n.localize('BOL.ui.attributeCheck') + " - " + game.i18n.localize(attribute.label) ;
return this.attributeRollDialog(actor, actorData, attribute, label, description, adv, 0);
}
static aptitudeCheck(actor, actorData, dataset, event) {
// const elt = $(event.currentTarget)[0];
// let key = elt.attributes["data-rolling"].value;
const key = dataset.key;
const adv = dataset.adv;
let aptitude = eval(`actor.data.data.aptitudes.${key}`);
let label = (aptitude.label) ? game.i18n.localize(aptitude.label) : null;
let description = actor.name + " - " + game.i18n.localize('BOL.ui.aptitudeCheck') + " - " + game.i18n.localize(aptitude.label) ;
return this.aptitudeRollDialog(actor, actorData, aptitude, label, description, adv, 0);
}
static weaponCheck(actor, actorData, dataset, event) {
// const elt = $(event.currentTarget)[0];
// let key = elt.attributes["data-rolling"].value;
let target = BoLUtility.getTarget()
const li = $(event.currentTarget).parents(".item");
const weapon = actor.items.get(li.data("item-id"));
if (!weapon) {
ui.notifications.warn("Unable to find weapon !");
return;
}
let weaponData = weapon.data.data;
let attackDef= {
id:randomID(16),
attacker: actor,
attackerData: actorData,
weapon :weapon,
mod: 0,
target : target,
defender: (target) ? game.actors.get(target.data.actorId) : undefined,
adv :dataset.adv || 0,
attribute : eval(`actor.data.data.attributes.${weaponData.properties.attackAttribute}`),
aptitude : eval(`actor.data.data.aptitudes.${weaponData.properties.attackAptitude}`),
label : (weapon.name) ? weapon.name : game.i18n.localize('BOL.ui.noWeaponName'),
description : actor.name + " - " + game.i18n.localize('BOL.ui.weaponAttack'),
}
console.log("WEAPON!", attackDef, weaponData);
return this.weaponRollDialog(attackDef);
} }
/* -------------------------------------------- */ static attributeCheck(actor, actorData, dataset, event) {
/* ROLL DIALOGS */ // const elt = $(event.currentTarget)[0];
/* -------------------------------------------- */ // let key = elt.attributes["data-rolling"].value;
static async attributeRollDialog(actor, actorData, attribute, label, description, adv, mod, onEnter = "submit") { const key = dataset.key;
const rollOptionTpl = 'systems/bol/templates/dialogs/attribute-roll-dialog.hbs'; const adv = dataset.adv;
const dialogData = { let attribute = eval(`actor.data.data.attributes.${key}`);
adv:adv, let label = (attribute.label) ? game.i18n.localize(attribute.label) : null;
mod: mod, let description = actor.name + " - " + game.i18n.localize('BOL.ui.attributeCheck') + " - " + game.i18n.localize(attribute.label);
attr:attribute, return this.attributeRollDialog(actor, actorData, attribute, label, description, adv, 0);
careers:actorData.features.careers, }
boons:actorData.features.boons,
flaws:actorData.features.flaws
};
const rollOptionContent = await renderTemplate(rollOptionTpl, dialogData); static aptitudeCheck(actor, actorData, dataset, event) {
let d = new Dialog({ // const elt = $(event.currentTarget)[0];
title: label, // let key = elt.attributes["data-rolling"].value;
content: rollOptionContent, const key = dataset.key;
buttons: { const adv = dataset.adv;
cancel: { let aptitude = eval(`actor.data.data.aptitudes.${key}`);
icon: '<i class="fas fa-times"></i>', let label = (aptitude.label) ? game.i18n.localize(aptitude.label) : null;
label: game.i18n.localize("BOL.ui.cancel"), let description = actor.name + " - " + game.i18n.localize('BOL.ui.aptitudeCheck') + " - " + game.i18n.localize(aptitude.label);
callback: () => { return this.aptitudeRollDialog(actor, actorData, aptitude, label, description, adv, 0);
} }
},
submit: { static weaponCheck(actor, actorData, dataset, event) {
icon: '<i class="fas fa-check"></i>', // const elt = $(event.currentTarget)[0];
label: game.i18n.localize("BOL.ui.submit"), // let key = elt.attributes["data-rolling"].value;
callback: (html) => { let target = BoLUtility.getTarget()
const attr = html.find('#attr').val(); const li = $(event.currentTarget).parents(".item");
const adv = html.find('#adv').val(); const weapon = actor.items.get(li.data("item-id"));
const mod = html.find('#mod').val(); if (!weapon) {
let careers = html.find('#career').val(); ui.notifications.warn("Unable to find weapon !");
const career = (careers.length == 0) ? 0 : Math.max(...careers.map(i => parseInt(i))); return;
const isMalus = adv < 0;
const dicePool = (isMalus) ? 2 - parseInt(adv) : 2 + parseInt(adv);
const attrValue = eval(`actor.data.data.attributes.${attr}.value`);
const modifiers = parseInt(attrValue) + parseInt(mod) + parseInt(career);
const formula = (isMalus) ? dicePool + "d6kl2 + " + modifiers : dicePool + "d6kh2 + " + modifiers;
let r = new BoLDefaultRoll(label, formula, description);
r.roll(actor);
}
}
},
default: onEnter,
close: () => {}
}, this.options());
return d.render(true);
} }
let weaponData = weapon.data.data;
let attackDef = {
id: randomID(16),
attacker: actor,
attackerData: actorData,
weapon: weapon,
mod: 0,
target: target,
defender: (target) ? game.actors.get(target.data.actorId) : undefined,
adv: dataset.adv || 0,
attribute: eval(`actor.data.data.attributes.${weaponData.properties.attackAttribute}`),
aptitude: eval(`actor.data.data.aptitudes.${weaponData.properties.attackAptitude}`),
label: (weapon.name) ? weapon.name : game.i18n.localize('BOL.ui.noWeaponName'),
description: actor.name + " - " + game.i18n.localize('BOL.ui.weaponAttack'),
}
console.log("WEAPON!", attackDef, weaponData);
return this.weaponRollDialog(attackDef);
}
static async weaponRollDialog( attackDef) { /* -------------------------------------------- */
const rollOptionTpl = 'systems/bol/templates/dialogs/weapon-roll-dialog.hbs'; /* ROLL DIALOGS */
const dialogData = { /* -------------------------------------------- */
attr:attackDef.attribute, static async attributeRollDialog(actor, actorData, attribute, label, description, adv, mod, onEnter = "submit") {
adv:attackDef.adv, const rollOptionTpl = 'systems/bol/templates/dialogs/attribute-roll-dialog.hbs';
mod: attackDef.mod, const dialogData = {
apt:attackDef.aptitude, adv: adv,
weapon: attackDef.weapon, mod: mod,
attackId: attackDef.id, attr: attribute,
careers: attackDef.attackerData.features.careers, careers: actorData.features.careers,
boons: attackDef.attackerData.features.boons, boons: actorData.features.boons,
flaws: attackDef.attackerData.features.flaws, flaws: actorData.features.flaws
}; };
if ( attackDef.defender) {
dialogData.defence = attackDef.defender.defenseValue, const rollOptionContent = await renderTemplate(rollOptionTpl, dialogData);
dialogData.shieldBlock = 'none' let d = new Dialog({
let shields = attackDef.defender.shields title: label,
for( let shield of shields) { content: rollOptionContent,
dialogData.shieldBlock = (shield.data.properties.blocking.blockingAll) ? 'blockall' : 'blockone'; buttons: {
dialogData.shieldAttackMalus = (shield.data.properties.blocking.malus)? shield.data.properties.blocking.malus : 1; cancel: {
dialogData.applyShieldMalus = false icon: '<i class="fas fa-times"></i>',
label: game.i18n.localize("BOL.ui.cancel"),
callback: () => {
}
},
submit: {
icon: '<i class="fas fa-check"></i>',
label: game.i18n.localize("BOL.ui.submit"),
callback: (html) => {
const attr = html.find('#attr').val();
const adv = html.find('#adv').val();
const mod = html.find('#mod').val();
let careers = html.find('#career').val();
const career = (careers.length == 0) ? 0 : Math.max(...careers.map(i => parseInt(i)));
const isMalus = adv < 0;
const dicePool = (isMalus) ? 2 - parseInt(adv) : 2 + parseInt(adv);
const attrValue = eval(`actor.data.data.attributes.${attr}.value`);
const modifiers = parseInt(attrValue) + parseInt(mod) + parseInt(career);
const formula = (isMalus) ? dicePool + "d6kl2 + " + modifiers : dicePool + "d6kh2 + " + modifiers;
let r = new BoLDefaultRoll(label, formula, description);
r.roll(actor);
}
} }
},
default: onEnter,
close: () => { }
}, this.options());
return d.render(true);
}
static async weaponRollDialog(attackDef) {
const rollOptionTpl = 'systems/bol/templates/dialogs/weapon-roll-dialog.hbs';
const dialogData = {
attr: attackDef.attribute,
adv: attackDef.adv,
mod: attackDef.mod,
apt: attackDef.aptitude,
weapon: attackDef.weapon,
attackId: attackDef.id,
careers: attackDef.attackerData.features.careers,
boons: attackDef.attackerData.features.boons,
flaws: attackDef.attackerData.features.flaws,
};
if (attackDef.defender) {
dialogData.defence = attackDef.defender.defenseValue,
dialogData.shieldBlock = 'none'
let shields = attackDef.defender.shields
for (let shield of shields) {
dialogData.shieldBlock = (shield.data.properties.blocking.blockingAll) ? 'blockall' : 'blockone';
dialogData.shieldAttackMalus = (shield.data.properties.blocking.malus) ? shield.data.properties.blocking.malus : 1;
dialogData.applyShieldMalus = false
} }
const rollOptionContent = await renderTemplate(rollOptionTpl, dialogData);
let d = new Dialog({
title: attackDef.label,
content: rollOptionContent,
buttons: {
cancel: {
icon: '<i class="fas fa-times"></i>',
label: game.i18n.localize("BOL.ui.cancel"),
callback: () => {
}
},
submit: {
icon: '<i class="fas fa-check"></i>',
label: game.i18n.localize("BOL.ui.submit"),
callback: (html) => {
const attr = html.find('#attr').val();
const apt = html.find('#apt').val();
const adv = html.find('#adv').val();
const mod = html.find('#mod').val() || 0;
let shieldMalus = 0;
const applyShieldMalus = html.find('#applyShieldMalus').val() || false;
if (applyShieldMalus || dialogData.shieldBlock =='blockall') {
shieldMalus = dialogData.shieldAttackMalus;
}
let careers = html.find('#career').val();
const career = (careers.length == 0) ? 0 : Math.max(...careers.map(i => parseInt(i)));
const isMalus = adv < 0;
const dicePool = (isMalus) ? 2 - parseInt(adv) : 2 + parseInt(adv);
const attrValue = eval(`attackDef.attacker.data.data.attributes.${attr}.value`);
const aptValue = eval(`attackDef.attacker.data.data.aptitudes.${apt}.value`);
const modifiers = parseInt(attrValue) + parseInt(aptValue) + parseInt(mod) + parseInt(career) - dialogData.defence - shieldMalus;
const formula = (isMalus) ? dicePool + "d6kl2 + " + modifiers : dicePool + "d6kh2 + " + modifiers;
attackDef.formula = formula;
let r = new BoLAttackRoll(attackDef);
r.roll();
}
}
},
default: 'submit',
close: () => {}
}, this.options());
return d.render(true);
} }
const rollOptionContent = await renderTemplate(rollOptionTpl, dialogData);
let d = new Dialog({
title: attackDef.label,
content: rollOptionContent,
buttons: {
cancel: {
icon: '<i class="fas fa-times"></i>',
label: game.i18n.localize("BOL.ui.cancel"),
callback: () => {
}
},
submit: {
icon: '<i class="fas fa-check"></i>',
label: game.i18n.localize("BOL.ui.submit"),
callback: (html) => {
const attr = html.find('#attr').val();
const apt = html.find('#apt').val();
const adv = html.find('#adv').val();
const mod = html.find('#mod').val() || 0;
static async aptitudeRollDialog(actor, actorData, aptitude, label, description, adv, mod, onEnter = "submit") { let shieldMalus = 0;
const rollOptionTpl = 'systems/bol/templates/dialogs/aptitude-roll-dialog.hbs'; const applyShieldMalus = html.find('#applyShieldMalus').val() || false;
const dialogData = { if (applyShieldMalus || dialogData.shieldBlock == 'blockall') {
adv:adv, shieldMalus = dialogData.shieldAttackMalus;
mod: mod, }
apt:aptitude,
careers:actorData.features.careers, let careers = html.find('#career').val();
boons:actorData.features.boons, const career = (careers.length == 0) ? 0 : Math.max(...careers.map(i => parseInt(i)));
flaws:actorData.features.flaws const isMalus = adv < 0;
}; const dicePool = (isMalus) ? 2 - parseInt(adv) : 2 + parseInt(adv);
const rollOptionContent = await renderTemplate(rollOptionTpl, dialogData); const attrValue = eval(`attackDef.attacker.data.data.attributes.${attr}.value`);
let d = new Dialog({ const aptValue = eval(`attackDef.attacker.data.data.aptitudes.${apt}.value`);
title: label, const modifiers = parseInt(attrValue) + parseInt(aptValue) + parseInt(mod) + parseInt(career) - dialogData.defence - shieldMalus;
content: rollOptionContent, const formula = (isMalus) ? dicePool + "d6kl2 + " + modifiers : dicePool + "d6kh2 + " + modifiers;
buttons: { attackDef.formula = formula;
cancel: { let r = new BoLAttackRoll(attackDef);
icon: '<i class="fas fa-times"></i>', r.roll();
label: game.i18n.localize("BOL.ui.cancel"), }
callback: () => { }
} },
}, default: 'submit',
submit: { close: () => { }
icon: '<i class="fas fa-check"></i>', }, this.options());
label: game.i18n.localize("BOL.ui.submit"), return d.render(true);
callback: (html) => { }
const apt = html.find('#apt').val();
const adv = html.find('#adv').val(); static async aptitudeRollDialog(actor, actorData, aptitude, label, description, adv, mod, onEnter = "submit") {
const mod = html.find('#mod').val(); const rollOptionTpl = 'systems/bol/templates/dialogs/aptitude-roll-dialog.hbs';
let careers = html.find('#career').val(); const dialogData = {
const career = (careers.length == 0) ? 0 : Math.max(...careers.map(i => parseInt(i))); adv: adv,
const isMalus = adv < 0; mod: mod,
const dicePool = (isMalus) ? 2 - parseInt(adv) : 2 + parseInt(adv); apt: aptitude,
const aptValue = eval(`actor.data.data.aptitudes.${apt}.value`); careers: actorData.features.careers,
const modifiers = parseInt(aptValue) + parseInt(mod) + parseInt(career); boons: actorData.features.boons,
const formula = (isMalus) ? dicePool + "d6kl2 + " + modifiers : dicePool + "d6kh2 + " + modifiers; flaws: actorData.features.flaws
let r = new BoLDefaultRoll(label, formula, description); };
r.roll(actor); const rollOptionContent = await renderTemplate(rollOptionTpl, dialogData);
} let d = new Dialog({
} title: label,
}, content: rollOptionContent,
default: onEnter, buttons: {
close: () => {} cancel: {
}, this.options()); icon: '<i class="fas fa-times"></i>',
return d.render(true); label: game.i18n.localize("BOL.ui.cancel"),
} callback: () => {
}
},
submit: {
icon: '<i class="fas fa-check"></i>',
label: game.i18n.localize("BOL.ui.submit"),
callback: (html) => {
const apt = html.find('#apt').val();
const adv = html.find('#adv').val();
const mod = html.find('#mod').val();
let careers = html.find('#career').val();
const career = (careers.length == 0) ? 0 : Math.max(...careers.map(i => parseInt(i)));
const isMalus = adv < 0;
const dicePool = (isMalus) ? 2 - parseInt(adv) : 2 + parseInt(adv);
const aptValue = eval(`actor.data.data.aptitudes.${apt}.value`);
const modifiers = parseInt(aptValue) + parseInt(mod) + parseInt(career);
const formula = (isMalus) ? dicePool + "d6kl2 + " + modifiers : dicePool + "d6kh2 + " + modifiers;
let r = new BoLDefaultRoll(label, formula, description);
r.roll(actor);
}
}
},
default: onEnter,
close: () => { }
}, this.options());
return d.render(true);
}
} }
export class BoLDefaultRoll { export class BoLDefaultRoll {
constructor(label, formula, description, isWeapon=false){ constructor(label, formula, description, isWeapon = false) {
this._label = label; this._label = label;
this._formula = formula; this._formula = formula;
this._isSuccess = false; this._isSuccess = false;
this._isCritical = false; this._isCritical = false;
this._isFumble = false; this._isFumble = false;
this._isWeapon = isWeapon; this._isWeapon = isWeapon;
this._description = description; this._description = description;
} }
async roll(actor){ async roll(actor) {
const r = new Roll(this._formula); const r = new Roll(this._formula);
await r.roll({"async": true}); await r.roll({ "async": true });
const activeDice = r.terms[0].results.filter(r => r.active); const activeDice = r.terms[0].results.filter(r => r.active);
const diceTotal = activeDice.map(r => r.result).reduce((a, b) => a + b); const diceTotal = activeDice.map(r => r.result).reduce((a, b) => a + b);
this._isSuccess = (r.total >= 9); this._isSuccess = (r.total >= 9);
this._isCritical = (diceTotal === 12); this._isCritical = (diceTotal === 12);
this._isFumble = (diceTotal === 2); this._isFumble = (diceTotal === 2);
this._buildChatMessage(actor).then(msgFlavor => { this._buildChatMessage(actor).then(msgFlavor => {
r.toMessage({ r.toMessage({
user: game.user.id, user: game.user.id,
flavor: msgFlavor, flavor: msgFlavor,
speaker: ChatMessage.getSpeaker({actor: actor}), speaker: ChatMessage.getSpeaker({ actor: actor }),
flags : {msgType : "default"} flags: { msgType: "default" }
}); });
}); });
if (this._isSuccess && this._isWeapon) { if (this._isSuccess && this._isWeapon) {
}
} }
}
_buildChatMessage(actor) { _buildChatMessage(actor) {
const rollMessageTpl = 'systems/bol/templates/chat/rolls/default-roll-card.hbs'; const rollMessageTpl = 'systems/bol/templates/chat/rolls/default-roll-card.hbs';
const tplData = { const tplData = {
actor : actor, actor: actor,
label : this._label, label: this._label,
isSuccess : this._isSuccess, isSuccess: this._isSuccess,
isFailure : !this._isSuccess, isFailure: !this._isSuccess,
isCritical : this._isCritical, isCritical: this._isCritical,
isFumble : this._isFumble, isFumble: this._isFumble,
hasDescription : this._description && this._description.length > 0, hasDescription: this._description && this._description.length > 0,
description : this._description description: this._description
}; };
return renderTemplate(rollMessageTpl, tplData); return renderTemplate(rollMessageTpl, tplData);
} }
} }
export class BoLAttackRoll { export class BoLAttackRoll {
constructor(attackDef){ constructor(attackDef) {
this.attackDef = attackDef; this.attackDef = attackDef;
this._isSuccess = false; this._isSuccess = false;
this._isCritical = false; this._isCritical = false;
this._isFumble = false; this._isFumble = false;
} }
async roll(){ async roll() {
const r = new Roll(this.attackDef.formula); const r = new Roll(this.attackDef.formula);
await r.roll({"async": false}); await r.roll({ "async": false });
const activeDice = r.terms[0].results.filter(r => r.active); //await BoLUtility.showDiceSoNice(r);
const diceTotal = activeDice.map(r => r.result).reduce((a, b) => a + b); const activeDice = r.terms[0].results.filter(r => r.active);
this._isSuccess = (r.total >= 9); const diceTotal = activeDice.map(r => r.result).reduce((a, b) => a + b);
this._isCritical = (diceTotal === 12); this._isSuccess = (r.total >= 9);
this._isFumble = (diceTotal === 2); this._isCritical = (diceTotal === 12);
this._buildChatMessage(this.attackDef.attacker).then(msgFlavor => { this._isFumble = (diceTotal === 2);
r.toMessage({ this._buildChatMessage(this.attackDef.attacker).then(msgFlavor => {
user: game.user.id, r.toMessage({
flavor: msgFlavor, user: game.user.id,
speaker: ChatMessage.getSpeaker({actor: this.attackDef.attacker}), flavor: msgFlavor,
flags : {msgType : "default"} speaker: ChatMessage.getSpeaker({ actor: this.attackDef.attacker }),
}); flags: { msgType: "default" }
}); });
});
if (this._isSuccess ) { if (this._isSuccess) {
let attrDamage = this.attackDef.weapon.data.data.properties.damageAttribute; let attrDamage = this.attackDef.weapon.data.data.properties.damageAttribute;
let weaponFormula = BoLUtility.getDamageFormula(this.attackDef.weapon.data.data.properties.damage) let weaponFormula = BoLUtility.getDamageFormula(this.attackDef.weapon.data.data.properties.damage)
let damageFormula = weaponFormula + "+" + this.attackDef.attacker.data.data.attributes[attrDamage].value; let damageFormula = weaponFormula + "+" + this.attackDef.attacker.data.data.attributes[attrDamage].value;
this.damageRoll = new Roll(damageFormula); this.damageRoll = new Roll(damageFormula);
await this.damageRoll.roll({"async": false}); await this.damageRoll.roll({ "async": false });
// Update attackDef object //await BoLUtility.showDiceSoNice(this.damageRoll);
this.attackDef.damageFormula = damageFormula; // Update attackDef object
this.attackDef.damageRoll = this.damageRoll; this.attackDef.damageFormula = damageFormula;
this.attackDef.damageRoll = this.damageRoll;
this._buildDamageChatMessage(this.attackDef.attacker, this.attackDef.weapon, this.damageRoll.total).then(msgFlavor => { this._buildDamageChatMessage(this.attackDef.attacker, this.attackDef.weapon, this.damageRoll.total).then(msgFlavor => {
this.damageRoll.toMessage({ this.damageRoll.toMessage({
user: game.user.id, user: game.user.id,
flavor: msgFlavor, flavor: msgFlavor,
speaker: ChatMessage.getSpeaker({actor: this.attackDef.attacker}), speaker: ChatMessage.getSpeaker({ actor: this.attackDef.attacker }),
flags : {msgType : "default"} flags: { msgType: "default" }
}).then( result => { });
if (this.attackDef.target) {
// Broadcast to GM or process it directly in case of GM defense
if ( !game.user.isGM) {
game.socket.emit("system.bol", { msg: "msg_attack_success", data: this.attackDef });
} else {
BoLUtility.processAttackSuccess( this.attackDef);
}
}
});
}); });
} if (this._isCritical) {
ChatMessage.create({
alias: this.attackDef.attacker.name,
whisper: BoLUtility.getWhisperRecipientsAndGMs(this.attackDef.attacker.name),
content: await renderTemplate('systems/bol/templates/chat/rolls/attack-heroic-card.hbs', {
attackId: attackDef.id,
attacker: attackDef.attacker,
defender: attackDef.defender,
defenderWeapons: defenderWeapons,
damageTotal: attackDef.damageRoll.total
})
})
} else {
BoLUtility.sendAttackSuccess( this.attackDef);
}
} }
}
_buildDamageChatMessage(actor, weapon, total) { _buildDamageChatMessage(actor, weapon, total) {
const rollMessageTpl = 'systems/bol/templates/chat/rolls/damage-roll-card.hbs'; const rollMessageTpl = 'systems/bol/templates/chat/rolls/damage-roll-card.hbs';
const tplData = { const tplData = {
actor : actor, actor: actor,
label : this._label, label: this._label,
weapon: weapon, weapon: weapon,
damage: total, damage: total,
}; isCritical: this._isCritical,
return renderTemplate(rollMessageTpl, tplData); };
} return renderTemplate(rollMessageTpl, tplData);
}
_buildChatMessage(actor) { _buildChatMessage(actor) {
const rollMessageTpl = 'systems/bol/templates/chat/rolls/default-roll-card.hbs'; const rollMessageTpl = 'systems/bol/templates/chat/rolls/default-roll-card.hbs';
const tplData = { const tplData = {
actor : actor, actor: actor,
label : this._label, label: this._label,
isSuccess : this._isSuccess, isSuccess: this._isSuccess,
isFailure : !this._isSuccess, isFailure: !this._isSuccess,
isCritical : this._isCritical, isCritical: this._isCritical,
isFumble : this._isFumble, isFumble: this._isFumble,
hasDescription : this._description && this._description.length > 0, hasDescription: this._description && this._description.length > 0,
description : this._description description: this._description
}; };
return renderTemplate(rollMessageTpl, tplData); return renderTemplate(rollMessageTpl, tplData);
} }
} }
// export class BoLWeaponRoll { // export class BoLWeaponRoll {

View File

@ -95,9 +95,31 @@ export class BoLUtility {
game.socket.emit("system.fvtt-fragged-kingdom", { msg: "msg_gm_chat_message", data: chatGM }); game.socket.emit("system.fvtt-fragged-kingdom", { msg: "msg_gm_chat_message", data: chatGM });
} }
/* -------------------------------------------- */
static sendAttackSuccess(attackDef) {
if (attackDef.target) {
// Broadcast to GM or process it directly in case of GM defense
if (!game.user.isGM) {
game.socket.emit("system.bol", { msg: "msg_attack_success", data: attackDef });
} else {
BoLUtility.processAttackSuccess(attackDef);
}
}
}
/* -------------------------------------------- */ /* -------------------------------------------- */
static async chatListeners(html) { static async chatListeners(html) {
// Damage handling // Damage handling
html.on("click", '.damage-increase', event => {
let attackId = event.currentTarget.attributes['data-attack-id'].value;
let damageMode = event.currentTarget.attributes['data-damage-mode'].value;
if ( game.user.isGM) {
BoLUtility.processDamageIncrease(event, attackId, damageMode)
} else {
game.socket.emit("system.bol", { msg: "msg_damage_increase", data: {event: event, attackId: attackId, damageMode: damageMode} });
}
});
html.on("click", '.damage-handling', event => { html.on("click", '.damage-handling', event => {
let attackId = event.currentTarget.attributes['data-attack-id'].value; let attackId = event.currentTarget.attributes['data-attack-id'].value;
let defenseMode = event.currentTarget.attributes['data-defense-mode'].value; let defenseMode = event.currentTarget.attributes['data-defense-mode'].value;
@ -111,6 +133,31 @@ export class BoLUtility {
}); });
} }
/* -------------------------------------------- */
static async processDamageIncrease(event, attackId, damageMode ) {
if ( !game.user.isGM) {
return;
}
BoLUtility.removeChatMessageId(BoLUtility.findChatMessageId(event.currentTarget));
// Only GM process this
let attackDef = this.attackStore[attackId];
if (attackDef) {
attackDef.damageMode = damageMode;
if (defenseMode == 'damage-plus-6') {
attackDef.damageRoll.total += 6;
}
if (defenseMode == 'damage-plus-12') {
attackDef.damageRoll.total += 12;
attackDef.defender.subHeroPoints(1);
}
if (defenseMode == 'damage-normal') {
// Do nothing !
}
BoLUtility.sendAttackSuccess( this.attackDef);
}
}
/* -------------------------------------------- */ /* -------------------------------------------- */
static async processDamageHandling(event, attackId, defenseMode, weaponId=-1) { static async processDamageHandling(event, attackId, defenseMode, weaponId=-1) {
if ( !game.user.isGM) { if ( !game.user.isGM) {
@ -120,14 +167,14 @@ export class BoLUtility {
// Only GM process this // Only GM process this
let attackDef = this.attackStore[attackId]; let attackDef = this.attackStore[attackId];
console.log("DEFENSE2", attackId, defenseMode, weaponId, attackDef);
if (attackDef) { if (attackDef) {
attackDef.defenseMode = defenseMode; attackDef.defenseMode = defenseMode;
if (defenseMode == 'damage-with-armor') { if (defenseMode == 'damage-with-armor') {
let armorFormula = attackDef.defender.getArmorFormula(); let armorFormula = attackDef.defender.getArmorFormula();
attackDef.rollArmor = new Roll(armorFormula) attackDef.rollArmor = new Roll(armorFormula)
attackDef.rollArmor.roll( {async: false} ); attackDef.rollArmor.roll( {async: false} );
attackDef.finalDamage = attackDef.damageRoll.total - attackDef.rollArmor.total; attackDef.armorProtect = (attackDef.rollArmor.total<0) ? 0 : attackDef.rollArmor.total;
attackDef.finalDamage = attackDef.damageRoll.total - attackDef.armorProtect;
attackDef.finalDamage = (attackDef.finalDamage<0) ? 0 : attackDef.finalDamage; attackDef.finalDamage = (attackDef.finalDamage<0) ? 0 : attackDef.finalDamage;
attackDef.defender.sufferDamage(attackDef.finalDamage); attackDef.defender.sufferDamage(attackDef.finalDamage);
} }
@ -136,9 +183,13 @@ export class BoLUtility {
attackDef.defender.sufferDamage(attackDef.finalDamage); attackDef.defender.sufferDamage(attackDef.finalDamage);
} }
if (defenseMode == 'hero-reduce-damage') { if (defenseMode == 'hero-reduce-damage') {
let armorFormula = attackDef.defender.getArmorFormula();
attackDef.rollArmor = new Roll(armorFormula)
attackDef.rollArmor.roll( {async: false} );
attackDef.armorProtect = (attackDef.rollArmor.total<0) ? 0 : attackDef.rollArmor.total;
attackDef.rollHero = new Roll("1d6"); attackDef.rollHero = new Roll("1d6");
attackDef.rollHero.roll( {async: false} ); attackDef.rollHero.roll( {async: false} );
attackDef.finalDamage = attackDef.damageRoll.total - attackDef.rollHero.total; attackDef.finalDamage = attackDef.damageRoll.total - attackDef.rollHero.total - attackDef.armorProtect;
attackDef.finalDamage = (attackDef.finalDamage<0) ? 0 : attackDef.finalDamage; attackDef.finalDamage = (attackDef.finalDamage<0) ? 0 : attackDef.finalDamage;
attackDef.defender.sufferDamage(attackDef.finalDamage); attackDef.defender.sufferDamage(attackDef.finalDamage);
attackDef.defender.subHeroPoints(1); attackDef.defender.subHeroPoints(1);
@ -157,6 +208,7 @@ export class BoLUtility {
rollArmor: attackDef.rollArmor, rollArmor: attackDef.rollArmor,
rollHero: attackDef.rollHero, rollHero: attackDef.rollHero,
weaponHero : attackDef.weaponHero, weaponHero : attackDef.weaponHero,
armorProtect: attackDef.armorProtect,
defender: attackDef.defender, defender: attackDef.defender,
defenseMode: attackDef.defenseMode, defenseMode: attackDef.defenseMode,
finalDamage: attackDef.finalDamage finalDamage: attackDef.finalDamage
@ -313,6 +365,9 @@ export class BoLUtility {
if (sockmsg.name == "msg_damage_handling") { if (sockmsg.name == "msg_damage_handling") {
BoLUtility.processDamageHandling(sockmsg.data.event, sockmsg.data.attackId, sockmsg.data.defenseMode) BoLUtility.processDamageHandling(sockmsg.data.event, sockmsg.data.attackId, sockmsg.data.defenseMode)
} }
if (sockmsg.name == "msg_damage_increase") {
BoLUtility.processDamageIncrease(sockmsg.data.event, sockmsg.data.attackId, sockmsg.data.damageMode)
}
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
@ -338,6 +393,30 @@ export class BoLUtility {
let formula = nbDice + "d" + res[2] + postForm + ((res[modIndex]) ? res[modIndex] : ""); let formula = nbDice + "d" + res[2] + postForm + ((res[modIndex]) ? res[modIndex] : "");
return formula; return formula;
} }
/* -------------------------------------------- */
static async showDiceSoNice(roll, rollMode) {
if (game.modules.get("dice-so-nice")?.active) {
if (game.dice3d) {
let whisper = null;
let blind = false;
rollMode = rollMode ?? game.settings.get("core", "rollMode");
switch (rollMode) {
case "blindroll": //GM only
blind = true;
case "gmroll": //GM + rolling player
whisper = BoLUtility.getUsers(user => user.isGM);
break;
case "roll": //everybody
whisper = BoLUtility.getUsers(user => user.active);
break;
case "selfroll":
whisper = [game.user.id];
break;
}
await game.dice3d.showForRoll(roll, game.user, true, whisper, blind);
}
}
}
/* -------------------------------------------- */ /* -------------------------------------------- */
static async confirmDelete(actorSheet, li) { static async confirmDelete(actorSheet, li) {

View File

@ -7,7 +7,7 @@
"url": "https://github.com/ZigmundKreud/bol", "url": "https://github.com/ZigmundKreud/bol",
"license": "LICENSE.txt", "license": "LICENSE.txt",
"flags": {}, "flags": {},
"version": "0.8.9.0", "version": "0.8.9.1",
"minimumCoreVersion": "0.8.6", "minimumCoreVersion": "0.8.6",
"compatibleCoreVersion": "9", "compatibleCoreVersion": "9",
"scripts": [], "scripts": [],

View File

@ -0,0 +1,6 @@
<img class="chat-icon" src="{{attacker.img}}" alt="{{attacker.name}}"/>
Jet Héroïque !
<button class="damage-increase" data-damage-mode="damage-plus-6" data-attack-id="{{attackId}}">Augmenter les dommages de 6</button>
<button class="damage-increase" data-damage-mode="damage-plus-12" data-attack-id="{{attackId}}">Augmenter les dommages de 12 (1 point d'Heroisme)</button>
<button class="damage-increase" data-damage-mode="damage-normal" data-attack-id="{{attackId}}">Laisser les dommages inchangés</button>

View File

@ -3,13 +3,14 @@
<ul> <ul>
<li> <li>
{{#if (eq defenseMode "damage-with-armor")}} {{#if (eq defenseMode "damage-with-armor")}}
Protection de l'armure : {{rollArmor.total}}. Protection de l'armure : {{armorProtect}}.
{{/if}} {{/if}}
{{#if (eq defenseMode "damage-without-armor")}} {{#if (eq defenseMode "damage-without-armor")}}
Aucune protection d'armure ! Aucune protection d'armure !
{{/if}} {{/if}}
{{#if (eq defenseMode "hero-reduce-damage")}} {{#if (eq defenseMode "hero-reduce-damage")}}
Un point d'héroisme dépensé, pour une réduction des dommages de {{rollHero.total}}. Protection de l'armure : {{armorProtect}}.
Un point d'héroisme dépensé, pour une réduction des dommages supplémentaire de {{rollHero.total}}.
{{/if}} {{/if}}
{{#if (eq defenseMode "hero-in-extremis")}} {{#if (eq defenseMode "hero-in-extremis")}}
Aucun dommage encaissé, grâce à la parade in-extremis avec {{weaponHero.name}}. L'arme a été détruite pendant cette parade ! Aucun dommage encaissé, grâce à la parade in-extremis avec {{weaponHero.name}}. L'arme a été détruite pendant cette parade !