From 9507b8ceaab6bf8c406cceca6301cb7655827945 Mon Sep 17 00:00:00 2001 From: liwei <2211068034@qq.com> Date: Fri, 28 Jul 2023 12:00:30 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/battle/configure.go | 19 +++++ modules/battle/modelBattle.go | 135 ++++++++++++---------------------- modules/battle/module.go | 81 +++++++++++++++++--- 3 files changed, 136 insertions(+), 99 deletions(-) diff --git a/modules/battle/configure.go b/modules/battle/configure.go index 54ff3f637..5f859f9d8 100644 --- a/modules/battle/configure.go +++ b/modules/battle/configure.go @@ -63,6 +63,25 @@ func (this *configureComp) Init(service core.IService, module core.IModule, comp return } +func (this *configureComp) GetBattleReady(id int32) (conf *cfg.GameBattleReadyData, err error) { + var ( + v interface{} + ok bool + ) + + if v, err = this.GetConfigure(game_battleready); err != nil { + this.module.Errorln(err) + return + } else { + if conf, ok = v.(*cfg.GameBattleReady).GetDataMap()[id]; !ok { + err = fmt.Errorf("not found:%d ", id) + this.module.Errorln(err) + return + } + } + return +} + // 查询阵容表 func (this *configureComp) GetMonsterFormat(id int32) (result []*cfg.GameMonsterFormatData, err error) { this.mformatlock.RLock() diff --git a/modules/battle/modelBattle.go b/modules/battle/modelBattle.go index 266ca4a92..2b24c68d5 100644 --- a/modules/battle/modelBattle.go +++ b/modules/battle/modelBattle.go @@ -43,7 +43,7 @@ func (this *modelBattleComp) queryrecord(oid string) (record *pb.DBBattleRecord, } // 创建pve 战斗记录 -func (this *modelBattleComp) createeve(session comm.IUserSession, conn *db.DBConn, btype pb.BattleType, req *pb.BattleEVEReq) (record *pb.DBBattleRecord, errdata *pb.ErrorData) { +func (this *modelBattleComp) createeve(session comm.IUserSession, conn *db.DBConn, btype pb.BattleType, req *pb.BattleEVEReq, conf *cfg.GameBattleReadyData) (record *pb.DBBattleRecord, errdata *pb.ErrorData) { record = &pb.DBBattleRecord{ Id: primitive.NewObjectID().Hex(), Title: req.Title, @@ -53,7 +53,7 @@ func (this *modelBattleComp) createeve(session comm.IUserSession, conn *db.DBCon RedCompId: session.GetUserId(), BlueCompId: "", Buleflist: make([]*pb.DBBattleFormt, len(req.Buleformat)), - Tasks: make([]int32, 0), + Tasks: conf.BattleEvents, } var ( battletas *cfg.GameBattletasktestingData @@ -88,13 +88,6 @@ func (this *modelBattleComp) createeve(session comm.IUserSession, conn *db.DBCon if record.Redflist[0].Team[i], errdata = 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 } @@ -142,48 +135,20 @@ func (this *modelBattleComp) createeve(session comm.IUserSession, conn *db.DBCon // } } } - if req.Sysformat != nil && len(req.Sysformat) > 0 { - for i, v := range req.Sysformat { - if v == 0 { - continue - } - if captain, masters, errdata = 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 conf.DefaultHero != 0 { + if captain, masters, errdata = this.createMasterRoles(100, 0, conf.DefaultHero); errdata != nil { + return + } + record.Redflist[0].Systeam = masters + if record.Redflist[0].Leadpos == -1 && captain != -1 { + record.Redflist[0].Leadpos = captain } } - if req.Backupformat != nil && len(req.Backupformat) > 0 { - for i, v := range req.Backupformat { - if v == 0 { - continue - } - if captain, masters, errdata = 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 - // } - // } - // } - // } + if conf.AssistTeam != 0 { + if captain, masters, errdata = this.createMasterRoles(100, 0, conf.AssistTeam); errdata != nil { + return } + record.Redflist[0].Backupteam = masters } } else { record.Redflist = make([]*pb.DBBattleFormt, len(req.Sysformat)) @@ -195,15 +160,6 @@ func (this *modelBattleComp) createeve(session comm.IUserSession, conn *db.DBCon 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 { @@ -211,15 +167,6 @@ func (this *modelBattleComp) createeve(session comm.IUserSession, conn *db.DBCon 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 - // } - // } - // } - // } } } } @@ -237,10 +184,11 @@ func (this *modelBattleComp) createeve(session comm.IUserSession, conn *db.DBCon } // 创建pve 战斗记录 -func (this *modelBattleComp) createpve(session comm.IUserSession, conn *db.DBConn, btype pb.BattleType, req *pb.BattlePVEReq) (record *pb.DBBattleRecord, errdata *pb.ErrorData) { +func (this *modelBattleComp) createpve(session comm.IUserSession, conn *db.DBConn, btype pb.BattleType, req *pb.BattlePVEReq, conf *cfg.GameBattleReadyData) (record *pb.DBBattleRecord, errdata *pb.ErrorData) { var ( - heros []*pb.DBHero = make([]*pb.DBHero, 5) - // buff *cfg.GamePandamasBuffData + heros []*pb.DBHero = make([]*pb.DBHero, 5) + captain int32 + masters []*pb.BattleRole ) record = &pb.DBBattleRecord{ Id: primitive.NewObjectID().Hex(), @@ -252,13 +200,13 @@ func (this *modelBattleComp) createpve(session comm.IUserSession, conn *db.DBCon Redflist: make([]*pb.DBBattleFormt, 1), BlueCompId: "", Buleflist: make([]*pb.DBBattleFormt, len(req.Mformat)), + Tasks: conf.BattleEvents, } 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 != "" { @@ -274,13 +222,6 @@ func (this *modelBattleComp) createpve(session comm.IUserSession, conn *db.DBCon if record.Redflist[0].Team[i], errdata = 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 } @@ -327,17 +268,31 @@ func (this *modelBattleComp) createpve(session comm.IUserSession, conn *db.DBCon // } } } - if ok := this.checkBattlereadyCapskill(req.Format.Leadpos, heros); !ok { - errdata = &pb.ErrorData{ - Code: pb.ErrorCode_BattleCapskillCheckFailed, - Title: pb.ErrorCode_BattleCapskillCheckFailed.ToString(), + + if conf.DefaultHero != 0 { + if captain, masters, errdata = this.createMasterRoles(100, 0, conf.DefaultHero); errdata != nil { + return + } + record.Redflist[0].Systeam = masters + if record.Redflist[0].Leadpos == -1 && captain != -1 { + record.Redflist[0].Leadpos = captain } - return } - var ( - captain int32 - masters []*pb.BattleRole - ) + if conf.AssistTeam != 0 { + if captain, masters, errdata = this.createMasterRoles(100, 0, conf.AssistTeam); errdata != nil { + return + } + record.Redflist[0].Backupteam = masters + } + //队长级 弃用 + // if ok := this.checkBattlereadyCapskill(req.Format.Leadpos, heros); !ok { + // errdata = &pb.ErrorData{ + // Code: pb.ErrorCode_BattleCapskillCheckFailed, + // Title: pb.ErrorCode_BattleCapskillCheckFailed.ToString(), + // } + // return + // } + for i, v := range req.Mformat { if captain, masters, errdata = this.createMasterRoles(200, i, v); errdata != nil { return @@ -351,7 +306,7 @@ func (this *modelBattleComp) createpve(session comm.IUserSession, conn *db.DBCon } // 创建pve 战斗记录 -func (this *modelBattleComp) createpvb(session comm.IUserSession, conn *db.DBConn, btype pb.BattleType, req *pb.BattlePVBReq) (record *pb.DBBattleRecord, errdata *pb.ErrorData) { +func (this *modelBattleComp) createpvb(session comm.IUserSession, conn *db.DBConn, btype pb.BattleType, req *pb.BattlePVBReq, conf *cfg.GameBattleReadyData) (record *pb.DBBattleRecord, errdata *pb.ErrorData) { var ( // buff *cfg.GamePandamasBuffData ) @@ -468,7 +423,7 @@ func (this *modelBattleComp) createpvb(session comm.IUserSession, conn *db.DBCon } // 创建pvp 战斗请求 -func (this *modelBattleComp) createpvp(session comm.IUserSession, conn *db.DBConn, btype pb.BattleType, req *pb.BattlePVPReq) (record *pb.DBBattleRecord, errdata *pb.ErrorData) { +func (this *modelBattleComp) createpvp(session comm.IUserSession, conn *db.DBConn, btype pb.BattleType, req *pb.BattlePVPReq, conf *cfg.GameBattleReadyData) (record *pb.DBBattleRecord, errdata *pb.ErrorData) { record = &pb.DBBattleRecord{ Id: primitive.NewObjectID().Hex(), Title: req.Title, @@ -529,7 +484,7 @@ func (this *modelBattleComp) createpvp(session comm.IUserSession, conn *db.DBCon } // 创建pvp 战斗请求 -func (this *modelBattleComp) creatertpvp(redmodel, bluemodel *db.DBModel, btype pb.BattleType, req *pb.BattleRTPVPReq) (record *pb.DBBattleRecord, errdata *pb.ErrorData) { +func (this *modelBattleComp) creatertpvp(redmodel, bluemodel *db.DBModel, btype pb.BattleType, req *pb.BattleRTPVPReq, conf *cfg.GameBattleReadyData) (record *pb.DBBattleRecord, errdata *pb.ErrorData) { record = &pb.DBBattleRecord{ Id: primitive.NewObjectID().Hex(), Title: req.Title, @@ -609,7 +564,7 @@ func (this *modelBattleComp) creatertpvp(redmodel, bluemodel *db.DBModel, btype } // 创建pve 战斗记录 -func (this *modelBattleComp) createlpve(session comm.IUserSession, conn *db.DBConn, btype pb.BattleType, req *pb.BattleLPVEReq) (record *pb.DBBattleRecord, errdata *pb.ErrorData) { +func (this *modelBattleComp) createlpve(session comm.IUserSession, conn *db.DBConn, btype pb.BattleType, req *pb.BattleLPVEReq, conf *cfg.GameBattleReadyData) (record *pb.DBBattleRecord, errdata *pb.ErrorData) { var ( heros []*pb.DBHero = make([]*pb.DBHero, 5) // buff *cfg.GamePandamasBuffData diff --git a/modules/battle/module.go b/modules/battle/module.go index 5bbaeb01e..e10ab3f6b 100644 --- a/modules/battle/module.go +++ b/modules/battle/module.go @@ -8,6 +8,7 @@ import ( "go_dreamfactory/lego/sys/log" "go_dreamfactory/modules" "go_dreamfactory/pb" + cfg "go_dreamfactory/sys/configure/structs" "go_dreamfactory/sys/db" "time" ) @@ -96,6 +97,7 @@ func (this *Battle) QueryBattleRecord(oid string) (errdata *pb.ErrorData, record // 创建pve战斗 func (this *Battle) CreateEveBattle(session comm.IUserSession, req *pb.BattleEVEReq) (errdata *pb.ErrorData, record *pb.DBBattleRecord) { var ( + conf *cfg.GameBattleReadyData conn *db.DBConn err error ) @@ -114,7 +116,16 @@ func (this *Battle) CreateEveBattle(session comm.IUserSession, req *pb.BattleEVE return } - if record, errdata = this.modelBattle.createeve(session, conn, pb.BattleType_eve, req); errdata != nil { + if conf, err = this.configure.GetBattleReady(req.Rulesid); err != nil { + errdata = &pb.ErrorData{ + Code: pb.ErrorCode_ConfigNoFound, + Title: pb.ErrorCode_ConfigNoFound.ToString(), + Message: err.Error(), + } + return + } + + if record, errdata = this.modelBattle.createeve(session, conn, pb.BattleType_eve, req, conf); errdata != nil { return } return @@ -123,6 +134,7 @@ func (this *Battle) CreateEveBattle(session comm.IUserSession, req *pb.BattleEVE // 创建pve战斗 func (this *Battle) CreatePveBattle(session comm.IUserSession, req *pb.BattlePVEReq) (errdata *pb.ErrorData, record *pb.DBBattleRecord) { var ( + conf *cfg.GameBattleReadyData conn *db.DBConn err error ) @@ -140,6 +152,14 @@ func (this *Battle) CreatePveBattle(session comm.IUserSession, req *pb.BattlePVE this.Errorf("session:%v err:", session, err) return } + if conf, err = this.configure.GetBattleReady(req.Rulesid); err != nil { + errdata = &pb.ErrorData{ + Code: pb.ErrorCode_ConfigNoFound, + Title: pb.ErrorCode_ConfigNoFound.ToString(), + Message: err.Error(), + } + return + } if req.Format == nil || req.Format.Format == nil || len(req.Format.Format) != 5 { errdata = &pb.ErrorData{ Code: pb.ErrorCode_ReqParameterError, @@ -157,13 +177,12 @@ func (this *Battle) CreatePveBattle(session comm.IUserSession, req *pb.BattlePVE for _, v := range req.Format.Friendformat { if v != "" { flag = true - // this.ModuleBuried.SendToRtask(session, comm.Rtype108, 1) go this.ModuleBuried.TriggerBuried(session.Clone(), comm.GetBuriedParam(comm.Rtype108, 1)) break } } - if record, errdata = this.modelBattle.createpve(session, conn, pb.BattleType_pve, req); errdata != nil { + if record, errdata = this.modelBattle.createpve(session, conn, pb.BattleType_pve, req, conf); errdata != nil { return } if flag { @@ -175,6 +194,7 @@ func (this *Battle) CreatePveBattle(session comm.IUserSession, req *pb.BattlePVE // 创建pve战斗 func (this *Battle) CreatePvbBattle(session comm.IUserSession, req *pb.BattlePVBReq) (errdata *pb.ErrorData, record *pb.DBBattleRecord) { var ( + conf *cfg.GameBattleReadyData conn *db.DBConn err error ) @@ -199,7 +219,15 @@ func (this *Battle) CreatePvbBattle(session comm.IUserSession, req *pb.BattlePVB } return } - if record, errdata = this.modelBattle.createpvb(session, conn, pb.BattleType_pvb, req); errdata != nil { + if conf, err = this.configure.GetBattleReady(req.Rulesid); err != nil { + errdata = &pb.ErrorData{ + Code: pb.ErrorCode_ConfigNoFound, + Title: pb.ErrorCode_ConfigNoFound.ToString(), + Message: err.Error(), + } + return + } + if record, errdata = this.modelBattle.createpvb(session, conn, pb.BattleType_pvb, req, conf); errdata != nil { return } return @@ -208,6 +236,7 @@ func (this *Battle) CreatePvbBattle(session comm.IUserSession, req *pb.BattlePVB // 创建pve战斗 func (this *Battle) CreatePvpBattle(session comm.IUserSession, req *pb.BattlePVPReq) (errdata *pb.ErrorData, record *pb.DBBattleRecord) { var ( + conf *cfg.GameBattleReadyData conn *db.DBConn err error ) @@ -225,7 +254,15 @@ func (this *Battle) CreatePvpBattle(session comm.IUserSession, req *pb.BattlePVP this.Errorf("session:%v err:", session, err) return } - if record, errdata = this.modelBattle.createpvp(session, conn, pb.BattleType_pvp, req); errdata != nil { + if conf, err = this.configure.GetBattleReady(req.Rulesid); err != nil { + errdata = &pb.ErrorData{ + Code: pb.ErrorCode_ConfigNoFound, + Title: pb.ErrorCode_ConfigNoFound.ToString(), + Message: err.Error(), + } + return + } + if record, errdata = this.modelBattle.createpvp(session, conn, pb.BattleType_pvp, req, conf); errdata != nil { return } return @@ -234,6 +271,7 @@ func (this *Battle) CreatePvpBattle(session comm.IUserSession, req *pb.BattlePVP // 只有跨服环境下才可使用 func (this *Battle) CreateRtPvpBattle(req *pb.BattleRTPVPReq) (errdata *pb.ErrorData, record *pb.DBBattleRecord) { var ( + conf *cfg.GameBattleReadyData redmodel *db.DBModel bluemodel *db.DBModel err error @@ -261,7 +299,15 @@ func (this *Battle) CreateRtPvpBattle(req *pb.BattleRTPVPReq) (errdata *pb.Error } return } - if record, errdata = this.modelBattle.creatertpvp(redmodel, bluemodel, pb.BattleType_rtpvp, req); errdata != nil { + if conf, err = this.configure.GetBattleReady(req.Rulesid); err != nil { + errdata = &pb.ErrorData{ + Code: pb.ErrorCode_ConfigNoFound, + Title: pb.ErrorCode_ConfigNoFound.ToString(), + Message: err.Error(), + } + return + } + if record, errdata = this.modelBattle.creatertpvp(redmodel, bluemodel, pb.BattleType_rtpvp, req, conf); errdata != nil { return } return @@ -270,6 +316,7 @@ func (this *Battle) CreateRtPvpBattle(req *pb.BattleRTPVPReq) (errdata *pb.Error // 创建连续战斗 func (this *Battle) CreateLPVEBattle(session comm.IUserSession, req *pb.BattleLPVEReq) (errdata *pb.ErrorData, record *pb.DBBattleRecord) { var ( + conf *cfg.GameBattleReadyData conn *db.DBConn err error ) @@ -309,8 +356,15 @@ func (this *Battle) CreateLPVEBattle(session comm.IUserSession, req *pb.BattleLP break } } - - if record, errdata = this.modelBattle.createlpve(session, conn, pb.BattleType_lpev, req); errdata != nil { + if conf, err = this.configure.GetBattleReady(req.Rulesid); err != nil { + errdata = &pb.ErrorData{ + Code: pb.ErrorCode_ConfigNoFound, + Title: pb.ErrorCode_ConfigNoFound.ToString(), + Message: err.Error(), + } + return + } + if record, errdata = this.modelBattle.createlpve(session, conn, pb.BattleType_lpev, req, conf); errdata != nil { return } if flag { @@ -474,6 +528,7 @@ func (this *Battle) CheckBattleReport(session comm.IUserSession, report *pb.Batt // 创建石阵秘境战斗 func (this *Battle) CreateStoneBattle(session comm.IUserSession, req *pb.BattlePVEReq) (errdata *pb.ErrorData, record *pb.DBBattleRecord) { var ( + conf *cfg.GameBattleReadyData conn *db.DBConn err error ) @@ -504,6 +559,14 @@ func (this *Battle) CreateStoneBattle(session comm.IUserSession, req *pb.BattleP Title: pb.ErrorCode_ReqParameterError.ToString(), } } + if conf, err = this.configure.GetBattleReady(req.Rulesid); err != nil { + errdata = &pb.ErrorData{ + Code: pb.ErrorCode_ConfigNoFound, + Title: pb.ErrorCode_ConfigNoFound.ToString(), + Message: err.Error(), + } + return + } var flag bool for _, v := range req.Format.Friendformat { if v != "" { @@ -514,7 +577,7 @@ func (this *Battle) CreateStoneBattle(session comm.IUserSession, req *pb.BattleP } } - if record, errdata = this.modelBattle.createpve(session, conn, pb.BattleType_pve, req); errdata != nil { + if record, errdata = this.modelBattle.createpve(session, conn, pb.BattleType_pve, req, conf); errdata != nil { return } if flag {