英雄羁绊信息

This commit is contained in:
meixiongfeng 2022-10-09 10:33:20 +08:00
parent f28a16cde0
commit fc54a8d888
4 changed files with 130 additions and 15 deletions

View File

@ -1,6 +1,7 @@
package library package library
import ( import (
"fmt"
"go_dreamfactory/lego/core" "go_dreamfactory/lego/core"
"go_dreamfactory/lego/sys/log" "go_dreamfactory/lego/sys/log"
"go_dreamfactory/modules" "go_dreamfactory/modules"
@ -9,27 +10,58 @@ import (
) )
const ( const (
game_libraryhero = "game_libraryhero.json" game_libraryhero = "game_libraryhero.json" // 英雄对应的羁绊id信息
game_libraryfetter = "game_libraryfetter.json" 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 { type configureComp struct {
modules.MCompConfigure 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) { 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.MCompConfigure.Init(service, module, comp, options)
//err = this.LoadConfigure(game_libraryhero, cfg.NewGameLibraryHero)
err = this.LoadMultiConfigure(map[string]interface{}{ err = this.LoadMultiConfigure(map[string]interface{}{
game_libraryhero: cfg.NewGameLibraryHero, game_libraryhero: cfg.NewGameLibraryHero,
game_libraryfetter: cfg.NewGameLibraryFetter, 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 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) { func (this *configureComp) LoadMultiConfigure(confs map[string]interface{}) (err error) {
for k, v := range confs { 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 v, err := this.GetConfigure(game_libraryhero); err == nil {
if configure, ok := v.(*cfg.GameLibraryHero); ok { if configure, ok := v.(*cfg.GameLibraryHero); ok {
data = configure.Get(hid) data = configure.Get(hid)
return
} }
} else { } else {
log.Errorf("get game_challenge conf err:%v", err) log.Errorf("get GetLibraryHero conf err:%v", err)
} }
return return
} }
func (this *configureComp) GetLibraryFetter(fid int32) (data *cfg.GameLibraryFetterData) { func (this *configureComp) GetLibraryFavor(id int32) (data *cfg.GameLibraryFavorData) {
if v, err := this.GetConfigure(game_libraryfetter); err == nil { if v, err := this.GetConfigure(game_libraryfavor); err == nil {
if configure, ok := v.(*cfg.GameLibraryFetter); ok { if configure, ok := v.(*cfg.GameLibraryFavor); ok {
data = configure.Get(fid) data = configure.Get(id)
return
} }
} else { } 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 return
} }

View File

@ -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
}

View File

@ -64,7 +64,7 @@ func (this *Library) CreateLibrary(uid string, fids []int32, heroConfId string)
Fetterlv: 0, Fetterlv: 0,
} }
conf := this.configure.GetLibraryFetter(fid) conf := this.configure.GetLibraryFetter(fid, 1)
if conf == nil { if conf == nil {
for _, v := range conf.Hid { for _, v := range conf.Hid {
obj.Hero[v] = 0 obj.Hero[v] = 0

View File

@ -13,6 +13,7 @@ import (
"go_dreamfactory/modules/hero" "go_dreamfactory/modules/hero"
"go_dreamfactory/modules/hunting" "go_dreamfactory/modules/hunting"
"go_dreamfactory/modules/items" "go_dreamfactory/modules/items"
"go_dreamfactory/modules/library"
"go_dreamfactory/modules/linestory" "go_dreamfactory/modules/linestory"
"go_dreamfactory/modules/mail" "go_dreamfactory/modules/mail"
"go_dreamfactory/modules/mainline" "go_dreamfactory/modules/mainline"
@ -81,6 +82,7 @@ func main() {
hunting.NewModule(), hunting.NewModule(),
battle.NewModule(), battle.NewModule(),
linestory.NewModule(), linestory.NewModule(),
library.NewModule(),
) )
} }