59 lines
1.5 KiB
Go
59 lines
1.5 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{}
|
|
fetter := this.module.getLibraryByObjID(session.GetUserId(), req.ObjId)
|
|
if fetter == nil {
|
|
code = pb.ErrorCode_LibraryNoData
|
|
return
|
|
}
|
|
if conf := this.module.configure.GetFriendData(fetter.Fid, req.Fetterlv); len(conf) == 0 {
|
|
code = pb.ErrorCode_ConfigNoFound
|
|
return
|
|
} else {
|
|
if conf[0].FavorabilityLv > fetter.Fetterlv {
|
|
code = pb.ErrorCode_LibraryLvReward
|
|
return
|
|
}
|
|
}
|
|
if _, ok := fetter.Prize[req.Fetterlv]; ok {
|
|
code = pb.ErrorCode_LibraryReward
|
|
return
|
|
}
|
|
// 等级校验
|
|
if req.Fetterlv > fetter.Fetterlv {
|
|
code = pb.ErrorCode_LibraryLvReward
|
|
return
|
|
}
|
|
fetter.Prize[req.Fetterlv] = 1
|
|
// 发奖
|
|
|
|
mapData := make(map[string]interface{}, 0)
|
|
mapData["prize"] = fetter.Prize
|
|
this.module.ModifyLibraryData(session.GetUserId(), fetter.Id, mapData) // 更新内存信息
|
|
rsp.Data = fetter
|
|
session.SendMsg(string(this.module.GetType()), LibraryGetRewardResp, rsp)
|
|
return
|
|
}
|