Skip to content

Pet Scripting, Attack Messages, and Attack Frequency#583

Merged
Volte6 merged 1 commit into
masterfrom
pet-scripting
May 17, 2026
Merged

Pet Scripting, Attack Messages, and Attack Frequency#583
Volte6 merged 1 commit into
masterfrom
pet-scripting

Conversation

@Volte6
Copy link
Copy Markdown
Member

@Volte6 Volte6 commented May 17, 2026

Description

Adds a JavaScript scripting system for pet types, configurable per-round action frequency, and support for custom pet attack messages. Extends the admin UI and API to manage pet scripts, and ships example scripts for the built-in pet types.

Changes

Scripting Engine

  • internal/scripting/pet.go — New pet VM runtime. Manages a per-type VM cache, compiles and runs pet scripts, and exposes two entry points:
    • TryPetScriptEvent(eventName, userId) — fires named events (e.g. PetAct) on the pet's script.
    • TryPetCommand(cmd, rest, userId) — allows pet scripts to intercept owner commands via onCommand or onCommand_{cmd} handlers.
  • internal/scripting/pet_func.goScriptPet type exposed to JavaScript. Provides read/write access to name, level, food, stat mods, capacity, and item count.
  • internal/scripting/actor_func.goScriptActor.GetPet() now returns a *ScriptPet instead of a raw *pets.Pet, making it consistent with the new scripting wrapper.
  • internal/scripting/schema.go — Adds pet script type to the schema with documented stubs for PetAct, onCommand, and onCommand_{command}.
  • internal/scripting/scripting.go — Registers pet VM cache in PruneVMs and setAllScriptingFunctions.
  • internal/scripting/memory.go — Minor: includes pet VM in memory tracking.

Pet Core

  • internal/pets/pets.go — Adds RoundActChance int field (0–100) to Pet. Adds GetScriptPath(), HasScript(), and GetScript() helpers.
  • internal/pets/admin.go — Adds SavePetScript(petType, content) to write or remove a pet's .js file. DeletePetSpec now also removes the associated script file.

Round Hook

  • internal/hooks/NewRound_UserRoundTick.go — Fires TryPetScriptEvent("PetAct", uId) each round when the owner is out of combat and the pet's RoundActChance roll succeeds.

Command Interception

  • internal/usercommands/usercommands.go — Before normal command dispatch, calls TryPetCommand so a pet script can intercept and optionally consume the command.

Admin API

  • internal/web/api_v1_pets.go — Adds GET /admin/api/v1/pets/{petname}/script and PUT /admin/api/v1/pets/{petname}/script endpoints.
  • internal/web/api_routes.go — Registers the two new script routes (ordered before the wildcard {petname} routes).

Admin UI

  • _datafiles/html/admin/pets.html — Script editor panel added to the pet edit page.
  • _datafiles/html/admin/pets-api.html — API documentation updated to include the script endpoints.

Example Pet Scripts

Added .js scripts and updated .yaml definitions for the four built-in pets:

  • cat.js / cat.yaml
  • dog.js / dog.yaml
  • mule.js / mule.yaml
  • owl.js / owl.yaml

Documentation

  • _datafiles/guides/building/scripting/FUNCTIONS_PETS.md — Pet scripting API reference.
  • _datafiles/guides/building/scripting/SCRIPTING_PETS.md — Pet scripting guide.
  • _datafiles/guides/building/scripting/README.md — Updated index to include pet scripting docs.
  • _datafiles/guides/building/scripting/FUNCTIONS_ACTORS.md — Updated GetPet() return type.

@Volte6 Volte6 merged commit 5072ba0 into master May 17, 2026
8 checks passed
@Volte6 Volte6 deleted the pet-scripting branch May 17, 2026 01:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant