74 lines
1.8 KiB
Go
74 lines
1.8 KiB
Go
package library
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
)
|
|
|
|
//参数校验
|
|
func (this *apiComp) GetRewardCheck(session comm.IUserSession, req *pb.LibraryGetRewardReq) (code pb.ErrorCode) {
|
|
if req.ObjId == "" || req.Fetterlv == 0 {
|
|
code = pb.ErrorCode_ReqParameterError
|
|
}
|
|
return
|
|
}
|
|
|
|
func (this *apiComp) GetReward(session comm.IUserSession, req *pb.LibraryGetRewardReq) (code pb.ErrorCode, data *pb.ErrorData) {
|
|
|
|
code = this.GetRewardCheck(session, req)
|
|
if code != pb.ErrorCode_Success {
|
|
return // 参数校验失败直接返回
|
|
}
|
|
rsp := &pb.LibraryGetRewardResp{}
|
|
defer session.SendMsg(string(this.module.GetType()), LibraryGetRewardResp, rsp)
|
|
fetter := this.module.getLibraryByObjID(session.GetUserId(), req.ObjId)
|
|
if fetter == nil {
|
|
code = pb.ErrorCode_LibraryNoData
|
|
return
|
|
}
|
|
// fetterlv check
|
|
var minLv int32
|
|
|
|
conf := this.module.configure.GetLibraryFetter(fetter.Fid, req.Fetterlv)
|
|
if conf == nil {
|
|
code = pb.ErrorCode_ConfigNoFound
|
|
}
|
|
|
|
for _, v := range conf.Hid { // 获取羁绊等级
|
|
_d := this.module.modelFetter.GetFetterByHeroId(session.GetUserId(), v)
|
|
if _d != nil {
|
|
if minLv == 0 {
|
|
minLv = _d.Favorlv
|
|
}
|
|
if _d.Favorlv > minLv {
|
|
minLv = _d.Favorlv
|
|
}
|
|
}
|
|
}
|
|
|
|
if minLv < req.Fetterlv {
|
|
code = pb.ErrorCode_LibraryLvReward
|
|
return
|
|
}
|
|
|
|
for k := range fetter.Prize {
|
|
if k == req.Fetterlv {
|
|
code = pb.ErrorCode_LibraryReward
|
|
return
|
|
}
|
|
}
|
|
fetter.Prize[req.Fetterlv] = 1
|
|
// 发奖
|
|
if len(conf.Prize) != 0 {
|
|
if code = this.module.DispenseRes(session, conf.Prize, true); code != pb.ErrorCode_Success { //
|
|
return
|
|
}
|
|
}
|
|
|
|
mapData := make(map[string]interface{}, 0)
|
|
mapData["prize"] = fetter.Prize
|
|
this.module.ModifyLibraryData(session.GetUserId(), fetter.Id, mapData) // 更新内存信息
|
|
rsp.Data = fetter
|
|
return
|
|
}
|