go_dreamfactory/modules/achieve/configure.go
2023-10-12 10:42:54 +08:00

72 lines
1.7 KiB
Go

package achieve
import (
"go_dreamfactory/comm"
"go_dreamfactory/lego/core"
"go_dreamfactory/modules"
"go_dreamfactory/sys/configure"
cfg "go_dreamfactory/sys/configure/structs"
"sync"
)
const (
game_achievetask = "game_achievetask.json"
)
type configureComp struct {
modules.MCompConfigure
module *Achieve
tasksConf []int32
lock sync.RWMutex
}
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.(*Achieve)
configure.RegisterConfigure(game_achievetask, cfg.NewGameAchieveTask, this.updateconfigure)
return
}
// 更新任务配置表
func (this *configureComp) updateconfigure() {
var (
v interface{}
conf *cfg.GameAchieveTask
ok bool
err error
)
if v, err = this.GetConfigure(game_achievetask); err != nil {
return
}
if conf, ok = v.(*cfg.GameAchieveTask); !ok {
this.module.Error("通用成就配置错误!")
return
}
tasksConf := make([]int32, 0)
for _, v := range conf.GetDataList() {
tasksConf = append(tasksConf, v.TaskBuried)
}
this.lock.Lock()
this.tasksConf = tasksConf
this.lock.Unlock()
}
//查询积分段位信息
func (this *configureComp) getAchieveTaskById(id int32) (result *cfg.GameAchieveTaskData, err error) {
var (
v interface{}
ok bool
)
if v, err = this.GetConfigure(game_achievetask); err != nil {
this.module.Errorln(err)
} else {
if result, ok = v.(*cfg.GameAchieveTask).GetDataMap()[id]; !ok {
err = comm.NewNotFoundConfErr(string(this.module.GetType()), game_achievetask, id)
this.module.Errorln(err)
}
}
return
}