scripting

package
v0.9.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 4, 2026 License: MIT Imports: 30 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrEventNotFound = errors.New(`event not found`)
)
View Source
var (
	EventFlags = map[string]events.EventFlag{
		`CmdNone`:                    events.CmdNone,
		`CmdSkipScripts`:             events.CmdSkipScripts,
		`CmdSecretly`:                events.CmdSecretly,
		`CmdIsRequeue`:               events.CmdIsRequeue,
		`CmdBlockInput`:              events.CmdBlockInput,
		`CmdUnBlockInput`:            events.CmdUnBlockInput,
		`CmdBlockInputUntilComplete`: events.CmdBlockInputUntilComplete,
	}
)

Functions

func ActorNames

func ActorNames(actorList []*ScriptActor) string

func AddModlueFunction

func AddModlueFunction(namespace string, name string, funcRef any)

func ClearBuffVMs

func ClearBuffVMs()

func ClearItemVMs

func ClearItemVMs()

func ClearMobVMs

func ClearMobVMs()

func ClearPetVMs added in v0.9.8

func ClearPetVMs()

func ClearRoomVMs

func ClearRoomVMs()

func ClearSpellVMs

func ClearSpellVMs()

func ColorWrap

func ColorWrap(txt string, colorClass ...string) string

func CreateEmptyRoomInstances added in v0.9.8

func CreateEmptyRoomInstances(quantity int) []int

////////////////////////////////////////////////////////

These functions get exported to the scripting engine

////////////////////////////////////////////////////////

func CreateInstancesFromRoomIds

func CreateInstancesFromRoomIds(roomList ...int) map[int]int

func CreateInstancesFromZone

func CreateInstancesFromZone(zoneName string) map[int]int

func ExpandCommand added in v0.9.8

func ExpandCommand(cmd string, limit ...int) string

func GetMap

func GetMap(mapRoomId int, zoomLevel int, mapHeight int, mapWidth int, mapName string, showSecrets bool, mapMarkers ...string) string

mapRoomId - Room the map is centered on mapSize - wide or normal mapHeight - Height of the map mapWidth - Width of the map mapName - The title of the map showSecrets - Include secret exits/rooms? mapMarkers - A list of strings representing custom map markers:

[roomId],[symbol],[legend text]
1,×,Here

func GetMemoryUsage added in v0.9.8

func GetMemoryUsage() map[string]util.MemoryResult

func GetPetSpec added in v0.9.8

func GetPetSpec(petType string) *pets.Pet

GetPetSpec returns the definition for a pet type by name (for scripting helpers).

func InvalidateBuffVM added in v0.9.8

func InvalidateBuffVM(buffId int)

InvalidateBuffVM removes the cached VM for a buff spec so the next call reloads the script from disk. Call this after saving a buff script via the admin API.

func InvalidateItemVM added in v0.9.8

func InvalidateItemVM(itemId int)

InvalidateItemVM removes the cached VM for an item spec so the next call reloads the script from disk. Call this after saving an item script via the admin API.

func InvalidateMobVM added in v0.9.8

func InvalidateMobVM(mobTypeId int, scriptTag string)

InvalidateMobVM removes the cached VM for a specific mob type + script tag combination. Use this when a script file has been updated for a mob that uses a non-default script tag.

func InvalidateMobVMById added in v0.9.8

func InvalidateMobVMById(mobTypeId int)

InvalidateMobVMById removes all cached VMs for the given mob type ID, regardless of script tag. This is the correct call after saving a mob script via the admin API because the tag is not known at that point.

func InvalidatePetVM added in v0.9.8

func InvalidatePetVM(petType string)

InvalidatePetVM removes the cached VM for a given pet type so the next call reloads the script from disk. Called after SavePetScript.

func InvalidateRoomVM added in v0.9.8

func InvalidateRoomVM(roomId int)

InvalidateRoomVM removes the cached VM for a room so the next call reloads the script from disk. Call this after saving a room script via the admin API.

func InvalidateSpellVM added in v0.9.8

func InvalidateSpellVM(spellId string)

InvalidateSpellVM removes the cached VM for a spell so the next call reloads the script from disk. Call this after saving a spell script via the admin API.

func PruneBuffVMs

func PruneBuffVMs(instanceIds ...int)

PruneBuffVMs is intentionally a no-op. Buff VMs are keyed by buff spec ID and are not tied to any instance lifecycle.

func PruneItemVMs

func PruneItemVMs(instanceIds ...int)

PruneItemVMs is intentionally a no-op. Item VMs are keyed by item spec ID and are not tied to any instance lifecycle.

func PruneMobVMs

func PruneMobVMs(instanceIds ...int)

PruneMobVMs is intentionally a no-op. Mob VMs are keyed by mob type ID and script tag, not by instance ID, so there is no per-instance lifecycle to prune. Use ClearMobVMs to evict all mob VMs at once.

func PrunePetVMs added in v0.9.8

func PrunePetVMs(petTypes ...string)

func PruneRoomVMs

func PruneRoomVMs(roomIds ...int)

func PruneSpellVMs

func PruneSpellVMs(instanceIds ...int)

PruneSpellVMs is intentionally a no-op. Spell VMs are keyed by spell ID and are not tied to any instance lifecycle.

func PruneVMs

func PruneVMs(forceClear ...bool)

func RaiseEvent

func RaiseEvent(name string, data map[string]any)

func RandInt added in v0.9.8

func RandInt(min int, max int) int

func SendBroadcast

func SendBroadcast(message string)

func SendRoomExitsMessage

func SendRoomExitsMessage(roomId int, message string, isQuiet bool, excludeUserIds ...int)

func SendRoomMessage

func SendRoomMessage(roomId int, message string, excludeIds ...int)

func SendUserMessage

func SendUserMessage(userId int, message string)

func SetHotReload added in v0.9.8

func SetHotReload(enabled bool)

SetHotReload enables or disables mtime-based script hot-reload. When enabled, each VM lookup checks whether the script file on disk is newer than the cached VM and reloads automatically if so.

func Setup

func Setup(scriptLoadTimeoutMs int, scriptRoomTimeoutMs int)

func TryBuffCommand

func TryBuffCommand(cmd string, rest string, userId int, mobInstanceId int, buffId int) (bool, error)

func TryBuffScriptEvent

func TryBuffScriptEvent(eventName string, userId int, mobInstanceId int, buffId int) (bool, error)

func TryItemCommand

func TryItemCommand(cmd string, item items.Item, userId int) (bool, error)

func TryItemScriptEvent

func TryItemScriptEvent(eventName string, item items.Item, userId int) (bool, error)

func TryItemTryPurchaseEvent added in v0.9.8

func TryItemTryPurchaseEvent(item items.Item, userId int) (bool, error)

func TryMobCommand

func TryMobCommand(cmd string, rest string, mobInstanceId int, sourceId int, sourceType string) (bool, error)

func TryMobScriptEvent

func TryMobScriptEvent(eventName string, mobInstanceId int, sourceId int, sourceType string, details map[string]any) (bool, error)

func TryPetCommand added in v0.9.8

func TryPetCommand(cmd string, rest string, userId int) (bool, error)

TryPetCommand checks whether the pet script intercepts a command typed by its owner.

func TryPetScriptEvent added in v0.9.8

func TryPetScriptEvent(eventName string, userId int) (bool, error)

TryPetScriptEvent fires a named event on the pet script (e.g. "onCommand", "PetAct"). userId is the owner of the pet.

func TryPlayerDownedEvent

func TryPlayerDownedEvent(mobInstanceId int, downedPlayerId int) (bool, error)

func TryRoomCommand

func TryRoomCommand(cmd string, rest string, userId int) (bool, error)

func TryRoomIdleEvent

func TryRoomIdleEvent(roomId int) (bool, error)

func TryRoomScriptEvent

func TryRoomScriptEvent(eventName string, userId int, roomId int) (bool, error)

func TryRoomTryEnterEvent added in v0.9.8

func TryRoomTryEnterEvent(userId int, destRoomId int) (bool, error)

func TryRoomTryExitEvent added in v0.9.8

func TryRoomTryExitEvent(exitName string, userId int, roomId int) (bool, error)

func TrySpellScriptEvent

func TrySpellScriptEvent(eventName string, sourceUserId int, sourceMobInstanceId int, spellAggro characters.SpellAggroInfo) (bool, error)

func UtilApplyColorPattern

func UtilApplyColorPattern(input string, patternName string, wordsOnly ...bool) string

func UtilDiceRoll

func UtilDiceRoll(diceQty int, diceSides int) int

func UtilFindMatchIn

func UtilFindMatchIn(search string, items []string) map[string]any

func UtilGetConfig

func UtilGetConfig() configs.Config

func UtilGetMinutesToRounds

func UtilGetMinutesToRounds(minutes int) int

func UtilGetMinutesToTurns

func UtilGetMinutesToTurns(minutes int) int

func UtilGetRoundNumber

func UtilGetRoundNumber() uint64

////////////////////////////////////////////////////////

These functions get exported to the scripting engine

////////////////////////////////////////////////////////

func UtilGetSecondsToRounds

func UtilGetSecondsToRounds(seconds int) int

func UtilGetSecondsToTurns

func UtilGetSecondsToTurns(seconds int) int

func UtilGetTime

func UtilGetTime() gametime.GameDate

func UtilGetTimeString

func UtilGetTimeString() string

func UtilIsDay

func UtilIsDay() bool

func UtilLocateUser

func UtilLocateUser(idOrName any) int

func UtilSetTime

func UtilSetTime(hour int, minutes int)

func UtilSetTimeDay

func UtilSetTimeDay()

func UtilSetTimeNight

func UtilSetTimeNight()

func UtilStripPrepositions

func UtilStripPrepositions(input string) string

Types

type DynamicName added in v0.9.8

type DynamicName struct {
	Placeholder string `json:"placeholder"`
	Label       string `json:"label"`
	Description string `json:"description"`
	InputType   string `json:"inputType"`
}

type EngineGlobalFuncDef added in v0.9.8

type EngineGlobalFuncDef struct {
	Name            string            `json:"name"`
	Description     string            `json:"description"`
	Params          []ScriptFuncParam `json:"params"`
	ReturnType      string            `json:"returnType,omitempty"`
	ReturnSemantics string            `json:"returnSemantics,omitempty"`
}

type ParamVariant added in v0.9.8

type ParamVariant struct {
	Type        string `json:"type"`
	Description string `json:"description"`
}

type ScriptActor

type ScriptActor struct {
	// contains filtered or unexported fields
}

func GetActor

func GetActor(userId int, mobInstanceId int) *ScriptActor

////////////////////////////////////////////////////////

These functions get exported to the scripting engine

////////////////////////////////////////////////////////

func GetMob

func GetMob(mobInstanceId int) *ScriptActor

func GetUser

func GetUser(userId int) *ScriptActor

func (ScriptActor) AddEventLog

func (a ScriptActor) AddEventLog(category string, message string)

func (ScriptActor) AddGold

func (a ScriptActor) AddGold(amt int, bankAmt ...int)

func (ScriptActor) AddHealth

func (a ScriptActor) AddHealth(amt int) int

func (ScriptActor) AddMana

func (a ScriptActor) AddMana(amt int) int

func (ScriptActor) ApplyFormChange added in v0.9.8

func (a ScriptActor) ApplyFormChange(raceId int) bool

func (ScriptActor) CancelBuffWithFlag

func (a ScriptActor) CancelBuffWithFlag(buffFlag string) bool

func (ScriptActor) ChangeAlignment

func (a ScriptActor) ChangeAlignment(alignmentChange int)

func (ScriptActor) CharmExpire

func (a ScriptActor) CharmExpire()

func (ScriptActor) CharmRemove

func (a ScriptActor) CharmRemove()

func (ScriptActor) CharmSet

func (a ScriptActor) CharmSet(userId int, charmRounds int, onRevertCommand ...string)

func (ScriptActor) Command

func (a ScriptActor) Command(cmd string, waitSeconds ...float64)

func (ScriptActor) CommandFlagged

func (a ScriptActor) CommandFlagged(cmd string, flags events.EventFlag, waitSeconds ...float64)

func (ScriptActor) GetAlignment

func (a ScriptActor) GetAlignment() int

func (ScriptActor) GetAlignmentName

func (a ScriptActor) GetAlignmentName() string

func (ScriptActor) GetBackpackItems

func (a ScriptActor) GetBackpackItems() []ScriptItem

func (ScriptActor) GetChanceToTame

func (a ScriptActor) GetChanceToTame(target ScriptActor) int

func (ScriptActor) GetCharacterName

func (a ScriptActor) GetCharacterName(wrapInTags bool) string

func (ScriptActor) GetCharmCount

func (a ScriptActor) GetCharmCount() int

func (ScriptActor) GetCharmedUserId

func (a ScriptActor) GetCharmedUserId() int

func (ScriptActor) GetHealth

func (a ScriptActor) GetHealth() int

func (ScriptActor) GetHealthMax

func (a ScriptActor) GetHealthMax() int

func (ScriptActor) GetHealthPct

func (a ScriptActor) GetHealthPct() float64

func (ScriptActor) GetLastInputRound

func (a ScriptActor) GetLastInputRound() uint64

func (ScriptActor) GetLevel

func (a ScriptActor) GetLevel() int

func (ScriptActor) GetMana

func (a ScriptActor) GetMana() int

func (ScriptActor) GetManaMax

func (a ScriptActor) GetManaMax() int

func (ScriptActor) GetManaPct

func (a ScriptActor) GetManaPct() float64

func (ScriptActor) GetMaxCharmCount

func (a ScriptActor) GetMaxCharmCount() int

func (ScriptActor) GetMiscCharacterData

func (a ScriptActor) GetMiscCharacterData(key string) any

func (ScriptActor) GetMiscCharacterDataKeys

func (a ScriptActor) GetMiscCharacterDataKeys(prefixMatches ...string) []string

func (ScriptActor) GetMobKills

func (a ScriptActor) GetMobKills(mobId int) int

func (ScriptActor) GetParty added in v0.9.8

func (a ScriptActor) GetParty(excludeSelf ...bool) ScriptParty

Gets a party object that indexes ALL members of the party

func (ScriptActor) GetPartyMissing added in v0.9.8

func (a ScriptActor) GetPartyMissing() ScriptParty

Gets a party object that indexes only members NOT in the same room.

func (ScriptActor) GetPartyPresent added in v0.9.8

func (a ScriptActor) GetPartyPresent(excludeSelf ...bool) ScriptParty

Gets a party object that indexes only party members in the same room

func (ScriptActor) GetPet

func (a ScriptActor) GetPet() *ScriptPet

func (ScriptActor) GetRace

func (a ScriptActor) GetRace() string

func (ScriptActor) GetRaceKills

func (a ScriptActor) GetRaceKills(race string) int

func (ScriptActor) GetRoomId

func (a ScriptActor) GetRoomId() int

func (ScriptActor) GetSize

func (a ScriptActor) GetSize() string

func (ScriptActor) GetSkillLevel

func (a ScriptActor) GetSkillLevel(skillName string) int

func (ScriptActor) GetStat

func (a ScriptActor) GetStat(statName string) int

func (ScriptActor) GetStatMod

func (a ScriptActor) GetStatMod(statModName string) int

func (ScriptActor) GetStatPoints

func (a ScriptActor) GetStatPoints() int

func (ScriptActor) GetTameMastery

func (a ScriptActor) GetTameMastery() map[int]int

func (ScriptActor) GetTempData

func (a ScriptActor) GetTempData(key string) any

func (ScriptActor) GetTrainingPoints

func (a ScriptActor) GetTrainingPoints() int

func (ScriptActor) GetTrueRace added in v0.9.8

func (a ScriptActor) GetTrueRace() string

func (ScriptActor) GiveBuff

func (a ScriptActor) GiveBuff(buffId int, source string)

func (ScriptActor) GiveExtraLife

func (a ScriptActor) GiveExtraLife()

func (ScriptActor) GiveItem

func (a ScriptActor) GiveItem(itm any)

func (ScriptActor) GiveQuest

func (a ScriptActor) GiveQuest(questId string)

func (ScriptActor) GiveStatPoints

func (a ScriptActor) GiveStatPoints(ct int)

func (ScriptActor) GiveTrainingPoints

func (a ScriptActor) GiveTrainingPoints(ct int)

func (ScriptActor) GrantXP

func (a ScriptActor) GrantXP(xpAmt int, reason string)

func (ScriptActor) HasBuff

func (a ScriptActor) HasBuff(buffId int) bool

func (ScriptActor) HasBuffFlag

func (a ScriptActor) HasBuffFlag(buffFlag string) bool

func (ScriptActor) HasItemId

func (a ScriptActor) HasItemId(itemId int, excludeWorn ...bool) bool

func (ScriptActor) HasQuest

func (a ScriptActor) HasQuest(questId string) bool

func (ScriptActor) HasSpell

func (a ScriptActor) HasSpell(spellId string) bool

func (ScriptActor) InstanceId

func (a ScriptActor) InstanceId() int

func (ScriptActor) IsAggro

func (a ScriptActor) IsAggro(actor ScriptActor) bool

func (ScriptActor) IsCharmed

func (a ScriptActor) IsCharmed(userId ...int) bool

Returns true if a mob is charmed by/friendly to a player. If userId is ommitted, it will return true if the mob is charmed by any player.

func (ScriptActor) IsFormChanged added in v0.9.8

func (a ScriptActor) IsFormChanged() bool

func (ScriptActor) IsHome

func (a ScriptActor) IsHome() bool

func (ScriptActor) IsTameable

func (a ScriptActor) IsTameable() bool

func (ScriptActor) LearnSpell

func (a ScriptActor) LearnSpell(spellId string) bool

func (ScriptActor) MarkVisitedRoom added in v0.9.8

func (a ScriptActor) MarkVisitedRoom(roomIds ...int)

MarkVisitedRoom marks one or more rooms as visited for this actor. Only applies to user actors; mobs do not track room visits. Each roomId argument is recorded under the zone that room belongs to.

func (ScriptActor) MarkVisitedZone added in v0.9.8

func (a ScriptActor) MarkVisitedZone(zoneName string)

MarkVisitedZone marks every room in the named zone as visited for this actor. Only applies to user actors; mobs do not track room visits. Uses FindZoneName for partial/best-match zone name resolution.

func (ScriptActor) MobTypeId

func (a ScriptActor) MobTypeId() int

func (ScriptActor) MoveRoom

func (a ScriptActor) MoveRoom(destRoomId int)

func (ScriptActor) Pathing

func (a ScriptActor) Pathing() bool

func (ScriptActor) PathingAtWaypoint

func (a ScriptActor) PathingAtWaypoint() bool

func (ScriptActor) PlayMusic added in v0.9.8

func (a ScriptActor) PlayMusic(musicFileOrId string)

PlayMusic sends a music-change event to this actor. Only affects user actors. musicFileOrId may be a filepath (e.g. "static/audio/music/intro.mp3") or a sound identifier from audio.yaml whose filepath resolves to a music file. Pass "Off" to stop music.

func (ScriptActor) PlaySound added in v0.9.8

func (a ScriptActor) PlaySound(soundId string, category string)

PlaySound sends a sound event to this actor. Only affects user actors. soundId is the identifier defined in audio.yaml (e.g. "levelup"). category groups related sounds for client-side volume control (e.g. "combat", "other").

func (ScriptActor) RemoveBuff

func (a ScriptActor) RemoveBuff(buffId int) bool

Remove a buff silently

func (ScriptActor) RevertFormChange added in v0.9.8

func (a ScriptActor) RevertFormChange() bool

func (ScriptActor) SendText

func (a ScriptActor) SendText(msg string)

func (ScriptActor) SetAdjective

func (a ScriptActor) SetAdjective(adj string, addIt bool)

func (ScriptActor) SetCharacterName

func (a ScriptActor) SetCharacterName(newName string)

func (ScriptActor) SetHealth

func (a ScriptActor) SetHealth(amt int)

func (ScriptActor) SetMiscCharacterData

func (a ScriptActor) SetMiscCharacterData(key string, value any)

func (ScriptActor) SetResetRoomId added in v0.9.8

func (a ScriptActor) SetResetRoomId(roomId int)

func (ScriptActor) SetTameMastery

func (a ScriptActor) SetTameMastery(mobId int, newSkillLevel int)

func (ScriptActor) SetTempData

func (a ScriptActor) SetTempData(key string, value any)

func (ScriptActor) ShorthandId

func (a ScriptActor) ShorthandId() string

func (ScriptActor) Sleep

func (a ScriptActor) Sleep(seconds int)

func (ScriptActor) TakeItem

func (a ScriptActor) TakeItem(itm ScriptItem)

func (ScriptActor) TimerExists

func (a ScriptActor) TimerExists(name string) bool

func (ScriptActor) TimerExpired

func (a ScriptActor) TimerExpired(name string) bool

func (ScriptActor) TimerSet

func (a ScriptActor) TimerSet(name string, period string)

func (ScriptActor) TrainSkill

func (a ScriptActor) TrainSkill(skillName string, skillLevel int) bool

func (ScriptActor) Uncurse

func (a ScriptActor) Uncurse() []*ScriptItem

func (ScriptActor) UpdateItem

func (a ScriptActor) UpdateItem(itm ScriptItem)

func (ScriptActor) UserId

func (a ScriptActor) UserId() int

type ScriptContainer added in v0.9.8

type ScriptContainer struct {
	// contains filtered or unexported fields
}

ScriptContainer wraps a named container in a room, providing scripting access to its contents, lock state, and gold.

func (ScriptContainer) AddGold added in v0.9.8

func (c ScriptContainer) AddGold(amount int)

func (ScriptContainer) AddItem added in v0.9.8

func (c ScriptContainer) AddItem(itm ScriptItem) bool

func (ScriptContainer) Count added in v0.9.8

func (c ScriptContainer) Count(itemId int) int

func (ScriptContainer) FindItem added in v0.9.8

func (c ScriptContainer) FindItem(itemName string) *ScriptItem

func (ScriptContainer) GetGold added in v0.9.8

func (c ScriptContainer) GetGold() int

func (ScriptContainer) GetItems added in v0.9.8

func (c ScriptContainer) GetItems() []ScriptItem

func (ScriptContainer) HasLock added in v0.9.8

func (c ScriptContainer) HasLock() bool

func (ScriptContainer) IsLocked added in v0.9.8

func (c ScriptContainer) IsLocked() bool

func (ScriptContainer) IsTemporary added in v0.9.8

func (c ScriptContainer) IsTemporary() bool

func (ScriptContainer) Lock added in v0.9.8

func (c ScriptContainer) Lock()

func (ScriptContainer) Name added in v0.9.8

func (c ScriptContainer) Name() string

func (ScriptContainer) RemoveGold added in v0.9.8

func (c ScriptContainer) RemoveGold(amount int) int

func (ScriptContainer) RemoveItem added in v0.9.8

func (c ScriptContainer) RemoveItem(itm ScriptItem) bool

func (ScriptContainer) Unlock added in v0.9.8

func (c ScriptContainer) Unlock()

type ScriptFuncDef added in v0.9.8

type ScriptFuncDef struct {
	Name            string            `json:"name"`
	Description     string            `json:"description"`
	Params          []ScriptFuncParam `json:"params"`
	ReturnSemantics string            `json:"returnSemantics"`
	ExtendedTimeout bool              `json:"extendedTimeout"`
	Dynamic         *DynamicName      `json:"dynamic"`
	Stub            string            `json:"stub"`
}

type ScriptFuncParam added in v0.9.8

type ScriptFuncParam struct {
	Name         string                   `json:"name"`
	Type         string                   `json:"type"`
	Description  string                   `json:"description"`
	TypeVariants map[string]*ParamVariant `json:"typeVariants,omitempty"`
}

type ScriptFunctionsSchema added in v0.9.8

type ScriptFunctionsSchema struct {
	Version         int                       `json:"version"`
	ScriptTypes     map[string]*ScriptTypeDef `json:"scriptTypes"`
	EngineFunctions []EngineGlobalFuncDef     `json:"engineFunctions"`
}

func GetScriptFunctionsSchema added in v0.9.8

func GetScriptFunctionsSchema() *ScriptFunctionsSchema

type ScriptItem

type ScriptItem struct {
	// contains filtered or unexported fields
}

func CreateItem

func CreateItem(itemId int) *ScriptItem

CreateItem creates a NEW instance of an item by id

func GetItem

func GetItem(i items.Item) *ScriptItem

Converts an item into a ScriptItem for use in the scripting engine

func (ScriptItem) AddUsesLeft

func (i ScriptItem) AddUsesLeft(amount int) int

func (ScriptItem) GetLastUsedRound

func (i ScriptItem) GetLastUsedRound() uint64

func (ScriptItem) GetTempData

func (i ScriptItem) GetTempData(key string) any

func (ScriptItem) GetUsesLeft

func (i ScriptItem) GetUsesLeft() int

func (ScriptItem) ItemId

func (i ScriptItem) ItemId() int

func (ScriptItem) MarkLastUsed

func (i ScriptItem) MarkLastUsed(clear ...bool) uint64

func (ScriptItem) Name

func (i ScriptItem) Name(simpleVersion ...bool) string

func (ScriptItem) NameComplex

func (i ScriptItem) NameComplex() string

func (ScriptItem) NameSimple

func (i ScriptItem) NameSimple() string

func (ScriptItem) Redescribe

func (i ScriptItem) Redescribe(newDescription string)

func (ScriptItem) Rename

func (i ScriptItem) Rename(newName string, displayNameOrStyle ...string)

func (ScriptItem) SetTempData

func (i ScriptItem) SetTempData(key string, value any)

func (ScriptItem) SetUsesLeft

func (i ScriptItem) SetUsesLeft(amount int) int

func (ScriptItem) ShorthandId

func (i ScriptItem) ShorthandId() string

type ScriptPanel added in v0.9.8

type ScriptPanel struct {
	// contains filtered or unexported fields
}

ScriptPanel is the script-facing wrapper for a Panel.

func (*ScriptPanel) Add added in v0.9.8

func (p *ScriptPanel) Add(fullLabel, shortLabel, value string) *ScriptPanel

Add appends a label+value row to the panel. fullLabel is used when it fits; shortLabel is the fallback. Returns the panel for chaining.

func (*ScriptPanel) AddBlank added in v0.9.8

func (p *ScriptPanel) AddBlank() *ScriptPanel

AddBlank appends an empty spacer row. Returns the panel for chaining.

func (*ScriptPanel) AddWithWrapWidth added in v0.9.8

func (p *ScriptPanel) AddWithWrapWidth(fullLabel, shortLabel, value string, wrapWidth int) *ScriptPanel

AddWithWrapWidth appends a label+value row with a maximum value wrap width. When the value's visual width exceeds wrapWidth, it is wrapped onto continuation lines indented to align with the value column of the first line. Returns the panel for chaining.

func (*ScriptPanel) SetCharset added in v0.9.8

func (p *ScriptPanel) SetCharset(name string) *ScriptPanel

SetCharset overrides the border character set for this panel. Accepts a named preset ("single", "double", "rounded") or an 8-rune literal string in the order: TopLeft, HorizontalTop, TopRight, VerticalLeft, VerticalRight, BottomLeft, HorizontalBottom, BottomRight. Example: "\u2554\u2550\u2557\u2551\u2502\u255a\u2500\u2518". If not called, the panel uses the layout-level charset. Returns the panel for chaining.

func (*ScriptPanel) SetColumnGap added in v0.9.8

func (p *ScriptPanel) SetColumnGap(n int) *ScriptPanel

SetColumnGap sets the spaces between columns when columns > 1. Returns the panel for chaining.

func (*ScriptPanel) SetColumns added in v0.9.8

func (p *ScriptPanel) SetColumns(n int) *ScriptPanel

SetColumns sets the number of label+value pairs per line (1 or 2). Returns the panel for chaining.

func (*ScriptPanel) SetLabelWidth added in v0.9.8

func (p *ScriptPanel) SetLabelWidth(w int) *ScriptPanel

SetLabelWidth sets a fixed visual width that all labels are padded to. When non-zero, values always start at the same column regardless of label length. Returns the panel for chaining.

func (*ScriptPanel) SetTitle added in v0.9.8

func (p *ScriptPanel) SetTitle(title string) *ScriptPanel

SetTitle sets the panel's title string (used verbatim in the top border). May contain ANSI tags; visual width is measured with tags stripped. Returns the panel for chaining.

func (*ScriptPanel) SetWidth added in v0.9.8

func (p *ScriptPanel) SetWidth(w int) *ScriptPanel

SetWidth sets the panel's total border-inclusive width. The panel will target this exact outer width and wrap values to fit within it. The panel will expand beyond this width only when a label+value pair cannot fit. Returns the panel for chaining.

type ScriptPanelLayout added in v0.9.8

type ScriptPanelLayout struct {
	// contains filtered or unexported fields
}

ScriptPanelLayout is the script-facing wrapper for a PanelLayout.

func PanelLayoutLoad added in v0.9.8

func PanelLayoutLoad(name string) *ScriptPanelLayout

PanelLayoutLoad loads a panel layout from the datafiles panel-layouts directory. name is relative to panel-layouts/ and has no extension. Example: PanelLayoutLoad("character/status") Returns a ScriptPanelLayout on success, or throws a JavaScript error on failure.

func PanelLayoutNew added in v0.9.8

func PanelLayoutNew(opts ...map[string]any) *ScriptPanelLayout

PanelLayoutNew creates a panel layout entirely in script, without a YAML file. opts is an optional JS object with any of: border, charset, gap, margin.

Example:

var layout = PanelLayoutNew({ border: "full", charset: "rounded", gap: 1, margin: 1 });
var slot = layout.AddSlot();
slot.AddRow(["myPanel"]);
layout.Panel("myPanel").SetTitle(' <ansi fg="20">Stats</ansi> ').SetWidth(34);
layout.Panel("myPanel").Add("Str:", "S:", "42");
SendText(layout.Render());

func (*ScriptPanelLayout) AddSlot added in v0.9.8

func (l *ScriptPanelLayout) AddSlot() *ScriptPanelSlot

AddSlot adds a new vertical slot (column) to the layout and returns a ScriptPanelSlot for adding rows of panels into it.

func (*ScriptPanelLayout) Panel added in v0.9.8

func (l *ScriptPanelLayout) Panel(id string) *ScriptPanel

Panel returns the named panel for data population. Panics with a descriptive message if the id does not exist.

func (*ScriptPanelLayout) Render added in v0.9.8

func (l *ScriptPanelLayout) Render() string

Render synthesizes the layout into a terminal string.

type ScriptPanelSlot added in v0.9.8

type ScriptPanelSlot struct {
	// contains filtered or unexported fields
}

ScriptPanelSlot is the script-facing wrapper for a layout slot.

func (*ScriptPanelSlot) AddRow added in v0.9.8

func (s *ScriptPanelSlot) AddRow(ids []string) *ScriptPanelSlot

AddRow adds a horizontal row of panels to this slot. ids is an array of panel IDs to create in this row. Each panel is created with default settings; use layout.Panel(id) to configure it. Returns the slot for chaining.

Example:

slot.AddRow(["info", "stats"]);

type ScriptParty added in v0.9.8

type ScriptParty struct {
	// contains filtered or unexported fields
}

func (ScriptParty) AddEventLog added in v0.9.8

func (p ScriptParty) AddEventLog(category string, message string)

func (ScriptParty) AddGold added in v0.9.8

func (p ScriptParty) AddGold(amt int, bankAmt ...int)

func (ScriptParty) AddHealth added in v0.9.8

func (p ScriptParty) AddHealth(amt int)

func (ScriptParty) AddMana added in v0.9.8

func (p ScriptParty) AddMana(amt int)

func (ScriptParty) CancelBuffWithFlag added in v0.9.8

func (p ScriptParty) CancelBuffWithFlag(buffFlag string)

func (ScriptParty) ChangeAlignment added in v0.9.8

func (p ScriptParty) ChangeAlignment(alignmentChange int)

func (ScriptParty) Command added in v0.9.8

func (p ScriptParty) Command(cmd string, waitSeconds ...float64)

func (ScriptParty) GetMembers added in v0.9.8

func (p ScriptParty) GetMembers() []ScriptActor

GetMembers() is the core feature of this, everything works off of it.

func (ScriptParty) GiveBuff added in v0.9.8

func (p ScriptParty) GiveBuff(buffId int, source string)

func (ScriptParty) GiveExtraLife added in v0.9.8

func (p ScriptParty) GiveExtraLife()

func (ScriptParty) GiveQuest added in v0.9.8

func (p ScriptParty) GiveQuest(questId string)

func (ScriptParty) GiveStatPoints added in v0.9.8

func (p ScriptParty) GiveStatPoints(ct int)

func (ScriptParty) GiveTrainingPoints added in v0.9.8

func (p ScriptParty) GiveTrainingPoints(ct int)

func (ScriptParty) GrantXP added in v0.9.8

func (p ScriptParty) GrantXP(xpAmt int, reason string)

func (ScriptParty) LearnSpell added in v0.9.8

func (p ScriptParty) LearnSpell(spellId string)

func (ScriptParty) MarkVisitedRoom added in v0.9.8

func (p ScriptParty) MarkVisitedRoom(roomIds ...int)

func (ScriptParty) MarkVisitedZone added in v0.9.8

func (p ScriptParty) MarkVisitedZone(zoneName string)

func (ScriptParty) MoveRoom added in v0.9.8

func (p ScriptParty) MoveRoom(destRoomId int)

func (ScriptParty) RemoveBuff added in v0.9.8

func (p ScriptParty) RemoveBuff(buffId int)

func (ScriptParty) SendText added in v0.9.8

func (p ScriptParty) SendText(msg string)

func (ScriptParty) SetAdjective added in v0.9.8

func (p ScriptParty) SetAdjective(adj string, addIt bool)

func (ScriptParty) SetHealth added in v0.9.8

func (p ScriptParty) SetHealth(amt int)

func (ScriptParty) SetResetRoomId added in v0.9.8

func (p ScriptParty) SetResetRoomId(roomId int)

func (ScriptParty) TimerSet added in v0.9.8

func (p ScriptParty) TimerSet(name string, period string)

func (ScriptParty) TrainSkill added in v0.9.8

func (p ScriptParty) TrainSkill(skillName string, skillLevel int)

type ScriptPet added in v0.9.8

type ScriptPet struct {
	// contains filtered or unexported fields
}

ScriptPet wraps a live pet record and exposes it to the scripting engine. The underlying record is a pointer into the owner's character data, so mutations are reflected immediately without any extra save call.

func GetPet added in v0.9.8

func GetPet(pet *pets.Pet, userId ...int) *ScriptPet

GetPet returns a ScriptPet wrapping the given pet pointer. Returns nil if pet is nil or does not exist. Pass the owner's userId as the optional second argument to enable script-triggered events such as GoMissing.

func (ScriptPet) Feed added in v0.9.8

func (p ScriptPet) Feed()

Feed increases the pet's hunger level by one step, up to a maximum of 3 (Full). Has no effect if the pet is already full.

func (ScriptPet) Food added in v0.9.8

func (p ScriptPet) Food() string

Food returns the pet's current hunger level as a string: "Starving" (0), "Hungry" (1), "Satisfied" (2), or "Full" (3).

func (ScriptPet) FoodLevel added in v0.9.8

func (p ScriptPet) FoodLevel() int

FoodLevel returns the pet's raw hunger value: 0 (starving) through 3 (full).

func (ScriptPet) GetCapacity added in v0.9.8

func (p ScriptPet) GetCapacity() int

GetCapacity returns the number of items the pet can carry at its current level. Returns 0 if the pet type has no carry ability.

func (ScriptPet) GetStatMod added in v0.9.8

func (p ScriptPet) GetStatMod(statName string) int

GetStatMod returns the effective stat modifier the pet currently grants its owner for the named stat (e.g. "strength", "speed", "smarts"). Returns 0 if the pet has no modifier for that stat at its current level.

func (ScriptPet) GoMissing added in v0.9.8

func (p ScriptPet) GoMissing(rounds int)

GoMissing causes the pet to go absent for the given number of rounds. Pass 0 to return the pet immediately, firing PetReturn instead of PetLeave. Any positive value fires PetLeave and begins the countdown.

func (ScriptPet) HasScript added in v0.9.8

func (p ScriptPet) HasScript() bool

HasScript returns true if this pet type has a script file on disk.

func (ScriptPet) IsMissing added in v0.9.8

func (p ScriptPet) IsMissing() bool

IsMissing returns true if the pet is currently absent (MissingCountdown > 0).

func (ScriptPet) ItemCount added in v0.9.8

func (p ScriptPet) ItemCount() int

ItemCount returns the number of items the pet is currently carrying.

func (ScriptPet) Level added in v0.9.8

func (p ScriptPet) Level() int

Level returns the pet's current level (1–10).

func (ScriptPet) Name added in v0.9.8

func (p ScriptPet) Name() string

Name returns the pet's display name, including ANSI colour tags and any hunger indicator. Use NameSimple() when you only need the plain text name.

func (ScriptPet) NameSimple added in v0.9.8

func (p ScriptPet) NameSimple() string

NameSimple returns the plain text name of the pet with no colour tags or hunger indicator. Falls back to the type identifier if no name has been set.

func (ScriptPet) SetName added in v0.9.8

func (p ScriptPet) SetName(name string)

SetName renames the pet. Pass an empty string to clear a custom name and revert to the type identifier.

func (ScriptPet) Starve added in v0.9.8

func (p ScriptPet) Starve()

Starve decreases the pet's hunger level by one step, down to a minimum of 0 (Starving). Has no effect if the pet is already starving.

func (ScriptPet) Type added in v0.9.8

func (p ScriptPet) Type() string

Type returns the pet's type identifier (e.g. "dog", "cat", "owl").

type ScriptRoom

type ScriptRoom struct {
	// contains filtered or unexported fields
}

func GetRoom

func GetRoom(roomId int) *ScriptRoom

func (ScriptRoom) AddMutator

func (r ScriptRoom) AddMutator(mutName string)

func (ScriptRoom) AddTemporaryExit

func (r ScriptRoom) AddTemporaryExit(exitNameSimple string, exitNameFancy string, exitRoomId int, expiresTimeString string) bool

func (ScriptRoom) DestroyItem

func (r ScriptRoom) DestroyItem(itm ScriptItem)

func (ScriptRoom) GetAllActors

func (r ScriptRoom) GetAllActors() []*ScriptActor

func (ScriptRoom) GetContainers

func (r ScriptRoom) GetContainers() []ScriptContainer

func (ScriptRoom) GetExits

func (r ScriptRoom) GetExits() []map[string]any

func (ScriptRoom) GetItems

func (r ScriptRoom) GetItems() []ScriptItem

func (ScriptRoom) GetMob

func (r ScriptRoom) GetMob(mobId int, createIfMissing ...bool) *ScriptActor

Get the first mob of the MobId type provided.

func (ScriptRoom) GetMobs

func (r ScriptRoom) GetMobs(mobId ...int) []*ScriptActor

Optionally can provide a MobId to look for

func (ScriptRoom) GetPermData

func (r ScriptRoom) GetPermData(key string) any

func (ScriptRoom) GetPlayers

func (r ScriptRoom) GetPlayers() []*ScriptActor

func (ScriptRoom) GetStashItems added in v0.9.8

func (r ScriptRoom) GetStashItems() []ScriptItem

func (ScriptRoom) GetTempData

func (r ScriptRoom) GetTempData(key string) any

func (ScriptRoom) HasMutator

func (r ScriptRoom) HasMutator(mutName string) bool

func (ScriptRoom) HasQuest

func (r ScriptRoom) HasQuest(questId string, partyUserId ...int) []int

Returns a list of userIds found to have the questId if userIdParty is specified, will only check users in the party of the user.

func (ScriptRoom) HasTag added in v0.9.8

func (r ScriptRoom) HasTag(tag string) bool

func (ScriptRoom) IsEphemeral

func (r ScriptRoom) IsEphemeral() bool

func (ScriptRoom) IsLocked

func (r ScriptRoom) IsLocked(exitName string) bool

func (ScriptRoom) MissingQuest

func (r ScriptRoom) MissingQuest(questId string, partyUserId ...int) []int

Returns a list of userIds found to NOT have the questId if userIdParty is specified, will only check users in the party of the user.

func (ScriptRoom) PlaySound added in v0.9.8

func (r ScriptRoom) PlaySound(soundId string, category string, excludeUserIds ...int)

PlaySound plays a sound for all players currently in the room. soundId is the identifier defined in audio.yaml (e.g. "room-enter"). category groups related sounds for client-side volume control (e.g. "combat", "movement"). Optional excludeUserIds are user IDs that should NOT receive the sound.

func (ScriptRoom) RemoveMutator

func (r ScriptRoom) RemoveMutator(mutName string)

func (ScriptRoom) RemoveTemporaryExit

func (r ScriptRoom) RemoveTemporaryExit(exitNameSimple string, exitNameFancy string, exitRoomId int) bool

func (ScriptRoom) RepeatSpawnItem

func (r ScriptRoom) RepeatSpawnItem(itemId int, roundFrequency int, containerName ...string) bool

func (ScriptRoom) RoomId

func (r ScriptRoom) RoomId() int

func (ScriptRoom) RoomIdSource

func (r ScriptRoom) RoomIdSource() int

func (ScriptRoom) SendText

func (r ScriptRoom) SendText(msg string, excludeIds ...int)

func (ScriptRoom) SendTextToExits

func (r ScriptRoom) SendTextToExits(msg string, isQuiet bool, excludeUserIds ...int)

func (ScriptRoom) SetLocked

func (r ScriptRoom) SetLocked(exitName string, lockIt bool)

func (ScriptRoom) SetPermData

func (r ScriptRoom) SetPermData(key string, value any)

func (ScriptRoom) SetTag added in v0.9.8

func (r ScriptRoom) SetTag(tag string)

func (ScriptRoom) SetTempData

func (r ScriptRoom) SetTempData(key string, value any)

func (ScriptRoom) SpawnItem

func (r ScriptRoom) SpawnItem(itemId int, inStash bool)

func (ScriptRoom) SpawnMob

func (r ScriptRoom) SpawnMob(mobId int) *ScriptActor

func (ScriptRoom) UnsetTag added in v0.9.8

func (r ScriptRoom) UnsetTag(tag string)

type ScriptTypeDef added in v0.9.8

type ScriptTypeDef struct {
	Label       string          `json:"label"`
	Description string          `json:"description"`
	Functions   []ScriptFuncDef `json:"functions"`
}

type TextWrapperStyle

type TextWrapperStyle struct {
	Fg           string // ansi class name for foreground
	Bg           string // ansi class name for background
	ColorPattern string // optional color pattern
	// contains filtered or unexported fields
}

func (*TextWrapperStyle) AnsiClass

func (t *TextWrapperStyle) AnsiClass() string

func (*TextWrapperStyle) Empty

func (t *TextWrapperStyle) Empty() bool

func (*TextWrapperStyle) Reset

func (t *TextWrapperStyle) Reset()

func (*TextWrapperStyle) Set

func (t *TextWrapperStyle) Set(fg string, bg string, colorpattern string, colorStyle ...colorpatterns.ColorizeStyle)

func (*TextWrapperStyle) Wrap

func (t *TextWrapperStyle) Wrap(str string) string

type VMWrapper

type VMWrapper struct {
	VM *goja.Runtime
	// contains filtered or unexported fields
}

func (*VMWrapper) GetFunction

func (vmw *VMWrapper) GetFunction(name string) (goja.Callable, bool)

type ValidationResult added in v0.9.8

type ValidationResult struct {
	Valid  bool   `json:"valid"`
	Error  string `json:"error,omitempty"`
	Line   int    `json:"line,omitempty"`
	Column int    `json:"column,omitempty"`
}

func ValidateScript added in v0.9.8

func ValidateScript(source string, script string) ValidationResult

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL