Talents automation + management
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
*/
|
||||
|
||||
import { HawkmoonUtility } from "./hawkmoon-utility.js";
|
||||
import { HawkmoonRollDialog } from "./hawkmoon-roll-dialog.js";
|
||||
import { HawkmoonAutomation } from "./hawkmoon-automation.js";
|
||||
|
||||
/* -------------------------------------------- */
|
||||
export class HawkmoonActorSheet extends ActorSheet {
|
||||
@@ -149,11 +149,18 @@ export class HawkmoonActorSheet extends ActorSheet {
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
/*async _onDropItem(event, dragData) {
|
||||
let item = await HawkmoonUtility.searchItem( dragData)
|
||||
this.actor.preprocessItem( event, item, true )
|
||||
super._onDropItem(event, dragData)
|
||||
}*/
|
||||
async _onDropItem(event, dragData) {
|
||||
let data = event.dataTransfer.getData('text/plain')
|
||||
let dataItem = JSON.parse( data)
|
||||
let item = fromUuidSync(dataItem.uuid)
|
||||
if (item.pack) {
|
||||
item = await HawkmoonUtility.searchItem(item)
|
||||
}
|
||||
let autoresult = HawkmoonAutomation.processAutomations("on-drop", item, this.actor)
|
||||
if ( autoresult.isValid ) {
|
||||
super._onDropItem(event, dragData)
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
/** @override */
|
||||
|
@@ -98,7 +98,7 @@ export class HawkmoonActor extends Actor {
|
||||
return this.items.find(item => item.type == "profil")
|
||||
}
|
||||
getTalents() {
|
||||
return this.items.find(item => item.type == "talent")
|
||||
return this.items.filter(item => item.type == "talent")
|
||||
}
|
||||
/* -------------------------------------------- */
|
||||
getSkills() {
|
||||
@@ -219,6 +219,30 @@ export class HawkmoonActor extends Actor {
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
checkAttribut(attribut, minLevel) {
|
||||
let attr = this.system.attributs.find( at => at.labelnorm == attribut.toLowerCase() )
|
||||
if (attr && attr.value >= minLevel) {
|
||||
return {isValid: true, attr: duplicate(attr) }
|
||||
}
|
||||
return {isValid: false}
|
||||
}
|
||||
/* -------------------------------------------- */
|
||||
checkCompetenceLevel(compName, minLevel) {
|
||||
let comp = this.items.find(i => i.type == "competence" && i.name.toLowerCase() == compName.toLowerCase() && i.system.niveau >= minLevel)
|
||||
if ( comp) {
|
||||
return {isValid: true, item: duplicate(comp) }
|
||||
}
|
||||
return {isValid: false, warningMessage: `Prérequis insuffisant : la compétence ${compName} doit être de niveau ${minLevel} au minimum`}
|
||||
}
|
||||
/* -------------------------------------------- */
|
||||
checkIfCompetence( compName ) {
|
||||
let comp = this.items.find(i => i.type == "competence" && i.name.toLowerCase() == compName.toLowerCase())
|
||||
if ( comp) {
|
||||
return {isValid: true, item: comp}
|
||||
}
|
||||
return {isValid: false }
|
||||
}
|
||||
/* -------------------------------------------- */
|
||||
getBonneAventure() {
|
||||
return this.system.bonneaventure.actuelle
|
||||
@@ -344,6 +368,24 @@ export class HawkmoonActor extends Actor {
|
||||
return bestArme
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
searchRelevantTalents(competence) {
|
||||
let talents = []
|
||||
|
||||
for( let talent of this.items) {
|
||||
if (talent.type == "talent" && talent.system.isautomated && talent.system.automations.length > 0) {
|
||||
for (let auto of talent.system.automations) {
|
||||
if (auto.eventtype === "associated-competence") {
|
||||
if (auto.script.toLowerCase() == competence.name.toLowerCase() ) {
|
||||
talents.push( talent)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return talents
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
getCommonRollData(attrKey = undefined, compId = undefined, compName = undefined) {
|
||||
let rollData = HawkmoonUtility.getBasicRollData()
|
||||
@@ -366,7 +408,8 @@ export class HawkmoonActor extends Actor {
|
||||
if (compId) {
|
||||
rollData.competence = duplicate(this.items.get(compId) || {})
|
||||
rollData.maitrises = rollData.competence.system.predilections.filter(p => p.maitrise )
|
||||
rollData.actionImg = rollData.competence?.img
|
||||
rollData.actionImg = rollData.competence?.img
|
||||
rollData.talents = this.searchRelevantTalents( rollData.competence)
|
||||
}
|
||||
if (compName) {
|
||||
rollData.competence = duplicate(this.items.find( item => item.name.toLowerCase() == compName.toLowerCase()) || {})
|
||||
|
54
modules/hawkmoon-automation.js
Normal file
54
modules/hawkmoon-automation.js
Normal file
@@ -0,0 +1,54 @@
|
||||
/* -------------------------------------------- */
|
||||
|
||||
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}
|
||||
}
|
||||
|
||||
}
|
@@ -1,40 +0,0 @@
|
||||
/* -------------------------------------------- */
|
||||
|
||||
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 HawkmoonEffectParser {
|
||||
|
||||
/* -------------------------------------------- */
|
||||
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 parseEffectString(effectString) {
|
||||
let parse1 = XRegExp.exec(effectString, XRegExp(__level1Expr, 'gi'))
|
||||
if (parse1.effectType && __effectTypes[parse1.effectType.toLowerCase()]) {
|
||||
parse1.effectType = parse1.effectType.toLowerCase()
|
||||
if ( parse1.objectType && this.__objectTypes[parse1.objectType.toLowerCase()] ) {
|
||||
parse1.objectType = parse1.objectType.toLowerCase()
|
||||
console.log("Level 1 parsing : ", parse1, Object.keys(__effectTypes) )
|
||||
} else {
|
||||
ui.notifications.warn("EffectParser : Le type d'objet est inconnu. Les valeurs valides sont : " + Object.keys(this.__objectTypes).toString() )
|
||||
}
|
||||
} else {
|
||||
ui.notifications.warn("EffectParser : Le type d'effet est inconnu. Les valeurs valides sont : " + Object.keys(__effectTypes).toString() )
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -144,8 +144,7 @@ export class HawkmoonItemSheet extends ItemSheet {
|
||||
pred[index].description = ev.currentTarget.value
|
||||
pred[index].id = pred[index].id || randomID(16)
|
||||
this.object.update( { 'system.predilections': pred })
|
||||
})
|
||||
|
||||
})
|
||||
html.find('.predilection-acquise').change(ev => {
|
||||
const li = $(ev.currentTarget).parents(".prediction-item")
|
||||
let index = li.data("prediction-index")
|
||||
@@ -153,8 +152,7 @@ export class HawkmoonItemSheet extends ItemSheet {
|
||||
pred[index].acquise = ev.currentTarget.checked
|
||||
pred[index].id = pred[index].id || randomID(16)
|
||||
this.object.update( { 'system.predilections': pred })
|
||||
})
|
||||
|
||||
})
|
||||
html.find('.predilection-maitrise').change(ev => {
|
||||
const li = $(ev.currentTarget).parents(".prediction-item")
|
||||
let index = li.data("prediction-index")
|
||||
@@ -172,6 +170,11 @@ export class HawkmoonItemSheet extends ItemSheet {
|
||||
this.object.update( { 'system.predilections': pred })
|
||||
})
|
||||
|
||||
html.find('#add-predilection').click(ev => {
|
||||
let pred = duplicate(this.object.system.predilections)
|
||||
pred.push( { name: "Nouvelle prédilection", id: randomID(16), used: false })
|
||||
this.object.update( { 'system.predilections': pred })
|
||||
})
|
||||
html.find('.delete-prediction').click(ev => {
|
||||
const li = $(ev.currentTarget).parents(".prediction-item")
|
||||
let index = li.data("prediction-index")
|
||||
@@ -180,11 +183,28 @@ export class HawkmoonItemSheet extends ItemSheet {
|
||||
this.object.update( { 'system.predilections': pred })
|
||||
})
|
||||
|
||||
html.find('#add-predilection').click(ev => {
|
||||
let pred = duplicate(this.object.system.predilections)
|
||||
pred.push( { name: "Nouvelle prédilection", id: randomID(16), used: false })
|
||||
this.object.update( { 'system.predilections': pred })
|
||||
html.find('#add-automation').click(ev => {
|
||||
let autom = duplicate(this.object.system.automations)
|
||||
autom.push( { eventtype: "on-drop", name: "Automatisation 1", script: "", id: randomID(16) })
|
||||
this.object.update( { 'system.automations': autom })
|
||||
})
|
||||
html.find('.delete-automation').click(ev => {
|
||||
const li = $(ev.currentTarget).parents(".automation-item")
|
||||
let index = li.data("automation-index")
|
||||
let autom = duplicate(this.object.system.automations)
|
||||
autom.splice(index,1)
|
||||
this.object.update( { 'system.automations': autom })
|
||||
})
|
||||
html.find('.automation-edit-field').change(ev => {
|
||||
const li = $(ev.currentTarget).parents(".automation-item")
|
||||
let index = li.data("automation-index")
|
||||
let field = li.data("automation-field")
|
||||
let auto = duplicate(this.object.system.automations)
|
||||
auto[index][field] = ev.currentTarget.value
|
||||
auto[index].id = auto[index].id || randomID(16)
|
||||
this.object.update( { 'system.automations': auto })
|
||||
})
|
||||
|
||||
// Update Inventory Item
|
||||
html.find('.item-delete').click(ev => {
|
||||
const li = $(ev.currentTarget).parents(".item");
|
||||
|
@@ -14,7 +14,7 @@ import { HawkmoonActorSheet } from "./hawkmoon-actor-sheet.js";
|
||||
import { HawkmoonUtility } from "./hawkmoon-utility.js";
|
||||
import { HawkmoonCombat } from "./hawkmoon-combat.js";
|
||||
import { HawkmoonItem } from "./hawkmoon-item.js";
|
||||
import { HawkmoonEffectParser } from "./hawkmoon-effect-parser.js";
|
||||
import { HawkmoonAutomation } from "./hawkmoon-automation.js";
|
||||
|
||||
/* -------------------------------------------- */
|
||||
/* Foundry VTT Initialization */
|
||||
@@ -47,7 +47,7 @@ Hooks.once("init", async function () {
|
||||
CONFIG.Item.documentClass = HawkmoonItem
|
||||
game.system.hawkmoon = {
|
||||
HawkmoonUtility,
|
||||
HawkmoonEffectParser
|
||||
HawkmoonAutomation
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
@@ -60,7 +60,7 @@ Hooks.once("init", async function () {
|
||||
Items.registerSheet("fvtt-hawkmoon-cyd", HawkmoonItemSheet, { makeDefault: true })
|
||||
|
||||
HawkmoonUtility.init()
|
||||
HawkmoonEffectParser.init()
|
||||
HawkmoonAutomation.init()
|
||||
|
||||
});
|
||||
|
||||
|
@@ -68,6 +68,9 @@ export class HawkmoonRollDialog extends Dialog {
|
||||
})
|
||||
html.find('#select-maitrise').change(async (event) => {
|
||||
this.rollData.maitriseId = String(event.currentTarget.value)
|
||||
})
|
||||
})
|
||||
html.find('#competence-talents').change((event) => {
|
||||
this.rollData.selectedTalents = $('#competence-talents').val()
|
||||
})
|
||||
}
|
||||
}
|
@@ -314,24 +314,25 @@ export class HawkmoonUtility {
|
||||
rollData.predilections = duplicate(rollData.competence.system.predilections.filter(pred => pred.acquise && !pred.maitrise && !pred.used) || [])
|
||||
let compmod = (rollData.competence.system.niveau == 0) ? -3 : 0
|
||||
rollData.diceFormula += `+${rollData.attr.value}+${rollData.competence.system.niveau}+${rollData.modificateur}+${compmod}`
|
||||
|
||||
if ( rollData.selectedTalents && rollData.selectedTalents.length > 0) {
|
||||
for (let id of rollData.selectedTalents) {
|
||||
let talent = actor.items.find(t => t.id == id)
|
||||
let bonus = talent.system.automations.find( a => a.eventtype == "roll-bonus")
|
||||
if (bonus) {
|
||||
rollData.diceFormula += `+${bonus.value}`
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
rollData.diceFormula += `+${rollData.attr.value}*2+${rollData.modificateur}`
|
||||
}
|
||||
|
||||
|
||||
if (rollData.arme && rollData.arme.type == "arme") {
|
||||
rollData.diceFormula += `+${rollData.arme.system.bonusmaniementoff}`
|
||||
}
|
||||
|
||||
if (rollData.rune) {
|
||||
rollData.runeduree = Math.ceil((rollData.runeame + 3) / 3)
|
||||
if (rollData.runemode == "inscrire") {
|
||||
rollData.runeduree *= 2
|
||||
}
|
||||
if (rollData.runemode == "prononcer") {
|
||||
rollData.runeduree = 1
|
||||
}
|
||||
}
|
||||
|
||||
let myRoll = new Roll(rollData.diceFormula).roll({ async: false })
|
||||
await this.showDiceSoNice(myRoll, game.settings.get("core", "rollMode"))
|
||||
rollData.roll = myRoll
|
||||
@@ -395,9 +396,11 @@ export class HawkmoonUtility {
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static async searchItem(dataItem) {
|
||||
let item;
|
||||
let item
|
||||
if (dataItem.pack) {
|
||||
item = await fromUuid("Compendium." + dataItem.pack + "." + dataItem.id);
|
||||
let id = dataItem.id || dataItem._id
|
||||
let items = await this.loadCompendium(dataItem.pack, item => item.id == id)
|
||||
item = items[0] || undefined
|
||||
} else {
|
||||
item = game.items.get(dataItem.id)
|
||||
}
|
||||
|
Reference in New Issue
Block a user