83 lines
2.2 KiB
Go
83 lines
2.2 KiB
Go
package worldtask
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/sys/log"
|
|
"go_dreamfactory/pb"
|
|
|
|
"google.golang.org/protobuf/proto"
|
|
)
|
|
|
|
// 战斗开始
|
|
func (this *apiComp) BattlestartCheck(session comm.IUserSession, req *pb.WorldtaskBattleStartReq) (code pb.ErrorCode) {
|
|
if req.BattleConfId == 0 || req.Battle == nil {
|
|
this.module.Error("世界任务战斗开始参数错误",
|
|
log.Field{Key: "uid", Value: session.GetUserId()},
|
|
log.Field{Key: "params", Value: req.String()},
|
|
)
|
|
code = pb.ErrorCode_ReqParameterError
|
|
}
|
|
return
|
|
}
|
|
|
|
func (this *apiComp) Battlestart(session comm.IUserSession, req *pb.WorldtaskBattleStartReq) (code pb.ErrorCode, data proto.Message) {
|
|
if code = this.BattlestartCheck(session, req); code != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
uid := session.GetUserId()
|
|
battleConf, err := this.module.configure.getWorldtaskBattleById(req.BattleConfId)
|
|
if err != nil || battleConf == nil {
|
|
code = pb.ErrorCode_ConfigNoFound
|
|
log.Error("战斗配置未找到",
|
|
log.Field{Key: "uid", Value: uid},
|
|
log.Field{Key: "battleConfId", Value: req.BattleConfId},
|
|
)
|
|
return
|
|
}
|
|
|
|
iBattle, err := this.module.service.GetModule(comm.ModuleBattle)
|
|
if err != nil {
|
|
code = pb.ErrorCode_SystemError
|
|
return
|
|
}
|
|
|
|
if b, y := iBattle.(comm.IBattle); y {
|
|
var (
|
|
record *pb.DBBattleRecord
|
|
resp *pb.WorldtaskBattleStartResp
|
|
)
|
|
code, record = b.CreateEveBattle(session, &pb.BattleEVEReq{
|
|
Ptype: pb.PlayType_rtask,
|
|
Format: req.Battle,
|
|
// Sysformat: []int32{battleConf.DefaultHero},
|
|
// Backupformat: []int32{battleConf.AssistTeam},
|
|
Buleformat: battleConf.FormatList,
|
|
})
|
|
|
|
if code != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
|
|
if record != nil {
|
|
resp = &pb.WorldtaskBattleStartResp{
|
|
Info: &pb.BattleInfo{
|
|
Id: record.Id,
|
|
Rulesid: battleConf.BattleReadyID,
|
|
Btype: record.Btype,
|
|
Ptype: record.Ptype,
|
|
RedCompId: record.RedCompId,
|
|
Redflist: record.Redflist,
|
|
BlueCompId: record.BlueCompId,
|
|
Buleflist: record.Buleflist,
|
|
Tasks: battleConf.EventList,
|
|
},
|
|
}
|
|
}
|
|
|
|
if err := session.SendMsg(string(this.module.GetType()), WorldtaskBattleStart, resp); err != nil {
|
|
code = pb.ErrorCode_SystemError
|
|
}
|
|
}
|
|
return
|
|
}
|