Skip to content

Commit

Permalink
Update for version 9. Minor bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
dwonderley committed Jan 4, 2022
1 parent fb1712e commit 30e8d38
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
4 changes: 2 additions & 2 deletions module.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
"title": "mookAI - An AI for your mooks",
"description": "<p>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.</p><p>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.</p><p>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.</p><p>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.</p><p>Please read the documentation.</p>",
"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"
Expand Down
20 changes: 14 additions & 6 deletions scripts/behaviors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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_)
Expand Down Expand Up @@ -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_);
Expand Down Expand Up @@ -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_)
Expand Down
6 changes: 2 additions & 4 deletions scripts/mookModelSettings.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 30e8d38

Please sign in to comment.