go_dreamfactory/modules/sociaty/api_cross_challengestart.go
2023-01-14 18:47:14 +08:00

72 lines
1.8 KiB
Go

package sociaty
import (
"errors"
"go_dreamfactory/comm"
"go_dreamfactory/lego/sys/log"
"go_dreamfactory/pb"
"google.golang.org/protobuf/proto"
)
// 开始挑战
func (this *apiComp) ChallengestartCheck(session comm.IUserSession, req *pb.SociatyBChallengeStartReq) (code pb.ErrorCode) {
return
}
func (this *apiComp) Challengestart(session comm.IUserSession, req *pb.SociatyBChallengeStartReq) (code pb.ErrorCode, data proto.Message) {
if code = this.ChallengestartCheck(session, req); code != pb.ErrorCode_Success {
return
}
uid := session.GetUserId()
sociaty := this.module.modelSociaty.getUserSociaty(uid)
if sociaty == nil {
code = pb.ErrorCode_SociatyNoFound
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()},
)
code = pb.ErrorCode_UserSessionNobeing
return
}
if userEx.SociatyTicket <= 0 {
code = pb.ErrorCode_SociatyTicketsNoEnough
return
}
//校验赛季时间
if this.module.modelSociatyBoss.sportsIsFinished() {
code = pb.ErrorCode_SociatySportsEnd
return
}
// 开始挑战
if err := this.module.modelSociatyBoss.challengestart(session, sociaty); err != nil {
var customErr = new(comm.CustomError)
if errors.As(err, &customErr) {
code = customErr.Code
// if code == pb.ErrorCode_SociatyNoFormation {
// return
// }
return
}
}
rsp := &pb.SociatyBChallengeStartResp{
SociatyId: sociaty.Id,
Uid: uid,
}
if err := session.SendMsg(string(this.module.GetType()), SociatySubTypeChallengestart, rsp); err != nil {
code = pb.ErrorCode_SystemError
}
return
}