bot

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: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bot

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

Bot implements the WoW client bot logic with behavior tree AI.

func NewBot

func NewBot(id string, config Config) *Bot

NewBot creates a new bot

func NewHeadlessBot

func NewHeadlessBot(wc *client.WorldClient, cfg Config) *Bot

NewHeadlessBot creates a bot attached to an already-authenticated and logged-in WorldClient. It skips auth/char creation/login and the optional DB pre-setup. Useful for integration tests and library use. The caller is responsible for maintaining the WorldClient lifecycle.

func (*Bot) AttackTarget

func (b *Bot) AttackTarget(guid uint64) error

func (*Bot) CanCast

func (b *Bot) CanCast(spellID uint32, targetGUID uint64) bool

func (*Bot) CastSpell

func (b *Bot) CastSpell(spellID uint32, targetGUID uint64) error

func (*Bot) ConsumeTeleport

func (b *Bot) ConsumeTeleport() bool

ConsumeTeleport returns true once after a completed summon/teleport so Lua can clear sticky state and re-settle at the new position.

func (*Bot) Events

func (b *Bot) Events() []BotEvent

Events returns the recorded events.

func (*Bot) FaceTarget

func (b *Bot) FaceTarget(guid uint64) bool

func (*Bot) GetClass

func (b *Bot) GetClass() uint8

func (*Bot) GetFacing

func (b *Bot) GetFacing() float32

func (*Bot) GetHealth

func (b *Bot) GetHealth() (current, max uint32)

func (*Bot) GetLevel

func (b *Bot) GetLevel() uint32

func (*Bot) GetNearbyPlayers

func (b *Bot) GetNearbyPlayers(maxDist float32) []luaengine.UnitInfo

func (*Bot) GetNearbyUnits

func (b *Bot) GetNearbyUnits(maxDist float32) []luaengine.UnitInfo

func (*Bot) GetOwnGUID

func (b *Bot) GetOwnGUID() uint64

func (*Bot) GetPetGUID

func (b *Bot) GetPetGUID() uint64

func (*Bot) GetPosition

func (b *Bot) GetPosition() (x, y, z, o float32)

func (*Bot) GetPower

func (b *Bot) GetPower() (current, max uint32)

func (*Bot) GetPowerType

func (b *Bot) GetPowerType() uint8

func (*Bot) GetRace

func (b *Bot) GetRace() uint8

func (*Bot) GetStance

func (b *Bot) GetStance() int

func (*Bot) GetTargetGUID

func (b *Bot) GetTargetGUID() uint64

func (*Bot) GetUnitInfo

func (b *Bot) GetUnitInfo(guid uint64) *luaengine.UnitInfo

func (*Bot) HasAuraOn

func (b *Bot) HasAuraOn(guid uint64, spellID uint32) bool

Extended BotAPI methods for the Lua AI framework (warrior rends, pet, stance, aura checks, etc.)

func (*Bot) InCombat

func (b *Bot) InCombat() bool

func (*Bot) IsAlive

func (b *Bot) IsAlive() bool

func (*Bot) IsBehindTarget

func (b *Bot) IsBehindTarget(targetGUID uint64) bool

func (*Bot) IsMoving

func (b *Bot) IsMoving() bool

IsMoving reports whether the movement controller is mid-path.

func (*Bot) IsSpellReady

func (b *Bot) IsSpellReady(spellID uint32) bool

func (*Bot) LoadAIBundle

func (b *Bot) LoadAIBundle(bundle scenario.AIBundle) error

LoadAIBundle applies a full AIBundle (Main + Helpers + Data + TickFunc) at runtime. This enables live phase broadcasts and richer scenario AI updates. It DoStrings Main then each Helper, sets scenario_data, and overrides the tick func. Existing globals from prior loads are not cleared (Lua state is additive for functions).

func (*Bot) LoadLuaScript

func (b *Bot) LoadLuaScript(code string) error

LoadLuaScript loads a Lua script at runtime (simple string form). For richer updates including helpers/data/tick func switch use LoadAIBundle.

func (*Bot) Log

func (b *Bot) Log(format string, args ...interface{})

func (*Bot) Loot

func (b *Bot) Loot(guid uint64) error

func (*Bot) LootAll

func (b *Bot) LootAll(guid uint64) error

LootAll opens loot, takes money, and releases without blocking the AI tick. Previously this slept 700ms on the AI goroutine, which froze ticks and caused loot spam under Lua grind (validation run: 122× CMSG_LOOT in ~45s). Server responses arrive asynchronously via OnLootOpened / SMSG_LOOT_*.

func (*Bot) MoveTo

func (b *Bot) MoveTo(x, y, z float32) error

func (*Bot) PetAttack

func (b *Bot) PetAttack(target uint64)

func (*Bot) Run

func (b *Bot) Run() BotResult

Run executes the full bot flow: authenticate, connect, enter world, run AI loop.

func (*Bot) RunAIOnly

func (b *Bot) RunAIOnly() BotResult

RunAIOnly runs only the AI loop (assumes world + nav + lua already attached/initialized). Does not perform login or full lifecycle management. Pairs with NewHeadlessBot.

func (*Bot) SendChat

func (b *Bot) SendChat(message string) error

func (*Bot) SendCommand

func (b *Bot) SendCommand(command string) error

func (*Bot) SendGuildCommand

func (b *Bot) SendGuildCommand(command string) error

func (*Bot) SetFacing

func (b *Bot) SetFacing(o float32) error

func (*Bot) SetLevel

func (b *Bot) SetLevel(level uint32)

func (*Bot) SetSheathed

func (b *Bot) SetSheathed(state uint32) error

func (*Bot) SetTarget

func (b *Bot) SetTarget(guid uint64) error

func (*Bot) Status

func (b *Bot) Status() BotResult

Status returns current status

func (*Bot) Stop

func (b *Bot) Stop()

Stop signals the bot to stop running.

func (*Bot) StopAttack

func (b *Bot) StopAttack() error

func (*Bot) StopMoving

func (b *Bot) StopMoving() error

func (*Bot) ValidationMode

func (b *Bot) ValidationMode() bool

ValidationMode satisfies the luaengine.BotAPI requirement. It is the central cheap gate for all heavy validation tooling (structured logs, packet traces, ring buffers, detailed aura data, etc.). When false (the default for regular operation), callers must do almost no work.

type BotEvent

type BotEvent struct {
	Time    time.Time `json:"time"`
	Type    string    `json:"type"`
	Message string    `json:"message"`
}

BotEvent is a notable event that occurred during the bot's life.

type BotResult

type BotResult struct {
	ID     string    `json:"id"`
	Status BotStatus `json:"status"`
	Error  string    `json:"error,omitempty"`
	Level  uint32    `json:"level,omitempty"`
	Kills  int       `json:"kills,omitempty"`
	Deaths int       `json:"deaths,omitempty"`
}

BotResult holds the result of a bot run

type BotStatus

type BotStatus string

BotStatus represents the current state of a bot

const (
	BotStatusIdle           BotStatus = "idle"
	BotStatusAuthenticating BotStatus = "authenticating"
	BotStatusConnecting     BotStatus = "connecting"
	BotStatusInWorld        BotStatus = "in_world"
	BotStatusDone           BotStatus = "done"
	BotStatusError          BotStatus = "error"
)

type Config

type Config struct {
	Username      string `json:"username"`
	Password      string `json:"password"`
	AuthServer    string `json:"auth_server"`
	CharacterName string `json:"character_name"`
	RealmIndex    int    `json:"realm_index"`

	Race   uint8 `json:"race"`
	Class  uint8 `json:"class"`
	Gender uint8 `json:"gender"`

	// Navigation
	DataDir            string `json:"data_dir"`            // root containing mmaps/, maps/, vmaps/
	PathfindingAddress string `json:"pathfinding_address"` // optional remote (deprioritized)

	// Lua
	LuaScript string `json:"lua_script"` // path to .lua file (DoFile)
	LuaCode   string `json:"lua_code"`   // inline script (DoString). Precedence: AIBundle > LuaCode > LuaScript

	// AIBundle carries richer scenario-distributed AI (Main + Helpers + Data + TickFunc).
	// When non-empty, takes precedence for initial AI payload.
	AIBundle scenario.AIBundle `json:"ai_bundle"`

	// Behavior mode (preserved for backward compat with existing load tests)
	Mode string `json:"mode"` // "grind", "hogger", "dungeon", "idle", "lua"

	// AI tick interval (ms). Default 200.
	AITickMs int `json:"ai_tick_ms"`

	// Dungeon for "dungeon" mode.
	DungeonName string `json:"dungeon_name"`

	// DeleteExistingCharacters: before creating target char, delete others on account.
	DeleteExistingCharacters bool `json:"delete_existing_characters"`

	// LogDecisionsToChat emits major AI decisions via /say (throttled).
	LogDecisionsToChat bool `json:"log_decisions_to_chat"`

	// DisableTargetCache forces fresh target scans every tick (debug).
	DisableTargetCache bool `json:"disable_target_cache"`

	// ValidationMode enables heavier instrumentation only used during E2E quality runs:
	// - Structured decision + outcome logging to ValidationLogPath (JSONL)
	// - Ring buffers for recent cast results / aura deltas (for post-run assertions)
	// - Optional packet tracing
	// When false (the default for regular runs), these paths allocate nothing and do minimal work.
	ValidationMode bool `json:"validation_mode"`

	// ValidationLogPath when set (and ValidationMode true) writes structured events
	// (decisions, cast results, aura changes, value snapshots) for later analysis.
	// Example: "validation/warrior-rend-001.jsonl". Empty = disabled.
	ValidationLogPath string `json:"validation_log_path"`

	// EnablePacketTrace when true + ValidationMode, logs or records selected high-value
	// opcodes (SPELL_GO, AURA_UPDATE*, ATTACKERSTATE, etc.) with timestamps.
	// Expensive; off by default.
	EnablePacketTrace bool `json:"enable_packet_trace"`

	// EnableDetailedAuras when true keeps richer per-aura metadata (duration, stacks, caster).
	// The basic spellID set for HasAura is always maintained (cheap). Detailed is opt-in.
	EnableDetailedAuras bool `json:"enable_detailed_auras"`

	// SkipCharacterSetup skips the entire auth + char enum/create/login flow.
	// Use together with NewHeadlessBot when you already performed login via client.WorldClient.
	SkipCharacterSetup bool `json:"skip_character_setup"`

	// AllowDBSetup gates the old preLoginDBSetup (level/pos/spells/gear via direct MySQL).
	// Default false for library and test use. When true + CharDBDSN provided, the
	// legacy DB path remains available for load-test modes that relied on it.
	AllowDBSetup bool `json:"allow_db_setup"`

	// CharDBDSN is the DSN for acore_characters used only when AllowDBSetup is true.
	CharDBDSN string `json:"char_db_dsn"`
}

Config holds configuration for a bot instance. This is the public config for AzerothGhost. It loosens coupling: DB setup is opt-in; headless usage is supported; Lua can be provided inline (LuaCode) or via AIBundle for scenarios.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns a Config with common defaults applied.

type Option

type Option func(*Config)

Option is a functional option for NewBot.

func WithAIBundle

func WithAIBundle(b scenario.AIBundle) Option

WithAIBundle provides a full scenario AIBundle.

func WithAllowDBSetup

func WithAllowDBSetup(allow bool) Option

WithAllowDBSetup enables the legacy pre-login DB writes (off by default).

func WithBehaviorProvider

func WithBehaviorProvider(_ interface{}) Option

WithBehaviorProvider can be used in future to inject a custom Behavior. Placeholder for the interface described in the design.

func WithDataDir

func WithDataDir(dir string) Option

WithDataDir sets the pathfinding data directory.

func WithLuaCode

func WithLuaCode(code string) Option

WithLuaCode provides inline Lua code (higher precedence than LuaScript file).

func WithSkipCharacterSetup

func WithSkipCharacterSetup(skip bool) Option

WithSkipCharacterSetup requests that Run() skips auth/char/login.

Jump to

Keyboard shortcuts

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