157 lines
4.0 KiB
Go
157 lines
4.0 KiB
Go
package dailytask
|
|
|
|
import (
|
|
"fmt"
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/core"
|
|
"go_dreamfactory/modules"
|
|
"go_dreamfactory/sys/configure"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
"sync"
|
|
)
|
|
|
|
const (
|
|
game_annulartaskall = "game_annulartaskall.json"
|
|
game_annulartask_library = "game_annulartask_library.json"
|
|
game_opencond = "game_opencond.json"
|
|
)
|
|
|
|
type configureComp struct {
|
|
modules.MCompConfigure
|
|
module *Dailytask
|
|
lock sync.RWMutex
|
|
groupTasks map[int32][]*cfg.GameAnnulartask_LibraryData //key 条件ID
|
|
}
|
|
|
|
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.(*Dailytask)
|
|
err = this.LoadMultiConfigure(map[string]interface{}{
|
|
game_annulartaskall: cfg.NewGameAnnulartaskAll,
|
|
game_opencond: cfg.NewGameOpencond,
|
|
})
|
|
configure.RegisterConfigure(game_annulartask_library, cfg.NewGameAnnulartask_Library, this.updateconfigure)
|
|
return
|
|
}
|
|
|
|
// 更新任务配置表
|
|
func (this *configureComp) updateconfigure() {
|
|
var (
|
|
v interface{}
|
|
conf *cfg.GameAnnulartask_Library
|
|
ok bool
|
|
err error
|
|
)
|
|
if v, err = this.GetConfigure(game_annulartask_library); err != nil {
|
|
return
|
|
}
|
|
if conf, ok = v.(*cfg.GameAnnulartask_Library); !ok {
|
|
this.module.Error("日常任务配置异常!")
|
|
return
|
|
}
|
|
groupTasksConf := make(map[int32][]*cfg.GameAnnulartask_LibraryData)
|
|
|
|
for _, v := range conf.GetDataList() {
|
|
|
|
if _, ok := groupTasksConf[v.Assembleid]; !ok {
|
|
groupTasksConf[v.Assembleid] = make([]*cfg.GameAnnulartask_LibraryData, 0)
|
|
}
|
|
groupTasksConf[v.Assembleid] = append(groupTasksConf[v.Assembleid], v)
|
|
}
|
|
|
|
this.lock.Lock()
|
|
this.groupTasks = groupTasksConf
|
|
this.lock.Unlock()
|
|
}
|
|
|
|
// 随机获取任务组
|
|
func (this *configureComp) getAnnulartaskAll() (results *cfg.GameAnnulartaskAllData, err error) {
|
|
var (
|
|
v interface{}
|
|
conf *cfg.GameAnnulartaskAll
|
|
weights []int32
|
|
index int32
|
|
ok bool
|
|
)
|
|
if v, err = this.GetConfigure(game_annulartaskall); err != nil {
|
|
return
|
|
} else {
|
|
if conf, ok = v.(*cfg.GameAnnulartaskAll); !ok {
|
|
this.module.Errorf("err:%v", err)
|
|
return
|
|
}
|
|
weights = make([]int32, len(conf.GetDataList()))
|
|
for i, v := range conf.GetDataList() {
|
|
weights[i] = v.Weight
|
|
}
|
|
index = comm.GetRandW(weights)
|
|
results = conf.GetDataList()[index]
|
|
return
|
|
}
|
|
}
|
|
|
|
// 随机获取任务组
|
|
func (this *configureComp) getAnnulartaskAllById(id int32) (results *cfg.GameAnnulartaskAllData, err error) {
|
|
var (
|
|
v interface{}
|
|
ok bool
|
|
)
|
|
if v, err = this.GetConfigure(game_annulartaskall); err != nil {
|
|
return
|
|
} else {
|
|
if results, ok = v.(*cfg.GameAnnulartaskAll).GetDataMap()[id]; !ok {
|
|
err = comm.NewNotFoundConfErr(string(this.module.GetType()), game_annulartaskall, id)
|
|
this.module.Errorln(err)
|
|
return
|
|
}
|
|
return
|
|
}
|
|
}
|
|
|
|
// 随机任务
|
|
func (this *configureComp) getAnnulartaskLibrary(ulv, group int32) (results *cfg.GameAnnulartask_LibraryData, err error) {
|
|
var (
|
|
tasks []*cfg.GameAnnulartask_LibraryData
|
|
canuse []*cfg.GameAnnulartask_LibraryData
|
|
weights []int32
|
|
index int32
|
|
ok bool
|
|
)
|
|
this.lock.RLock()
|
|
tasks, ok = this.groupTasks[group]
|
|
this.lock.RUnlock()
|
|
if !ok {
|
|
err = fmt.Errorf("no found group:%d", group)
|
|
return
|
|
}
|
|
canuse = make([]*cfg.GameAnnulartask_LibraryData, 0, len(tasks))
|
|
for _, v := range tasks {
|
|
if v.Lvstart <= ulv && v.Lvend >= ulv {
|
|
canuse = append(canuse, v)
|
|
}
|
|
}
|
|
weights = make([]int32, len(canuse))
|
|
for i, v := range canuse {
|
|
weights[i] = v.Itemwt
|
|
}
|
|
index = comm.GetRandW(weights)
|
|
results = canuse[index]
|
|
return
|
|
}
|
|
|
|
func (this *configureComp) getOpencondCfg(id string) (conf *cfg.GameOpencondData, err error) {
|
|
var (
|
|
v interface{}
|
|
ok bool
|
|
)
|
|
if v, err = this.GetConfigure(game_opencond); err != nil {
|
|
err = fmt.Errorf("%T no is *cfg.GameOpencond", v)
|
|
return
|
|
}
|
|
if conf, ok = v.(*cfg.GameOpencond).GetDataMap()[id]; !ok {
|
|
err = comm.NewNotFoundConfErr(string(this.module.GetType()), game_opencond, id)
|
|
return
|
|
}
|
|
return
|
|
}
|