go_dreamfactory/modules/smithy/comp_configure.go
2023-06-09 21:55:06 +08:00

335 lines
10 KiB
Go

package smithy
import (
"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"
"sync"
)
var moduleName = "smithy"
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" // 图鉴积分
game_smithytask = "game_smithytask.json" //图鉴任务
game_smithymake = "game_smithymake.json" //打铁小游戏
//game_smithyDrop = "game_smithydrop.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]int32 // 图鉴积分
//_dropMap map[int32][]*cfg.GameSmithyDropData // 掉落表 key 是DiropId
}
// 组件初始化接口
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._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]int32, 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_smithycustomer, cfg.NewGameSmithyCustomer)
err = this.LoadConfigure(game_smithyatlas, cfg.NewGameSmithyAtlas)
err = this.LoadConfigure(game_smithyatlaslv, cfg.NewGameSmithyAtlasLv)
err = this.LoadConfigure(game_smithytask, cfg.NewGameSmithyTask)
err = this.LoadConfigure(game_smithymake, cfg.NewGameSmithyMake)
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, err error) {
var (
v interface{}
)
if v, err = this.GetConfigure(game_smithyreel); err == nil {
if configure, ok := v.(*cfg.GameNewSmithy); ok {
if data = configure.Get(int32(id)); data == nil {
err = comm.NewNotFoundConfErr(moduleName, game_smithyreel, id)
}
return
}
}
err = comm.NewNotFoundConfErr(moduleName, game_smithyreel, id)
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 false
}
// 获取铁匠铺熟练度数据
func (this *configureComp) GetSmithProficiencyConf(id int32) (data *cfg.GameSmithyProficiencyData, err error) {
var (
v interface{}
)
if v, err = this.GetConfigure(game_smproficiency); err == nil {
if configure, ok := v.(*cfg.GameSmithyProficiency); ok {
data = configure.Get(int(id))
if data != nil {
return
}
}
}
comm.NewNotFoundConfErr(moduleName, game_smproficiency, id)
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, lv int32) *cfg.GameSmithyProficiencyData {
return this._mapProficile[int64(reelid<<16)+int64(lv)]
}
// 获取铁匠铺顾客配置
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) (data *cfg.GameSmithyCustomerData, err error) {
var (
v interface{}
)
if v, err = this.GetConfigure(game_smithycustomer); err == nil {
if configure, ok := v.(*cfg.GameSmithyCustomer); ok {
if data = configure.Get(id); data != nil {
return
}
}
}
err = comm.NewNotFoundConfErr(moduleName, game_smithycustomer, id)
return
}
// 获取铁匠铺工作台信息
func (this *configureComp) GetSmithyToolsData(id int32) (data *cfg.GameSmithyToolData, err error) {
var (
v interface{}
)
if v, err = this.GetConfigure(game_smithytools); err == nil {
if configure, ok := v.(*cfg.GameSmithyTool); ok {
if data = configure.Get(int(id)); data != nil {
return
}
}
}
err = comm.NewNotFoundConfErr(moduleName, game_smithytools, id)
return
}
func (this *configureComp) GetSmithyStoveConf(level int32) (data *cfg.GameSmithyStoveV1Data, err error) {
var (
v interface{}
)
if v, err = this.GetConfigure(game_smithystove); err == nil {
if configure, ok := v.(*cfg.GameSmithyStoveV1); ok {
if data = configure.Get(int32(level)); data != nil {
return
}
}
}
err = comm.NewNotFoundConfErr(moduleName, game_smithystove, level)
return
}
// 获取图鉴信息
func (this *configureComp) GetSmithyAtlasConf(id string) (data *cfg.GameSmithyAtlasData, err error) {
var (
v interface{}
)
if v, err = this.GetConfigure(game_smithyatlas); err == nil {
if configure, ok := v.(*cfg.GameSmithyAtlas); ok {
if data = configure.Get(id); data != nil {
return
}
}
}
err = comm.NewNotFoundConfErr(moduleName, game_smithyatlas, id)
return
}
func (this *configureComp) GetSmithyAtlasLvConf(lv int32) (data *cfg.GameSmithyAtlasLvData, err error) {
var (
v interface{}
)
if v, err = this.GetConfigure(game_smithyatlaslv); err == nil {
if configure, ok := v.(*cfg.GameSmithyAtlasLv); ok {
if data = configure.Get(lv); data == nil {
err = comm.NewNotFoundConfErr(moduleName, game_smithyatlaslv, lv)
}
return
}
}
err = comm.NewNotFoundConfErr(moduleName, game_smithyatlaslv, lv)
return
}
func (this *configureComp) GetSmithyAtlasScoreConf(quality int32, lv int32) (score int32) {
return this._mapAtlasScore[int64(quality<<16)+int64(lv)]
}
// 获取图鉴分数
func (this *configureComp) LoadSmithyAtlasScoreConf() {
if v, err := this.GetConfigure(game_smithyatlasscore); err == nil {
if configure, ok := v.(*cfg.GameSmithyAtlasScore); ok {
this.hlock.Lock()
this._mapAtlasScore = make(map[int64]int32, 0)
defer this.hlock.Unlock()
for _, value := range configure.GetDataList() {
this._mapAtlasScore[int64(value.InitLv<<16)+int64(value.EntryNum)] = value.Score
}
return
}
} else {
log.Errorf("get LoadSmithyAtlasScoreConf conf err:%v", err)
}
}
// 获取图鉴任务配置
func (this *configureComp) GetSmithyTask(taskId int32) (data *cfg.GameSmithyTaskData, err error) {
var (
v interface{}
)
if v, err = this.GetConfigure(game_smithytask); err == nil {
if configure, ok := v.(*cfg.GameSmithyTask); ok {
if data = configure.Get(taskId); data != nil {
return
}
}
}
err = comm.NewNotFoundConfErr(moduleName, game_smithytask, taskId)
return
}
func (this *configureComp) GetSmithyTasks() (data []*cfg.GameSmithyTaskData, err error) {
var (
v interface{}
)
if v, err = this.GetConfigure(game_smithytask); err == nil {
if configure, ok := v.(*cfg.GameSmithyTask); ok {
if data = configure.GetDataList(); data != nil {
return
}
}
}
return
}
func (this *configureComp) GetSmithyMake(cid int32) (data *cfg.GameSmithyMakeData, err error) {
var (
v interface{}
)
if v, err = this.GetConfigure(game_smithymake); err == nil {
if configure, ok := v.(*cfg.GameSmithyMake); ok {
if data = configure.Get(cid); data == nil {
err = comm.NewNotFoundConfErr(moduleName, game_smithymake, cid)
}
return
}
}
err = comm.NewNotFoundConfErr(moduleName, game_smithymake, cid)
return
}