Documentation
¶
Overview ¶
Package fairy provides a highly modular and extensible Go library for fetching, parsing, and enriching Zenless Zone Zero player profiles via the EnkaNetwork API.
The raw response from Enka.Network provides basic IDs for agents, W-Engines, and Drive Discs. Fairy takes care of the heavy lifting by replacing raw IDs with full localized names for agents, weapons, discs, and skills, building full URLs for splash arts, icons, and avatars, and calculating precise final combat stats taking into account base stats, weapon scalings, disc substat rolls, and set bonuses.
Quick Start ¶
The easiest way to get started is by using the global functions. By default, this uses the embedded metadata store and English localization:
profile, err := fairy.GetProfile(context.Background(), "1504687050")
if err != nil {
log.Fatal(err)
}
fmt.Printf("Player: %s (Level %d)\n", profile.Nickname, profile.InterknotLevel)
Custom Client ¶
If you are building a multi-language application or want to configure custom HTTP settings, you should create a dedicated client:
client, err := fairy.NewClient(
fairy.WithDefaultLang(fairy.LangJA), // Default to Japanese
)
if err != nil {
log.Fatal(err)
}
See https://github.com/kirinyoku/fairy for more advanced features.
Index ¶
- func GetRawProfile(ctx context.Context, uid string) (*zzz.Profile, error)
- type Agent
- type Attribute
- type Avatar
- type Badge
- type Client
- func (c *Client) GetProfile(ctx context.Context, uid string) (*Profile, error)
- func (c *Client) GetProfileWithLang(ctx context.Context, uid string, lang Language) (*Profile, error)
- func (c *Client) GetRawProfile(ctx context.Context, uid string) (*zzz.Profile, error)
- func (c *Client) Localize(raw *zzz.Profile, lang Language) (*Profile, error)
- type DriveDisc
- type DriveDiscSetBonus
- type FormattedStatBreakdown
- type FormattedStats
- type Language
- type Namecard
- type Option
- type Options
- type Profile
- type PropertyID
- type Rarity
- type Region
- type Set
- type Skill
- type Skin
- type Specialty
- type StatValue
- type Stats
- type Title
- type UIStats
- type WEngine
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Agent ¶
type Agent struct {
ID int `json:"id"` // The internal ID of the agent.
Name string `json:"name"` // The localized name of the agent (e.g., "Ellen").
Level int `json:"level"` // The current level of the agent (1-60).
Promotion int `json:"promotion"` // The promotion/ascension phase of the agent (0-5).
MindscapeCinema int `json:"mindscape_cinema"` // The unlocked Mindscape Cinema level (0-6).
CoreSkillEnhancement int `json:"core_skill_enhancement"` // The Core Skill enhancement level (0-6).
Attribute Attribute `json:"attribute"` // The elemental damage type (e.g., Ice).
AttributeName string `json:"attribute_name"` // The localized name of the attribute.
Specialty Specialty `json:"specialty"` // The combat role (e.g., Attack).
SpecialtyName string `json:"specialty_name"` // The localized name of the specialty.
Rarity Rarity `json:"rarity"` // The rarity tier (S or A).
Skin *Skin `json:"skin"` // The currently equipped skin (can be nil if not found).
SplashArtURL string `json:"splash_art_url"` // The URL to the agent's splash art.
Skills []Skill `json:"skills"` // The agent's skills and passives.
WEngine *WEngine `json:"w_engine"` // The currently equipped W-Engine (can be nil).
DriveDiscs []DriveDisc `json:"drive_discs"` // The equipped Drive Discs (up to 6).
ActiveSetBonuses []DriveDiscSetBonus `json:"active_set_bonuses"` // The active 2-piece or 4-piece set bonuses.
BaseStats Stats `json:"base_stats"` // The agent's base combat stats before gear/buffs.
Stats Stats `json:"stats"` // The agent's final combat stats including all gear/buffs.
}
Agent represents an enriched agent (character) showcased on a player's profile. A profile can showcase a maximum of 6 agents. It contains the agent's combat metadata, equipped gear, and final stats.
func (*Agent) CountEffectiveRolls ¶
func (a *Agent) CountEffectiveRolls(targetProps ...PropertyID) int
CountEffectiveRolls returns the total number of sub-stat rolls across all Drive Discs that match any of the provided target property IDs (also known as "effective" or "useful" rolls). Example usage for an Attack agent:
effective := agent.CountEffectiveRolls(fairy.PropCritRate, fairy.PropCritDMG, fairy.PropATKPercent)
func (*Agent) FormattedUIStats ¶
FormattedUIStats generates a complete breakdown of base vs added stats for UI display. This structure precisely matches the visual representation and layout seen in the in-game stat panel or on platforms like Enka.Network.
func (*Agent) SubStatTotals ¶
SubStatTotals calculates the sum of all sub-stats across all equipped Drive Discs. It groups them by PropertyID and sums the Rolls and Values. The returned slice is guaranteed to preserve the initial appearance order of sub-stats.
type Attribute ¶
type Attribute string
Attribute represents the elemental damage type of an agent.
const ( AttributePhysical Attribute = "Physical" AttributeHonedEdge Attribute = "HonedEdge" AttributeFire Attribute = "Fire" AttributeIce Attribute = "Ice" AttributeFrost Attribute = "Frost" AttributeElectric Attribute = "Electric" AttributeEther Attribute = "Ether" AttributeAuricInk Attribute = "AuricInk" AttributeWind Attribute = "Wind" AttributeLumiflux Attribute = "Lumiflux" )
type Avatar ¶
type Avatar struct {
ID int `json:"id"` // The internal ID of the avatar.
URL string `json:"url"` // The URL to the avatar's image asset.
}
Avatar represents a selectable proxy avatar (profile picture). See: https://zenless-zone-zero.fandom.com/wiki/Avatar
type Badge ¶
type Badge struct {
ID int `json:"id"` // The internal ID of the badge.
Title string `json:"title"` // The localized name/title of the badge.
Value int `json:"value"` // The progression value associated with the badge.
IconURL string `json:"icon_url"` // The URL to the badge's visual icon.
}
Badge represents a collectible medal or badge displayed on the profile. See: https://zenless-zone-zero.fandom.com/wiki/Badge
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client coordinates fetching data from the API and enriching it using a metadata store. It serves as the main entry point for the fairy library.
func NewClient ¶
NewClient creates a new instance of Client. If opts.Store is nil, it will automatically load the default EmbeddedStore. If opts.DefaultLang is empty, it defaults to LangEN. Returns an error if the fallback EmbeddedStore fails to load its internal files.
func (*Client) GetProfile ¶
GetProfile fetches the game profile from the EnkaNetwork API and localizes it using the client's default language. The provided context controls the HTTP request timeout and cancellation.
func (*Client) GetProfileWithLang ¶
func (c *Client) GetProfileWithLang(ctx context.Context, uid string, lang Language) (*Profile, error)
GetProfileWithLang fetches the game profile from the EnkaNetwork API and localizes it with a specific language. The provided context controls the HTTP request timeout and cancellation.
func (*Client) GetRawProfile ¶
GetRawProfile fetches the raw zzz.Profile without localization. Use this if you only need the raw data structure provided by the EnkaNetwork API. The provided context controls the HTTP request timeout and cancellation.
type DriveDisc ¶
type DriveDisc struct {
ID int `json:"id"` // The internal ID of the specific disc variation.
UID string `json:"uid"` // The unique instance ID of this specific Drive Disc.
Set Set `json:"set"` // The equipment set this disc belongs to.
Slot int `json:"slot"` // The equip slot number (1 to 6). Slots 1-3 have fixed main stats, while 4-6 are randomized.
Level int `json:"level"` // The upgrade level of the disc (0-15).
Rarity Rarity `json:"rarity"` // The rarity tier (S, A, B).
IconPath string `json:"icon_path"` // The URL to the disc's icon.
MainStat StatValue `json:"main_stat"` // The primary stat provided by this disc.
SubStats []StatValue `json:"sub_stats"` // The randomly rolled sub-stats (up to 4).
}
DriveDisc represents an enriched Drive Disc (artifact/equipment).
func (*DriveDisc) CountEffectiveRolls ¶
func (d *DriveDisc) CountEffectiveRolls(targetProps ...PropertyID) int
CountEffectiveRolls returns the total number of sub-stat rolls on this specific Drive Disc that match any of the provided target property IDs. Example usage for an Anomaly agent's disc:
usefulRolls := disc.CountEffectiveRolls(fairy.PropAnomalyProficiency, fairy.PropATKPercent)
type DriveDiscSetBonus ¶
type DriveDiscSetBonus struct {
Set Set `json:"set"` // The set granting the bonus.
PieceCount int `json:"piece_count"` // The number of pieces equipped from this set (typically 2 or 4).
Description string `json:"description"` // The localized HTML description of the set bonus from game data.
}
DriveDiscSetBonus represents an active set bonus from equipped Drive Discs.
type FormattedStatBreakdown ¶
type FormattedStatBreakdown struct {
Base string `json:"base"`
Added string `json:"added"`
Total string `json:"total"`
}
FormattedStatBreakdown represents a single stat broken down into its base and added components, pre-formatted as human-readable strings for UI display.
type FormattedStats ¶
type FormattedStats struct {
HP string `json:"hp"`
ATK string `json:"atk"`
DEF string `json:"def"`
Impact string `json:"impact"`
CritRate string `json:"crit_rate"`
CritDMG string `json:"crit_dmg"`
AnomalyMastery string `json:"anomaly_mastery"`
AnomalyProficiency string `json:"anomaly_proficiency"`
PenRatio string `json:"pen_ratio"`
PenFlat string `json:"pen_flat"`
EnergyRegen string `json:"energy_regen"`
}
FormattedStats contains the agent's combat stats pre-formatted as human-readable strings. This is extremely useful for UI/Frontend developers who just want to display the values. Note: JSON tags intentionally match those in UIStats for frontend consistency.
type Language ¶
type Language string
Language represents the localization language for game strings.
const ( LangEN Language = "en" // English LangRU Language = "ru" // Russian LangDE Language = "de" // German LangES Language = "es" // Spanish LangFR Language = "fr" // French LangID Language = "id" // Indonesian LangJA Language = "ja" // Japanese LangKO Language = "ko" // Korean LangPT Language = "pt" // Portuguese LangTH Language = "th" // Thai LangVI Language = "vi" // Vietnamese LangZHCN Language = "zh-cn" // Chinese (Simplified) LangZHTW Language = "zh-tw" // Chinese (Traditional) )
Supported language constants matching the in-game localizations. These determine which translation strings are pulled from the metadata store.
type Namecard ¶
type Namecard struct {
ID int `json:"id"` // The internal ID of the namecard.
URL string `json:"url"` // The URL to the namecard's background asset.
}
Namecard represents a profile background image. See: https://zenless-zone-zero.fandom.com/wiki/Namecard
type Option ¶
type Option func(*Options)
Option defines a functional option for the fairy Client.
func WithDefaultLang ¶
WithDefaultLang sets the default language for the Client.
func WithEnkaOptions ¶
WithEnkaOptions sets the underlying enkanetwork-go client options.
func WithStore ¶
func WithStore(s store.MetadataStore) Option
WithStore sets the metadata store for the Client.
type Options ¶
type Options struct {
DefaultLang Language // The default language for string localization.
Store store.MetadataStore // The store providing game metadata.
EnkaOpts zzz.Options // Configuration for the underlying enkanetwork-go client.
}
Options holds the configuration for the fairy Client.
type Profile ¶
type Profile struct {
UID string `json:"uid"` // The unique identifier of the player (typically a 9-digit string).
Nickname string `json:"nickname"` // The player's chosen nickname. Can be empty if the API returned no name.
InterknotLevel int `json:"interknot_level"` // The player's overall account level.
Region Region `json:"region"` // The server region the player belongs to.
Title *Title `json:"title"` // The active title displayed on the profile. May be nil if none is equipped.
Avatar *Avatar `json:"avatar"` // The active avatar (profile picture) displayed. May be nil.
Namecard *Namecard `json:"namecard"` // The active background namecard. May be nil.
Badges []Badge `json:"badges"` // The showcase badges selected by the player. Can be empty.
Agents []Agent `json:"agents"` // The list of agents showcased on the profile (max 6). Can be empty.
}
Profile represents the enriched user profile data. It contains player-level metadata and the showcased agents.
func GetProfile ¶
GetProfile fetches the game profile by UID and localizes it into the default language using a shared, global client.
Example ¶
package main
import (
"context"
"fmt"
"log"
"github.com/kirinyoku/fairy"
)
func main() {
// 1. You can fetch a profile directly using the package-level helper method.
// This will use a shared default client with English localization.
profile, err := fairy.GetProfile(context.Background(), "100000000")
if err != nil {
log.Fatal(err)
}
fmt.Printf("Player: %s (UID: %s)\n", profile.Nickname, profile.UID)
fmt.Printf("Level: %d | Region: %s\n", profile.InterknotLevel, profile.Region)
if len(profile.Agents) > 0 {
agent := profile.Agents[0]
fmt.Printf("Featured Agent: %s (Level %d, %s)\n", agent.Name, agent.Level, agent.AttributeName)
}
}
Output:
func GetProfileWithLang ¶
GetProfileWithLang fetches the game profile by UID and localizes it into the specified language using a shared, global client.
func Localize ¶
Localize maps a raw zzz.Profile into an enriched Profile using the specified language. It uses the global default client's metadata store for the conversion.
Example ¶
package main
import (
"context"
"fmt"
"log"
"github.com/kirinyoku/enkanetwork-go/client/zzz"
"github.com/kirinyoku/fairy"
)
func main() {
// 1. Initialize a custom client if you want to set specific options
// (e.g. setting up caching or changing the default language).
client, err := fairy.NewClient(
fairy.WithDefaultLang(fairy.LangRU), // Use Russian by default
fairy.WithEnkaOptions(zzz.Options{
UserAgent: "MyAwesomeApp/1.0",
}),
)
if err != nil {
log.Fatal(err)
}
// 2. Fetch the profile. It will be localized in Russian automatically.
profile, err := client.GetProfile(context.Background(), "100000000")
if err != nil {
log.Fatal(err)
}
fmt.Printf("Игрок: %s (Сервер: %s)\n", profile.Nickname, profile.Region)
}
Output:
type PropertyID ¶
type PropertyID int
PropertyID represents a strongly-typed ID for combat properties. The naming convention follows: - Base: The character's innate foundational stat (e.g., PropBaseHP). - Percent / PercentBonus: A percentage modifier applied to the base stat. - Flat / FlatBonus: A direct numerical addition applied after percentages.
const ( // Health properties PropBaseHP PropertyID = 11101 PropHPPercent PropertyID = 11102 PropHPFlat PropertyID = 11103 PropHPPercentBonus PropertyID = 11104 PropHPFlatBonus PropertyID = 11105 // Attack properties PropBaseATK PropertyID = 12101 PropATKPercent PropertyID = 12102 PropATKFlat PropertyID = 12103 // Defense properties PropBaseDEF PropertyID = 13101 PropDEFPercent PropertyID = 13102 PropDEFFlat PropertyID = 13103 // Impact properties PropBaseImpact PropertyID = 12201 PropImpactPercent PropertyID = 12202 PropImpactFlat PropertyID = 12203 // Critical properties PropBaseCritRate PropertyID = 20101 PropCritRate PropertyID = 20103 PropBaseCritDMG PropertyID = 21101 PropCritDMG PropertyID = 21103 // Penetration properties PropBasePENRatio PropertyID = 23101 PropPENRatio PropertyID = 23103 PropBasePENFlat PropertyID = 23201 PropPENFlat PropertyID = 23203 // Energy properties PropBaseEnergyRegen PropertyID = 30501 PropEnergyRegenPercent PropertyID = 30502 PropEnergyRegen PropertyID = 30503 // Anomaly properties PropBaseAnomalyMastery PropertyID = 31201 PropAnomalyMastery PropertyID = 31203 PropBaseAnomalyProficiency PropertyID = 31401 PropAnomalyProficiencyPercent PropertyID = 31402 PropAnomalyProficiency PropertyID = 31403 )
type Set ¶
type Set struct {
ID int `json:"id"` // The internal ID of the set.
Name string `json:"name"` // The localized name of the set (e.g., "Woodpecker Electro").
}
Set represents a specific Drive Disc equipment set. A Set grants bonus effects when an agent equips 2 or 4 pieces of the same set.
type Skill ¶
type Skill struct {
Level int `json:"level"` // The level of the skill.
Name string `json:"name"` // The localized name of the skill.
Description string `json:"description"` // The localized description of the skill.
}
Skill represents an agent's combat skill or passive ability.
type Skin ¶
type Skin struct {
ID int `json:"id"` // The internal ID of the skin.
Name string `json:"name"` // The localized name of the skin.
Description string `json:"description"` // The localized description of the skin.
SplashArtURL string `json:"splash_art_url"` // The URL to the skin's splash art.
}
Skin represents the equipped skin (outfit) of an agent.
type StatValue ¶
type StatValue struct {
PropertyID PropertyID `json:"property_id"` // The internal property ID (e.g., 12102 for ATK%).
Name string `json:"name"` // The localized name of the stat.
Value float64 `json:"value"` // The final calculated value of the stat.
IsPercent bool `json:"is_percent"` // Indicates if the stat is a percentage.
Rolls int `json:"rolls"` // The number of times this stat was upgraded (1 for base, up to 5 for max upgrades).
}
StatValue represents a single combat stat (main or sub stat).
func (StatValue) DisplayValue ¶
DisplayValue returns the stat's value formatted as a human-readable string. Percentages are multiplied by 100 and formatted with a '%' sign.
type Stats ¶
type Stats struct {
HP float64 `json:"hp"` // Total Health Points.
ATK float64 `json:"atk"` // Total Attack.
DEF float64 `json:"def"` // Total Defense.
Impact float64 `json:"impact"` // Impact (influences Daze build-up).
CritRate float64 `json:"crit_rate"` // Critical Hit Rate (as a decimal, e.g., 0.05 for 5%).
CritDMG float64 `json:"crit_dmg"` // Critical Hit Damage (as a decimal, e.g., 1.50 for 150%).
AnomalyMastery float64 `json:"anomaly_mastery"` // Anomaly Mastery (influences Anomaly Buildup rate).
AnomalyProficiency float64 `json:"anomaly_proficiency"` // Anomaly Proficiency (influences Anomaly Damage).
PenRatio float64 `json:"pen_ratio"` // Penetration Ratio (ignores a percentage of enemy DEF).
PenFlat float64 `json:"pen_flat"` // Flat Penetration (ignores a flat amount of enemy DEF).
EnergyRegen float64 `json:"energy_regen"` // Energy Regeneration rate (as a decimal, e.g., 1.20).
}
Stats represents the aggregated combat stats of an agent. This structure keeps fields minimal and flat for easy access. NOTE: Internal representation of percentages is in decimal form (e.g., CritRate 0.05 = 5%). EnergyRegen is also represented as its divided final value (e.g., 1.20). Precise calculations and final formulas are opt-in via the calc package.
func (*Stats) Formatted ¶
func (s *Stats) Formatted() FormattedStats
Formatted returns a new FormattedStats struct where all numerical stats are converted into precise, human-readable strings (e.g. "50.0%" instead of 0.5).
type Title ¶
type Title struct {
ID int `json:"id"` // The internal ID of the title.
Text string `json:"text"` // The localized text of the title.
PrimaryColor string `json:"primary_color"` // The primary color hex (without #).
SecondaryColor string `json:"secondary_color"` // The secondary color hex (without #).
}
Title represents an achievement or status title chosen by the player. Titles often have gradients represented by two hex colors. To properly display this gradient, use the PrimaryColorHex() and SecondaryColorHex() helpers. See: https://zenless-zone-zero.fandom.com/wiki/Titles
func (*Title) PrimaryColorHex ¶
PrimaryColorHex returns the primary gradient color formatted as a standard hex string (#RRGGBB).
func (*Title) SecondaryColorHex ¶
SecondaryColorHex returns the secondary gradient color formatted as a standard hex string (#RRGGBB).
type UIStats ¶
type UIStats struct {
HP FormattedStatBreakdown `json:"hp"`
ATK FormattedStatBreakdown `json:"atk"`
DEF FormattedStatBreakdown `json:"def"`
Impact FormattedStatBreakdown `json:"impact"`
CritRate FormattedStatBreakdown `json:"crit_rate"`
CritDMG FormattedStatBreakdown `json:"crit_dmg"`
AnomalyMastery FormattedStatBreakdown `json:"anomaly_mastery"`
AnomalyProficiency FormattedStatBreakdown `json:"anomaly_proficiency"`
PenRatio FormattedStatBreakdown `json:"pen_ratio"`
PenFlat FormattedStatBreakdown `json:"pen_flat"`
EnergyRegen FormattedStatBreakdown `json:"energy_regen"`
}
UIStats contains all combat stats broken down into base and added components, ready to be displayed on a frontend profile page (like Enka.Network).
type WEngine ¶
type WEngine struct {
ID int `json:"id"` // The internal ID of the W-Engine.
UID string `json:"uid"` // The unique instance ID of this specific W-Engine.
Name string `json:"name"` // The localized name of the W-Engine.
Level int `json:"level"` // The current level of the W-Engine (1-60).
Phase int `json:"phase"` // The star level from the API (ascension phase).
Modification int `json:"modification"` // The refinement/upgrade level of the passive (1-5).
Rarity Rarity `json:"rarity"` // The rarity tier (S, A, or B).
Specialty Specialty `json:"specialty"` // The intended role specialty for this W-Engine.
SpecialtyName string `json:"specialty_name"` // The localized name of the specialty.
IconURL string `json:"icon_url"` // The URL to the W-Engine's visual icon.
MainStat StatValue `json:"main_stat"` // The primary stat provided by the W-Engine.
SecondaryStat StatValue `json:"secondary_stat"` // The secondary stat provided by the W-Engine.
PassiveDescription string `json:"passive_description"` // The localized description of the passive skill. Note: Changes based on Modification phase.
}
WEngine represents an enriched W-Engine equipped by an agent.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
internal
|
|
|
api
Package api provides a thin adapter layer over the upstream enkanetwork-go client.
|
Package api provides a thin adapter layer over the upstream enkanetwork-go client. |
|
assets
Package assets provides embedded binary data for the fairy library.
|
Package assets provides embedded binary data for the fairy library. |
|
tools/extractor
command
|
|
|
Package store provides an abstraction over the Zenless Zone Zero datamined game data.
|
Package store provides an abstraction over the Zenless Zone Zero datamined game data. |