72 lines
1.7 KiB
Go
72 lines
1.7 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_Item struct {
|
|
items map[string]*pb.DB_UserItemData
|
|
}
|
|
|
|
func (this *ModuleRobot_Item) Init() (err error) {
|
|
this.items = make(map[string]*pb.DB_UserItemData)
|
|
return
|
|
}
|
|
|
|
//接收到消息
|
|
func (this *ModuleRobot_Item) Receive(robot IRobot, stype string, message proto.Message) (err error) {
|
|
switch stype {
|
|
case "list":
|
|
resp := message.(*pb.ItemsGetlistResp)
|
|
for _, v := range resp.Grids {
|
|
this.items[v.GridId] = v
|
|
}
|
|
break
|
|
case "change":
|
|
resp := message.(*pb.ItemsChangePush)
|
|
for _, v := range resp.Grids {
|
|
this.items[v.GridId] = v
|
|
}
|
|
break
|
|
}
|
|
return
|
|
}
|
|
func (this *ModuleRobot_Item) OncePipeline(robot IRobot) (err error) {
|
|
var (
|
|
errdata *pb.ErrorData
|
|
)
|
|
if _, errdata = robot.SendMessage("items", "getlist", &pb.ItemsGetlistReq{}); errdata != nil {
|
|
err = errors.New(fmt.Sprintf("code:%d message:%s", errdata.Code, errdata.Message))
|
|
return
|
|
}
|
|
return
|
|
}
|
|
|
|
//机器人执行流
|
|
func (this *ModuleRobot_Item) DoPipeline(robot IRobot) (err error) {
|
|
|
|
return
|
|
}
|
|
|
|
//做任务
|
|
func (this *ModuleRobot_Item) DoTask(robot IRobot, taskconf *cfg.GameWorldTaskData, condconf *cfg.GameBuriedCondiData) (err error) {
|
|
var (
|
|
errdata *pb.ErrorData
|
|
)
|
|
switch comm.TaskType(condconf.Type) {
|
|
case comm.Rtype14:
|
|
if _, errdata = robot.SendTaskMessage(taskconf.Key, condconf.Id, "hero", "drawcard", &pb.HeroDrawCardReq{DrawType: 2, DrawCount: 1, Consume: 0}); errdata != nil {
|
|
err = errors.New(fmt.Sprintf("code:%d message:%s", errdata.Code, errdata.Message))
|
|
return
|
|
}
|
|
}
|
|
return
|
|
}
|