78 lines
1.9 KiB
Go
78 lines
1.9 KiB
Go
package sociaty
|
|
|
|
import (
|
|
"errors"
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/sys/log"
|
|
"go_dreamfactory/pb"
|
|
)
|
|
|
|
// 开始挑战
|
|
func (this *apiComp) ChallengestartCheck(session comm.IUserSession, req *pb.SociatyBChallengeStartReq) (errdata *pb.ErrorData) {
|
|
return
|
|
}
|
|
|
|
func (this *apiComp) Challengestart(session comm.IUserSession, req *pb.SociatyBChallengeStartReq) (errdata *pb.ErrorData) {
|
|
if errdata = this.ChallengestartCheck(session, req); errdata != nil {
|
|
return
|
|
}
|
|
|
|
uid := session.GetUserId()
|
|
sociaty := this.module.modelSociaty.getUserSociaty(uid)
|
|
if sociaty == nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_SociatyNoFound,
|
|
Title: pb.ErrorCode_SociatyNoFound.ToString(),
|
|
}
|
|
|
|
this.module.Error("当前玩家所在的公会未找到", log.Field{Key: "uid", Value: uid})
|
|
return
|
|
}
|
|
//校验挑战券
|
|
userEx, err := this.module.ModuleUser.GetUserExpand(uid)
|
|
if err != nil {
|
|
this.module.Error("GetRemoteUserExpand",
|
|
log.Field{Key: "uid", Value: uid},
|
|
log.Field{Key: "err", Value: err.Error()},
|
|
)
|
|
return
|
|
}
|
|
if userEx.SociatyTicket <= 0 {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_SociatyTicketsNoEnough,
|
|
Title: pb.ErrorCode_SociatyTicketsNoEnough.ToString(),
|
|
}
|
|
return
|
|
}
|
|
|
|
//校验赛季时间
|
|
if this.module.modelSociatyBoss.sportsIsFinished() {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_SociatySportsEnd,
|
|
Title: pb.ErrorCode_SociatySportsEnd.ToString(),
|
|
}
|
|
return
|
|
}
|
|
|
|
// 开始挑战
|
|
if err := this.module.modelSociatyBoss.challengestart(session, sociaty); err != nil {
|
|
var customErr = new(comm.CustomError)
|
|
if errors.As(err, &customErr) {
|
|
code := customErr.Code
|
|
errdata = &pb.ErrorData{
|
|
Code: code,
|
|
Title: code.ToString(),
|
|
}
|
|
return
|
|
}
|
|
}
|
|
|
|
rsp := &pb.SociatyBChallengeStartResp{
|
|
SociatyId: sociaty.Id,
|
|
Uid: uid,
|
|
}
|
|
|
|
session.SendMsg(string(this.module.GetType()), SociatySubTypeChallengestart, rsp)
|
|
return
|
|
}
|