go_dreamfactory/modules/robot/modulerobot_mainline.go
2023-08-24 18:45:06 +08:00

179 lines
4.4 KiB
Go

package robot
import (
"errors"
"fmt"
"go_dreamfactory/comm"
"go_dreamfactory/pb"
"go_dreamfactory/sys/configure"
cfg "go_dreamfactory/sys/configure/structs"
"google.golang.org/protobuf/proto"
)
//用户模块 机器人
type ModuleRobot_MainLine struct {
info *pb.DBMainline
group map[int32][]*cfg.GameMainStageData
}
func (this *ModuleRobot_MainLine) Init() (err error) {
var (
confs []*cfg.GameMainStageData
ok bool
)
this.group = make(map[int32][]*cfg.GameMainStageData)
if confs, err = this.getGameMainStageDatas(); err != nil {
return
}
for _, v := range confs {
if _, ok = this.group[v.GroupId]; !ok {
this.group[v.GroupId] = make([]*cfg.GameMainStageData, 0)
}
this.group[v.GroupId] = append(this.group[v.GroupId], v)
}
return
}
//接收到消息
func (this *ModuleRobot_MainLine) Receive(robot IRobot, stype string, message proto.Message) (err error) {
switch stype {
case "info":
resp := message.(*pb.MainlineInfoResp)
this.info = resp.Info
break
case "create":
// resp := message.(*pb.UserCreateResp)
break
}
return
}
//机器人执行流
func (this *ModuleRobot_MainLine) DoPipeline(robot IRobot) (err error) {
return
}
//做任务
func (this *ModuleRobot_MainLine) DoTask(robot IRobot, taskconf *cfg.GameWorldTaskData, condconf *cfg.GameBuriedCondiData) (err error) {
var (
errdata *pb.ErrorData
)
if _, errdata = robot.SendMessage("mainline", "info", &pb.MainlineInfoReq{}); errdata != nil {
err = errors.New(errdata.Message)
return
}
switch comm.TaskType(condconf.Type) {
case comm.Rtype61:
var (
conf *cfg.GameMainStageData
ok bool
)
if _, ok = this.info.Level[condconf.Filter[0]]; ok { //已通关
return
}
if conf, err = this.getGameMainStageData(condconf.Filter[0]); err != nil {
return
}
if conf, err = this.findlevel(conf); err != nil { //找到目标管卡
return
}
switch conf.Episodetype {
case 1, 4, 8:
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, "mainline", "challenge",
&pb.MainlineChallengeReq{Level: conf.Id, Battle: &pb.BattleFormation{
Format: heros,
}}); errdata != nil {
err = errors.New(errdata.Message)
return
}
if _, errdata = robot.SendTaskMessage(taskconf.Key, condconf.Id, "mainline", "challengeover", &pb.MainlineChallengeOverReq{Level: conf.Id, Report: &pb.BattleReport{
Info: resp.(*pb.MainlineChallengeResp).Info,
WinSide: 1,
}}); errdata != nil {
err = errors.New(errdata.Message)
return
}
break
case 3, 7:
if _, errdata = robot.SendTaskMessage(taskconf.Key, condconf.Id, "mainline", "levelpass", &pb.MainlineLevelPassReq{Level: conf.Id}); errdata != nil {
err = errors.New(errdata.Message)
return
}
default:
err = fmt.Errorf("no fund mainline id:%d type:%d", conf.Id, conf.Episodetype)
}
}
return
}
func (this *ModuleRobot_MainLine) findlevel(conf *cfg.GameMainStageData) (rconf *cfg.GameMainStageData, err error) {
var (
confs []*cfg.GameMainStageData
nconf *cfg.GameMainStageData
ok bool
)
//前置组判断
for _, v := range conf.PreviousGroupId {
confs = this.group[v]
for _, nconf := range confs {
if _, ok = this.info.Level[nconf.Id]; !ok {
return this.findlevel(nconf)
}
}
}
if conf.Previoustage != 0 {
if _, ok = this.info.Level[conf.Previoustage]; !ok {
if nconf, err = this.getGameMainStageData(conf.Previoustage); err != nil {
return
}
return this.findlevel(nconf)
}
}
//没找到前置了,直接放回
rconf = conf
return
}
// 读取主线关卡表
func (this *ModuleRobot_MainLine) getGameMainStageData(id int32) (conf *cfg.GameMainStageData, err error) {
var (
v interface{}
ok bool
)
if v, err = configure.GetConfigure(game_mainstage); err != nil {
return
} else {
if conf, ok = v.(*cfg.GameMainStage).GetDataMap()[id]; !ok {
err = comm.NewNotFoundConfErr("robot", game_mainstage, id)
return
}
}
return
}
// 读取主线关卡表
func (this *ModuleRobot_MainLine) getGameMainStageDatas() (confs []*cfg.GameMainStageData, err error) {
var (
v interface{}
)
if v, err = configure.GetConfigure(game_mainstage); err != nil {
return
} else {
confs = v.(*cfg.GameMainStage).GetDataList()
}
return
}