From 14c474cc0b9444a945fdc7e13ac34d226c82172d Mon Sep 17 00:00:00 2001 From: meixiongfeng <766881921@qq.com> Date: Wed, 7 Sep 2022 20:06:43 +0800 Subject: [PATCH] =?UTF-8?q?=E8=97=8F=E4=B9=A6=E9=A6=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/library/api.go | 37 +++++++++++ modules/library/comp_configure.go | 101 ++++++++++++++++++++++++++++++ 2 files changed, 138 insertions(+) create mode 100644 modules/library/api.go create mode 100644 modules/library/comp_configure.go diff --git a/modules/library/api.go b/modules/library/api.go new file mode 100644 index 000000000..ab2710e6a --- /dev/null +++ b/modules/library/api.go @@ -0,0 +1,37 @@ +package library + +import ( + "go_dreamfactory/lego/core" + "go_dreamfactory/modules" +) + +const ( + LibraryGetListResp = "getlist" + LibraryChallengeResp = "challenge" + LibrarySkillLvResp = "skilllv" + LibraryGetRewardResp = "getreward" + LibraryBuyResp = "buy" + LibraryRankListResp = "ranklist" +) + +type apiComp struct { + modules.MCompGate + service core.IService + configure *configureComp + module *Library +} + +//组件初始化接口 +func (this *apiComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) { + err = this.MCompGate.Init(service, module, comp, options) + this.module = module.(*Library) + + this.service = service + return +} + +func (this *apiComp) Start() (err error) { + err = this.MCompGate.Start() + + return +} diff --git a/modules/library/comp_configure.go b/modules/library/comp_configure.go new file mode 100644 index 000000000..20981c97e --- /dev/null +++ b/modules/library/comp_configure.go @@ -0,0 +1,101 @@ +package library + +import ( + "go_dreamfactory/lego/core" + "go_dreamfactory/lego/sys/log" + "go_dreamfactory/modules" + "go_dreamfactory/sys/configure" + cfg "go_dreamfactory/sys/configure/structs" + "sync" +) + +const ( + game_huntingboss = "game_huntingboss.json" + game_challenge = "game_huntingchallenge.json" +) + +///配置管理基础组件 +type configureComp struct { + hlock sync.RWMutex + modules.MCompConfigure + _huntingMap map[int64]*cfg.GameHuntingBossData +} + +//组件初始化接口 +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._huntingMap = make(map[int64]*cfg.GameHuntingBossData, 0) + configure.RegisterConfigure(game_huntingboss, cfg.NewGameHuntingBoss, func() { + if v, err := this.GetConfigure(game_huntingboss); err == nil { + if configure, ok := v.(*cfg.GameHuntingBoss); ok { + this.hlock.Lock() + defer this.hlock.Unlock() + for _, value := range configure.GetDataList() { + this._huntingMap[int64(value.Type<<16)+int64(value.Difficulty)] = value + } + return + } + } else { + log.Errorf("get game_huntingboss conf err:%v", err) + } + return + }) + err = this.LoadConfigure(game_challenge, cfg.NewGameHuntingChallenge) + return +} + +// 参数: boss类型 难度 +func (this *configureComp) GetHuntingBossConfigData(bossType int32, difficulty int32) (data *cfg.GameHuntingBossData) { + + return this._huntingMap[int64(bossType<<16)+int64(difficulty)] +} + +//加载多个配置文件 +func (this *configureComp) LoadMultiConfigure(confs map[string]interface{}) (err error) { + for k, v := range confs { + err = configure.RegisterConfigure(k, v, nil) + if err != nil { + log.Errorf("配置文件:%s解析失败!", k) + break + } + } + return +} + +//读取配置数据 +func (this *configureComp) GetConfigure(name string) (v interface{}, err error) { + return configure.GetConfigure(name) +} + +// get boss Type +func (this *configureComp) GetHuntingBossTypeConfigData() (mapType map[int32]struct{}) { + + mapType = make(map[int32]struct{}, 0) + if v, err := this.GetConfigure(game_huntingboss); err == nil { + if configure, ok := v.(*cfg.GameHuntingBoss); ok { + this.hlock.Lock() + defer this.hlock.Unlock() + for _, value := range configure.GetDataList() { + if _, ok := mapType[value.Type]; !ok { + mapType[value.Type] = struct{}{} + } + } + + } + } + return +} + +func (this *configureComp) GetBuyChallengeCount(index int32) (data *cfg.GameHuntingChallengeData) { + if v, err := this.GetConfigure(game_challenge); err == nil { + if configure, ok := v.(*cfg.GameHuntingChallenge); ok { + data = configure.Get(index) + return + } + } else { + log.Errorf("get game_challenge conf err:%v", err) + } + + return +}