go_dreamfactory/modules/pagoda/comp_configure.go

280 lines
7.5 KiB
Go

package pagoda
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"
"sync"
)
const moduleName = "pagoda"
const (
game_pagoda = "game_pagoda.json"
game_pagodaseasonreward = "game_pagodaseasonreward.json"
game_pagodataskreward = "game_pagodataskreward.json"
game_circulate = "game_circulate.json"
game_sixdirections = "game_sixdirections.json"
game_sixdirectionsreward = "game_sixdirectionsreward.json"
game_circulateseason = "game_circulateseason.json"
)
///配置管理基础组件
type configureComp struct {
modules.MCompConfigure
module *Pagoda
hlock sync.RWMutex
_mapPagoda map[int32]*cfg.GamePagodaData
_mapFloor map[int32]int32 // key 页签 value 层数
_mapCycle map[int32]*cfg.GameCirculateData // 阵营塔
circulate []int32
_mapSixReward map[int32][]*cfg.GameSixDirectionsRewardData // 六合塔奖励
}
//组件初始化接口
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.(*Pagoda)
err = this.LoadMultiConfigure(map[string]interface{}{
game_pagodataskreward: cfg.NewGamePagodaTaskReward,
game_pagoda: cfg.NewGamePagoda,
game_circulate: cfg.NewGameCirculate,
game_sixdirections: cfg.NewGameSixDirections,
game_circulateseason: cfg.NewGameCirculateSeason,
})
configure.RegisterConfigure(game_pagoda, cfg.NewGamePagoda, this.LoadPagoda)
configure.RegisterConfigure(game_circulate, cfg.NewGameCirculate, this.LoadCirculate)
configure.RegisterConfigure(game_sixdirectionsreward, cfg.NewGameSixDirectionsReward, this.LoadSixDirections)
return
}
func (this *configureComp) Start() (err error) {
err = this.MCompConfigure.Start()
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) GetPagodaRewardconfig(id int32) (data *cfg.GamePagodaTaskRewardData, err error) {
var (
v interface{}
)
if v, err = this.GetConfigure(game_pagodataskreward); err == nil {
if configure, ok := v.(*cfg.GamePagodaTaskReward); ok {
data = configure.Get(id)
if data != nil {
return
}
}
}
err = comm.NewNotFoundConfErr(moduleName, game_pagodataskreward, id)
return
}
// 获取某类型塔层数
func (this *configureComp) GetPagodaFloor(PagodaType int32) int32 {
var maxFloor int32
if v, err := this.GetConfigure(game_pagoda); err == nil {
var (
configure *cfg.GamePagoda
ok bool
)
if configure, ok = v.(*cfg.GamePagoda); !ok {
log.Errorf("%T no is *cfg.Game_pagodaData", v)
return 0
}
maxFloor = int32(len(configure.GetDataList()))
} else {
log.Errorf("get game_pagodataskreward conf err:%v", err)
return 0
}
return maxFloor
}
func (this *configureComp) GetPagodaConfigData(id int32) (data *cfg.GamePagodaData, err error) {
var (
v interface{}
)
if v, err = this.GetConfigure(game_pagoda); err == nil {
if configure, ok := v.(*cfg.GamePagoda); ok {
data = configure.Get(id)
if data != nil {
return
}
}
}
err = comm.NewNotFoundConfErr(moduleName, game_pagoda, id)
return
}
func (this *configureComp) LoadPagoda() {
if v, err := this.GetConfigure(game_pagoda); err == nil {
if configure, ok := v.(*cfg.GamePagoda); ok {
this.hlock.Lock()
defer this.hlock.Unlock()
this._mapPagoda = make(map[int32]*cfg.GamePagodaData)
this._mapFloor = make(map[int32]int32)
for _, value := range configure.GetDataList() {
key := value.Tab<<16 + value.LayerNum
this._mapPagoda[key] = value
this._mapFloor[value.Tab] = value.LayerNum
}
return
}
}
return
}
func (this *configureComp) GetMapFloorData() (data map[int32]int32) {
this.hlock.RLock()
defer this.hlock.RUnlock()
return this._mapFloor
}
func (this *configureComp) GetPagodaConfBytab(tab int32, lv int32) (data *cfg.GamePagodaData, err error) {
var (
ok bool
)
this.hlock.RLock()
data, ok = this._mapPagoda[tab<<16+lv]
this.hlock.RUnlock()
if !ok {
err = comm.NewNotFoundConfErr("pagoda", game_pagoda, fmt.Errorf("tab %d ,ly %d not found", tab, lv))
}
return
}
func (this *configureComp) LoadCirculate() {
_m := make(map[int32]struct{}, 0)
if v, err := this.GetConfigure(game_circulate); err == nil {
if configure, ok := v.(*cfg.GameCirculate); ok {
this.hlock.Lock()
defer this.hlock.Unlock()
this._mapCycle = make(map[int32]*cfg.GameCirculateData)
for _, value := range configure.GetDataList() {
this._mapCycle[value.Itype<<16+value.Floors] = value
if _, ok := _m[value.Itype]; !ok {
_m[value.Itype] = struct{}{}
this.circulate = append(this.circulate, value.Itype)
}
}
return
}
}
return
}
// 获取阵营塔数据
func (this *configureComp) GetPagodaCirculateConf(restriction int32, floor int32) (data *cfg.GameCirculateData, err error) {
var ok bool
this.hlock.RLock()
data, ok = this._mapCycle[restriction<<16+floor]
this.hlock.RUnlock()
if !ok {
err = comm.NewNotFoundConfErr("pagoda", game_circulate, fmt.Errorf("tab %d ,ly %d not found", restriction, floor))
}
return
}
func (this *configureComp) GetRaceCirculateConf() []int32 {
return this.circulate
}
// 获取六合塔的信息
func (this *configureComp) GetSixPagodaConf(id int32) (data *cfg.GameSixDirectionsData, err error) {
var (
v interface{}
)
if v, err = this.GetConfigure(game_sixdirections); err == nil {
if configure, ok := v.(*cfg.GameSixDirections); ok {
if data = configure.Get(id); data != nil {
return
}
}
}
err = comm.NewNotFoundConfErr(moduleName, game_sixdirections, id)
return
}
func (this *configureComp) LoadSixDirections() {
_m := make(map[int32][]*cfg.GameSixDirectionsRewardData, 0)
if v, err := this.GetConfigure(game_sixdirectionsreward); err == nil {
if configure, ok := v.(*cfg.GameSixDirectionsReward); ok {
for _, v1 := range configure.GetDataList() {
_m[v1.Boxid] = append(_m[v1.Boxid], v1)
}
}
}
this.hlock.Lock()
this._mapSixReward = make(map[int32][]*cfg.GameSixDirectionsRewardData)
this._mapSixReward = _m
this.hlock.Unlock()
return
}
// 奖励组
func (this *configureComp) GetSixDirectionsGroudConf(groud int32) (sz []int32) {
var (
v interface{}
err error
)
if v, err = this.GetConfigure(game_sixdirections); err == nil {
if configure, ok := v.(*cfg.GameSixDirections); ok {
for _, v := range configure.GetDataList() {
if v.Groud == groud {
sz = append(sz, v.Floors)
}
}
}
}
return
}
func (this *configureComp) GetSixDirectionsConf(boxid int32) (conf []*cfg.GameSixDirectionsRewardData) {
this.hlock.RLock()
conf, _ = this._mapSixReward[boxid]
this.hlock.RUnlock()
return
}
// 获取赛季的数量
func (this *configureComp) GetCirculateSeasonLenght() (conf []*cfg.GameCirculateSeasonData, err error) {
var (
v interface{}
)
if v, err = this.GetConfigure(game_circulateseason); err == nil {
if configure, ok := v.(*cfg.GameCirculateSeason); ok {
if conf = configure.GetDataList(); len(conf) > 0 {
return
}
}
}
err = comm.NewNotFoundConfErr(moduleName, game_circulateseason, "")
return
}