Merge branch 'dev' of http://git.legu.cc/liwei_3d/go_dreamfactory into dev
This commit is contained in:
commit
f4c421f2cc
@ -25,12 +25,13 @@ type IRobot interface {
|
||||
ServerId() string
|
||||
GetModule(module core.M_Modules) IModuleRobot
|
||||
SendMessage(mtype, stype string, msg proto.Message) (resp proto.Message, errdata *pb.ErrorData)
|
||||
SendTaskMessage(task, comdi int32, mtype, stype string, msg proto.Message) (resp proto.Message, errdata *pb.ErrorData)
|
||||
DoTask(taskconf *cfg.GameWorldTaskData, condconf *cfg.GameBuriedCondiData, module core.M_Modules) (err error)
|
||||
}
|
||||
|
||||
//机器人模块
|
||||
type IModuleRobot interface {
|
||||
Init()
|
||||
Init() (err error)
|
||||
//接收到回应和推送消息
|
||||
Receive(robot IRobot, stype string, message proto.Message) (err error)
|
||||
//执行流水线任务
|
||||
|
@ -15,8 +15,9 @@ type ModuleRobot_Hero struct {
|
||||
heros map[string]*pb.DBHero
|
||||
}
|
||||
|
||||
func (this *ModuleRobot_Hero) Init() {
|
||||
func (this *ModuleRobot_Hero) Init() (err error) {
|
||||
this.heros = make(map[string]*pb.DBHero)
|
||||
return
|
||||
}
|
||||
|
||||
//接收到消息
|
||||
@ -57,7 +58,7 @@ func (this *ModuleRobot_Hero) DoTask(robot IRobot, taskconf *cfg.GameWorldTaskDa
|
||||
)
|
||||
switch comm.TaskType(condconf.Type) {
|
||||
case comm.Rtype14:
|
||||
if _, errdata = robot.SendMessage("hero", "drawcard", &pb.HeroDrawCardReq{DrawType: 2, DrawCount: 1, Consume: 0}); errdata != nil {
|
||||
if _, errdata = robot.SendTaskMessage(taskconf.Key, condconf.Id, "hero", "drawcard", &pb.HeroDrawCardReq{DrawType: 2, DrawCount: 1, Consume: 0}); errdata != nil {
|
||||
err = errors.New(errdata.Message)
|
||||
return
|
||||
}
|
||||
@ -88,3 +89,13 @@ func (this *ModuleRobot_Hero) getbattlehero() (bheros []string) {
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
//获取武官训练英雄英雄
|
||||
func (this *ModuleRobot_Hero) getpracticehero() (bheros string) {
|
||||
for _, v := range this.heros {
|
||||
if v.Status != pb.HeroType_HeroTypeKongFu {
|
||||
return v.Id
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package robot
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"go_dreamfactory/comm"
|
||||
"go_dreamfactory/pb"
|
||||
"go_dreamfactory/sys/configure"
|
||||
@ -12,11 +13,26 @@ import (
|
||||
|
||||
//用户模块 机器人
|
||||
type ModuleRobot_MainLine struct {
|
||||
info *pb.DBMainline
|
||||
info *pb.DBMainline
|
||||
group map[int32][]*cfg.GameMainStageData
|
||||
}
|
||||
|
||||
func (this *ModuleRobot_MainLine) Init() {
|
||||
|
||||
func (this *ModuleRobot_MainLine) Init() (err error) {
|
||||
var (
|
||||
confs []*cfg.GameMainStageData
|
||||
ok bool
|
||||
)
|
||||
this.group = make(map[int32][]*cfg.GameMainStageData)
|
||||
if confs, err = this.getGameMainStageDatas(); err != nil {
|
||||
return
|
||||
}
|
||||
for _, v := range confs {
|
||||
if _, ok = this.group[v.GroupId]; !ok {
|
||||
this.group[v.GroupId] = make([]*cfg.GameMainStageData, 0)
|
||||
}
|
||||
this.group[v.GroupId] = append(this.group[v.GroupId], v)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
//接收到消息
|
||||
@ -43,28 +59,116 @@ func (this *ModuleRobot_MainLine) DoPipeline(robot IRobot) (err error) {
|
||||
func (this *ModuleRobot_MainLine) DoTask(robot IRobot, taskconf *cfg.GameWorldTaskData, condconf *cfg.GameBuriedCondiData) (err error) {
|
||||
var (
|
||||
errdata *pb.ErrorData
|
||||
conf *cfg.GameMainStageData
|
||||
ok bool
|
||||
)
|
||||
if _, errdata = robot.SendMessage("mainline", "info", &pb.MainlineInfoReq{}); errdata != nil {
|
||||
err = errors.New(errdata.Message)
|
||||
return
|
||||
}
|
||||
|
||||
switch comm.TaskType(condconf.Type) {
|
||||
case comm.Rtype61:
|
||||
if _, ok = this.info.Level[condconf.Filter[0]]; ok { //已通关
|
||||
return
|
||||
}
|
||||
if conf, err = this.getGameMainStageData(condconf.Filter[0]); err != nil {
|
||||
return
|
||||
}
|
||||
if conf, err = this.findlevel(conf); err != nil { //找到目标管卡
|
||||
return
|
||||
}
|
||||
|
||||
switch conf.Episodetype {
|
||||
case 1, 4, 8:
|
||||
var (
|
||||
heromodule *ModuleRobot_Hero
|
||||
heros []string
|
||||
resp proto.Message
|
||||
)
|
||||
heromodule = robot.GetModule(comm.ModuleHero).(*ModuleRobot_Hero)
|
||||
heros = heromodule.getbattlehero()
|
||||
if resp, errdata = robot.SendTaskMessage(taskconf.Key, condconf.Id, "mainline", "challenge", &pb.MainlineChallengeReq{Level: conf.Id, Battle: &pb.BattleFormation{
|
||||
Format: heros,
|
||||
}}); errdata != nil {
|
||||
err = errors.New(errdata.Message)
|
||||
return
|
||||
}
|
||||
if _, errdata = robot.SendTaskMessage(taskconf.Key, condconf.Id, "mainline", "challengeover", &pb.MainlineChallengeOverReq{Level: conf.Id, Report: &pb.BattleReport{
|
||||
Info: resp.(*pb.MainlineChallengeResp).Info,
|
||||
WinSide: 1,
|
||||
}}); errdata != nil {
|
||||
err = errors.New(errdata.Message)
|
||||
return
|
||||
}
|
||||
break
|
||||
case 3, 7:
|
||||
if _, errdata = robot.SendTaskMessage(taskconf.Key, condconf.Id, "mainline", "levelpass", &pb.MainlineLevelPassReq{Level: conf.Id}); errdata != nil {
|
||||
err = errors.New(errdata.Message)
|
||||
return
|
||||
}
|
||||
}
|
||||
default:
|
||||
err = fmt.Errorf("no fund mainline id:%d type:%d", conf.Id, conf.Episodetype)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (this *ModuleRobot_MainLine) findlevel(conf *cfg.GameMainStageData) (rconf *cfg.GameMainStageData, err error) {
|
||||
var (
|
||||
confs []*cfg.GameMainStageData
|
||||
nconf *cfg.GameMainStageData
|
||||
ok bool
|
||||
)
|
||||
|
||||
//前置组判断
|
||||
for _, v := range conf.PreviousGroupId {
|
||||
confs = this.group[v]
|
||||
for _, nconf := range confs {
|
||||
if _, ok = this.info.Level[nconf.Id]; !ok {
|
||||
return this.findlevel(nconf)
|
||||
}
|
||||
}
|
||||
}
|
||||
if conf.Previoustage != 0 {
|
||||
if _, ok = this.info.Level[conf.Previoustage]; !ok {
|
||||
if nconf, err = this.getGameMainStageData(conf.Previoustage); err != nil {
|
||||
return
|
||||
}
|
||||
return this.findlevel(nconf)
|
||||
}
|
||||
}
|
||||
//没找到前置了,直接放回
|
||||
rconf = conf
|
||||
return
|
||||
}
|
||||
|
||||
// 读取主线关卡表
|
||||
func (this *ModuleRobot_MainLine) getGameMainStageData(cid int32) (conf []*cfg.GameMainStageData, err error) {
|
||||
func (this *ModuleRobot_MainLine) getGameMainStageData(id int32) (conf *cfg.GameMainStageData, err error) {
|
||||
var (
|
||||
v interface{}
|
||||
ok bool
|
||||
)
|
||||
if v, err = configure.GetConfigure(game_mainstage); err != nil {
|
||||
return
|
||||
} else {
|
||||
if conf, ok = v.(*cfg.GameMainStage).GetDataMap()[id]; !ok {
|
||||
err = comm.NewNotFoundConfErr("robot", game_mainstage, id)
|
||||
return
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// 读取主线关卡表
|
||||
func (this *ModuleRobot_MainLine) getGameMainStageDatas() (confs []*cfg.GameMainStageData, err error) {
|
||||
var (
|
||||
v interface{}
|
||||
)
|
||||
if v, err = configure.GetConfigure(game_mainstage); err != nil {
|
||||
return
|
||||
} else {
|
||||
conf = v.(*cfg.GameMainStage).GetDataList()
|
||||
confs = v.(*cfg.GameMainStage).GetDataList()
|
||||
}
|
||||
return
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package robot
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"go_dreamfactory/comm"
|
||||
"go_dreamfactory/pb"
|
||||
cfg "go_dreamfactory/sys/configure/structs"
|
||||
@ -14,8 +15,8 @@ type ModuleRobot_Practice struct {
|
||||
Info *pb.DBPracticeRoom
|
||||
}
|
||||
|
||||
func (this *ModuleRobot_Practice) Init() {
|
||||
|
||||
func (this *ModuleRobot_Practice) Init() (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
//接收到消息
|
||||
@ -25,20 +26,13 @@ func (this *ModuleRobot_Practice) Receive(robot IRobot, stype string, message pr
|
||||
resp := message.(*pb.PracticeInfoResp)
|
||||
this.Info = resp.Info
|
||||
break
|
||||
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
//机器人执行流
|
||||
func (this *ModuleRobot_Practice) DoPipeline(robot IRobot) (err error) {
|
||||
var (
|
||||
errdata *pb.ErrorData
|
||||
)
|
||||
if _, errdata = robot.SendMessage("hero", "list", &pb.HeroListReq{}); errdata != nil {
|
||||
err = errors.New(errdata.Message)
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@ -53,11 +47,77 @@ func (this *ModuleRobot_Practice) DoTask(robot IRobot, taskconf *cfg.GameWorldTa
|
||||
}
|
||||
switch comm.TaskType(condconf.Type) {
|
||||
case comm.Rtype149:
|
||||
|
||||
if _, errdata = robot.SendMessage("practice", "practice", &pb.PracticePracticeReq{}); errdata != nil {
|
||||
err = errors.New(errdata.Message)
|
||||
return
|
||||
for i := 1; i < 4; i++ {
|
||||
if err = this.practice(taskconf.Key, condconf.Id, robot, int32(i)); err == nil {
|
||||
break
|
||||
}
|
||||
}
|
||||
case comm.Rtype152:
|
||||
for i := 1; i <= int(condconf.Value); i++ {
|
||||
if err = this.unlock(taskconf.Key, condconf.Id, robot, int32(i)); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
//练功
|
||||
func (this *ModuleRobot_Practice) unlock(tid, cid int32, robot IRobot, index int32) (err error) {
|
||||
var (
|
||||
sysmodule *ModuleRobot_Sys
|
||||
)
|
||||
sysmodule = robot.GetModule(comm.ModuleSys).(*ModuleRobot_Sys)
|
||||
switch index {
|
||||
case 1:
|
||||
err = sysmodule.funcactivate(tid, cid, robot, "practice_ pillar1")
|
||||
break
|
||||
case 2:
|
||||
err = sysmodule.funcactivate(tid, cid, robot, "practice_ pillar2")
|
||||
break
|
||||
case 3:
|
||||
err = sysmodule.funcactivate(tid, cid, robot, "practice_ pillar3")
|
||||
break
|
||||
default:
|
||||
err = fmt.Errorf("no found pillar:%d", index)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
//练功
|
||||
func (this *ModuleRobot_Practice) practice(tid, cid int32, robot IRobot, index int32) (err error) {
|
||||
var (
|
||||
errdata *pb.ErrorData
|
||||
sysmodule *ModuleRobot_Sys
|
||||
heromodule *ModuleRobot_Hero
|
||||
hero string
|
||||
)
|
||||
sysmodule = robot.GetModule(comm.ModuleSys).(*ModuleRobot_Sys)
|
||||
switch index {
|
||||
case 1:
|
||||
err = sysmodule.funcactivate(tid, cid, robot, "practice_ pillar1")
|
||||
break
|
||||
case 2:
|
||||
err = sysmodule.funcactivate(tid, cid, robot, "practice_ pillar2")
|
||||
break
|
||||
case 3:
|
||||
err = sysmodule.funcactivate(tid, cid, robot, "practice_ pillar3")
|
||||
break
|
||||
default:
|
||||
err = fmt.Errorf("no found pillar:%d", index)
|
||||
}
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
heromodule = robot.GetModule(comm.ModuleHero).(*ModuleRobot_Hero)
|
||||
hero = heromodule.getpracticehero()
|
||||
if hero == "" {
|
||||
err = fmt.Errorf("no found can practice hero")
|
||||
return
|
||||
}
|
||||
if _, errdata = robot.SendTaskMessage(tid, cid, "practice", "practice", &pb.PracticePracticeReq{Index: index, Hero: hero}); errdata != nil {
|
||||
err = errors.New(errdata.Message)
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
75
modules/robot/modulerobot_sys.go
Normal file
75
modules/robot/modulerobot_sys.go
Normal file
@ -0,0 +1,75 @@
|
||||
package robot
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"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
|
||||
}
|
||||
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(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(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 {
|
||||
err = errors.New(errdata.Message)
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
@ -14,8 +14,8 @@ type ModuleRobot_User struct {
|
||||
userex *pb.DBUserExpand
|
||||
}
|
||||
|
||||
func (this *ModuleRobot_User) Init() {
|
||||
|
||||
func (this *ModuleRobot_User) Init() (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
//接收到消息
|
||||
|
@ -21,8 +21,9 @@ type ModuleRobot_WTask struct {
|
||||
change chan bool
|
||||
}
|
||||
|
||||
func (this *ModuleRobot_WTask) Init() {
|
||||
func (this *ModuleRobot_WTask) Init() (err error) {
|
||||
this.change = make(chan bool)
|
||||
return
|
||||
}
|
||||
|
||||
//接收到消息
|
||||
@ -124,6 +125,10 @@ locp:
|
||||
module = comm.ModuleHero
|
||||
case comm.Rtype20001, comm.Rtype70, comm.Rtype227:
|
||||
module = comm.ModuleWtask
|
||||
case comm.Rtype149, comm.Rtype152:
|
||||
module = comm.ModulePractice
|
||||
case comm.Rtype61:
|
||||
module = comm.ModuleMainline
|
||||
default:
|
||||
log.Error("[Robot DoTask]", log.Field{Key: "ctype", Value: cconf.Type}, log.Field{Key: "conld", Value: cconf.Id}, log.Field{Key: "err", Value: "Not Achieved !"})
|
||||
break locp
|
||||
@ -133,7 +138,7 @@ locp:
|
||||
log.Error("[Robot DoTask]", log.Field{Key: "task", Value: tconf.Key}, log.Field{Key: "conld", Value: cconf.Id}, log.Field{Key: "err", Value: err.Error()})
|
||||
break locp
|
||||
}
|
||||
time.Sleep(time.Second)
|
||||
time.Sleep(time.Second * 2)
|
||||
continue
|
||||
} else { //任务已完成直接完成
|
||||
if _, errdata = robot.SendMessage("wtask", "finish", &pb.WTaskFinishReq{Tid: tconf.Key}); errdata != nil {
|
||||
@ -152,7 +157,7 @@ func (this *ModuleRobot_WTask) DoTask(robot IRobot, taskconf *cfg.GameWorldTaskD
|
||||
)
|
||||
switch comm.TaskType(condconf.Type) {
|
||||
case comm.Rtype20001: //完成对话
|
||||
if _, errdata = robot.SendMessage("wtask", "completecondi", &pb.WTaskCompleteCondiReq{TaskId: taskconf.Key, CondiId: condconf.Id}); errdata != nil {
|
||||
if _, errdata = robot.SendTaskMessage(taskconf.Key, condconf.Id, "wtask", "completecondi", &pb.WTaskCompleteCondiReq{TaskId: taskconf.Key, CondiId: condconf.Id}); errdata != nil {
|
||||
err = errors.New(errdata.Message)
|
||||
return
|
||||
}
|
||||
@ -165,11 +170,11 @@ func (this *ModuleRobot_WTask) DoTask(robot IRobot, taskconf *cfg.GameWorldTaskD
|
||||
)
|
||||
heromodule = robot.GetModule(comm.ModuleHero).(*ModuleRobot_Hero)
|
||||
heros = heromodule.getbattlehero()
|
||||
if resp, errdata = robot.SendMessage("wtask", "battlestart", &pb.WTaskBattleStartReq{BattleConfId: condconf.Filter[0], Battle: &pb.BattleFormation{Format: heros}}); errdata != nil {
|
||||
if resp, errdata = robot.SendTaskMessage(taskconf.Key, condconf.Id, "wtask", "battlestart", &pb.WTaskBattleStartReq{BattleConfId: condconf.Filter[0], Battle: &pb.BattleFormation{Format: heros}}); errdata != nil {
|
||||
err = errors.New(errdata.Message)
|
||||
return
|
||||
}
|
||||
if _, errdata = robot.SendMessage("wtask", "battlefinish", &pb.WTaskBattleFinishReq{BattleConfId: condconf.Filter[0], Report: &pb.BattleReport{
|
||||
if _, errdata = robot.SendTaskMessage(taskconf.Key, condconf.Id, "wtask", "battlefinish", &pb.WTaskBattleFinishReq{BattleConfId: condconf.Filter[0], Report: &pb.BattleReport{
|
||||
Info: resp.(*pb.WTaskBattleStartResp).Info,
|
||||
WinSide: 1,
|
||||
}}); errdata != nil {
|
||||
@ -185,11 +190,11 @@ func (this *ModuleRobot_WTask) DoTask(robot IRobot, taskconf *cfg.GameWorldTaskD
|
||||
)
|
||||
heromodule = robot.GetModule(comm.ModuleHero).(*ModuleRobot_Hero)
|
||||
heros = heromodule.getbattlehero()
|
||||
if resp, errdata = robot.SendMessage("wtask", "battlestart", &pb.WTaskBattleStartReq{BattleConfId: condconf.Filter[0], Battle: &pb.BattleFormation{Format: heros}}); errdata != nil {
|
||||
if resp, errdata = robot.SendTaskMessage(taskconf.Key, condconf.Id, "wtask", "battlestart", &pb.WTaskBattleStartReq{BattleConfId: condconf.Filter[0], Battle: &pb.BattleFormation{Format: heros}}); errdata != nil {
|
||||
err = errors.New(errdata.Message)
|
||||
return
|
||||
}
|
||||
if _, errdata = robot.SendMessage("wtask", "battlefinish", &pb.WTaskBattleFinishReq{BattleConfId: condconf.Filter[0], Report: &pb.BattleReport{
|
||||
if _, errdata = robot.SendTaskMessage(taskconf.Key, condconf.Id, "wtask", "battlefinish", &pb.WTaskBattleFinishReq{BattleConfId: condconf.Filter[0], Report: &pb.BattleReport{
|
||||
Info: resp.(*pb.WTaskBattleStartResp).Info,
|
||||
WinSide: 2,
|
||||
}}); errdata != nil {
|
||||
|
@ -44,8 +44,11 @@ func (this *Robot) Init(addr string, client IClient) (err error) {
|
||||
this.await = make(chan *MessageResp)
|
||||
this.modules = make(map[core.M_Modules]IModuleRobot)
|
||||
this.modules[comm.ModuleUser] = new(ModuleRobot_User)
|
||||
this.modules[comm.ModuleSys] = new(ModuleRobot_Sys)
|
||||
this.modules[comm.ModuleHero] = new(ModuleRobot_Hero)
|
||||
this.modules[comm.ModuleWtask] = new(ModuleRobot_WTask)
|
||||
this.modules[comm.ModulePractice] = new(ModuleRobot_Practice)
|
||||
this.modules[comm.ModuleMainline] = new(ModuleRobot_MainLine)
|
||||
for _, v := range this.modules {
|
||||
v.Init()
|
||||
}
|
||||
@ -75,12 +78,6 @@ func (this *Robot) Receive(msg *pb.UserMessage) (err error) {
|
||||
if msgpath == "notify.errornotify" { //错误通知
|
||||
resp := message.(*pb.NotifyErrorNotifyPush)
|
||||
reqpath := fmt.Sprintf("%s.%s", resp.ReqMainType, resp.ReqSubType)
|
||||
// if module, ok = this.modules[core.M_Modules(resp.ReqMainType)]; ok {
|
||||
// if err = module.ErrReceive(this, resp.ReqSubType, resp.Code); err != nil {
|
||||
// log.Error("[Robot NotifyErrorNotifyPush]", log.Field{Key: "Account", Value: this.account}, log.Field{Key: "message", Value: reqpath}, log.Field{Key: "err", Value: err.Error()})
|
||||
// return
|
||||
// }
|
||||
// }
|
||||
if reqpath == this.curreq { //收到回应
|
||||
this.await <- &MessageResp{
|
||||
resp: nil,
|
||||
@ -112,6 +109,37 @@ func (this *Robot) WriteMsg(msg *pb.UserMessage) (err error) {
|
||||
|
||||
//发送消息
|
||||
func (this *Robot) SendMessage(mtype, stype string, msg proto.Message) (resp proto.Message, errdata *pb.ErrorData) {
|
||||
var (
|
||||
messageresp *MessageResp
|
||||
err error
|
||||
)
|
||||
// stime := time.Now()
|
||||
data, _ := anypb.New(msg)
|
||||
message := &pb.UserMessage{
|
||||
MainType: mtype,
|
||||
SubType: stype,
|
||||
Data: data,
|
||||
}
|
||||
if err = this.WriteMsg(message); err != nil {
|
||||
errdata = &pb.ErrorData{
|
||||
Code: pb.ErrorCode_ClientError,
|
||||
Title: pb.ErrorCode_ClientError.String(),
|
||||
Message: err.Error(),
|
||||
}
|
||||
return
|
||||
}
|
||||
if mtype != "gateway" {
|
||||
this.curreq = fmt.Sprintf("%s.%s", mtype, stype)
|
||||
messageresp = <-this.await //等待回应
|
||||
resp = messageresp.resp
|
||||
errdata = messageresp.errdata
|
||||
// log.Debug("[机器人 Message]", log.Field{Key: "t", Value: time.Since(stime).Milliseconds()}, log.Field{Key: "Account", Value: this.account}, log.Field{Key: "message", Value: fmt.Sprintf("%s.%s", mtype, stype)}, log.Field{Key: "resp", Value: errdata == nil})
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
//发送消息
|
||||
func (this *Robot) SendTaskMessage(task, comdi int32, mtype, stype string, msg proto.Message) (resp proto.Message, errdata *pb.ErrorData) {
|
||||
var (
|
||||
messageresp *MessageResp
|
||||
err error
|
||||
@ -136,7 +164,7 @@ func (this *Robot) SendMessage(mtype, stype string, msg proto.Message) (resp pro
|
||||
messageresp = <-this.await //等待回应
|
||||
resp = messageresp.resp
|
||||
errdata = messageresp.errdata
|
||||
log.Debug("[机器人 Message]", log.Field{Key: "t", Value: time.Since(stime).Milliseconds()}, log.Field{Key: "Account", Value: this.account}, log.Field{Key: "message", Value: fmt.Sprintf("%s.%s", mtype, stype)}, log.Field{Key: "resp", Value: errdata == nil})
|
||||
log.Debug("[机器人 Message]", log.Field{Key: "t", Value: time.Since(stime).Milliseconds()}, log.Field{Key: "Account", Value: this.account}, log.Field{Key: "Task", Value: fmt.Sprintf("[%d-%d]", task, comdi)}, log.Field{Key: "message", Value: fmt.Sprintf("%s.%s", mtype, stype)}, log.Field{Key: "resp", Value: errdata == nil})
|
||||
}
|
||||
return
|
||||
}
|
||||
|
@ -29,6 +29,10 @@ func NewModule() core.IModule {
|
||||
return &ModuleSys{}
|
||||
}
|
||||
|
||||
func (this *ModuleSys) GetType() core.M_Modules {
|
||||
return comm.ModuleSys
|
||||
}
|
||||
|
||||
func (this *ModuleSys) OnInstallComp() {
|
||||
this.ModuleBase.OnInstallComp()
|
||||
this.api = this.RegisterComp(new(apiComp)).(*apiComp)
|
||||
@ -72,10 +76,6 @@ func (this *ModuleSys) Start() (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func (this *ModuleSys) GetType() core.M_Modules {
|
||||
return comm.ModuleSys
|
||||
}
|
||||
|
||||
func (this *ModuleSys) ValidCond(uid string, conf *cfg.GameOpencondData) string {
|
||||
return this.modelSys.validCond(uid, conf)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user