131 lines
3.9 KiB
Go
131 lines
3.9 KiB
Go
package stonehenge
|
|
|
|
import (
|
|
"fmt"
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
)
|
|
|
|
//参数校验
|
|
func (this *apiComp) BattleCheck(session comm.IUserSession, req *pb.StonehengeBattleReq) (errdata *pb.ErrorData) {
|
|
if req.Eventid == 0 {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
///挑战主线关卡
|
|
func (this *apiComp) Battle(session comm.IUserSession, req *pb.StonehengeBattleReq) (errdata *pb.ErrorData) {
|
|
var (
|
|
stone *pb.DBStonehenge
|
|
conf *cfg.GameStoneEventData
|
|
err error
|
|
battleConf *cfg.GameStoneBattleData
|
|
szHero []*pb.BattleRole
|
|
weBuff []*pb.DySkillData // 我方buff
|
|
diBuff []*pb.DySkillData // 敌方buff
|
|
)
|
|
if conf, err = this.module.configure.GetStoneEventDataById(req.Eventid); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ConfigNoFound,
|
|
Title: pb.ErrorCode_ConfigNoFound.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
// 事件校验
|
|
stone = this.module.modelStonehenge.GetStonehengeData(session.GetUserId())
|
|
if v, ok := stone.Rooms.Eventid[req.Eventid]; !ok || v == true { // 不存在该事件
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
Message: fmt.Sprintf("req.Eventid err :%d", req.Eventid),
|
|
}
|
|
return
|
|
}
|
|
if battleConf, err = this.module.configure.GetBattleConfById(conf.Value1); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ConfigNoFound,
|
|
Title: pb.ErrorCode_ConfigNoFound.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
if errdata = this.BattleCheck(session, req); errdata != nil {
|
|
return // 参数校验失败直接返回
|
|
}
|
|
// 优先环境buff
|
|
weBuff = make([]*pb.DySkillData, 0)
|
|
diBuff = make([]*pb.DySkillData, 0)
|
|
if stage := this.module.modelStonehenge.GetStoneBoosData(stone.StageID); stage != nil {
|
|
for _, v := range stage.Mainebuff { // 我方环境buff
|
|
if buff, err := this.module.configure.GetStoneBuffDataById(v); err == nil {
|
|
weBuff = append(weBuff, &pb.DySkillData{
|
|
SkillID: buff.SkillId,
|
|
SkillLv: buff.BuffLevel,
|
|
Param: 0,
|
|
})
|
|
}
|
|
}
|
|
|
|
for _, v := range stage.Enemybuff { // 敌方环境buff
|
|
if buff, err := this.module.configure.GetStoneBuffDataById(v); err == nil {
|
|
diBuff = append(weBuff, &pb.DySkillData{
|
|
SkillID: buff.SkillId,
|
|
SkillLv: buff.BuffLevel,
|
|
Param: 0,
|
|
})
|
|
}
|
|
}
|
|
} else {
|
|
return
|
|
}
|
|
for _, v := range req.Battle.Format {
|
|
if v != "" {
|
|
if v1, ok := stone.Hero[v]; ok {
|
|
v1.BattleBeforeSkill = weBuff
|
|
szHero = append(szHero, v1)
|
|
} else {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ConfigNoFound,
|
|
Title: pb.ErrorCode_ConfigNoFound.ToString(),
|
|
Message: fmt.Sprintf("can't found hero %s", v),
|
|
}
|
|
return
|
|
}
|
|
} else {
|
|
szHero = append(szHero, nil)
|
|
}
|
|
}
|
|
stoneBattle := &pb.StroneBattleReq{
|
|
DiBuff: diBuff,
|
|
Format: battleConf.FormatList,
|
|
Role: szHero,
|
|
Leadpos: req.Battle.Leadpos,
|
|
Btype: pb.BattleType_pve,
|
|
Ptype: pb.PlayType_stone,
|
|
BattleEvents: battleConf.BattleReadyID,
|
|
}
|
|
// 石阵秘境战斗前准备
|
|
// errdata, record := this.module.battle.CreatePveBattle(session, &pb.BattlePVEReq{
|
|
// Rulesid: battleConf.BattleReadyID,
|
|
// Ptype: pb.PlayType_mainline,
|
|
// Title: "",
|
|
// Format: req.Battle,
|
|
// Mformat: battleConf.FormatList,
|
|
// })
|
|
errdata, record := this.module.battle.CreateStoneBattle(session, stoneBattle)
|
|
if errdata != nil {
|
|
return
|
|
}
|
|
session.SendMsg(string(this.module.GetType()), "battle", &pb.StonehengeBattleResp{
|
|
Eventid: req.Eventid,
|
|
Info: &pb.BattleInfo{Id: record.Id, Title: record.Title, Rulesid: battleConf.BattleReadyID, Btype: record.Btype, Ptype: record.Ptype, RedCompId: record.RedCompId, Redflist: record.Redflist, BlueCompId: record.BlueCompId, Buleflist: record.Buleflist},
|
|
})
|
|
return
|
|
}
|