112 lines
3.1 KiB
Go
112 lines
3.1 KiB
Go
package parkour
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
)
|
|
|
|
//参数校验
|
|
func (this *apiComp) RaceMatchCheck(session comm.IUserSession, req *pb.ParkourRaceMatchReq) (errdata *pb.ErrorData) {
|
|
if session.GetUserId() != req.Captainid {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
///匹配请求
|
|
func (this *apiComp) RaceMatch(session comm.IUserSession, req *pb.ParkourRaceMatchReq) (errdata *pb.ErrorData) {
|
|
var (
|
|
team *pb.DBParkour
|
|
tuser *pb.DBUser
|
|
mount *cfg.GameBuzkashiMountData
|
|
users []string
|
|
err error
|
|
)
|
|
if errdata = this.RaceMatchCheck(session, req); errdata != nil {
|
|
return
|
|
}
|
|
if team, err = this.module.parkourComp.queryinfo(session.GetUserId()); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Title: pb.ErrorCode_DBError.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
if team.Captainid != "" && team.Captainid != session.GetUserId() {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
}
|
|
return
|
|
}
|
|
if team.Captainid == "" { //为组队情况
|
|
team.Captainid = team.Uid
|
|
team.State = pb.RaceTeamState_teaming
|
|
if tuser = this.module.ModuleUser.GetUser(session.GetUserId()); tuser == nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_SystemError,
|
|
Title: pb.ErrorCode_SystemError.ToString(),
|
|
}
|
|
return
|
|
}
|
|
if mount, err = this.module.configure.getGameBuzkashiMount(team.Dfmount); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ConfigNoFound,
|
|
Title: pb.ErrorCode_ConfigNoFound.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
team.Member = append(team.Member, &pb.DBRaceMember{Uid: tuser.Uid, Name: tuser.Name, Avatar: tuser.Avatar, Lv: tuser.Lv, Mount: team.Dfmount, Maxhp: mount.Hp})
|
|
if err = this.module.parkourComp.Change(team.Captainid, map[string]interface{}{
|
|
"state": team.State,
|
|
"captainid": team.Captainid,
|
|
"member": team.Member,
|
|
}); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Title: pb.ErrorCode_DBError.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
}
|
|
|
|
if err = this.module.match(team); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Title: pb.ErrorCode_DBError.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
|
|
users = make([]string, len(team.Member))
|
|
for i, v := range team.Member {
|
|
if !v.Isai {
|
|
users[i] = v.Uid
|
|
if err = this.module.parkourComp.Change(v.Uid, map[string]interface{}{
|
|
"state": pb.RaceTeamState_matching,
|
|
}); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Title: pb.ErrorCode_DBError.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
}
|
|
|
|
}
|
|
this.module.SendMsgToUsers(string(this.module.GetType()), "racematchstart",
|
|
&pb.ParkourRaceMatchStartPush{Team: team}, users...)
|
|
|
|
session.SendMsg(string(this.module.GetType()), "racematch", &pb.ParkourRaceMatchResp{})
|
|
return
|
|
}
|