优化代码

This commit is contained in:
flswld
2023-03-12 02:08:15 +08:00
parent 3bcdf75448
commit 8c1dedc472
20 changed files with 407 additions and 296 deletions
-30
View File
@@ -6,7 +6,6 @@ import (
"hk4e/pkg/logger"
"github.com/jszwec/csvutil"
"github.com/mroth/weightedrand"
)
// ReliquaryAffixData 圣遗物追加属性配置表
@@ -46,35 +45,6 @@ func GetReliquaryAffixDataByDepotIdAndPropId(appendPropDepotId int32, appendProp
return value[appendPropId]
}
func GetReliquaryAffixDataRandomByDepotId(appendPropDepotId int32, excludeTypeList ...uint32) *ReliquaryAffixData {
appendPropMap, exist := CONF.ReliquaryAffixDataMap[appendPropDepotId]
if !exist {
return nil
}
choices := make([]weightedrand.Choice, 0, len(appendPropMap))
for _, data := range appendPropMap {
isBoth := false
// 排除列表中的属性类型是否相同
for _, propType := range excludeTypeList {
if propType == uint32(data.PropType) {
isBoth = true
break
}
}
if isBoth {
continue
}
choices = append(choices, weightedrand.NewChoice(data, uint(data.RandomWeight)))
}
chooser, err := weightedrand.NewChooser(choices...)
if err != nil {
logger.Error("reliquary append random error: %v", err)
return nil
}
result := chooser.Pick()
return result.(*ReliquaryAffixData)
}
func GetReliquaryAffixDataMap() map[int32]map[int32]*ReliquaryAffixData {
return CONF.ReliquaryAffixDataMap
}