94 lines
2.0 KiB
Go
94 lines
2.0 KiB
Go
package robot
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"go_dreamfactory/pb"
|
|
"go_dreamfactory/sys/configure"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
|
|
"google.golang.org/protobuf/proto"
|
|
)
|
|
|
|
//用户模块 机器人
|
|
type ModuleRobot_Horoscope struct {
|
|
Info *pb.DBHoroscope
|
|
}
|
|
|
|
func (this *ModuleRobot_Horoscope) Init() (err error) {
|
|
|
|
return
|
|
}
|
|
|
|
//接收到消息
|
|
func (this *ModuleRobot_Horoscope) Receive(robot IRobot, stype string, message proto.Message) (err error) {
|
|
switch stype {
|
|
case "info":
|
|
resp := message.(*pb.HoroscopeInfoResp)
|
|
this.Info = resp.Info
|
|
break
|
|
}
|
|
return
|
|
}
|
|
|
|
func (this *ModuleRobot_Horoscope) OncePipeline(robot IRobot) (err error) {
|
|
var (
|
|
errdata *pb.ErrorData
|
|
)
|
|
if _, errdata = robot.SendMessage("horoscope", "info", &pb.HoroscopeInfoReq{}); errdata != nil {
|
|
err = errors.New(fmt.Sprintf("code:%d message:%s", errdata.Code, errdata.Message))
|
|
return
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
//机器人执行流
|
|
func (this *ModuleRobot_Horoscope) DoPipeline(robot IRobot) (err error) {
|
|
var (
|
|
errdata *pb.ErrorData
|
|
conf *cfg.GameHoroscopeData
|
|
)
|
|
if conf, err = this.findcanupnode(); err != nil {
|
|
return
|
|
}
|
|
if _, errdata = robot.SendMessage("horoscope", "upgrade", &pb.HoroscopeUpgradeReq{Nid: conf.Id}); errdata != nil {
|
|
err = errors.New(fmt.Sprintf("code:%d message:%s", errdata.Code, errdata.Message))
|
|
return
|
|
}
|
|
return
|
|
}
|
|
|
|
//做任务
|
|
func (this *ModuleRobot_Horoscope) DoTask(robot IRobot, taskconf *cfg.GameWorldTaskData, condconf *cfg.GameBuriedCondiData) (err error) {
|
|
|
|
return
|
|
}
|
|
|
|
func (this *ModuleRobot_Horoscope) findcanupnode() (conf *cfg.GameHoroscopeData, err error) {
|
|
var (
|
|
v interface{}
|
|
ok bool
|
|
)
|
|
if v, err = configure.GetConfigure(game_horoscope); err != nil {
|
|
return
|
|
} else {
|
|
for _, v := range v.(*cfg.GameHoroscope).GetDataList() {
|
|
ok = true
|
|
for _, v := range v.Front {
|
|
if v != 0 {
|
|
if _, ok = this.Info.Nodes[v]; !ok {
|
|
break
|
|
}
|
|
}
|
|
}
|
|
if ok {
|
|
conf = v
|
|
return
|
|
}
|
|
}
|
|
err = fmt.Errorf("no fund")
|
|
return
|
|
}
|
|
}
|