157 lines
4.3 KiB
Go
157 lines
4.3 KiB
Go
package mainline
|
|
|
|
import (
|
|
"fmt"
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
)
|
|
|
|
// 参数校验
|
|
func (this *apiComp) ReceiveAwardCheck(session comm.IUserSession, req *pb.MainlineReceiveAwardReq) (errdata *pb.ErrorData) {
|
|
return
|
|
}
|
|
|
|
// /获取主线关卡信息
|
|
func (this *apiComp) ReceiveAward(session comm.IUserSession, req *pb.MainlineReceiveAwardReq) (errdata *pb.ErrorData) {
|
|
var (
|
|
info *pb.DBMainline
|
|
award *pb.DBMainlineAward
|
|
chapterconf *cfg.GameMainChapterData
|
|
awardConfs []*cfg.GameMainStarrewardData
|
|
awardid int32
|
|
awardConf *cfg.GameMainStarrewardData
|
|
reward []*pb.UserAssets
|
|
pass int32
|
|
ok bool
|
|
err error
|
|
)
|
|
|
|
errdata = this.ReceiveAwardCheck(session, req)
|
|
if errdata != nil {
|
|
return // 参数校验失败直接返回
|
|
}
|
|
|
|
info, err = this.module.modelMline.getMainlineData(session.GetUserId())
|
|
if err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Title: pb.ErrorCode_DBError.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
|
|
if req.Rtype == 0 {
|
|
if award, ok = info.Chapteraward[req.Chapter]; !ok || award.Stage < req.Stage {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
Message: fmt.Sprintf("chapter:%d stage:%d no arrive", req.Chapter, req.Stage),
|
|
}
|
|
return
|
|
}
|
|
if chapterconf, err = this.module.configure.GetMainChapterConf(req.Chapter); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ConfigNoFound,
|
|
Title: pb.ErrorCode_ConfigNoFound.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
awardid = chapterconf.Starreward
|
|
} else if req.Rtype == 1 {
|
|
if award, ok = info.Exploreaward[req.Chapter]; !ok || award.Stage < req.Stage {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
Message: fmt.Sprintf("chapter:%d stage:%d no arrive", req.Chapter, req.Stage),
|
|
}
|
|
return
|
|
}
|
|
if chapterconf, err = this.module.configure.GetMainChapterConf(req.Chapter); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ConfigNoFound,
|
|
Title: pb.ErrorCode_ConfigNoFound.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
awardid = chapterconf.Starreward
|
|
} else {
|
|
if award, ok = info.Groupaward[req.Group]; !ok || award.Stage < req.Stage {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
Message: fmt.Sprintf("group:%d stage:%d no arrive", req.Group, req.Stage),
|
|
}
|
|
return
|
|
}
|
|
|
|
}
|
|
if award.Award == nil {
|
|
award.Award = make(map[int32]int32)
|
|
}
|
|
if pass, ok = award.Award[req.Stage]; ok && pass == 2 {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_MainlineRepeatReward,
|
|
Title: pb.ErrorCode_MainlineRepeatReward.ToString(),
|
|
Message: fmt.Sprintf("progress:%d stage:%d repeatreward", req.Chapter, req.Stage),
|
|
}
|
|
return
|
|
}
|
|
award.Award[req.Stage] = 2
|
|
if awardConfs, ok = this.module.configure.getrewardMap()[awardid]; !ok {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ConfigNoFound,
|
|
Title: pb.ErrorCode_ConfigNoFound.ToString(),
|
|
Message: fmt.Sprintf("no found awardid:%d", awardid),
|
|
}
|
|
return
|
|
}
|
|
ok = false
|
|
for _, v := range awardConfs {
|
|
if v.Starnum == req.Stage {
|
|
ok = true
|
|
awardConf = v
|
|
}
|
|
}
|
|
|
|
if !ok {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
Message: fmt.Sprintf("Stage:%d no found ", req.Stage),
|
|
}
|
|
return
|
|
}
|
|
|
|
if errdata = this.module.DispenseRes(session, awardConf.Reward, true); errdata != nil {
|
|
return
|
|
}
|
|
reward = make([]*pb.UserAssets, 0)
|
|
for _, v := range awardConf.Reward {
|
|
reward = append(reward, &pb.UserAssets{
|
|
A: v.A,
|
|
T: v.T,
|
|
N: v.N,
|
|
})
|
|
}
|
|
if err = this.module.modelMline.updateMainlineData(session.GetUserId(), info); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Title: pb.ErrorCode_DBError.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
session.SendMsg(string(this.module.GetType()), "receiveaward", &pb.MainlineReceiveAwardResp{
|
|
Rtype: req.Rtype,
|
|
Chapter: req.Chapter,
|
|
Group: req.Group,
|
|
Stage: req.Stage,
|
|
Reward: reward,
|
|
})
|
|
return
|
|
}
|