diff --git a/modules/robot/modulerobot_pagoda.go b/modules/robot/modulerobot_pagoda.go new file mode 100644 index 000000000..2b42987ba --- /dev/null +++ b/modules/robot/modulerobot_pagoda.go @@ -0,0 +1,99 @@ +package robot + +import ( + "errors" + "go_dreamfactory/comm" + "go_dreamfactory/pb" + cfg "go_dreamfactory/sys/configure/structs" + + "google.golang.org/protobuf/proto" +) + +//爬塔模块 机器人 +type ModuleRobot_Pagoda struct { + pagoda *pb.DBPagoda +} + +func (this *ModuleRobot_Pagoda) Init() (err error) { + return +} + +//接收到消息 +func (this *ModuleRobot_Pagoda) Receive(robot IRobot, stype string, message proto.Message) (err error) { + switch stype { + case "challengeover": + //resp := message.(*pb.PagodaChallengeOverResp) + + break + case "getlist": + resp := message.(*pb.PagodaGetListResp) + this.pagoda = resp.Data + break + } + return +} + +//机器人执行流 +func (this *ModuleRobot_Pagoda) DoPipeline(robot IRobot) (err error) { + var ( + errdata *pb.ErrorData + ) + // 获取爬塔信息 + if _, errdata = robot.SendMessage("pagoda", "getlist", &pb.PagodaGetListReq{}); errdata != nil { + err = errors.New(errdata.Message) + return + } + //创角 + if _, errdata = robot.SendMessage("pagoda", "challengeover", &pb.PagodaChallengeOverReq{ + Cid: 1, + Report: &pb.BattleReport{}, + }); errdata != nil { + if errdata.Code == pb.ErrorCode_RoleCreated { //已创角 + err = nil + } else { + err = errors.New(errdata.Message) + } + + return + } + return +} + +//做任务 +func (this *ModuleRobot_Pagoda) DoTask(robot IRobot, taskconf *cfg.GameWorldTaskData, condconf *cfg.GameBuriedCondiData) (err error) { + + var ( + errdata *pb.ErrorData + conf *cfg.GamePagodaData + ) + + switch comm.TaskType(condconf.Type) { + case comm.Rtype168: //完成功夫大师挑战塔第X层 + var ( + heromodule *ModuleRobot_Hero + heros []string + resp proto.Message + ) + heromodule = robot.GetModule(comm.ModuleHero).(*ModuleRobot_Hero) + heros = heromodule.getbattlehero() + if resp, errdata = robot.SendTaskMessage(taskconf.Key, condconf.Id, "pagoda", "challenge", &pb.PagodaChallengeReq{ + Cid: conf.Key, + Battle: &pb.BattleFormation{ + Format: heros, + }}); errdata != nil { + err = errors.New(errdata.Message) + return + } + if _, errdata = robot.SendTaskMessage(taskconf.Key, condconf.Id, "pagoda", "challengeover", &pb.PagodaChallengeOverReq{ + Cid: conf.Key, + Report: &pb.BattleReport{ + Info: resp.(*pb.PagodaChallengeResp).Info, + WinSide: 1, + }}); errdata != nil { + err = errors.New(errdata.Message) + return + } + break + } + return +} diff --git a/modules/robot/robot.go b/modules/robot/robot.go index a129853be..6ac6c3bbf 100644 --- a/modules/robot/robot.go +++ b/modules/robot/robot.go @@ -51,6 +51,7 @@ func (this *Robot) Init(addr string, client IClient) (err error) { this.modules[comm.ModuleWtask] = new(ModuleRobot_WTask) this.modules[comm.ModulePractice] = new(ModuleRobot_Practice) this.modules[comm.ModuleMainline] = new(ModuleRobot_MainLine) + this.modules[comm.ModuleUser] = new(ModuleRobot_Pagoda) for _, v := range this.modules { v.Init() }