From f6ac63de8816e6433936b564125e62fe8d4a90e4 Mon Sep 17 00:00:00 2001 From: meixiongfeng <766881921@qq.com> Date: Fri, 26 May 2023 16:24:47 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E9=94=99=E8=AF=AF=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/atlas/api_atlasaward.go | 4 +- modules/atlas/comp_configure.go | 29 +++++----- modules/autoBattle/api.go | 36 ------------ modules/autoBattle/api_autochallenge.go | 74 ------------------------- modules/autoBattle/api_autoover.go | 63 --------------------- modules/autoBattle/api_autostop.go | 47 ---------------- modules/autoBattle/comp_configure.go | 39 ------------- modules/autoBattle/model_auto.go | 62 --------------------- modules/autoBattle/module.go | 62 --------------------- modules/caravan/api_buyorsell.go | 19 ++++++- modules/caravan/api_getlist.go | 6 +- modules/caravan/api_getstory.go | 7 ++- modules/caravan/api_gotocity.go | 12 +++- modules/caravan/comp_configure.go | 67 ++++++++++++++-------- modules/caravan/model_caravan.go | 2 +- modules/caravan/module.go | 14 ++--- 16 files changed, 104 insertions(+), 439 deletions(-) delete mode 100644 modules/autoBattle/api.go delete mode 100644 modules/autoBattle/api_autochallenge.go delete mode 100644 modules/autoBattle/api_autoover.go delete mode 100644 modules/autoBattle/api_autostop.go delete mode 100644 modules/autoBattle/comp_configure.go delete mode 100644 modules/autoBattle/model_auto.go delete mode 100644 modules/autoBattle/module.go diff --git a/modules/atlas/api_atlasaward.go b/modules/atlas/api_atlasaward.go index b8b766f67..d4b804226 100644 --- a/modules/atlas/api_atlasaward.go +++ b/modules/atlas/api_atlasaward.go @@ -21,8 +21,8 @@ func (this *apiComp) Award(session comm.IUserSession, req *pb.AtlasAwardReq) (co ) list, _ := this.module.modelPandaAtlas.getPandaAtlasList(session.GetUserId()) for { - conf := this.module.configure.GetPandoAtlasAwardConf(list.Award + 1) - if conf == nil { + conf, err := this.module.configure.GetPandoAtlasAwardConf(list.Award + 1) + if err != nil { break } if list.Score < conf.AtlasScore { // 校验积分够不够 diff --git a/modules/atlas/comp_configure.go b/modules/atlas/comp_configure.go index 5785b465e..01a4306fd 100644 --- a/modules/atlas/comp_configure.go +++ b/modules/atlas/comp_configure.go @@ -1,7 +1,6 @@ package atlas import ( - "fmt" "go_dreamfactory/comm" "go_dreamfactory/lego/core" "go_dreamfactory/lego/sys/log" @@ -62,9 +61,8 @@ func (this *configureComp) GetPandoJxConf(id string) (conf *cfg.GamePandamasJxDa this.module.Errorln(err) } } - } else { - err = fmt.Errorf("%T no is *cfg.GamePandamasJxData", v) } + err = comm.NewNotFoundConfErr("atlas", pandaJx, id) return } @@ -75,27 +73,32 @@ func (this *configureComp) GetPandoAtlasConf(id string) (conf *cfg.GamePandamasT ) if v, err = this.GetConfigure(pandaAtlas); err == nil { if configure, ok := v.(*cfg.GamePandamasTj); ok { - conf = configure.Get(id) - if nil == conf { - err = fmt.Errorf("GamePandamasTj not found key :%s", id) + if conf = configure.Get(id); nil == conf { + err = comm.NewNotFoundConfErr("atlas", pandaAtlas, id) + this.module.Errorln(err) } return } } - err = fmt.Errorf("%T no is *cfg.GetPandoAtlasConf", v) + err = comm.NewNotFoundConfErr("atlas", pandaAtlas, id) return } // 获取图鉴奖励 -func (this *configureComp) GetPandoAtlasAwardConf(lv int32) (conf *cfg.GamePandamasTjjlData) { - - if v, err := this.GetConfigure(pandaAtlasAward); err == nil { +func (this *configureComp) GetPandoAtlasAwardConf(lv int32) (conf *cfg.GamePandamasTjjlData, err error) { + var ( + v interface{} + ) + if v, err = this.GetConfigure(pandaAtlasAward); err == nil { if configure, ok := v.(*cfg.GamePandamasTjjl); ok { - return configure.Get(lv) + if conf = configure.Get(lv); nil == conf { + err = comm.NewNotFoundConfErr("atlas", pandaAtlasAward, lv) + this.module.Errorln(err) + } + return } - } else { - err = fmt.Errorf("%T no is *cfg.GamePandamasTjData", v) } + err = comm.NewNotFoundConfErr("atlas", pandaAtlasAward, lv) return } diff --git a/modules/autoBattle/api.go b/modules/autoBattle/api.go deleted file mode 100644 index cee59459b..000000000 --- a/modules/autoBattle/api.go +++ /dev/null @@ -1,36 +0,0 @@ -package autoBattle - -import ( - "go_dreamfactory/comm" - "go_dreamfactory/lego/core" - "go_dreamfactory/modules" -) - -const () - -type apiComp struct { - modules.MCompGate - service core.IService - configure *configureComp - module *AutoBattle - viking comm.IViking -} - -//组件初始化接口 -func (this *apiComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) { - err = this.MCompGate.Init(service, module, comp, options) - this.module = module.(*AutoBattle) - - this.service = service - return -} - -func (this *apiComp) Start() (err error) { - err = this.MCompGate.Start() - var module core.IModule - if module, err = this.service.GetModule(comm.ModuleViking); err != nil { - return - } - this.viking = module.(comm.IViking) - return -} diff --git a/modules/autoBattle/api_autochallenge.go b/modules/autoBattle/api_autochallenge.go deleted file mode 100644 index 9b7281315..000000000 --- a/modules/autoBattle/api_autochallenge.go +++ /dev/null @@ -1,74 +0,0 @@ -package autoBattle - -import ( - "go_dreamfactory/comm" - "go_dreamfactory/pb" - - "go.mongodb.org/mongo-driver/bson/primitive" -) - -//参数校验 -func (this *apiComp) AutoChallengeCheck(session comm.IUserSession, req *pb.AutoBattleChallengeReq) (code pb.ErrorCode) { - if req.BossId <= 0 || req.Difficulty <= 0 { - code = pb.ErrorCode_ReqParameterError - return - } - return -} - -func (this *apiComp) AutoChallenge(session comm.IUserSession, req *pb.AutoBattleChallengeReq) (code pb.ErrorCode, data *pb.ErrorData) { - var ( - battleInfo *pb.BattleInfo - ) - if code = this.AutoChallengeCheck(session, req); code != pb.ErrorCode_Success { - return - } - list, err := this.module.modelAutoBattle.getAutoBattleList(session.GetUserId()) - if err != nil { - code = pb.ErrorCode_DBError - return - } - for _, v := range list { - if v.Ptype == req.Ptype { // 有正在自动战斗的数据 - code = pb.ErrorCode_AutoBattleStatesErr - return - } - } - // 写入数据 - battle := make(map[string]interface{}, 0) - _d := &pb.DBAutoBattle{ - Id: primitive.NewObjectID().Hex(), - Uid: session.GetUserId(), - AutoWin: req.AutoWin, - MaxExp: req.MaxExp, - AutoBuy: req.AutoBuy, - AutoSell: req.AutoSell, - Ptype: req.Ptype, - BossId: req.BossId, - Difficulty: req.Difficulty, - Battle: req.Battle, - } - battle[_d.Id] = _d - if err = this.module.modelAutoBattle.AddListByObjId(session.GetUserId(), battle); err != nil { - code = pb.ErrorCode_DBError - return - } - - // 优先判断门票够不够 - if req.Ptype == pb.PlayType_viking { - if req.AutoBuy { - this.viking.AutoBuyTicket(session, req.BossId, req.Difficulty) - code = this.viking.CheckBattelParameter(session, req.Battle, req.BossId, req.Difficulty) // 参数校验 - if code != pb.ErrorCode_Success { - return - } - code, battleInfo = this.viking.AutoBattleInfo(session, req.Battle, req.BossId, req.Difficulty) - if code == pb.ErrorCode_Success { - session.SendMsg(string(this.module.GetType()), "challenge", &pb.AutoBattleChallengeResp{ - Info: battleInfo, - }) - } - } - } - return -} diff --git a/modules/autoBattle/api_autoover.go b/modules/autoBattle/api_autoover.go deleted file mode 100644 index ec3eb3010..000000000 --- a/modules/autoBattle/api_autoover.go +++ /dev/null @@ -1,63 +0,0 @@ -package autoBattle - -import ( - "go_dreamfactory/comm" - "go_dreamfactory/pb" -) - -//参数校验 -func (this *apiComp) AutoOverCheck(session comm.IUserSession, req *pb.AutoBattleOverReq) (code pb.ErrorCode) { - if req.Ptype == pb.PlayType_null || req.Report == nil { - code = pb.ErrorCode_ReqParameterError - return - } - if req.Report.Info == nil { - code = pb.ErrorCode_ReqParameterError - return - } - return -} - -func (this *apiComp) AutoOver(session comm.IUserSession, req *pb.AutoBattleOverReq) (code pb.ErrorCode, data *pb.ErrorData) { - var ( - autoBattle *pb.DBAutoBattle - atno []*pb.UserAtno - autoOver bool - ) - if code = this.AutoOverCheck(session, req); code != pb.ErrorCode_Success { - return - } - list, err := this.module.modelAutoBattle.getAutoBattleList(session.GetUserId()) - if err != nil { - code = pb.ErrorCode_DBError - return - } - for _, v := range list { - if v.Ptype == req.Ptype { // 有正在自动战斗的数据 - autoBattle = v - } - } - if autoBattle == nil { - code = pb.ErrorCode_AutoBattleNoData - return - } - // 分析战报 数据 - if req.Ptype == pb.PlayType_viking { - if code, atno = this.viking.AutoBattleOver(session, req.Report, autoBattle); code != pb.ErrorCode_Success { - this.module.modelAutoBattle.DelListByObjId(session.GetUserId(), autoBattle.Id) // 自动战斗结束 删除数据 - autoOver = true - } - } - code, battleInfo := this.viking.AutoBattleInfo(session, autoBattle.Battle, autoBattle.BossId, autoBattle.Difficulty) - if code == pb.ErrorCode_Success { - session.SendMsg(string(this.module.GetType()), "challenge", &pb.AutoBattleChallengeResp{ - Info: battleInfo, - }) - } - session.SendMsg(string(this.module.GetType()), "over", &pb.AutoBattleOverResp{ - Asset: atno, - Info: battleInfo, - Over: autoOver, - }) - return -} diff --git a/modules/autoBattle/api_autostop.go b/modules/autoBattle/api_autostop.go deleted file mode 100644 index 2963c5cff..000000000 --- a/modules/autoBattle/api_autostop.go +++ /dev/null @@ -1,47 +0,0 @@ -package autoBattle - -import ( - "go_dreamfactory/comm" - "go_dreamfactory/pb" -) - -//参数校验 -func (this *apiComp) AutoStopCheck(session comm.IUserSession, req *pb.AutoBattleStopReq) (code pb.ErrorCode) { - if req.Ptype == pb.PlayType_null { - code = pb.ErrorCode_ReqParameterError - return - } - - return -} - -func (this *apiComp) AutoStop(session comm.IUserSession, req *pb.AutoBattleStopReq) (code pb.ErrorCode, data *pb.ErrorData) { - var ( - autoBattle *pb.DBAutoBattle - ) - if code = this.AutoStopCheck(session, req); code != pb.ErrorCode_Success { - return - } - list, err := this.module.modelAutoBattle.getAutoBattleList(session.GetUserId()) - if err != nil { - code = pb.ErrorCode_DBError - return - } - for _, v := range list { - if v.Ptype == req.Ptype { // 有正在自动战斗的数据 - autoBattle = v - } - } - if autoBattle == nil { - code = pb.ErrorCode_AutoBattleNoData - return - } - if err = this.module.modelAutoBattle.DelListByObjId(session.GetUserId(), autoBattle.Id); err != nil { - code = pb.ErrorCode_DBError - return - } - session.SendMsg(string(this.module.GetType()), "stop", &pb.AutoBattleStopReq{ - Ptype: req.Ptype, - }) - return -} diff --git a/modules/autoBattle/comp_configure.go b/modules/autoBattle/comp_configure.go deleted file mode 100644 index b3427bfe5..000000000 --- a/modules/autoBattle/comp_configure.go +++ /dev/null @@ -1,39 +0,0 @@ -package autoBattle - -import ( - "go_dreamfactory/lego/core" - "go_dreamfactory/lego/sys/log" - "go_dreamfactory/modules" - "go_dreamfactory/sys/configure" -) - -const () - -///配置管理基础组件 -type configureComp struct { - modules.MCompConfigure -} - -//组件初始化接口 -func (this *configureComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) { - err = this.MCompConfigure.Init(service, module, comp, options) - - return -} - -//加载多个配置文件 -func (this *configureComp) LoadMultiConfigure(confs map[string]interface{}) (err error) { - for k, v := range confs { - err = configure.RegisterConfigure(k, v, nil) - if err != nil { - log.Errorf("配置文件:%s解析失败!", k) - break - } - } - return -} - -//读取配置数据 -func (this *configureComp) GetConfigure(name string) (v interface{}, err error) { - return configure.GetConfigure(name) -} diff --git a/modules/autoBattle/model_auto.go b/modules/autoBattle/model_auto.go deleted file mode 100644 index ffcc2fe01..000000000 --- a/modules/autoBattle/model_auto.go +++ /dev/null @@ -1,62 +0,0 @@ -package autoBattle - -import ( - "go_dreamfactory/comm" - "go_dreamfactory/lego/core" - "go_dreamfactory/lego/sys/mgo" - "go_dreamfactory/modules" - "go_dreamfactory/pb" - - "go.mongodb.org/mongo-driver/mongo" - "go.mongodb.org/mongo-driver/x/bsonx" -) - -type modelAutoBattle struct { - modules.MCompModel - module *AutoBattle -} - -func (this *modelAutoBattle) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) { - this.TableName = string(comm.TableAuto) - err = this.MCompModel.Init(service, module, comp, options) - this.module = module.(*AutoBattle) - // uid 创建索引 - this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{ - Keys: bsonx.Doc{{Key: "uid", Value: bsonx.Int32(1)}}, - }) - return -} - -// 修改列表信息 -func (this *modelAutoBattle) ChangeListByObjId(uid string, id string, data map[string]interface{}) error { - err := this.ChangeList(uid, id, data) - return err -} - -// 删除自动战斗信息 -func (this *modelAutoBattle) DelListByObjId(uid string, id string) error { - err := this.DelListlds(uid, []string{id}) - return err -} - -// 删除自动战斗信息 -func (this *modelAutoBattle) AddListByObjId(uid string, data map[string]interface{}) error { - err := this.AddLists(uid, data) - return err -} - -// 获取列表信息 -func (this *modelAutoBattle) getAutoBattleList(uid string) (result []*pb.DBAutoBattle, err error) { - result = make([]*pb.DBAutoBattle, 0) - err = this.GetList(uid, &result) - if err == mgo.MongodbNil { - err = nil - } - return result, err -} - -// 玩家离线清除自动战斗数据 -func (this *modelAutoBattle) RemoveUserInfo(uid string) (err error) { - this.BatchDelLists(uid) - return err -} diff --git a/modules/autoBattle/module.go b/modules/autoBattle/module.go deleted file mode 100644 index adc4c1bd6..000000000 --- a/modules/autoBattle/module.go +++ /dev/null @@ -1,62 +0,0 @@ -package autoBattle - -import ( - "go_dreamfactory/comm" - "go_dreamfactory/lego/core" - "go_dreamfactory/lego/sys/event" - "go_dreamfactory/lego/sys/log" - "go_dreamfactory/modules" - "go_dreamfactory/pb" -) - -type AutoBattle struct { - modules.ModuleBase - modelAutoBattle *modelAutoBattle - api *apiComp - configure *configureComp - service core.IService -} - -func NewModule() core.IModule { - return &AutoBattle{} -} - -func (this *AutoBattle) GetType() core.M_Modules { - return comm.ModuleAutoBattle -} - -func (this *AutoBattle) Init(service core.IService, module core.IModule, options core.IModuleOptions) (err error) { - err = this.ModuleBase.Init(service, module, options) - this.service = service - return -} - -func (this *AutoBattle) Start() (err error) { - err = this.ModuleBase.Start() - - event.RegisterGO(comm.EventUserOffline, this.EventUserOffline) - return -} - -func (this *AutoBattle) OnInstallComp() { - this.ModuleBase.OnInstallComp() - this.api = this.RegisterComp(new(apiComp)).(*apiComp) - this.modelAutoBattle = this.RegisterComp(new(modelAutoBattle)).(*modelAutoBattle) - this.configure = this.RegisterComp(new(configureComp)).(*configureComp) -} - -// 接口信息 -func (this *AutoBattle) ModifyAutoData(uid string, id string, data map[string]interface{}) (code pb.ErrorCode) { - err := this.modelAutoBattle.ChangeListByObjId(uid, id, data) - if err != nil { - code = pb.ErrorCode_DBError - } - return -} - -//Event-------------------------------------------------------------------------------------------------玩家离线 -func (this *AutoBattle) EventUserOffline(uid, sessionid string) { - if err := this.modelAutoBattle.RemoveUserInfo(uid); err != nil { - this.Error("EventUserOffline", log.Field{Key: "uid", Value: uid}, log.Field{Key: "err", Value: err.Error()}) - } -} diff --git a/modules/caravan/api_buyorsell.go b/modules/caravan/api_buyorsell.go index 03f5df733..4bf3855de 100644 --- a/modules/caravan/api_buyorsell.go +++ b/modules/caravan/api_buyorsell.go @@ -33,8 +33,13 @@ func (this *apiComp) BuyOrSell(session comm.IUserSession, req *pb.CaravanBuyOrSe code = pb.ErrorCode_ConfigNoFound return } - if c := this.module.configure.GetCaravanLv(caravan.Lv); c != nil { + c, err := this.module.configure.GetCaravanLv(caravan.Lv) + if err == nil { upperLimit = c.Bagtagnum // 获取单个格子堆叠数 + } else { + data.Message = err.Error() + code = pb.ErrorCode_ConfigNoFound + return } // special 城市卖给玩家的商品 @@ -89,8 +94,12 @@ func (this *apiComp) BuyOrSell(session comm.IUserSession, req *pb.CaravanBuyOrSe curLv := this.module.CheckCaravavLvUp(caravan) if curLv > caravan.Lv { for i := caravan.Lv; i <= curLv-caravan.Lv; i++ { - if c := this.module.configure.GetCaravanLv(int32(i)); c != nil { + if c, err := this.module.configure.GetCaravanLv(int32(i)); err == nil { lvReward = append(lvReward, c.Reward...) + } else { + data.Message = err.Error() + code = pb.ErrorCode_ConfigNoFound + return } } } @@ -129,13 +138,17 @@ func (this *apiComp) BuyOrSell(session comm.IUserSession, req *pb.CaravanBuyOrSe caravan.Items[k].Price = totla / caravan.Items[k].Count // 同步更新该城市的 出售货物信息 cityInfo.Count[k] += v - if itemConf := this.configure.GetCaravanGoods(k); itemConf != nil { // 更新商店库存 + if itemConf, err := this.configure.GetCaravanGoods(k); err == nil { // 更新商店库存 if cityInfo.Count[k] > itemConf.Goodsnum { code = pb.ErrorCode_TrollBuyMax // 商品数量不足 return } update["city"] = caravan.City addScore -= price * v + } else { + data.Message = err.Error() + code = pb.ErrorCode_ConfigNoFound + return } } if this.module.ArrayBag(caravan, upperLimit) { // 背包满了 diff --git a/modules/caravan/api_getlist.go b/modules/caravan/api_getlist.go index c611add25..ebcd1b235 100644 --- a/modules/caravan/api_getlist.go +++ b/modules/caravan/api_getlist.go @@ -24,8 +24,12 @@ func (this *apiComp) GetList(session comm.IUserSession, req *pb.CaravanGetListRe list, err := this.module.modelCaravan.getCaravanList(session.GetUserId()) if configure.Now().Unix() >= list.Resettime || err == mgo.MongodbNil { // 初始化门票和虚拟币 - if conf := this.module.configure.GetCaravanLv(list.Lv); conf != nil { + if conf, err := this.module.configure.GetCaravanLv(list.Lv); err == nil { this.module.ModuleItems.CleanItemById(session, conf.Tickettop.T) // 清理之前的门票数据 + } else { + data.Message = err.Error() + code = pb.ErrorCode_ConfigNoFound + return } if code = this.module.InitCaravanTicket(session, list.Lv); code != pb.ErrorCode_Success { return diff --git a/modules/caravan/api_getstory.go b/modules/caravan/api_getstory.go index 01ce0a86d..8e6fdd100 100644 --- a/modules/caravan/api_getstory.go +++ b/modules/caravan/api_getstory.go @@ -27,9 +27,10 @@ func (this *apiComp) GetStory(session comm.IUserSession, req *pb.CaravanGetStory } list, _ := this.module.modelCaravan.getCaravanList(session.GetUserId()) - conf := this.module.configure.GetCaravanEventById(req.Cid) - if conf == nil { - code = pb.ErrorCode_ReqParameterError + conf, err := this.module.configure.GetCaravanEventById(req.Cid) + if err != nil { + data.Message = err.Error() + code = pb.ErrorCode_ConfigNoFound return } if list.Eventid != req.Cid { diff --git a/modules/caravan/api_gotocity.go b/modules/caravan/api_gotocity.go index 96ae3597a..bc88ab269 100644 --- a/modules/caravan/api_gotocity.go +++ b/modules/caravan/api_gotocity.go @@ -30,7 +30,7 @@ func (this *apiComp) GotoCity(session comm.IUserSession, req *pb.CaravanGotoCity // 获取事件 if list.Eventid != 0 { - if event := this.module.configure.GetCaravanEventById(list.Eventid); event != nil { + if event, err := this.module.configure.GetCaravanEventById(list.Eventid); err == nil { // 校验任务是否超时 if list.Tasktime-configure.Now().Unix() > int64(event.Eventtime) { //TODO 任务超时 @@ -41,6 +41,10 @@ func (this *apiComp) GotoCity(session comm.IUserSession, req *pb.CaravanGotoCity } else { bNewTask = false } + } else { + data.Message = err.Error() + code = pb.ErrorCode_ConfigNoFound + return } } if bNewTask { // 到该城市随机一个新的任务 @@ -61,13 +65,17 @@ func (this *apiComp) GotoCity(session comm.IUserSession, req *pb.CaravanGotoCity return } // 校验门票 - if d := this.module.configure.GetCaravanLv(list.Lv); d != nil { + if d, err := this.module.configure.GetCaravanLv(list.Lv); err == nil { //d.Tickettop res = &cfg.Gameatn{ A: d.Tickettop.A, T: d.Tickettop.T, N: req.Ticket, } + } else { + data.Message = err.Error() + code = pb.ErrorCode_ConfigNoFound + return } if code = this.module.ConsumeRes(session, []*cfg.Gameatn{res}, true); code != pb.ErrorCode_Success { // 校验门票数量 return diff --git a/modules/caravan/comp_configure.go b/modules/caravan/comp_configure.go index 27592b222..7f9ce2f29 100644 --- a/modules/caravan/comp_configure.go +++ b/modules/caravan/comp_configure.go @@ -1,7 +1,7 @@ package caravan import ( - "fmt" + "go_dreamfactory/comm" "go_dreamfactory/lego/core" "go_dreamfactory/lego/sys/log" "go_dreamfactory/modules" @@ -61,43 +61,54 @@ 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 { - data = configure.Get(cityId) - if data == nil { - err = fmt.Errorf("caravan GetCaravanCity conf not found key:%d", cityId) + if data = configure.Get(cityId); data == nil { + err = comm.NewNotFoundConfErr("caravan", game_caravan, cityId) + this.module.Errorln(err) } return } } - err = fmt.Errorf("get GetCaravanCity conf err:%v", err) + err = comm.NewNotFoundConfErr("caravan", game_caravan, cityId) return } // 获取货物基本信息 -func (this *configureComp) GetCaravanLv(lv int32) (data *cfg.GameCaravanLvData) { - if v, err := this.GetConfigure(game_caravan_lv); err == nil { +func (this *configureComp) GetCaravanLv(lv int32) (data *cfg.GameCaravanLvData, err error) { + var ( + v interface{} + ) + if v, err = this.GetConfigure(game_caravan_lv); err == nil { if configure, ok := v.(*cfg.GameCaravanLv); ok { - data = configure.Get(lv) + if data = configure.Get(lv); data == nil { + err = comm.NewNotFoundConfErr("caravan", game_caravan_lv, lv) + this.module.Errorln(err) + } return } - } else { - log.Errorf("get GetCaravanGoods conf err:%v", err) } + err = comm.NewNotFoundConfErr("caravan", game_caravan_lv, lv) return } -func (this *configureComp) GetCaravanGoods(itemId int32) (data *cfg.GameCaravanThingData) { - if v, err := this.GetConfigure(game_caravan_thing); err == nil { +func (this *configureComp) GetCaravanGoods(itemId int32) (data *cfg.GameCaravanThingData, err error) { + var ( + v interface{} + ) + if v, err = this.GetConfigure(game_caravan_thing); err == nil { if configure, ok := v.(*cfg.GameCaravanThing); ok { - data = configure.Get(itemId) + if data = configure.Get(itemId); data == nil { + err = comm.NewNotFoundConfErr("caravan", game_caravan_thing, itemId) + this.module.Errorln(err) + } return } - } else { - log.Errorf("get GetCaravanGoods conf err:%v", err) } + err = comm.NewNotFoundConfErr("caravan", game_caravan_thing, itemId) return } func (this *configureComp) GetAllCaravanCity() (data []*cfg.GameCaravanCityData) { + if v, err := this.GetConfigure(game_caravan); err == nil { if configure, ok := v.(*cfg.GameCaravanCity); ok { for _, v := range configure.GetDataList() { @@ -111,6 +122,7 @@ func (this *configureComp) GetAllCaravanCity() (data []*cfg.GameCaravanCityData) return } func (this *configureComp) GetAllCaravanItem() (data []*cfg.GameCaravanThingData) { + if v, err := this.GetConfigure(game_caravan_thing); err == nil { if configure, ok := v.(*cfg.GameCaravanThing); ok { for _, v := range configure.GetDataList() { @@ -125,15 +137,20 @@ func (this *configureComp) GetAllCaravanItem() (data []*cfg.GameCaravanThingData } // 获取随机事件 -func (this *configureComp) GetCaravanEventById(id int32) (data *cfg.GameCaravanEventData) { - if v, err := this.GetConfigure(game_caravan_event); err == nil { +func (this *configureComp) GetCaravanEventById(id int32) (data *cfg.GameCaravanEventData, err error) { + var ( + v interface{} + ) + if v, err = this.GetConfigure(game_caravan_event); err == nil { if configure, ok := v.(*cfg.GameCaravanEvent); ok { - data = configure.Get(id) + if data = configure.Get(id); data == nil { + err = comm.NewNotFoundConfErr("caravan", game_caravan_event, id) + this.module.Errorln(err) + } return } - } else { - log.Errorf("get GetCaravanEventById conf err:%v", err) } + err = comm.NewNotFoundConfErr("caravan", game_caravan_event, id) return } @@ -179,13 +196,15 @@ func (this *configureComp) GetCaravanReward() (reward []*cfg.GameCaravanRewardDa return } -func (this *configureComp) GetCaravanRank(index int32) (reward *cfg.GameCaravanRankData) { +func (this *configureComp) GetCaravanRank(index int32) (reward *cfg.GameCaravanRankData, err error) { if v, err := this.GetConfigure(game_caravan_rank); err == nil { if configure, ok := v.(*cfg.GameCaravanRank); ok { - reward = configure.Get(index) + if reward = configure.Get(index); reward == nil { + err = comm.NewNotFoundConfErr("caravan", game_caravan_rank, index) + this.module.Errorln(err) + } } - } else { - log.Errorf("get GetCaravanInitCity conf err:%v", err) } + err = comm.NewNotFoundConfErr("caravan", game_caravan_rank, index) return } diff --git a/modules/caravan/model_caravan.go b/modules/caravan/model_caravan.go index f8ba0beb1..56378a5c5 100644 --- a/modules/caravan/model_caravan.go +++ b/modules/caravan/model_caravan.go @@ -54,7 +54,7 @@ func (this *modelCaravan) getCaravanList(uid string) (result *pb.DBCaravan, err result.Citystime = configure.Now().Unix() result.Lv = 1 result.Curcity = this.module.configure.GetCaravanInitCity() // 获取默认城市 - if conf := this.module.configure.GetCaravanLv(result.Lv); conf != nil { + if conf, err := this.module.configure.GetCaravanLv(result.Lv); err != nil { result.Baglimit = conf.Bagtop } this.module.InitCaravanCityData(uid, result) // 初始1级 diff --git a/modules/caravan/module.go b/modules/caravan/module.go index f15e774e1..a02d889f7 100644 --- a/modules/caravan/module.go +++ b/modules/caravan/module.go @@ -115,7 +115,7 @@ func (this *Caravan) InitCaravanItemData(uid string, data *pb.DBCaravan) { // 初始化门票和虚拟币 func (this *Caravan) InitCaravanTicket(session comm.IUserSession, lv int32) (code pb.ErrorCode) { code = pb.ErrorCode_ConfigNoFound - if conf := this.modelCaravan.module.configure.GetCaravanLv(lv); conf != nil { + if conf, _ := this.modelCaravan.module.configure.GetCaravanLv(lv); conf != nil { var res []*cfg.Gameatn res = append(res, conf.Tickettop) res = append(res, conf.Moneynumtop) @@ -153,7 +153,7 @@ func (this *Caravan) refreshCaravanCityInfo(uid string, caravan *pb.DBCaravan) { icount := int32(subTime / int64(changeTime)) // 循环周期 caravan.Citystime += int64(changeTime * icount) for k, v := range caravan.Goods { - if c := this.configure.GetCaravanGoods(k); c != nil { + if c, err := this.configure.GetCaravanGoods(k); err == nil { caravan.Oldprice[k] = v.Price if icount > 50 { //超过一定的周期 则不计算 // 随机出新的变动周期 @@ -222,7 +222,7 @@ func (this *Caravan) refreshCaravanCityInfo(uid string, caravan *pb.DBCaravan) { // 校验随机事件是否超时 func (this *Caravan) CheckCaravanTask(session comm.IUserSession, data *pb.DBCaravan) { if data.Eventid != 0 { - if list := this.configure.GetCaravanEventById(data.Eventid); list != nil { + if list, err := this.configure.GetCaravanEventById(data.Eventid); err == nil { // 校验任务是否超时 if data.Tasktime-configure.Now().Unix() > int64(list.Eventtime) { //TODO 任务超时 通知任务模块处理 并清理相关数据 module, err := this.service.GetModule(comm.ModuleWorldtask) @@ -277,7 +277,7 @@ func (this *Caravan) TaskComplete(session comm.IUserSession, taskid int32) { resp *pb.CaravanTaskCompletePush ) if !this.IsCross() { - if conf := this.configure.GetCaravanEventById(taskid); conf != nil { + if conf, err := this.configure.GetCaravanEventById(taskid); err == nil { list, _ := this.modelCaravan.getCaravanList(session.GetUserId()) if list.Taskid == taskid { this.CleanCaravanTask(session.GetUserId(), list) //任务完成 清理任务数据 @@ -329,7 +329,7 @@ func (this *Caravan) ArrayBag(data *pb.DBCaravan, limit int32) (bFull bool) { func (this *Caravan) CheckCaravavLvUp(data *pb.DBCaravan) (curLv int32) { curLv = data.Lv for { - if conf := this.configure.GetCaravanLv(curLv + 1); conf != nil { + if conf, err := this.configure.GetCaravanLv(curLv + 1); err == nil { if conf.Newmoneyexp <= int32(data.Profit) { curLv++ } else { @@ -363,8 +363,8 @@ func (this *Caravan) Rpc_ModuleCaravanSettlement(ctx context.Context, args *pb.E rankIndex++ temp := &pb.DBUser{} if err = _data.Decode(temp); err == nil { - c := this.configure.GetCaravanRank(rankIndex) - if c != nil { + c, err := this.configure.GetCaravanRank(rankIndex) + if err == nil { this.mail.SendMailByUID(temp.Uid, "CaravanRank", c.Reward, []string{strconv.Itoa(int(rankIndex))}) } }