diff --git a/modules/hero/api_buy.go b/modules/hero/api_buy.go index 8cbb17b96..3ff4d85e9 100644 --- a/modules/hero/api_buy.go +++ b/modules/hero/api_buy.go @@ -42,6 +42,7 @@ func (this *apiComp) Buy(session comm.IUserSession, req *pb.HeroBuyReq) (code pb if conf, err = this.module.configure.GetShopItemsConfigureByGroups(req.BuyType, udata); err != nil { // 找配置 code = pb.ErrorCode_ConfigNoFound + data.Message = err.Error() return } diff --git a/modules/hero/api_drawCard.go b/modules/hero/api_drawCard.go index 542f1e0bf..d40e9c611 100644 --- a/modules/hero/api_drawCard.go +++ b/modules/hero/api_drawCard.go @@ -266,9 +266,10 @@ func (this *apiComp) DrawCard(session comm.IUserSession, req *pb.HeroDrawCardReq } for index, star := range szStar { - _data := this.module.configure.GetPollByType(strPool[index]) - if _data == nil { + _data, err := this.module.configure.GetPollByType(strPool[index]) + if err != nil { code = pb.ErrorCode_ConfigNoFound + data.Message = err.Error() return } sz := make([]int32, 0) diff --git a/modules/hero/api_strengthenUpSkill.go b/modules/hero/api_strengthenUpSkill.go index f76f0d179..c68733372 100644 --- a/modules/hero/api_strengthenUpSkill.go +++ b/modules/hero/api_strengthenUpSkill.go @@ -77,9 +77,10 @@ func (this *apiComp) StrengthenUpSkill(session comm.IUserSession, req *pb.HeroSt for index, skill := range _hero.NormalSkill { skillMaxLv := this.module.configure.GetHeroSkillMaxLvConfig(uint32(skill.SkillID)) if skill.SkillLv < skillMaxLv { // 找到没有满级的技能id - skillData := this.module.configure.GetHeroSkillUpConfig(skill.SkillID) - if skillData == nil { + skillData, err := this.module.configure.GetHeroSkillUpConfig(skill.SkillID) + if err != nil { code = pb.ErrorCode_ConfigNoFound + data.Message = err.Error() return } sz = append(sz, skillData.Probability[skill.SkillLv]) diff --git a/modules/hero/api_talentlearn.go b/modules/hero/api_talentlearn.go index 9555f912f..ba0faa5f6 100644 --- a/modules/hero/api_talentlearn.go +++ b/modules/hero/api_talentlearn.go @@ -58,9 +58,10 @@ func (this *apiComp) TalentLearn(session comm.IUserSession, req *pb.HeroTalentLe } } - talentConf := this.module.configure.GetHeroTalent(req.TalentID) - if talentConf == nil { + talentConf, err := this.module.configure.GetHeroTalent(req.TalentID) + if err != nil { code = pb.ErrorCode_ConfigNoFound + data.Message = err.Error() return } // 校验 diff --git a/modules/hero/api_talentreset.go b/modules/hero/api_talentreset.go index 164c2f594..dcba69038 100644 --- a/modules/hero/api_talentreset.go +++ b/modules/hero/api_talentreset.go @@ -42,9 +42,12 @@ func (this *apiComp) TalentReset(session comm.IUserSession, req *pb.HeroTalentRe } for k := range _talent.Talent { - if conf := this.module.configure.GetHeroTalent(k); conf != nil { + if conf, err := this.module.configure.GetHeroTalent(k); err == nil { talentPoint += conf.Point // 获取当前英雄的天赋点数 - + } else { + code = pb.ErrorCode_ConfigNoFound + data.Message = err.Error() + return } } if t := this.module.configure.GetHeroTalentBoxItem(_talent.HeroId); t != "" { diff --git a/modules/hero/configure_comp.go b/modules/hero/configure_comp.go index 339768b82..6febdc4f6 100644 --- a/modules/hero/configure_comp.go +++ b/modules/hero/configure_comp.go @@ -172,8 +172,12 @@ func (this *configureComp) SetHeroDrawConfig() { return } -func (this *configureComp) GetPollByType(poosType string) map[int32][]*cfg.GameDrawCardData { - return this.drawCardCfg[poosType] +func (this *configureComp) GetPollByType(poosType string) (conf map[int32][]*cfg.GameDrawCardData, err error) { + var ok bool + if conf, ok = this.drawCardCfg[poosType]; !ok { + err = comm.NewNotFoundConfErr("hero", hero_drawcard, poosType) + } + return } func (this *configureComp) GetHeroExp(hid string) (conf *cfg.GameHeroExpData, err error) { @@ -248,15 +252,19 @@ func (this *configureComp) GetHeroLvgrow(heroId string) *cfg.GameHeroLevelgrowDa } // 获取英雄技能升级相关信息 -func (this *configureComp) GetHeroSkillUpConfig(skillid int32) (data *cfg.GameHeroSkillLevelData) { - - if v, err := this.GetConfigure(hero_skillup); err == nil { - if conf, ok := v.(*cfg.GameHeroSkillLevel); ok { - data = conf.Get(skillid) +func (this *configureComp) GetHeroSkillUpConfig(skillid int32) (data *cfg.GameHeroSkillLevelData, err error) { + var ( + v interface{} + ) + if conf, ok := v.(*cfg.GameHeroSkillLevel); ok { + if v, err = this.GetConfigure(hero_skillup); err == nil { + if data = conf.Get(skillid); data == nil { + err = comm.NewNotFoundConfErr("hero", hero_skillup, skillid) + } return } } - this.module.Errorf("cfg.GetHeroSkillUpConfig :id = %d", skillid) + err = comm.NewNotFoundConfErr("hero", hero_skillup, skillid) return } @@ -293,15 +301,20 @@ func (this *configureComp) GetHeroFucionConfig(cid string) (data *cfg.GameHerofu return } -func (this *configureComp) GetHeroTalent(id int32) (data *cfg.GameHeroTalentData) { - if v, err := this.GetConfigure(hero_talent); err == nil { +func (this *configureComp) GetHeroTalent(id int32) (data *cfg.GameHeroTalentData, err error) { + var ( + v interface{} + ) + if v, err = this.GetConfigure(hero_talent); err == nil { if configure, ok := v.(*cfg.GameHeroTalent); ok { - data = configure.Get(id) + if data = configure.Get(id); data == nil { + err = comm.NewNotFoundConfErr("hero", hero_talent, id) + } return } } - this.module.Errorf("cfg.GameHeroTalentData GetHeroTalent:id = %d", id) - return nil + err = comm.NewNotFoundConfErr("hero", hero_talent, id) + return } // 天赋指定消耗 @@ -341,6 +354,7 @@ func (this *configureComp) GetShopItemsConfigureByGroups(groupid int32, user *pb ) if v, err = this.GetConfigure(game_shopitem); err != nil { this.module.Errorf("err:%v", err) + err = comm.NewNotFoundConfErr("hero", game_shopitem, groupid) return } else { table = v.(*cfg.GameShopitem) diff --git a/modules/hero/model_hero.go b/modules/hero/model_hero.go index 48ff9d388..6135f436e 100644 --- a/modules/hero/model_hero.go +++ b/modules/hero/model_hero.go @@ -814,7 +814,7 @@ func (this *ModelHero) resetTalentProperty(hero *pb.DBHero) { for _, v := range rst { if v.HeroId == hero.HeroID { // 找到对应的英雄 for k := range v.Talent { - if conf := this.module.configure.GetHeroTalent(k); conf != nil { //获取天赋树 + if conf, _ := this.module.configure.GetHeroTalent(k); conf != nil { //获取天赋树 if conf.Hp != -1 { attr[0] += conf.Hp } diff --git a/modules/hero/module.go b/modules/hero/module.go index 7757fe1aa..0df1308c1 100644 --- a/modules/hero/module.go +++ b/modules/hero/module.go @@ -536,7 +536,7 @@ func (this *Hero) ContinuousRestriction(uid string, heroCid string, drawCount in iMaxCOunt := conf.DrawCardContinuousRestrictionStar5 if drawCount-index <= iMaxCOunt { // 连续n次还获得该英雄 直接替换其他英雄 - _data := this.configure.GetPollByType(pool) + _data, _ := this.configure.GetPollByType(pool) if _data == nil { return heroCid diff --git a/modules/library/api_getstoryreward.go b/modules/library/api_getstoryreward.go index 4c9cf0950..1d4359fbc 100644 --- a/modules/library/api_getstoryreward.go +++ b/modules/library/api_getstoryreward.go @@ -33,9 +33,10 @@ func (this *apiComp) GetStoryReward(session comm.IUserSession, req *pb.LibraryGe code = pb.ErrorCode_ReqParameterError return } - favorConf := this.module.configure.GetFavorability(_heroFetter.Heroid, 1) // 取1级的就可以 - if favorConf == nil { + favorConf, err := this.module.configure.GetFavorability(_heroFetter.Heroid, 1) // 取1级的就可以 + if err != nil { code = pb.ErrorCode_ConfigNoFound + data.Message = err.Error() return } // 领取传记往事id diff --git a/modules/library/api_lvreward.go b/modules/library/api_lvreward.go index 4434ca2f8..50732dbc3 100644 --- a/modules/library/api_lvreward.go +++ b/modules/library/api_lvreward.go @@ -38,9 +38,10 @@ func (this *apiComp) LvReward(session comm.IUserSession, req *pb.LibraryLvReward code = pb.ErrorCode_LibraryReward // 重复领奖 return } - confData := this.module.configure.GetFavorability(_heroFetter.Heroid, req.Lv) - if confData == nil { + confData, err := this.module.configure.GetFavorability(_heroFetter.Heroid, req.Lv) + if err != nil { code = pb.ErrorCode_ReqParameterError + data.Message = err.Error() return } diff --git a/modules/library/api_lvup.go b/modules/library/api_lvup.go index ce9a42be2..8df8c7741 100644 --- a/modules/library/api_lvup.go +++ b/modules/library/api_lvup.go @@ -38,9 +38,10 @@ func (this *apiComp) FetterLvUp(session comm.IUserSession, req *pb.LibraryFetter } } fetter.Fidlv += 1 - conf := this.module.configure.GetFriendData(fetter.Fid, fetter.Fidlv) - if len(conf) == 0 { + conf, e := this.module.configure.GetFriendData(fetter.Fid, fetter.Fidlv) + if e != nil || len(conf) == 0 { code = pb.ErrorCode_ConfigNoFound + data.Message = e.Error() return } diff --git a/modules/library/api_usegift.go b/modules/library/api_usegift.go index af0984127..bd169711f 100644 --- a/modules/library/api_usegift.go +++ b/modules/library/api_usegift.go @@ -39,9 +39,10 @@ func (this *apiComp) UseGift(session comm.IUserSession, req *pb.LibraryUseGiftRe return } - _exp := this.module.configure.GetFavorabilityExp(_heroObj.Heroid) - if len(_exp) == 0 { + _exp, err := this.module.configure.GetFavorabilityExp(_heroObj.Heroid) + if err != nil { code = pb.ErrorCode_ConfigNoFound + data.Message = err.Error() return } maxLv = int32(len(_exp)) // 获取当前星级羁绊最大等级 @@ -70,9 +71,10 @@ func (this *apiComp) UseGift(session comm.IUserSession, req *pb.LibraryUseGiftRe } _heroObj.Givecount += req.Counts // 校验是否是自己喜欢的食物 - _c := this.module.configure.GetFavorability(_heroObj.Heroid, _heroObj.Favorlv) - if _c == nil { + _c, err := this.module.configure.GetFavorability(_heroObj.Heroid, _heroObj.Favorlv) + if err != nil { code = pb.ErrorCode_ConfigNoFound + data.Message = err.Error() return } for _, v := range _c.LikesFood { // 喜欢的食物 diff --git a/modules/library/comp_configure.go b/modules/library/comp_configure.go index 2e6608960..326255f2e 100644 --- a/modules/library/comp_configure.go +++ b/modules/library/comp_configure.go @@ -2,6 +2,7 @@ package library import ( "fmt" + "go_dreamfactory/comm" "go_dreamfactory/lego/core" "go_dreamfactory/lego/sys/log" "go_dreamfactory/modules" @@ -62,9 +63,16 @@ func (this *configureComp) SetFavorability() { } } -func (this *configureComp) GetFavorability(hid string, lv int32) *cfg.GameFavorabilityData { - - return this.favorability[hid+"-"+strconv.Itoa(int(lv))] +func (this *configureComp) GetFavorability(hid string, lv int32) (conf *cfg.GameFavorabilityData, err error) { + var ( + ok bool + par interface{} + ) + if conf, ok = this.favorability[hid+"-"+strconv.Itoa(int(lv))]; !ok { + par = fmt.Errorf("hid:%s,lv:%d", hid, lv) + err = comm.NewNotFoundConfErr("hero", game_favorability, par) + } + return } func (this *configureComp) SetFriendData() { @@ -90,8 +98,16 @@ func (this *configureComp) SetFriendData() { } // id:羁绊id lv 羁绊等级 -func (this *configureComp) GetFriendData(id int32, lv int32) []*cfg.GameFriendsData { - return this.friend[int64(id)<<8+int64(lv)] +func (this *configureComp) GetFriendData(id int32, lv int32) (conf []*cfg.GameFriendsData, err error) { + var ( + ok bool + par interface{} + ) + if conf, ok = this.friend[int64(id)<<8+int64(lv)]; !ok { + par = fmt.Errorf("hid:%d,lv:%d", id, lv) + err = comm.NewNotFoundConfErr("hero", game_friends, par) + } + return } // 通过英雄获取当前英雄的所有羁绊ID @@ -116,7 +132,12 @@ func (this *configureComp) GetConfigure(name string) (v interface{}, err error) return configure.GetConfigure(name) } -func (this *configureComp) GetFavorabilityExp(hid string) []int32 { - - return this.favorLvExp[hid] +func (this *configureComp) GetFavorabilityExp(hid string) (conf []int32, err error) { + var ( + ok bool + ) + if conf, ok = this.favorLvExp[hid]; !ok { + err = comm.NewNotFoundConfErr("hero", game_favorability, hid) + } + return } diff --git a/modules/mline/api_getlist.go b/modules/mline/api_getlist.go index 4970676dd..9b78c10d5 100644 --- a/modules/mline/api_getlist.go +++ b/modules/mline/api_getlist.go @@ -35,7 +35,7 @@ func (this *apiComp) GetList(session comm.IUserSession, req *pb.MlineGetListReq) } } if len(rsp.Data) == 0 { // 什么数据都没有 创建一条 - if chapterConf := this.module.configure.GetFirstChapterIDByType(req.CType); chapterConf != nil { // 配置文件校验 + if chapterConf, err := this.module.configure.GetFirstChapterIDByType(req.CType); err == nil { // 配置文件校验 if stageConf := this.module.configure.GetFirstStageIDByChapter(chapterConf.Id); stageConf != nil { newData := &pb.DBMline{ Id: primitive.NewObjectID().Hex(), @@ -52,6 +52,7 @@ func (this *apiComp) GetList(session comm.IUserSession, req *pb.MlineGetListReq) } } else { code = pb.ErrorCode_ConfigNoFound + data.Message = err.Error() return } } diff --git a/modules/mline/comp_configure.go b/modules/mline/comp_configure.go index d89060acb..96bea151f 100644 --- a/modules/mline/comp_configure.go +++ b/modules/mline/comp_configure.go @@ -1,6 +1,7 @@ package mline import ( + "go_dreamfactory/comm" "go_dreamfactory/lego/core" "go_dreamfactory/modules" "go_dreamfactory/sys/configure" @@ -85,18 +86,21 @@ func (this *configureComp) GetPreMainChapter(stageId int32) (preStageID int32) { } return } -func (this *configureComp) GetFirstChapterIDByType(iType int32) *cfg.GameMainChapterData { - if v, err := this.GetConfigure(game_mainchapter); err == nil { +func (this *configureComp) GetFirstChapterIDByType(iType int32) (conf *cfg.GameMainChapterData, err error) { + var ( + v interface{} + ) + if v, err = this.GetConfigure(game_mainchapter); err == nil { if configure, ok := v.(*cfg.GameMainChapter); ok { - for _, v := range configure.GetDataList() { - if v.ChapterType == iType { - return v + for _, conf = range configure.GetDataList() { + if conf.ChapterType == iType { + return } } } } - return nil - + err = comm.NewNotFoundConfErr("mline", game_mainchapter, iType) + return } func (this *configureComp) GetFirstStageIDByChapter(chapterID int32) *cfg.GameMainStageData { diff --git a/modules/shop/api_getlist.go b/modules/shop/api_getlist.go index c2d4fb5b8..a8e709f2d 100644 --- a/modules/shop/api_getlist.go +++ b/modules/shop/api_getlist.go @@ -138,6 +138,7 @@ func (this *apiComp) Getlist(session comm.IUserSession, req *pb.ShopGetListReq) for _, v := range shopconf.Shopitem { if _items, err = this.module.configure.GetShopItemsConfigureByGroups(v, udata); err != nil || len(_items) == 0 { code = pb.ErrorCode_SystemError + data.Message = err.Error() return } items = append(items, randomGoods(_items)) diff --git a/modules/shop/configure.go b/modules/shop/configure.go index be5f17345..7df5cf1ab 100644 --- a/modules/shop/configure.go +++ b/modules/shop/configure.go @@ -2,6 +2,7 @@ package shop import ( "fmt" + "go_dreamfactory/comm" "go_dreamfactory/lego/core" "go_dreamfactory/modules" "go_dreamfactory/pb" @@ -75,6 +76,7 @@ func (this *configureComp) GetShopItemsConfigureByGroups(groupid int32, user *pb ) if v, err = this.GetConfigure(game_shopitem); err != nil { this.module.Errorf("err:%v", err) + err = comm.NewNotFoundConfErr("hero", game_shopitem, groupid) return } else { table = v.(*cfg.GameShopitem)