-
Notifications
You must be signed in to change notification settings - Fork 15
/
eiafx.go
130 lines (108 loc) · 3.62 KB
/
eiafx.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
package eiafx
import (
_ "embed"
"encoding/json"
"github.com/pkg/errors"
"github.com/fanaticscripter/EggContractor/api"
)
//go:embed eiafx-data.json
var _eiafxDataJSON []byte
var Data *Store
type Store struct {
Schema string `json:"$schema"`
ArtifactFamilies []*Family `json:"artifact_families"`
}
type Family struct {
CoreFamily
Effect string `json:"effect"`
EffectTarget string `json:"effect_target"`
Tiers []*Tier `json:"tiers"`
}
type CoreFamily struct {
Id string `json:"id"`
AfxId api.ArtifactSpec_Name `json:"afx_id"`
Name string `json:"name"`
AfxType api.ArtifactSpec_Type `json:"afx_type"`
Type string `json:"type"`
SortKey uint32 `json:"sort_key"`
ChildAfxIds []api.ArtifactSpec_Name `json:"child_afx_ids"`
}
type Tier struct {
Family *CoreFamily `json:"family"`
CoreTier
Quality float64 `json:"quality"`
Craftable bool `json:"craftable"`
BaseCraftingPrices []float64 `json:"base_crafting_prices"`
HasRarities bool `json:"has_rarities"`
PossibleAfxRarities []api.ArtifactSpec_Rarity `json:"possible_afx_rarities"`
HasEffects bool `json:"has_effects"`
AvailableFromMissions bool `json:"available_from_missions"`
Effects []*Effect `json:"effects"`
Recipe *Recipe `json:"recipe"`
IngredientsAvailableFromMissions bool `json:"ingredients_available_from_missions"`
HardDependencies []Ingredient `json:"hard_dependencies"`
}
type CoreTier struct {
ItemIdentifiers
TierNumber int `json:"tier_number"`
TierName string `json:"tier_name"`
AfxType api.ArtifactSpec_Type `json:"afx_type"`
Type string `json:"type"`
IconFilename string `json:"icon_filename"`
}
type ItemIdentifiers struct {
Id string `json:"id"`
AfxId api.ArtifactSpec_Name `json:"afx_id"`
AfxLevel api.ArtifactSpec_Level `json:"afx_level"`
Name string `json:"name"`
}
type Effect struct {
AfxRarity api.ArtifactSpec_Rarity `json:"afx_rarity"`
Rarity string `json:"rarity"`
Effect string `json:"effect"`
EffectTarget string `json:"effect_target"`
EffectSize string `json:"effect_size"`
FamilyEffect string `json:"family_effect"`
// May be null (for stones).
Slots *uint32 `json:"slots"`
}
type Recipe struct {
Ingredients []Ingredient `json:"ingredients"`
CraftingPrice CraftingPrice `json:"crafting_price"`
}
type Ingredient struct {
CoreTier
Count uint32 `json:"count"`
}
type CraftingPrice struct {
Base float64 `json:"base"`
Low float64 `json:"low"`
Domain uint32 `json:"domain"`
Curve float64 `json:"curve"`
Initial uint32 `json:"initial"`
Minimum uint32 `json:"minimum"`
}
func LoadData() error {
Data = &Store{}
err := json.Unmarshal(_eiafxDataJSON, Data)
if err != nil {
return errors.Wrap(err, "error unmarshalling eiafx-data.json")
}
return nil
}
func GetTier(spec *api.ArtifactSpec) (*Tier, error) {
afxId := spec.Name
afxLevel := spec.Level
familyAfxId := spec.Family()
for _, f := range Data.ArtifactFamilies {
if f.AfxId == familyAfxId {
for _, t := range f.Tiers {
if t.AfxId == afxId && t.AfxLevel == afxLevel {
return t, nil
}
}
break
}
}
return nil, errors.Errorf("artifact (%s, %s) not found in data.json", afxId, afxLevel)
}