From 3eb6773160d4a53f9977776a244ed67c46b787bd Mon Sep 17 00:00:00 2001 From: meixiongfeng <766881921@qq.com> Date: Tue, 16 Aug 2022 11:05:46 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BE=8E=E9=A3=9F=E9=A6=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- comm/const.go | 2 + modules/gourmet/api.go | 32 +++++++++++ modules/gourmet/api_getReward.go | 27 +++++++++ modules/gourmet/api_getlist.go | 20 +++++++ modules/gourmet/comp_configure.go | 95 +++++++++++++++++++++++++++++++ modules/gourmet/model_pagoda.go | 20 +++++++ modules/gourmet/module.go | 42 ++++++++++++++ 7 files changed, 238 insertions(+) create mode 100644 modules/gourmet/api.go create mode 100644 modules/gourmet/api_getReward.go create mode 100644 modules/gourmet/api_getlist.go create mode 100644 modules/gourmet/comp_configure.go create mode 100644 modules/gourmet/model_pagoda.go create mode 100644 modules/gourmet/module.go diff --git a/comm/const.go b/comm/const.go index 0c61ef50c..bdee2e3bb 100644 --- a/comm/const.go +++ b/comm/const.go @@ -93,6 +93,8 @@ const ( TablePagoda = "pagoda" ///武馆数据表 TableMartialhall = "martialhall" + // 美食馆 + TableGourmet = "gourmet" ) //RPC服务接口定义处 diff --git a/modules/gourmet/api.go b/modules/gourmet/api.go new file mode 100644 index 000000000..e85ebd6e5 --- /dev/null +++ b/modules/gourmet/api.go @@ -0,0 +1,32 @@ +package gourmet + +import ( + "go_dreamfactory/lego/core" + "go_dreamfactory/modules" +) + +const ( + PagodaGetListResp = "getlist" + PagodaChallengeResp = "challenge" + PagodaGetRewardResp = "getreward" +) + +type apiComp struct { + modules.MCompGate + service core.IService + module *Gourmet +} + +//组件初始化接口 +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.(*Gourmet) + this.service = service + return +} + +func (this *apiComp) Start() (err error) { + err = this.MCompGate.Start() + + return +} diff --git a/modules/gourmet/api_getReward.go b/modules/gourmet/api_getReward.go new file mode 100644 index 000000000..e8b9d36a7 --- /dev/null +++ b/modules/gourmet/api_getReward.go @@ -0,0 +1,27 @@ +package gourmet + +import ( + "go_dreamfactory/comm" + "go_dreamfactory/pb" + + "google.golang.org/protobuf/proto" +) + +//参数校验 +func (this *apiComp) GetRewardCheck(session comm.IUserSession, req *pb.PagodaGetRewardReq) (code pb.ErrorCode) { + if req.Id <= 0 { + code = pb.ErrorCode_ReqParameterError + } + return +} + +///获取主线关卡信息 +func (this *apiComp) GetReward(session comm.IUserSession, req *pb.PagodaGetRewardReq) (code pb.ErrorCode, data proto.Message) { + + code = this.GetRewardCheck(session, req) + if code != pb.ErrorCode_Success { + return // 参数校验失败直接返回 + } + + return +} diff --git a/modules/gourmet/api_getlist.go b/modules/gourmet/api_getlist.go new file mode 100644 index 000000000..466147b62 --- /dev/null +++ b/modules/gourmet/api_getlist.go @@ -0,0 +1,20 @@ +package gourmet + +import ( + "go_dreamfactory/comm" + "go_dreamfactory/pb" + + "google.golang.org/protobuf/proto" +) + +//参数校验 +func (this *apiComp) GetListCheck(session comm.IUserSession, req *pb.PagodaGetListReq) (code pb.ErrorCode) { + + return +} + +///获取主线关卡信息 +func (this *apiComp) GetList(session comm.IUserSession, req *pb.PagodaGetListReq) (code pb.ErrorCode, data proto.Message) { + + return +} diff --git a/modules/gourmet/comp_configure.go b/modules/gourmet/comp_configure.go new file mode 100644 index 000000000..6f799573f --- /dev/null +++ b/modules/gourmet/comp_configure.go @@ -0,0 +1,95 @@ +package gourmet + +import ( + "go_dreamfactory/lego/core" + "go_dreamfactory/lego/core/cbase" + "go_dreamfactory/lego/sys/log" + "go_dreamfactory/sys/configure" + cfg "go_dreamfactory/sys/configure/structs" + "sync" +) + +const ( + game_pagoda = "game_pagoda.json" + game_pagodaseasonreward = "game_pagodaseasonreward.json" + game_pagodataskreward = "game_pagodataskreward.json" +) + +///配置管理基础组件 +type configureComp struct { + cbase.ModuleCompBase + hlock sync.RWMutex + _pagodaMap map[int64]*cfg.GamepagodaData +} + +//组件初始化接口 +func (this *configureComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) { + err = this.ModuleCompBase.Init(service, module, comp, options) + err = this.LoadMultiConfigure(map[string]interface{}{ + //game_pagoda: cfg.NewGame_pagoda, + game_pagodaseasonreward: cfg.NewGamepagodaSeasonReward, + game_pagodataskreward: cfg.NewGamepagodaTaskReward, + }) + + this._pagodaMap = make(map[int64]*cfg.GamepagodaData, 0) + configure.RegisterConfigure(game_pagoda, cfg.NewGamepagoda, func() { + if v, err := this.GetConfigure(game_pagoda); err == nil { + if configure, ok := v.(*cfg.Gamepagoda); ok { + this.hlock.Lock() + defer this.hlock.Unlock() + for _, value := range configure.GetDataList() { + this._pagodaMap[int64(value.PagodaType<<16)+int64(value.LayerNum)] = value + } + return + } + } + log.Errorf("get game_pagoda conf err:%v", err) + return + }) + return +} + +// 获取爬塔信息 参数1 塔类型 参数2 层数 +func (this *configureComp) GetPagodaConfigData(PagodaType int32, floorId int32) (data *cfg.GamepagodaData) { + + return this._pagodaMap[int64(PagodaType<<16)+int64(floorId)] +} + +//加载多个配置文件 +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) +} + +// 获取爬塔配置表数据 +func (this *configureComp) GetPagodaconfig(id int32) (data *cfg.GamepagodaData) { + if v, err := this.GetConfigure(game_pagoda); err != nil { + log.Errorf("get global conf err:%v", err) + return + } else { + var ( + configure *cfg.Gamepagoda + ok bool + ) + if configure, ok = v.(*cfg.Gamepagoda); !ok { + log.Errorf("%T no is *cfg.Game_pagodaData", v) + return + } + + if data, ok = configure.GetDataMap()[id]; ok { + return + } + } + return +} diff --git a/modules/gourmet/model_pagoda.go b/modules/gourmet/model_pagoda.go new file mode 100644 index 000000000..2c87d0d22 --- /dev/null +++ b/modules/gourmet/model_pagoda.go @@ -0,0 +1,20 @@ +package gourmet + +import ( + "go_dreamfactory/comm" + "go_dreamfactory/lego/core" + "go_dreamfactory/modules" +) + +type ModelPagoda struct { + modules.MCompModel + module *Gourmet +} + +func (this *ModelPagoda) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) { + this.TableName = string(comm.TableGourmet) + err = this.MCompModel.Init(service, module, comp, options) + this.module = module.(*Gourmet) + + return +} diff --git a/modules/gourmet/module.go b/modules/gourmet/module.go new file mode 100644 index 000000000..621242f07 --- /dev/null +++ b/modules/gourmet/module.go @@ -0,0 +1,42 @@ +package gourmet + +import ( + "go_dreamfactory/comm" + "go_dreamfactory/lego/core" + "go_dreamfactory/modules" + "go_dreamfactory/pb" +) + +type Gourmet struct { + modules.ModuleBase + modelPagoda *ModelPagoda + api *apiComp + configure *configureComp +} + +func NewModule() core.IModule { + return &Gourmet{} +} + +func (this *Gourmet) GetType() core.M_Modules { + return comm.ModulePagoda +} + +func (this *Gourmet) Init(service core.IService, module core.IModule, options core.IModuleOptions) (err error) { + err = this.ModuleBase.Init(service, module, options) + + return +} + +func (this *Gourmet) OnInstallComp() { + this.ModuleBase.OnInstallComp() + this.api = this.RegisterComp(new(apiComp)).(*apiComp) + this.modelPagoda = this.RegisterComp(new(ModelPagoda)).(*ModelPagoda) + this.configure = this.RegisterComp(new(configureComp)).(*configureComp) +} + +// 接口信息 +func (this *Gourmet) ModifyGourmetData(uid string, objId string, data map[string]interface{}) (code pb.ErrorCode) { + + return +}