package library import ( "go_dreamfactory/comm" "go_dreamfactory/pb" cfg "go_dreamfactory/sys/configure/structs" ) //参数校验 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 } conf := this.module.configure.GetFriendData(fetter.Fid, req.Fetterlv) if 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 // 发奖 hProperty := make(map[string][]*cfg.Gameatr, 0) for _, v := range conf { var sz []*cfg.Gameatr for _, v1 := range v.Attribute { b := &cfg.Gameatr{ A: v1.A, N: v1.N, } sz = append(sz, b) } hProperty[v.Hid] = sz } this.module.ModuleHero.AddHeroFetterAttribute(session, hProperty) 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 }