package rtask 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.RtaskBattleStartReq) (code pb.ErrorCode) { if req.BattleConfId == 0 { code = pb.ErrorCode_ReqParameterError } return } func (this *apiComp) BattleStart(session comm.IUserSession, req *pb.RtaskBattleStartReq) (code pb.ErrorCode, data proto.Message) { if code = this.BattleStartCheck(session, req); code != pb.ErrorCode_Success { return } battleConf := this.moduleRtask.configure.getRtaskBattleById(req.BattleConfId) if battleConf == nil { code = pb.ErrorCode_ConfigNoFound log.Errorf("rdtask_battle %v no found", req.BattleConfId) return } iBattle, err := this.moduleRtask.modelRtask.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.RtaskBattleStartResp ) code, record = b.CreatePveBattle(session, &pb.BattlePVEReq{ Ptype: pb.PlayType_mainline, Leadpos: req.Leadpos, Teamids: req.Teamids, Mformat: battleConf.FormatList, }) if code != pb.ErrorCode_Success { return } if record != nil { resp = &pb.RtaskBattleStartResp{ Info: &pb.BattleInfo{ Id: record.Id, Btype: record.Btype, Ptype: record.Ptype, RedCompId: record.RedCompId, Redflist: record.Redflist, BlueCompId: record.BlueCompId, Buleflist: record.Buleflist, }, } } if err := session.SendMsg(string(this.moduleRtask.GetType()), RtaskSubTypeBattleStart, resp); err != nil { code = pb.ErrorCode_SystemError } } return }