141 lines
4.2 KiB
Go
141 lines
4.2 KiB
Go
package library
|
|
|
|
import (
|
|
"fmt"
|
|
"go_dreamfactory/lego/core"
|
|
"go_dreamfactory/lego/sys/log"
|
|
"go_dreamfactory/modules"
|
|
"go_dreamfactory/sys/configure"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
)
|
|
|
|
const (
|
|
game_libraryhero = "game_libraryhero.json" // 英雄对应的羁绊id信息
|
|
game_libraryfetter = "game_libraryfetter.json" // 羁绊信息表
|
|
game_libraryhistory = "game_libraryhistory.json" // 往事id 对应的奖励
|
|
game_libraryfavor = "game_libraryfavor.json" // 英雄好感度升级所需的经验
|
|
game_librarystory = "game_librarystory.json" // 羁绊id对应剧情奖励
|
|
game_favornum = "game_favornum.json" // 羁绊id对应经验
|
|
)
|
|
|
|
///配置管理基础组件
|
|
type configureComp struct {
|
|
modules.MCompConfigure
|
|
fetter map[int64]*cfg.GameLibraryFetterData
|
|
}
|
|
|
|
//组件初始化接口
|
|
func (this *configureComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
|
|
err = this.MCompConfigure.Init(service, module, comp, options)
|
|
err = this.LoadMultiConfigure(map[string]interface{}{
|
|
game_libraryhero: cfg.NewGameLibraryHero,
|
|
game_libraryhistory: cfg.NewGameLibraryHistory,
|
|
game_libraryfavor: cfg.NewGameLibraryFavor,
|
|
game_librarystory: cfg.NewGameLibraryStory,
|
|
game_favornum: cfg.NewGameFavorNum,
|
|
})
|
|
|
|
this.fetter = make(map[int64]*cfg.GameLibraryFetterData, 0)
|
|
|
|
configure.RegisterConfigure(game_libraryfetter, cfg.NewGameLibraryFetter, this.SetLibraryFetter)
|
|
|
|
_data := this.GetFavorNum("10016")
|
|
fmt.Printf("%v", _data)
|
|
_data1 := this.GetLibraryFavor(3)
|
|
fmt.Printf("%v", _data1)
|
|
// _data2 := this.GetLibraryHistory("350011")
|
|
// fmt.Printf("%v", _data2)
|
|
return
|
|
}
|
|
|
|
func (this *configureComp) SetLibraryFetter() {
|
|
if v, err := this.GetConfigure(game_libraryfetter); err == nil {
|
|
if _configure, ok := v.(*cfg.GameLibraryFetter); ok {
|
|
for _, v := range _configure.GetDataList() {
|
|
this.fetter[int64(v.Fid<<8)+int64(v.Favorlv)] = v
|
|
}
|
|
return
|
|
}
|
|
} else {
|
|
err = fmt.Errorf("%T no is *cfg.GameLibraryFetter", v)
|
|
}
|
|
}
|
|
func (this *configureComp) GetLibraryFetter(fid, favorlv int32) (data *cfg.GameLibraryFetterData) {
|
|
return this.fetter[int64(fid<<8)+int64(favorlv)]
|
|
}
|
|
|
|
//加载多个配置文件
|
|
func (this *configureComp) LoadMultiConfigure(confs map[string]interface{}) (err error) {
|
|
for k, v := range confs {
|
|
err = configure.RegisterConfigure(k, v, nil)
|
|
if err != nil {
|
|
log.Errorf("配置文件:%s解析失败!", k)
|
|
break
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
//读取配置数据
|
|
func (this *configureComp) GetConfigure(name string) (v interface{}, err error) {
|
|
return configure.GetConfigure(name)
|
|
}
|
|
|
|
func (this *configureComp) GetLibraryHero(hid string) (data *cfg.GameLibraryHeroData) {
|
|
if v, err := this.GetConfigure(game_libraryhero); err == nil {
|
|
if configure, ok := v.(*cfg.GameLibraryHero); ok {
|
|
data = configure.Get(hid)
|
|
}
|
|
} else {
|
|
log.Errorf("get GetLibraryHero conf err:%v", err)
|
|
}
|
|
return
|
|
}
|
|
|
|
func (this *configureComp) GetLibraryFavor(star int32) (data []int32) {
|
|
if v, err := this.GetConfigure(game_libraryfavor); err == nil {
|
|
if configure, ok := v.(*cfg.GameLibraryFavor); ok {
|
|
for _, v := range configure.GetDataList() {
|
|
data = append(data, v.Expneed)
|
|
}
|
|
}
|
|
} else {
|
|
log.Errorf("GetLibraryFavor conf err:%v", err)
|
|
}
|
|
return
|
|
}
|
|
|
|
func (this *configureComp) GetLibraryHistory(id string) (data *cfg.GameLibraryHistoryData) {
|
|
if v, err := this.GetConfigure(game_libraryhistory); err == nil {
|
|
if configure, ok := v.(*cfg.GameLibraryHistory); ok {
|
|
data = configure.Get(id)
|
|
}
|
|
} else {
|
|
log.Errorf("GetLibraryHistory conf err:%v", err)
|
|
}
|
|
return
|
|
}
|
|
|
|
func (this *configureComp) GetLibraryStory(fid int32) (data *cfg.GameLibraryStoryData) {
|
|
if v, err := this.GetConfigure(game_librarystory); err == nil {
|
|
if configure, ok := v.(*cfg.GameLibraryStory); ok {
|
|
data = configure.Get(fid)
|
|
}
|
|
} else {
|
|
log.Errorf("GetLibraryStory conf err:%v", err)
|
|
}
|
|
return
|
|
}
|
|
|
|
// 获取羁绊英雄经验数据
|
|
func (this *configureComp) GetFavorNum(cid string) (data *cfg.GameFavorNumData) {
|
|
if v, err := this.GetConfigure(game_favornum); err == nil {
|
|
if configure, ok := v.(*cfg.GameFavorNum); ok {
|
|
data = configure.Get(cid)
|
|
}
|
|
} else {
|
|
log.Errorf("GetLibraryStory conf err:%v", err)
|
|
}
|
|
return
|
|
}
|