106 lines
2.7 KiB
Go
106 lines
2.7 KiB
Go
package caravan
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
)
|
|
|
|
//参数校验
|
|
func (this *apiComp) GetRewardCheck(session comm.IUserSession, req *pb.CaravanGetRewardReq) (errdata *pb.ErrorData) {
|
|
|
|
return
|
|
}
|
|
|
|
func (this *apiComp) GetReward(session comm.IUserSession, req *pb.CaravanGetRewardReq) (errdata *pb.ErrorData) {
|
|
var (
|
|
update map[string]interface{}
|
|
atno []*pb.UserAtno
|
|
res []*cfg.Gameatn
|
|
)
|
|
update = make(map[string]interface{})
|
|
|
|
if errdata = this.GetRewardCheck(session, req); errdata != nil {
|
|
return // 参数校验失败直接返回
|
|
}
|
|
caravan, _ := this.module.modelCaravan.getCaravanList(session.GetUserId())
|
|
|
|
curProfit := this.module.ModuleUser.QueryAttributeValue(session.GetUserId(), "profit")
|
|
if req.Lv == 0 {
|
|
var index int32
|
|
for {
|
|
index++
|
|
reward, err := this.configure.GetCaravanRewardById(index)
|
|
if err != nil {
|
|
break
|
|
}
|
|
if reward.Key < 0 {
|
|
break
|
|
}
|
|
if _, ok := caravan.Reward[index]; ok {
|
|
continue
|
|
}
|
|
if curProfit < int64(reward.Key) {
|
|
break
|
|
} else {
|
|
res = append(res, reward.Reward...)
|
|
caravan.Reward[index] = true
|
|
}
|
|
}
|
|
|
|
} 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 {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_TrollRepeatedReward,
|
|
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)
|
|
session.SendMsg(string(this.module.GetType()), "getreward", &pb.CaravanGetRewardResp{
|
|
Reward: caravan.Reward,
|
|
Anto: atno,
|
|
})
|
|
|
|
go this.module.AsynHandleSession(session.Clone(), func(session comm.IUserSession) {
|
|
this.module.WriteUserLog(session.GetUserId(), comm.GMResAddType, "CaravanGetRewardReq", atno)
|
|
})
|
|
return
|
|
}
|