69 lines
1.4 KiB
Go
69 lines
1.4 KiB
Go
package parkour
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
)
|
|
|
|
//参数校验
|
|
func (this *apiComp) ReadyCheck(session comm.IUserSession, req *pb.ParkourReadyReq) (code pb.ErrorCode) {
|
|
return
|
|
}
|
|
|
|
///匹配请求
|
|
func (this *apiComp) Ready(session comm.IUserSession, req *pb.ParkourReadyReq) (code pb.ErrorCode, data *pb.ErrorData) {
|
|
var (
|
|
race *RaceItem
|
|
ok bool
|
|
isready bool
|
|
)
|
|
if code = this.ReadyCheck(session, req); code != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
this.module.lock.RLock()
|
|
race, ok = this.module.battles[req.Battleid]
|
|
this.module.lock.RUnlock()
|
|
if ok {
|
|
race.lock.Lock()
|
|
ok = false
|
|
isready = true
|
|
for _, v := range race.RedMember {
|
|
if v.Uid == session.GetUserId() {
|
|
v.Ready = true
|
|
ok = true
|
|
} else {
|
|
if !v.Ready {
|
|
isready = false
|
|
}
|
|
}
|
|
}
|
|
for _, v := range race.BuleMember {
|
|
if v.Uid == session.GetUserId() {
|
|
v.Ready = true
|
|
ok = true
|
|
} else {
|
|
if !v.Ready {
|
|
isready = false
|
|
}
|
|
}
|
|
}
|
|
if !ok {
|
|
code = pb.ErrorCode_ReqParameterError
|
|
race.lock.Unlock()
|
|
return
|
|
}
|
|
race.lock.Unlock()
|
|
this.module.lock.Lock()
|
|
this.module.battles[req.Battleid] = race
|
|
this.module.lock.Unlock()
|
|
if isready {
|
|
go this.module.startbattle(req.Battleid)
|
|
}
|
|
} else {
|
|
code = pb.ErrorCode_ReqParameterError
|
|
return
|
|
}
|
|
session.SendMsg(string(this.module.GetType()), "ready", &pb.ParkourReadyResp{})
|
|
return
|
|
}
|