package library import ( "fmt" "go_dreamfactory/comm" "go_dreamfactory/lego/core" "go_dreamfactory/lego/sys/log" "go_dreamfactory/modules" "go_dreamfactory/sys/configure" cfg "go_dreamfactory/sys/configure/structs" "strconv" "sync" ) 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_librarycomplot = "game_librarycomplot.json" game_favorability = "game_favorability.json" // 好感度 game_friends = "game_friends.json" // 好感度 ) ///配置管理基础组件 type configureComp struct { modules.MCompConfigure hlock sync.RWMutex favorability map[string]*cfg.GameFavorabilityData favorLvExp map[string][]int32 // key 英雄id value 每级升级所需要的经验值 friend map[int64][]*cfg.GameFriendsData heroFetter map[string]map[int32]int32 // key 英雄id value 羁绊id } //组件初始化接口 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) configure.RegisterConfigure(game_favorability, cfg.NewGameFavorability, this.SetFavorability) configure.RegisterConfigure(game_friends, cfg.NewGameFriends, this.SetFriendData) return } func (this *configureComp) SetFavorability() { if v, err := this.GetConfigure(game_favorability); err == nil { this.hlock.Lock() defer this.hlock.Unlock() this.favorability = make(map[string]*cfg.GameFavorabilityData, 0) this.favorLvExp = make(map[string][]int32) if _configure, ok := v.(*cfg.GameFavorability); ok { for _, v1 := range _configure.GetDataList() { lv := strconv.Itoa(int(v1.FavorLv)) this.favorLvExp[v1.Hid] = append(this.favorLvExp[v1.Hid], v1.FavorExp) this.favorability[v1.Hid+"-"+lv] = v1 } return } } else { err = fmt.Errorf("%T no is *cfg.SetFavorability", err) } } func (this *configureComp) GetFavorability(hid string, lv int32) (conf *cfg.GameFavorabilityData, err error) { var ( ok bool par interface{} ) if conf, ok = this.favorability[hid+"-"+strconv.Itoa(int(lv))]; !ok { par = fmt.Errorf("hid:%s,lv:%d", hid, lv) err = comm.NewNotFoundConfErr("hero", game_favorability, par) } return } func (this *configureComp) SetFriendData() { if v, err := this.GetConfigure(game_friends); err == nil { this.hlock.Lock() defer this.hlock.Unlock() this.friend = make(map[int64][]*cfg.GameFriendsData, 0) this.heroFetter = make(map[string]map[int32]int32) if _configure, ok := v.(*cfg.GameFriends); ok { for _, v1 := range _configure.GetDataList() { key := int64(v1.FriendId)<<8 + int64(v1.FriendsLv) this.friend[key] = append(this.friend[key], v1) if _, ok := this.heroFetter[v1.Hid]; !ok { this.heroFetter[v1.Hid] = make(map[int32]int32, 0) } this.heroFetter[v1.Hid][v1.FriendId] = 1 } } } else { err = fmt.Errorf("%T no is *cfg.SetFavorability", err) } return } // id:羁绊id lv 羁绊等级 func (this *configureComp) GetFriendData(id int32, lv int32) (conf []*cfg.GameFriendsData, err error) { var ( ok bool par interface{} ) if conf, ok = this.friend[int64(id)<<8+int64(lv)]; !ok { par = fmt.Errorf("hid:%d,lv:%d", id, lv) err = comm.NewNotFoundConfErr("hero", game_friends, par) } return } // 通过英雄获取当前英雄的所有羁绊ID func (this *configureComp) GetHeroFetterID(hid string) map[int32]int32 { return this.heroFetter[hid] } //加载多个配置文件 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) GetFavorabilityExp(hid string) (conf []int32, err error) { var ( ok bool ) if conf, ok = this.favorLvExp[hid]; !ok { err = comm.NewNotFoundConfErr("hero", game_favorability, hid) } return }