132 lines
3.2 KiB
Go
132 lines
3.2 KiB
Go
package user
|
|
|
|
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_signreset = "game_signreset.json"
|
|
game_sign = "game_sign.json"
|
|
gameOpencond = "game_opencond.json"
|
|
game_SignExtra = "game_signextra.json"
|
|
)
|
|
|
|
///配置管理基础组件
|
|
type configureComp struct {
|
|
hlock sync.RWMutex
|
|
modules.MCompConfigure
|
|
_sign map[int32]*cfg.GameSignData
|
|
_signExtra map[int32]*cfg.GameSignExtraData
|
|
}
|
|
|
|
//组件初始化接口
|
|
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._sign = make(map[int32]*cfg.GameSignData, 0)
|
|
configure.RegisterConfigure(game_sign, cfg.NewGameSign, this.LoadSignData)
|
|
this.LoadConfigure(gameOpencond, cfg.NewGameOpencond)
|
|
configure.RegisterConfigure(game_sign, cfg.NewGameSign, this.LoadSignExtraData)
|
|
return
|
|
}
|
|
|
|
// 获取签到信息
|
|
func (this *configureComp) GetSignConf(day, group int32) *cfg.GameSignData {
|
|
if v, ok := this._sign[group<<8+day]; ok {
|
|
return v
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// 获取组id
|
|
func (this *configureComp) GetSignResetConf(id int32) int32 {
|
|
if v, err := this.GetConfigure(game_signreset); err == nil {
|
|
if configure, ok := v.(*cfg.GameSignReset); ok {
|
|
if configure != nil {
|
|
if _, ok := configure.GetDataMap()[id]; !ok {
|
|
return configure.Get(1).Groups
|
|
}
|
|
return configure.Get(id).Groups
|
|
}
|
|
}
|
|
}
|
|
return -1
|
|
}
|
|
func (this *configureComp) LoadSignData() {
|
|
if v, err := this.GetConfigure(game_sign); err == nil {
|
|
if configure, ok := v.(*cfg.GameSign); ok {
|
|
this.hlock.Lock()
|
|
defer this.hlock.Unlock()
|
|
for _, value := range configure.GetDataList() {
|
|
this._sign[value.Group<<8+value.Day] = value
|
|
}
|
|
return
|
|
}
|
|
} else {
|
|
log.Errorf("get game_sign conf err:%v", err)
|
|
}
|
|
return
|
|
}
|
|
|
|
func (this *configureComp) GetOpenCondList() []*cfg.GameOpencondData {
|
|
if v, err := this.GetConfigure(gameOpencond); err != nil {
|
|
return nil
|
|
} else {
|
|
data, ok := v.(*cfg.GameOpencond)
|
|
if !ok {
|
|
err = fmt.Errorf("%T no is *cfg.GameOpencond", v)
|
|
return nil
|
|
}
|
|
return data.GetDataList()
|
|
}
|
|
}
|
|
|
|
func (this *configureComp) FindFunc(lv int32) (funcIds []string) {
|
|
if v, err := this.GetConfigure(gameOpencond); err != nil {
|
|
return nil
|
|
} else {
|
|
data, ok := v.(*cfg.GameOpencond)
|
|
if !ok {
|
|
err = fmt.Errorf("%T no is *cfg.GameOpencond", v)
|
|
return nil
|
|
}
|
|
for _, d := range data.GetDataList() {
|
|
for _, v := range d.Main {
|
|
if v.Key == 1 && v.Param == lv {
|
|
funcIds = append(funcIds, d.Id)
|
|
continue
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
func (this *configureComp) LoadSignExtraData() {
|
|
if v, err := this.GetConfigure(game_SignExtra); err == nil {
|
|
if configure, ok := v.(*cfg.GameSignExtra); ok {
|
|
this.hlock.Lock()
|
|
defer this.hlock.Unlock()
|
|
for _, value := range configure.GetDataList() {
|
|
this._signExtra[value.Groups<<8+value.Day] = value
|
|
}
|
|
return
|
|
}
|
|
} else {
|
|
log.Errorf("get SignExtra conf err:%v", err)
|
|
}
|
|
return
|
|
}
|
|
func (this *configureComp) GetSignExtarConf(day, group int32) *cfg.GameSignExtraData {
|
|
if v, ok := this._signExtra[group<<8+day]; ok {
|
|
return v
|
|
}
|
|
return nil
|
|
}
|