From 30e8d385592c3e7b72201443ec5c959f85977b5c Mon Sep 17 00:00:00 2001 From: David Wonderley Date: Mon, 3 Jan 2022 19:14:06 -0600 Subject: [PATCH] Update for version 9. Minor bug fix --- module.json | 4 ++-- scripts/behaviors.js | 20 ++++++++++++++------ scripts/mookModelSettings.js | 6 ++---- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/module.json b/module.json index e3435b1..43c932f 100644 --- a/module.json +++ b/module.json @@ -3,9 +3,9 @@ "title": "mookAI - An AI for your mooks", "description": "

The mook is characterizied by a lack of ambition: they must be told where to go, what to do, and when to do it. This module automates those decisions on their behalf, freeing you of managing their doomed efforts.

The scope of this module does not include full automation. It is merely a tool to handle the movement and choices of low-intelligence, low-utility, high-quantity enemies (e.g. goblins, wild animals, barbarians) so that the game master may focus on the Heroes and their true adversaries.

This module adds a hotkey ('g') that, when pressed, triggers this automation. The module finds the token with the current initiative, checks its vision for possible targets, chooses one to attack (or explores if there are none), plans a collission-free path, moves the token into range, attacks, and ends the turn. Mooks will repeat these steps to account for changes in vision and will run until they attack or run out of resources.

In a future release, rules for taking a turn will be customized from a token's actor's character sheet, but for now, settings apply to all tokens.

Please read the documentation.

", "author": "Dave Of Wonders", - "version": "0.2.0", + "version": "0.2.1", "minimumCoreVersion": "0.8.7", - "compatibleCoreVersion": "0.8.7", + "compatibleCoreVersion": "9", "dependencies": [ { "name": "lib-find-the-path" diff --git a/scripts/behaviors.js b/scripts/behaviors.js index 7173198..f79a47e 100644 --- a/scripts/behaviors.js +++ b/scripts/behaviors.js @@ -34,6 +34,14 @@ export const MookTypes = Object.freeze ({ // Attacks highest "armor" }); +export function getMookType (index_) +{ + if (index_ === 0) + return MookTypes.EAGER_BEAVER; + + return MookTypes.SHIA_SURPRISE; +} + export class Target { constructor (token_, range_, action_) @@ -65,22 +73,22 @@ export class Behaviors return Behaviors.attackByDistance (mook_, targets_, false); case (MookTypes.NELSON): return Behaviors.attackByCurrentHealth (mook_, targets_, false); - case (MookTypes.SHIA): + case (MookTypes.SHIA_SURPRISE): return Behaviors.surprise (mook_, targets_); case (MookTypes.VEGETA): return Behaviors.attackByCurrentHealth (mook_, targets_, true); default: console.log ("mookAI | Unsupported mook type!"); - mook_.settings.mookType = MookTypes.SHIA; + mook_.settings.mookType = MookTypes.SHIA_SURPRISE; return Behaviors.surprise (mook_, targets_); } throw "Failed to select a target"; } - static attackByValue (mm_, targets_, evaluator_, min_) + static attackByValue (mm_, targets_, evaluator_, maximize_) { - const comparator = min ? Behaviors.getLargest : Behaviors.getSmallest; + const comparator = maximize_ ? Behaviors.getLargest : Behaviors.getSmallest; const meleToken = comparator (targets_.mele?.map (t => t.token), evaluator_); const rangedToken = comparator (targets_.ranged?.map (t => t.token), evaluator_); @@ -126,8 +134,8 @@ export class Behaviors static attackByCurrentHealth (mook_, targets_, gmTech_) { - const getHealth = mook_.mookModel.getCurrentHealth; - return attackByValue (mook_.mookModel, targets_, getHealth, gmTech_); + const getHealth = mook_.mookModel.getCurrentHealth.bind (mook_.mookModel); + return Behaviors.attackByValue (mook_.mookModel, targets_, getHealth, gmTech_); } static surprise (mook_, targets_) diff --git a/scripts/mookModelSettings.js b/scripts/mookModelSettings.js index fb70c1d..d0998c8 100644 --- a/scripts/mookModelSettings.js +++ b/scripts/mookModelSettings.js @@ -1,4 +1,4 @@ -import { MookTypes } from "./behaviors.js" +import { MookTypes, getMookType } from "./behaviors.js" import { Mook } from "./mook.js"; // Controls what a mook does when their are no viable targets @@ -29,9 +29,7 @@ export class MookModelSettings // todo: Use the token's actor to access individualized mook settings const actor = token_.actor; - this.mookType = MookTypes[settingIndexToString ("mookAI.MookType", "MookType")]; - if (! this.mookType) - this.mookType = MookTypes.SHIA; + this.mookType = getMookType (game.settings.get ("mookAI", "MookType")); // false indicates "do not automate this token" // todo: default false when actor-level configuration is available