106 lines
2.8 KiB
Go
106 lines
2.8 KiB
Go
package enchant
|
|
|
|
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"
|
|
)
|
|
|
|
const (
|
|
game_enchantboss = "game_enchantboss.json"
|
|
game_enchantshop = "game_enchantshop.json"
|
|
)
|
|
|
|
///配置管理基础组件
|
|
type configureComp struct {
|
|
hlock sync.RWMutex
|
|
modules.MCompConfigure
|
|
_enchantMap map[int32][]*cfg.GameEnchantBossData
|
|
}
|
|
|
|
//组件初始化接口
|
|
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._enchantMap = make(map[int32][]*cfg.GameEnchantBossData, 0)
|
|
configure.RegisterConfigure(game_enchantboss, cfg.NewGameEnchantBoss, func() {
|
|
if v, err := this.GetConfigure(game_enchantboss); err == nil {
|
|
if configure, ok := v.(*cfg.GameEnchantBoss); ok {
|
|
this.hlock.Lock()
|
|
defer this.hlock.Unlock()
|
|
for _, value := range configure.GetDataList() {
|
|
this._enchantMap[value.Bossid] = append(this._enchantMap[value.Bossid], value)
|
|
}
|
|
return
|
|
}
|
|
} else {
|
|
log.Errorf("get game_enchantboss conf err:%v", err)
|
|
}
|
|
return
|
|
})
|
|
err = this.LoadConfigure(game_enchantshop, cfg.NewGameEnchantShop)
|
|
return
|
|
}
|
|
|
|
// 参数: boss类型 难度
|
|
func (this *configureComp) GetEnchantBossConfigData(bossId int32) (data []*cfg.GameEnchantBossData, err error) {
|
|
var (
|
|
ok bool
|
|
)
|
|
if data, ok = this._enchantMap[bossId]; !ok {
|
|
err = comm.NewNotFoundConfErr("enchant", game_enchantboss, bossId)
|
|
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) GetBuyChallengeCount(index int32) (data *cfg.GameEnchantShopData, err error) {
|
|
var (
|
|
v interface{}
|
|
)
|
|
if v, err = this.GetConfigure(game_enchantshop); err == nil {
|
|
if configure, ok := v.(*cfg.GameEnchantShop); ok {
|
|
data = configure.Get(index)
|
|
if data == nil {
|
|
err = comm.NewNotFoundConfErr("enchant", game_enchantshop, index)
|
|
}
|
|
return
|
|
}
|
|
}
|
|
err = comm.NewNotFoundConfErr("enchant", game_enchantshop, index)
|
|
return
|
|
}
|
|
|
|
func (this *configureComp) GetMaxBuyChallengeCount() int32 {
|
|
if v, err := this.GetConfigure(game_enchantshop); err == nil {
|
|
if configure, ok := v.(*cfg.GameEnchantShop); ok {
|
|
return int32(len(configure.GetDataList()))
|
|
}
|
|
} else {
|
|
log.Errorf("get game_challenge conf err:%v", err)
|
|
}
|
|
|
|
return 0
|
|
}
|