package robot import ( "errors" "fmt" "go_dreamfactory/comm" "go_dreamfactory/pb" cfg "go_dreamfactory/sys/configure/structs" "google.golang.org/protobuf/proto" ) //用户模块 机器人 type ModuleRobot_Arena struct { Info *pb.DBArenaUser players []*pb.ArenaPlayer index int32 } func (this *ModuleRobot_Arena) Init() (err error) { return } //接收到消息 func (this *ModuleRobot_Arena) Receive(robot IRobot, stype string, message proto.Message) (err error) { switch stype { case "info": resp := message.(*pb.ArenaInfoResp) this.Info = resp.Info break case "matche": resp := message.(*pb.ArenaMatcheResp) this.players = resp.Players break } return } func (this *ModuleRobot_Arena) OncePipeline(robot IRobot) (err error) { var ( errdata *pb.ErrorData ) if _, errdata = robot.SendMessage("arena", "info", &pb.ArenaInfoReq{}); errdata != nil { err = errors.New(fmt.Sprintf("code:%d message:%s", errdata.Code, errdata.Message)) return } return } //机器人执行流 func (this *ModuleRobot_Arena) DoPipeline(robot IRobot) (err error) { var ( errdata *pb.ErrorData heromodule *ModuleRobot_Hero heros []string player *pb.ArenaPlayer resp proto.Message ) if this.players == nil || this.index >= int32(len(this.players)) { if _, errdata = robot.SendMessage("arena", "matche", &pb.ArenaMatcheReq{}); errdata != nil { err = errors.New(fmt.Sprintf("code:%d message:%s", errdata.Code, errdata.Message)) return } this.index = 0 } heromodule = robot.GetModule(comm.ModuleHero).(*ModuleRobot_Hero) heros = heromodule.getbattlehero() player = this.players[this.index] this.index++ if player == nil { return } if resp, errdata = robot.SendMessage("arena", "challenge", &pb.ArenaChallengeReq{ Playerid: player.Uinfo.Uid, Isai: player.Isai, MformatId: player.Mformatid, 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("arena", "challengereward", &pb.ArenaChallengeRewardReq{ Iswin: true, Isai: player.Isai, Aiintegral: player.Integral, Aiinfo: player.Uinfo, Report: &pb.BattleReport{ Info: resp.(*pb.ArenaChallengeResp).Info, WinSide: 1, }}); errdata != nil { err = errors.New(fmt.Sprintf("code:%d message:%s", errdata.Code, errdata.Message)) return } return } //做任务 func (this *ModuleRobot_Arena) DoTask(robot IRobot, taskconf *cfg.GameWorldTaskData, condconf *cfg.GameBuriedCondiData) (err error) { var ( errdata *pb.ErrorData ) if _, errdata = robot.SendMessage("arena", "info", &pb.ArenaInfoReq{}); errdata != nil { err = errors.New(fmt.Sprintf("code:%d message:%s", errdata.Code, errdata.Message)) return } if _, errdata = robot.SendMessage("arena", "matche", &pb.ArenaMatcheReq{}); errdata != nil { err = errors.New(fmt.Sprintf("code:%d message:%s", errdata.Code, errdata.Message)) return } switch comm.TaskType(condconf.Type) { case comm.Rtype128, comm.Rtype129, comm.Rtype131: var ( heromodule *ModuleRobot_Hero heros []string player *pb.ArenaPlayer resp proto.Message ) heromodule = robot.GetModule(comm.ModuleHero).(*ModuleRobot_Hero) heros = heromodule.getbattlehero() for _, v := range this.players { player = v break } if resp, errdata = robot.SendTaskMessage(taskconf.Key, condconf.Id, "arena", "challenge", &pb.ArenaChallengeReq{ Playerid: player.Uinfo.Uid, Isai: player.Isai, MformatId: player.Mformatid, Battle: &pb.BattleFormation{ Format: heros, }}); errdata != nil { err = errors.New(fmt.Sprintf("code:%d message:%s", errdata.Code, errdata.Message)) return } if _, errdata = robot.SendTaskMessage(taskconf.Key, condconf.Id, "arena", "challengeover", &pb.ArenaChallengeRewardReq{ Iswin: true, Isai: player.Isai, Aiintegral: player.Integral, Aiinfo: player.Uinfo, 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 } break default: } return }