diff --git a/lang/en.json b/lang/en.json index 87ad2d9..989f516 100644 --- a/lang/en.json +++ b/lang/en.json @@ -108,7 +108,8 @@ "BOL.ui.duration": "Duration", "BOL.ui.spellkeep": "Maintain", "BOL.ui.concentrate": "Concentrate", - + "BOL.ui.registerInit": "Register Init.", + "BOL.featureCategory.origins": "Origines", "BOL.featureCategory.races": "Races", "BOL.featureCategory.careers": "Carrières", diff --git a/lang/fr.json b/lang/fr.json index a24983b..12151f9 100644 --- a/lang/fr.json +++ b/lang/fr.json @@ -109,7 +109,8 @@ "BOL.ui.duration": "Durée", "BOL.ui.spellkeep": "Prolongation", "BOL.ui.concentrate": "Concentration", - + "BOL.ui.registerInit": "Enregistrer comme Init. de combat", + "BOL.featureCategory.origins": "Origines", "BOL.featureCategory.races": "Races", "BOL.featureCategory.careers": "Carrières", diff --git a/module/actor/actor.js b/module/actor/actor.js index 220af12..2e4b8e5 100644 --- a/module/actor/actor.js +++ b/module/actor/actor.js @@ -243,6 +243,16 @@ export class BoLActor extends Actor { } } + /*-------------------------------------------- */ + registerInit(initScore, isCritical, isFumble) { + this.update( { 'data.combat.lastinit': initScore, 'data.combat.iscritical': isCritical, 'data.combat.isfumble': isFumble} ) + } + + /*-------------------------------------------- */ + getLastInitData() { + return this.data.data.combat + } + /*-------------------------------------------- */ async subHeroPoints( nb) { let newHeroP = this.data.data.resources.hero.value - nb; diff --git a/module/bol.js b/module/bol.js index 750dec5..6ab5f59 100644 --- a/module/bol.js +++ b/module/bol.js @@ -8,9 +8,9 @@ import { preloadHandlebarsTemplates } from "./system/templates.js"; import { registerHandlebarsHelpers } from "./system/helpers.js"; import { registerSystemSettings } from "./system/settings.js"; import registerHooks from "./system/hooks.js"; -// import {DataLoader} from "./system/data.js"; import { Macros } from "./system/macros.js"; import { BoLUtility } from "./system/bol-utility.js"; +import { BoLCombatManager } from "./system/bol-combat.js"; Hooks.once('init', async function () { @@ -33,12 +33,13 @@ Hooks.once('init', async function () { */ CONFIG.Combat.initiative = { formula: "2d6+@attributes.mind.value+@aptitudes.init.value", - decimals: 0 + decimals: 2 }; 0 // Define custom Entity classes CONFIG.Actor.documentClass = BoLActor; CONFIG.Item.documentClass = BoLItem; + CONFIG.Combat.documentClass = BoLCombatManager; // Register sheet application classes Actors.unregisterSheet("core", ActorSheet); diff --git a/module/controllers/bol-rolls.js b/module/controllers/bol-rolls.js index aef7101..384d3b5 100644 --- a/module/controllers/bol-rolls.js +++ b/module/controllers/bol-rolls.js @@ -1,6 +1,8 @@ import { BoLUtility } from "../system/bol-utility.js"; const __adv2dice = { ["1B"]: 3, ["2B"]: 4, ["2"]: 2, ["1M"]: 3, ["2M"]: 4} +const _apt2attr = {init: "mind", melee: "agility", ranged: "agility", def: "vigor"} + export class BoLRoll { static options() { return { classes: ["bol", "dialog"] }; @@ -10,7 +12,9 @@ export class BoLRoll { if (adv == 0) return "2" return Math.abs(adv) + (adv < 0)?'M':'B'; } - + static getDefaultAttribute( key ) { + return _apt2attr[key] + } static attributeCheck(actor, actorData, dataset, event) { // const elt = $(event.currentTarget)[0]; // let key = elt.attributes["data-rolling"].value; @@ -37,7 +41,11 @@ export class BoLRoll { // let key = elt.attributes["data-rolling"].value; const key = dataset.key; const adv = dataset.adv; + let aptitude = eval(`actor.data.data.aptitudes.${key}`); + let attrKey = this.getDefaultAttribute(key) + let attribute = eval(`actor.data.data.attributes.${attrKey}`); + 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.displayRollDialog( @@ -45,6 +53,7 @@ export class BoLRoll { mode: "aptitude", actor: actor, actorData: actorData, + attribute: attribute, aptitude: aptitude, label: label, description: description, @@ -134,7 +143,8 @@ export class BoLRoll { 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; @@ -188,6 +198,10 @@ export class BoLDefaultRoll { this.rollData.isFailure = !this.rollData.isSuccess this.rollData.reroll = this.rollData.actor.heroReroll() + if (this.rollData.registerInit) { + this.rollData.actor.registerInit( r.total, this.rollData.isCritical); + } + this._buildChatMessage(this.rollData).then(msgFlavor => { r.toMessage({ user: game.user.id, diff --git a/module/system/bol-combat.js b/module/system/bol-combat.js index 2162ed5..2334d96 100644 --- a/module/system/bol-combat.js +++ b/module/system/bol-combat.js @@ -1,5 +1,17 @@ +/* +Init order = + 10 - Legendary + 9 - Heroic + 8 - Success + 7 - Rivals/adversary + 6 - Coriaces/tough + 5 - Failure + 4 - Pietaille + 3 - Echec critique +*/ -export class RdDCombatManager extends Combat { + +export class BoLCombatManager extends Combat { /************************************************************************************/ async rollInitiative(ids, formula = undefined, messageOptions = {}) { @@ -7,15 +19,35 @@ export class RdDCombatManager extends Combat { // Structure input data ids = typeof ids === "string" ? [ids] : ids; const currentId = this.combatant._id; - + // calculate initiative - if ( game.combat.current.round == 1) { - for (let cId = 0; cId < ids.length; cId++) { - const combatant = this.combatants.get(ids[cId]); - // TODO - console.log("TODO : Compute init for actor"); + for (let cId = 0; cId < ids.length; cId++) { + const combatant = this.combatants.get(ids[cId]); + let fvttInit = 5 + if (combatant.actor.type == 'character') { + let initData = combatant.actor.getLastInitData(); + if (initData.isLegendary) { + fvttInit = 10 + } else if (initData.isCritical) { + fvttInit = 9 + } else if (initData.lastinit >= 9) { + fvttInit = 8 + } else if (initData.isFumble) { + fvttInit = 3 + } + } else { + fvttInit = 4 // Pietaille par defaut + if ( combatant.actor.getSubtype == 'adversary') { + fvttInit = 7 + } + if ( combatant.actor.getSubtype == 'tough') { + fvttInit = 6 + } } + fvttInit += (cId / 10) + await this.updateEmbeddedDocuments("Combatant", [{ _id: ids[cId], initiative: fvttInit }]); } + console.log("TODO : Compute init for actor"); } +} -} \ No newline at end of file diff --git a/system.json b/system.json index 518890f..c1b135e 100644 --- a/system.json +++ b/system.json @@ -7,8 +7,8 @@ "url": "https://github.com/ZigmundKreud/bol", "license": "LICENSE.txt", "flags": {}, - "version": "0.8.9.7", - "templateVersion": 14, + "version": "0.8.9.9", + "templateVersion": 16, "minimumCoreVersion": "0.8.6", "compatibleCoreVersion": "9", "scripts": [], diff --git a/template.json b/template.json index 16645eb..a26f869 100644 --- a/template.json +++ b/template.json @@ -11,6 +11,12 @@ "notes": "", "languages": [] }, + "combat": { + "lastinit": 0, + "iscritical": false, + "isfumble": false, + "islegendary": false + }, "prot": { "key": "prot", "label": "BOL.aptitudes.prot", diff --git a/templates/dialogs/aptitude-roll-dialog.hbs b/templates/dialogs/aptitude-roll-dialog.hbs index 5b207a9..745e1ea 100644 --- a/templates/dialogs/aptitude-roll-dialog.hbs +++ b/templates/dialogs/aptitude-roll-dialog.hbs @@ -7,9 +7,26 @@ - + + {{> "systems/bol/templates/dialogs/attribute-roll-part.hbs"}} + {{> "systems/bol/templates/dialogs/aptitude-roll-part.hbs"}} + {{#if (equals aptitude.key "init" )}} +