forked from public/bol
Rollable damages + protection
This commit is contained in:
parent
69b6fbca6b
commit
831b192691
@ -54,6 +54,7 @@
|
|||||||
"BOL.ui.roll" : "Utiliser",
|
"BOL.ui.roll" : "Utiliser",
|
||||||
"BOL.ui.equipment" : "Équipement",
|
"BOL.ui.equipment" : "Équipement",
|
||||||
"BOL.ui.equipmentProperties" : "Propiétés d'équipement",
|
"BOL.ui.equipmentProperties" : "Propiétés d'équipement",
|
||||||
|
"BOL.ui.weaponAttack" : "Weapon attack",
|
||||||
"BOL.ui.weaponProperties" : "Propiétés offensives",
|
"BOL.ui.weaponProperties" : "Propiétés offensives",
|
||||||
"BOL.ui.protectionProperties" : "Protection",
|
"BOL.ui.protectionProperties" : "Protection",
|
||||||
"BOL.ui.magicalProperties" : "Propriétés magiques",
|
"BOL.ui.magicalProperties" : "Propriétés magiques",
|
||||||
|
@ -54,6 +54,7 @@
|
|||||||
"BOL.ui.roll" : "Utiliser",
|
"BOL.ui.roll" : "Utiliser",
|
||||||
"BOL.ui.equipment" : "Équipement",
|
"BOL.ui.equipment" : "Équipement",
|
||||||
"BOL.ui.equipmentProperties" : "Propriétés d'équipement",
|
"BOL.ui.equipmentProperties" : "Propriétés d'équipement",
|
||||||
|
"BOL.ui.weaponAttack" : "Attaque d'arme",
|
||||||
"BOL.ui.weaponProperties" : "Propriétés offensives",
|
"BOL.ui.weaponProperties" : "Propriétés offensives",
|
||||||
"BOL.ui.protectionProperties" : "Protection",
|
"BOL.ui.protectionProperties" : "Protection",
|
||||||
"BOL.ui.magicalProperties" : "Propriétés magiques",
|
"BOL.ui.magicalProperties" : "Propriétés magiques",
|
||||||
|
@ -182,6 +182,7 @@ export class BoLActorSheet extends ActorSheet {
|
|||||||
const dataset = element.dataset;
|
const dataset = element.dataset;
|
||||||
const actorData = this.getData();
|
const actorData = this.getData();
|
||||||
const rollType = dataset.rollType;
|
const rollType = dataset.rollType;
|
||||||
|
const li = $(event.currentTarget).closest(".item");
|
||||||
switch(rollType) {
|
switch(rollType) {
|
||||||
case "attribute" :
|
case "attribute" :
|
||||||
BoLRoll.attributeCheck(this.actor, actorData, dataset, event);
|
BoLRoll.attributeCheck(this.actor, actorData, dataset, event);
|
||||||
@ -192,6 +193,12 @@ export class BoLActorSheet extends ActorSheet {
|
|||||||
case "weapon":
|
case "weapon":
|
||||||
BoLRoll.weaponCheck(this.actor, actorData, dataset, event);
|
BoLRoll.weaponCheck(this.actor, actorData, dataset, event);
|
||||||
break;
|
break;
|
||||||
|
case "protection":
|
||||||
|
this.actor.rollProtection(li.data("item-id"))
|
||||||
|
break;
|
||||||
|
case "damage":
|
||||||
|
this.actor.rollWeaponDamage(li.data("item-id"))
|
||||||
|
break;
|
||||||
default : break;
|
default : break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
import { BoLDefaultRoll } from "../controllers/bol-rolls.js";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extend the base Actor entity by defining a custom roll data structure which is ideal for the Simple system.
|
* Extend the base Actor entity by defining a custom roll data structure which is ideal for the Simple system.
|
||||||
* @extends {Actor}
|
* @extends {Actor}
|
||||||
@ -270,6 +272,27 @@ export class BoLActor extends Actor {
|
|||||||
return (formula == "") ? 0 :formula;
|
return (formula == "") ? 0 :formula;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* -------------------------------------------- */
|
||||||
|
rollProtection( itemId) {
|
||||||
|
let armor = this.data.items.get( itemId )
|
||||||
|
if ( armor ) {
|
||||||
|
let armorFormula = armor.data.data.properties.soak.formula;
|
||||||
|
let rollArmor = new Roll(armorFormula)
|
||||||
|
rollArmor.roll( {async: false} ).toMessage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* -------------------------------------------- */
|
||||||
|
rollWeaponDamage( itemId) {
|
||||||
|
let weapon = this.data.items.get(itemId )
|
||||||
|
if ( weapon ) {
|
||||||
|
console.log("WE", weapon)
|
||||||
|
let r = new BoLDefaultRoll( { id: randomID(16), isSuccess: true, mode: "weapon", weapon: weapon, actor: this} )
|
||||||
|
r.setSuccess(true)
|
||||||
|
r.processResult()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* -------------------------------------------- */
|
/* -------------------------------------------- */
|
||||||
toggleEquipItem(item) {
|
toggleEquipItem(item) {
|
||||||
const equipable = item.data.data.properties.equipable;
|
const equipable = item.data.data.properties.equipable;
|
||||||
|
@ -1,10 +1,16 @@
|
|||||||
import { BoLUtility } from "../system/bol-utility.js";
|
import { BoLUtility } from "../system/bol-utility.js";
|
||||||
|
|
||||||
|
const __adv2dice = { ["1B"]: 3, ["2B"]: 4, ["2"]: 2, ["1M"]: 3, ["2M"]: 4}
|
||||||
export class BoLRoll {
|
export class BoLRoll {
|
||||||
static options() {
|
static options() {
|
||||||
return { classes: ["bol", "dialog"] };
|
return { classes: ["bol", "dialog"] };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static convertToAdv( adv) {
|
||||||
|
if (adv == 0) return "2"
|
||||||
|
return Math.abs(adv) + (adv < 0)?'M':'B';
|
||||||
|
}
|
||||||
|
|
||||||
static attributeCheck(actor, actorData, dataset, event) {
|
static attributeCheck(actor, actorData, dataset, event) {
|
||||||
// const elt = $(event.currentTarget)[0];
|
// const elt = $(event.currentTarget)[0];
|
||||||
// let key = elt.attributes["data-rolling"].value;
|
// let key = elt.attributes["data-rolling"].value;
|
||||||
@ -13,7 +19,17 @@ export class BoLRoll {
|
|||||||
let attribute = eval(`actor.data.data.attributes.${key}`);
|
let attribute = eval(`actor.data.data.attributes.${key}`);
|
||||||
let label = (attribute.label) ? game.i18n.localize(attribute.label) : null;
|
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);
|
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);
|
return this.displayRollDialog(
|
||||||
|
{
|
||||||
|
mode: "attribute",
|
||||||
|
actor: actor,
|
||||||
|
actorData: actorData,
|
||||||
|
attribute: attribute,
|
||||||
|
label: label,
|
||||||
|
description: description,
|
||||||
|
adv: this.convertToAdv(adv),
|
||||||
|
mod: 0
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
static aptitudeCheck(actor, actorData, dataset, event) {
|
static aptitudeCheck(actor, actorData, dataset, event) {
|
||||||
@ -24,7 +40,17 @@ export class BoLRoll {
|
|||||||
let aptitude = eval(`actor.data.data.aptitudes.${key}`);
|
let aptitude = eval(`actor.data.data.aptitudes.${key}`);
|
||||||
let label = (aptitude.label) ? game.i18n.localize(aptitude.label) : null;
|
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);
|
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);
|
return this.displayRollDialog(
|
||||||
|
{
|
||||||
|
mode: "aptitude",
|
||||||
|
actor: actor,
|
||||||
|
actorData: actorData,
|
||||||
|
aptitude: aptitude,
|
||||||
|
label: label,
|
||||||
|
description: description,
|
||||||
|
adv: this.convertToAdv(adv),
|
||||||
|
mod: 0
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
static weaponCheck(actor, actorData, dataset, event) {
|
static weaponCheck(actor, actorData, dataset, event) {
|
||||||
@ -39,102 +65,57 @@ export class BoLRoll {
|
|||||||
}
|
}
|
||||||
let weaponData = weapon.data.data;
|
let weaponData = weapon.data.data;
|
||||||
let attackDef = {
|
let attackDef = {
|
||||||
id: randomID(16),
|
mode: "weapon",
|
||||||
attacker: actor,
|
actor: actor,
|
||||||
attackerData: actorData,
|
actorData: actorData,
|
||||||
weapon: weapon,
|
weapon: weapon,
|
||||||
mod: 0,
|
|
||||||
target: target,
|
target: target,
|
||||||
defender: (target) ? game.actors.get(target.data.actorId) : undefined,
|
defender: (target) ? game.actors.get(target.data.actorId) : undefined,
|
||||||
adv: dataset.adv || 0,
|
|
||||||
attribute: eval(`actor.data.data.attributes.${weaponData.properties.attackAttribute}`),
|
attribute: eval(`actor.data.data.attributes.${weaponData.properties.attackAttribute}`),
|
||||||
aptitude: eval(`actor.data.data.aptitudes.${weaponData.properties.attackAptitude}`),
|
aptitude: eval(`actor.data.data.aptitudes.${weaponData.properties.attackAptitude}`),
|
||||||
label: (weapon.name) ? weapon.name : game.i18n.localize('BOL.ui.noWeaponName'),
|
label: (weapon.name) ? weapon.name : game.i18n.localize('BOL.ui.noWeaponName'),
|
||||||
description: actor.name + " - " + game.i18n.localize('BOL.ui.weaponAttack'),
|
description: actor.name + " - " + game.i18n.localize('BOL.ui.weaponAttack'),
|
||||||
|
adv: "2",
|
||||||
|
|
||||||
}
|
}
|
||||||
console.debug("WEAPON!", attackDef, weaponData);
|
console.debug("WEAPON!", attackDef, weaponData);
|
||||||
return this.weaponRollDialog(attackDef);
|
return this.displayRollDialog(attackDef);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------------------------------- */
|
/* -------------------------------------------- */
|
||||||
/* ROLL DIALOGS */
|
/* ROLL DIALOGS */
|
||||||
/* -------------------------------------------- */
|
/* -------------------------------------------- */
|
||||||
static async attributeRollDialog(actor, actorData, attribute, label, description, adv, mod, onEnter = "submit") {
|
static async displayRollDialog(rollData, onEnter = "submit") {
|
||||||
const rollOptionTpl = 'systems/bol/templates/dialogs/attribute-roll-dialog.hbs';
|
|
||||||
const dialogData = {
|
|
||||||
adv: adv,
|
|
||||||
mod: mod,
|
|
||||||
attr: attribute,
|
|
||||||
careers: actorData.features.careers,
|
|
||||||
boons: actorData.features.boons,
|
|
||||||
flaws: actorData.features.flaws
|
|
||||||
};
|
|
||||||
|
|
||||||
const rollOptionContent = await renderTemplate(rollOptionTpl, dialogData);
|
const rollOptionTpl = `systems/bol/templates/dialogs/${rollData.mode}-roll-dialog.hbs`
|
||||||
let d = new Dialog({
|
rollData.careers = rollData.actorData.features.careers
|
||||||
title: label,
|
rollData.boons = rollData.actorData.features.boons
|
||||||
content: rollOptionContent,
|
rollData.flaws = rollData.actorData.features.flaws
|
||||||
buttons: {
|
rollData.defence = 0
|
||||||
cancel: {
|
rollData.mod = 0
|
||||||
icon: '<i class="fas fa-times"></i>',
|
rollData.id = randomID(16)
|
||||||
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 || 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) {
|
// Weapon mode specific management
|
||||||
const rollOptionTpl = 'systems/bol/templates/dialogs/weapon-roll-dialog.hbs';
|
if (rollData.mode == "weapon") {
|
||||||
const dialogData = {
|
if (rollData.defender) { // If target is selected
|
||||||
attr: attackDef.attribute,
|
rollData.defence = rollData.defender.defenseValue,
|
||||||
adv: attackDef.adv,
|
rollData.shieldBlock = 'none'
|
||||||
mod: attackDef.mod,
|
let shields = rollData.defender.shields
|
||||||
apt: attackDef.aptitude,
|
|
||||||
weapon: attackDef.weapon,
|
|
||||||
attackId: attackDef.id,
|
|
||||||
careers: attackDef.attackerData.features.careers,
|
|
||||||
boons: attackDef.attackerData.features.boons,
|
|
||||||
flaws: attackDef.attackerData.features.flaws,
|
|
||||||
defence: 0
|
|
||||||
};
|
|
||||||
|
|
||||||
if (attackDef.defender) {
|
|
||||||
dialogData.defence = attackDef.defender.defenseValue,
|
|
||||||
dialogData.shieldBlock = 'none'
|
|
||||||
let shields = attackDef.defender.shields
|
|
||||||
for (let shield of shields) {
|
for (let shield of shields) {
|
||||||
dialogData.shieldBlock = (shield.data.properties.blocking.blockingAll) ? 'blockall' : 'blockone';
|
rollData.shieldBlock = (shield.data.properties.blocking.blockingAll) ? 'blockall' : 'blockone';
|
||||||
dialogData.shieldAttackMalus = (shield.data.properties.blocking.malus) ? shield.data.properties.blocking.malus : 1;
|
rollData.shieldAttackMalus = (shield.data.properties.blocking.malus) ? shield.data.properties.blocking.malus : 1;
|
||||||
dialogData.applyShieldMalus = false
|
rollData.applyShieldMalus = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const rollOptionContent = await renderTemplate(rollOptionTpl, dialogData);
|
}
|
||||||
|
|
||||||
|
console.log("ROL1", rollData)
|
||||||
|
|
||||||
|
const rollOptionContent = await renderTemplate(rollOptionTpl, rollData);
|
||||||
let d = new Dialog({
|
let d = new Dialog({
|
||||||
title: attackDef.label,
|
title: rollData.label,
|
||||||
content: rollOptionContent,
|
content: rollOptionContent,
|
||||||
|
rollData: rollData,
|
||||||
buttons: {
|
buttons: {
|
||||||
cancel: {
|
cancel: {
|
||||||
icon: '<i class="fas fa-times"></i>',
|
icon: '<i class="fas fa-times"></i>',
|
||||||
@ -146,77 +127,37 @@ export class BoLRoll {
|
|||||||
icon: '<i class="fas fa-check"></i>',
|
icon: '<i class="fas fa-check"></i>',
|
||||||
label: game.i18n.localize("BOL.ui.submit"),
|
label: game.i18n.localize("BOL.ui.submit"),
|
||||||
callback: (html) => {
|
callback: (html) => {
|
||||||
const attr = html.find('#attr').val();
|
rollData.attrKey = html.find('#attr').val();
|
||||||
const apt = html.find('#apt').val();
|
rollData.aptKey = html.find('#apt').val();
|
||||||
const adv = html.find('#adv').val();
|
rollData.adv = $("input[name='adv']:checked").val() || "2";
|
||||||
const mod = html.find('#mod').val() || 0;
|
//rollData.adv = html.find('#adv').val() || 0;
|
||||||
|
rollData.mod = html.find('#mod').val() || 0;
|
||||||
|
let careers = html.find('#career').val();
|
||||||
|
rollData.career = (!careers || careers.length == 0) ? 0 : Math.max(...careers.map(i => parseInt(i)));
|
||||||
|
|
||||||
let shieldMalus = 0;
|
let shieldMalus = 0;
|
||||||
|
if ( rollData.mode == "weapon") {
|
||||||
const applyShieldMalus = html.find('#applyShieldMalus').val() || false;
|
const applyShieldMalus = html.find('#applyShieldMalus').val() || false;
|
||||||
if (applyShieldMalus || dialogData.shieldBlock == 'blockall') {
|
if (applyShieldMalus || rollData.shieldBlock == 'blockall') {
|
||||||
shieldMalus = dialogData.shieldAttackMalus;
|
shieldMalus = rollData.shieldAttackMalus;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let careers = html.find('#career').val();
|
const isMalus = rollData.adv.includes('M');
|
||||||
const career = (!careers || careers.length == 0) ? 0 : Math.max(...careers.map(i => parseInt(i)));
|
const dicePool = __adv2dice[rollData.adv]
|
||||||
const isMalus = adv < 0;
|
//// const dicePool = (isMalus) ? 2 - parseInt(rollData.adv) : 2 + parseInt(rollData.adv);
|
||||||
const dicePool = (isMalus) ? 2 - parseInt(adv) : 2 + parseInt(adv);
|
const attrValue = (rollData.attrKey) && eval(`rollData.actor.data.data.attributes.${rollData.attrKey}.value`) || 0;
|
||||||
const attrValue = eval(`attackDef.attacker.data.data.attributes.${attr}.value`);
|
const aptValue = (rollData.aptKey) && eval(`rollData.actor.data.data.aptitudes.${rollData.aptKey}.value`) || 0
|
||||||
const aptValue = eval(`attackDef.attacker.data.data.aptitudes.${apt}.value`);
|
|
||||||
const modifiers = parseInt(attrValue) + parseInt(aptValue) + parseInt(mod) + parseInt(career) - dialogData.defence - shieldMalus;
|
const modifiers = parseInt(attrValue) + parseInt(aptValue) + parseInt(rollData.mod) + parseInt(rollData.career) - rollData.defence - shieldMalus;
|
||||||
const formula = (isMalus) ? dicePool + "d6kl2 + " + modifiers : dicePool + "d6kh2 + " + modifiers;
|
const formula = (isMalus) ? dicePool + "d6kl2 + " + modifiers : dicePool + "d6kh2 + " + modifiers;
|
||||||
attackDef.formula = formula;
|
rollData.formula = formula;
|
||||||
let r = new BoLAttackRoll(attackDef);
|
|
||||||
|
let r = new BoLDefaultRoll(rollData);
|
||||||
r.roll();
|
r.roll();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
default: 'submit',
|
|
||||||
close: () => { }
|
|
||||||
}, this.options());
|
|
||||||
return d.render(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
static async aptitudeRollDialog(actor, actorData, aptitude, label, description, adv, mod, onEnter = "submit") {
|
|
||||||
const rollOptionTpl = 'systems/bol/templates/dialogs/aptitude-roll-dialog.hbs';
|
|
||||||
const dialogData = {
|
|
||||||
adv: adv,
|
|
||||||
mod: mod,
|
|
||||||
apt: aptitude,
|
|
||||||
careers: actorData.features.careers,
|
|
||||||
boons: actorData.features.boons,
|
|
||||||
flaws: actorData.features.flaws
|
|
||||||
};
|
|
||||||
const rollOptionContent = await renderTemplate(rollOptionTpl, dialogData);
|
|
||||||
let d = new Dialog({
|
|
||||||
title: 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 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 || 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,
|
default: onEnter,
|
||||||
close: () => { }
|
close: () => { }
|
||||||
}, this.options());
|
}, this.options());
|
||||||
@ -225,192 +166,92 @@ export class BoLRoll {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class BoLDefaultRoll {
|
export class BoLDefaultRoll {
|
||||||
constructor(label, formula, description, isWeapon = false) {
|
constructor(rollData) {
|
||||||
this._label = label;
|
BoLUtility.storeRoll(rollData);
|
||||||
this._formula = formula;
|
this.rollData = rollData
|
||||||
this._isSuccess = false;
|
this.rollData.isSuccess = false;
|
||||||
this._isCritical = false;
|
this.rollData.isCritical = false;
|
||||||
this._isFumble = false;
|
this.rollData.isFumble = false;
|
||||||
this._isWeapon = isWeapon;
|
|
||||||
this._description = description;
|
|
||||||
}
|
|
||||||
|
|
||||||
async roll(actor) {
|
|
||||||
const r = new Roll(this._formula);
|
|
||||||
await r.roll({ "async": true });
|
|
||||||
const activeDice = r.terms[0].results.filter(r => r.active);
|
|
||||||
const diceTotal = activeDice.map(r => r.result).reduce((a, b) => a + b);
|
|
||||||
this._isSuccess = (r.total >= 9);
|
|
||||||
this._isCritical = (diceTotal === 12);
|
|
||||||
this._isFumble = (diceTotal === 2);
|
|
||||||
this._buildChatMessage(actor).then(msgFlavor => {
|
|
||||||
r.toMessage({
|
|
||||||
user: game.user.id,
|
|
||||||
flavor: msgFlavor,
|
|
||||||
speaker: ChatMessage.getSpeaker({ actor: actor }),
|
|
||||||
flags: { msgType: "default" }
|
|
||||||
});
|
|
||||||
});
|
|
||||||
if (this._isSuccess && this._isWeapon) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_buildChatMessage(actor) {
|
|
||||||
const rollMessageTpl = 'systems/bol/templates/chat/rolls/default-roll-card.hbs';
|
|
||||||
const tplData = {
|
|
||||||
actor: actor,
|
|
||||||
label: this._label,
|
|
||||||
reroll: actor.heroReroll(),
|
|
||||||
isSuccess: this._isSuccess,
|
|
||||||
isFailure: !this._isSuccess,
|
|
||||||
isCritical: this._isCritical,
|
|
||||||
isFumble: this._isFumble,
|
|
||||||
hasDescription: this._description && this._description.length > 0,
|
|
||||||
description: this._description
|
|
||||||
};
|
|
||||||
return renderTemplate(rollMessageTpl, tplData);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
export class BoLAttackRoll {
|
|
||||||
constructor(attackDef) {
|
|
||||||
this.attackDef = attackDef;
|
|
||||||
this._isSuccess = false;
|
|
||||||
this._isCritical = false;
|
|
||||||
this._isFumble = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async roll() {
|
async roll() {
|
||||||
console.log("Attack def",this.attackDef.formula )
|
console.log("ROLL", this.rollData)
|
||||||
const r = new Roll(this.attackDef.formula);
|
|
||||||
|
const r = new Roll(this.rollData.formula);
|
||||||
await r.roll({ "async": false });
|
await r.roll({ "async": false });
|
||||||
await BoLUtility.showDiceSoNice(r);
|
//await BoLUtility.showDiceSoNice(r);
|
||||||
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.rollData.isSuccess = (r.total >= 9);
|
||||||
this._isCritical = (diceTotal === 12);
|
this.rollData.isCritical = (diceTotal === 12);
|
||||||
this._isFumble = (diceTotal === 2);
|
this.rollData.isFumble = (diceTotal === 2);
|
||||||
this._buildChatMessage(this.attackDef.attacker).then(msgFlavor => {
|
this.rollData.isFailure = !this.rollData.isSuccess
|
||||||
|
this.rollData.reroll = this.rollData.actor.heroReroll()
|
||||||
|
|
||||||
|
this._buildChatMessage(this.rollData).then(msgFlavor => {
|
||||||
r.toMessage({
|
r.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.rollData.actor }),
|
||||||
flags: { msgType: "default" }
|
flags: { msgType: "default" }
|
||||||
}).then(this.processResult());
|
}).then(this.processResult());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async processDefense() {
|
async processDefense() {
|
||||||
if (this._isCritical) {
|
if (this.rollData.isCritical) {
|
||||||
ChatMessage.create({
|
ChatMessage.create({
|
||||||
alias: this.attackDef.attacker.name,
|
alias: this.rollData.actor.name,
|
||||||
whisper: BoLUtility.getWhisperRecipientsAndGMs(this.attackDef.attacker.name),
|
whisper: BoLUtility.getWhisperRecipientsAndGMs(this.rollData.actor.name),
|
||||||
content: await renderTemplate('systems/bol/templates/chat/rolls/attack-heroic-card.hbs', {
|
content: await renderTemplate('systems/bol/templates/chat/rolls/attack-heroic-card.hbs', this.rollData )
|
||||||
attackId: attackDef.id,
|
|
||||||
attacker: attackDef.attacker,
|
|
||||||
defender: attackDef.defender,
|
|
||||||
defenderWeapons: defenderWeapons,
|
|
||||||
damageTotal: attackDef.damageRoll.total
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
BoLUtility.sendAttackSuccess( this.attackDef);
|
BoLUtility.sendAttackSuccess(this.rollData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setSuccess( flag) {
|
||||||
|
this.rollData.isSuccess = flag
|
||||||
|
}
|
||||||
|
|
||||||
async processResult() {
|
async processResult() {
|
||||||
if (this._isSuccess) {
|
if ( this.rollData.mode != "weapon") { // Only specific process in Weapon mode
|
||||||
let attrDamage = this.attackDef.weapon.data.data.properties.damageAttribute;
|
return;
|
||||||
let weaponFormula = BoLUtility.getDamageFormula(this.attackDef.weapon.data.data.properties.damage,
|
}
|
||||||
this.attackDef.weapon.data.data.properties.damageModifiers,
|
|
||||||
this.attackDef.weapon.data.data.properties.damageMultiplier)
|
|
||||||
let damageFormula = weaponFormula + "+" + this.attackDef.attacker.data.data.attributes[attrDamage].value;
|
|
||||||
console.log("Formula", damageFormula)
|
|
||||||
this.damageRoll = new Roll(damageFormula);
|
|
||||||
await this.damageRoll.roll({ "async": false });
|
|
||||||
await BoLUtility.showDiceSoNice(this.damageRoll);
|
|
||||||
// Update attackDef object
|
|
||||||
this.attackDef.damageFormula = damageFormula;
|
|
||||||
this.attackDef.damageRoll = this.damageRoll;
|
|
||||||
|
|
||||||
this._buildDamageChatMessage(this.attackDef.attacker, this.attackDef.weapon, this.damageRoll.total).then(msgFlavor => {
|
if (this.rollData.isSuccess) {
|
||||||
this.damageRoll.toMessage({
|
let attrDamage = this.rollData.weapon.data.data.properties.damageAttribute;
|
||||||
|
let weaponFormula = BoLUtility.getDamageFormula(this.rollData.weapon.data.data.properties.damage,
|
||||||
|
this.rollData.weapon.data.data.properties.damageModifiers,
|
||||||
|
this.rollData.weapon.data.data.properties.damageMultiplier)
|
||||||
|
let damageFormula = weaponFormula + ((attrDamage) ? "+" + this.rollData.actor.data.data.attributes[attrDamage].value : "+0");
|
||||||
|
|
||||||
|
//console.log("Formula", weaponFormula, damageFormula, this.rollData.weapon.data.data.properties.damage)
|
||||||
|
this.rollData.damageRoll = new Roll(damageFormula);
|
||||||
|
await this.rollData.damageRoll.roll({ "async": false });
|
||||||
|
await BoLUtility.showDiceSoNice(this.rollData.damageRoll);
|
||||||
|
// Update rollData object
|
||||||
|
this.rollData.damageFormula = damageFormula;
|
||||||
|
|
||||||
|
this._buildDamageChatMessage( this.rollData ).then(msgFlavor => {
|
||||||
|
this.rollData.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.rollData.actor }),
|
||||||
flags: { msgType: "default" }
|
flags: { msgType: "default" }
|
||||||
}).then(this.processDefense());
|
}).then(this.processDefense());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_buildDamageChatMessage(actor, weapon, total) {
|
_buildDamageChatMessage(rollData) {
|
||||||
const rollMessageTpl = 'systems/bol/templates/chat/rolls/damage-roll-card.hbs';
|
const rollMessageTpl = 'systems/bol/templates/chat/rolls/damage-roll-card.hbs';
|
||||||
const tplData = {
|
return renderTemplate(rollMessageTpl, rollData);
|
||||||
actor: actor,
|
|
||||||
label: this._label,
|
|
||||||
weapon: weapon,
|
|
||||||
damage: total,
|
|
||||||
isCritical: this._isCritical,
|
|
||||||
};
|
|
||||||
return renderTemplate(rollMessageTpl, tplData);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_buildChatMessage(actor) {
|
_buildChatMessage(rollData) {
|
||||||
const rollMessageTpl = 'systems/bol/templates/chat/rolls/default-roll-card.hbs';
|
const rollMessageTpl = 'systems/bol/templates/chat/rolls/default-roll-card.hbs';
|
||||||
const tplData = {
|
return renderTemplate(rollMessageTpl, rollData);
|
||||||
actor: actor,
|
|
||||||
label: this._label,
|
|
||||||
reroll: actor.heroReroll(),
|
|
||||||
isSuccess: this._isSuccess,
|
|
||||||
isFailure: !this._isSuccess,
|
|
||||||
isCritical: this._isCritical,
|
|
||||||
isFumble: this._isFumble,
|
|
||||||
hasDescription: this._description && this._description.length > 0,
|
|
||||||
description: this._description
|
|
||||||
};
|
|
||||||
return renderTemplate(rollMessageTpl, tplData);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
// export class BoLWeaponRoll {
|
|
||||||
// constructor(actor, label, formula, isCritical, description){
|
|
||||||
// this._label = label;
|
|
||||||
// this._formula = formula;
|
|
||||||
// this._isCritical = isCritical;
|
|
||||||
// this._description = description;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// _buildChatMessage() {
|
|
||||||
// const rollMessageTpl = 'systems/bol/templates/chat/rolls/weapon-roll-card.hbs';
|
|
||||||
// const tplData = {
|
|
||||||
// label : this._label,
|
|
||||||
// isCritical : this._isCritical,
|
|
||||||
// hasDescription : this._description && this._description.length > 0,
|
|
||||||
// description : this._description
|
|
||||||
// };
|
|
||||||
// return renderTemplate(rollMessageTpl, tplData);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// export class BoLSpellRoll {
|
|
||||||
// constructor(actor, label, formula, isCritical, description){
|
|
||||||
// this._label = label;
|
|
||||||
// this._formula = formula;
|
|
||||||
// this._isCritical = isCritical;
|
|
||||||
// this._description = description;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// _buildChatMessage() {
|
|
||||||
// const rollMessageTpl = 'systems/bol/templates/chat/rolls/spell-roll-card.hbs';
|
|
||||||
// const tplData = {
|
|
||||||
// label : this._label,
|
|
||||||
// isCritical : this._isCritical,
|
|
||||||
// hasDescription : this._description && this._description.length > 0,
|
|
||||||
// description : this._description
|
|
||||||
// };
|
|
||||||
// return renderTemplate(rollMessageTpl, tplData);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
|
import { BoLDefaultRoll } from "../controllers/bol-rolls.js";
|
||||||
|
|
||||||
export class BoLUtility {
|
export class BoLUtility {
|
||||||
|
|
||||||
|
|
||||||
/* -------------------------------------------- */
|
/* -------------------------------------------- */
|
||||||
static async init() {
|
static async init() {
|
||||||
this.attackStore = {};
|
this.attackStore = {}
|
||||||
Hooks.on('renderChatLog', (log, html, data) => BoLUtility.chatListeners(html));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------------------------------- */
|
/* -------------------------------------------- */
|
||||||
@ -25,6 +25,16 @@ export class BoLUtility {
|
|||||||
return it;
|
return it;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* -------------------------------------------- */
|
||||||
|
static storeRoll(roll) {
|
||||||
|
this.lastRoll = roll
|
||||||
|
}
|
||||||
|
|
||||||
|
/* -------------------------------------------- */
|
||||||
|
static getLastRoll() {
|
||||||
|
return this.lastRoll
|
||||||
|
}
|
||||||
|
|
||||||
/* -------------------------------------------- */
|
/* -------------------------------------------- */
|
||||||
static createDirectOptionList(min, max) {
|
static createDirectOptionList(min, max) {
|
||||||
let options = {};
|
let options = {};
|
||||||
@ -123,7 +133,11 @@ export class BoLUtility {
|
|||||||
|
|
||||||
html.on("click", '.hero-reroll', event => {
|
html.on("click", '.hero-reroll', event => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
ui.notifications.warn("Not implemented up to now");
|
|
||||||
|
let rollData = BoLUtility.getLastRoll()
|
||||||
|
rollData.actor.subHeroPoints(1)
|
||||||
|
let r = new BoLDefaultRoll( rollData )
|
||||||
|
r.roll();
|
||||||
} );
|
} );
|
||||||
|
|
||||||
html.on("click", '.damage-handling', event => {
|
html.on("click", '.damage-handling', event => {
|
||||||
|
@ -30,9 +30,15 @@ export const preloadHandlebarsTemplates = async function () {
|
|||||||
"systems/bol/templates/item/parts/properties/feature/flaw-properties.hbs",
|
"systems/bol/templates/item/parts/properties/feature/flaw-properties.hbs",
|
||||||
"systems/bol/templates/item/parts/properties/feature/origin-properties.hbs",
|
"systems/bol/templates/item/parts/properties/feature/origin-properties.hbs",
|
||||||
"systems/bol/templates/item/parts/properties/feature/race-properties.hbs",
|
"systems/bol/templates/item/parts/properties/feature/race-properties.hbs",
|
||||||
|
|
||||||
// DIALOGS
|
// DIALOGS
|
||||||
"systems/bol/templates/roll/parts/roll-dialog-modifiers.hbs",
|
"systems/bol/templates/roll/parts/roll-dialog-modifiers.hbs",
|
||||||
"systems/bol/templates/roll/parts/roll-dialog-attribute.hbs"
|
"systems/bol/templates/roll/parts/roll-dialog-attribute.hbs",
|
||||||
|
"systems/bol/templates/dialogs/aptitude-roll-part.hbs",
|
||||||
|
"systems/bol/templates/dialogs/attribute-roll-part.hbs",
|
||||||
|
"systems/bol/templates/dialogs/mod-roll-part.hbs",
|
||||||
|
"systems/bol/templates/dialogs/adv-roll-part.hbs",
|
||||||
|
"systems/bol/templates/dialogs/career-roll-part.hbs",
|
||||||
];
|
];
|
||||||
|
|
||||||
// Load the template parts
|
// Load the template parts
|
||||||
|
@ -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.6",
|
"version": "0.8.9.7",
|
||||||
"templateVersion": 14,
|
"templateVersion": 14,
|
||||||
"minimumCoreVersion": "0.8.6",
|
"minimumCoreVersion": "0.8.6",
|
||||||
"compatibleCoreVersion": "9",
|
"compatibleCoreVersion": "9",
|
||||||
|
Loading…
Reference in New Issue
Block a user