From cbe0c9363504306b38f2afa18939516d4a6d9b76 Mon Sep 17 00:00:00 2001 From: meixiongfeng <766881921@qq.com> Date: Mon, 9 Oct 2023 18:20:42 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=97=E8=BD=A6=E7=BB=93=E8=B4=A6=E6=94=B6?= =?UTF-8?q?=E7=9B=8A=E5=A5=96=E5=8A=B1=E9=A2=86=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/caravan/api_getreward.go | 79 +++++++++++++++++++------------ modules/caravan/comp_configure.go | 14 ++++++ 2 files changed, 63 insertions(+), 30 deletions(-) diff --git a/modules/caravan/api_getreward.go b/modules/caravan/api_getreward.go index bf68e9434..220b98012 100644 --- a/modules/caravan/api_getreward.go +++ b/modules/caravan/api_getreward.go @@ -25,52 +25,71 @@ func (this *apiComp) GetReward(session comm.IUserSession, req *pb.CaravanGetRewa } caravan, _ := this.module.modelCaravan.getCaravanList(session.GetUserId()) - reward := this.configure.GetCaravanReward() curProfit := this.module.ModuleUser.QueryAttributeValue(session.GetUserId(), "profit") if req.Lv == 0 { - for _, v := range reward { - if v.Key > 0 { - if curProfit > int64(v.Key) { - if _, ok := caravan.Reward[v.Key]; !ok { - res = append(res, v.Reward...) - caravan.Reward[v.Key] = true - } - } - } - } - } else { - for _, v := range reward { - if v.Key == req.Lv { - if curProfit < int64(v.Key) { - errdata = &pb.ErrorData{ - Code: pb.ErrorCode_TrollCantReward, - Title: pb.ErrorCode_TrollCantReward.ToString(), - } - return - } else { - res = append(res, v.Reward...) - } + var index int32 + for { + index++ + reward, err := this.configure.GetCaravanRewardById(index) + if err != nil { break } + if reward.Key < 0 { + break + } + if _, ok := caravan.Reward[req.Lv]; ok { + continue + } + if curProfit < int64(reward.Key) { + break + } else { + res = append(res, reward.Reward...) + caravan.Reward[req.Lv] = true + } } - if len(res) == 0 { + + } else { + reward, err := this.configure.GetCaravanRewardById(req.Lv) + if err != nil { + errdata = &pb.ErrorData{ + Code: pb.ErrorCode_ReqParameterError, + Title: pb.ErrorCode_ReqParameterError.ToString(), + Message: err.Error(), + } + return + } + if reward.Key < 0 { errdata = &pb.ErrorData{ Code: pb.ErrorCode_ReqParameterError, Title: pb.ErrorCode_ReqParameterError.ToString(), } return } - - if _, ok := caravan.Reward[req.Lv]; !ok { - caravan.Reward[req.Lv] = true - } else { // 重复领取 + if _, ok := caravan.Reward[req.Lv]; ok { errdata = &pb.ErrorData{ Code: pb.ErrorCode_TrollRepeatedReward, - Title: pb.ErrorCode_TrollRepeatedReward.ToString(), + Title: pb.ErrorCode_TrollRepeatedReward.ToString(), // 重复领取 } + return + } + if curProfit < int64(reward.Key) { + errdata = &pb.ErrorData{ + Code: pb.ErrorCode_TrollCantReward, + Title: pb.ErrorCode_TrollCantReward.ToString(), // 重复领取 + } + return + } else { + res = append(res, reward.Reward...) + caravan.Reward[req.Lv] = true } } - + if len(res) == 0 { + errdata = &pb.ErrorData{ + Code: pb.ErrorCode_ReqParameterError, + Title: pb.ErrorCode_ReqParameterError.ToString(), + } + return + } errdata, atno = this.module.DispenseAtno(session, res, true) update["reward"] = caravan.Reward this.module.modelCaravan.modifyCaravanDataByObjId(session.GetUserId(), update) diff --git a/modules/caravan/comp_configure.go b/modules/caravan/comp_configure.go index 6f883402d..c79f1777a 100644 --- a/modules/caravan/comp_configure.go +++ b/modules/caravan/comp_configure.go @@ -270,3 +270,17 @@ func (this *configureComp) GetCaravanEventById(id int32) (data *cfg.GameCaravanE err = comm.NewNotFoundConfErr(moduleName, game_caravan_event, id) return } + +func (this *configureComp) GetCaravanRewardById(id int32) (reward *cfg.GameCaravanRewardData, err error) { + var v interface{} + if v, err = this.GetConfigure(game_caravan_reward); err == nil { + if configure, ok := v.(*cfg.GameCaravanReward); ok { + reward = configure.Get(id) + if reward != nil { + return + } + } + } + log.Errorf("get GetCaravanRewardById conf err:%v", err) + return +}