945 lines
27 KiB
Go
945 lines
27 KiB
Go
package battle
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/core"
|
|
"go_dreamfactory/lego/sys/log"
|
|
"go_dreamfactory/modules"
|
|
"go_dreamfactory/pb"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
"go_dreamfactory/sys/db"
|
|
"time"
|
|
|
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
|
)
|
|
|
|
///数据组件
|
|
type modelBattleComp struct {
|
|
modules.MCompModel
|
|
module *Battle
|
|
}
|
|
|
|
//组件初始化接口
|
|
func (this *modelBattleComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, opt core.IModuleOptions) (err error) {
|
|
this.TableName = comm.TableForum
|
|
this.MCompModel.Init(service, module, comp, opt)
|
|
this.module = module.(*Battle)
|
|
this.TableName = "battle"
|
|
// _, err = this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{
|
|
// Keys: bsonx.Doc{{Key: "heroid", Value: bsonx.Int32(1)}},
|
|
// })
|
|
return
|
|
}
|
|
|
|
//查询战斗记录
|
|
func (this *modelBattleComp) queryrecord(oid string) (record *pb.DBBattleRecord, err error) {
|
|
record = &pb.DBBattleRecord{}
|
|
if err = this.Get(oid, record); err != nil {
|
|
this.module.Errorln(err)
|
|
}
|
|
return
|
|
}
|
|
|
|
//创建pve 战斗记录
|
|
func (this *modelBattleComp) createeve(session comm.IUserSession, conn *db.DBConn, btype pb.BattleType, req *pb.BattleEVEReq) (record *pb.DBBattleRecord, errdata *pb.ErrorData) {
|
|
record = &pb.DBBattleRecord{
|
|
Id: primitive.NewObjectID().Hex(),
|
|
Title: req.Title,
|
|
Btype: btype,
|
|
Ptype: req.Ptype,
|
|
State: pb.BBattleState_in,
|
|
RedCompId: session.GetUserId(),
|
|
BlueCompId: "",
|
|
Buleflist: make([]*pb.DBBattleFormt, len(req.Buleformat)),
|
|
Tasks: make([]int32, 0),
|
|
}
|
|
var (
|
|
battletas *cfg.GameBattletasktestingData
|
|
captain int32
|
|
masters []*pb.BattleRole
|
|
buff *cfg.GamePandamasBuffData
|
|
)
|
|
buff, _ = this.getGlobalBuff(session.GetUserId())
|
|
if battletas, _ = this.module.configure.GetBattleTask(int32(req.Ptype)); battletas != nil {
|
|
record.Tasks = battletas.BattletaskTestingId
|
|
}
|
|
|
|
if req.Format != nil {
|
|
model := db.NewDBModel(comm.TableHero, time.Hour, conn)
|
|
record.Redflist = make([]*pb.DBBattleFormt, 1)
|
|
record.Redflist[0] = &pb.DBBattleFormt{
|
|
Leadpos: req.Format.Leadpos,
|
|
Team: make([]*pb.BattleRole, len(req.Format.Format)),
|
|
}
|
|
//自己的英雄阵营
|
|
for i, v := range req.Format.Format {
|
|
if v != "" {
|
|
hero := &pb.DBHero{}
|
|
if err := model.GetListObj(session.GetUserId(), v, hero); err != nil {
|
|
code = pb.ErrorCode_HeroNoExist
|
|
return
|
|
}
|
|
tid := 100 + i
|
|
if record.Redflist[0].Team[i], code = this.createBattleRole(hero, tid, i); errdata != nil {
|
|
return
|
|
}
|
|
if buff != nil {
|
|
if conf, err := this.module.configure.GetHeroConfig(hero.HeroID); err == nil {
|
|
if buff.CampRestriction == conf.Race && buff.OccupationalRestrictions == conf.Job && conf.Star >= buff.StarLimit {
|
|
record.Redflist[0].Team[i].PandaBuff = buff.Buffid
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
record.Redflist[0].Team[i] = nil
|
|
}
|
|
}
|
|
//好友的英雄阵营
|
|
for i, v := range req.Format.Friendformat {
|
|
if v != "" {
|
|
var (
|
|
hero *pb.DBHero
|
|
err error
|
|
)
|
|
// 获取好友英雄信息
|
|
if this.module.IsCross() {
|
|
if hero, err = this.module.friend.UseAssistHero(session.GetUserId(), v); err != nil {
|
|
this.module.Errorln(err)
|
|
code = pb.ErrorCode_HeroNoExist
|
|
return
|
|
}
|
|
} else { //获取跨服数据
|
|
hero = &pb.DBHero{}
|
|
if err = this.module.service.AcrossClusterRpcCall(
|
|
context.Background(),
|
|
this.module.GetCrossTag(),
|
|
comm.Service_Worker,
|
|
string(comm.Rpc_ModuleFriendUseAssitHero),
|
|
pb.RPCGeneralReqA2{Param1: session.GetUserId(), Param2: v},
|
|
hero); err != nil {
|
|
this.module.Errorln(err)
|
|
}
|
|
}
|
|
tid := 100 + i
|
|
if record.Redflist[0].Team[i], code = this.createBattleRole(hero, tid, i); errdata != nil {
|
|
return
|
|
}
|
|
record.Redflist[0].Team[i].Ishelp = true
|
|
if buff != nil {
|
|
if conf, err := this.module.configure.GetHeroConfig(hero.HeroID); err == nil {
|
|
if buff.CampRestriction == conf.Race && buff.OccupationalRestrictions == conf.Job && conf.Star >= buff.StarLimit {
|
|
record.Redflist[0].Team[i].PandaBuff = buff.Buffid
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if req.Sysformat != nil && len(req.Sysformat) > 0 {
|
|
for i, v := range req.Sysformat {
|
|
if v == 0 {
|
|
continue
|
|
}
|
|
if captain, masters, code = this.createMasterRoles(100, i, v); errdata != nil {
|
|
return
|
|
}
|
|
record.Redflist[i].Systeam = masters
|
|
if record.Redflist[i].Leadpos == -1 && captain != -1 {
|
|
record.Redflist[i].Leadpos = captain
|
|
}
|
|
if buff != nil {
|
|
for _, v := range masters {
|
|
if conf, err := this.module.configure.GetHeroConfig(v.HeroID); err == nil {
|
|
if buff.CampRestriction == conf.Race && buff.OccupationalRestrictions == conf.Job && conf.Star >= buff.StarLimit {
|
|
v.PandaBuff = buff.Buffid
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if req.Backupformat != nil && len(req.Backupformat) > 0 {
|
|
for i, v := range req.Backupformat {
|
|
if v == 0 {
|
|
continue
|
|
}
|
|
if captain, masters, code = this.createMasterRoles(100, i, v); errdata != nil {
|
|
return
|
|
}
|
|
record.Redflist[i].Backupteam = masters
|
|
if buff != nil {
|
|
for _, v := range masters {
|
|
if conf, err := this.module.configure.GetHeroConfig(v.HeroID); err == nil {
|
|
if buff.CampRestriction == conf.Race && buff.OccupationalRestrictions == conf.Job && conf.Star >= buff.StarLimit {
|
|
v.PandaBuff = buff.Buffid
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
record.Redflist = make([]*pb.DBBattleFormt, len(req.Sysformat))
|
|
for i, v := range req.Sysformat {
|
|
if captain, masters, code = this.createMasterRoles(100, i, v); errdata != nil {
|
|
return
|
|
}
|
|
record.Redflist[i] = &pb.DBBattleFormt{
|
|
Leadpos: captain,
|
|
Systeam: masters,
|
|
}
|
|
if buff != nil {
|
|
for _, v := range masters {
|
|
if conf, err := this.module.configure.GetHeroConfig(v.HeroID); err == nil {
|
|
if buff.CampRestriction == conf.Race && buff.OccupationalRestrictions == conf.Job && conf.Star >= buff.StarLimit {
|
|
v.PandaBuff = buff.Buffid
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if req.Backupformat != nil && len(req.Backupformat) > 0 {
|
|
for i, v := range req.Backupformat {
|
|
if captain, masters, code = this.createMasterRoles(100, i, v); errdata != nil {
|
|
return
|
|
}
|
|
record.Redflist[i].Backupteam = masters
|
|
if buff != nil {
|
|
for _, v := range masters {
|
|
if conf, err := this.module.configure.GetHeroConfig(v.HeroID); err == nil {
|
|
if buff.CampRestriction == conf.Race && buff.OccupationalRestrictions == conf.Job && conf.Star >= buff.StarLimit {
|
|
v.PandaBuff = buff.Buffid
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
for i, v := range req.Buleformat {
|
|
if captain, masters, code = this.createMasterRoles(200, i, v); errdata != nil {
|
|
return
|
|
}
|
|
record.Buleflist[i] = &pb.DBBattleFormt{
|
|
Leadpos: captain,
|
|
Team: masters,
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
//创建pve 战斗记录
|
|
func (this *modelBattleComp) createpve(session comm.IUserSession, conn *db.DBConn, btype pb.BattleType, req *pb.BattlePVEReq) (record *pb.DBBattleRecord, errdata *pb.ErrorData) {
|
|
var (
|
|
heros []*pb.DBHero = make([]*pb.DBHero, 5)
|
|
buff *cfg.GamePandamasBuffData
|
|
)
|
|
record = &pb.DBBattleRecord{
|
|
Id: primitive.NewObjectID().Hex(),
|
|
Title: req.Title,
|
|
Btype: btype,
|
|
Ptype: req.Ptype,
|
|
State: pb.BBattleState_in,
|
|
RedCompId: session.GetUserId(),
|
|
Redflist: make([]*pb.DBBattleFormt, 1),
|
|
BlueCompId: "",
|
|
Buleflist: make([]*pb.DBBattleFormt, len(req.Mformat)),
|
|
}
|
|
record.Redflist[0] = &pb.DBBattleFormt{
|
|
Leadpos: req.Format.Leadpos,
|
|
Team: make([]*pb.BattleRole, len(req.Format.Format)),
|
|
}
|
|
model := db.NewDBModel(comm.TableHero, time.Hour, conn)
|
|
buff, _ = this.getGlobalBuff(session.GetUserId())
|
|
//自己的英雄阵营
|
|
for i, v := range req.Format.Format {
|
|
if v != "" {
|
|
heros[i] = &pb.DBHero{}
|
|
if err := model.GetListObj(session.GetUserId(), v, heros[i]); err != nil {
|
|
code = pb.ErrorCode_HeroNoExist
|
|
return
|
|
}
|
|
tid := 100 + i
|
|
if record.Redflist[0].Team[i], code = this.createBattleRole(heros[i], tid, i); errdata != nil {
|
|
return
|
|
}
|
|
if buff != nil {
|
|
if conf, err := this.module.configure.GetHeroConfig(heros[i].HeroID); err == nil {
|
|
if buff.CampRestriction == conf.Race && buff.OccupationalRestrictions == conf.Job && conf.Star >= buff.StarLimit {
|
|
record.Redflist[0].Team[i].PandaBuff = buff.Buffid
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
record.Redflist[0].Team[i] = nil
|
|
}
|
|
}
|
|
//好友的英雄阵营
|
|
for i, v := range req.Format.Friendformat {
|
|
if v != "" {
|
|
var (
|
|
err error
|
|
)
|
|
// 获取好友英雄信息
|
|
if this.module.IsCross() {
|
|
if heros[i], err = this.module.friend.UseAssistHero(session.GetUserId(), v); err != nil {
|
|
this.module.Errorln(err)
|
|
code = pb.ErrorCode_HeroNoExist
|
|
return
|
|
}
|
|
} else { //获取跨服数据
|
|
heros[i] = &pb.DBHero{}
|
|
if err = this.module.service.AcrossClusterRpcCall(
|
|
context.Background(),
|
|
this.module.GetCrossTag(),
|
|
comm.Service_Worker,
|
|
string(comm.Rpc_ModuleFriendUseAssitHero),
|
|
pb.RPCGeneralReqA2{Param1: session.GetUserId(), Param2: v},
|
|
heros[i]); err != nil {
|
|
this.module.Errorln(err)
|
|
}
|
|
}
|
|
tid := 100 + i
|
|
if record.Redflist[0].Team[i], code = this.createBattleRole(heros[i], tid, i); errdata != nil {
|
|
return
|
|
}
|
|
record.Redflist[0].Team[i].Ishelp = true
|
|
if buff != nil {
|
|
if conf, err := this.module.configure.GetHeroConfig(heros[i].HeroID); err == nil {
|
|
if buff.CampRestriction == conf.Race && buff.OccupationalRestrictions == conf.Job && conf.Star >= buff.StarLimit {
|
|
record.Redflist[0].Team[i].PandaBuff = buff.Buffid
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if ok := this.checkBattlereadyCapskill(req.Format.Leadpos, heros); !ok {
|
|
code = pb.ErrorCode_BattleCapskillCheckFailed
|
|
return
|
|
}
|
|
var (
|
|
captain int32
|
|
masters []*pb.BattleRole
|
|
)
|
|
for i, v := range req.Mformat {
|
|
if captain, masters, code = this.createMasterRoles(200, i, v); errdata != nil {
|
|
return
|
|
}
|
|
record.Buleflist[i] = &pb.DBBattleFormt{
|
|
Leadpos: captain,
|
|
Team: masters,
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
//创建pve 战斗记录
|
|
func (this *modelBattleComp) createpvb(session comm.IUserSession, conn *db.DBConn, btype pb.BattleType, req *pb.BattlePVBReq) (record *pb.DBBattleRecord, errdata *pb.ErrorData) {
|
|
var (
|
|
buff *cfg.GamePandamasBuffData
|
|
)
|
|
record = &pb.DBBattleRecord{
|
|
Id: primitive.NewObjectID().Hex(),
|
|
Title: req.Title,
|
|
Btype: btype,
|
|
Ptype: req.Ptype,
|
|
State: pb.BBattleState_in,
|
|
RedCompId: session.GetUserId(),
|
|
Redflist: make([]*pb.DBBattleFormt, len(req.Format)),
|
|
BlueCompId: "",
|
|
Buleflist: make([]*pb.DBBattleFormt, len(req.Mformat)),
|
|
}
|
|
buff, _ = this.getGlobalBuff(session.GetUserId())
|
|
for ii, v := range req.Format {
|
|
heros := make([]*pb.DBHero, 5)
|
|
record.Redflist[ii] = &pb.DBBattleFormt{
|
|
Leadpos: v.Leadpos,
|
|
Team: make([]*pb.BattleRole, len(v.Format)),
|
|
}
|
|
model := db.NewDBModel(comm.TableHero, time.Hour, conn)
|
|
//自己的英雄阵营
|
|
for i, v := range v.Format {
|
|
if v != "" {
|
|
heros[i] = &pb.DBHero{}
|
|
if err := model.GetListObj(session.GetUserId(), v, heros[i]); err != nil {
|
|
code = pb.ErrorCode_HeroNoExist
|
|
return
|
|
}
|
|
tid := 100 + i
|
|
if record.Redflist[ii].Team[i], code = this.createBattleRole(heros[i], tid, i); errdata != nil {
|
|
return
|
|
}
|
|
if buff != nil {
|
|
if conf, err := this.module.configure.GetHeroConfig(heros[i].HeroID); err == nil {
|
|
if buff.CampRestriction == conf.Race && buff.OccupationalRestrictions == conf.Job && conf.Star >= buff.StarLimit {
|
|
record.Redflist[ii].Team[i].PandaBuff = buff.Buffid
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
record.Redflist[ii].Team[i] = nil
|
|
}
|
|
}
|
|
//好友的英雄阵营
|
|
for i, v := range v.Friendformat {
|
|
if v != "" {
|
|
var (
|
|
err error
|
|
)
|
|
// 获取好友英雄信息
|
|
if this.module.IsCross() {
|
|
if heros[i], err = this.module.friend.UseAssistHero(session.GetUserId(), v); err != nil {
|
|
this.module.Errorln(err)
|
|
code = pb.ErrorCode_HeroNoExist
|
|
return
|
|
}
|
|
} else { //获取跨服数据
|
|
heros[i] = &pb.DBHero{}
|
|
if err = this.module.service.AcrossClusterRpcCall(
|
|
context.Background(),
|
|
this.module.GetCrossTag(),
|
|
comm.Service_Worker,
|
|
string(comm.Rpc_ModuleFriendUseAssitHero),
|
|
pb.RPCGeneralReqA2{Param1: session.GetUserId(), Param2: v},
|
|
heros[i]); err != nil {
|
|
this.module.Errorln(err)
|
|
}
|
|
}
|
|
tid := 100 + i
|
|
if record.Redflist[ii].Team[i], code = this.createBattleRole(heros[i], tid, i); errdata != nil {
|
|
return
|
|
}
|
|
record.Redflist[ii].Team[i].Ishelp = true
|
|
if buff != nil {
|
|
if conf, err := this.module.configure.GetHeroConfig(heros[i].HeroID); err == nil {
|
|
if buff.CampRestriction == conf.Race && buff.OccupationalRestrictions == conf.Job && conf.Star >= buff.StarLimit {
|
|
record.Redflist[ii].Team[i].PandaBuff = buff.Buffid
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if ok := this.checkBattlereadyCapskill(v.Leadpos, heros); !ok {
|
|
code = pb.ErrorCode_BattleCapskillCheckFailed
|
|
return
|
|
}
|
|
}
|
|
|
|
var (
|
|
captain int32
|
|
masters []*pb.BattleRole
|
|
)
|
|
for i, v := range req.Mformat {
|
|
if captain, masters, code = this.createMasterRoles(200, i, v); errdata != nil {
|
|
return
|
|
}
|
|
record.Buleflist[i] = &pb.DBBattleFormt{
|
|
Leadpos: captain,
|
|
Team: masters,
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
//创建pvp 战斗请求
|
|
func (this *modelBattleComp) createpvp(session comm.IUserSession, conn *db.DBConn, btype pb.BattleType, req *pb.BattlePVPReq) (record *pb.DBBattleRecord, errdata *pb.ErrorData) {
|
|
record = &pb.DBBattleRecord{
|
|
Id: primitive.NewObjectID().Hex(),
|
|
Title: req.Title,
|
|
Btype: btype,
|
|
Ptype: req.Ptype,
|
|
State: pb.BBattleState_in,
|
|
RedCompId: req.Redformat.Uid,
|
|
Redflist: make([]*pb.DBBattleFormt, 1),
|
|
BlueCompId: req.Buleformat.Uid,
|
|
Buleflist: make([]*pb.DBBattleFormt, 1),
|
|
}
|
|
record.Redflist[0] = &pb.DBBattleFormt{
|
|
Leadpos: req.Redformat.Leadpos,
|
|
Team: make([]*pb.BattleRole, len(req.Redformat.Format)),
|
|
}
|
|
//自己的英雄阵营
|
|
for i, v := range req.Redformat.Format {
|
|
if v != nil {
|
|
tid := 100 + i
|
|
if record.Redflist[0].Team[i], code = this.createBattleRole(v, tid, i); errdata != nil {
|
|
return
|
|
}
|
|
} else {
|
|
record.Redflist[0].Team[i] = nil
|
|
}
|
|
}
|
|
if ok := this.checkBattlereadyCapskill(req.Redformat.Leadpos, req.Redformat.Format); !ok {
|
|
code = pb.ErrorCode_BattleCapskillCheckFailed
|
|
return
|
|
}
|
|
|
|
record.Buleflist[0] = &pb.DBBattleFormt{
|
|
Leadpos: req.Buleformat.Leadpos,
|
|
Team: make([]*pb.BattleRole, len(req.Buleformat.Format)),
|
|
}
|
|
//自己的英雄阵营
|
|
for i, v := range req.Buleformat.Format {
|
|
if v != nil {
|
|
tid := 200 + i
|
|
if record.Buleflist[0].Team[i], code = this.createBattleRole(v, tid, i); errdata != nil {
|
|
return
|
|
}
|
|
} else {
|
|
record.Buleflist[0].Team[i] = nil
|
|
}
|
|
}
|
|
if ok := this.checkBattlereadyCapskill(req.Buleformat.Leadpos, req.Buleformat.Format); !ok {
|
|
code = pb.ErrorCode_BattleCapskillCheckFailed
|
|
return
|
|
}
|
|
return
|
|
}
|
|
|
|
//创建pvp 战斗请求
|
|
func (this *modelBattleComp) creatertpvp(redmodel, bluemodel *db.DBModel, btype pb.BattleType, req *pb.BattleRTPVPReq) (record *pb.DBBattleRecord, errdata *pb.ErrorData) {
|
|
record = &pb.DBBattleRecord{
|
|
Id: primitive.NewObjectID().Hex(),
|
|
Title: req.Title,
|
|
Btype: btype,
|
|
Ptype: req.Ptype,
|
|
State: pb.BBattleState_in,
|
|
RedCompId: req.RedCompId,
|
|
Redflist: make([]*pb.DBBattleFormt, len(req.Redformat)),
|
|
BlueCompId: req.BlueCompId,
|
|
Buleflist: make([]*pb.DBBattleFormt, len(req.Bulefformat)),
|
|
}
|
|
for ii, v := range req.Redformat {
|
|
heros := make([]*pb.DBHero, 5)
|
|
record.Redflist[ii] = &pb.DBBattleFormt{
|
|
Leadpos: v.Leadpos,
|
|
Team: make([]*pb.BattleRole, len(v.Format)),
|
|
}
|
|
for i, v := range v.Format {
|
|
if v != "" {
|
|
heros[i] = &pb.DBHero{}
|
|
if err := redmodel.GetListObj(req.RedCompId, v, heros[i]); err != nil {
|
|
code = pb.ErrorCode_HeroNoExist
|
|
return
|
|
}
|
|
tid := 100 + i
|
|
if record.Redflist[ii].Team[i], code = this.createBattleRole(heros[i], tid, i); errdata != nil {
|
|
return
|
|
}
|
|
} else {
|
|
record.Redflist[ii].Team[i] = nil
|
|
}
|
|
}
|
|
if ok := this.checkBattlereadyCapskill(v.Leadpos, heros); !ok {
|
|
code = pb.ErrorCode_BattleCapskillCheckFailed
|
|
return
|
|
}
|
|
}
|
|
for ii, v := range req.Bulefformat {
|
|
heros := make([]*pb.DBHero, 5)
|
|
record.Buleflist[ii] = &pb.DBBattleFormt{
|
|
Leadpos: v.Leadpos,
|
|
Team: make([]*pb.BattleRole, len(v.Format)),
|
|
}
|
|
for i, v := range v.Format {
|
|
if v != "" {
|
|
heros[i] = &pb.DBHero{}
|
|
if err := bluemodel.GetListObj(req.BlueCompId, v, heros[i]); err != nil {
|
|
code = pb.ErrorCode_HeroNoExist
|
|
return
|
|
}
|
|
tid := 200 + i
|
|
if record.Buleflist[ii].Team[i], code = this.createBattleRole(heros[i], tid, i); errdata != nil {
|
|
return
|
|
}
|
|
} else {
|
|
record.Buleflist[ii].Team[i] = nil
|
|
}
|
|
}
|
|
if ok := this.checkBattlereadyCapskill(v.Leadpos, heros); !ok {
|
|
code = pb.ErrorCode_BattleCapskillCheckFailed
|
|
return
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
//创建pve 战斗记录
|
|
func (this *modelBattleComp) createlpve(session comm.IUserSession, conn *db.DBConn, btype pb.BattleType, req *pb.BattleLPVEReq) (record *pb.DBBattleRecord, errdata *pb.ErrorData) {
|
|
var (
|
|
heros []*pb.DBHero = make([]*pb.DBHero, 5)
|
|
buff *cfg.GamePandamasBuffData
|
|
)
|
|
record = &pb.DBBattleRecord{
|
|
Id: primitive.NewObjectID().Hex(),
|
|
Title: req.Title,
|
|
Btype: btype,
|
|
Ptype: req.Ptype,
|
|
State: pb.BBattleState_in,
|
|
RedCompId: session.GetUserId(),
|
|
Redflist: make([]*pb.DBBattleFormt, 1),
|
|
BlueCompId: "",
|
|
Buleflist: make([]*pb.DBBattleFormt, 1),
|
|
}
|
|
record.Redflist[0] = &pb.DBBattleFormt{
|
|
Leadpos: req.Format.Leadpos,
|
|
Team: make([]*pb.BattleRole, len(req.Format.Format)),
|
|
}
|
|
model := db.NewDBModel(comm.TableHero, time.Hour, conn)
|
|
buff, _ = this.getGlobalBuff(session.GetUserId())
|
|
//自己的英雄阵营
|
|
for i, v := range req.Format.Format {
|
|
if v != "" {
|
|
heros[i] = &pb.DBHero{}
|
|
if err := model.GetListObj(session.GetUserId(), v, heros[i]); err != nil {
|
|
code = pb.ErrorCode_HeroNoExist
|
|
return
|
|
}
|
|
tid := 100 + i
|
|
if record.Redflist[0].Team[i], code = this.createBattleRole(heros[i], tid, i); errdata != nil {
|
|
return
|
|
}
|
|
if buff != nil {
|
|
if conf, err := this.module.configure.GetHeroConfig(heros[i].HeroID); err == nil {
|
|
if buff.CampRestriction == conf.Race && buff.OccupationalRestrictions == conf.Job && conf.Star >= buff.StarLimit {
|
|
record.Redflist[0].Team[i].PandaBuff = buff.Buffid
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
record.Redflist[0].Team[i] = nil
|
|
}
|
|
}
|
|
//好友的英雄阵营
|
|
for i, v := range req.Format.Friendformat {
|
|
if v != "" {
|
|
var (
|
|
err error
|
|
)
|
|
// 获取好友英雄信息
|
|
if this.module.IsCross() {
|
|
if heros[i], err = this.module.friend.UseAssistHero(session.GetUserId(), v); err != nil {
|
|
this.module.Errorln(err)
|
|
code = pb.ErrorCode_HeroNoExist
|
|
return
|
|
}
|
|
} else { //获取跨服数据
|
|
heros[i] = &pb.DBHero{}
|
|
if err = this.module.service.AcrossClusterRpcCall(
|
|
context.Background(),
|
|
this.module.GetCrossTag(),
|
|
comm.Service_Worker,
|
|
string(comm.Rpc_ModuleFriendUseAssitHero),
|
|
pb.RPCGeneralReqA2{Param1: session.GetUserId(), Param2: v},
|
|
heros[i]); err != nil {
|
|
this.module.Errorln(err)
|
|
}
|
|
}
|
|
tid := 100 + i
|
|
if record.Redflist[0].Team[i], code = this.createBattleRole(heros[i], tid, i); errdata != nil {
|
|
return
|
|
}
|
|
record.Redflist[0].Team[i].Ishelp = true
|
|
if buff != nil {
|
|
if conf, err := this.module.configure.GetHeroConfig(heros[i].HeroID); err == nil {
|
|
if buff.CampRestriction == conf.Race && buff.OccupationalRestrictions == conf.Job && conf.Star >= buff.StarLimit {
|
|
record.Redflist[0].Team[i].PandaBuff = buff.Buffid
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if ok := this.checkBattlereadyCapskill(req.Format.Leadpos, heros); !ok {
|
|
code = pb.ErrorCode_BattleCapskillCheckFailed
|
|
return
|
|
}
|
|
record.Buleflist[0] = &pb.DBBattleFormt{
|
|
Leadpos: req.Monsterleadpos,
|
|
Team: req.Monsters,
|
|
}
|
|
return
|
|
}
|
|
|
|
func (this *modelBattleComp) createBattleRole(hero *pb.DBHero, tid, pos int) (role *pb.BattleRole, errdata *pb.ErrorData) {
|
|
role = &pb.BattleRole{
|
|
Tid: int32(tid),
|
|
Oid: hero.Id,
|
|
HeroID: hero.HeroID,
|
|
Pos: int32(pos),
|
|
Star: hero.Star,
|
|
Lv: hero.Lv,
|
|
CaptainSkill: hero.CaptainSkill,
|
|
NormalSkill: hero.NormalSkill,
|
|
EquipSkill: make([]*pb.SkillData, 0),
|
|
Property: make(map[int32]int32),
|
|
}
|
|
for k, v := range hero.Property {
|
|
arrt := AttributesTransBase(k)
|
|
role.Property[arrt] += v
|
|
if k == comm.Hp {
|
|
role.Currhp += v
|
|
}
|
|
}
|
|
for k, v := range hero.AddProperty {
|
|
arrt := AttributesTransExt(k)
|
|
role.Property[arrt] += v
|
|
if k == comm.Hp {
|
|
role.Currhp += v
|
|
}
|
|
}
|
|
|
|
for k, v := range hero.JuexProperty {
|
|
arrt := AttributesTransExt(k)
|
|
role.Property[arrt] += v
|
|
if k == comm.Hp {
|
|
role.Currhp += v
|
|
}
|
|
}
|
|
for k, v := range hero.HoroscopeProperty {
|
|
arrt := AttributesTransExt(k)
|
|
role.Property[arrt] += v
|
|
if k == comm.Hp {
|
|
role.Currhp += v
|
|
}
|
|
}
|
|
if hero.SuiteId != 0 { //主套装
|
|
if suit, err := this.module.configure.Getequipsuit(hero.SuiteId); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ConfigNoFound,
|
|
Title: pb.ErrorCode_ConfigNoFound.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
} else {
|
|
role.MainSuitSkill = suit.Skill
|
|
}
|
|
}
|
|
if hero.SuiteExtId != 0 { //副套装
|
|
if suit, err := this.module.configure.Getequipsuit(hero.SuiteExtId); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ConfigNoFound,
|
|
Title: pb.ErrorCode_ConfigNoFound.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
} else {
|
|
role.SubSuitSkill = suit.Skill
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
//创建怪物阵营
|
|
func (this *modelBattleComp) createMasterRoles(comp, wheel int, fid int32) (captain int32, roles []*pb.BattleRole, errdata *pb.ErrorData) {
|
|
var (
|
|
result []*cfg.GameMonsterFormatData
|
|
err error
|
|
)
|
|
if result, err = this.module.configure.GetMonsterFormat(fid); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ConfigNoFound,
|
|
Title: pb.ErrorCode_ConfigNoFound.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
captain = -1
|
|
roles = make([]*pb.BattleRole, len(result))
|
|
for i, v := range result {
|
|
if v != nil {
|
|
if v.CaptainId == 1 {
|
|
captain = int32(i)
|
|
}
|
|
// if monst, err := this.module.configure.GetMonster(v.Monster); err != nil {
|
|
// errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ConfigNoFound,
|
|
Title: pb.ErrorCode_ConfigNoFound.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
// } else {
|
|
hero := &pb.DBHero{}
|
|
if hero = this.module.ModuleHero.CreateMonster(fmt.Sprintf("%d", v.Heroid), v.Star, v.Lv); hero == nil {
|
|
this.module.Error("on found battle req data",
|
|
log.Field{Key: "HeroId", Value: v.Heroid},
|
|
)
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
}
|
|
return
|
|
} else {
|
|
roles[i] = &pb.BattleRole{
|
|
Tid: int32(comp + wheel*10 + i),
|
|
Oid: hero.Id,
|
|
HeroID: hero.HeroID,
|
|
Pos: int32(i),
|
|
Star: hero.Star,
|
|
Lv: hero.Lv,
|
|
CaptainSkill: hero.CaptainSkill,
|
|
NormalSkill: hero.NormalSkill,
|
|
EquipSkill: hero.EquipSkill,
|
|
Property: make(map[int32]int32),
|
|
Isboos: v.IsBoss,
|
|
Monsterid: v.Heroid,
|
|
}
|
|
|
|
for i, v1 := range roles[i].NormalSkill {
|
|
if i == 0 {
|
|
v1.SkillLv = v.Skill1
|
|
} else if i == 1 {
|
|
v1.SkillLv = v.Skill2
|
|
} else {
|
|
v1.SkillLv = v.Skill3
|
|
}
|
|
}
|
|
for _, v := range v.Newskill {
|
|
roles[i].EquipSkill = append(roles[i].EquipSkill, &pb.SkillData{
|
|
SkillID: v,
|
|
SkillLv: 1,
|
|
})
|
|
}
|
|
if v.Equip4 != 0 {
|
|
if suit, err := this.module.configure.Getequipsuit(v.Equip4); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ConfigNoFound,
|
|
Title: pb.ErrorCode_ConfigNoFound.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
} else {
|
|
roles[i].MainSuitSkill = suit.Skill
|
|
}
|
|
}
|
|
if v.Equip2 != 0 {
|
|
if suit, err := this.module.configure.Getequipsuit(v.Equip2); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ConfigNoFound,
|
|
Title: pb.ErrorCode_ConfigNoFound.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
} else {
|
|
roles[i].SubSuitSkill = suit.Skill
|
|
}
|
|
}
|
|
hero.Property[comm.Hp] = int32(float32(hero.Property[comm.Hp]) * v.Hppro)
|
|
hero.Property[comm.Atk] = int32(float32(hero.Property[comm.Atk]) * v.Atkpro)
|
|
hero.Property[comm.Def] = int32(float32(hero.Property[comm.Def]) * v.Defpro)
|
|
hero.Property[comm.Speed] = v.Speed
|
|
for k, v := range hero.Property {
|
|
arrt := AttributesTransBase(k)
|
|
roles[i].Property[arrt] = v
|
|
}
|
|
roles[i].Currhp = hero.Property[comm.Hp]
|
|
// }
|
|
}
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
//校验队长技是否激活 暂时不启用
|
|
func (this *modelBattleComp) checkBattlereadyCapskill(leadpos int32, heros []*pb.DBHero) (ok bool) {
|
|
// if leadpos < 0 || leadpos > 5 {
|
|
ok = true
|
|
return
|
|
// }
|
|
var (
|
|
conf []*cfg.GameHeroData
|
|
caprule *cfg.GameBattleready_capskillData
|
|
err error
|
|
)
|
|
if heros[leadpos] == nil {
|
|
ok = true
|
|
return
|
|
}
|
|
conf = make([]*cfg.GameHeroData, len(heros))
|
|
for i, v := range heros {
|
|
if v != nil {
|
|
conf[i], _ = this.module.configure.GetHeroConfig(v.HeroID)
|
|
}
|
|
}
|
|
if caprule, err = this.module.configure.GetBattlereadyCapskill(conf[leadpos].Capskillrule); err != nil {
|
|
this.module.Errorln(err)
|
|
ok = false
|
|
return
|
|
}
|
|
if len(caprule.Lv) == 2 { //等级校验
|
|
n := 0
|
|
for _, v := range heros {
|
|
if v != nil && v.Lv >= caprule.Lv[0] {
|
|
n++
|
|
}
|
|
}
|
|
if n < int(caprule.Lv[1]) {
|
|
ok = false
|
|
return
|
|
}
|
|
}
|
|
if len(caprule.Start) == 2 { //星级校验
|
|
n := 0
|
|
for _, v := range heros {
|
|
if v != nil && v.Star >= caprule.Start[0] {
|
|
n++
|
|
}
|
|
}
|
|
if n < int(caprule.Start[1]) {
|
|
ok = false
|
|
return
|
|
}
|
|
}
|
|
|
|
if len(caprule.Race) == 2 { //阵营校验
|
|
n := 0
|
|
for _, v := range conf {
|
|
if v != nil && v.Race == caprule.Race[0] {
|
|
n++
|
|
}
|
|
}
|
|
if n < int(caprule.Race[1]) {
|
|
ok = false
|
|
return
|
|
}
|
|
}
|
|
|
|
if len(caprule.Heroid) > 0 { //阵营校验
|
|
|
|
for _, v := range caprule.Heroid {
|
|
iskeep := false
|
|
for _, v1 := range heros {
|
|
if v1 != nil && v1.HeroID == v {
|
|
iskeep = true
|
|
}
|
|
}
|
|
if !iskeep {
|
|
ok = false
|
|
return
|
|
}
|
|
}
|
|
|
|
}
|
|
return
|
|
}
|
|
|
|
//获取熊猫buff
|
|
func (this *modelBattleComp) getGlobalBuff(uid string) (buff *cfg.GamePandamasBuffData, ok bool) {
|
|
var (
|
|
userex *pb.DBUserExpand
|
|
err error
|
|
)
|
|
if userex, err = this.module.ModuleUser.GetUserExpand(uid); err != nil {
|
|
ok = false
|
|
return
|
|
}
|
|
if userex.Globalbuff != 0 {
|
|
if buff, err = this.module.configure.getPandamasBuff(userex.Globalbuff); err != nil {
|
|
ok = false
|
|
return
|
|
}
|
|
ok = true
|
|
}
|
|
return
|
|
}
|