上传压测机器人代码
This commit is contained in:
parent
f6a5d14e3c
commit
6b0d6cedc8
@ -14,6 +14,8 @@ const (
|
|||||||
gameWorldtaskBattle = "game_worldbattle.json"
|
gameWorldtaskBattle = "game_worldbattle.json"
|
||||||
game_buriedcondi = "game_buriedcondi.json"
|
game_buriedcondi = "game_buriedcondi.json"
|
||||||
game_mainstage = "game_mainstage.json" //主线表
|
game_mainstage = "game_mainstage.json" //主线表
|
||||||
|
game_equip = "game_equip.json" //装备信息表
|
||||||
|
equip_intensify = "game_equipintensify.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"
|
||||||
@ -35,7 +37,8 @@ func (this *configureComp) Init(service core.IService, module core.IModule, comp
|
|||||||
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)
|
configure.RegisterConfigure(game_mainstage, cfg.NewGameMainStage, nil)
|
||||||
|
configure.RegisterConfigure(game_equip, cfg.NewGameEquip, nil)
|
||||||
|
configure.RegisterConfigure(equip_intensify, cfg.NewGameEquipIntensify, nil)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
198
modules/robot/modulerobot_equipment.go
Normal file
198
modules/robot/modulerobot_equipment.go
Normal file
@ -0,0 +1,198 @@
|
|||||||
|
package robot
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"go_dreamfactory/comm"
|
||||||
|
"go_dreamfactory/pb"
|
||||||
|
"go_dreamfactory/sys/configure"
|
||||||
|
cfg "go_dreamfactory/sys/configure/structs"
|
||||||
|
"sort"
|
||||||
|
|
||||||
|
"google.golang.org/protobuf/proto"
|
||||||
|
)
|
||||||
|
|
||||||
|
//用户模块 机器人
|
||||||
|
type ModuleRobot_Equipment struct {
|
||||||
|
equipments map[string]*pb.DB_Equipment
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *ModuleRobot_Equipment) Init() (err error) {
|
||||||
|
this.equipments = make(map[string]*pb.DB_Equipment)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
//接收到消息
|
||||||
|
func (this *ModuleRobot_Equipment) Receive(robot IRobot, stype string, message proto.Message) (err error) {
|
||||||
|
switch stype {
|
||||||
|
case "getlist":
|
||||||
|
resp := message.(*pb.EquipmentGetListResp)
|
||||||
|
for _, v := range resp.Equipments {
|
||||||
|
this.equipments[v.Id] = v
|
||||||
|
}
|
||||||
|
break
|
||||||
|
case "change":
|
||||||
|
resp := message.(*pb.EquipmentChangePush)
|
||||||
|
for _, v := range resp.Equipments {
|
||||||
|
this.equipments[v.Id] = v
|
||||||
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
//机器人执行流
|
||||||
|
func (this *ModuleRobot_Equipment) DoPipeline(robot IRobot) (err error) {
|
||||||
|
var (
|
||||||
|
errdata *pb.ErrorData
|
||||||
|
)
|
||||||
|
if _, errdata = robot.SendMessage("equipment", "getlist", &pb.EquipmentGetListReq{}); errdata != nil {
|
||||||
|
err = errors.New(errdata.Message)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
//做任务
|
||||||
|
func (this *ModuleRobot_Equipment) DoTask(robot IRobot, taskconf *cfg.GameWorldTaskData, condconf *cfg.GameBuriedCondiData) (err error) {
|
||||||
|
var (
|
||||||
|
errdata *pb.ErrorData
|
||||||
|
)
|
||||||
|
switch comm.TaskType(condconf.Type) {
|
||||||
|
case comm.Rtype5: //穿戴
|
||||||
|
var (
|
||||||
|
heromodule *ModuleRobot_Hero
|
||||||
|
heros map[string]*pb.DBHero
|
||||||
|
equipments []string
|
||||||
|
hero *pb.DBHero
|
||||||
|
change bool
|
||||||
|
)
|
||||||
|
heromodule = robot.GetModule(comm.ModuleHero).(*ModuleRobot_Hero)
|
||||||
|
heros = heromodule.heros
|
||||||
|
for _, hero = range heros {
|
||||||
|
if equipments, change, err = this.findcanEquipEquipment(hero); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if change {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if change {
|
||||||
|
if _, errdata = robot.SendTaskMessage(taskconf.Key, condconf.Id, "equipment", "equip", &pb.EquipmentEquipReq{
|
||||||
|
HeroCardId: hero.Id,
|
||||||
|
EquipmentId: equipments,
|
||||||
|
}); errdata != nil {
|
||||||
|
err = errors.New(errdata.Message)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
err = fmt.Errorf("no fund can use equipments")
|
||||||
|
}
|
||||||
|
case comm.Rtype92, comm.Rtype96: //强化
|
||||||
|
var (
|
||||||
|
equipment *pb.DB_Equipment
|
||||||
|
)
|
||||||
|
if equipment, err = this.findcanupgrade(); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if _, errdata = robot.SendTaskMessage(taskconf.Key, condconf.Id, "equipment", "upgrade", &pb.EquipmentUpgradeReq{
|
||||||
|
EquipmentId: equipment.Id,
|
||||||
|
}); errdata != nil {
|
||||||
|
err = errors.New(errdata.Message)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
//查询能穿戴的装备
|
||||||
|
func (this *ModuleRobot_Equipment) findcanEquipEquipment(hero *pb.DBHero) (equipments []string, change bool, err error) {
|
||||||
|
var (
|
||||||
|
conf *cfg.GameEquipData
|
||||||
|
)
|
||||||
|
equipments = hero.EquipID
|
||||||
|
for i, v := range hero.EquipID {
|
||||||
|
if v == "" {
|
||||||
|
for _, equipment := range this.equipments {
|
||||||
|
if equipment.HeroId == "" {
|
||||||
|
if conf, err = this.getGameEquipData(equipment.CId); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if conf.Pos == int32(i) { //找到匹配装备
|
||||||
|
equipments[i] = equipment.Id
|
||||||
|
change = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
//查询能强化的装备
|
||||||
|
func (this *ModuleRobot_Equipment) findcanupgrade() (equipment *pb.DB_Equipment, err error) {
|
||||||
|
var (
|
||||||
|
equipments []*pb.DB_Equipment = make([]*pb.DB_Equipment, 0, len(this.equipments))
|
||||||
|
conf *cfg.GameEquipData
|
||||||
|
upconf *cfg.GameEquipIntensifyData
|
||||||
|
)
|
||||||
|
var ()
|
||||||
|
for _, v := range this.equipments {
|
||||||
|
equipments = append(equipments, v)
|
||||||
|
}
|
||||||
|
sort.Slice(equipments, func(i, j int) bool {
|
||||||
|
return equipments[i].Lv < equipments[j].Lv
|
||||||
|
})
|
||||||
|
for _, equipment = range equipments {
|
||||||
|
if conf, err = this.getGameEquipData(equipment.CId); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if upconf, err = this.getEquipmentMaxIntensifyConfigure(conf.EquipId, conf.Color); err == nil && upconf.Level < equipment.Lv {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
equipment = nil
|
||||||
|
err = fmt.Errorf("no fund can upgrade equipment")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 读取条件任务id配置
|
||||||
|
func (this *ModuleRobot_Equipment) getGameEquipData(cid string) (conf *cfg.GameEquipData, err error) {
|
||||||
|
var (
|
||||||
|
v interface{}
|
||||||
|
ok bool
|
||||||
|
)
|
||||||
|
if v, err = configure.GetConfigure(game_equip); err != nil {
|
||||||
|
return
|
||||||
|
} else {
|
||||||
|
if conf, ok = v.(*cfg.GameEquip).GetDataMap()[cid]; !ok {
|
||||||
|
err = comm.NewNotFoundConfErr("robot", game_buriedcondi, cid)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 读取条件任务id配置
|
||||||
|
// 获取武器等级消耗表
|
||||||
|
func (this *ModuleRobot_Equipment) getEquipmentMaxIntensifyConfigure(etype, star int32) (conf *cfg.GameEquipIntensifyData, err error) {
|
||||||
|
var (
|
||||||
|
v interface{}
|
||||||
|
lv int32
|
||||||
|
)
|
||||||
|
if v, err = configure.GetConfigure(equip_intensify); err != nil {
|
||||||
|
return
|
||||||
|
} else {
|
||||||
|
for _, v1 := range v.(*cfg.GameEquipIntensify).GetDataList() {
|
||||||
|
if v1.TypeId == etype && v1.Star == star && len(v1.Need) > 0 && v1.Level > lv {
|
||||||
|
lv = v1.Level
|
||||||
|
conf = v1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if conf == nil {
|
||||||
|
err = fmt.Errorf("GetEquipmentMaxIntensifyConfigure not found star :%d lv:%d", star, lv)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
@ -129,6 +129,8 @@ locp:
|
|||||||
module = comm.ModulePractice
|
module = comm.ModulePractice
|
||||||
case comm.Rtype61:
|
case comm.Rtype61:
|
||||||
module = comm.ModuleMainline
|
module = comm.ModuleMainline
|
||||||
|
case comm.Rtype5:
|
||||||
|
module = comm.ModuleEquipment
|
||||||
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
|
||||||
|
@ -46,6 +46,7 @@ func (this *Robot) Init(addr string, client IClient) (err error) {
|
|||||||
this.modules[comm.ModuleUser] = new(ModuleRobot_User)
|
this.modules[comm.ModuleUser] = new(ModuleRobot_User)
|
||||||
this.modules[comm.ModuleSys] = new(ModuleRobot_Sys)
|
this.modules[comm.ModuleSys] = new(ModuleRobot_Sys)
|
||||||
this.modules[comm.ModuleHero] = new(ModuleRobot_Hero)
|
this.modules[comm.ModuleHero] = new(ModuleRobot_Hero)
|
||||||
|
this.modules[comm.ModuleEquipment] = new(ModuleRobot_Equipment)
|
||||||
this.modules[comm.ModuleWtask] = new(ModuleRobot_WTask)
|
this.modules[comm.ModuleWtask] = new(ModuleRobot_WTask)
|
||||||
this.modules[comm.ModulePractice] = new(ModuleRobot_Practice)
|
this.modules[comm.ModulePractice] = new(ModuleRobot_Practice)
|
||||||
this.modules[comm.ModuleMainline] = new(ModuleRobot_MainLine)
|
this.modules[comm.ModuleMainline] = new(ModuleRobot_MainLine)
|
||||||
|
Loading…
Reference in New Issue
Block a user