95 lines
2.6 KiB
Go
95 lines
2.6 KiB
Go
package pagoda
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
)
|
|
|
|
//参数校验
|
|
func (this *apiComp) GetRewardCheck(session comm.IUserSession, req *pb.PagodaGetRewardReq) (code pb.ErrorCode) {
|
|
if req.Id <= 0 {
|
|
code = pb.ErrorCode_ReqParameterError
|
|
}
|
|
return
|
|
}
|
|
|
|
///获取主线关卡信息
|
|
func (this *apiComp) GetReward(session comm.IUserSession, req *pb.PagodaGetRewardReq) (code pb.ErrorCode, data *pb.ErrorData) {
|
|
|
|
code = this.GetRewardCheck(session, req)
|
|
if code != pb.ErrorCode_Success {
|
|
return // 参数校验失败直接返回
|
|
}
|
|
// 获取 奖励信息
|
|
list, err := this.module.modelPagoda.getPagodaList(session.GetUserId())
|
|
if err != nil || list == nil {
|
|
code = pb.ErrorCode_DBError
|
|
return
|
|
}
|
|
season, _ := this.module.modelSeasonPagoda.getSeasonPagodaList(session.GetUserId())
|
|
if season != nil {
|
|
_cfg := this.module.configure.GetPagodaRewardconfig(req.Id)
|
|
if _cfg == nil {
|
|
code = pb.ErrorCode_ConfigNoFound
|
|
return
|
|
}
|
|
// 校验是否能领取
|
|
if _cfg.LayerNum > season.PagodaId {
|
|
code = pb.ErrorCode_PagodaConditionErr
|
|
return
|
|
}
|
|
|
|
if _, ok := season.Reward[req.Id]; ok { // 校验是否重复领取
|
|
code = pb.ErrorCode_PagodaGetRewardErr
|
|
return
|
|
}
|
|
if season.Reward == nil {
|
|
season.Reward = make(map[int32]bool, 0)
|
|
}
|
|
// 发奖励
|
|
if code = this.module.DispenseRes(session, _cfg.Reward, true); code != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
season.Reward[req.Id] = true
|
|
mapData := make(map[string]interface{}, 0)
|
|
mapData["reward"] = season.Reward
|
|
code = this.module.ModifySeasonPagodaData(session.GetUserId(), mapData)
|
|
|
|
session.SendMsg(string(this.module.GetType()), PagodaGetRewardResp, &pb.PagodaGetRewardResp{Data: &pb.DBPagoda{
|
|
PagodaId: season.PagodaId,
|
|
Reward: season.Reward,
|
|
Type: season.Type,
|
|
}})
|
|
} else {
|
|
_cfg := this.module.configure.GetPagodaRewardconfig(req.Id)
|
|
if _cfg == nil {
|
|
code = pb.ErrorCode_ConfigNoFound
|
|
return
|
|
}
|
|
// 校验是否能领取
|
|
if _cfg.LayerNum > list.PagodaId {
|
|
code = pb.ErrorCode_PagodaConditionErr
|
|
return
|
|
}
|
|
|
|
if _, ok := list.Reward[req.Id]; ok { // 校验是否重复领取
|
|
code = pb.ErrorCode_PagodaGetRewardErr
|
|
return
|
|
}
|
|
if list.Reward == nil {
|
|
list.Reward = make(map[int32]bool, 0)
|
|
}
|
|
// 发奖励
|
|
if code = this.module.DispenseRes(session, _cfg.Reward, true); code != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
list.Reward[req.Id] = true
|
|
mapData := make(map[string]interface{}, 0)
|
|
mapData["reward"] = list.Reward
|
|
code = this.module.ModifyPagodaData(session.GetUserId(), mapData)
|
|
session.SendMsg(string(this.module.GetType()), PagodaGetRewardResp, &pb.PagodaGetRewardResp{Data: list})
|
|
}
|
|
|
|
return
|
|
}
|