package common import ( "encoding/json" "fmt" "slices" ) type CurrencyWarsAugmentGrant struct { Kind string `json:"kind"` Count uint32 `json:"count"` ID uint32 `json:"id,omitempty"` Cost uint32 `json:"cost,omitempty"` Star uint32 `json:"star,omitempty"` } type CurrencyWarsAugment struct { ID uint32 `json:"id"` Quality uint32 `json:"quality"` Chapters []uint32 `json:"chapters"` OC bool `json:"oc"` Grants []CurrencyWarsAugmentGrant `json:"grants"` GrantsComplete bool `json:"grants_complete"` } type CurrencyWarsAugmentsCatalog struct { FormatVersion uint32 `json:"format_version"` TargetClientVersion string `json:"target_client_version"` TargetAssemblySHA256 string `json:"target_assembly_sha256"` SeasonID uint32 `json:"season_id"` Augments []CurrencyWarsAugment `json:"augments"` byID map[uint32]CurrencyWarsAugment } func LoadCurrencyWarsAugments(catalog *CurrencyWarsCatalog) (*CurrencyWarsAugmentsCatalog, error) { raw, err := ReadResourceFile("resources/CurrencyWarsAugments.json") if err != nil { return nil, err } var out CurrencyWarsAugmentsCatalog if err = json.Unmarshal(raw, &out); err != nil { return nil, err } if catalog != nil { if out.FormatVersion != 1 || out.TargetClientVersion != catalog.ClientVersion || out.TargetAssemblySHA256 != catalog.Provenance.GameAssemblySHA256 { return nil, fmt.Errorf("CW augments revision differs from catalog") } } out.byID = make(map[uint32]CurrencyWarsAugment, len(out.Augments)) for _, a := range out.Augments { out.byID[a.ID] = a } return &out, nil } func (c *CurrencyWarsAugmentsCatalog) Augment(id uint32) (CurrencyWarsAugment, bool) { if c == nil || c.byID == nil { return CurrencyWarsAugment{}, false } a, ok := c.byID[id] return a, ok } func (c *CurrencyWarsAugmentsCatalog) IsEligible(aug CurrencyWarsAugment, chapter uint32, isOverclock bool) bool { if isOverclock && !aug.OC { return false } if len(aug.Chapters) > 0 && !slices.Contains(aug.Chapters, chapter) { return false } return true }