Pet Scripting, Attack Messages, and Attack Frequency#583
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 viaonCommandoronCommand_{cmd}handlers.internal/scripting/pet_func.go—ScriptPettype exposed to JavaScript. Provides read/write access to name, level, food, stat mods, capacity, and item count.internal/scripting/actor_func.go—ScriptActor.GetPet()now returns a*ScriptPetinstead of a raw*pets.Pet, making it consistent with the new scripting wrapper.internal/scripting/schema.go— Addspetscript type to the schema with documented stubs forPetAct,onCommand, andonCommand_{command}.internal/scripting/scripting.go— Registers pet VM cache inPruneVMsandsetAllScriptingFunctions.internal/scripting/memory.go— Minor: includes pet VM in memory tracking.Pet Core
internal/pets/pets.go— AddsRoundActChance intfield (0–100) toPet. AddsGetScriptPath(),HasScript(), andGetScript()helpers.internal/pets/admin.go— AddsSavePetScript(petType, content)to write or remove a pet's.jsfile.DeletePetSpecnow also removes the associated script file.Round Hook
internal/hooks/NewRound_UserRoundTick.go— FiresTryPetScriptEvent("PetAct", uId)each round when the owner is out of combat and the pet'sRoundActChanceroll succeeds.Command Interception
internal/usercommands/usercommands.go— Before normal command dispatch, callsTryPetCommandso a pet script can intercept and optionally consume the command.Admin API
internal/web/api_v1_pets.go— AddsGET /admin/api/v1/pets/{petname}/scriptandPUT /admin/api/v1/pets/{petname}/scriptendpoints.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
.jsscripts and updated.yamldefinitions for the four built-in pets:cat.js/cat.yamldog.js/dog.yamlmule.js/mule.yamlowl.js/owl.yamlDocumentation
_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— UpdatedGetPet()return type.