luaengine

package
v1.0.8 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package luaengine provides a Lua scripting runtime for the WoW bot, using github.com/Shopify/go-lua. It exposes bot actions and queries to Lua scripts and allows runtime behavior modification.

This is part of github.com/azerothcore/AzerothGhost. Existing script syntax (on_tick, bot.* functions) is preserved.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BotAPI

type BotAPI interface {
	// Movement
	GetPosition() (x, y, z, o float32)
	MoveTo(x, y, z float32) error
	StopMoving() error
	IsMoving() bool

	// Combat
	AttackTarget(guid uint64) error
	StopAttack() error
	SetTarget(guid uint64) error
	CastSpell(spellID uint32, targetGUID uint64) error
	IsSpellReady(spellID uint32) bool
	GetHealth() (current, max uint32)
	GetPower() (current, max uint32)
	GetLevel() uint32
	InCombat() bool
	IsAlive() bool
	GetTargetGUID() uint64

	// Objects
	GetNearbyUnits(maxDist float32) []UnitInfo
	GetNearbyPlayers(maxDist float32) []UnitInfo
	GetUnitInfo(guid uint64) *UnitInfo

	// Actions
	SendChat(message string) error
	SendCommand(command string) error
	SendGuildCommand(command string) error
	Loot(guid uint64) error
	LootAll(guid uint64) error

	// Logging
	Log(format string, args ...interface{})

	// Extended for Lua AI framework (scripts/ai/*)
	GetClass() uint8
	HasAuraOn(guid uint64, spellID uint32) bool
	CanCast(spellID uint32, targetGUID uint64) bool
	GetPetGUID() uint64
	PetAttack(target uint64)
	GetStance() int
	GetOwnGUID() uint64    // own character GUID for faction/self checks
	SetLevel(level uint32) // force level for scenario prep (GM .level may not update internal state immediately)

	GetPowerType() uint8
	IsBehindTarget(targetGUID uint64) bool

	// Facing for proper melee combat (server rejects swings on bad facing / requires facing target)
	GetFacing() float32
	SetFacing(o float32) error
	FaceTarget(guid uint64) bool
	SetSheathed(state uint32) error

	// ValidationMode reports whether the bot is running with heavy validation
	// instrumentation enabled. Must be cheap to call every tick when false.
	// See AZEROTHGHOST_E2E_QUALITY_ASSURANCE_PLAN.md (Performance Isolation section).
	ValidationMode() bool

	// ConsumeTeleport returns true once after a completed near/far teleport
	// (summon, MSG_MOVE_TELEPORT, SMSG_NEW_WORLD). Scripts should interrupt sticky
	// chase/combat state and restart from the new position.
	ConsumeTeleport() bool
}

BotAPI is the interface that the Lua engine uses to interact with the bot.

type Engine

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

Engine wraps a Lua state and provides methods to load/run scripts.

func NewEngine

func NewEngine(bot BotAPI) *Engine

NewEngine creates a new Lua engine bound to the given bot API.

func (*Engine) CallFunction

func (e *Engine) CallFunction(name string) error

CallFunction calls a named global Lua function with no arguments.

func (*Engine) CallFunctionIfExists

func (e *Engine) CallFunctionIfExists(name string) error

CallFunctionIfExists calls a named global Lua function if present. Missing functions are a no-op (used for optional hooks like on_teleport).

func (*Engine) CallTick

func (e *Engine) CallTick() bool

CallTick calls the global on_tick function if it exists. Returns true if the function was found and called.

func (*Engine) Close

func (e *Engine) Close()

Close releases the Lua state.

func (*Engine) DoFile

func (e *Engine) DoFile(path string) error

DoFile loads and executes a Lua file.

func (*Engine) DoString

func (e *Engine) DoString(code string) error

DoString executes Lua code.

func (*Engine) Reload

func (e *Engine) Reload(scriptPath string) error

Reload reinitializes the Lua state and reloads a script file.

func (*Engine) SetTable

func (e *Engine) SetTable(name string, data map[string]any)

SetTable sets a global Lua table from a Go map[string]any (used for AIBundle.Data). Supports scalars (string, bool, numeric) and nested maps. Slices are supported as 1-based indexed tables. Mirrors the NewTable/SetField/Push*/SetField patterns from pushUnitInfo and registerBotFunctions.

func (*Engine) SetTickFunc

func (e *Engine) SetTickFunc(name string)

SetTickFunc sets the name of the Lua function to call on each tick.

type UnitInfo

type UnitInfo struct {
	GUID      uint64
	Entry     uint32
	Health    uint32
	MaxHealth uint32
	Level     uint32
	PosX      float32
	PosY      float32
	PosZ      float32
	IsAlive   bool
	IsPlayer  bool
	Distance  float32
	Name      string
	Faction   uint32
	NPCFlags  uint32
	Flags     uint32
	DynFlags  uint32
	Lootable  bool
}

UnitInfo is a simplified view of a nearby unit passed to Lua.

Jump to

Keyboard shortcuts

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