补充机器人的逻辑
This commit is contained in:
parent
2333e29b5b
commit
8acef69bd5
59
modules/robot/modulerobot_chat.go
Normal file
59
modules/robot/modulerobot_chat.go
Normal file
@ -0,0 +1,59 @@
|
||||
package robot
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"go_dreamfactory/comm"
|
||||
"go_dreamfactory/pb"
|
||||
cfg "go_dreamfactory/sys/configure/structs"
|
||||
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
//用户模块 机器人
|
||||
type ModuleRobot_Chat struct {
|
||||
}
|
||||
|
||||
func (this *ModuleRobot_Chat) Init() (err error) {
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
//接收到消息
|
||||
func (this *ModuleRobot_Chat) Receive(robot IRobot, stype string, message proto.Message) (err error) {
|
||||
switch stype {
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
//机器人执行流
|
||||
func (this *ModuleRobot_Chat) DoPipeline(robot IRobot) (err error) {
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
//做任务
|
||||
func (this *ModuleRobot_Chat) DoTask(robot IRobot, taskconf *cfg.GameWorldTaskData, condconf *cfg.GameBuriedCondiData) (err error) {
|
||||
var (
|
||||
errdata *pb.ErrorData
|
||||
)
|
||||
switch comm.TaskType(condconf.Type) {
|
||||
case comm.Rtype62:
|
||||
var (
|
||||
usermodule *ModuleRobot_User
|
||||
)
|
||||
usermodule = robot.GetModule(comm.ModuleUser).(*ModuleRobot_User)
|
||||
if _, errdata = robot.SendMessage("chat", "send", &pb.ChatSendReq{
|
||||
Avatar: usermodule.user.Avatar,
|
||||
Uname: usermodule.user.Name,
|
||||
Ulv: usermodule.user.Lv,
|
||||
Channel: pb.ChatChannel_World,
|
||||
Ctype: pb.ChatType_Text,
|
||||
Content: fmt.Sprintf("你好!我是%s", robot.Account()),
|
||||
}); errdata != nil {
|
||||
err = errors.New(fmt.Sprintf("code:%d message:%s", errdata.Code, errdata.Message))
|
||||
return
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
74
modules/robot/modulerobot_shop.go
Normal file
74
modules/robot/modulerobot_shop.go
Normal file
@ -0,0 +1,74 @@
|
||||
package robot
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"go_dreamfactory/comm"
|
||||
"go_dreamfactory/pb"
|
||||
cfg "go_dreamfactory/sys/configure/structs"
|
||||
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
//用户模块 机器人
|
||||
type ModuleRobot_Shop struct {
|
||||
goods map[pb.ShopType][]*pb.ShopItem
|
||||
}
|
||||
|
||||
func (this *ModuleRobot_Shop) Init() (err error) {
|
||||
this.goods = make(map[pb.ShopType][]*pb.ShopItem)
|
||||
return
|
||||
}
|
||||
|
||||
//接收到消息
|
||||
func (this *ModuleRobot_Shop) Receive(robot IRobot, stype string, message proto.Message) (err error) {
|
||||
switch stype {
|
||||
case "getlist":
|
||||
resp := message.(*pb.ShopGetListResp)
|
||||
this.goods[resp.SType] = resp.Goods
|
||||
break
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
//机器人执行流
|
||||
func (this *ModuleRobot_Shop) DoPipeline(robot IRobot) (err error) {
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
//做任务
|
||||
func (this *ModuleRobot_Shop) DoTask(robot IRobot, taskconf *cfg.GameWorldTaskData, condconf *cfg.GameBuriedCondiData) (err error) {
|
||||
var (
|
||||
errdata *pb.ErrorData
|
||||
)
|
||||
switch comm.TaskType(condconf.Type) {
|
||||
case comm.Rtype104:
|
||||
var (
|
||||
usermodule *ModuleRobot_User
|
||||
)
|
||||
usermodule = robot.GetModule(comm.ModuleUser).(*ModuleRobot_User)
|
||||
if _, errdata = robot.SendMessage("shop", "getlist", &pb.ShopGetListReq{
|
||||
SType: pb.ShopType_DiamondShop,
|
||||
}); errdata != nil {
|
||||
err = errors.New(fmt.Sprintf("code:%d message:%s", errdata.Code, errdata.Message))
|
||||
return
|
||||
}
|
||||
|
||||
for _, v := range this.goods[pb.ShopType_DiamondShop] {
|
||||
if v.LeftBuyNum > 0 && usermodule.user.Diamond >= int64(v.Consume[0].N) {
|
||||
if _, errdata = robot.SendMessage("shop", "buy", &pb.ShopBuyReq{
|
||||
ShopType: pb.ShopType_DiamondShop,
|
||||
Gid: v.Gid,
|
||||
BuyNum: 1,
|
||||
}); errdata != nil {
|
||||
err = errors.New(fmt.Sprintf("code:%d message:%s", errdata.Code, errdata.Message))
|
||||
return
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return
|
||||
}
|
@ -140,6 +140,10 @@ locp:
|
||||
module = comm.ModuleViking
|
||||
case comm.Rtype199:
|
||||
module = comm.ModuleHero
|
||||
case comm.Rtype62:
|
||||
module = comm.ModuleChat
|
||||
case comm.Rtype104:
|
||||
module = comm.ModuleShop
|
||||
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
|
||||
|
@ -54,6 +54,8 @@ func (this *Robot) Init(addr string, client IClient) (err error) {
|
||||
this.modules[comm.ModuleArena] = new(ModuleRobot_Arena)
|
||||
this.modules[comm.ModulePagoda] = new(ModuleRobot_Pagoda)
|
||||
this.modules[comm.ModuleViking] = new(ModuleRobot_Viking)
|
||||
this.modules[comm.ModuleChat] = new(ModuleRobot_Chat)
|
||||
this.modules[comm.ModuleShop] = new(ModuleRobot_Shop)
|
||||
|
||||
for _, v := range this.modules {
|
||||
v.Init()
|
||||
|
Loading…
Reference in New Issue
Block a user