97 lines
2.5 KiB
Go
97 lines
2.5 KiB
Go
package worldtask
|
|
|
|
import (
|
|
"fmt"
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/sys/log"
|
|
"go_dreamfactory/pb"
|
|
)
|
|
|
|
// 战斗开始
|
|
func (this *apiComp) BattlestartCheck(session comm.IUserSession, req *pb.WorldtaskBattleStartReq) (errdata *pb.ErrorData) {
|
|
if req.BattleConfId == 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(),
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
func (this *apiComp) Battlestart(session comm.IUserSession, req *pb.WorldtaskBattleStartReq) (errdata *pb.ErrorData) {
|
|
if errdata = this.BattlestartCheck(session, req); errdata != nil {
|
|
return
|
|
}
|
|
resp := &pb.WorldtaskBattleStartResp{}
|
|
|
|
battleConf, err := this.module.configure.getWorldtaskBattleById(req.BattleConfId)
|
|
if err != nil || battleConf == nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ConfigNoFound,
|
|
Title: pb.ErrorCode_ConfigNoFound.ToString(),
|
|
Message: fmt.Sprintf("战斗配置未找到 %v", req.BattleConfId),
|
|
}
|
|
return
|
|
}
|
|
|
|
iBattle, err := this.module.service.GetModule(comm.ModuleBattle)
|
|
if err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_SystemError,
|
|
Title: pb.ErrorCode_SystemError.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
|
|
if b, y := iBattle.(comm.IBattle); y {
|
|
var (
|
|
record *pb.DBBattleRecord
|
|
)
|
|
errdata, record = b.CreateEveBattle(session, &pb.BattleEVEReq{
|
|
Ptype: pb.PlayType_rtask,
|
|
Format: req.Battle,
|
|
Buleformat: battleConf.FormatList,
|
|
})
|
|
|
|
if errdata != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ExternalModule,
|
|
Title: pb.ErrorCode_ExternalModule.ToString(),
|
|
Message: "创建Eve战斗失败",
|
|
}
|
|
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,
|
|
},
|
|
}
|
|
} else {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_WorldtaskBattleCreate,
|
|
Title: pb.ErrorCode_WorldtaskBattleCreate.ToString(),
|
|
Message: "战斗记录是空",
|
|
}
|
|
return
|
|
}
|
|
|
|
this.sendMsg(session, WorldtaskBattleStart, resp)
|
|
}
|
|
return
|
|
}
|