go_dreamfactory/modules/mainline/comp_configure.go
2023-08-24 19:23:23 +08:00

238 lines
6.3 KiB
Go

package mainline
import (
"go_dreamfactory/comm"
"go_dreamfactory/lego/core"
"go_dreamfactory/modules"
"go_dreamfactory/sys/configure"
cfg "go_dreamfactory/sys/configure/structs"
"sync"
)
const moduleName = "mline"
const (
game_mainchapter = "game_mainchapter.json"
game_mainstage = "game_mainstage.json"
game_mainstarreward = "game_mainstarreward.json"
game_mainshopitem = "game_mainshopitem.json"
game_mainachievement = "game_mainachievement.json"
)
// /配置管理基础组件
type configureComp struct {
modules.MCompConfigure
module *Mainline
lock sync.RWMutex
chapterMap map[int32][]*cfg.GameMainStageData
rewardMap map[int32][]*cfg.GameMainStarrewardData
tasks map[int32]struct{}
groupTasks map[int32][]*cfg.GameMainAchievementData //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.(*Mainline)
err = this.LoadMultiConfigure(map[string]interface{}{
game_mainchapter: cfg.NewGameMainChapter,
game_mainshopitem: cfg.NewGameMainShopItem,
})
this.chapterMap = make(map[int32][]*cfg.GameMainStageData)
configure.RegisterConfigure(game_mainstage, cfg.NewGameMainStage, this.updateMlineStage)
configure.RegisterConfigure(game_mainstarreward, cfg.NewGameMainStarreward, this.updateMlineReward)
configure.RegisterConfigure(game_mainachievement, cfg.NewGameMainAchievement, this.GameMainAchievement)
return
}
func (this *configureComp) getchapterMap() map[int32][]*cfg.GameMainStageData {
this.lock.Lock()
chapterMap := this.chapterMap
this.lock.RUnlock()
return chapterMap
}
func (this *configureComp) getrewardMap() map[int32][]*cfg.GameMainStarrewardData {
this.lock.Lock()
rewardMap := this.rewardMap
this.lock.Unlock()
return rewardMap
}
func (this *configureComp) updateMlineStage() {
var (
v interface{}
configure *cfg.GameMainStage
chapterMap map[int32][]*cfg.GameMainStageData
err error
ok bool
)
if v, err = this.GetConfigure(game_mainstage); err != nil {
this.module.Errorln(err)
return
}
if configure, ok = v.(*cfg.GameMainStage); ok {
chapterMap = make(map[int32][]*cfg.GameMainStageData)
for _, v := range configure.GetDataList() {
if _, ok = chapterMap[v.Chapterid]; !ok {
chapterMap[v.Chapterid] = make([]*cfg.GameMainStageData, 0)
}
chapterMap[v.Chapterid] = append(chapterMap[v.Chapterid], v)
}
}
this.lock.Lock()
this.chapterMap = chapterMap
this.lock.Unlock()
return
}
func (this *configureComp) updateMlineReward() {
var (
v interface{}
configure *cfg.GameMainStarreward
rewardMap map[int32][]*cfg.GameMainStarrewardData
err error
ok bool
)
if v, err = this.GetConfigure(game_mainstarreward); err != nil {
this.module.Errorln(err)
return
}
if configure, ok = v.(*cfg.GameMainStarreward); ok {
rewardMap = make(map[int32][]*cfg.GameMainStarrewardData)
for _, v := range configure.GetDataList() {
if _, ok = rewardMap[v.Boxid]; !ok {
rewardMap[v.Boxid] = make([]*cfg.GameMainStarrewardData, 0)
}
rewardMap[v.Boxid] = append(rewardMap[v.Boxid], v)
}
}
this.lock.Lock()
this.rewardMap = rewardMap
this.lock.Unlock()
return
}
func (this *configureComp) GetMainChapterConf(id int32) (conf *cfg.GameMainChapterData, err error) {
var (
v interface{}
ok bool
)
if v, err = this.GetConfigure(game_mainchapter); err != nil {
this.module.Errorln(err)
return
}
if conf, ok = v.(*cfg.GameMainChapter).GetDataMap()[id]; !ok {
err = comm.NewNotFoundConfErr(string(this.module.GetType()), game_mainchapter, id)
}
return
}
func (this *configureComp) GetMainStageConfs() (data []*cfg.GameMainStageData, err error) {
var (
v interface{}
)
if v, err = this.GetConfigure(game_mainstage); err != nil {
this.module.Errorln(err)
return
}
data = v.(*cfg.GameMainStage).GetDataList()
return
}
func (this *configureComp) GetMainStageConf(id int32) (data *cfg.GameMainStageData, err error) {
var (
v interface{}
)
if v, err = this.GetConfigure(game_mainstage); err == nil {
if configure, ok := v.(*cfg.GameMainStage); ok {
data = configure.Get(id)
if data != nil {
return
}
}
}
err = comm.NewNotFoundConfErr(moduleName, game_mainstage, id)
return
}
func (this *configureComp) GetAllShopConf() (sz []*cfg.GameMainShopItemData) {
if v, err := this.GetConfigure(game_mainshopitem); err == nil {
if configure, ok := v.(*cfg.GameMainShopItem); ok {
for _, v := range configure.GetDataList() {
if v.Unlock != 0 {
sz = append(sz, v)
}
}
}
}
return
}
func (this *configureComp) GetMlineShopConfById(cid int32) (conf *cfg.GameMainShopItemData, err error) {
var (
v interface{}
)
if v, err = this.GetConfigure(game_mainshopitem); err == nil {
if configure, ok := v.(*cfg.GameMainShopItem); ok {
if conf = configure.Get(cid); conf != nil {
return
}
}
}
err = comm.NewNotFoundConfErr(moduleName, game_mainstage, cid)
return
}
// 更新任务配置表
func (this *configureComp) GameMainAchievement() {
var (
v interface{}
conf *cfg.GameMainAchievement
ok bool
err error
)
if v, err = this.GetConfigure(game_mainachievement); err != nil {
return
}
if conf, ok = v.(*cfg.GameMainAchievement); !ok {
this.module.Error("日常任务配置异常!")
return
}
tasks := make(map[int32]struct{})
groupTasksConf := make(map[int32][]*cfg.GameMainAchievementData)
for _, v := range conf.GetDataList() {
if _, ok := groupTasksConf[v.Id]; !ok {
groupTasksConf[v.Id] = make([]*cfg.GameMainAchievementData, 0)
}
groupTasksConf[v.Id] = append(groupTasksConf[v.Id], v)
tasks[v.Taskid] = struct{}{}
}
this.lock.Lock()
this.groupTasks = groupTasksConf
this.tasks = tasks
this.lock.Unlock()
}
func (this *configureComp) gettasks() map[int32]struct{} {
this.lock.RLock()
defer this.lock.RUnlock()
return this.tasks
}
func (this *configureComp) getGameVenturegiftsTask(id int32) (conf *cfg.GameMainAchievementData, err error) {
var (
v interface{}
ok bool
)
if v, err = this.GetConfigure(game_mainachievement); err != nil {
return
}
if conf, ok = v.(*cfg.GameMainAchievement).GetDataMap()[id]; !ok {
err = comm.NewNotFoundConfErr(string(this.module.GetType()), game_mainachievement, id)
this.module.Errorln(err)
return
}
return
}