100 lines
2.3 KiB
Go
100 lines
2.3 KiB
Go
package robot
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"go_dreamfactory/pb"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
|
|
"google.golang.org/protobuf/proto"
|
|
)
|
|
|
|
//商队模块 机器人
|
|
type ModuleRobot_Caravan struct {
|
|
caravan *pb.DBCaravan
|
|
curCity int32
|
|
}
|
|
|
|
func (this *ModuleRobot_Caravan) Init() (err error) {
|
|
this.caravan = &pb.DBCaravan{}
|
|
this.curCity = 102
|
|
return
|
|
}
|
|
|
|
//接收到消息
|
|
func (this *ModuleRobot_Caravan) Receive(robot IRobot, stype string, message proto.Message) (err error) {
|
|
switch stype {
|
|
case "getlist":
|
|
resp := message.(*pb.CaravanGetListResp)
|
|
this.caravan = resp.Data
|
|
break
|
|
}
|
|
return
|
|
}
|
|
func (this *ModuleRobot_Caravan) OncePipeline(robot IRobot) (err error) {
|
|
var (
|
|
errdata *pb.ErrorData
|
|
)
|
|
if _, errdata = robot.SendMessage("caravan", "getlist", &pb.CaravanGetListReq{}); errdata != nil {
|
|
err = errors.New(fmt.Sprintf("code:%d message:%s", errdata.Code, errdata.Message))
|
|
return
|
|
}
|
|
return
|
|
}
|
|
|
|
//机器人执行流
|
|
func (this *ModuleRobot_Caravan) DoPipeline(robot IRobot) (err error) {
|
|
var (
|
|
resp proto.Message
|
|
errdata *pb.ErrorData
|
|
)
|
|
this.curCity += 1
|
|
if this.curCity >= 113 {
|
|
this.curCity = 102
|
|
}
|
|
if resp, errdata = robot.SendMessage("caravan", "gotocity", &pb.CaravanGotoCityReq{
|
|
City: this.curCity,
|
|
Ticket: 1,
|
|
}); errdata != nil {
|
|
err = errors.New(fmt.Sprintf("code:%d message:%s", errdata.Code, errdata.Message))
|
|
return
|
|
}
|
|
|
|
if resp.(*pb.CaravanGotoCityResp).Eventid != 0 {
|
|
if resp, errdata = robot.SendMessage("caravan", "getstory", &pb.CaravanGetStoryReq{
|
|
Cid: 1,
|
|
Citystory: 50020020, // 拒绝剧情
|
|
}); errdata != nil {
|
|
err = errors.New(fmt.Sprintf("code:%d message:%s", errdata.Code, errdata.Message))
|
|
return
|
|
}
|
|
}
|
|
//CaravanBuyOrSellReq
|
|
if this.caravan == nil {
|
|
return
|
|
}
|
|
var item string
|
|
for _, v := range this.caravan.City[this.curCity].Special {
|
|
item = v
|
|
break
|
|
}
|
|
if resp, errdata = robot.SendMessage("caravan", "buyorsell", &pb.CaravanBuyOrSellReq{
|
|
City: this.curCity,
|
|
Items: map[string]int32{
|
|
item: 2,
|
|
},
|
|
IsBuy: true,
|
|
}); errdata != nil {
|
|
err = errors.New(fmt.Sprintf("code:%d message:%s", errdata.Code, errdata.Message))
|
|
return
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
//做任务
|
|
func (this *ModuleRobot_Caravan) DoTask(robot IRobot, taskconf *cfg.GameWorldTaskData, condconf *cfg.GameBuriedCondiData) (err error) {
|
|
|
|
return
|
|
}
|