fvtt-hawkmoon-cyd/modules/hawkmoon-automation.js

52 lines
1.6 KiB
JavaScript
Raw Normal View History

2022-10-28 21:44:49 +02:00
/* -------------------------------------------- */
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 => {
2024-05-02 09:27:16 +02:00
this.__objectTypes[kv[0]] = foundry.utils.duplicate(kv[1])
2022-10-28 21:44:49 +02:00
})
Object.entries(game.data.model.Item).forEach(kv => {
2024-05-02 09:27:16 +02:00
this.__objectTypes[kv[0]] = foundry.utils.duplicate(kv[1])
2022-10-28 21:44:49 +02:00
})
}
/* -------------------------------------------- */
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}
}
2022-11-09 23:39:55 +01:00
let validTab = []
2022-10-28 21:44:49 +02:00
for(let auto of relevantAutomations) {
2022-11-09 23:39:55 +01:00
if ( event == "on-drop") {
validTab.push( actor.checkAttributOrCompetenceLevel( auto.competence, auto.minLevel) )
}
}
// Post process validation array
for (let ret of validTab) {
if ( !ret.isValid) {
return ret
2022-10-28 21:44:49 +02:00
}
}
2022-11-09 23:39:55 +01:00
return {isValid: true}
2022-10-28 21:44:49 +02:00
}
}