mirror of
https://github.com/FlourishingWorld/hk4e.git
synced 2026-03-01 00:35:36 +08:00
圣遗物追加词条初步
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
package gdconf
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"hk4e/pkg/logger"
|
||||
|
||||
"github.com/jszwec/csvutil"
|
||||
"github.com/mroth/weightedrand"
|
||||
)
|
||||
|
||||
// ReliquaryAffixData 圣遗物追加属性配置表
|
||||
type ReliquaryAffixData struct {
|
||||
AppendPropId int32 `csv:"AppendPropId"` // 追加属性ID
|
||||
AppendPropDepotId int32 `csv:"AppendPropDepotId,omitempty"` // 追加属性库ID
|
||||
PropType int32 `csv:"PropType,omitempty"` // 属性类别
|
||||
RandomWeight int32 `csv:"RandomWeight,omitempty"` // 随机权重
|
||||
}
|
||||
|
||||
func (g *GameDataConfig) loadReliquaryAffixData() {
|
||||
g.ReliquaryAffixDataMap = make(map[int32]map[int32]*ReliquaryAffixData)
|
||||
data := g.readCsvFileData("ReliquaryAffixData.csv")
|
||||
var reliquaryAffixDataList []*ReliquaryAffixData
|
||||
err := csvutil.Unmarshal(data, &reliquaryAffixDataList)
|
||||
if err != nil {
|
||||
info := fmt.Sprintf("parse file error: %v", err)
|
||||
panic(info)
|
||||
}
|
||||
for _, reliquaryAffixData := range reliquaryAffixDataList {
|
||||
// 通过主属性库ID找到
|
||||
_, ok := g.ReliquaryAffixDataMap[reliquaryAffixData.AppendPropDepotId]
|
||||
if !ok {
|
||||
g.ReliquaryAffixDataMap[reliquaryAffixData.AppendPropDepotId] = make(map[int32]*ReliquaryAffixData)
|
||||
}
|
||||
// list -> map
|
||||
g.ReliquaryAffixDataMap[reliquaryAffixData.AppendPropDepotId][reliquaryAffixData.AppendPropId] = reliquaryAffixData
|
||||
}
|
||||
logger.Info("ReliquaryAffixData count: %v", len(g.ReliquaryAffixDataMap))
|
||||
}
|
||||
|
||||
func GetReliquaryAffixDataByDepotIdAndPropId(appendPropDepotId int32, appendPropId int32) *ReliquaryAffixData {
|
||||
value, exist := CONF.ReliquaryAffixDataMap[appendPropDepotId]
|
||||
if !exist {
|
||||
return nil
|
||||
}
|
||||
return value[appendPropId]
|
||||
}
|
||||
|
||||
func GetReliquaryAffixDataRandomByDepotId(appendPropDepotId int32) *ReliquaryAffixData {
|
||||
appendPropMap, exist := CONF.ReliquaryAffixDataMap[appendPropDepotId]
|
||||
if !exist {
|
||||
return nil
|
||||
}
|
||||
choices := make([]weightedrand.Choice, 0, len(appendPropMap))
|
||||
for _, data := range appendPropMap {
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user