63 lines
1.7 KiB
Go
63 lines
1.7 KiB
Go
package library
|
|
|
|
/*
|
|
* 单个英雄剧情id 奖励
|
|
*/
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
)
|
|
|
|
//参数校验
|
|
func (this *apiComp) LvRewardCheck(session comm.IUserSession, req *pb.LibraryLvRewardReq) (code pb.ErrorCode) {
|
|
if req.Oid == "" || req.Lv <= 0 {
|
|
code = pb.ErrorCode_ReqParameterError
|
|
}
|
|
return
|
|
}
|
|
|
|
func (this *apiComp) LvReward(session comm.IUserSession, req *pb.LibraryLvRewardReq) (code pb.ErrorCode, data *pb.ErrorData) {
|
|
|
|
resp := &pb.LibraryLvRewardResp{}
|
|
code = this.LvRewardCheck(session, req)
|
|
if code != pb.ErrorCode_Success {
|
|
return // 参数校验失败直接返回
|
|
}
|
|
_heroFetter := this.module.modelFetter.getOneHeroFetter(session.GetUserId(), req.Oid)
|
|
if _heroFetter == nil {
|
|
code = pb.ErrorCode_ReqParameterError
|
|
return
|
|
}
|
|
curStar := this.module.configure.GetHeroConfigStar(_heroFetter.Heroid) // 查询原始星级
|
|
if curStar == 0 {
|
|
code = pb.ErrorCode_ConfigNoFound
|
|
return
|
|
}
|
|
confData := this.module.configure.GetLibraryFavorData(curStar, req.Lv)
|
|
if len(confData.Prize) == 0 {
|
|
code = pb.ErrorCode_ReqParameterError
|
|
return
|
|
}
|
|
|
|
for _, v := range _heroFetter.Lvprize {
|
|
if v == req.Lv {
|
|
code = pb.ErrorCode_LibraryReward // 重复领奖
|
|
break
|
|
}
|
|
}
|
|
_heroFetter.Lvprize = append(_heroFetter.Lvprize, req.Lv)
|
|
// 发奖
|
|
code = this.module.DispenseRes(session, confData.Prize, true)
|
|
if code != pb.ErrorCode_Success {
|
|
this.module.Errorf("GetStoryReward err:add item : %v", confData.Prize)
|
|
}
|
|
mapData := make(map[string]interface{}, 0)
|
|
mapData["lvprize"] = _heroFetter.Lvprize
|
|
this.module.modelFetter.modifyHeroFetterDataByObjId(session.GetUserId(), _heroFetter.Id, mapData)
|
|
resp.Data = _heroFetter
|
|
|
|
session.SendMsg(string(this.module.GetType()), LibraryLvRewardResp, resp)
|
|
return
|
|
}
|