上传压测工具
This commit is contained in:
parent
605ad803b5
commit
362b421ce6
@ -717,7 +717,7 @@ const (
|
|||||||
Rtype67 TaskType = 67 //商店购物消耗xx货币xx个
|
Rtype67 TaskType = 67 //商店购物消耗xx货币xx个
|
||||||
Rtype68 TaskType = 68 //任意渠道消耗xx金币
|
Rtype68 TaskType = 68 //任意渠道消耗xx金币
|
||||||
Rtype69 TaskType = 69 //与其他玩家切磋xx次
|
Rtype69 TaskType = 69 //与其他玩家切磋xx次
|
||||||
Rtype70 TaskType = 70 //通关世界任务XX关卡
|
Rtype70 TaskType = 70 //完成世界任务战斗
|
||||||
Rtype72 TaskType = 72 //完成一次捏人
|
Rtype72 TaskType = 72 //完成一次捏人
|
||||||
Rtype73 TaskType = 73 //通关难度A维京远征指定BOSSN次(从接到任务开始,只有通关A难度进度才+1)
|
Rtype73 TaskType = 73 //通关难度A维京远征指定BOSSN次(从接到任务开始,只有通关A难度进度才+1)
|
||||||
//Rtype74 TaskType = 74 //通关难度A维京远征指定BOSS(检查最高难度记录是否超过了此难度,超过则完成)
|
//Rtype74 TaskType = 74 //通关难度A维京远征指定BOSS(检查最高难度记录是否超过了此难度,超过则完成)
|
||||||
|
@ -8,7 +8,6 @@ import (
|
|||||||
|
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
"google.golang.org/protobuf/proto"
|
"google.golang.org/protobuf/proto"
|
||||||
"google.golang.org/protobuf/types/known/anypb"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Client struct {
|
type Client struct {
|
||||||
@ -118,17 +117,6 @@ func (this *Client) Receive(msg *pb.UserMessage) (err error) {
|
|||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
func (this *Client) SendMessage(mtype, stype string, msg proto.Message) (err error) {
|
|
||||||
data, _ := anypb.New(msg)
|
|
||||||
message := &pb.UserMessage{
|
|
||||||
MainType: mtype,
|
|
||||||
SubType: stype,
|
|
||||||
Data: data,
|
|
||||||
}
|
|
||||||
|
|
||||||
err = this.WriteMsg(message)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *Client) Heartbeat() {
|
func (this *Client) Heartbeat() {
|
||||||
|
|
||||||
|
@ -13,6 +13,7 @@ const (
|
|||||||
gameWorldTask = "game_worldtask.json"
|
gameWorldTask = "game_worldtask.json"
|
||||||
gameWorldtaskBattle = "game_worldbattle.json"
|
gameWorldtaskBattle = "game_worldbattle.json"
|
||||||
game_buriedcondi = "game_buriedcondi.json"
|
game_buriedcondi = "game_buriedcondi.json"
|
||||||
|
game_mainstage = "game_mainstage.json" //主线表
|
||||||
// gameWorldAll = "game_worldall.json"
|
// gameWorldAll = "game_worldall.json"
|
||||||
// gameburiedCond = "game_buriedcondi.json"
|
// gameburiedCond = "game_buriedcondi.json"
|
||||||
// gamerdtasknpc = "game_rdtasknpc.json"
|
// gamerdtasknpc = "game_rdtasknpc.json"
|
||||||
@ -33,6 +34,8 @@ func (this *configureComp) Init(service core.IService, module core.IModule, comp
|
|||||||
configure.RegisterConfigure(gameWorldTask, cfg.NewGameWorldTask, nil)
|
configure.RegisterConfigure(gameWorldTask, cfg.NewGameWorldTask, nil)
|
||||||
configure.RegisterConfigure(gameWorldtaskBattle, cfg.NewGameWorldBattle, nil)
|
configure.RegisterConfigure(gameWorldtaskBattle, cfg.NewGameWorldBattle, nil)
|
||||||
configure.RegisterConfigure(game_buriedcondi, cfg.NewGameBuriedCondi, nil)
|
configure.RegisterConfigure(game_buriedcondi, cfg.NewGameBuriedCondi, nil)
|
||||||
|
configure.RegisterConfigure(game_mainstage, cfg.NewGameMainStage, nil)
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,7 +14,6 @@ type IClient interface {
|
|||||||
Heartbeat()
|
Heartbeat()
|
||||||
Receive(msg *pb.UserMessage) (err error)
|
Receive(msg *pb.UserMessage) (err error)
|
||||||
WriteMsg(msg *pb.UserMessage) (err error)
|
WriteMsg(msg *pb.UserMessage) (err error)
|
||||||
SendMessage(mtype, stype string, msg proto.Message) (err error)
|
|
||||||
Close()
|
Close()
|
||||||
OnClose()
|
OnClose()
|
||||||
}
|
}
|
||||||
@ -24,17 +23,16 @@ type IRobot interface {
|
|||||||
IClient
|
IClient
|
||||||
Account() string
|
Account() string
|
||||||
ServerId() string
|
ServerId() string
|
||||||
SetData(key string, data interface{})
|
GetModule(module core.M_Modules) IModuleRobot
|
||||||
GetData(key string) interface{}
|
SendMessage(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)
|
DoTask(taskconf *cfg.GameWorldTaskData, condconf *cfg.GameBuriedCondiData, module core.M_Modules) (err error)
|
||||||
}
|
}
|
||||||
|
|
||||||
//机器人模块
|
//机器人模块
|
||||||
type IModuleRobot interface {
|
type IModuleRobot interface {
|
||||||
|
Init()
|
||||||
//接收到回应和推送消息
|
//接收到回应和推送消息
|
||||||
Receive(robot IRobot, stype string, message proto.Message) (err error)
|
Receive(robot IRobot, stype string, message proto.Message) (err error)
|
||||||
//错误码接收
|
|
||||||
ErrReceive(robot IRobot, stype string, code pb.ErrorCode) (err error)
|
|
||||||
//执行流水线任务
|
//执行流水线任务
|
||||||
DoPipeline(robot IRobot) (err error)
|
DoPipeline(robot IRobot) (err error)
|
||||||
//执行任务
|
//执行任务
|
||||||
@ -46,3 +44,8 @@ type SecBuild struct {
|
|||||||
ServerId string `json:"serverId"`
|
ServerId string `json:"serverId"`
|
||||||
TimeStamp int64 `json:"timestamp"`
|
TimeStamp int64 `json:"timestamp"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type MessageResp struct {
|
||||||
|
resp proto.Message
|
||||||
|
errdata *pb.ErrorData
|
||||||
|
}
|
||||||
|
90
modules/robot/modulerobot_hero.go
Normal file
90
modules/robot/modulerobot_hero.go
Normal file
@ -0,0 +1,90 @@
|
|||||||
|
package robot
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"go_dreamfactory/comm"
|
||||||
|
"go_dreamfactory/pb"
|
||||||
|
cfg "go_dreamfactory/sys/configure/structs"
|
||||||
|
"sort"
|
||||||
|
|
||||||
|
"google.golang.org/protobuf/proto"
|
||||||
|
)
|
||||||
|
|
||||||
|
//用户模块 机器人
|
||||||
|
type ModuleRobot_Hero struct {
|
||||||
|
heros map[string]*pb.DBHero
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *ModuleRobot_Hero) Init() {
|
||||||
|
this.heros = make(map[string]*pb.DBHero)
|
||||||
|
}
|
||||||
|
|
||||||
|
//接收到消息
|
||||||
|
func (this *ModuleRobot_Hero) Receive(robot IRobot, stype string, message proto.Message) (err error) {
|
||||||
|
switch stype {
|
||||||
|
case "list":
|
||||||
|
resp := message.(*pb.HeroListResp)
|
||||||
|
for _, v := range resp.List {
|
||||||
|
this.heros[v.Id] = v
|
||||||
|
}
|
||||||
|
break
|
||||||
|
case "change":
|
||||||
|
resp := message.(*pb.HeroChangePush)
|
||||||
|
for _, v := range resp.List {
|
||||||
|
this.heros[v.Id] = v
|
||||||
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
//机器人执行流
|
||||||
|
func (this *ModuleRobot_Hero) 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
|
||||||
|
}
|
||||||
|
|
||||||
|
//做任务
|
||||||
|
func (this *ModuleRobot_Hero) 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_Hero) getbattlehero() (bheros []string) {
|
||||||
|
var (
|
||||||
|
heros []*pb.DBHero = make([]*pb.DBHero, 0, len(this.heros))
|
||||||
|
)
|
||||||
|
bheros = make([]string, 5)
|
||||||
|
for _, v := range this.heros {
|
||||||
|
heros = append(heros, v)
|
||||||
|
}
|
||||||
|
// 使用sort.Slice进行排序
|
||||||
|
sort.Slice(heros, func(i, j int) bool {
|
||||||
|
return heros[i].Lv > heros[j].Lv
|
||||||
|
})
|
||||||
|
|
||||||
|
for i, v := range heros {
|
||||||
|
if i < 5 {
|
||||||
|
bheros[i] = v.Id
|
||||||
|
} else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
70
modules/robot/modulerobot_mainline.go
Normal file
70
modules/robot/modulerobot_mainline.go
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
package robot
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"go_dreamfactory/comm"
|
||||||
|
"go_dreamfactory/pb"
|
||||||
|
"go_dreamfactory/sys/configure"
|
||||||
|
cfg "go_dreamfactory/sys/configure/structs"
|
||||||
|
|
||||||
|
"google.golang.org/protobuf/proto"
|
||||||
|
)
|
||||||
|
|
||||||
|
//用户模块 机器人
|
||||||
|
type ModuleRobot_MainLine struct {
|
||||||
|
info *pb.DBMainline
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *ModuleRobot_MainLine) Init() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//接收到消息
|
||||||
|
func (this *ModuleRobot_MainLine) Receive(robot IRobot, stype string, message proto.Message) (err error) {
|
||||||
|
switch stype {
|
||||||
|
case "info":
|
||||||
|
resp := message.(*pb.MainlineInfoResp)
|
||||||
|
this.info = resp.Info
|
||||||
|
break
|
||||||
|
case "create":
|
||||||
|
// resp := message.(*pb.UserCreateResp)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
//机器人执行流
|
||||||
|
func (this *ModuleRobot_MainLine) DoPipeline(robot IRobot) (err error) {
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
//做任务
|
||||||
|
func (this *ModuleRobot_MainLine) DoTask(robot IRobot, taskconf *cfg.GameWorldTaskData, condconf *cfg.GameBuriedCondiData) (err error) {
|
||||||
|
var (
|
||||||
|
errdata *pb.ErrorData
|
||||||
|
)
|
||||||
|
if _, errdata = robot.SendMessage("mainline", "info", &pb.MainlineInfoReq{}); errdata != nil {
|
||||||
|
err = errors.New(errdata.Message)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
switch comm.TaskType(condconf.Type) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 读取主线关卡表
|
||||||
|
func (this *ModuleRobot_MainLine) getGameMainStageData(cid int32) (conf []*cfg.GameMainStageData, err error) {
|
||||||
|
var (
|
||||||
|
v interface{}
|
||||||
|
)
|
||||||
|
if v, err = configure.GetConfigure(game_mainstage); err != nil {
|
||||||
|
return
|
||||||
|
} else {
|
||||||
|
conf = v.(*cfg.GameMainStage).GetDataList()
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
@ -1,7 +1,7 @@
|
|||||||
package robot
|
package robot
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"errors"
|
||||||
"go_dreamfactory/pb"
|
"go_dreamfactory/pb"
|
||||||
cfg "go_dreamfactory/sys/configure/structs"
|
cfg "go_dreamfactory/sys/configure/structs"
|
||||||
|
|
||||||
@ -10,6 +10,12 @@ import (
|
|||||||
|
|
||||||
//用户模块 机器人
|
//用户模块 机器人
|
||||||
type ModuleRobot_User struct {
|
type ModuleRobot_User struct {
|
||||||
|
user *pb.DBUser
|
||||||
|
userex *pb.DBUserExpand
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *ModuleRobot_User) Init() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//接收到消息
|
//接收到消息
|
||||||
@ -17,8 +23,8 @@ func (this *ModuleRobot_User) Receive(robot IRobot, stype string, message proto.
|
|||||||
switch stype {
|
switch stype {
|
||||||
case "login":
|
case "login":
|
||||||
resp := message.(*pb.UserLoginResp)
|
resp := message.(*pb.UserLoginResp)
|
||||||
robot.SetData("user", resp.Data)
|
this.user = resp.Data
|
||||||
robot.SetData("userex", resp.Ex)
|
this.userex = resp.Ex
|
||||||
break
|
break
|
||||||
case "create":
|
case "create":
|
||||||
// resp := message.(*pb.UserCreateResp)
|
// resp := message.(*pb.UserCreateResp)
|
||||||
@ -27,33 +33,31 @@ func (this *ModuleRobot_User) Receive(robot IRobot, stype string, message proto.
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
//接收到消息
|
|
||||||
func (this *ModuleRobot_User) ErrReceive(robot IRobot, stype string, code pb.ErrorCode) (err error) {
|
|
||||||
switch stype {
|
|
||||||
case "login":
|
|
||||||
err = fmt.Errorf("登录错误:%d", code)
|
|
||||||
break
|
|
||||||
case "create":
|
|
||||||
break
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
//机器人执行流
|
//机器人执行流
|
||||||
func (this *ModuleRobot_User) DoPipeline(robot IRobot) (err error) {
|
func (this *ModuleRobot_User) DoPipeline(robot IRobot) (err error) {
|
||||||
|
var (
|
||||||
|
errdata *pb.ErrorData
|
||||||
|
)
|
||||||
//登录
|
//登录
|
||||||
if err = robot.SendMessage("user", "login", &pb.UserLoginReq{
|
if _, errdata = robot.SendMessage("user", "login", &pb.UserLoginReq{
|
||||||
Account: robot.Account(),
|
Account: robot.Account(),
|
||||||
Sid: robot.ServerId(),
|
Sid: robot.ServerId(),
|
||||||
}); err != nil {
|
}); errdata != nil {
|
||||||
|
err = errors.New(errdata.Message)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
//创角
|
//创角
|
||||||
if err = robot.SendMessage("user", "create", &pb.UserCreateReq{
|
if _, errdata = robot.SendMessage("user", "create", &pb.UserCreateReq{
|
||||||
NickName: robot.Account(),
|
NickName: robot.Account(),
|
||||||
Figure: 100,
|
Figure: 100,
|
||||||
Gender: 1,
|
Gender: 1,
|
||||||
}); err != nil {
|
}); errdata != nil {
|
||||||
|
if errdata.Code == pb.ErrorCode_RoleCreated { //已创角
|
||||||
|
err = nil
|
||||||
|
} else {
|
||||||
|
err = errors.New(errdata.Message)
|
||||||
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package robot
|
package robot
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"errors"
|
||||||
"go_dreamfactory/comm"
|
"go_dreamfactory/comm"
|
||||||
"go_dreamfactory/lego/core"
|
"go_dreamfactory/lego/core"
|
||||||
"go_dreamfactory/lego/sys/log"
|
"go_dreamfactory/lego/sys/log"
|
||||||
@ -16,6 +16,12 @@ import (
|
|||||||
type ModuleRobot_WTask struct {
|
type ModuleRobot_WTask struct {
|
||||||
info *pb.DBWTask
|
info *pb.DBWTask
|
||||||
progress []*pb.DBWTaskItem //任务进度
|
progress []*pb.DBWTaskItem //任务进度
|
||||||
|
state int32
|
||||||
|
change chan bool
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *ModuleRobot_WTask) Init() {
|
||||||
|
this.change = make(chan bool)
|
||||||
}
|
}
|
||||||
|
|
||||||
//接收到消息
|
//接收到消息
|
||||||
@ -69,16 +75,9 @@ func (this *ModuleRobot_WTask) Receive(robot IRobot, stype string, message proto
|
|||||||
this.info.Accepts = append(this.info.Accepts, v.Tid)
|
this.info.Accepts = append(this.info.Accepts, v.Tid)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break
|
if this.state == 1 {
|
||||||
}
|
this.change <- true
|
||||||
return
|
}
|
||||||
}
|
|
||||||
|
|
||||||
//接收到消息
|
|
||||||
func (this *ModuleRobot_WTask) ErrReceive(robot IRobot, stype string, code pb.ErrorCode) (err error) {
|
|
||||||
switch stype {
|
|
||||||
case "info":
|
|
||||||
err = fmt.Errorf("信息获取:%d", code)
|
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
@ -86,8 +85,12 @@ func (this *ModuleRobot_WTask) ErrReceive(robot IRobot, stype string, code pb.Er
|
|||||||
|
|
||||||
//机器人执行流
|
//机器人执行流
|
||||||
func (this *ModuleRobot_WTask) DoPipeline(robot IRobot) (err error) {
|
func (this *ModuleRobot_WTask) DoPipeline(robot IRobot) (err error) {
|
||||||
|
var (
|
||||||
|
errdata *pb.ErrorData
|
||||||
|
)
|
||||||
//获取任务列表
|
//获取任务列表
|
||||||
if err = robot.SendMessage("wtask", "info", &pb.WTaskInfoReq{}); err != nil {
|
if _, errdata = robot.SendMessage("wtask", "info", &pb.WTaskInfoReq{}); errdata != nil {
|
||||||
|
err = errors.New(errdata.Message)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
var (
|
var (
|
||||||
@ -103,7 +106,8 @@ locp:
|
|||||||
break locp
|
break locp
|
||||||
}
|
}
|
||||||
if this.checkaccept(tconf) { //是否需要接收任务
|
if this.checkaccept(tconf) { //是否需要接收任务
|
||||||
if err = robot.SendMessage("wtask", "accept", &pb.WTaskAcceptReq{Tid: tconf.Key}); err != nil {
|
if _, errdata = robot.SendMessage("wtask", "accept", &pb.WTaskAcceptReq{Tid: tconf.Key}); errdata != nil {
|
||||||
|
err = errors.New(errdata.Message)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
@ -116,21 +120,26 @@ locp:
|
|||||||
//有问完成的子任务
|
//有问完成的子任务
|
||||||
if cconf != nil {
|
if cconf != nil {
|
||||||
switch comm.TaskType(cconf.Type) {
|
switch comm.TaskType(cconf.Type) {
|
||||||
case comm.Rtype1:
|
case comm.Rtype1, comm.Rtype14:
|
||||||
module = comm.ModuleHero
|
module = comm.ModuleHero
|
||||||
case comm.Rtype20001:
|
case comm.Rtype20001, comm.Rtype70, comm.Rtype227:
|
||||||
module = comm.ModuleWtask
|
module = comm.ModuleWtask
|
||||||
default:
|
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 !"})
|
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
|
break locp
|
||||||
}
|
}
|
||||||
|
this.change = make(chan bool)
|
||||||
|
this.state = 1
|
||||||
if err = robot.DoTask(tconf, cconf, module); err != nil {
|
if err = robot.DoTask(tconf, cconf, module); err != nil {
|
||||||
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()})
|
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
|
break locp
|
||||||
}
|
}
|
||||||
|
<-this.change //等待任务进度更新
|
||||||
|
this.state = 0
|
||||||
continue
|
continue
|
||||||
} else { //任务已完成直接完成
|
} else { //任务已完成直接完成
|
||||||
if err = robot.SendMessage("wtask", "finish", &pb.WTaskFinishReq{Tid: tconf.Key}); err != nil {
|
if _, errdata = robot.SendMessage("wtask", "finish", &pb.WTaskFinishReq{Tid: tconf.Key}); errdata != nil {
|
||||||
|
err = errors.New(errdata.Message)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -140,9 +149,53 @@ locp:
|
|||||||
|
|
||||||
//做任务
|
//做任务
|
||||||
func (this *ModuleRobot_WTask) DoTask(robot IRobot, taskconf *cfg.GameWorldTaskData, condconf *cfg.GameBuriedCondiData) (err error) {
|
func (this *ModuleRobot_WTask) DoTask(robot IRobot, taskconf *cfg.GameWorldTaskData, condconf *cfg.GameBuriedCondiData) (err error) {
|
||||||
|
var (
|
||||||
|
errdata *pb.ErrorData
|
||||||
|
)
|
||||||
switch comm.TaskType(condconf.Type) {
|
switch comm.TaskType(condconf.Type) {
|
||||||
case comm.Rtype20001:
|
case comm.Rtype20001: //完成对话
|
||||||
if err = robot.SendMessage("wtask", "completecondi", &pb.WTaskCompleteCondiReq{TaskId: taskconf.Key, CondiId: condconf.Id}); err != nil {
|
if _, errdata = robot.SendMessage("wtask", "completecondi", &pb.WTaskCompleteCondiReq{TaskId: taskconf.Key, CondiId: condconf.Id}); errdata != nil {
|
||||||
|
err = errors.New(errdata.Message)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
break
|
||||||
|
case comm.Rtype70: //完成世界任务战斗
|
||||||
|
var (
|
||||||
|
heromodule *ModuleRobot_Hero
|
||||||
|
heros []string
|
||||||
|
resp proto.Message
|
||||||
|
)
|
||||||
|
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 {
|
||||||
|
err = errors.New(errdata.Message)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if _, errdata = robot.SendMessage("wtask", "battlefinish", &pb.WTaskBattleFinishReq{BattleConfId: condconf.Filter[0], Report: &pb.BattleReport{
|
||||||
|
Info: resp.(*pb.WTaskBattleStartResp).Info,
|
||||||
|
WinSide: 1,
|
||||||
|
}}); errdata != nil {
|
||||||
|
err = errors.New(errdata.Message)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
break
|
||||||
|
case comm.Rtype227: //完成世界任务战斗 失败
|
||||||
|
var (
|
||||||
|
heromodule *ModuleRobot_Hero
|
||||||
|
heros []string
|
||||||
|
resp proto.Message
|
||||||
|
)
|
||||||
|
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 {
|
||||||
|
err = errors.New(errdata.Message)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if _, errdata = robot.SendMessage("wtask", "battlefinish", &pb.WTaskBattleFinishReq{BattleConfId: condconf.Filter[0], Report: &pb.BattleReport{
|
||||||
|
Info: resp.(*pb.WTaskBattleStartResp).Info,
|
||||||
|
WinSide: 2,
|
||||||
|
}}); errdata != nil {
|
||||||
|
err = errors.New(errdata.Message)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
|
@ -21,9 +21,8 @@ type Robot struct {
|
|||||||
index int32 //编号
|
index int32 //编号
|
||||||
account, serverId string
|
account, serverId string
|
||||||
curreq string //当前请求
|
curreq string //当前请求
|
||||||
await chan string
|
await chan *MessageResp
|
||||||
modules map[core.M_Modules]IModuleRobot
|
modules map[core.M_Modules]IModuleRobot
|
||||||
datas map[string]interface{}
|
|
||||||
pipeline []string //执行流水线
|
pipeline []string //执行流水线
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -34,21 +33,22 @@ func (this *Robot) Account() string {
|
|||||||
func (this *Robot) ServerId() string {
|
func (this *Robot) ServerId() string {
|
||||||
return this.serverId
|
return this.serverId
|
||||||
}
|
}
|
||||||
func (this *Robot) SetData(key string, data interface{}) {
|
|
||||||
this.datas[key] = data
|
func (this *Robot) GetModule(module core.M_Modules) IModuleRobot {
|
||||||
}
|
return this.modules[module]
|
||||||
func (this *Robot) GetData(key string) interface{} {
|
|
||||||
return this.datas[key]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//初始化
|
//初始化
|
||||||
func (this *Robot) Init(addr string, client IClient) (err error) {
|
func (this *Robot) Init(addr string, client IClient) (err error) {
|
||||||
this.Client.Init(addr, client)
|
this.Client.Init(addr, client)
|
||||||
this.datas = make(map[string]interface{})
|
this.await = make(chan *MessageResp)
|
||||||
this.await = make(chan string)
|
|
||||||
this.modules = make(map[core.M_Modules]IModuleRobot)
|
this.modules = make(map[core.M_Modules]IModuleRobot)
|
||||||
this.modules[comm.ModuleUser] = new(ModuleRobot_User)
|
this.modules[comm.ModuleUser] = new(ModuleRobot_User)
|
||||||
|
this.modules[comm.ModuleHero] = new(ModuleRobot_Hero)
|
||||||
this.modules[comm.ModuleWtask] = new(ModuleRobot_WTask)
|
this.modules[comm.ModuleWtask] = new(ModuleRobot_WTask)
|
||||||
|
for _, v := range this.modules {
|
||||||
|
v.Init()
|
||||||
|
}
|
||||||
go this.run()
|
go this.run()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -73,16 +73,19 @@ func (this *Robot) Receive(msg *pb.UserMessage) (err error) {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if msgpath == "notify.errornotify" { //错误通知
|
if msgpath == "notify.errornotify" { //错误通知
|
||||||
req := message.(*pb.NotifyErrorNotifyPush)
|
resp := message.(*pb.NotifyErrorNotifyPush)
|
||||||
reqpath := fmt.Sprintf("%s.%s", req.ReqMainType, req.ReqSubType)
|
reqpath := fmt.Sprintf("%s.%s", resp.ReqMainType, resp.ReqSubType)
|
||||||
if module, ok = this.modules[core.M_Modules(req.ReqMainType)]; ok {
|
// if module, ok = this.modules[core.M_Modules(resp.ReqMainType)]; ok {
|
||||||
if err = module.ErrReceive(this, req.ReqSubType, req.Code); err != nil {
|
// 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()})
|
// 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
|
// return
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
if reqpath == this.curreq { //收到回应
|
if reqpath == this.curreq { //收到回应
|
||||||
this.await <- msgpath
|
this.await <- &MessageResp{
|
||||||
|
resp: nil,
|
||||||
|
errdata: resp.Err,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -94,7 +97,10 @@ func (this *Robot) Receive(msg *pb.UserMessage) (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if msgpath == this.curreq { //收到回应
|
if msgpath == this.curreq { //收到回应
|
||||||
this.await <- msgpath
|
this.await <- &MessageResp{
|
||||||
|
resp: message,
|
||||||
|
errdata: nil,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -105,7 +111,11 @@ func (this *Robot) WriteMsg(msg *pb.UserMessage) (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//发送消息
|
//发送消息
|
||||||
func (this *Robot) SendMessage(mtype, stype string, msg proto.Message) (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()
|
stime := time.Now()
|
||||||
data, _ := anypb.New(msg)
|
data, _ := anypb.New(msg)
|
||||||
message := &pb.UserMessage{
|
message := &pb.UserMessage{
|
||||||
@ -113,11 +123,20 @@ func (this *Robot) SendMessage(mtype, stype string, msg proto.Message) (err erro
|
|||||||
SubType: stype,
|
SubType: stype,
|
||||||
Data: data,
|
Data: data,
|
||||||
}
|
}
|
||||||
err = this.WriteMsg(message)
|
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" {
|
if mtype != "gateway" {
|
||||||
this.curreq = fmt.Sprintf("%s.%s", mtype, stype)
|
this.curreq = fmt.Sprintf("%s.%s", mtype, stype)
|
||||||
<-this.await //等待回应
|
messageresp = <-this.await //等待回应
|
||||||
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)})
|
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
|
return
|
||||||
}
|
}
|
||||||
@ -160,10 +179,14 @@ func (this *Robot) DoTask(taskconf *cfg.GameWorldTaskData, condconf *cfg.GameBur
|
|||||||
func (this *Robot) run() {
|
func (this *Robot) run() {
|
||||||
var (
|
var (
|
||||||
module IModuleRobot
|
module IModuleRobot
|
||||||
|
err error
|
||||||
)
|
)
|
||||||
for _, v := range this.pipeline {
|
for _, v := range this.pipeline {
|
||||||
module = this.modules[core.M_Modules(v)]
|
module = this.modules[core.M_Modules(v)]
|
||||||
module.DoPipeline(this)
|
if err = module.DoPipeline(this); err != nil {
|
||||||
|
log.Debug("[机器人 执行异常]", log.Field{Key: "Account", Value: this.account}, log.Field{Key: "module", Value: v}, log.Field{Key: "err", Value: err.Error()})
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
this.Close()
|
this.Close()
|
||||||
}
|
}
|
||||||
|
@ -39,7 +39,7 @@ locp:
|
|||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-timer.C:
|
case <-timer.C:
|
||||||
if this.currRobotNum <= this.module.options.RobotSingleNum {
|
if this.currRobotNum < this.module.options.RobotSingleNum {
|
||||||
for i := 0; i < int(this.module.options.RobotSingleNum); i++ {
|
for i := 0; i < int(this.module.options.RobotSingleNum); i++ {
|
||||||
this.createRobot(this.currRobotNum)
|
this.createRobot(this.currRobotNum)
|
||||||
this.currRobotNum++
|
this.currRobotNum++
|
||||||
|
1046
pb/errorcode.pb.go
1046
pb/errorcode.pb.go
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user