diff --git a/internal/logic/hero/hero.go b/internal/logic/hero/hero.go index d161c5b..7813953 100644 --- a/internal/logic/hero/hero.go +++ b/internal/logic/hero/hero.go @@ -148,63 +148,10 @@ func (l *Logic) GetHeroDetailByCode(ctx context.Context, code string) (*v1.HeroD allItems []dto.HeroSetItem ) //now := time.Now() - setTypeNameMap := map[string]string{ - "set_speed": "速度", - "set_cri": "暴击", - "set_revenge": "复仇", - "set_counter": "反击", - "set_vampire": "吸血", - "set_immune": "免疫", - "set_cri_dmg": "破灭", - "set_torrent": "激流", - "set_max_hp": "生命", - "set_penetrate": "穿透", - "set_scar": "伤口", - "set_shield": "护盾", - "set_def": "防御", - "set_acc": "命中", - "set_res": "抵抗", - } - isTwoSet := func(setType string) bool { - twoSet := map[string]struct{}{ - "set_acc": {}, "set_cri": {}, "set_immune": {}, "set_torrent": {}, - "set_max_hp": {}, "set_penetrate": {}, "set_def": {}, "set_res": {}, - } - _, ok := twoSet[setType] - return ok - } - isFourSet := func(setType string) bool { - fourSet := map[string]struct{}{ - "set_speed": {}, "set_cri_dmg": {}, "set_revenge": {}, "set_counter": {}, - "set_vampire": {}, "set_scar": {}, "set_shield": {}, - } - _, ok := fourSet[setType] - return ok - } for i := range heroSetData.Data { item := &heroSetData.Data[i] // 1. 解析 SetsName - var fourNames, twoNames []string - for setType, count := range item.Sets { - if isFourSet(setType) && count >= 4 { - if cn, ok := setTypeNameMap[setType]; ok { - fourNames = append(fourNames, cn) - } else { - fourNames = append(fourNames, setType) - } - } - } - for setType, count := range item.Sets { - if isTwoSet(setType) && count >= 2 { - if cn, ok := setTypeNameMap[setType]; ok { - twoNames = append(twoNames, cn) - } else { - twoNames = append(twoNames, setType) - } - } - } - allNames := append(fourNames, twoNames...) - item.SetsName = strings.Join(allNames, ",") + item.SetsName = GetSetNames(item.Sets) // 2. 累加属性 totalCp += item.Gs totalAtk += item.Atk @@ -420,8 +367,8 @@ func (l *Logic) GetHeroDetailByCode(ctx context.Context, code string) (*v1.HeroD Dac: 0, Eff: float64(item.Eff), Efr: float64(item.Efr), - Hds: "", - Ctr: "", + Hds: GetSetNames(item.Sets), + Ctr: item.CreateDate, ArfName: func() string { info := artifactInfoMap[item.ArtifactCode] if info != nil { @@ -465,3 +412,64 @@ func (l *Logic) ClearHeroCache(ctx context.Context, code string) error { return nil } + +// 公用套装名称映射和判断 +var setTypeNameMap = map[string]string{ + "set_speed": "速度", + "set_cri": "暴击", + "set_revenge": "复仇", + "set_counter": "反击", + "set_vampire": "吸血", + "set_immune": "免疫", + "set_cri_dmg": "破灭", + "set_torrent": "激流", + "set_max_hp": "生命", + "set_penetrate": "穿透", + "set_scar": "伤口", + "set_shield": "护盾", + "set_def": "防御", + "set_acc": "命中", + "set_res": "抵抗", +} + +func isTwoSet(setType string) bool { + twoSet := map[string]struct{}{ + "set_acc": {}, "set_cri": {}, "set_immune": {}, "set_torrent": {}, + "set_max_hp": {}, "set_penetrate": {}, "set_def": {}, "set_res": {}, + } + _, ok := twoSet[setType] + return ok +} +func isFourSet(setType string) bool { + fourSet := map[string]struct{}{ + "set_speed": {}, "set_cri_dmg": {}, "set_revenge": {}, "set_counter": {}, + "set_vampire": {}, "set_scar": {}, "set_shield": {}, + } + _, ok := fourSet[setType] + return ok +} + +// GetSetNames 公用方法:根据套装 map 生成套装中文名 +func GetSetNames(sets map[string]int) string { + var fourNames, twoNames []string + for setType, count := range sets { + if isFourSet(setType) && count >= 4 { + if cn, ok := setTypeNameMap[setType]; ok { + fourNames = append(fourNames, cn) + } else { + fourNames = append(fourNames, setType) + } + } + } + for setType, count := range sets { + if isTwoSet(setType) && count >= 2 { + if cn, ok := setTypeNameMap[setType]; ok { + twoNames = append(twoNames, cn) + } else { + twoNames = append(twoNames, setType) + } + } + } + allNames := append(fourNames, twoNames...) + return strings.Join(allNames, ",") +}