295 lines
9.2 KiB
Go
295 lines
9.2 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" // 铁匠铺工具台
|
|
game_smithycustomer = "game_smithycustomer.json"
|
|
game_smithyatlas = "game_smithyatlas.json" // 收藏图鉴
|
|
game_smithyatlaslv = "game_smithyatlaslv.json" // 收藏等级积分
|
|
game_smithyatlasscore = "game_smithyatlasscore.json" // 图鉴积分
|
|
)
|
|
|
|
// /配置管理基础组件
|
|
type configureComp struct {
|
|
modules.MCompConfigure
|
|
module *Smithy
|
|
hlock sync.RWMutex
|
|
_smithyMap map[int64]*cfg.GameSmithyData
|
|
|
|
_mapProficile map[int64]*cfg.GameSmithyProficiencyData // 熟练度 key 卷轴ID+ 等级
|
|
_mapskill map[int64]*cfg.GameSmithyToolData // 熟练度 key 技能类型+ 技能等级等级
|
|
_mapAtlasScore map[int64]*cfg.GameSmithyAtlasScoreData // 图鉴积分
|
|
}
|
|
|
|
// 组件初始化接口
|
|
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)
|
|
this._mapskill = make(map[int64]*cfg.GameSmithyToolData, 0)
|
|
configure.RegisterConfigure(game_smithytools, cfg.NewGameSmithyTool, this.LoadSmithySkillData)
|
|
|
|
this._mapAtlasScore = make(map[int64]*cfg.GameSmithyAtlasScoreData, 0)
|
|
configure.RegisterConfigure(game_smithyatlasscore, cfg.NewGameSmithyAtlasScore, this.LoadSmithyAtlasScoreConf)
|
|
err = this.LoadConfigure(game_smithyreel, cfg.NewGameNewSmithy)
|
|
err = this.LoadConfigure(game_smithystove, cfg.NewGameSmithyStoveV1)
|
|
err = this.LoadConfigure(game_smithytools, cfg.NewGameSmithyTool)
|
|
err = this.LoadConfigure(game_smithystoveold, cfg.NewGameSmithyStove)
|
|
err = this.LoadConfigure(game_smithycustomer, cfg.NewGameSmithyCustomer)
|
|
err = this.LoadConfigure(game_smithyatlas, cfg.NewGameSmithyAtlas)
|
|
err = this.LoadConfigure(game_smithyatlaslv, cfg.NewGameSmithyAtlasLv)
|
|
err = this.LoadConfigure(game_smithyatlasscore, cfg.NewGameSmithyAtlasScore)
|
|
|
|
_d := this.GetSmithProficiencyConf(1)
|
|
this.module.Errorf("%v", _d)
|
|
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) GetSmithySkill(skillType int32, skillLv int32) *cfg.GameSmithyToolData {
|
|
return this._mapskill[int64(skillType<<16)+int64(skillLv)]
|
|
}
|
|
|
|
func (this *configureComp) LoadSmithySkillData() {
|
|
if v, err := this.GetConfigure(game_smithytools); err == nil {
|
|
if configure, ok := v.(*cfg.GameSmithyTool); ok {
|
|
this.hlock.Lock()
|
|
defer this.hlock.Unlock()
|
|
for _, value := range configure.GetDataList() {
|
|
this._mapskill[int64(value.SkillType<<16)+int64(value.SkillLv)] = value
|
|
}
|
|
return
|
|
}
|
|
} else {
|
|
log.Errorf("get LoadSmithySkillData conf err:%v", err)
|
|
|
|
}
|
|
}
|
|
|
|
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) GetSmithyCustomerConfList() (data []*cfg.GameSmithyCustomerData) {
|
|
if v, err := this.GetConfigure(game_smithycustomer); err == nil {
|
|
if conf, ok := v.(*cfg.GameSmithyCustomer); ok {
|
|
data = conf.GetDataList()
|
|
return
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
func (this *configureComp) GetSmithyCustomerConf(id int32) *cfg.GameSmithyCustomerData {
|
|
if v, err := this.GetConfigure(game_smithycustomer); err == nil {
|
|
if configure, ok := v.(*cfg.GameSmithyCustomer); ok {
|
|
return configure.GetDataMap()[id]
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// 获取铁匠铺工作台信息
|
|
func (this *configureComp) GetSmithyToolsData(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
|
|
|
|
}
|
|
}
|
|
this.module.Errorf("GetSmithyToolsData notfound id:%d", id)
|
|
return nil
|
|
}
|
|
|
|
func (this *configureComp) GetSmithyStoveConf(level int32) (data *cfg.GameSmithyStoveV1Data) {
|
|
if v, err := this.GetConfigure(game_smithystove); err == nil {
|
|
if configure, ok := v.(*cfg.GameSmithyStoveV1); ok {
|
|
data = configure.Get(int32(level))
|
|
return
|
|
}
|
|
}
|
|
this.module.Errorf("GetSmithyStoveConf notfound level:%d", level)
|
|
return
|
|
}
|
|
|
|
// 获取图鉴信息
|
|
func (this *configureComp) GetSmithyAtlasConf(id string) (data *cfg.GameSmithyAtlasData) {
|
|
if v, err := this.GetConfigure(game_smithystove); err == nil {
|
|
if configure, ok := v.(*cfg.GameSmithyAtlas); ok {
|
|
data = configure.Get(id)
|
|
return
|
|
}
|
|
}
|
|
this.module.Errorf("GetSmithyAtlasConf notfound id:%d", id)
|
|
return
|
|
}
|
|
|
|
func (this *configureComp) GetSmithyAtlasLvConf(lv int32) (data *cfg.GameSmithyAtlasLvData) {
|
|
if v, err := this.GetConfigure(game_smithystove); err == nil {
|
|
if configure, ok := v.(*cfg.GameSmithyAtlasLv); ok {
|
|
data = configure.Get(lv)
|
|
return
|
|
}
|
|
}
|
|
this.module.Errorf("GetSmithyAtlasLvConf notfound lv:%d", lv)
|
|
return
|
|
}
|
|
|
|
func (this *configureComp) GetSmithyAtlasScoreConf(quality int32, lv int32) (data *cfg.GameSmithyAtlasScoreData) {
|
|
return this._mapAtlasScore[int64(quality<<16)+int64(lv)]
|
|
}
|
|
|
|
// 获取图鉴分数
|
|
func (this *configureComp) LoadSmithyAtlasScoreConf() {
|
|
if v, err := this.GetConfigure(game_smithystove); err == nil {
|
|
if configure, ok := v.(*cfg.GameSmithyAtlasScore); ok {
|
|
this.hlock.Lock()
|
|
defer this.hlock.Unlock()
|
|
for _, value := range configure.GetDataList() {
|
|
this._mapAtlasScore[int64(value.Quality<<16)+int64(value.Lv)] = value
|
|
}
|
|
return
|
|
}
|
|
} else {
|
|
log.Errorf("get LoadSmithyAtlasScoreConf conf err:%v", err)
|
|
}
|
|
}
|