package turntable 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_venturegiftstask = "game_venturegiftstask.json" venturegiftsdraw = "game_venturegiftsdraw.json" //大转盘 ) type configureComp struct { modules.MCompConfigure module *Turntable lock sync.RWMutex tasks map[int32]struct{} groupTasks map[int32][]*cfg.GameVenturegiftsTaskData //key 条件ID pool1 map[int32]*cfg.GameVenturegiftsDrawData pool2 map[int32]*cfg.GameVenturegiftsDrawData } 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.(*Turntable) configure.RegisterConfigure(game_venturegiftstask, cfg.NewGameVenturegiftsTask, this.updateconfigure) configure.RegisterConfigure(venturegiftsdraw, cfg.NewGameVenturegiftsDraw, this.updateconfigureDraw) return } func (this *configureComp) gettasks() map[int32]struct{} { this.lock.RLock() defer this.lock.RUnlock() return this.tasks } // 更新任务配置表 func (this *configureComp) updateconfigureDraw() { var pool1 string if v, err := this.GetConfigure(venturegiftsdraw); err == nil { this.lock.Lock() this.pool1 = make(map[int32]*cfg.GameVenturegiftsDrawData) this.pool2 = make(map[int32]*cfg.GameVenturegiftsDrawData) defer this.lock.Unlock() if _configure, ok := v.(*cfg.GameVenturegiftsDraw); ok { for _, v := range _configure.GetDataList() { if pool1 == "" { pool1 = v.DrawType } if pool1 == v.DrawType { this.pool1[v.Drawkey] = v } else { this.pool2[v.Drawkey] = v } } return } } else { err = fmt.Errorf("%T no is *cfg.GameHeroAwaken", v) } } func (this *configureComp) updateconfigure() { var ( v interface{} conf *cfg.GameVenturegiftsTask ok bool err error ) if v, err = this.GetConfigure(game_venturegiftstask); err != nil { return } if conf, ok = v.(*cfg.GameVenturegiftsTask); !ok { this.module.Error("日常任务配置异常!") return } tasks := make(map[int32]struct{}) groupTasksConf := make(map[int32][]*cfg.GameVenturegiftsTaskData) for _, v := range conf.GetDataList() { if _, ok := groupTasksConf[v.Openday]; !ok { groupTasksConf[v.Openday] = make([]*cfg.GameVenturegiftsTaskData, 0) } groupTasksConf[v.Openday] = append(groupTasksConf[v.Openday], v) tasks[v.Venturetask] = struct{}{} } this.lock.Lock() this.groupTasks = groupTasksConf this.tasks = tasks this.lock.Unlock() } func (this *configureComp) getGameVenturegiftsTask(id int32) (conf *cfg.GameVenturegiftsTaskData, err error) { var ( v interface{} ok bool ) if v, err = this.GetConfigure(game_venturegiftstask); err != nil { return } if conf, ok = v.(*cfg.GameVenturegiftsTask).GetDataMap()[id]; !ok { err = comm.NewNotFoundConfErr(string(this.module.GetType()), game_venturegiftstask, id) this.module.Errorln(err) return } return } // 获取抽奖数据 func (this *configureComp) GetVenturegiftsDraw(id int32) (configure *cfg.GameVenturegiftsDrawData, err error) { var ( v interface{} ok bool ) if v, err = this.GetConfigure(venturegiftsdraw); err == nil { if configure, ok = v.(*cfg.GameVenturegiftsDraw).GetDataMap()[id]; !ok { err = fmt.Errorf("%T no is *cfg.GameVenturegiftsDrawData", v) return } } return } func (this *configureComp) GetPool1() (m map[int32]*cfg.GameVenturegiftsDrawData) { return this.pool1 } func (this *configureComp) GetPool2() (m map[int32]*cfg.GameVenturegiftsDrawData) { return this.pool2 } func (this *configureComp) GetMaxTurntableCount() (count int32) { return int32(len(this.pool1) + len(this.pool2)) }