123 lines
3.1 KiB
Go
123 lines
3.1 KiB
Go
package island
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/sys/log"
|
|
"go_dreamfactory/pb"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
)
|
|
|
|
// 参数校验
|
|
func (this *apiComp) BattleCheck(session comm.IUserSession, req *pb.IsLandBattleReq) (errdata *pb.ErrorData) {
|
|
if req.Level == 0 || req.Battle == nil {
|
|
this.module.Error("战斗开始参数错误",
|
|
log.Field{Key: "uid", Value: session.GetUserId()},
|
|
log.Field{Key: "params", Value: req.String()},
|
|
)
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
Message: "BattleConfId is 0",
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
// /获取系统公告
|
|
func (this *apiComp) Battle(session comm.IUserSession, req *pb.IsLandBattleReq) (errdata *pb.ErrorData) {
|
|
var (
|
|
info *pb.DBIsland
|
|
conf *cfg.GamePuggsyEventData
|
|
bconf *cfg.GamePuggsyFightData
|
|
heroids []string
|
|
heros []*pb.DBHero
|
|
tempHeros []*pb.DBHero
|
|
record *pb.DBBattleRecord
|
|
err error
|
|
)
|
|
if errdata = this.BattleCheck(session, req); errdata != nil {
|
|
return
|
|
}
|
|
if conf, err = this.module.configure.getGamePuggsyEventData(req.Level); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Title: pb.ErrorCode_DBError.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
if bconf, err = this.module.configure.getGamePuggsyFightData(conf.Value); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Title: pb.ErrorCode_DBError.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
if info, err = this.module.model.getmodel(session.GetUserId()); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
heroids = make([]string, 0)
|
|
for _, v := range req.Battle.Format {
|
|
if v != "" {
|
|
heroids = append(heroids, v)
|
|
}
|
|
}
|
|
|
|
if tempHeros, err = this.module.modelhero.getHeros(session.GetUserId(), heroids); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
if err = this.module.model.compute(info, heros); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ConfigNoFound,
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
|
|
heros = make([]*pb.DBHero, 5)
|
|
for i, v := range req.Battle.Format {
|
|
for _, v1 := range tempHeros {
|
|
if v == v1.Id {
|
|
heros[i] = v1
|
|
}
|
|
}
|
|
}
|
|
|
|
if errdata, record = this.module.battle.CreateHeroPveBattle(session, &pb.BattleHeroPVEReq{
|
|
Rulesid: bconf.BattleReadyID,
|
|
Ptype: pb.PlayType_rtask,
|
|
Mformat: bconf.Boss,
|
|
Redformat: &pb.PVPFormation{
|
|
Uid: session.GetUserId(),
|
|
Leadpos: req.Battle.Leadpos,
|
|
Format: heros,
|
|
},
|
|
}); err != nil {
|
|
return
|
|
}
|
|
session.SendMsg(string(this.module.GetType()), "battle", &pb.StorylineBattleResp{
|
|
Level: req.Level,
|
|
Info: &pb.BattleInfo{
|
|
Id: record.Id,
|
|
Rulesid: bconf.BattleReadyID,
|
|
Btype: record.Btype,
|
|
Ptype: record.Ptype,
|
|
RedCompId: record.RedCompId,
|
|
Redflist: record.Redflist,
|
|
BlueCompId: record.BlueCompId,
|
|
Buleflist: record.Buleflist,
|
|
Tasks: record.Tasks,
|
|
},
|
|
})
|
|
return
|
|
}
|