71 lines
1.4 KiB
Go
71 lines
1.4 KiB
Go
package robot
|
|
|
|
import (
|
|
"errors"
|
|
"go_dreamfactory/pb"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
|
|
"google.golang.org/protobuf/proto"
|
|
)
|
|
|
|
//用户模块 机器人
|
|
type ModuleRobot_User struct {
|
|
user *pb.DBUser
|
|
userex *pb.DBUserExpand
|
|
}
|
|
|
|
func (this *ModuleRobot_User) Init() {
|
|
|
|
}
|
|
|
|
//接收到消息
|
|
func (this *ModuleRobot_User) Receive(robot IRobot, stype string, message proto.Message) (err error) {
|
|
switch stype {
|
|
case "login":
|
|
resp := message.(*pb.UserLoginResp)
|
|
this.user = resp.Data
|
|
this.userex = resp.Ex
|
|
break
|
|
case "create":
|
|
// resp := message.(*pb.UserCreateResp)
|
|
break
|
|
}
|
|
return
|
|
}
|
|
|
|
//机器人执行流
|
|
func (this *ModuleRobot_User) DoPipeline(robot IRobot) (err error) {
|
|
var (
|
|
errdata *pb.ErrorData
|
|
)
|
|
//登录
|
|
if _, errdata = robot.SendMessage("user", "login", &pb.UserLoginReq{
|
|
Account: robot.Account(),
|
|
Sid: robot.ServerId(),
|
|
}); errdata != nil {
|
|
err = errors.New(errdata.Message)
|
|
return
|
|
}
|
|
//创角
|
|
if _, errdata = robot.SendMessage("user", "create", &pb.UserCreateReq{
|
|
NickName: robot.Account(),
|
|
Figure: 100,
|
|
Gender: 1,
|
|
}); errdata != nil {
|
|
if errdata.Code == pb.ErrorCode_RoleCreated { //已创角
|
|
err = nil
|
|
} else {
|
|
err = errors.New(errdata.Message)
|
|
}
|
|
|
|
return
|
|
}
|
|
return
|
|
}
|
|
|
|
//做任务
|
|
func (this *ModuleRobot_User) DoTask(robot IRobot, taskconf *cfg.GameWorldTaskData, condconf *cfg.GameBuriedCondiData) (err error) {
|
|
|
|
return
|
|
}
|