package catalogs import ( "encoding/json" "os" "path/filepath" "sync" ) var _ = json.RawMessage{} var _ = sync.Mutex{} var _ = os.ReadFile var _ = filepath.Join // One commodity as the server restocks it, from Configs/NpcShopCatalog.json. type NpcShopCommodity4229938 struct { TemplateId uint32 `json:"templateId"` Price uint32 `json:"price"` LimitNum int32 `json:"limitNum"` LimitOnceNum uint32 `json:"limitOnceNum"` ConsumableId uint32 `json:"consumableId"` Currency uint32 `json:"currency"` } // One shop and the flat list of commodities it sells. type NpcShop4229938 struct { ShopId uint32 `json:"shopId"` Name string `json:"name"` Commodities []NpcShopCommodity4229938 `json:"commodities"` } // // Reads Configs/NpcShopCatalog.json — a projection of the official ShopConfig / // ShopCommodityGroupConfig / ShopCommodityConfig triple (see _gen_shop_catalog.py). // The client owns the same three tables, so this catalog deliberately carries only what a // server has to decide: which commodity ids are on the shelf and what they cost. Names, icons, // quality and descriptions stay client-side, which is why the projection is 0.9 MB instead of // the 3.3 MB of source tables. // A missing or malformed file is not fatal: the catalog turns empty and LoadError // explains why, so AskNpcShop can answer OK without pushing a shelf instead of throwing. // var ( NpcShopCatalog4229938_cacheLock sync.RWMutex NpcShopCatalog4229938_cached = false NpcShopCatalog4229938_entries []any ) // LoadNpcShopCatalog4229938 loads catalog records from client config directory func LoadNpcShopCatalog4229938(configDir string) ([]any, error) { NpcShopCatalog4229938_cacheLock.RLock() if NpcShopCatalog4229938_cached { defer NpcShopCatalog4229938_cacheLock.RUnlock() return NpcShopCatalog4229938_entries, nil } NpcShopCatalog4229938_cacheLock.RUnlock() NpcShopCatalog4229938_cacheLock.Lock() defer NpcShopCatalog4229938_cacheLock.Unlock() if NpcShopCatalog4229938_cached { return NpcShopCatalog4229938_entries, nil } filePath := filepath.Join(configDir, "NpcShopCatalog.json.json") data, err := os.ReadFile(filePath) if err != nil { return nil, err } var raw struct { Records []json.RawMessage `json:"records"` } if err := json.Unmarshal(data, &raw); err != nil { return nil, err } var result []any for _, item := range raw.Records { var m map[string]any if err := json.Unmarshal(item, &m); err == nil { result = append(result, m) } } NpcShopCatalog4229938_entries = result NpcShopCatalog4229938_cached = true return result, nil } func NpcShopCatalog4229938_TryGetShop(shopId uint32, shop NpcShop4229938) bool { // Catalog helper NpcShopCatalog4229938_TryGetShop return false }