@ -17,12 +17,20 @@ const XREGEXP_COMP_CREATURE = WHITESPACES + "(?<carac>\\d+)"
// Skill parser depending on the type of actor
const compParser = {
//personnage: "(\\D+)*" + WHITESPACES + NUMERIC_VALUE,
personnage : WHITESPACES + NUMERIC _VALUE ,
personnage : "(\\s+\\((?<special>[^\\)]+)\\))?(,\\s*\\p{Letter}+)*(\\s+(?<malus>avec armure))?" + WHITESPACES + NUMERIC _VALUE ,
creature : XREGEXP _COMP _CREATURE ,
entite : XREGEXP _COMP _CREATURE
}
const MANIEMENTS = {
'de lancer' : ( weapon ) => { return { name : weapon . system . lancer , categorie : 'lancer' } } ,
'de jet' : ( weapon ) => { return { name : weapon . system . lancer , categorie : 'lancer' } } ,
'à une main' : ( weapon ) => { return { name : weapon . system . competence , categorie : 'melee' } } ,
'à deux main' : ( weapon ) => { return { name : weapon . system . competence . replace ( "à 1 main" , "à 2 main" ) , categorie : 'melee' } } ,
'mêlée' : ( weapon ) => { return { name : weapon . system . competence , categorie : 'melee' } } ,
}
const XREGEXP _WEAPON _MANIEMENT = "(?<maniement>(" + Misc . join ( Object . keys ( MANIEMENTS ) , '|' ) + "))"
const XREGEXP _SORT _VOIE = "(?<voies>[OHNT](\\/[OHNT])*)"
const XREGEXP _SORT _NAME = "(?<name>[^\\(]+)"
const XREGEXP _SORT _CASE = "\\((?<case>([A-Za-zÀ-ÖØ-öø-ÿ\\s\\-]+|[A-M]\\d{1,2})+)\\)" ;
@ -110,7 +118,7 @@ export class RdDStatBlockParser {
name = name . replace ( "Voie d'" , "" ) ;
name = name . replace ( "Voie de " , "" ) ;
return name
}
}
static async parseStatBlock ( statString ) {
@ -134,6 +142,9 @@ export class RdDStatBlockParser {
// Now start carac
let actorData = foundry . utils . deepClone ( game . model . Actor [ type ] ) ;
let items = [ ] ;
actorData . flags = { hautRevant : false , malusArmure : 0 }
for ( let key in actorData . carac ) {
let caracDef = actorData . carac [ key ] ;
// Parse the stat string for each caracteristic
@ -152,17 +163,49 @@ export class RdDStatBlockParser {
RdDStatBlockParser . parseEntite ( statString , actorData )
break
}
if ( type == "personnage" ) {
// Now process armors
await RdDStatBlockParser . parseArmors ( statString , actorData , items ) ;
}
let items = [ ] ;
// Get skills from compendium
await RdDStatBlockParser . parseCompetences ( type , statString , actorData , items ) ;
if ( type == "personnage" ) {
// Now process weapons
await RdDStatBlockParser . parseWeapons ( statString , items ) ;
await RdDStatBlockParser . parseHautReve ( statString , actorData , items ) ;
RdDStatBlockParser . parsePersonnage ( statString , actorData ) ;
}
const name = RdDStatBlockParser . extractName ( type , statString ) ;
actorData . flags = undefined
console . log ( actorData ) ;
let newActor = await RdDBaseActorReve . create ( { name , type , system : actorData , items } ) ;
await newActor . remiseANeuf ( )
await RdDStatBlockParser . setValeursActuelles ( newActor , statString )
await newActor ? . sheet . render ( true )
}
static async parseCompetences ( type , statString , actorData , items ) {
const competences = await SystemCompendiums . getCompetences ( type ) ;
//console.log("Competences : ", competences);
for ( let comp of competences ) {
let compNameToSearch = RdDStatBlockParser . fixCompName ( comp . name )
let compMatch = XRegExp . exec ( statString , XRegExp ( compNameToSearch + compParser [ type ] , 'giu' ) ) ;
let compNameToSearch = RdDStatBlockParser . fixCompName ( comp . name ) ;
let compMatch = XRegExp . exec ( statString , XRegExp ( "\\s" + compNameToSearch + compParser [ type ] , 'giu' ) ) ;
if ( compMatch ) {
comp = comp . toObject ( )
comp . system . niveau = Number ( compMatch . value ) ;
comp . system . niveau = Number ( compMatch . value )
if ( compMatch . malus ) {
comp . system . niveau = Number ( compMatch . value ) - actorData . flags . malusArmure
}
if ( comp . system . categorie == 'draconic' && comp . system . niveau > - 11 ) {
actorData . flags . hautRevant = true
}
if ( type == "creature" || type == "entite" ) {
comp . system . carac _value = Number ( compMatch . carac ) ;
if ( compMatch . dommages != undefined ) {
@ -170,74 +213,71 @@ export class RdDStatBlockParser {
comp . system . iscombat = true ;
}
}
items . push ( comp )
items . push ( comp ) ;
}
else if ( type == "personnage" ) {
comp = comp . toObject ( )
items . push ( comp )
comp = comp . toObject ( ) ;
items . push ( comp ) ;
}
}
}
// Now process weapons
const weapons = await SystemCompendiums . getWorldOrCompendiumItems ( "arme" , "equipement" )
//console.log("Equipement : ", equipment);
// TODO: les noms d'armes peuvent avoir un suffixe (à une main, lancée) qui détermine la compétence correspondante
// TODO: une arme peut être spécifique ("fourche"), ajouter une compétence dans ces cas là?
for ( let weapon of weapons ) {
let weapMatch = XRegExp . exec ( statString , XRegExp ( weapon . name + "\\s+(?<value>\\+\\d+)" , 'giu' ) ) ;
if ( weapMatch ) {
weapon = weapon . toObject ( )
weapon . system . equipe = 'true'
items . push ( weapon )
// now process the skill
if ( weapon . system ? . competence != "" ) {
let wComp = items . find ( i => Grammar . equalsInsensitive ( i . name , weapon . system . competence ) )
if ( wComp ) {
wComp . system . niveau = Number ( weapMatch . value ) ;
}
}
if ( weapon . system ? . tir != "" ) {
let wComp = items . find ( i => Grammar . equalsInsensitive ( i . name , weapon . system . tir ) )
if ( wComp ) {
wComp . system . niveau = Number ( weapMatch . value ) ;
}
}
if ( weapon . system ? . lancer != "" ) {
let wComp = items . find ( i => Grammar . equalsInsensitive ( i . name , weapon . system . lancer ) )
if ( wComp ) {
wComp . system . niveau = Number ( weapMatch . value ) ;
}
}
}
}
// Now process armors
const armors = await SystemCompendiums . getWorldOrCompendiumItems ( "armure" , "equipement" )
static async parseArmors ( statString , actorData , items ) {
const armors = await SystemCompendiums . getWorldOrCompendiumItems ( "armure" , "equipement" ) ;
for ( let armor of armors ) {
let matchArmor = XRegExp . exec ( statString , XRegExp ( armor . name , 'giu' ) ) ;
if ( matchArmor ) {
armor = armor . toObject ( )
armor . system . equipe = true
items . push ( armor ) ;
actorData . flags . malusArmure = armor . system . malus
items . push ( armor )
break
}
}
if ( type == "personnage" ) {
await RdDStatBlockParser . parseHautReve ( statString , actorData , items ) ;
RdDStatBlockParser . parsePersonnage ( statString , actorData ) ;
}
let name = RdDStatBlockParser . extractName ( type , statString ) ;
let newActor = await RdDBaseActorReve . create ( { name , type : type , system : actorData , items } ) ;
await newActor . remiseANeuf ( )
await RdDStatBlockParser . setValActuelle ( newActor , statString )
// DUmp....
console . log ( actorData ) ;
}
static async setValActuelle ( newActor , statString ) {
static async parseWeapons ( statString , items ) {
const weapons = await SystemCompendiums . getWorldOrCompendiumItems ( "arme" , "equipement" ) ;
//console.log("Equipement : ", equipment);
// TODO: les noms d'armes peuvent avoir un suffixe (à une main, lancée) qui détermine la compétence correspondante
// TODO: une arme peut être spécifique ("fourche"), ajouter une compétence dans ces cas là?
for ( let weapon of weapons ) {
let nomArmeManiement = XRegExp . exec ( weapon . name , XRegExp ( ".*" + XREGEXP _WEAPON _MANIEMENT ) ) ;
if ( nomArmeManiement ) {
continue // ignore les objets 'Dague de jet" ou "dague mêlée"
}
let weapMatch = XRegExp . exec ( statString , XRegExp ( weapon . name
+ "(\\s*" + XREGEXP _WEAPON _MANIEMENT + ")?"
+ "\\s+(?<value>\\+\\d+)" , 'giu' ) ) ;
if ( weapMatch ) {
weapon = weapon . toObject ( ) ;
weapon . system . equipe = 'true' ;
items . push ( weapon ) ;
const niveau = Number ( weapMatch . value ) ;
// now process the skill
if ( weapMatch ? . maniement ) {
RdDStatBlockParser . setNiveauCompetenceArme ( items , MANIEMENTS [ weapMatch . maniement ] ( weapon ) , niveau )
}
else {
RdDStatBlockParser . setNiveauCompetenceArme ( items , { name : weapon . system . competence , categorie : 'melee' } , niveau )
RdDStatBlockParser . setNiveauCompetenceArme ( items , { name : weapon . system . tir , categorie : 'tir' } , niveau )
RdDStatBlockParser . setNiveauCompetenceArme ( items , { name : weapon . system . lancer , categorie : 'lancer' } , niveau )
}
}
}
}
static setNiveauCompetenceArme ( items , competence , niveau ) {
if ( competence != "" ) {
const item = items . find ( i => i . system . categorie == competence . categorie && Grammar . equalsInsensitive ( i . name , competence . name ) )
if ( item ) {
item . system . niveau = niveau
}
}
}
static async setValeursActuelles ( newActor , statString ) {
const updates = {
}
const endurance = XRegExp . exec ( statString , XRegExp ( "endurance\\s+(?<value>\\d+)\\s+(\\(actuelle\\s*:\\s+(?<actuelle>\\d+)\\))?" , 'giu' ) ) ;
@ -263,7 +303,6 @@ export class RdDStatBlockParser {
}
static async parseHautReve ( statString , actorData , items ) {
let hautRevant = false ;
// Attemp to detect spell
let sorts = await SystemCompendiums . getWorldOrCompendiumItems ( "sort" , "sorts-oniros" ) ;
sorts = sorts . concat ( await SystemCompendiums . getWorldOrCompendiumItems ( "sort" , "sorts-hypnos" ) ) ;
@ -275,7 +314,7 @@ export class RdDStatBlockParser {
const sortName = Grammar . toLowerCaseNoAccent ( matchSort . name ) . trim ( ) . replace ( "’ " , "'" ) ;
let sort = sorts . find ( s => Grammar . toLowerCaseNoAccent ( s . name ) == sortName )
if ( sort ) {
hautRevant = true ;
actorData. flags . hautRevant = true
sort = sort . toObject ( ) ;
if ( matchSort . bonus && matchSort . bonuscase ) {
sort . system . bonuscase = ` ${ matchSort . bonuscase } : ${ matchSort . bonus } ` ;
@ -287,7 +326,7 @@ export class RdDStatBlockParser {
}
} ) ;
if ( hautRevant) {
if ( actorData. flags . hautRevant) {
const donHR = await RdDItemTete . teteDonDeHautReve ( ) ;
if ( donHR ) {
items . push ( donHR . toObject ( ) ) ;
@ -322,7 +361,7 @@ export class RdDStatBlockParser {
actorData . taille = taille . value ;
}
// Get weight
const poids = XRegExp . exec ( statString , XRegExp ( "(?<value>\\d+ ) kg", 'giu' ) ) ;
const poids = XRegExp . exec ( statString , XRegExp ( "(?<value>\\d+ kg) ", 'giu' ) ) ;
if ( poids ? . value ) {
actorData . poids = poids . value ;
}
@ -387,7 +426,7 @@ export class RdDStatBlockParser {
case "personnage" :
// Check if ',né le' is present
let namePersonnage = "Importé"
if ( statString . includes ( ", né" ) ) {
if ( statString . includes ( ", né" ) ) {
// Name is all string before first comma ','
namePersonnage = XRegExp . exec ( statString , XRegExp ( "(?<value>[\\p{Letter}\\s\\d]+)," , 'giu' ) ) ;
} else {