188 lines
4.9 KiB
Go
188 lines
4.9 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_Pagoda struct {
|
|
pagoda *pb.DBPagoda
|
|
_mapPagoda map[int32]*cfg.GamePagodaData
|
|
mainline *ModuleRobot_MainLine
|
|
}
|
|
|
|
func (this *ModuleRobot_Pagoda) Init() (err error) {
|
|
var (
|
|
v interface{}
|
|
)
|
|
if v, err = configure.GetConfigure(game_pagoda); err == nil {
|
|
if configure, ok := v.(*cfg.GamePagoda); ok {
|
|
this._mapPagoda = make(map[int32]*cfg.GamePagodaData)
|
|
for _, value := range configure.GetDataList() {
|
|
key := value.Tab<<16 + value.LayerNum
|
|
this._mapPagoda[key] = value
|
|
}
|
|
return
|
|
}
|
|
}
|
|
|
|
//
|
|
|
|
return
|
|
}
|
|
|
|
//接收到消息
|
|
func (this *ModuleRobot_Pagoda) Receive(robot IRobot, stype string, message proto.Message) (err error) {
|
|
switch stype {
|
|
case "getlist":
|
|
resp := message.(*pb.PagodaGetListResp)
|
|
this.pagoda = resp.Data
|
|
break
|
|
case "challengeover": // 更新塔信息
|
|
resp := message.(*pb.PagodaChallengeOverResp)
|
|
this.pagoda = resp.Data
|
|
break
|
|
}
|
|
|
|
return
|
|
}
|
|
func (this *ModuleRobot_Pagoda) OncePipeline(robot IRobot) (err error) {
|
|
|
|
if _, errdata := robot.SendMessage("pagoda", "getlist", &pb.PagodaGetListReq{}); errdata != nil {
|
|
err = errors.New(fmt.Sprintf("code:%d message:%s", errdata.Code, errdata.Message))
|
|
return
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
//机器人执行流
|
|
func (this *ModuleRobot_Pagoda) DoPipeline(robot IRobot) (err error) {
|
|
var (
|
|
resp proto.Message
|
|
errdata *pb.ErrorData
|
|
)
|
|
heromodule := robot.GetModule(comm.ModuleHero).(*ModuleRobot_Hero)
|
|
heros := heromodule.getbattlehero()
|
|
|
|
this.mainline = robot.GetModule(comm.ModuleMainline).(*ModuleRobot_MainLine)
|
|
this.pagoda.PagodaId += 1
|
|
// 校验能不能打
|
|
if c, e := this.getPagodaDataById(this.pagoda.PagodaId); e != nil { // 参数有误
|
|
return
|
|
} else {
|
|
if c.Unlock != 0 {
|
|
if _, ok := this.mainline.info.Level[c.Unlock]; !ok {
|
|
return
|
|
}
|
|
}
|
|
}
|
|
|
|
if resp, errdata = robot.SendMessage("pagoda", "challenge", &pb.PagodaChallengeReq{
|
|
Cid: this.pagoda.PagodaId,
|
|
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("pagoda", "challengeover", &pb.PagodaChallengeOverReq{
|
|
Cid: this.pagoda.PagodaId,
|
|
Report: &pb.BattleReport{
|
|
Info: resp.(*pb.PagodaChallengeResp).Info,
|
|
WinSide: 1,
|
|
}}); errdata != nil {
|
|
err = errors.New(fmt.Sprintf("code:%d message:%s", errdata.Code, 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
|
|
)
|
|
// 获取爬塔信息
|
|
if _, errdata = robot.SendMessage("pagoda", "getlist", &pb.PagodaGetListReq{}); errdata != nil {
|
|
err = errors.New(fmt.Sprintf("code:%d message:%s", errdata.Code, errdata.Message))
|
|
return
|
|
}
|
|
switch comm.TaskType(condconf.Type) {
|
|
case comm.Rtype168: //完成功夫大师挑战塔第X层
|
|
var (
|
|
heromodule *ModuleRobot_Hero
|
|
heros []string
|
|
resp proto.Message
|
|
)
|
|
if conf, err = this.getPagodaData(condconf.Filter[0], this.pagoda.Data[condconf.Filter[0]]+1); err != nil { // 参数有误
|
|
return
|
|
}
|
|
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(fmt.Sprintf("code:%d message:%s", errdata.Code, 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(fmt.Sprintf("code:%d message:%s", errdata.Code, errdata.Message))
|
|
return
|
|
}
|
|
break
|
|
}
|
|
return
|
|
}
|
|
|
|
// 获取爬塔的配置
|
|
func (this *ModuleRobot_Pagoda) getPagodaData(tab int32, lv int32) (conf *cfg.GamePagodaData, err error) {
|
|
var (
|
|
v interface{}
|
|
)
|
|
if v, err = configure.GetConfigure(game_pagoda); err != nil {
|
|
return
|
|
} else {
|
|
for _, conf = range v.(*cfg.GamePagoda).GetDataList() {
|
|
if conf.Tab == tab && conf.LayerNum == lv {
|
|
return
|
|
}
|
|
}
|
|
}
|
|
err = comm.NewNotFoundConfErr("robot", game_buriedcondi, fmt.Sprintf("tab:%d,lv:%d", tab, lv))
|
|
return
|
|
}
|
|
|
|
func (this *ModuleRobot_Pagoda) getPagodaDataById(id int32) (conf *cfg.GamePagodaData, err error) {
|
|
var (
|
|
v interface{}
|
|
)
|
|
if v, err = configure.GetConfigure(game_pagoda); err != nil {
|
|
return
|
|
} else {
|
|
conf = v.(*cfg.GamePagoda).Get(id)
|
|
if conf != nil {
|
|
return
|
|
}
|
|
}
|
|
err = comm.NewNotFoundConfErr("robot", game_buriedcondi, id)
|
|
return
|
|
}
|