65 lines
1.7 KiB
Go
65 lines
1.7 KiB
Go
package mainline
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
|
|
"google.golang.org/protobuf/proto"
|
|
)
|
|
|
|
//参数校验
|
|
func (this *apiComp) GetRewardCheck(session comm.IUserSession, req *pb.MainlineGetRewardReq) (code pb.ErrorCode) {
|
|
if req.ChapterObj == "" {
|
|
code = pb.ErrorCode_ReqParameterError
|
|
}
|
|
return
|
|
}
|
|
|
|
///获取主线关卡信息
|
|
func (this *apiComp) GetReward(session comm.IUserSession, req *pb.MainlineGetRewardReq) (code pb.ErrorCode, data proto.Message) {
|
|
rsp := &pb.MainlineGetRewardResp{}
|
|
|
|
code = this.GetRewardCheck(session, req)
|
|
if code != pb.ErrorCode_Success {
|
|
return // 参数校验失败直接返回
|
|
}
|
|
|
|
_obj := this.module.modelMainline.getOneChapterInfo(session.GetUserId(), req.ChapterObj)
|
|
if _obj != nil {
|
|
code = pb.ErrorCode_DBError
|
|
return
|
|
}
|
|
if _obj.AwaredID >= 0 {
|
|
code = pb.ErrorCode_MainlineRepeatReward // 重复领奖
|
|
return
|
|
}
|
|
// 校验是不是通关了
|
|
chaptConfig := this.module.configure.GetMainlineChapter(int32(_obj.ChapterId)) // 根据配置文件找
|
|
if chaptConfig == nil {
|
|
code = pb.ErrorCode_ConfigNoFound
|
|
return
|
|
}
|
|
if chaptConfig.Episode[len(chaptConfig.Episode)-1] != _obj.MainlineId {
|
|
code = pb.ErrorCode_MainlineCompleteReward // 通关才能领奖
|
|
return
|
|
}
|
|
_obj.AwaredID = 1
|
|
update := map[string]interface{}{
|
|
"awaredID": _obj.AwaredID,
|
|
}
|
|
// 发奖
|
|
code = this.module.DispenseRes(session, chaptConfig.Award, true)
|
|
if code != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
err := this.module.modelMainline.modifyMainlineData(session.GetUserId(), _obj.Id, update)
|
|
if err != nil {
|
|
code = pb.ErrorCode_DBError
|
|
return
|
|
}
|
|
|
|
rsp.Data = _obj
|
|
session.SendMsg(string(this.module.GetType()), MainlineGetRewardResp, rsp)
|
|
return
|
|
}
|