From d3d4998ec7c8f63d786b4489d55a3f8ebeba16de Mon Sep 17 00:00:00 2001 From: liwei1dao Date: Thu, 14 Sep 2023 11:03:14 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/robot/modulerobot_mainline.go | 82 +++++++++++++++++++++++++-- modules/shop/model_shop.go | 14 ++++- 2 files changed, 88 insertions(+), 8 deletions(-) diff --git a/modules/robot/modulerobot_mainline.go b/modules/robot/modulerobot_mainline.go index 754735de1..217a937e8 100644 --- a/modules/robot/modulerobot_mainline.go +++ b/modules/robot/modulerobot_mainline.go @@ -49,12 +49,45 @@ func (this *ModuleRobot_MainLine) Receive(robot IRobot, stype string, message pr return } func (this *ModuleRobot_MainLine) OncePipeline(robot IRobot) (err error) { + var ( + errdata *pb.ErrorData + ) + if _, errdata = robot.SendMessage("mainline", "info", &pb.MainlineInfoReq{}); errdata != nil { + err = errors.New(fmt.Sprintf("code:%d message:%s", errdata.Code, errdata.Message)) + return + } return } //机器人执行流 func (this *ModuleRobot_MainLine) DoPipeline(robot IRobot) (err error) { - + var ( + errdata *pb.ErrorData + heromodule *ModuleRobot_Hero + conf *cfg.GameMainStageData + heros []string + resp proto.Message + ) + if conf, err = this.findcanpasslevel(); err != nil { //找到目标管卡 + return + } + heromodule = robot.GetModule(comm.ModuleHero).(*ModuleRobot_Hero) + heros = heromodule.getbattlehero() + if resp, errdata = robot.SendMessage("mainline", "challenge", + &pb.MainlineChallengeReq{Level: conf.Id, Battle: &pb.BattleFormation{ + Format: heros, + }}); errdata != nil { + err = errors.New(fmt.Sprintf("code:%d message:%s", errdata.Code, errdata.Message)) + return + } + if _, errdata = robot.SendMessage("mainline", "challengeover", &pb.MainlineChallengeOverReq{Level: conf.Id, Report: &pb.BattleReport{ + Info: resp.(*pb.MainlineChallengeResp).Info, + WinSide: 1, + }}); errdata != nil { + err = errors.New(fmt.Sprintf("code:%d message:%s", errdata.Code, errdata.Message)) + return + } + this.info.Level[conf.Id] = 32 return } @@ -63,10 +96,6 @@ func (this *ModuleRobot_MainLine) DoTask(robot IRobot, taskconf *cfg.GameWorldTa var ( errdata *pb.ErrorData ) - if _, errdata = robot.SendMessage("mainline", "info", &pb.MainlineInfoReq{}); errdata != nil { - err = errors.New(fmt.Sprintf("code:%d message:%s", errdata.Code, errdata.Message)) - return - } switch comm.TaskType(condconf.Type) { case comm.Rtype61: var ( @@ -179,3 +208,46 @@ func (this *ModuleRobot_MainLine) getGameMainStageDatas() (confs []*cfg.GameMain } return } + +func (this *ModuleRobot_MainLine) findcanpasslevel() (conf *cfg.GameMainStageData, err error) { + var ( + v interface{} + confs []*cfg.GameMainStageData + ok bool + ) + if v, err = configure.GetConfigure(game_mainstage); err != nil { + return + } else { + for _, tempconf := range v.(*cfg.GameMainStage).GetDataList() { + if _, ok = this.info.Level[tempconf.Id]; ok { //已通关 + continue + } + ok = true + //前置组判断 + for _, v := range tempconf.PreviousGroupId { + confs = this.group[v] + for _, nconf := range confs { + if _, ok = this.info.Level[nconf.Id]; !ok { + ok = false + break + } + } + if !ok { + break + } + } + if !ok { + continue + } + if tempconf.Previoustage != 0 { + if _, ok = this.info.Level[tempconf.Previoustage]; !ok { + continue + } + } + conf = tempconf + return + } + err = fmt.Errorf("no fund lv") + } + return +} diff --git a/modules/shop/model_shop.go b/modules/shop/model_shop.go index 61a21a6c0..83e4155c6 100644 --- a/modules/shop/model_shop.go +++ b/modules/shop/model_shop.go @@ -7,6 +7,7 @@ import ( "go_dreamfactory/modules" "go_dreamfactory/pb" + "go.mongodb.org/mongo-driver/bson/primitive" "go.mongodb.org/mongo-driver/mongo" "go.mongodb.org/mongo-driver/x/bsonx" ) @@ -30,11 +31,18 @@ func (this *modelShopComp) Init(service core.IService, module core.IModule, comp } //查询用户装备数据 -func (this *modelShopComp) QueryUserShopData(uId string) (data *pb.DBShop, err error) { +func (this *modelShopComp) QueryUserShopData(uid string) (data *pb.DBShop, err error) { data = &pb.DBShop{} - if err = this.Get(uId, data); err != nil && err != mgo.MongodbNil { + if err = this.Get(uid, data); err != nil && err != mgo.MongodbNil { this.module.Errorf("err:%v", err) } - err = nil + + if err == mgo.MongodbNil { //没有数据初始化数据 + data = &pb.DBShop{ + Id: primitive.NewObjectID().Hex(), + Uid: uid, + } + err = this.Add(uid, data) + } return }