135 lines
3.8 KiB
Go
135 lines
3.8 KiB
Go
package robot
|
||
|
||
import (
|
||
"errors"
|
||
"fmt"
|
||
"go_dreamfactory/comm"
|
||
"go_dreamfactory/pb"
|
||
cfg "go_dreamfactory/sys/configure/structs"
|
||
|
||
"google.golang.org/protobuf/proto"
|
||
)
|
||
|
||
//维京模块 机器人
|
||
type ModuleRobot_Viking struct {
|
||
viking *pb.DBViking
|
||
}
|
||
|
||
func (this *ModuleRobot_Viking) Init() (err error) {
|
||
return
|
||
}
|
||
|
||
//接收到消息
|
||
func (this *ModuleRobot_Viking) Receive(robot IRobot, stype string, message proto.Message) (err error) {
|
||
switch stype {
|
||
case "getlist":
|
||
resp := message.(*pb.VikingGetListResp)
|
||
this.viking = resp.Data
|
||
break
|
||
case "challengeover": // 更新塔信息
|
||
resp := message.(*pb.VikingChallengeOverResp)
|
||
this.viking = resp.Data
|
||
break
|
||
}
|
||
|
||
return
|
||
}
|
||
func (this *ModuleRobot_Viking) OncePipeline(robot IRobot) (err error) {
|
||
return
|
||
}
|
||
|
||
//机器人执行流
|
||
func (this *ModuleRobot_Viking) DoPipeline(robot IRobot) (err error) {
|
||
var (
|
||
resp proto.Message
|
||
errdata *pb.ErrorData
|
||
)
|
||
// 获取爬塔信息
|
||
if resp, errdata = robot.SendMessage("viking", "getlist", &pb.VikingGetListReq{}); errdata != nil {
|
||
err = errors.New(fmt.Sprintf("code:%d message:%s", errdata.Code, errdata.Message))
|
||
return
|
||
}
|
||
this.viking = resp.(*pb.VikingGetListResp).Data
|
||
heromodule := robot.GetModule(comm.ModuleHero).(*ModuleRobot_Hero)
|
||
heros := heromodule.getbattlehero()
|
||
var bossid int32
|
||
var difficulty int32
|
||
for k, v := range this.viking.Boss {
|
||
bossid = k
|
||
difficulty = v
|
||
break
|
||
}
|
||
if bossid == 0 || difficulty == 0 {
|
||
bossid = 1
|
||
difficulty = 1
|
||
}
|
||
if resp, errdata = robot.SendMessage("viking", "challenge", &pb.VikingChallengeReq{
|
||
BossId: bossid,
|
||
Difficulty: difficulty,
|
||
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("viking", "challengeover", &pb.VikingChallengeOverReq{
|
||
BossId: bossid,
|
||
Difficulty: difficulty,
|
||
Report: &pb.BattleReport{
|
||
Info: resp.(*pb.VikingChallengeResp).Info,
|
||
WinSide: 1,
|
||
}}); errdata != nil {
|
||
err = errors.New(fmt.Sprintf("code:%d message:%s", errdata.Code, errdata.Message))
|
||
return
|
||
}
|
||
return
|
||
}
|
||
|
||
//做任务
|
||
func (this *ModuleRobot_Viking) DoTask(robot IRobot, taskconf *cfg.GameWorldTaskData, condconf *cfg.GameBuriedCondiData) (err error) {
|
||
|
||
var (
|
||
errdata *pb.ErrorData
|
||
)
|
||
// 获取爬塔信息
|
||
if _, errdata = robot.SendMessage("viking", "getlist", &pb.VikingGetListReq{}); errdata != nil {
|
||
err = errors.New(fmt.Sprintf("code:%d message:%s", errdata.Code, errdata.Message))
|
||
return
|
||
}
|
||
switch comm.TaskType(condconf.Type) {
|
||
case comm.Rtype73: //通关难度A维京远征指定BOSSN次(从接到任务开始,只有通关A难度进度才+1)
|
||
var (
|
||
heromodule *ModuleRobot_Hero
|
||
heros []string
|
||
resp proto.Message
|
||
)
|
||
// if conf, err = this.getPagodaData(condconf.Filter[0], this.viking.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, "viking", "challenge", &pb.VikingChallengeReq{
|
||
BossId: condconf.Filter[0],
|
||
Difficulty: condconf.Filter[1],
|
||
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, "viking", "challengeover", &pb.VikingChallengeOverReq{
|
||
BossId: condconf.Filter[0],
|
||
Difficulty: condconf.Filter[1],
|
||
Report: &pb.BattleReport{
|
||
Info: resp.(*pb.VikingChallengeResp).Info,
|
||
WinSide: 1,
|
||
}}); errdata != nil {
|
||
err = errors.New(fmt.Sprintf("code:%d message:%s", errdata.Code, errdata.Message))
|
||
return
|
||
}
|
||
break
|
||
}
|
||
return
|
||
}
|