Ehance rols

This commit is contained in:
2022-02-18 21:58:53 +01:00
parent cfdfa27f23
commit 0ee9e41a50
21 changed files with 372 additions and 216 deletions

View File

@ -5,7 +5,7 @@ const _apt2attr = { init: "mind", melee: "agility", ranged: "agility", def: "vig
export class BoLRoll {
static options() {
return { classes: ["bol", "dialog"] };
return { classes: ["bol", "dialog"], width: 480, height: 540 };
}
static convertToAdv(adv) {
@ -15,9 +15,8 @@ export class BoLRoll {
static getDefaultAttribute(key) {
return _apt2attr[key]
}
/* -------------------------------------------- */
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}`);
@ -29,16 +28,18 @@ export class BoLRoll {
actor: actor,
actorData: actorData,
attribute: attribute,
attrValue: attribute.value,
aptValue: 0,
label: label,
careerBonus: 0,
description: description,
adv: this.convertToAdv(adv),
mod: 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;
@ -55,13 +56,17 @@ export class BoLRoll {
actorData: actorData,
attribute: attribute,
aptitude: aptitude,
attrValue: attribute.value,
aptValue: aptitude.value,
label: label,
careerBonus: 0,
description: description,
adv: this.convertToAdv(adv),
mod: 0
});
}
/* -------------------------------------------- */
static weaponCheck(actor, actorData, dataset, event) {
let target = BoLUtility.getTarget()
const li = $(event.currentTarget).parents(".item");
@ -71,15 +76,22 @@ export class BoLRoll {
return;
}
let weaponData = weapon.data.data;
let attribute = eval(`actor.data.data.attributes.${weaponData.properties.attackAttribute}`)
let aptitude = eval(`actor.data.data.aptitudes.${weaponData.properties.attackAptitude}`)
let attackDef = {
mode: "weapon",
actor: actor,
actorData: actorData,
weapon: weapon,
target: target,
careerBonus: 0,
defender: (target) ? game.actors.get(target.data.actorId) : undefined,
attribute: eval(`actor.data.data.attributes.${weaponData.properties.attackAttribute}`),
aptitude: eval(`actor.data.data.aptitudes.${weaponData.properties.attackAptitude}`),
attribute: attribute,
aptitude: aptitude,
attrValue: attribute.value,
aptValue: aptitude.value,
mod: 0,
label: (weapon.name) ? weapon.name : game.i18n.localize('BOL.ui.noWeaponName'),
description: actor.name + " - " + game.i18n.localize('BOL.ui.weaponAttack'),
adv: "2",
@ -88,7 +100,8 @@ export class BoLRoll {
return this.displayRollDialog(attackDef);
}
static alchemyCheck( actor, actorData, dataset, event) {
/* -------------------------------------------- */
static alchemyCheck(actor, actorData, dataset, event) {
const li = $(event.currentTarget).parents(".item");
const alchemy = actor.items.get(li.data("item-id"));
if (!alchemy) {
@ -107,6 +120,8 @@ export class BoLRoll {
actorData: actorData,
alchemy: alchemy,
attribute: actor.data.data.attributes.mind,
attrValue: actor.data.data.attributes.mind.value,
aptValue: 0,
careerBonus: actor.getAlchemistBonus(),
pcCost: alchemyData.properties.pccost,
pcCostCurrent: alchemyData.properties.pccurrent,
@ -119,8 +134,9 @@ export class BoLRoll {
return this.displayRollDialog(alchemyDef);
}
static spellCheck( actor, actorData, dataset, event) {
/* -------------------------------------------- */
static spellCheck(actor, actorData, dataset, event) {
if (actor.data.data.resources.power.value <= 0) {
ui.notifications.warn("Plus assez de points de Pouvoir !")
return
@ -138,7 +154,9 @@ export class BoLRoll {
actorData: actorData,
spell: spell,
attribute: actor.data.data.attributes.mind,
ppCurrent: actor.data.data.resources.power.value,
attrValue: actor.data.data.attributes.mind.value,
aptValue: 0,
ppCurrent: actor.data.data.resources.power.value,
careerBonus: actor.getSorcererBonus(),
ppCost: spell.data.data.properties.ppcost,
mod: spellData.properties.difficulty,
@ -151,13 +169,82 @@ export class BoLRoll {
}
/* -------------------------------------------- */
static rollDialogListener(html) {
static updateTotalDice() {
this.rollData.bmDice = this.rollData.nbBoons - this.rollData.nbFlaws + this.rollData.bDice - this.rollData.mDice
this.rollData.nbDice = 2 + Math.abs(this.rollData.bmDice)
if (this.rollData.bmDice == 0 ) {
$('#roll-nbdice').val( "2" )
} else {
let letter = (this.rollData.bmDice > 0) ? "B" : "M"
$('#roll-nbdice').val( "2 + " + String(Math.abs(this.rollData.bmDice)) + letter )
}
$('#roll-modifier').val( this.rollData.attrValue + "+" + this.rollData.aptValue + "+" + this.rollData.careerBonus + "+" + this.rollData.mod + "+" +
this.rollData.weaponModifier + "-" + this.rollData.defence + "+" + this.rollData.shieldMalus )
}
/* -------------------------------------------- */
static rollDialogListener(html) {
this.updateTotalDice()
html.find('#optcond').change((event) => { // Dynamic change of PP cost of spell
let pp = BoLUtility.computeSpellCost(this.rollData.spell, event.currentTarget.selectedOptions.length)
$('#ppcost').html(pp)
this.rollData.ppCost = pp
});
})
html.find('#mod').change((event) => {
this.rollData.mod = Number(event.currentTarget.value)
this.updateTotalDice()
})
html.find('#attr').change((event) => {
let attrKey = event.currentTarget.value
this.rollData.attribute = duplicate(this.rollData.actor.data.data.attributes[attrKey])
this.rollData.attrValue = this.rollData.actor.data.data.attributes[attrKey].value
this.updateTotalDice()
} )
html.find('#apt').change((event) => {
let aptKey = event.currentTarget.value
this.rollData.aptitude = duplicate(this.rollData.actor.data.data.aptitudes[aptKey])
this.rollData.aptValue = this.rollData.actor.data.data.aptitudes[aptKey].value
this.updateTotalDice()
} )
html.find('#applyShieldMalus').click( (event) => {
if (event.currentTarget.checked) {
this.rollData.shieldMalus = this.rollData.shieldAttackMalus
} else {
this.rollData.shieldMalus = 0
}
})
html.find('#career').change((event) => {
let careers = $('#career').val()
this.rollData.careerBonus = (!careers || careers.length == 0) ? 0 : Math.max(...careers.map(i => parseInt(i)))
this.updateTotalDice()
})
html.find('#boon').change((event) => {
let boons = $('#boon').val()
this.rollData.nbBoons = (!boons || boons.length == 0) ? 0 : Math.max(...boons.map(i => parseInt(i)))
this.updateTotalDice()
})
html.find('#flaw').change((event) => {
let flaws = $('#flaw').val()
this.rollData.nbFlaws = (!flaws || flaws.length == 0) ? 0 : Math.max(...flaws.map(i => parseInt(i)))
this.updateTotalDice()
})
html.find('.bdice').click((event) => {
this.rollData.mDice = 0
this.rollData.bDice = Number(event.currentTarget.value)
this.updateTotalDice()
})
html.find('.mdice').click((event) => {
this.rollData.bDice = 0
this.rollData.mDice = Number(event.currentTarget.value)
this.updateTotalDice()
})
}
/* ROLL DIALOGS */
@ -166,20 +253,33 @@ export class BoLRoll {
const rollOptionTpl = `systems/bol/templates/dialogs/${rollData.mode}-roll-dialog.hbs`
rollData.careers = rollData.actorData.features.careers
rollData.boons = rollData.actorData.features.boons
rollData.flaws = rollData.actorData.features.flaws
rollData.boons = rollData.actor.bonusBoons
rollData.flaws = rollData.actor.malusFlaws
rollData.defence = 0
rollData.careerBonus = rollData.careerBonus?? 0
rollData.mod = rollData.mod?? 0
rollData.bDice = 0
rollData.mDice = 0
rollData.nbBoons = 0
rollData.nbFlaws = 0
rollData.nbDice = 0
if (rollData.shieldBlock == 'blockall') {
rollData.shieldMalus = rollData.shieldAttackMalus;
} else {
rollData.shieldMalus = 0
}
rollData.careerBonus = rollData.careerBonus ?? 0
rollData.mod = rollData.mod ?? 0
rollData.id = randomID(16)
this.rollData = rollData
// Weapon mode specific management
rollData.weaponModifier = 0
rollData.attackBonusDice = false
// Saves
this.rollData = rollData
console.log("ROLLDATA", rollData)
if (rollData.mode == "weapon") {
//console.log("WEAPON", rollData.weapon)
rollData.weaponModifier = rollData.weapon.data.data.properties.attackModifiers?? 0;
rollData.weaponModifier = rollData.weapon.data.data.properties.attackModifiers ?? 0;
rollData.attackBonusDice = rollData.weapon.data.data.properties.attackBonusDice
if (rollData.defender) { // If target is selected
rollData.defence = rollData.defender.defenseValue
@ -216,33 +316,14 @@ export class BoLRoll {
return
}
rollData.attrKey = html.find('#attr').val();
rollData.aptKey = html.find('#apt').val();
rollData.adv = $("input[name='adv']:checked").val() || "2";
//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)));
rollData.registerInit = (rollData.aptKey == 'init') ? $('#register-init').is(":checked") : false;
let shieldMalus = 0
if (rollData.mode == "weapon") {
const applyShieldMalus = html.find('#applyShieldMalus').val() || false
if (applyShieldMalus || rollData.shieldBlock == 'blockall') {
shieldMalus = rollData.shieldAttackMalus;
}
}
const isMalus = rollData.mDice > 0
rollData.nbDice += (rollData.attackBonusDice) ? 1 : 0
const isMalus = rollData.adv.includes('M')
let dicePool = __adv2dice[rollData.adv]
dicePool += (rollData.attackBonusDice) ? 1 : 0
const attrValue = (rollData.attrKey) && eval(`rollData.actor.data.data.attributes.${rollData.attrKey}.value`) || 0;
const aptValue = (rollData.aptKey) && eval(`rollData.actor.data.data.aptitudes.${rollData.aptKey}.value`) || 0
const modifiers = rollData.careerBonus + rollData.weaponModifier + parseInt(attrValue) + parseInt(aptValue) + parseInt(rollData.mod) + parseInt(rollData.career) - rollData.defence + shieldMalus;
const formula = (isMalus) ? dicePool + "d6kl2 + " + modifiers : dicePool + "d6kh2 + " + modifiers;
rollData.formula = formula;
const modifiers = rollData.attrValue + rollData.aptValue + rollData.careerBonus + rollData.mod + rollData.weaponModifier - rollData.defence + rollData.shieldMalus
const formula = (isMalus) ? rollData.nbDice + "d6kl2 + " + modifiers : rollData.nbDice + "d6kh2 + " + modifiers
rollData.formula = formula
rollData.modifiers = modifiers
let r = new BoLDefaultRoll(rollData);
@ -259,21 +340,21 @@ export class BoLRoll {
}
export class BoLDefaultRoll {
constructor(rollData) {
BoLUtility.storeRoll(rollData)
this.rollData = rollData
if ( this.rollData.isSuccess == undefined ) { // First init
if (this.rollData.isSuccess == undefined) { // First init
this.rollData.isSuccess = false;
this.rollData.isCritical = false;
this.rollData.isFumble = false;
}
if ( this.rollData.optionsId) {
if (this.rollData.optionsId) {
$(`#${this.rollData.optionsId}`).hide() // Hide the options roll buttons
}
if ( this.rollData.applyId) {
}
if (this.rollData.applyId) {
$(`#${this.rollData.applyId}`).hide() // Hide the options roll buttons
}
}
this.rollData.optionsId = randomID(16)
this.rollData.applyId = randomID(16)
}
@ -344,11 +425,11 @@ export class BoLDefaultRoll {
})
});
}
getDamageAttributeValue( attrDamage) {
getDamageAttributeValue(attrDamage) {
let attrDamageValue = 0
if ( attrDamage.includes("vigor") ) {
attrDamageValue = this.rollData.actor.data.data.attributes.vigor.value
if (attrDamage.includes("vigor")) {
attrDamageValue = this.rollData.actor.data.data.attributes.vigor.value
if (attrDamage.includes("half")) {
attrDamageValue = Math.floor(attrDamageValue / 2)
}
@ -362,19 +443,19 @@ export class BoLDefaultRoll {
}
if (this.rollData.isSuccess) {
if ( !this.rollData.damageRoll) {
if (!this.rollData.damageRoll) {
let bonusDmg = 0
if ( this.rollData.damageMode == 'damage-plus-6') {
if (this.rollData.damageMode == 'damage-plus-6') {
bonusDmg = 6
}
if ( this.rollData.damageMode == 'damage-plus-12') {
if (this.rollData.damageMode == 'damage-plus-12') {
bonusDmg = 12
}
let attrDamageValue = this.getDamageAttributeValue(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 + "+" + bonusDmg + "+" + attrDamageValue
this.rollData.weapon.data.data.properties.damageModifiers,
this.rollData.weapon.data.data.properties.damageMultiplier)
let damageFormula = weaponFormula + "+" + bonusDmg + "+" + attrDamageValue
console.log("DAMAGE !!!", damageFormula, attrDamageValue)
//console.log("Formula", weaponFormula, damageFormula, this.rollData.weapon.data.data.properties.damage)