192 lines
5.5 KiB
Go
192 lines
5.5 KiB
Go
package smithy
|
|
|
|
import (
|
|
"go_dreamfactory/lego/core"
|
|
"go_dreamfactory/lego/sys/log"
|
|
"go_dreamfactory/modules"
|
|
"go_dreamfactory/sys/configure"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
"sync"
|
|
)
|
|
|
|
const (
|
|
game_smithy = "game_smithy.json"
|
|
game_smithystoveold = "game_smithystove.json"
|
|
|
|
game_smithyreel = "game_newsmithy.json" // 新版铁匠铺卷轴
|
|
game_smproficiency = "game_smithyproficiency.json" // 铁匠铺熟练度
|
|
game_smithystove = "game_smithystovev1.json" // 铁匠铺台子 打造配置
|
|
game_smithytools = "game_smithytool.json" // 铁匠铺工具台
|
|
)
|
|
|
|
///配置管理基础组件
|
|
type configureComp struct {
|
|
modules.MCompConfigure
|
|
module *Smithy
|
|
hlock sync.RWMutex
|
|
_smithyMap map[int64]*cfg.GameSmithyData
|
|
|
|
_mapProficile map[int64]*cfg.GameSmithyProficiencyData // 熟练度 key 卷轴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)
|
|
this.module = module.(*Smithy)
|
|
this._smithyMap = make(map[int64]*cfg.GameSmithyData, 0)
|
|
configure.RegisterConfigure(game_smithy, cfg.NewGameSmithy, func() {
|
|
if v, err := this.GetConfigure(game_smithy); err == nil {
|
|
if configure, ok := v.(*cfg.GameSmithy); ok {
|
|
this.hlock.Lock()
|
|
defer this.hlock.Unlock()
|
|
for _, value := range configure.GetDataList() {
|
|
this._smithyMap[int64(value.Type<<16)+int64(value.Star)] = value
|
|
}
|
|
return
|
|
}
|
|
}
|
|
log.Errorf("get game_pagoda conf err:%v", err)
|
|
return
|
|
})
|
|
|
|
this._mapProficile = make(map[int64]*cfg.GameSmithyProficiencyData, 0)
|
|
configure.RegisterConfigure(game_smproficiency, cfg.NewGameSmithyProficiency, this.LoadProficileData)
|
|
err = this.LoadConfigure(game_smithyreel, cfg.NewGameSmithyStove)
|
|
err = this.LoadConfigure(game_smithystove, cfg.NewGameSmithyStoveV1)
|
|
err = this.LoadConfigure(game_smithytools, cfg.NewGameSmithyTool)
|
|
err = this.LoadConfigure(game_smithystoveold, cfg.NewGameSmithyStove)
|
|
|
|
return
|
|
}
|
|
|
|
func (this *configureComp) GetSmithyConfigData(smithyType int32, level int32) (data *cfg.GameSmithyData) {
|
|
|
|
return this._smithyMap[int64(smithyType<<16)+int64(level)]
|
|
}
|
|
func (this *configureComp) GetSmithyTypeConfigData() (mapType map[int32]struct{}) {
|
|
mapType = make(map[int32]struct{}, 0)
|
|
if v, err := this.GetConfigure(game_smithy); err == nil {
|
|
if configure, ok := v.(*cfg.GameSmithy); ok {
|
|
for _, v1 := range configure.GetDataList() {
|
|
if _, ok := mapType[v1.Type]; !ok {
|
|
mapType[v1.Type] = struct{}{}
|
|
}
|
|
}
|
|
return
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
// 获取炉子配置数据
|
|
func (this *configureComp) GetSmithyStoveConfigData(level int32) (data *cfg.GameSmithyStoveData) {
|
|
if v, err := this.GetConfigure(game_smithystoveold); err == nil {
|
|
if configure, ok := v.(*cfg.GameSmithyStove); ok {
|
|
data = configure.Get(int32(level))
|
|
return
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
//加载多个配置文件
|
|
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) GetSmithyReelConfigData(id int32) (data *cfg.GameNewSmithyData) {
|
|
if v, err := this.GetConfigure(game_smithyreel); err == nil {
|
|
if configure, ok := v.(*cfg.GameNewSmithy); ok {
|
|
data = configure.Get(int32(id))
|
|
return
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
func (this *configureComp) CheckSmithyFirstReelConfigData(etype int32, id int32) bool {
|
|
if v, err := this.GetConfigure(game_smithyreel); err == nil {
|
|
if configure, ok := v.(*cfg.GameNewSmithy); ok {
|
|
for _, v := range configure.GetDataList() {
|
|
if v.Type == etype {
|
|
if v.Id == id {
|
|
return true
|
|
} else {
|
|
return false
|
|
}
|
|
}
|
|
}
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
// 获取铁匠铺熟练度数据
|
|
func (this *configureComp) GetSmithProficiencyConf(id int32) (data *cfg.GameSmithyProficiencyData) {
|
|
if v, err := this.GetConfigure(game_smproficiency); err == nil {
|
|
if configure, ok := v.(*cfg.GameSmithyProficiency); ok {
|
|
data = configure.Get(int32(id))
|
|
return
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
func (this *configureComp) LoadProficileData() {
|
|
|
|
if v, err := this.GetConfigure(game_smproficiency); err == nil {
|
|
if configure, ok := v.(*cfg.GameSmithyProficiency); ok {
|
|
this.hlock.Lock()
|
|
defer this.hlock.Unlock()
|
|
for _, value := range configure.GetDataList() {
|
|
this._mapProficile[int64(value.ReelId<<16)+int64(value.ProficiencyLv)] = value
|
|
}
|
|
return
|
|
}
|
|
} else {
|
|
log.Errorf("get game_pagoda conf err:%v", err)
|
|
|
|
}
|
|
return
|
|
}
|
|
|
|
func (this *configureComp) GetSmithyProficileData(reelid int32, proficile int32) *cfg.GameSmithyProficiencyData {
|
|
return this._mapProficile[int64(reelid<<16)+int64(proficile)]
|
|
}
|
|
|
|
// 获取铁匠铺工作台信息
|
|
func (this *configureComp) GetSmithyStoveConf(star int32) (data *cfg.GameSmithyStoveV1Data) {
|
|
if v, err := this.GetConfigure(game_smithystove); err == nil {
|
|
if configure, ok := v.(*cfg.GameSmithyStoveV1); ok {
|
|
data = configure.Get(int32(star))
|
|
return
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
// 获取铁匠铺工作台信息
|
|
func (this *configureComp) GetSmithyStoveConf1(id int32) (data *cfg.GameSmithyToolData) {
|
|
if v, err := this.GetConfigure(game_smithytools); err == nil {
|
|
if configure, ok := v.(*cfg.GameSmithyTool); ok {
|
|
data = configure.Get(int32(id))
|
|
return
|
|
}
|
|
}
|
|
return
|
|
}
|