From fc54a8d8881dc1a405f70db2cef06219bda1184b Mon Sep 17 00:00:00 2001 From: meixiongfeng <766881921@qq.com> Date: Sun, 9 Oct 2022 10:33:20 +0800 Subject: [PATCH] =?UTF-8?q?=E8=8B=B1=E9=9B=84=E7=BE=81=E7=BB=8A=E4=BF=A1?= =?UTF-8?q?=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/library/comp_configure.go | 80 +++++++++++++++++++++++++------ modules/library/model_fetter.go | 61 +++++++++++++++++++++++ modules/library/module.go | 2 +- services/worker/main.go | 2 + 4 files changed, 130 insertions(+), 15 deletions(-) create mode 100644 modules/library/model_fetter.go diff --git a/modules/library/comp_configure.go b/modules/library/comp_configure.go index df5b197ee..dcca4b8d5 100644 --- a/modules/library/comp_configure.go +++ b/modules/library/comp_configure.go @@ -1,6 +1,7 @@ package library import ( + "fmt" "go_dreamfactory/lego/core" "go_dreamfactory/lego/sys/log" "go_dreamfactory/modules" @@ -9,27 +10,58 @@ import ( ) const ( - game_libraryhero = "game_libraryhero.json" - game_libraryfetter = "game_libraryfetter.json" + game_libraryhero = "game_libraryhero.json" // 英雄对应的羁绊id信息 + game_libraryfetter = "game_libraryfetter.json" // 羁绊信息表 + game_libraryhistory = "game_libraryhistory.json" // 往事id 对应的奖励 + game_libraryfavor = "game_libraryfavor.json" // 英雄好感度升级所需的经验 + game_librarystory = "game_librarystory.json" // 羁绊id对应剧情奖励 ) ///配置管理基础组件 type configureComp struct { modules.MCompConfigure + fetter map[int64]*cfg.GameLibraryFetterData } //组件初始化接口 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) - - //err = this.LoadConfigure(game_libraryhero, cfg.NewGameLibraryHero) err = this.LoadMultiConfigure(map[string]interface{}{ - game_libraryhero: cfg.NewGameLibraryHero, - game_libraryfetter: cfg.NewGameLibraryFetter, + game_libraryhero: cfg.NewGameLibraryHero, + game_libraryhistory: cfg.NewGameLibraryHistory, + game_libraryfavor: cfg.NewGameLibraryFavor, + game_librarystory: cfg.NewGameLibraryStory, }) + + this.fetter = make(map[int64]*cfg.GameLibraryFetterData, 0) + + configure.RegisterConfigure(game_libraryfetter, cfg.NewGameLibraryFetter, this.SetLibraryFetter) + + // _data := this.GetLibraryStory(101) + // fmt.Printf("%v", _data) + // _data1 := this.GetLibraryFavor(2) + // fmt.Printf("%v", _data1) + // _data2 := this.GetLibraryHistory("350011") + // fmt.Printf("%v", _data2) return } +func (this *configureComp) SetLibraryFetter() { + if v, err := this.GetConfigure(game_libraryfetter); err == nil { + if _configure, ok := v.(*cfg.GameLibraryFetter); ok { + for _, v := range _configure.GetDataList() { + this.fetter[int64(v.Fid<<8)+int64(v.Favorlv)] = v + } + return + } + } else { + err = fmt.Errorf("%T no is *cfg.GameLibraryFetter", v) + } +} +func (this *configureComp) GetLibraryFetter(fid, favorlv int32) (data *cfg.GameLibraryFetterData) { + return this.fetter[int64(fid<<8)+int64(favorlv)] +} + //加载多个配置文件 func (this *configureComp) LoadMultiConfigure(confs map[string]interface{}) (err error) { for k, v := range confs { @@ -51,22 +83,42 @@ func (this *configureComp) GetLibraryHero(hid string) (data *cfg.GameLibraryHero if v, err := this.GetConfigure(game_libraryhero); err == nil { if configure, ok := v.(*cfg.GameLibraryHero); ok { data = configure.Get(hid) - return } } else { - log.Errorf("get game_challenge conf err:%v", err) + log.Errorf("get GetLibraryHero conf err:%v", err) } return } -func (this *configureComp) GetLibraryFetter(fid int32) (data *cfg.GameLibraryFetterData) { - if v, err := this.GetConfigure(game_libraryfetter); err == nil { - if configure, ok := v.(*cfg.GameLibraryFetter); ok { - data = configure.Get(fid) - return +func (this *configureComp) GetLibraryFavor(id int32) (data *cfg.GameLibraryFavorData) { + if v, err := this.GetConfigure(game_libraryfavor); err == nil { + if configure, ok := v.(*cfg.GameLibraryFavor); ok { + data = configure.Get(id) } } else { - log.Errorf("get game_challenge conf err:%v", err) + log.Errorf("GetLibraryFavor conf err:%v", err) + } + return +} + +func (this *configureComp) GetLibraryHistory(id string) (data *cfg.GameLibraryHistoryData) { + if v, err := this.GetConfigure(game_libraryhistory); err == nil { + if configure, ok := v.(*cfg.GameLibraryHistory); ok { + data = configure.Get(id) + } + } else { + log.Errorf("GetLibraryHistory conf err:%v", err) + } + return +} + +func (this *configureComp) GetLibraryStory(fid int32) (data *cfg.GameLibraryStoryData) { + if v, err := this.GetConfigure(game_librarystory); err == nil { + if configure, ok := v.(*cfg.GameLibraryStory); ok { + data = configure.Get(fid) + } + } else { + log.Errorf("GetLibraryStory conf err:%v", err) } return } diff --git a/modules/library/model_fetter.go b/modules/library/model_fetter.go new file mode 100644 index 000000000..193d09258 --- /dev/null +++ b/modules/library/model_fetter.go @@ -0,0 +1,61 @@ +package library + +import ( + "go_dreamfactory/comm" + "go_dreamfactory/lego/core" + "go_dreamfactory/modules" + "go_dreamfactory/pb" + + "go.mongodb.org/mongo-driver/mongo" + "go.mongodb.org/mongo-driver/x/bsonx" +) + +type modelFetter struct { + modules.MCompModel + module *Library +} + +func (this *modelFetter) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) { + this.TableName = string(comm.TableLibrary) + err = this.MCompModel.Init(service, module, comp, options) + this.module = module.(*Library) + // uid 创建索引 + this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{ + Keys: bsonx.Doc{{Key: "uid", Value: bsonx.Int32(1)}}, + }) + return +} + +func (this *modelFetter) modifyLibraryDataByObjId(uid string, data map[string]interface{}) error { + return this.Change(uid, data) +} + +// 获取列表信息 +func (this *modelFetter) getLibraryList(uid string) []*pb.DBLibrary { + libs := make([]*pb.DBLibrary, 0) + err := this.GetList(uid, &libs) + if err != nil { + return nil + } + return libs +} + +//创建一条信息 +func (this *modelFetter) createLibrary(uid string, fetter *pb.DBLibrary) (err error) { + + if err = this.AddList(uid, fetter.Id, fetter); err != nil { + this.module.Errorf("%v", err) + return + } + return +} + +// 通过objid 找对应的数据 +func (this *modelFetter) getOneLibrary(uid, oid string) *pb.DBLibrary { + fetter := &pb.DBLibrary{} + err := this.GetListObj(uid, oid, fetter) + if err != nil { + return nil + } + return fetter +} diff --git a/modules/library/module.go b/modules/library/module.go index 95526b041..9f1226c00 100644 --- a/modules/library/module.go +++ b/modules/library/module.go @@ -64,7 +64,7 @@ func (this *Library) CreateLibrary(uid string, fids []int32, heroConfId string) Fetterlv: 0, } - conf := this.configure.GetLibraryFetter(fid) + conf := this.configure.GetLibraryFetter(fid, 1) if conf == nil { for _, v := range conf.Hid { obj.Hero[v] = 0 diff --git a/services/worker/main.go b/services/worker/main.go index 64a632a1a..05693f3af 100644 --- a/services/worker/main.go +++ b/services/worker/main.go @@ -13,6 +13,7 @@ import ( "go_dreamfactory/modules/hero" "go_dreamfactory/modules/hunting" "go_dreamfactory/modules/items" + "go_dreamfactory/modules/library" "go_dreamfactory/modules/linestory" "go_dreamfactory/modules/mail" "go_dreamfactory/modules/mainline" @@ -81,6 +82,7 @@ func main() { hunting.NewModule(), battle.NewModule(), linestory.NewModule(), + library.NewModule(), ) }