character

package
v0.7.81 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: MIT Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package character reads characters captured by ForeverScribe (https://github.com/MattMaximo/foreverscribe, MIT) into a typed model.

Fields ForeverScribe did not capture are nil (or an empty string for text), never invented.

Index

Constants

View Source
const (
	SourceWoWC = "WoW Companion addon"
	SourceFS   = "ForeverScribe"
)

Source names for Character.Source.

View Source
const (
	FSFile   = "ForeverScribe.lua"
	WoWCFile = "WoWCompanion.lua"
)

File names beside each other in one SavedVariables folder.

View Source
const DBVariable = "ForeverScribeDB"

DBVariable is the one global the addon writes.

View Source
const NearFraction = 0.75

NearFraction is the share of objectives done at which an open quest counts as nearly complete.

View Source
const RecentGiver = 7 * 24 * time.Hour

RecentGiver is how recently a giver must have been met to be flagged as a recent interaction.

View Source
const SeenByYou = "seen by you"

SeenByYou is the mark on a fact that came from what the player saw in game (WoWCompanionDB.observed, docs/observed-format.md of the addon).

View Source
const StaleAfter = 30 * 24 * time.Hour

StaleAfter is how old an observation may be and still count as current price data.

View Source
const WoWCVariable = "WoWCompanionDB"

WoWCVariable is the global the WoW Companion addon writes; its characters sit in `characters` (docs/capture-format.md of the addon).

Variables

This section is empty.

Functions

func ParseAddon added in v0.7.47

func ParseAddon(text, key, name string) (*Totals, *Observed)

ParseAddon reads the addon's SavedVariables text: the stat totals of one character and what the player saw.

func SeenAgo added in v0.7.53

func SeenAgo(t int64, now time.Time) string

SeenAgo says when something was seen, in plain words ("seen 3 days ago"); "" when t is unknown.

func SeenNote added in v0.7.53

func SeenNote(t int64, now time.Time) string

SeenNote is the freshness phrase for an observation: "seen 3 days ago", with "; prices may have changed" added once it is older than StaleAfter.

func Siblings added in v0.7.47

func Siblings(path string) (fsPath, wowcPath string)

Siblings returns the ForeverScribe and the WoW Companion file in the folder of path. A path named WoWCompanion.lua is the addon's file; any other name is taken as ForeverScribe's.

func Stale added in v0.7.53

func Stale(t int64, now time.Time) bool

Stale reports whether an observation made at t is too old to count as current prices.

Types

type Character

type Character struct {
	Key        string // "Realm:Name"; the name alone when the realm is empty
	Name       string
	Realm      string
	Level      *int
	Class      string
	Race       string
	Faction    string
	Money      *int
	XP         *int
	XPMax      *int
	RestedXP   *int // experience points (GetXPExhaustion), not a percentage
	CapturedAt *int64
	Addon      string
	Client     Client
	Location   *Location // nil when the capture holds none
	Hearth     string    // the hearthstone's bind location name
	// Source says which capture the character came from: SourceWoWC, SourceFS or both joined.
	Source string

	Equipment    map[string]EquippedItem // nil when not captured
	Bags         []ItemStack
	BagsCaptured bool
	Bank         []ItemStack
	BankCaptured bool // false until the player has opened the bank with ForeverScribe running

	NPCs            []NPC // nil when the capture holds no npcs table
	Quests          []Quest
	QuestsCaptured  bool
	CompletedQuests []int
	Talents         *Talents
	Skills          []Skill
	SkillsCaptured  bool
	Professions     []Skill // each profession once
	Reputations     []Reputation

	// Profile is the player's own, kept locally (internal/profile) and attached after the
	// capture is read; nil when the player has set none. They are never part of a capture.
	Profile *Profile
	// KnownSpells are the spell ids the character knows (a recipe's spell id included), when a capture
	// lists them; nil when it does not.
	KnownSpells map[int64]bool
	// Recipes are the recipes the client's own trade skill window listed, by profession (lower-case);
	// nil when none were recorded. A recipe listed here is known.
	Recipes map[string]SeenRecipes
	// Totals are the stat totals the addon records (WoWCompanionDB.characters[key].stats), attached with AttachTotals;
	// nil when none.
	Totals *Totals
	// Seen is what the player saw in game (WoWCompanionDB.observed): trainers, vendors, gathering and
	// quest givers; nil when nothing was recorded. These "seen by you" facts come before the dataset.
	Seen *Observed
}

func AttachAddon added in v0.7.47

func AttachAddon(addonSV string, c Character) Character

AttachAddon returns c with what the addon recorded in its SavedVariables file: the stat totals and the observations ("seen by you"). Nothing is attached when the file is missing or unreadable.

func AttachTotals added in v0.7.12

func AttachTotals(addonSV string, c Character) Character

AttachTotals returns c with what the addon recorded in its SavedVariables file: its stat totals and what the player saw (Seen). c is unchanged when the file is unreadable or holds none.

func LoadCharacter

func LoadCharacter(key string, rec lua.Table) Character

func LoadWoWCharacter added in v0.7.47

func LoadWoWCharacter(key string, rec lua.Table) Character

LoadWoWCharacter builds one character from a WoWCompanionDB.characters record.

func MergeCharacters added in v0.7.47

func MergeCharacters(a, b Character) Character

MergeCharacters returns the newer capture, with each part it lacks filled from the other.

func (Character) KnowsRecipe added in v0.7.77

func (c Character) KnowsRecipe(profession string, spell int64, name string, creates int64) Knowledge

KnowsRecipe decides whether the character knows a recipe, by its spell id, its name and the item it creates. Known spells and the recorded recipes for the profession both count as known; when either source exists and the recipe is in neither, it is not known (even if the other source is empty).

func (Character) LastKnownPosition added in v0.5.0

func (c Character) LastKnownPosition() *Position

LastKnownPosition is nil when neither a located save nor any NPC sighting exists.

func (Character) NearbyGivers added in v0.5.0

func (c Character) NearbyGivers(now time.Time) []Giver

NearbyGivers lists kind "quest" NPCs in the position's zone (same map when both ids are known), nearest first. A giver sighted at several spots is listed once.

func (Character) Recipe added in v0.7.53

func (c Character) Recipe(profession, name string) (SeenRecipe, bool)

Recipe finds a recipe the player's window listed for the profession, by name (case-blind).

func (Character) WithRecipeProfessions added in v0.7.64

func (c Character) WithRecipeProfessions() Character

WithRecipeProfessions adds a profession for each one the character has recorded recipes for and the skills do not list: a recipe window only opens for a profession the character has. The skill level of an added one is unknown. It returns c unchanged when nothing needs adding.

func (Character) ZoneOfMap added in v0.7.47

func (c Character) ZoneOfMap(mapID int) string

ZoneOfMap names the zone of a uiMapID from what the capture knows (where the character stood, the NPCs it met); "" when it knows none. A name is never invented.

type Client

type Client struct {
	Version string
	Build   string
	TOC     string
}

Client is the game client that wrote the capture.

func (Client) Empty

func (c Client) Empty() bool

type EquippedItem

type EquippedItem struct {
	Slot          string
	ItemID        *int
	Enchant       *int
	Link          string
	Name          string
	ItemLevel     *int
	Quality       *int
	Durability    *int
	DurabilityMax *int
}

type File

type File struct {
	Addon      string
	Schema     *int
	Client     Client
	Characters []Character
	// HasWoWC and HasFS say which capture files were read (WoWCompanionDB.characters, ForeverScribeDB).
	HasWoWC, HasFS bool
}

File is everything one SavedVariables file holds.

func Load

func Load(vars map[string]any) (File, error)

Load builds models from parsed variables (the result of lua.Parse).

func LoadFile

func LoadFile(path string) (File, error)

LoadFile reads the character captures beside path: the WoW Companion addon's (WoWCompanionDB.characters in WoWCompanion.lua) and ForeverScribe's. A character in both is merged: the newer capture leads and the other fills the parts it lacks. A file that is missing or unreadable is skipped when the other gives characters; otherwise the error is the one for path. A malformed file is a *lua.ParseError.

func LoadWoWC added in v0.7.47

func LoadWoWC(vars map[string]any) (File, error)

LoadWoWC builds models from parsed variables holding WoWCompanionDB.characters. The result has no characters (and HasWoWC false upstream) when the table is absent.

func (File) CapturedAt

func (f File) CapturedAt() *int64

CapturedAt is the newest capture time over all characters.

func (File) ClientOf

func (f File) ClientOf(c Character) Client

ClientOf is the client block of one character, falling back to the file's.

type Giver added in v0.5.0

type Giver struct {
	NPC
	Distance float64 // straight line in map percent
	Recent   bool    // met within RecentGiver
}

Giver is a quest-giver NPC the character has met, with its distance from the position.

type ItemStack

type ItemStack struct {
	ItemID int
	Count  int
	Name   string
	Link   string
	// The addon's optional per-item fields; nil or empty when it did not record them.
	Quality   *int
	ItemLevel *int
	ReqLevel  *int
	EquipLoc  string
	Suffix    string
}

type Knowledge added in v0.7.77

type Knowledge int

Knowledge says whether the character knows a recipe.

const (
	// RecipeUnknown: nothing recorded decides it (no known spells and no recorded list for the profession).
	RecipeUnknown Knowledge = iota
	// RecipeKnown: the spell is a known spell, or the recipe is in the recorded list for the profession.
	RecipeKnown
	// RecipeNotKnown: the character has a spell list or a recorded recipe list and the recipe is in neither.
	RecipeNotKnown
)

type Location added in v0.4.0

type Location struct {
	Zone    string
	Subzone string
	MapName string
	MapID   *int
	X, Y    *float64
}

Location is where the character stood at the last save (ForeverScribe snapshot.location). X and Y are percent of the map (0 to 100) and nil when the client gave no position.

type NPC added in v0.5.0

type NPC struct {
	ID      int
	Name    string
	MapID   *int
	Zone    string
	Subzone string
	X, Y    *float64
	Kind    string
	First   *int64
	Seen    *int64 // t: last interaction, epoch seconds
	Count   *int   // n: interactions
	Spots   []Spot
}

NPC is one NPC sighting (ForeverScribe npcs["<npcID>:<uiMapID>"]). Kind is "quest" or "gossip".

type Objective

type Objective struct {
	Text string
	Have *int
	Need *int
	Done *bool
	Type string
}

func (Objective) Label added in v0.7.2

func (o Objective) Label() string

Label is the objective's text without its have/need count: "Windsong Crawler Meat".

func (Objective) ObjectiveDone added in v0.7.79

func (o Objective) ObjectiveDone() bool

ObjectiveDone reports whether o is finished, by its done flag or its count.

type Observed added in v0.7.47

type Observed struct {
	Trainers []SeenTrainer
	Vendors  []SeenVendor
	Gather   []SeenGather
	Givers   []SeenGiver
	// Flights are the flight masters the player opened.
	Flights []SeenFlight
}

Observed is what the player saw, read from the addon's SavedVariables. Every list may be empty.

func ParseObserved added in v0.7.47

func ParseObserved(vars map[string]any) *Observed

ParseObserved reads WoWCompanionDB.observed out of parsed variables: trainers, vendors, gathering and the quest givers of accepted events (the newest sighting of each quest wins). It is tolerant: a missing section or field is empty.

func (*Observed) Empty added in v0.7.47

func (o *Observed) Empty() bool

Empty reports whether nothing was observed.

func (*Observed) FlightsFor added in v0.7.53

func (o *Observed) FlightsFor(faction string) []SeenFlight

FlightsFor lists the seen flight masters open to the faction, newest first.

func (*Observed) GiverOf added in v0.7.47

func (o *Observed) GiverOf(questID int) (SeenGiver, bool)

GiverOf is the seen giver of a quest.

func (*Observed) TrainersFor added in v0.7.47

func (o *Observed) TrainersFor(faction string) []SeenTrainer

TrainersFor lists the seen trainers open to the character's faction, newest first.

func (*Observed) VendorsOf added in v0.7.47

func (o *Observed) VendorsOf(item int64, faction string) (vs []SeenVendor, stock []SeenStock)

VendorsOf lists the seen vendors open to the faction that sold the item, with the stock row.

type PerPoint added in v0.7.56

type PerPoint struct {
	SpellCritFromInt, CritFromAgi, ManaRegenFromSpi, HealthRegenFromSpi *float64
}

PerPoint are the client's per-point getters, every field optional: stats.perPoint.spellCritFromInt, critFromAgi, manaRegenFromSpi and healthRegenFromSpi.

type Position added in v0.5.0

type Position struct {
	Zone, Subzone string
	MapID         *int
	X, Y          float64
	Approximate   bool
}

Position is the character's last known place: the saved location when it has coordinates, else (Approximate) where the most recent NPC interaction happened.

func (Position) InZone added in v0.5.0

func (p Position) InZone(zone string) bool

InZone reports whether a quest's zone name matches the position's zone or subzone.

func (Position) Label added in v0.5.0

func (p Position) Label() string

Label describes the position, marking an approximate one.

type Profile added in v0.7.0

type Profile struct {
	Role  string `json:"role"`
	Focus string `json:"focus"`
	Spec  string `json:"spec,omitempty"`
	// StatPref is the optional stat preference: balanced, damage or survival ("" is balanced).
	StatPref string `json:"stat_pref,omitempty"`
}

Profile is a character's play style: role (tank, healer, damage or balanced), focus (leveling, dungeons, pvp or mixed), the spec tree the player chose.

type Quest

type Quest struct {
	QuestID    int
	Title      string
	Level      *int
	Zone       string
	Complete   *bool
	Failed     *bool
	Objectives []Objective
	// Observed marks a quest the addon saw accepted after the capture: it is in the log, but its
	// objectives are not in the capture.
	Observed bool
}

func (Quest) Fraction added in v0.5.0

func (q Quest) Fraction() (float64, bool)

Fraction is the share of the quest's objectives that are done, and whether it is known. A complete quest is 1; a quest with no readable objectives is unknown.

func (Quest) NearlyDone added in v0.5.0

func (q Quest) NearlyDone() bool

NearlyDone reports a quest that is complete or has at least NearFraction of its objectives done.

func (Quest) ObjectiveProgress added in v0.5.0

func (q Quest) ObjectiveProgress() string

ObjectiveProgress is ProgressText without the quest name: "3/8 Crab Claws; 1/1 Boss".

func (Quest) ProgressText added in v0.5.0

func (q Quest) ProgressText() string

ProgressText is the quest's objective progress, such as "Crab Season: 3/8 Crab Claws; 1/1 Boss". It is empty when the quest has no objective with a count.

func (Quest) Readiness added in v0.7.79

func (q Quest) Readiness() string

Readiness is the quest's state in words: "ready to turn in", "1 of 3 objectives done", or "not ready to turn in" when the capture lists no objectives.

func (Quest) Ready added in v0.7.79

func (q Quest) Ready() bool

Ready reports whether the quest can be handed in: the game says it is complete, or it has objectives and every one is finished. A quest with no readable objectives is not ready.

type Reputation

type Reputation struct {
	FactionID int
	Name      string
	Standing  *int
	Value     *int
	Min       *int
	Max       *int
	AtWar     *bool
	Group     string
}

type SeenFlight added in v0.7.53

type SeenFlight struct {
	NPC     int64
	Name    string
	Map     int
	X, Y    float64
	Faction string
	T       int64
}

SeenFlight is one flight master the player opened: a known flight point.

type SeenGather added in v0.7.47

type SeenGather struct {
	Kind               string // herb, mine, skin or fish
	Source             string
	Map                int
	CX, CY             int // the cell: floor(percent / 5)
	N                  int
	T                  int64
	SkillMin, SkillMax int
	Items              map[int64]int // item id -> total looted
}

SeenGather is one aggregated gathering or fishing row: where, what and how much.

type SeenGiver added in v0.7.47

type SeenGiver struct {
	QuestID int
	NPC     string
	NPCID   int64
	Map     int
	X, Y    float64
	T       int64
}

SeenGiver is where the player saw a quest's giver, from an accepted event.

type SeenOffer added in v0.7.47

type SeenOffer struct {
	Name       string
	Rank       string
	State      string // available, unavailable or used (already known)
	Cost       int64  // copper
	Level      int    // the character level it needs, 0 when none shown
	Skill      string // the skill gate's profession, "" when none
	SkillLevel int
	Spell      int64
}

SeenOffer is one thing a trainer teaches, as the trainer window showed it.

type SeenRecipe added in v0.7.53

type SeenRecipe struct {
	Name       string
	ID         int64  // the spell or item id in the recipe's link, 0 when none
	Difficulty string // orange, yellow, green or grey at the skill the window was opened at
	Makes      int64  // item id, 0 when none
	MakesCount int
	Reagents   []ItemStack
}

SeenRecipe is one recipe the player's own trade skill window listed.

type SeenRecipes added in v0.7.53

type SeenRecipes struct {
	SeenAt  int64
	Entries []SeenRecipe
}

SeenRecipes is one profession's recipes and when the window was read.

type SeenStock added in v0.7.47

type SeenStock struct {
	ItemID int64
	Price  int64
	Ext    bool // also costs tokens or items
}

SeenStock is one item a vendor sold, with its price in copper.

type SeenTrainer added in v0.7.47

type SeenTrainer struct {
	NPC     int64
	Name    string
	Map     int
	X, Y    float64
	Faction string
	T       int64
	Offers  []SeenOffer
}

SeenTrainer is one trainer the player opened.

type SeenVendor added in v0.7.47

type SeenVendor struct {
	NPC     int64
	Name    string
	Map     int
	X, Y    float64
	Faction string
	T       int64
	Items   []SeenStock
}

SeenVendor is one vendor the player opened.

type Skill

type Skill struct {
	Name    string
	SkillID *int
	Rank    *int
	Max     *int
	Group   string
	// FromRecipes marks a profession known only because the character's recipes for it were recorded;
	// its skill level is not captured.
	FromRecipes bool
}

type Spot added in v0.5.0

type Spot struct {
	X, Y *float64
	T    *int64
	N    *int
}

Spot is one place an NPC was seen (map percent) and when.

type Talent

type Talent struct {
	Name    string
	Group   string
	Rank    int
	MaxRank *int
	NodeID  *int
	SpellID *int
	Type    string // node type as captured, "" when absent
	CanBuy  *bool  // nil when the capture does not say
}

type TalentGroup

type TalentGroup struct {
	Name  string
	Order *int
	Spent int
}

TalentGroup is one named branch of a tree (for example "Discipline") and its spent points.

type TalentTree

type TalentTree struct {
	Name      string
	Key       string // "professions" for a profession tree; "" for a class tree
	Points    *int   // points spent in the tree
	Unspent   *int   // currency.unspent
	MaxPoints *int   // currency.max
	MaxAvail  *int   // currency.maxAvailable
	Groups    []TalentGroup
	Talents   []Talent
}

func (TalentTree) IsProfession added in v0.7.0

func (t TalentTree) IsProfession() bool

IsProfession reports whether the tree is a profession talent tree, not a class tree.

type Talents

type Talents struct {
	System  string
	Loadout string
	Unspent *int // class talent points (class tree currencies, else the top-level field)
	Trees   []TalentTree
}

func (*Talents) ProfessionUnspent added in v0.7.0

func (t *Talents) ProfessionUnspent() int

ProfessionUnspent is the unspent points over the profession trees; 0 when there are none.

type Totals added in v0.7.12

type Totals struct {
	At    *int64 // stats.seenAt
	Level *int   // stats.level
	// The five stats, as the totals the player sees (stats.stats.<stat>.total); Base, Pos and Neg are the
	// same stat's unmodified value and its gear/buff and penalty parts.
	Str, Agi, Sta, Int, Spi *float64
	Base, Pos, Neg          map[string]float64 // keyed "str", "agi", "sta", "int", "spi"
	HealthMax, ManaMax      *float64
	Armor, AttackPower      *float64
	RangedAttackPower       *float64
	// Crit is the melee crit chance (stats.meleeCrit); RangedCrit and SpellCrit (the best school) are percents.
	Crit, RangedCrit, SpellCrit *float64
	Dodge, Parry, Block         *float64
	ManaRegenBase               *float64 // stats.manaRegen.base
	ManaRegenCasting            *float64 // stats.manaRegen.casting
	SpellDamage, SpellHealing   *float64
	// Per are what the client's own per-point getters report for this character (stats.perPoint); nil when
	// the addon wrote none.
	Per *PerPoint
}

Totals are a character's stat numbers as the WoW Companion addon records them read-only in WoWCompanionDB.characters[<character key>].stats (every field optional; nil when the addon wrote none).

func ParseTotals added in v0.7.12

func ParseTotals(text, key, name string) *Totals

ParseTotals reads WoWCompanionDB.characters[key].stats out of the addon's SavedVariables text, tolerantly: a missing table, entry or field gives nil or a nil field. The key is matched as captured, then case-insensitively, then by character name alone.

func (*Totals) Any added in v0.7.12

func (t *Totals) Any() bool

Any reports whether at least one total is present and positive.

func (*Totals) Total added in v0.7.63

func (t *Totals) Total(k string) float64

Total is the stat's total (0 when the capture has none), keyed like Base.

Jump to

Keyboard shortcuts

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