错误码返回

This commit is contained in:
meixiongfeng 2023-05-29 19:39:31 +08:00
parent fb5ab9f073
commit fa1dec7514
17 changed files with 104 additions and 49 deletions

View File

@ -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 { // 找配置 if conf, err = this.module.configure.GetShopItemsConfigureByGroups(req.BuyType, udata); err != nil { // 找配置
code = pb.ErrorCode_ConfigNoFound code = pb.ErrorCode_ConfigNoFound
data.Message = err.Error()
return return
} }

View File

@ -266,9 +266,10 @@ func (this *apiComp) DrawCard(session comm.IUserSession, req *pb.HeroDrawCardReq
} }
for index, star := range szStar { for index, star := range szStar {
_data := this.module.configure.GetPollByType(strPool[index]) _data, err := this.module.configure.GetPollByType(strPool[index])
if _data == nil { if err != nil {
code = pb.ErrorCode_ConfigNoFound code = pb.ErrorCode_ConfigNoFound
data.Message = err.Error()
return return
} }
sz := make([]int32, 0) sz := make([]int32, 0)

View File

@ -77,9 +77,10 @@ func (this *apiComp) StrengthenUpSkill(session comm.IUserSession, req *pb.HeroSt
for index, skill := range _hero.NormalSkill { for index, skill := range _hero.NormalSkill {
skillMaxLv := this.module.configure.GetHeroSkillMaxLvConfig(uint32(skill.SkillID)) skillMaxLv := this.module.configure.GetHeroSkillMaxLvConfig(uint32(skill.SkillID))
if skill.SkillLv < skillMaxLv { // 找到没有满级的技能id if skill.SkillLv < skillMaxLv { // 找到没有满级的技能id
skillData := this.module.configure.GetHeroSkillUpConfig(skill.SkillID) skillData, err := this.module.configure.GetHeroSkillUpConfig(skill.SkillID)
if skillData == nil { if err != nil {
code = pb.ErrorCode_ConfigNoFound code = pb.ErrorCode_ConfigNoFound
data.Message = err.Error()
return return
} }
sz = append(sz, skillData.Probability[skill.SkillLv]) sz = append(sz, skillData.Probability[skill.SkillLv])

View File

@ -58,9 +58,10 @@ func (this *apiComp) TalentLearn(session comm.IUserSession, req *pb.HeroTalentLe
} }
} }
talentConf := this.module.configure.GetHeroTalent(req.TalentID) talentConf, err := this.module.configure.GetHeroTalent(req.TalentID)
if talentConf == nil { if err != nil {
code = pb.ErrorCode_ConfigNoFound code = pb.ErrorCode_ConfigNoFound
data.Message = err.Error()
return return
} }
// 校验 // 校验

View File

@ -42,9 +42,12 @@ func (this *apiComp) TalentReset(session comm.IUserSession, req *pb.HeroTalentRe
} }
for k := range _talent.Talent { 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 // 获取当前英雄的天赋点数 talentPoint += conf.Point // 获取当前英雄的天赋点数
} else {
code = pb.ErrorCode_ConfigNoFound
data.Message = err.Error()
return
} }
} }
if t := this.module.configure.GetHeroTalentBoxItem(_talent.HeroId); t != "" { if t := this.module.configure.GetHeroTalentBoxItem(_talent.HeroId); t != "" {

View File

@ -172,8 +172,12 @@ func (this *configureComp) SetHeroDrawConfig() {
return return
} }
func (this *configureComp) GetPollByType(poosType string) map[int32][]*cfg.GameDrawCardData { func (this *configureComp) GetPollByType(poosType string) (conf map[int32][]*cfg.GameDrawCardData, err error) {
return this.drawCardCfg[poosType] 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) { 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) { func (this *configureComp) GetHeroSkillUpConfig(skillid int32) (data *cfg.GameHeroSkillLevelData, err error) {
var (
if v, err := this.GetConfigure(hero_skillup); err == nil { v interface{}
)
if conf, ok := v.(*cfg.GameHeroSkillLevel); ok { if conf, ok := v.(*cfg.GameHeroSkillLevel); ok {
data = conf.Get(skillid) if v, err = this.GetConfigure(hero_skillup); err == nil {
if data = conf.Get(skillid); data == nil {
err = comm.NewNotFoundConfErr("hero", hero_skillup, skillid)
}
return return
} }
} }
this.module.Errorf("cfg.GetHeroSkillUpConfig :id = %d", skillid) err = comm.NewNotFoundConfErr("hero", hero_skillup, skillid)
return return
} }
@ -293,15 +301,20 @@ func (this *configureComp) GetHeroFucionConfig(cid string) (data *cfg.GameHerofu
return return
} }
func (this *configureComp) GetHeroTalent(id int32) (data *cfg.GameHeroTalentData) { func (this *configureComp) GetHeroTalent(id int32) (data *cfg.GameHeroTalentData, err error) {
if v, err := this.GetConfigure(hero_talent); err == nil { var (
v interface{}
)
if v, err = this.GetConfigure(hero_talent); err == nil {
if configure, ok := v.(*cfg.GameHeroTalent); ok { 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 return
} }
} }
this.module.Errorf("cfg.GameHeroTalentData GetHeroTalent:id = %d", id) err = comm.NewNotFoundConfErr("hero", hero_talent, id)
return nil return
} }
// 天赋指定消耗 // 天赋指定消耗
@ -341,6 +354,7 @@ func (this *configureComp) GetShopItemsConfigureByGroups(groupid int32, user *pb
) )
if v, err = this.GetConfigure(game_shopitem); err != nil { if v, err = this.GetConfigure(game_shopitem); err != nil {
this.module.Errorf("err:%v", err) this.module.Errorf("err:%v", err)
err = comm.NewNotFoundConfErr("hero", game_shopitem, groupid)
return return
} else { } else {
table = v.(*cfg.GameShopitem) table = v.(*cfg.GameShopitem)

View File

@ -814,7 +814,7 @@ func (this *ModelHero) resetTalentProperty(hero *pb.DBHero) {
for _, v := range rst { for _, v := range rst {
if v.HeroId == hero.HeroID { // 找到对应的英雄 if v.HeroId == hero.HeroID { // 找到对应的英雄
for k := range v.Talent { 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 { if conf.Hp != -1 {
attr[0] += conf.Hp attr[0] += conf.Hp
} }

View File

@ -536,7 +536,7 @@ func (this *Hero) ContinuousRestriction(uid string, heroCid string, drawCount in
iMaxCOunt := conf.DrawCardContinuousRestrictionStar5 iMaxCOunt := conf.DrawCardContinuousRestrictionStar5
if drawCount-index <= iMaxCOunt { // 连续n次还获得该英雄 直接替换其他英雄 if drawCount-index <= iMaxCOunt { // 连续n次还获得该英雄 直接替换其他英雄
_data := this.configure.GetPollByType(pool) _data, _ := this.configure.GetPollByType(pool)
if _data == nil { if _data == nil {
return heroCid return heroCid

View File

@ -33,9 +33,10 @@ func (this *apiComp) GetStoryReward(session comm.IUserSession, req *pb.LibraryGe
code = pb.ErrorCode_ReqParameterError code = pb.ErrorCode_ReqParameterError
return return
} }
favorConf := this.module.configure.GetFavorability(_heroFetter.Heroid, 1) // 取1级的就可以 favorConf, err := this.module.configure.GetFavorability(_heroFetter.Heroid, 1) // 取1级的就可以
if favorConf == nil { if err != nil {
code = pb.ErrorCode_ConfigNoFound code = pb.ErrorCode_ConfigNoFound
data.Message = err.Error()
return return
} }
// 领取传记往事id // 领取传记往事id

View File

@ -38,9 +38,10 @@ func (this *apiComp) LvReward(session comm.IUserSession, req *pb.LibraryLvReward
code = pb.ErrorCode_LibraryReward // 重复领奖 code = pb.ErrorCode_LibraryReward // 重复领奖
return return
} }
confData := this.module.configure.GetFavorability(_heroFetter.Heroid, req.Lv) confData, err := this.module.configure.GetFavorability(_heroFetter.Heroid, req.Lv)
if confData == nil { if err != nil {
code = pb.ErrorCode_ReqParameterError code = pb.ErrorCode_ReqParameterError
data.Message = err.Error()
return return
} }

View File

@ -38,9 +38,10 @@ func (this *apiComp) FetterLvUp(session comm.IUserSession, req *pb.LibraryFetter
} }
} }
fetter.Fidlv += 1 fetter.Fidlv += 1
conf := this.module.configure.GetFriendData(fetter.Fid, fetter.Fidlv) conf, e := this.module.configure.GetFriendData(fetter.Fid, fetter.Fidlv)
if len(conf) == 0 { if e != nil || len(conf) == 0 {
code = pb.ErrorCode_ConfigNoFound code = pb.ErrorCode_ConfigNoFound
data.Message = e.Error()
return return
} }

View File

@ -39,9 +39,10 @@ func (this *apiComp) UseGift(session comm.IUserSession, req *pb.LibraryUseGiftRe
return return
} }
_exp := this.module.configure.GetFavorabilityExp(_heroObj.Heroid) _exp, err := this.module.configure.GetFavorabilityExp(_heroObj.Heroid)
if len(_exp) == 0 { if err != nil {
code = pb.ErrorCode_ConfigNoFound code = pb.ErrorCode_ConfigNoFound
data.Message = err.Error()
return return
} }
maxLv = int32(len(_exp)) // 获取当前星级羁绊最大等级 maxLv = int32(len(_exp)) // 获取当前星级羁绊最大等级
@ -70,9 +71,10 @@ func (this *apiComp) UseGift(session comm.IUserSession, req *pb.LibraryUseGiftRe
} }
_heroObj.Givecount += req.Counts _heroObj.Givecount += req.Counts
// 校验是否是自己喜欢的食物 // 校验是否是自己喜欢的食物
_c := this.module.configure.GetFavorability(_heroObj.Heroid, _heroObj.Favorlv) _c, err := this.module.configure.GetFavorability(_heroObj.Heroid, _heroObj.Favorlv)
if _c == nil { if err != nil {
code = pb.ErrorCode_ConfigNoFound code = pb.ErrorCode_ConfigNoFound
data.Message = err.Error()
return return
} }
for _, v := range _c.LikesFood { // 喜欢的食物 for _, v := range _c.LikesFood { // 喜欢的食物

View File

@ -2,6 +2,7 @@ package library
import ( import (
"fmt" "fmt"
"go_dreamfactory/comm"
"go_dreamfactory/lego/core" "go_dreamfactory/lego/core"
"go_dreamfactory/lego/sys/log" "go_dreamfactory/lego/sys/log"
"go_dreamfactory/modules" "go_dreamfactory/modules"
@ -62,9 +63,16 @@ func (this *configureComp) SetFavorability() {
} }
} }
func (this *configureComp) GetFavorability(hid string, lv int32) *cfg.GameFavorabilityData { func (this *configureComp) GetFavorability(hid string, lv int32) (conf *cfg.GameFavorabilityData, err error) {
var (
return this.favorability[hid+"-"+strconv.Itoa(int(lv))] 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() { func (this *configureComp) SetFriendData() {
@ -90,8 +98,16 @@ func (this *configureComp) SetFriendData() {
} }
// id:羁绊id lv 羁绊等级 // id:羁绊id lv 羁绊等级
func (this *configureComp) GetFriendData(id int32, lv int32) []*cfg.GameFriendsData { func (this *configureComp) GetFriendData(id int32, lv int32) (conf []*cfg.GameFriendsData, err error) {
return this.friend[int64(id)<<8+int64(lv)] 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 // 通过英雄获取当前英雄的所有羁绊ID
@ -116,7 +132,12 @@ func (this *configureComp) GetConfigure(name string) (v interface{}, err error)
return configure.GetConfigure(name) return configure.GetConfigure(name)
} }
func (this *configureComp) GetFavorabilityExp(hid string) []int32 { func (this *configureComp) GetFavorabilityExp(hid string) (conf []int32, err error) {
var (
return this.favorLvExp[hid] ok bool
)
if conf, ok = this.favorLvExp[hid]; !ok {
err = comm.NewNotFoundConfErr("hero", game_favorability, hid)
}
return
} }

View File

@ -35,7 +35,7 @@ func (this *apiComp) GetList(session comm.IUserSession, req *pb.MlineGetListReq)
} }
} }
if len(rsp.Data) == 0 { // 什么数据都没有 创建一条 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 { if stageConf := this.module.configure.GetFirstStageIDByChapter(chapterConf.Id); stageConf != nil {
newData := &pb.DBMline{ newData := &pb.DBMline{
Id: primitive.NewObjectID().Hex(), Id: primitive.NewObjectID().Hex(),
@ -52,6 +52,7 @@ func (this *apiComp) GetList(session comm.IUserSession, req *pb.MlineGetListReq)
} }
} else { } else {
code = pb.ErrorCode_ConfigNoFound code = pb.ErrorCode_ConfigNoFound
data.Message = err.Error()
return return
} }
} }

View File

@ -1,6 +1,7 @@
package mline package mline
import ( import (
"go_dreamfactory/comm"
"go_dreamfactory/lego/core" "go_dreamfactory/lego/core"
"go_dreamfactory/modules" "go_dreamfactory/modules"
"go_dreamfactory/sys/configure" "go_dreamfactory/sys/configure"
@ -85,18 +86,21 @@ func (this *configureComp) GetPreMainChapter(stageId int32) (preStageID int32) {
} }
return return
} }
func (this *configureComp) GetFirstChapterIDByType(iType int32) *cfg.GameMainChapterData { func (this *configureComp) GetFirstChapterIDByType(iType int32) (conf *cfg.GameMainChapterData, err error) {
if v, err := this.GetConfigure(game_mainchapter); err == nil { var (
v interface{}
)
if v, err = this.GetConfigure(game_mainchapter); err == nil {
if configure, ok := v.(*cfg.GameMainChapter); ok { if configure, ok := v.(*cfg.GameMainChapter); ok {
for _, v := range configure.GetDataList() { for _, conf = range configure.GetDataList() {
if v.ChapterType == iType { if conf.ChapterType == iType {
return v return
} }
} }
} }
} }
return nil err = comm.NewNotFoundConfErr("mline", game_mainchapter, iType)
return
} }
func (this *configureComp) GetFirstStageIDByChapter(chapterID int32) *cfg.GameMainStageData { func (this *configureComp) GetFirstStageIDByChapter(chapterID int32) *cfg.GameMainStageData {

View File

@ -138,6 +138,7 @@ func (this *apiComp) Getlist(session comm.IUserSession, req *pb.ShopGetListReq)
for _, v := range shopconf.Shopitem { for _, v := range shopconf.Shopitem {
if _items, err = this.module.configure.GetShopItemsConfigureByGroups(v, udata); err != nil || len(_items) == 0 { if _items, err = this.module.configure.GetShopItemsConfigureByGroups(v, udata); err != nil || len(_items) == 0 {
code = pb.ErrorCode_SystemError code = pb.ErrorCode_SystemError
data.Message = err.Error()
return return
} }
items = append(items, randomGoods(_items)) items = append(items, randomGoods(_items))

View File

@ -2,6 +2,7 @@ package shop
import ( import (
"fmt" "fmt"
"go_dreamfactory/comm"
"go_dreamfactory/lego/core" "go_dreamfactory/lego/core"
"go_dreamfactory/modules" "go_dreamfactory/modules"
"go_dreamfactory/pb" "go_dreamfactory/pb"
@ -75,6 +76,7 @@ func (this *configureComp) GetShopItemsConfigureByGroups(groupid int32, user *pb
) )
if v, err = this.GetConfigure(game_shopitem); err != nil { if v, err = this.GetConfigure(game_shopitem); err != nil {
this.module.Errorf("err:%v", err) this.module.Errorf("err:%v", err)
err = comm.NewNotFoundConfErr("hero", game_shopitem, groupid)
return return
} else { } else {
table = v.(*cfg.GameShopitem) table = v.(*cfg.GameShopitem)