Enhance forge support

This commit is contained in:
sladecraven 2020-11-07 13:46:15 +01:00
parent 292ff281ac
commit c475762af0
5 changed files with 8384 additions and 41 deletions

View File

@ -1,20 +1,6 @@
/************************************************************************************/
//import WFRP_Tables from "/systems/wfrp4e/modules/system/tables-wfrp4e.js";
//import WFRP4E from "/systems/wfrp4e/modules/system/config-wfrp4e.js";
//import ActorWfrp4e from "/systems/wfrp4e//modules/actor/actor-wfrp4e.js";
import ActorWfrp4e_fr from "./modules/fr-actor-wfrp4e.js"
/************************************************************************************/
/* Override some methods of the WFRP4 actor class, mainly to compute spells/weapons */
/************************************************************************************/ /************************************************************************************/
var compmod = "wfrp4e"; var compmod = "wfrp4e";
Hooks.once('ready', () => {
} );
/************************************************************************************/ /************************************************************************************/
Hooks.once('init', () => { Hooks.once('init', () => {
@ -27,8 +13,130 @@ Hooks.once('init', () => {
//WFRP_Tables = game.wfrp4e.tables; //WFRP_Tables = game.wfrp4e.tables;
//WFRP4E = game.wfrp4e.config; //WFRP4E = game.wfrp4e.config;
CONFIG.Actor.entityClass = ActorWfrp4e_fr; //CONFIG.Actor.entityClass = ActorWfrp4e_fr;
game.wfrp4e.entities.ActorWfrp4e.prototype.calculateRangeOrDamage = function(formula)
{
//console.log("FR function calculateRangeOrDamage !", formula);
let actorData = this.data
try
{
formula = formula.toLowerCase();
// Iterate through characteristics
for(let ch in actorData.data.characteristics)
{
// Determine if the formula includes the characteristic's abbreviation + B (SB, WPB, etc.)
if (formula.includes(ch.concat('b')))
{
// Replace that abbreviation with the Bonus value
formula = formula.replace(ch.concat('b'), actorData.data.characteristics[ch].bonus.toString());
}
}
if (formula.includes("yard") )
formula = formula.replace('yard', "mètre" );
if (formula.includes("yds") )
formula = formula.replace('yds', "m." );
// To evaluate multiplication, replace x with *
formula = formula.replace('x', '*');
return eval(formula);
}
catch
{
return formula
}
}
game.wfrp4e.entities.ActorWfrp4e.prototype.calculateSpellDamage = function(formula, isMagicMissile) {
//console.log("Compute FR")
let actorData = this.data
formula = formula.toLowerCase();
if (isMagicMissile) // If it's a magic missile, damage includes willpower bonus
{
formula += "+ " + actorData.data.characteristics["wp"].bonus
}
// Specific case, to avoid wrong matching with "Force"
if (formula.includes("force mentale"))
{
// Determine if it's looking for the bonus or the value
if (formula.includes('bonus')) {
formula = formula.replace( "bonus de force mentale", actorData.data.characteristics["wp"].bonus);
formula = formula.replace( "force mentale bonus", actorData.data.characteristics["wp"].bonus);
} else
formula = formula.replace("force mentale", actorData.data.characteristics["wp"].value);
}
// Iterate through characteristics
for(let ch in actorData.data.characteristics)
{
// If formula includes characteristic name
while (formula.includes(actorData.data.characteristics[ch].label.toLowerCase()))
{
// Determine if it's looking for the bonus or the value
if (formula.includes('bonus')) {
formula = formula.replace("bonus de " + game.wfrp4e.config.characteristics[ch].toLowerCase(), actorData.data.characteristics[ch].bonus);
formula = formula.replace(game.wfrp4e.config.characteristics[ch].toLowerCase() + " bonus", actorData.data.characteristics[ch].bonus);
}
else
formula = formula.replace(game.wfrp4e.config.characteristics[ch].toLowerCase(), actorData.data.characteristics[ch].value);
}
}
//console.log("calculateSpellDamage -> " + formula );
return eval(formula);
}
game.wfrp4e.entities.ActorWfrp4e.prototype.calculateSpellAttributes = function(formula, aoe=false) {
//console.log("Compute FR")
let actorData = this.data
formula = formula.toLowerCase();
// Do not process these special values
if (formula != game.i18n.localize("You").toLowerCase() && formula != game.i18n.localize("Special").toLowerCase() && formula != game.i18n.localize("Instant").toLowerCase())
{
// Specific case, to avoid wrong matching with "Force"
if (formula.includes("force mentale"))
{
// Determine if it's looking for the bonus or the value
if (formula.includes('bonus')) {
formula = formula.replace( "bonus de force mentale", actorData.data.characteristics["wp"].bonus);
formula = formula.replace( "force mentale bonus", actorData.data.characteristics["wp"].bonus);
}
else
formula = formula.replace("force mentale", actorData.data.characteristics["wp"].value);
}
if (formula.includes("yard") )
formula = formula.replace('yard', "mètre" );
if (formula.includes("yds") )
formula = formula.replace('yds', "m." );
// Iterate through remaining characteristics
for(let ch in actorData.data.characteristics)
{
// If formula includes characteristic name
//console.log("Testing :", ch, WFRP4E.characteristics[ch].toLowerCase());
if (formula.includes(game.wfrp4e.config.characteristics[ch].toLowerCase()))
{
// Determine if it's looking for the bonus or the value
if (formula.includes('bonus')) {
formula = formula.replace("bonus de " + game.wfrp4e.config.characteristics[ch].toLowerCase(), actorData.data.characteristics[ch].bonus);
formula = formula.replace(game.wfrp4e.config.characteristics[ch].toLowerCase() + " bonus", actorData.data.characteristics[ch].bonus);
}
else
formula = formula.replace(game.wfrp4e.config.characteristics[ch].toLowerCase(), actorData.data.characteristics[ch].value);
}
}
}
// If AoE - wrap with AoE ( )
if (aoe)
formula = "AoE (" + formula.capitalize() + ")";
//console.log("calculateSpellAttributes -> " + formula );
return formula.capitalize();
}
console.log("PROTO", game.wfrp4e.entities.ActorWfrp4e.prototype);
// Babele stuff // Babele stuff
if(typeof Babele !== 'undefined') { if(typeof Babele !== 'undefined') {

View File

@ -3,7 +3,7 @@
"name": "WH4-fr-translation", "name": "WH4-fr-translation",
"title": "Traduction du module WH4 en Français.", "title": "Traduction du module WH4 en Français.",
"description": "La traduction du module WH4.", "description": "La traduction du module WH4.",
"version": "1.3.15", "version": "1.3.16",
"minimumCoreVersion" : "0.6.6", "minimumCoreVersion" : "0.6.6",
"compatibleCoreVersion": "1.0.0", "compatibleCoreVersion": "1.0.0",
"author": "LeRatierBretonnien", "author": "LeRatierBretonnien",
@ -20,7 +20,7 @@
"esmodules": [ "esmodules": [
"babele-register.js", "babele-register.js",
"addon-register.js", "addon-register.js",
"modules/fr-actor-wfrp4e.js" "modules/import-stat-2.js"
], ],
"scripts": [ ], "scripts": [ ],
"styles": [], "styles": [],

34
modules/import-stat-2.js Normal file
View File

@ -0,0 +1,34 @@
let str = `JABBERSLYTHE
M WS BS S T I Agi Dex
Int WP Fel W
7 45 40 55
50 20 35 - 10 20 - 20
Traits: Armour 3, Bestial, Bite+9, Bounce, Corrosive
Blood, Distracting, Infected, Maddening Aura (see
page 17), Night Vision, Size (Enormous), Tail +8,
Tongue Attack +5 (12), Venom, Weapon +9.
`;
import "./xregexp-all.js";
const us_carac = 'm\\s+ws\\s+bs\\s+s\\s+t\\s+i\\s+agi?\\s+dex\\s+int\\s+\\wp\\s+fel\\s+w';
const fr_carac = 'm\\s+ws\\s+bs\\s+s\\s+t\\s+i\\s+agi?\\s+dex\\s+int\\s+\\wp\\s+fel\\s+w';
const carac_val = '(?<M>[0-9-]+)\\s+(?<WS>[0-9-]+)\\s+(?<BS>[0-9-]+)\\s+(?<S>[0-9-]+)\\s+(?<T>[0-9-]+)\\s+(?<I>[0-9-]+)\\s+(?<Ag>[0-9-]+)\\s+(?<Dex>[0-9-]+)\\s+(?<Int>[0-9-]+)\\s+(?<WP>[0-9-]+)\\s+(?<Soc>[0-9-]+)\\s+(?<W>[0-9-]+)';
const traits = "Traits:"
Hooks.once('init', () => {
let t1 = "agi";
let reg0 = XRegExp('agi?', 'gi');
//console.log("PARSER pos 1: ", reg0.test( t1 ) );
let reg1 = XRegExp(us_carac, 'gi');
let res = reg1.test(str);
//console.log("PARSER pos 2: ", res);
if (res) { //stat block identified
let reg2 = XRegExp(carac_val, 'gi')
let res = XRegExp.exec(str, reg2);
//console.log("Movement is : ", res);
}
//Do we have Traits ?
})

8225
modules/xregexp-all.js Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long