54 lines
1.8 KiB
JavaScript
54 lines
1.8 KiB
JavaScript
/* -------------------------------------------- */
|
|
|
|
import { HawkmoonUtility } from "./hawkmoon-utility.js";
|
|
import "./xregexp-all.js";
|
|
|
|
const __level1Expr = '(?<effectType>[a-z]+):(?<objectType>[a-zA-Z]+)\\((?<objectName>[a-zA-Z0-9\\.]+)\\)\\s+(?<modifierValue>[\\d]+)\\s*{*(?<modifierLabel>[a-zA-Zàéè\\s]*)}*'
|
|
const __effectTypes = {modifier: 1, cost: 1, provide: 1}
|
|
|
|
/* -------------------------------------------- */
|
|
export class HawkmoonAutomation {
|
|
|
|
/* -------------------------------------------- */
|
|
static init() {
|
|
this.__objectTypes = { }
|
|
|
|
Object.entries(game.data.model.Actor).forEach(kv => {
|
|
this.__objectTypes[kv[0]] = duplicate(kv[1])
|
|
})
|
|
Object.entries(game.data.model.Item).forEach(kv => {
|
|
this.__objectTypes[kv[0]] = duplicate(kv[1])
|
|
})
|
|
}
|
|
|
|
/* -------------------------------------------- */
|
|
static processAutomations(event, item, actor) {
|
|
//console.log("We have", event, item, actor)
|
|
if ( !item.system.isautomated || item.system.automations.length == 0 ) {
|
|
return {isValid: true}
|
|
}
|
|
let relevantAutomations = item.system.automations.filter( auto => auto.eventtype == event)
|
|
if ( !relevantAutomations || relevantAutomations.length == 0) {
|
|
return {isValid: true}
|
|
}
|
|
|
|
for(let auto of relevantAutomations) {
|
|
console.log(" Script", auto.script)
|
|
try {
|
|
let result = eval(auto.script)
|
|
if (result.isValid) {
|
|
return { isValid: result.isValid, item: duplicate(result) }
|
|
} else {
|
|
if (result.warningMessage) {
|
|
ui.notifications.warn(result.warningMessage)
|
|
}
|
|
}
|
|
}
|
|
catch(error) {
|
|
ui.notifications.error("Erreur lors du processing de l'automation : " + error)
|
|
}
|
|
}
|
|
return {isValid: false}
|
|
}
|
|
|
|
} |