package user 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_signreset = "game_signreset.json" game_sign = "game_sign.json" gameOpencond = "game_opencond.json" game_SignExtra = "game_signextra.json" game_initial = "game_initial.json" //初始化表 game_playerinfor_overview = "game_playerinfor_overview.json" //皮肤配置表 ) // /配置管理基础组件 type configureComp struct { modules.MCompConfigure module *User hlock sync.RWMutex _sign map[int32]*cfg.GameSignData _signExtra map[int32]*cfg.GameSignExtraData _pInforoverview map[string]*cfg.GamePlayerInfor_overviewData } // 组件初始化接口 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.(*User) err = this.LoadConfigure(game_initial, cfg.NewGameInitial) this._sign = make(map[int32]*cfg.GameSignData, 0) configure.RegisterConfigure(game_sign, cfg.NewGameSign, this.LoadSignData) this.LoadConfigure(gameOpencond, cfg.NewGameOpencond) this._signExtra = make(map[int32]*cfg.GameSignExtraData, 0) configure.RegisterConfigure(game_SignExtra, cfg.NewGameSignExtra, this.LoadSignExtraData) configure.RegisterConfigure(game_playerinfor_overview, cfg.NewGamePlayerInfor_overview, this.updatePlayerOverview) return } // 获取签到信息 func (this *configureComp) GetSignConf(day, group int32) *cfg.GameSignData { if v, ok := this._sign[group<<8+day]; ok { return v } this.module.Errorf("get GetSignConf conf err day:%d,group:%d", day, group) 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 { this.module.Errorf("get game_sign conf err:%v", err) } return } func (this *configureComp) GetOpenCondConf() []*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) this.module.Errorln(err) 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 { this.module.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 } func (this *configureComp) GetGlobalInitConf() (configure *cfg.GameInitial, err error) { var ( v interface{} ok bool ) if v, err = this.GetConfigure(game_initial); err == nil { if configure, ok = v.(*cfg.GameInitial); !ok { err = fmt.Errorf("%T no is *cfg.Game_comInitial", v) this.module.Errorln(err) return } } return } func (this *configureComp) updatePlayerOverview() { var ( v interface{} err error key string temp map[string]*cfg.GamePlayerInfor_overviewData ) if v, err = this.GetConfigure(game_playerinfor_overview); err != nil { this.module.Errorf("err:%v", err) return } else { temp = make(map[string]*cfg.GamePlayerInfor_overviewData) for _, v := range v.(*cfg.GamePlayerInfor_overview).GetDataList() { key = fmt.Sprintf("%s%d", v.Id, v.Sex) temp[key] = v } this._pInforoverview = temp // if configure, ok = v.(*cfg.GamePlayerInfor_overview).GetDataMap()[id]; !ok { // err = fmt.Errorf("GetPlayerOverview not found:%s ", id) // this.module.Errorf("err:%v", err) // return // } } } func (this *configureComp) GetPlayerOverview(id string, sex int32) (configure *cfg.GamePlayerInfor_overviewData, err error) { var ( key string ok bool ) key = fmt.Sprintf("%s%d", id, sex) if configure, ok = this._pInforoverview[key]; !ok { err = comm.NewNotFoundConfErr("用户模块", game_playerinfor_overview, key) this.module.Errorf("err:%v", err) return } return }