go_dreamfactory/modules/robot/modulerobot_caravan.go
2023-09-14 14:36:20 +08:00

101 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
}
data := resp.(*pb.CaravanGotoCityResp).Data
if data.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 _, ok := data.City[this.curCity]; !ok {
return
}
var item string
for _, v := range data.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
}