From 7f57b8521aac2965bff0397511ec116a64a6eb72 Mon Sep 17 00:00:00 2001 From: meixiongfeng <766881921@qq.com> Date: Mon, 26 Dec 2022 18:37:17 +0800 Subject: [PATCH] =?UTF-8?q?=E8=87=AA=E5=8A=A8=E6=88=98=E6=96=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- comm/const.go | 7 +++- modules/auto/api.go | 49 ++++++++++++++++++++++++ modules/auto/api_buy.go | 22 +++++++++++ modules/auto/api_challenge.go | 23 +++++++++++ modules/auto/api_challengeover.go | 23 +++++++++++ modules/auto/api_getlist.go | 19 ++++++++++ modules/auto/comp_configure.go | 39 +++++++++++++++++++ modules/auto/model_auto.go | 43 +++++++++++++++++++++ modules/auto/module.go | 63 +++++++++++++++++++++++++++++++ 9 files changed, 286 insertions(+), 2 deletions(-) create mode 100644 modules/auto/api.go create mode 100644 modules/auto/api_buy.go create mode 100644 modules/auto/api_challenge.go create mode 100644 modules/auto/api_challengeover.go create mode 100644 modules/auto/api_getlist.go create mode 100644 modules/auto/comp_configure.go create mode 100644 modules/auto/model_auto.go create mode 100644 modules/auto/module.go diff --git a/comm/const.go b/comm/const.go index b31c0dca0..e94e39501 100644 --- a/comm/const.go +++ b/comm/const.go @@ -158,8 +158,8 @@ const ( TableLinestory = "linestory" TableFetterstory = "fetterstory" - TableLibrary = "library" - TableFetter = "herofetter" + TableLibrary = "library" + TableFetter = "herofetter" TableCrossSession = "crosssession" @@ -208,6 +208,9 @@ const ( TableEnchantRank = "enchantRank" TableEnchant = "enchant" + + // 自动战斗 + TableAuto = "autoBattle" ) //RPC服务接口定义处 diff --git a/modules/auto/api.go b/modules/auto/api.go new file mode 100644 index 000000000..4d2a9625e --- /dev/null +++ b/modules/auto/api.go @@ -0,0 +1,49 @@ +package autoBattle + +import ( + "go_dreamfactory/comm" + "go_dreamfactory/lego/core" + "go_dreamfactory/modules" +) + +const ( + HuntingGetListResp = "getlist" + HuntingChallengeResp = "challenge" + HuntingChallengeOverResp = "challengeover" + HuntingSkillLvResp = "skilllv" + HuntingGetRewardResp = "getreward" + HuntingBuyResp = "buy" + HuntingRankListResp = "ranklist" +) + +type apiComp struct { + modules.MCompGate + service core.IService + configure *configureComp + module *AutoBattle + friend comm.IFriend + chat comm.IChat +} + +//组件初始化接口 +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.(*AutoBattle) + + this.service = service + return +} + +func (this *apiComp) Start() (err error) { + err = this.MCompGate.Start() + var module core.IModule + if module, err = this.service.GetModule(comm.ModuleFriend); err != nil { + return + } + this.friend = module.(comm.IFriend) + if module, err = this.service.GetModule(comm.ModuleChat); err != nil { + return + } + this.chat = module.(comm.IChat) + return +} diff --git a/modules/auto/api_buy.go b/modules/auto/api_buy.go new file mode 100644 index 000000000..854f579d0 --- /dev/null +++ b/modules/auto/api_buy.go @@ -0,0 +1,22 @@ +package autoBattle + +import ( + "go_dreamfactory/comm" + "go_dreamfactory/pb" + + "google.golang.org/protobuf/proto" +) + +//参数校验 +func (this *apiComp) BuyCheck(session comm.IUserSession, req *pb.HuntingBuyReq) (code pb.ErrorCode) { + if req.Count <= 0 { + code = pb.ErrorCode_ReqParameterError + return + } + return +} + +func (this *apiComp) Buy(session comm.IUserSession, req *pb.HuntingBuyReq) (code pb.ErrorCode, data proto.Message) { + + return +} diff --git a/modules/auto/api_challenge.go b/modules/auto/api_challenge.go new file mode 100644 index 000000000..5f0367f0b --- /dev/null +++ b/modules/auto/api_challenge.go @@ -0,0 +1,23 @@ +package autoBattle + +import ( + "go_dreamfactory/comm" + "go_dreamfactory/pb" + + "google.golang.org/protobuf/proto" +) + +//参数校验 +func (this *apiComp) ChallengeCheck(session comm.IUserSession, req *pb.HuntingChallengeReq) (code pb.ErrorCode) { + if req.BossType <= 0 && req.Difficulty > 0 { + code = pb.ErrorCode_ReqParameterError + return + } + return +} + +///挑战主线关卡 +func (this *apiComp) Challenge(session comm.IUserSession, req *pb.HuntingChallengeReq) (code pb.ErrorCode, data proto.Message) { + + return +} diff --git a/modules/auto/api_challengeover.go b/modules/auto/api_challengeover.go new file mode 100644 index 000000000..baefb5dc7 --- /dev/null +++ b/modules/auto/api_challengeover.go @@ -0,0 +1,23 @@ +package autoBattle + +import ( + "go_dreamfactory/comm" + "go_dreamfactory/pb" + + "google.golang.org/protobuf/proto" +) + +//参数校验 +func (this *apiComp) ChallengeOverCheck(session comm.IUserSession, req *pb.HuntingChallengeOverReq) (code pb.ErrorCode) { + if req.BossType <= 0 && req.Difficulty > 0 { + code = pb.ErrorCode_ReqParameterError + return + } + return +} + +///挑战主线关卡 +func (this *apiComp) ChallengeOver(session comm.IUserSession, req *pb.HuntingChallengeOverReq) (code pb.ErrorCode, data proto.Message) { + + return +} diff --git a/modules/auto/api_getlist.go b/modules/auto/api_getlist.go new file mode 100644 index 000000000..3a7f1e53f --- /dev/null +++ b/modules/auto/api_getlist.go @@ -0,0 +1,19 @@ +package autoBattle + +import ( + "go_dreamfactory/comm" + "go_dreamfactory/pb" + + "google.golang.org/protobuf/proto" +) + +//参数校验 +func (this *apiComp) GetListCheck(session comm.IUserSession, req *pb.HuntingGetListReq) (code pb.ErrorCode) { + + return +} + +func (this *apiComp) GetList(session comm.IUserSession, req *pb.HuntingGetListReq) (code pb.ErrorCode, data proto.Message) { + + return +} diff --git a/modules/auto/comp_configure.go b/modules/auto/comp_configure.go new file mode 100644 index 000000000..b3427bfe5 --- /dev/null +++ b/modules/auto/comp_configure.go @@ -0,0 +1,39 @@ +package autoBattle + +import ( + "go_dreamfactory/lego/core" + "go_dreamfactory/lego/sys/log" + "go_dreamfactory/modules" + "go_dreamfactory/sys/configure" +) + +const () + +///配置管理基础组件 +type configureComp struct { + modules.MCompConfigure +} + +//组件初始化接口 +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) + + return +} + +//加载多个配置文件 +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) +} diff --git a/modules/auto/model_auto.go b/modules/auto/model_auto.go new file mode 100644 index 000000000..8f5ad8c59 --- /dev/null +++ b/modules/auto/model_auto.go @@ -0,0 +1,43 @@ +package autoBattle + +import ( + "go_dreamfactory/comm" + "go_dreamfactory/lego/core" + "go_dreamfactory/modules" + "go_dreamfactory/pb" + + "go.mongodb.org/mongo-driver/mongo" + "go.mongodb.org/mongo-driver/x/bsonx" +) + +type modelAutoBattle struct { + modules.MCompModel + module *AutoBattle +} + +func (this *modelAutoBattle) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) { + this.TableName = string(comm.TableAuto) + err = this.MCompModel.Init(service, module, comp, options) + this.module = module.(*AutoBattle) + // uid 创建索引 + this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{ + Keys: bsonx.Doc{{Key: "uid", Value: bsonx.Int32(1)}}, + }) + return +} + +func (this *modelAutoBattle) modifyAutoBattleDataByObjId(uid string, id string, data map[string]interface{}) error { + err := this.ChangeList(uid, id, data) + return err +} + +// 获取列表信息 +func (this *modelAutoBattle) getAutoBattleList(uid string) (result *pb.DBAutoBattle, err error) { + result = &pb.DBAutoBattle{} + if err = this.Get(uid, result); err != nil { + return + } + + err = nil + return result, err +} diff --git a/modules/auto/module.go b/modules/auto/module.go new file mode 100644 index 000000000..558a0f5fa --- /dev/null +++ b/modules/auto/module.go @@ -0,0 +1,63 @@ +package autoBattle + +import ( + "go_dreamfactory/comm" + "go_dreamfactory/lego/core" + "go_dreamfactory/modules" + "go_dreamfactory/pb" +) + +type AutoBattle struct { + modules.ModuleBase + modelAutoBattle *modelAutoBattle + api *apiComp + configure *configureComp + battle comm.IBattle + service core.IService +} + +func NewModule() core.IModule { + return &AutoBattle{} +} + +func (this *AutoBattle) GetType() core.M_Modules { + return comm.ModuleHunting +} + +func (this *AutoBattle) Init(service core.IService, module core.IModule, options core.IModuleOptions) (err error) { + err = this.ModuleBase.Init(service, module, options) + this.service = service + return +} + +func (this *AutoBattle) Start() (err error) { + err = this.ModuleBase.Start() + var module core.IModule + if module, err = this.service.GetModule(comm.ModuleBattle); err != nil { + return + } + + this.battle = module.(comm.IBattle) + return +} + +func (this *AutoBattle) OnInstallComp() { + this.ModuleBase.OnInstallComp() + this.api = this.RegisterComp(new(apiComp)).(*apiComp) + + this.configure = this.RegisterComp(new(configureComp)).(*configureComp) +} + +// 接口信息 +func (this *AutoBattle) ModifyAutoData(uid string, id string, data map[string]interface{}) (code pb.ErrorCode) { + err := this.modelAutoBattle.modifyAutoBattleDataByObjId(uid, id, data) + if err != nil { + code = pb.ErrorCode_DBError + } + return +} + +func (this *AutoBattle) CheckUserBaseHuntingInfo(uid string) (data []*pb.DBHuntingRank) { + + return +}