88 lines
2.0 KiB
Go
88 lines
2.0 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_Sys struct {
|
|
cmd map[string]int32
|
|
}
|
|
|
|
func (this *ModuleRobot_Sys) Init() (err error) {
|
|
this.cmd = make(map[string]int32)
|
|
return
|
|
}
|
|
|
|
//接收到消息
|
|
func (this *ModuleRobot_Sys) Receive(robot IRobot, stype string, message proto.Message) (err error) {
|
|
switch stype {
|
|
case "funcgetlist":
|
|
resp := message.(*pb.SysFuncGetListResp)
|
|
this.cmd = resp.Cond
|
|
break
|
|
case "funcactivate":
|
|
resp := message.(*pb.SysFuncActivateResp)
|
|
this.cmd[resp.Cid] = 2
|
|
break
|
|
}
|
|
return
|
|
}
|
|
func (this *ModuleRobot_Sys) OncePipeline(robot IRobot) (err error) {
|
|
return
|
|
}
|
|
|
|
//机器人执行流
|
|
func (this *ModuleRobot_Sys) DoPipeline(robot IRobot) (err error) {
|
|
var (
|
|
errdata *pb.ErrorData
|
|
)
|
|
if _, errdata = robot.SendMessage("sys", "funcgetlist", &pb.SysFuncGetListReq{}); errdata != nil {
|
|
err = errors.New(fmt.Sprintf("code:%d message:%s", errdata.Code, errdata.Message))
|
|
return
|
|
}
|
|
return
|
|
}
|
|
|
|
//做任务
|
|
func (this *ModuleRobot_Sys) 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.SendMessage("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
|
|
}
|
|
|
|
//解锁
|
|
func (this *ModuleRobot_Sys) funcactivate(tid, sid int32, robot IRobot, cid string) (err error) {
|
|
var (
|
|
errdata *pb.ErrorData
|
|
)
|
|
|
|
if this.cmd[cid] == 2 { //已解锁
|
|
return
|
|
}
|
|
|
|
if _, errdata = robot.SendTaskMessage(tid, sid, "sys", "funcactivate", &pb.SysFuncActivateReq{Cid: cid}); errdata != nil {
|
|
if errdata.Code == pb.ErrorCode_OpenCondActivate {
|
|
this.cmd[cid] = 2
|
|
return
|
|
}
|
|
err = errors.New(fmt.Sprintf("code:%d message:%s", errdata.Code, errdata.Message))
|
|
return
|
|
}
|
|
return
|
|
}
|