go_dreamfactory/modules/pagoda/comp_configure.go
2022-11-11 17:35:52 +08:00

185 lines
4.9 KiB
Go

package pagoda
import (
"fmt"
"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_pagoda = "game_pagoda.json"
game_pagodaseasonreward = "game_pagodaseasonreward.json"
game_pagodataskreward = "game_pagodataskreward.json"
game_passcheck = "game_passcheck.json"
)
///配置管理基础组件
type configureComp struct {
modules.MCompConfigure
hlock sync.RWMutex
_pagodaMap map[int64]*cfg.GamePagodaData
_checkType map[int32][]*cfg.GamePassCheckData // key type
}
//组件初始化接口
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)
err = this.LoadMultiConfigure(map[string]interface{}{
//game_pagoda: cfg.NewGame_pagoda,
game_pagodaseasonreward: cfg.NewGamePagodaSeasonReward,
game_pagodataskreward: cfg.NewGamePagodaTaskReward,
})
this._pagodaMap = make(map[int64]*cfg.GamePagodaData, 0)
configure.RegisterConfigure(game_pagoda, cfg.NewGamePagoda, func() {
if v, err := this.GetConfigure(game_pagoda); err == nil {
if configure, ok := v.(*cfg.GamePagoda); ok {
this.hlock.Lock()
defer this.hlock.Unlock()
for _, value := range configure.GetDataList() {
this._pagodaMap[int64(value.PagodaType<<16)+int64(value.LayerNum)] = value
}
return
}
}
log.Errorf("get game_pagoda conf err:%v", err)
return
})
this._checkType = make(map[int32][]*cfg.GamePassCheckData, 0)
configure.RegisterConfigure(game_passcheck, cfg.NewGamePassCheck, func() {
if v, err := this.GetConfigure(game_passcheck); err == nil {
if configure, ok := v.(*cfg.GamePassCheck); ok {
this.hlock.Lock()
defer this.hlock.Unlock()
for _, value := range configure.GetDataList() {
this._checkType[value.PasscheckType] = append(this._checkType[value.PasscheckType], value)
}
return
}
}
log.Errorf("get game_pagoda conf err:%v", err)
return
})
_data := this.GetPagodaSeasonReward()
fmt.Printf("%v", _data)
return
}
// 获取爬塔信息 参数1 塔类型 参数2 层数
func (this *configureComp) GetPagodaConfigData(PagodaType int32, floorId int32) (data *cfg.GamePagodaData) {
return this._pagodaMap[int64(PagodaType<<16)+int64(floorId)]
}
//加载多个配置文件
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) {
if v, err := this.GetConfigure(game_pagodataskreward); err == nil {
var (
configure *cfg.GamePagodaTaskReward
ok bool
)
if configure, ok = v.(*cfg.GamePagodaTaskReward); !ok {
log.Errorf("%T no is *cfg.Game_pagodaData", v)
return
}
if data, ok = configure.GetDataMap()[id]; ok {
return
}
} else {
log.Errorf("get game_pagodataskreward conf err:%v", err)
return
}
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
}
for _, value := range configure.GetDataList() {
if value.PagodaType == PagodaType {
maxFloor++
}
}
} else {
log.Errorf("get game_pagodataskreward conf err:%v", err)
return 0
}
return maxFloor
}
// 通过类型获取战令数据
func (this *configureComp) GetPassCheckByTtype(cType int32) []*cfg.GamePassCheckData {
if data, ok := this._checkType[cType]; ok {
return data
}
return nil
}
// 获取该类型的计费点
func (this *configureComp) GetPassCheckPointByTtype(cType int32) string {
if data, ok := this._checkType[cType]; ok {
if len(data) > 0 {
return data[0].PayId
}
}
return ""
}
// 通过id获取信息
func (this *configureComp) GetPassCheckByID(id int32) *cfg.GamePassCheckData {
if v, err := this.GetConfigure(game_passcheck); err == nil {
if configure, ok := v.(*cfg.GamePassCheck); ok {
return configure.Get(id)
}
}
return nil
}
// 获取
func (this *configureComp) GetPagodaSeasonReward() []*cfg.GamePagodaSeasonRewardData {
if v, err := this.GetConfigure(game_pagodaseasonreward); err == nil {
var (
configure *cfg.GamePagodaSeasonReward
ok bool
)
if configure, ok = v.(*cfg.GamePagodaSeasonReward); ok {
return configure.GetDataList()
}
}
return nil
}