From 732398c5eae4e3fbeb0aebbbd5c4388e3985bfd4 Mon Sep 17 00:00:00 2001 From: meixiongfeng <766881921@qq.com> Date: Wed, 31 May 2023 18:17:21 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E6=95=B4=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/caravan/api_buyorsell.go | 5 +- modules/caravan/api_gotocity.go | 5 +- modules/caravan/comp_configure.go | 22 +++--- modules/hero/configure_comp.go | 2 +- modules/hunting/api_challenge.go | 4 +- modules/hunting/api_challengeover.go | 10 ++- modules/hunting/comp_configure.go | 13 +++- modules/hunting/model_hunting.go | 2 +- modules/hunting/module.go | 2 +- modules/library/api_lvup.go | 5 +- modules/privilege/configure.go | 23 +++--- modules/shop/api_getlist.go | 5 +- modules/smithy/api_atlasactivate.go | 8 +- modules/smithy/api_atlasaward.go | 4 +- modules/smithy/api_forgeequip.go | 18 +++-- modules/smithy/api_receive.go | 6 +- modules/smithy/api_rise.go | 2 +- modules/smithy/api_stoveup.go | 16 +++- modules/smithy/api_toolsup.go | 16 +++- modules/smithy/api_trade.go | 8 +- modules/smithy/comp_configure.go | 112 +++++++++++++++++++-------- modules/smithy/model_atlas.go | 2 +- modules/smithy/model_stove.go | 4 +- modules/smithy/model_task.go | 2 +- modules/smithy/module.go | 4 +- modules/viking/api_challenge.go | 16 ++-- modules/viking/api_challengeover.go | 9 ++- modules/viking/comp_configure.go | 12 ++- modules/viking/model_viking.go | 7 +- modules/viking/module.go | 10 +-- 30 files changed, 232 insertions(+), 122 deletions(-) diff --git a/modules/caravan/api_buyorsell.go b/modules/caravan/api_buyorsell.go index e893aca73..1c7ebd664 100644 --- a/modules/caravan/api_buyorsell.go +++ b/modules/caravan/api_buyorsell.go @@ -85,7 +85,10 @@ func (this *apiComp) BuyOrSell(session comm.IUserSession, req *pb.CaravanBuyOrSe } } else { code = pb.ErrorCode_DataNotFound - data.Message = e.Error() + data = &pb.ErrorData{ + Title: pb.GetErrorCodeMsg(code), + Message: err.Error(), + } } } addScore += price * v // 卖出收益 diff --git a/modules/caravan/api_gotocity.go b/modules/caravan/api_gotocity.go index a7f8f4165..22a2fe773 100644 --- a/modules/caravan/api_gotocity.go +++ b/modules/caravan/api_gotocity.go @@ -60,7 +60,10 @@ func (this *apiComp) GotoCity(session comm.IUserSession, req *pb.CaravanGotoCity // } } else { code = pb.ErrorCode_DataNotFound - data.Message = e.Error() + data = &pb.ErrorData{ + Title: pb.GetErrorCodeMsg(code), + Message: e.Error(), + } } } if list.Curcity == req.City { diff --git a/modules/caravan/comp_configure.go b/modules/caravan/comp_configure.go index 7f9ce2f29..da9dfc71b 100644 --- a/modules/caravan/comp_configure.go +++ b/modules/caravan/comp_configure.go @@ -9,6 +9,8 @@ import ( cfg "go_dreamfactory/sys/configure/structs" ) +var moduleName = "caravan" + const ( game_caravan = "game_caravancity.json" game_caravan_lv = "game_caravanlv.json" @@ -62,13 +64,13 @@ func (this *configureComp) GetCaravanCity(cityId int32) (data *cfg.GameCaravanCi if v, err = this.GetConfigure(game_caravan); err == nil { if configure, ok := v.(*cfg.GameCaravanCity); ok { if data = configure.Get(cityId); data == nil { - err = comm.NewNotFoundConfErr("caravan", game_caravan, cityId) + err = comm.NewNotFoundConfErr(moduleName, game_caravan, cityId) this.module.Errorln(err) } return } } - err = comm.NewNotFoundConfErr("caravan", game_caravan, cityId) + err = comm.NewNotFoundConfErr(moduleName, game_caravan, cityId) return } @@ -80,13 +82,13 @@ func (this *configureComp) GetCaravanLv(lv int32) (data *cfg.GameCaravanLvData, if v, err = this.GetConfigure(game_caravan_lv); err == nil { if configure, ok := v.(*cfg.GameCaravanLv); ok { if data = configure.Get(lv); data == nil { - err = comm.NewNotFoundConfErr("caravan", game_caravan_lv, lv) + err = comm.NewNotFoundConfErr(moduleName, game_caravan_lv, lv) this.module.Errorln(err) } return } } - err = comm.NewNotFoundConfErr("caravan", game_caravan_lv, lv) + err = comm.NewNotFoundConfErr(moduleName, game_caravan_lv, lv) return } @@ -97,13 +99,13 @@ func (this *configureComp) GetCaravanGoods(itemId int32) (data *cfg.GameCaravanT if v, err = this.GetConfigure(game_caravan_thing); err == nil { if configure, ok := v.(*cfg.GameCaravanThing); ok { if data = configure.Get(itemId); data == nil { - err = comm.NewNotFoundConfErr("caravan", game_caravan_thing, itemId) + err = comm.NewNotFoundConfErr(moduleName, game_caravan_thing, itemId) this.module.Errorln(err) } return } } - err = comm.NewNotFoundConfErr("caravan", game_caravan_thing, itemId) + err = comm.NewNotFoundConfErr(moduleName, game_caravan_thing, itemId) return } @@ -144,13 +146,13 @@ func (this *configureComp) GetCaravanEventById(id int32) (data *cfg.GameCaravanE if v, err = this.GetConfigure(game_caravan_event); err == nil { if configure, ok := v.(*cfg.GameCaravanEvent); ok { if data = configure.Get(id); data == nil { - err = comm.NewNotFoundConfErr("caravan", game_caravan_event, id) + err = comm.NewNotFoundConfErr(moduleName, game_caravan_event, id) this.module.Errorln(err) } return } } - err = comm.NewNotFoundConfErr("caravan", game_caravan_event, id) + err = comm.NewNotFoundConfErr(moduleName, game_caravan_event, id) return } @@ -200,11 +202,11 @@ func (this *configureComp) GetCaravanRank(index int32) (reward *cfg.GameCaravanR if v, err := this.GetConfigure(game_caravan_rank); err == nil { if configure, ok := v.(*cfg.GameCaravanRank); ok { if reward = configure.Get(index); reward == nil { - err = comm.NewNotFoundConfErr("caravan", game_caravan_rank, index) + err = comm.NewNotFoundConfErr(moduleName, game_caravan_rank, index) this.module.Errorln(err) } } } - err = comm.NewNotFoundConfErr("caravan", game_caravan_rank, index) + err = comm.NewNotFoundConfErr(moduleName, game_caravan_rank, index) return } diff --git a/modules/hero/configure_comp.go b/modules/hero/configure_comp.go index 6febdc4f6..0ca61e03f 100644 --- a/modules/hero/configure_comp.go +++ b/modules/hero/configure_comp.go @@ -291,7 +291,7 @@ func (this *configureComp) GetHeroFucionConfig(cid string) (data *cfg.GameHerofu ) if v, err = this.GetConfigure(hero_fusion); err == nil { if configure, ok := v.(*cfg.GameHerofusion); ok { - if data = configure.Get(cid); data != nil { + if data = configure.Get(cid); data == nil { err = comm.NewNotFoundConfErr("hero", hero_fusion, cid) } return diff --git a/modules/hunting/api_challenge.go b/modules/hunting/api_challenge.go index d14ae74df..fd73d9be1 100644 --- a/modules/hunting/api_challenge.go +++ b/modules/hunting/api_challenge.go @@ -30,8 +30,8 @@ func (this *apiComp) Challenge(session comm.IUserSession, req *pb.HuntingChallen code = pb.ErrorCode_PagodaNotFound return } - cfgData := this.module.configure.GetHuntingBossConfigData(req.BossType, req.Difficulty) - if cfgData == nil { + cfgData, err := this.module.configure.GetHuntingBossConfigData(req.BossType, req.Difficulty) + if err != nil { code = pb.ErrorCode_ConfigNoFound return } diff --git a/modules/hunting/api_challengeover.go b/modules/hunting/api_challengeover.go index b5bff4b90..b046c407c 100644 --- a/modules/hunting/api_challengeover.go +++ b/modules/hunting/api_challengeover.go @@ -1,7 +1,6 @@ package hunting import ( - "fmt" "go_dreamfactory/comm" "go_dreamfactory/pb" cfg "go_dreamfactory/sys/configure/structs" @@ -41,10 +40,13 @@ func (this *apiComp) ChallengeOver(session comm.IUserSession, req *pb.HuntingCha code = pb.ErrorCode_PagodaNotFound return } - cfgHunting := this.module.configure.GetHuntingBossConfigData(req.BossType, req.Difficulty) - if cfgHunting == nil { + cfgHunting, err := this.module.configure.GetHuntingBossConfigData(req.BossType, req.Difficulty) + if err != nil { code = pb.ErrorCode_ConfigNoFound - data.Message = fmt.Sprintf("GetHuntingBossConfig No't Found:BossType = %d,Difficulty = %d", req.BossType, req.Difficulty) + data = &pb.ErrorData{ + Title: pb.GetErrorCodeMsg(code), + Message: err.Error(), + } return } diff --git a/modules/hunting/comp_configure.go b/modules/hunting/comp_configure.go index 1c9dbe93f..92a94dcba 100644 --- a/modules/hunting/comp_configure.go +++ b/modules/hunting/comp_configure.go @@ -1,6 +1,8 @@ package hunting import ( + "fmt" + "go_dreamfactory/comm" "go_dreamfactory/lego/core" "go_dreamfactory/lego/sys/log" "go_dreamfactory/modules" @@ -9,6 +11,8 @@ import ( "sync" ) +var moduleName = "hunting" + const ( game_huntingboss = "game_huntingboss.json" // game_challenge = "game_huntingchallenge.json" @@ -49,9 +53,12 @@ func (this *configureComp) Init(service core.IService, module core.IModule, comp } // 参数: boss类型 难度 -func (this *configureComp) GetHuntingBossConfigData(bossType int32, difficulty int32) (data *cfg.GameHuntingBossData) { - - return this._huntingMap[int64(bossType<<16)+int64(difficulty)] +func (this *configureComp) GetHuntingBossConfigData(bossType int32, difficulty int32) (data *cfg.GameHuntingBossData, err error) { + data = this._huntingMap[int64(bossType<<16)+int64(difficulty)] + if data == nil { + err = comm.NewNotFoundConfErr(moduleName, game_huntingboss, fmt.Errorf("bossId:%d,difficulty:%d", bossType, difficulty)) + } + return } //加载多个配置文件 diff --git a/modules/hunting/model_hunting.go b/modules/hunting/model_hunting.go index 699f76c9a..b9f577e19 100644 --- a/modules/hunting/model_hunting.go +++ b/modules/hunting/model_hunting.go @@ -59,7 +59,7 @@ func (this *modelHunting) getHuntingList(uid string) (result *pb.DBHunting, err func (this *modelHunting) checkReddot32(session comm.IUserSession) bool { if list, err := this.module.modelHunting.getHuntingList(session.GetUserId()); err == nil { if _, ok := list.Boss[1]; ok { - conf := this.module.configure.GetHuntingBossConfigData(1, 1) + conf, _ := this.module.configure.GetHuntingBossConfigData(1, 1) if code := this.module.CheckRes(session, conf.PsConsume); code == pb.ErrorCode_Success { return true } diff --git a/modules/hunting/module.go b/modules/hunting/module.go index 0ecbbef81..24032ff69 100644 --- a/modules/hunting/module.go +++ b/modules/hunting/module.go @@ -187,7 +187,7 @@ func (this *Hunting) CompleteAllLevel(session comm.IUserSession) (code pb.ErrorC // 查配置获取每个Boss的最大难度 for k := range list.Boss { for i := 1; ; i++ { - conf := this.configure.GetHuntingBossConfigData(k, int32(i)) + conf, _ := this.configure.GetHuntingBossConfigData(k, int32(i)) if conf == nil { list.Boss[k] = int32(i - 1) } diff --git a/modules/library/api_lvup.go b/modules/library/api_lvup.go index 8df8c7741..3fbc55c34 100644 --- a/modules/library/api_lvup.go +++ b/modules/library/api_lvup.go @@ -41,7 +41,10 @@ func (this *apiComp) FetterLvUp(session comm.IUserSession, req *pb.LibraryFetter conf, e := this.module.configure.GetFriendData(fetter.Fid, fetter.Fidlv) if e != nil || len(conf) == 0 { code = pb.ErrorCode_ConfigNoFound - data.Message = e.Error() + data = &pb.ErrorData{ + Title: pb.GetErrorCodeMsg(code), + Message: e.Error(), + } return } diff --git a/modules/privilege/configure.go b/modules/privilege/configure.go index 9ffd4d210..1f9202227 100644 --- a/modules/privilege/configure.go +++ b/modules/privilege/configure.go @@ -1,7 +1,7 @@ package privilege import ( - "fmt" + "go_dreamfactory/comm" "go_dreamfactory/lego/core" "go_dreamfactory/lego/sys/log" "go_dreamfactory/modules" @@ -10,6 +10,8 @@ import ( "sync" ) +var moduleName = "privilege" + const ( game_privilegecard = "game_privilegecard.json" game_privilege = "game_privilege.json" @@ -52,21 +54,18 @@ func (this *configureComp) Init(service core.IService, module core.IModule, comp return } -func (this *configureComp) GetPrivilegeCard(id string) (configure *cfg.GamePrivilegeCardData, err error) { +func (this *configureComp) GetPrivilegeCard(id string) (data *cfg.GamePrivilegeCardData, err error) { var ( - v interface{} - ok bool + v interface{} ) - if v, err = this.GetConfigure(game_privilegecard); err != nil { - this.module.Errorf("err:%v", err) - return - } else { - if configure, ok = v.(*cfg.GamePrivilegeCard).GetDataMap()[id]; !ok { - err = fmt.Errorf("GamePrivilegeCardData not found:%s ", id) - this.module.Errorf("err:%v", err) - return + if v, err = this.GetConfigure(game_privilegecard); err == nil { + if configure, ok := v.(*cfg.GamePrivilegeCard); !ok { + if data = configure.Get(id); data != nil { + return + } } } + err = comm.NewNotFoundConfErr(moduleName, game_privilegecard, id) return } diff --git a/modules/shop/api_getlist.go b/modules/shop/api_getlist.go index a8e709f2d..20157123d 100644 --- a/modules/shop/api_getlist.go +++ b/modules/shop/api_getlist.go @@ -138,7 +138,10 @@ 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() + data = &pb.ErrorData{ + Title: pb.GetErrorCodeMsg(code), + Message: err.Error(), + } return } items = append(items, randomGoods(_items)) diff --git a/modules/smithy/api_atlasactivate.go b/modules/smithy/api_atlasactivate.go index b01c8916c..4867d573e 100644 --- a/modules/smithy/api_atlasactivate.go +++ b/modules/smithy/api_atlasactivate.go @@ -28,9 +28,13 @@ func (this *apiComp) AtlasActivate(session comm.IUserSession, req *pb.SmithyAtla code = pb.ErrorCode_DBError return } - conf := this.module.configure.GetSmithyAtlasConf(req.Id) - if conf == nil { + conf, err := this.module.configure.GetSmithyAtlasConf(req.Id) + if err != nil { code = pb.ErrorCode_SmithyNoFoundAtlas + data = &pb.ErrorData{ + Title: pb.GetErrorCodeMsg(code), + Message: err.Error(), + } return } if conf.TypeId == 1 { diff --git a/modules/smithy/api_atlasaward.go b/modules/smithy/api_atlasaward.go index 185e972af..1a52c134c 100644 --- a/modules/smithy/api_atlasaward.go +++ b/modules/smithy/api_atlasaward.go @@ -28,8 +28,8 @@ func (this *apiComp) AtlasAward(session comm.IUserSession, req *pb.SmithyAtlasAw return } for { - conf := this.module.configure.GetSmithyAtlasLvConf(atlas.Award + 1) - if conf == nil { + conf, err := this.module.configure.GetSmithyAtlasLvConf(atlas.Award + 1) + if err != nil { break } if atlas.Score < conf.AtlasScore { // 校验积分够不够 diff --git a/modules/smithy/api_forgeequip.go b/modules/smithy/api_forgeequip.go index 5037aa08e..1fc0c9b21 100644 --- a/modules/smithy/api_forgeequip.go +++ b/modules/smithy/api_forgeequip.go @@ -46,8 +46,8 @@ func (this *apiComp) ForgeEquip(session comm.IUserSession, req *pb.SmithyForgeEq code = pb.ErrorCode_DBError return } - reelcfg := this.module.configure.GetSmithyReelConfigData(req.ReelId) - if reelcfg == nil { + reelcfg, err := this.module.configure.GetSmithyReelConfigData(req.ReelId) + if err != nil { code = pb.ErrorCode_ReqParameterError // 没有找到该类型的图纸信息 return } @@ -149,10 +149,14 @@ func (this *apiComp) ForgeEquip(session comm.IUserSession, req *pb.SmithyForgeEq hitLen int32 ) for k, v := range req.Hit { - confMake := this.module.configure.GetSmithyMake(k) - if confMake == nil { + confMake, err := this.module.configure.GetSmithyMake(k) + if err != nil { code = pb.ErrorCode_ConfigNoFound this.module.Errorf("GetSmithyMake配置没找到:%d", k) + data = &pb.ErrorData{ + Title: pb.GetErrorCodeMsg(code), + Message: err.Error(), + } return } hitLen += v @@ -170,8 +174,8 @@ func (this *apiComp) ForgeEquip(session comm.IUserSession, req *pb.SmithyForgeEq if stove.Hit[k] != v { var curProbability int32 for k, v := range stove.Hit { - confMake := this.module.configure.GetSmithyMake(k) - if confMake == nil { + confMake, err := this.module.configure.GetSmithyMake(k) + if err != nil { break } curProbability += v * confMake.Probability @@ -226,7 +230,7 @@ func (this *apiComp) ForgeEquip(session comm.IUserSession, req *pb.SmithyForgeEq } - if stoveLvConf := this.module.configure.GetSmithyStoveConf(stove.Lv); stoveLvConf != nil { + if stoveLvConf, err := this.module.configure.GetSmithyStoveConf(stove.Lv); err == nil { maxT = stoveLvConf.MaxTemperature } if stove.RecoveTime == 0 && stove.Temperature <= maxT { diff --git a/modules/smithy/api_receive.go b/modules/smithy/api_receive.go index 1c19ec7d2..00a21ee78 100644 --- a/modules/smithy/api_receive.go +++ b/modules/smithy/api_receive.go @@ -31,8 +31,12 @@ func (this *apiComp) TaskAward(session comm.IUserSession, req *pb.SmithyTaskAwar resp := &pb.SmithyTaskAwardResp{ TaskId: req.TaskId, } - if conf := this.module.configure.GetSmithyTask(req.TaskId); conf == nil { + if conf, err := this.module.configure.GetSmithyTask(req.TaskId); err != nil { code = pb.ErrorCode_ConfigNoFound + data = &pb.ErrorData{ + Title: pb.GetErrorCodeMsg(code), + Message: err.Error(), + } return } else { if code = this.module.DispenseRes(session, conf.Reword, true); code != pb.ErrorCode_Success { diff --git a/modules/smithy/api_rise.go b/modules/smithy/api_rise.go index d33ada951..b26c25638 100644 --- a/modules/smithy/api_rise.go +++ b/modules/smithy/api_rise.go @@ -29,7 +29,7 @@ func (this *apiComp) Rise(session comm.IUserSession, req *pb.SmithyRiseReq) (cod code = pb.ErrorCode_DBError return } - if conf := this.module.configure.GetSmithyStoveConf(stove.Lv); conf != nil { + if conf, err := this.module.configure.GetSmithyStoveConf(stove.Lv); err == nil { if stove.Temperature >= conf.MaxTemperature { // 已经达到最大的温度值了 code = pb.ErrorCode_SmithyMaxTemperature return diff --git a/modules/smithy/api_stoveup.go b/modules/smithy/api_stoveup.go index c7336cfdb..1655daf63 100644 --- a/modules/smithy/api_stoveup.go +++ b/modules/smithy/api_stoveup.go @@ -23,14 +23,22 @@ func (this *apiComp) StoveUp(session comm.IUserSession, req *pb.SmithyStoveUpReq code = pb.ErrorCode_DBError return } - conf := this.module.configure.GetSmithyStoveConf(stove.Lv) - if conf == nil { + conf, err := this.module.configure.GetSmithyStoveConf(stove.Lv) + if err != nil { code = pb.ErrorCode_ConfigNoFound + data = &pb.ErrorData{ + Title: pb.GetErrorCodeMsg(code), + Message: err.Error(), + } return } - nexConf := this.module.configure.GetSmithyStoveConf(stove.Lv + 1) - if nexConf == nil { + _, err = this.module.configure.GetSmithyStoveConf(stove.Lv + 1) + if err != nil { code = pb.ErrorCode_SmithyStoveMaxLv + data = &pb.ErrorData{ + Title: pb.GetErrorCodeMsg(code), + Message: err.Error(), + } return } if code = this.module.ConsumeRes(session, conf.UpMaterial, true); code != pb.ErrorCode_Success { diff --git a/modules/smithy/api_toolsup.go b/modules/smithy/api_toolsup.go index 8d127484c..f37914bfc 100644 --- a/modules/smithy/api_toolsup.go +++ b/modules/smithy/api_toolsup.go @@ -25,9 +25,13 @@ func (this *apiComp) ToolsUp(session comm.IUserSession, req *pb.SmithyToolsUpReq code = pb.ErrorCode_DBError return } - conf := this.module.configure.GetSmithyToolsData(req.Id) - if conf == nil { + conf, err := this.module.configure.GetSmithyToolsData(req.Id) + if err != nil { code = pb.ErrorCode_ReqParameterError + data = &pb.ErrorData{ + Title: pb.GetErrorCodeMsg(code), + Message: err.Error(), + } return } // 校验前置条件 @@ -35,9 +39,13 @@ func (this *apiComp) ToolsUp(session comm.IUserSession, req *pb.SmithyToolsUpReq if stove.Skill[conf.SkillType]+1 == conf.SkillLv { // 必须是一级一级的升级(即当前等级的下一级) // 判断前置条件 if conf.Preconditions != 0 { - poreConf := this.module.configure.GetSmithyToolsData(conf.Preconditions) - if poreConf == nil { // 配置没找到 + poreConf, err := this.module.configure.GetSmithyToolsData(conf.Preconditions) + if err != nil { // 配置没找到 code = pb.ErrorCode_ConfigNoFound + data = &pb.ErrorData{ + Title: pb.GetErrorCodeMsg(code), + Message: err.Error(), + } return } if _, ok := stove.Skill[poreConf.SkillType]; !ok { diff --git a/modules/smithy/api_trade.go b/modules/smithy/api_trade.go index 421574f66..a93856dd7 100644 --- a/modules/smithy/api_trade.go +++ b/modules/smithy/api_trade.go @@ -36,9 +36,13 @@ func (this *apiComp) Sell(session comm.IUserSession, req *pb.SmithySellReq) (cod return } - conf := this.module.configure.GetSmithyCustomerConf(req.CustomerId) - if conf == nil { + conf, err := this.module.configure.GetSmithyCustomerConf(req.CustomerId) + if err != nil { code = pb.ErrorCode_ConfigNoFound + data = &pb.ErrorData{ + Title: pb.GetErrorCodeMsg(code), + Message: err.Error(), + } return } diff --git a/modules/smithy/comp_configure.go b/modules/smithy/comp_configure.go index 7996a1471..c647654b5 100644 --- a/modules/smithy/comp_configure.go +++ b/modules/smithy/comp_configure.go @@ -1,6 +1,7 @@ package smithy import ( + "go_dreamfactory/comm" "go_dreamfactory/lego/core" "go_dreamfactory/lego/sys/log" "go_dreamfactory/modules" @@ -9,6 +10,8 @@ import ( "sync" ) +var moduleName = "smithy" + const ( //game_smithy = "game_smithy.json" //game_smithystoveold = "game_smithystove.json" @@ -80,13 +83,19 @@ func (this *configureComp) GetConfigure(name string) (v interface{}, err error) } // 获取图纸信息 -func (this *configureComp) GetSmithyReelConfigData(id int32) (data *cfg.GameNewSmithyData) { - if v, err := this.GetConfigure(game_smithyreel); err == nil { +func (this *configureComp) GetSmithyReelConfigData(id int32) (data *cfg.GameNewSmithyData, err error) { + var ( + v interface{} + ) + if v, err = this.GetConfigure(game_smithyreel); err == nil { if configure, ok := v.(*cfg.GameNewSmithy); ok { - data = configure.Get(int32(id)) + if data = configure.Get(int32(id)); data == nil { + err = comm.NewNotFoundConfErr(moduleName, game_smithyreel, id) + } return } } + err = comm.NewNotFoundConfErr(moduleName, game_smithyreel, id) return } @@ -172,59 +181,86 @@ func (this *configureComp) GetSmithyCustomerConfList() (data []*cfg.GameSmithyCu return } -func (this *configureComp) GetSmithyCustomerConf(id int32) *cfg.GameSmithyCustomerData { - if v, err := this.GetConfigure(game_smithycustomer); err == nil { +func (this *configureComp) GetSmithyCustomerConf(id int32) (data *cfg.GameSmithyCustomerData, err error) { + var ( + v interface{} + ) + if v, err = this.GetConfigure(game_smithycustomer); err == nil { if configure, ok := v.(*cfg.GameSmithyCustomer); ok { - return configure.GetDataMap()[id] + if data = configure.Get(id); data == nil { + err = comm.NewNotFoundConfErr(moduleName, game_smithycustomer, id) + } + return } } - return nil + err = comm.NewNotFoundConfErr(moduleName, game_smithycustomer, id) + return } // 获取铁匠铺工作台信息 -func (this *configureComp) GetSmithyToolsData(id int32) (data *cfg.GameSmithyToolData) { - if v, err := this.GetConfigure(game_smithytools); err == nil { +func (this *configureComp) GetSmithyToolsData(id int32) (data *cfg.GameSmithyToolData, err error) { + var ( + v interface{} + ) + if v, err = this.GetConfigure(game_smithytools); err == nil { if configure, ok := v.(*cfg.GameSmithyTool); ok { - data = configure.Get(int(id)) + if data = configure.Get(int(id)); data == nil { + err = comm.NewNotFoundConfErr(moduleName, game_smithytools, id) + } return - } } - this.module.Errorf("GetSmithyToolsData notfound id:%d", id) - return nil + err = comm.NewNotFoundConfErr(moduleName, game_smithytools, id) + return } -func (this *configureComp) GetSmithyStoveConf(level int32) (data *cfg.GameSmithyStoveV1Data) { - if v, err := this.GetConfigure(game_smithystove); err == nil { +func (this *configureComp) GetSmithyStoveConf(level int32) (data *cfg.GameSmithyStoveV1Data, err error) { + var ( + v interface{} + ) + if v, err = this.GetConfigure(game_smithystove); err == nil { if configure, ok := v.(*cfg.GameSmithyStoveV1); ok { - data = configure.Get(int32(level)) + if data = configure.Get(int32(level)); data == nil { + err = comm.NewNotFoundConfErr(moduleName, game_smithystove, level) + } return } } - this.module.Errorf("GetSmithyStoveConf notfound level:%d", level) + err = comm.NewNotFoundConfErr(moduleName, game_smithystove, level) return } // 获取图鉴信息 -func (this *configureComp) GetSmithyAtlasConf(id string) (data *cfg.GameSmithyAtlasData) { - if v, err := this.GetConfigure(game_smithyatlas); err == nil { +func (this *configureComp) GetSmithyAtlasConf(id string) (data *cfg.GameSmithyAtlasData, err error) { + var ( + v interface{} + ) + if v, err = this.GetConfigure(game_smithyatlas); err == nil { if configure, ok := v.(*cfg.GameSmithyAtlas); ok { - data = configure.Get(id) + if data = configure.Get(id); data == nil { + err = comm.NewNotFoundConfErr(moduleName, game_smithyatlas, id) + } return } } - this.module.Errorf("GetSmithyAtlasConf notfound id:%d", id) + err = comm.NewNotFoundConfErr(moduleName, game_smithyatlas, id) + return } -func (this *configureComp) GetSmithyAtlasLvConf(lv int32) (data *cfg.GameSmithyAtlasLvData) { - if v, err := this.GetConfigure(game_smithyatlaslv); err == nil { +func (this *configureComp) GetSmithyAtlasLvConf(lv int32) (data *cfg.GameSmithyAtlasLvData, err error) { + var ( + v interface{} + ) + if v, err = this.GetConfigure(game_smithyatlaslv); err == nil { if configure, ok := v.(*cfg.GameSmithyAtlasLv); ok { - data = configure.Get(lv) + if data = configure.Get(lv); data == nil { + err = comm.NewNotFoundConfErr(moduleName, game_smithyatlaslv, lv) + } return } } - this.module.Errorf("GetSmithyAtlasLvConf notfound lv:%d", lv) + err = comm.NewNotFoundConfErr(moduleName, game_smithyatlaslv, lv) return } @@ -250,24 +286,34 @@ func (this *configureComp) LoadSmithyAtlasScoreConf() { } // 获取图鉴任务配置 -func (this *configureComp) GetSmithyTask(taskId int32) (data *cfg.GameSmithyTaskData) { - if v, err := this.GetConfigure(game_smithytask); err == nil { +func (this *configureComp) GetSmithyTask(taskId int32) (data *cfg.GameSmithyTaskData, err error) { + var ( + v interface{} + ) + if v, err = this.GetConfigure(game_smithytask); err == nil { if configure, ok := v.(*cfg.GameSmithyTask); ok { - data = configure.Get(taskId) + if data = configure.Get(taskId); data == nil { + err = comm.NewNotFoundConfErr(moduleName, game_smithytask, taskId) + } return } } - this.module.Errorf("GetSmithyTask notfound taskId:%d", taskId) + err = comm.NewNotFoundConfErr(moduleName, game_smithytask, taskId) return } -func (this *configureComp) GetSmithyMake(cid int32) (data *cfg.GameSmithyMakeData) { - if v, err := this.GetConfigure(game_smithymake); err == nil { +func (this *configureComp) GetSmithyMake(cid int32) (data *cfg.GameSmithyMakeData, err error) { + var ( + v interface{} + ) + if v, err = this.GetConfigure(game_smithymake); err == nil { if configure, ok := v.(*cfg.GameSmithyMake); ok { - data = configure.Get(cid) + if data = configure.Get(cid); data == nil { + err = comm.NewNotFoundConfErr(moduleName, game_smithymake, cid) + } return } } - this.module.Errorf("GetSmithyMake notfound taskId:%d", cid) + err = comm.NewNotFoundConfErr(moduleName, game_smithymake, cid) return } diff --git a/modules/smithy/model_atlas.go b/modules/smithy/model_atlas.go index 5d0fd4f95..225ae9cc3 100644 --- a/modules/smithy/model_atlas.go +++ b/modules/smithy/model_atlas.go @@ -64,7 +64,7 @@ func (this *modelAtlas) CheckActivateAtlas(uid string, id string, lv int32, qual list *pb.DBAtlas err error ) - if atlasConf = this.module.configure.GetSmithyAtlasConf(id); atlasConf == nil { + if atlasConf, err = this.module.configure.GetSmithyAtlasConf(id); err != nil { return false } if list, err = this.module.modelAtlas.getSmithyAtlasList(uid); err != nil { diff --git a/modules/smithy/model_stove.go b/modules/smithy/model_stove.go index 6b22b3ee1..d315c1509 100644 --- a/modules/smithy/model_stove.go +++ b/modules/smithy/model_stove.go @@ -48,7 +48,7 @@ func (this *modelStove) getSmithyStoveList(uid string) (result *pb.DBStove, err result.Lv = 1 result.RecoveTime = 0 - if conf := this.module.configure.GetSmithyStoveConf(result.Lv); conf != nil { // 获取1级炉子温度配置 + if conf, _ := this.module.configure.GetSmithyStoveConf(result.Lv); conf != nil { // 获取1级炉子温度配置 result.Temperature = conf.MaxTemperature } if err = this.Add(uid, result); err != nil { @@ -135,7 +135,7 @@ func (this *modelStove) CheckForgeConsume(reelId int32, lv int32) (atn []*cfg.Ga // 计算恢复进度 func (this *modelStove) calculationRecoveryT(uid string, stove *pb.DBStove) { - if conf := this.module.configure.GetSmithyStoveConf(stove.Lv); conf != nil { + if conf, _ := this.module.configure.GetSmithyStoveConf(stove.Lv); conf != nil { if stove.Temperature < conf.MaxTemperature { // 小于最高温度就开始恢复 if addT := (configure.Now().Unix() - stove.RecoveTime) / int64(conf.TemperatureRecovery); addT > 0 { diff --git a/modules/smithy/model_task.go b/modules/smithy/model_task.go index 4f9b785a5..ec7a8e398 100644 --- a/modules/smithy/model_task.go +++ b/modules/smithy/model_task.go @@ -76,7 +76,7 @@ func (this *modelTask) updateTaskRecord(uid string, taskId int32) error { // 检查任务状态 func (this *modelTask) checkTaskStatus(uid string, taskId int32) bool { - conf := this.module.configure.GetSmithyTask(taskId) + conf, _ := this.module.configure.GetSmithyTask(taskId) if conf == nil { return false } diff --git a/modules/smithy/module.go b/modules/smithy/module.go index 921c0982f..8bb3a4e8b 100644 --- a/modules/smithy/module.go +++ b/modules/smithy/module.go @@ -51,8 +51,8 @@ func (this *Smithy) OnInstallComp() { } func (this *Smithy) CheckActivateAtlasCollect(uid string, id string) { - atlasConf := this.configure.GetSmithyAtlasConf(id) - if atlasConf == nil || atlasConf.TypeId != 2 { + atlasConf, err := this.configure.GetSmithyAtlasConf(id) + if err != nil || atlasConf.TypeId != 2 { return } diff --git a/modules/viking/api_challenge.go b/modules/viking/api_challenge.go index c6ee0aa69..23e07760f 100644 --- a/modules/viking/api_challenge.go +++ b/modules/viking/api_challenge.go @@ -24,22 +24,20 @@ func (this *apiComp) Challenge(session comm.IUserSession, req *pb.VikingChalleng if code != pb.ErrorCode_Success { return // 参数校验失败直接返回 } - viking, err := this.module.modelViking.getVikingList(session.GetUserId()) - if err != nil { - code = pb.ErrorCode_VikingBoosType - return - } + viking, _ := this.module.modelViking.getVikingList(session.GetUserId()) - cfgData := this.module.configure.GetVikingBossConfigData(req.BossId, req.Difficulty) - if cfgData == nil { + cfgData, err := this.module.configure.GetVikingBossConfigData(req.BossId, req.Difficulty) + if err != nil { code = pb.ErrorCode_ConfigNoFound + data = &pb.ErrorData{ + Title: pb.GetErrorCodeMsg(code), + Message: err.Error(), + } return } if v1, ok := viking.Ps[req.BossId]; ok && v1 == 0 { - if code = this.module.ConsumeRes(session, cfgData.PsMg, true); code != pb.ErrorCode_Success { // 扣1点 - return } } else { diff --git a/modules/viking/api_challengeover.go b/modules/viking/api_challengeover.go index dd22763fd..f870a9964 100644 --- a/modules/viking/api_challengeover.go +++ b/modules/viking/api_challengeover.go @@ -42,9 +42,14 @@ func (this *apiComp) ChallengeOver(session comm.IUserSession, req *pb.VikingChal return } - vikingCfg := this.module.configure.GetVikingBossConfigData(req.BossId, req.Difficulty) - if vikingCfg == nil { + vikingCfg, err := this.module.configure.GetVikingBossConfigData(req.BossId, req.Difficulty) + if err != nil { code = pb.ErrorCode_ConfigNoFound + data = &pb.ErrorData{ + Title: pb.GetErrorCodeMsg(code), + Message: err.Error(), + } + return } diff --git a/modules/viking/comp_configure.go b/modules/viking/comp_configure.go index 5639368f6..597c76dd8 100644 --- a/modules/viking/comp_configure.go +++ b/modules/viking/comp_configure.go @@ -1,6 +1,8 @@ package viking import ( + "fmt" + "go_dreamfactory/comm" "go_dreamfactory/lego/core" "go_dreamfactory/lego/sys/log" "go_dreamfactory/modules" @@ -9,6 +11,8 @@ import ( "sync" ) +var moduleName = "viking" + const ( game_vikingboss = "game_vikingboss.json" // game_challenge = "game_vikingchallenge.json" @@ -51,9 +55,11 @@ func (this *configureComp) Init(service core.IService, module core.IModule, comp } // 参数: boss类型 难度 -func (this *configureComp) GetVikingBossConfigData(bossId int32, difficulty int32) (data *cfg.GameVikingBossData) { - - return this._vikingMap[int64(bossId<<16)+int64(difficulty)] +func (this *configureComp) GetVikingBossConfigData(bossId int32, difficulty int32) (data *cfg.GameVikingBossData, err error) { + if data = this._vikingMap[int64(bossId<<16)+int64(difficulty)]; data == nil { + err = comm.NewNotFoundConfErr(moduleName, game_vikingboss, fmt.Errorf("bossId:%d,difficulty:%d", bossId, difficulty)) + } + return } //加载多个配置文件 diff --git a/modules/viking/model_viking.go b/modules/viking/model_viking.go index 140dda568..b22f48a0b 100644 --- a/modules/viking/model_viking.go +++ b/modules/viking/model_viking.go @@ -57,9 +57,10 @@ func (this *modelViking) checkReddot31(session comm.IUserSession) bool { if list, err := this.module.modelViking.getVikingList(session.GetUserId()); err == nil { if _, ok := list.Boss[1]; ok { - conf := this.module.configure.GetVikingBossConfigData(1, 1) - if code := this.module.CheckRes(session, conf.PsConsume); code == pb.ErrorCode_Success { - return true + if conf, _ := this.module.configure.GetVikingBossConfigData(1, 1); conf != nil { + if code := this.module.CheckRes(session, conf.PsConsume); code == pb.ErrorCode_Success { + return true + } } } } diff --git a/modules/viking/module.go b/modules/viking/module.go index 3c5a30d49..8b2a0243a 100644 --- a/modules/viking/module.go +++ b/modules/viking/module.go @@ -193,7 +193,7 @@ func (this *Viking) CompleteAllLevel(session comm.IUserSession) (code pb.ErrorCo // 查配置获取每个Boss的最大难度 for k := range list.Boss { for i := 1; ; i++ { - conf := this.configure.GetVikingBossConfigData(k, int32(i)) + conf, _ := this.configure.GetVikingBossConfigData(k, int32(i)) if conf == nil { list.Boss[k] = int32(i - 1) } @@ -207,7 +207,7 @@ func (this *Viking) CompleteAllLevel(session comm.IUserSession) (code pb.ErrorCo } func (this *Viking) AutoBuyTicket(session comm.IUserSession, bossId, difficulty int32) (code pb.ErrorCode) { - conf := this.configure.GetVikingBossConfigData(bossId, difficulty) + conf, _ := this.configure.GetVikingBossConfigData(bossId, difficulty) if code := this.CheckRes(session, conf.PsConsume); code != pb.ErrorCode_Success { amount := int32(this.ModuleItems.QueryItemAmount(session.GetUserId(), conf.PsConsume[0].T)) // 获取当前数量 if amount < conf.PsConsume[0].N { // 数量不足直接购买 @@ -222,7 +222,7 @@ func (this *Viking) AutoBuyTicket(session comm.IUserSession, bossId, difficulty func (this *Viking) AutoBattleInfo(session comm.IUserSession, battle *pb.BattleFormation, bossId, difficulty int32) (code pb.ErrorCode, battleInfo *pb.BattleInfo) { - cfgData := this.configure.GetVikingBossConfigData(bossId, difficulty) + cfgData, _ := this.configure.GetVikingBossConfigData(bossId, difficulty) if cfgData == nil { code = pb.ErrorCode_ConfigNoFound return @@ -254,7 +254,7 @@ func (this *Viking) AutoBattleOver(session comm.IUserSession, Report *pb.BattleR bossId := autoBattle.BossId difficulty := autoBattle.Difficulty atno = make([]*pb.UserAtno, 0) - conf := this.configure.GetVikingBossConfigData(bossId, difficulty) + conf, _ := this.configure.GetVikingBossConfigData(bossId, difficulty) tasks := make([]*pb.BuriedParam, 0) // costRes := this.ModuleTools.GetGlobalConf().VikingExpeditionCos // if costRes == nil { @@ -281,7 +281,7 @@ func (this *Viking) AutoBattleOver(session comm.IUserSession, Report *pb.BattleR } } mapData := make(map[string]interface{}, 0) - vikingCfg := this.configure.GetVikingBossConfigData(bossId, difficulty) + vikingCfg, _ := this.configure.GetVikingBossConfigData(bossId, difficulty) if vikingCfg == nil { code = pb.ErrorCode_ConfigNoFound return