From 2a1f9ce395295f7724a681568992a293d56192ff Mon Sep 17 00:00:00 2001 From: meixiongfeng <766881921@qq.com> Date: Fri, 26 Aug 2022 17:04:27 +0800 Subject: [PATCH] viking --- modules/comp_configure.go | 23 ++++ modules/gourmet/comp_configure.go | 28 +---- modules/smithy/comp_configure.go | 27 ----- modules/viking/api_getlist.go | 22 +++- modules/viking/comp_configure.go | 111 +++++------------- .../{model_gourmet.go => model_viking.go} | 20 ++-- pb/viking_db.pb.go | 16 +-- 7 files changed, 87 insertions(+), 160 deletions(-) rename modules/viking/{model_gourmet.go => model_viking.go} (83%) diff --git a/modules/comp_configure.go b/modules/comp_configure.go index 9ecd17246..43d8231c7 100644 --- a/modules/comp_configure.go +++ b/modules/comp_configure.go @@ -7,6 +7,7 @@ import ( "go_dreamfactory/lego/sys/log" "go_dreamfactory/sys/configure" cfg "go_dreamfactory/sys/configure/structs" + "sync" ) const ( @@ -14,11 +15,14 @@ const ( game_initial = "game_initial.json" //初始化表 game_playerlv = "game_playerlv.json" //玩家等级 game_facemod = "game_facemod.json" // 形象配置表 + game_drop = "game_drop.json" //掉落 ) ///配置管理基础组件 type MCompConfigure struct { cbase.ModuleCompBase + hlock sync.RWMutex + _dropMap map[int32][]*cfg.GameDropData // 掉落表 key 是DiropId } //组件初始化接口 @@ -28,6 +32,21 @@ func (this *MCompConfigure) Init(service core.IService, module core.IModule, com err = this.LoadConfigure(game_initial, cfg.NewGameInitial) err = this.LoadConfigure(game_playerlv, cfg.NewGamePlayerlv) err = this.LoadConfigure(game_facemod, cfg.NewGameFacemod) + this._dropMap = make(map[int32][]*cfg.GameDropData, 0) + configure.RegisterConfigure(game_drop, cfg.NewGameDrop, func() { + if v, err := this.GetConfigure(game_drop); err == nil { + if configure, ok := v.(*cfg.GameDrop); ok { + this.hlock.Lock() + defer this.hlock.Unlock() + for _, value := range configure.GetDataList() { + this._dropMap[value.Dropid] = append(this._dropMap[value.Dropid], value) + } + return + } + } + log.Errorf("get game_pagoda conf err:%v", err) + return + }) return } @@ -137,3 +156,7 @@ func (this *MCompConfigure) GetPlayerFigureConf() (list []*cfg.GameFacemodData) } return } +func (this *MCompConfigure) GetDropData(dropId int32) (data []*cfg.GameDropData) { + data = this._dropMap[dropId] + return +} diff --git a/modules/gourmet/comp_configure.go b/modules/gourmet/comp_configure.go index 095471e30..954542c1a 100644 --- a/modules/gourmet/comp_configure.go +++ b/modules/gourmet/comp_configure.go @@ -13,7 +13,6 @@ import ( const ( game_gourmet = "game_gourmet.json" game_gourmetskill = "game_gourmetskill.json" - game_drop = "game_drop.json" ) ///配置管理基础组件 @@ -23,7 +22,6 @@ type configureComp struct { modules.MCompConfigure _gourmetMap map[int64]*cfg.GameGourmetData _gourmetSkillMap map[int64]*cfg.GameGourmetSkillData - _dropMap map[int32][]*cfg.GameDropData // 掉落表 key 是DiropId } //组件初始化接口 @@ -60,25 +58,7 @@ func (this *configureComp) Init(service core.IService, module core.IModule, comp log.Errorf("get game_pagoda conf err:%v", err) return }) - this._dropMap = make(map[int32][]*cfg.GameDropData, 0) - configure.RegisterConfigure(game_drop, cfg.NewGameDrop, func() { - if v, err := this.GetConfigure(game_drop); err == nil { - if configure, ok := v.(*cfg.GameDrop); ok { - this.hlock.Lock() - defer this.hlock.Unlock() - for _, value := range configure.GetDataList() { - this._dropMap[value.Dropid] = append(this._dropMap[value.Dropid], value) - } - return - } - } - log.Errorf("get game_pagoda conf err:%v", err) - return - }) - // _data := this.GetGourmetConfigData(1002, 4) // 测试配置文件读取 - // _dataskill := this.GetGourmetSkillConfigData(1001, 4) - // _data := this.GetDropData(1001) - // fmt.Printf("%v", _data) + return } @@ -115,7 +95,6 @@ func (this *configureComp) GetGourmetSkillConfigBySkillType(skillType int) (szSk szSkill = append(szSkill, data.Type) } } - //data = configure.Get(int32(skillId)) return } } @@ -138,8 +117,3 @@ func (this *configureComp) LoadMultiConfigure(confs map[string]interface{}) (err func (this *configureComp) GetConfigure(name string) (v interface{}, err error) { return configure.GetConfigure(name) } - -func (this *configureComp) GetDropData(dropId int32) (data []*cfg.GameDropData) { - data = this._dropMap[dropId] - return -} diff --git a/modules/smithy/comp_configure.go b/modules/smithy/comp_configure.go index 82399905d..2dbe26248 100644 --- a/modules/smithy/comp_configure.go +++ b/modules/smithy/comp_configure.go @@ -13,7 +13,6 @@ import ( const ( game_smithy = "game_smithy.json" game_smithystove = "game_smithystove.json" - game_drop = "game_drop.json" ) ///配置管理基础组件 @@ -22,7 +21,6 @@ type configureComp struct { hlock sync.RWMutex modules.MCompConfigure _smithyMap map[int64]*cfg.GameSmithyData - _dropMap map[int32][]*cfg.GameDropData // 掉落表 key 是DiropId } //组件初始化接口 @@ -44,26 +42,6 @@ func (this *configureComp) Init(service core.IService, module core.IModule, comp log.Errorf("get game_pagoda conf err:%v", err) return }) - - this._dropMap = make(map[int32][]*cfg.GameDropData, 0) - configure.RegisterConfigure(game_drop, cfg.NewGameDrop, func() { - if v, err := this.GetConfigure(game_drop); err == nil { - if configure, ok := v.(*cfg.GameDrop); ok { - this.hlock.Lock() - defer this.hlock.Unlock() - for _, value := range configure.GetDataList() { - this._dropMap[value.Dropid] = append(this._dropMap[value.Dropid], value) - } - return - } - } - log.Errorf("get game_pagoda conf err:%v", err) - return - }) - // _data := this.GetSmithyConfigData(1002, 4) // 测试配置文件读取 - // _dataskill := this.GetSmithyStoveConfigData(1001, 4) - // _data := this.GetDropData(1001) - // fmt.Printf("%v", _data) err = this.LoadConfigure(game_smithystove, cfg.NewGameSmithyStove) return } @@ -114,8 +92,3 @@ func (this *configureComp) LoadMultiConfigure(confs map[string]interface{}) (err func (this *configureComp) GetConfigure(name string) (v interface{}, err error) { return configure.GetConfigure(name) } - -func (this *configureComp) GetDropData(dropId int32) (data []*cfg.GameDropData) { - data = this._dropMap[dropId] - return -} diff --git a/modules/viking/api_getlist.go b/modules/viking/api_getlist.go index 648643044..a9dc614e7 100644 --- a/modules/viking/api_getlist.go +++ b/modules/viking/api_getlist.go @@ -4,21 +4,37 @@ import ( "go_dreamfactory/comm" "go_dreamfactory/pb" + "go.mongodb.org/mongo-driver/bson/primitive" "google.golang.org/protobuf/proto" ) //参数校验 -func (this *apiComp) GetListCheck(session comm.IUserSession, req *pb.GourmetGetListReq) (code pb.ErrorCode) { +func (this *apiComp) GetListCheck(session comm.IUserSession, req *pb.VikingGetListReq) (code pb.ErrorCode) { return } -func (this *apiComp) GetList(session comm.IUserSession, req *pb.GourmetGetListReq) (code pb.ErrorCode, data proto.Message) { +func (this *apiComp) GetList(session comm.IUserSession, req *pb.VikingGetListReq) (code pb.ErrorCode, data proto.Message) { code = this.GetListCheck(session, req) if code != pb.ErrorCode_Success { return // 参数校验失败直接返回 } - + list, err := this.module.modelViking.getVikingList(session.GetUserId()) + if err != nil { + code = pb.ErrorCode_DBError + return + } + if list == nil { + list.Id = primitive.NewObjectID().Hex() + list.Uid = session.GetUserId() + list.Boos = make(map[int32]int32) + _mapType := this.configure.GetVikingBossTypeConfigData() + for k := range _mapType { + list.Boos[k] = 1 + } + this.module.modelViking.Add(session.GetUserId(), list) // 写缓存 + } + session.SendMsg(string(this.module.GetType()), VikingGetListResp, &pb.VikingGetListResp{Data: list}) return } diff --git a/modules/viking/comp_configure.go b/modules/viking/comp_configure.go index cdcb6aa28..1717731d0 100644 --- a/modules/viking/comp_configure.go +++ b/modules/viking/comp_configure.go @@ -11,9 +11,7 @@ import ( ) const ( - game_gourmet = "game_gourmet.json" - game_gourmetskill = "game_gourmetskill.json" - game_drop = "game_drop.json" + game_vikingboss = "game_vikingboss.json" ) ///配置管理基础组件 @@ -21,23 +19,21 @@ type configureComp struct { cbase.ModuleCompBase hlock sync.RWMutex modules.MCompConfigure - _gourmetMap map[int64]*cfg.GameGourmetData - _gourmetSkillMap map[int64]*cfg.GameGourmetSkillData - _dropMap map[int32][]*cfg.GameDropData // 掉落表 key 是DiropId + _vikingMap map[int64]*cfg.GameVikingBossData } //组件初始化接口 func (this *configureComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) { err = this.ModuleCompBase.Init(service, module, comp, options) - this._gourmetMap = make(map[int64]*cfg.GameGourmetData, 0) - configure.RegisterConfigure(game_gourmet, cfg.NewGameGourmet, func() { - if v, err := this.GetConfigure(game_gourmet); err == nil { - if configure, ok := v.(*cfg.GameGourmet); ok { + this._vikingMap = make(map[int64]*cfg.GameVikingBossData, 0) + configure.RegisterConfigure(game_vikingboss, cfg.NewGameVikingBoss, func() { + if v, err := this.GetConfigure(game_vikingboss); err == nil { + if configure, ok := v.(*cfg.GameVikingBoss); ok { this.hlock.Lock() defer this.hlock.Unlock() for _, value := range configure.GetDataList() { - this._gourmetMap[int64(value.Type<<16)+int64(value.Level)] = value + this._vikingMap[int64(value.Type<<16)+int64(value.Difficulty)] = value } return } @@ -45,81 +41,14 @@ func (this *configureComp) Init(service core.IService, module core.IModule, comp log.Errorf("get game_pagoda conf err:%v", err) return }) - this._gourmetSkillMap = make(map[int64]*cfg.GameGourmetSkillData, 0) - configure.RegisterConfigure(game_gourmetskill, cfg.NewGameGourmetSkill, func() { - if v, err := this.GetConfigure(game_gourmetskill); err == nil { - if configure, ok := v.(*cfg.GameGourmetSkill); ok { - this.hlock.Lock() - defer this.hlock.Unlock() - for _, value := range configure.GetDataList() { - this._gourmetSkillMap[int64(value.Type<<16)+int64(value.Level)] = value - } - return - } - } - log.Errorf("get game_pagoda conf err:%v", err) - return - }) - this._dropMap = make(map[int32][]*cfg.GameDropData, 0) - configure.RegisterConfigure(game_drop, cfg.NewGameDrop, func() { - if v, err := this.GetConfigure(game_drop); err == nil { - if configure, ok := v.(*cfg.GameDrop); ok { - this.hlock.Lock() - defer this.hlock.Unlock() - for _, value := range configure.GetDataList() { - this._dropMap[value.Dropid] = append(this._dropMap[value.Dropid], value) - } - return - } - } - log.Errorf("get game_pagoda conf err:%v", err) - return - }) - // _data := this.GetGourmetConfigData(1002, 4) // 测试配置文件读取 - // _dataskill := this.GetGourmetSkillConfigData(1001, 4) - // _data := this.GetDropData(1001) - // fmt.Printf("%v", _data) + return } -// 获取美食馆配置数据 -func (this *configureComp) GetGourmetConfigData(gourmetType int32, level int32) (data *cfg.GameGourmetData) { +// 参数: boss类型 难度 +func (this *configureComp) GetVikingBossConfigData(bossType int32, difficulty int32) (data *cfg.GameVikingBossData) { - return this._gourmetMap[int64(gourmetType<<16)+int64(level)] -} - -// 获取美食馆配置数据 -func (this *configureComp) GetGourmetSkillConfigData(gourmetType int32, level int32) (data *cfg.GameGourmetSkillData) { - - return this._gourmetSkillMap[int64(gourmetType<<16)+int64(level)] -} - -// 通过技能id 查询技能配置表 -func (this *configureComp) GetGourmetSkillConfigBySkillID(skillId int) (data *cfg.GameGourmetSkillData) { - - if v, err := this.GetConfigure(game_gourmetskill); err == nil { - if configure, ok := v.(*cfg.GameGourmetSkill); ok { - data = configure.Get(int32(skillId)) - return - } - } - return -} - -func (this *configureComp) GetGourmetSkillConfigBySkillType(skillType int) (szSkill []int32) { - szSkill = make([]int32, 0) - if v, err := this.GetConfigure(game_gourmetskill); err == nil { - if configure, ok := v.(*cfg.GameGourmetSkill); ok { - for _, data := range configure.GetDataList() { - if skillType == int(data.SkillType) && data.Initial == 1 { - szSkill = append(szSkill, data.Type) - } - } - //data = configure.Get(int32(skillId)) - return - } - } - return + return this._vikingMap[int64(bossType<<16)+int64(difficulty)] } //加载多个配置文件 @@ -139,7 +68,21 @@ func (this *configureComp) GetConfigure(name string) (v interface{}, err error) return configure.GetConfigure(name) } -func (this *configureComp) GetDropData(dropId int32) (data []*cfg.GameDropData) { - data = this._dropMap[dropId] +// get boss Type +func (this *configureComp) GetVikingBossTypeConfigData() (mapType map[int32]struct{}) { + + mapType = make(map[int32]struct{}, 0) + if v, err := this.GetConfigure(game_vikingboss); err == nil { + if configure, ok := v.(*cfg.GameVikingBoss); ok { + this.hlock.Lock() + defer this.hlock.Unlock() + for _, value := range configure.GetDataList() { + if _, ok := mapType[value.Type]; !ok { + mapType[value.Type] = struct{}{} + } + } + + } + } return } diff --git a/modules/viking/model_gourmet.go b/modules/viking/model_viking.go similarity index 83% rename from modules/viking/model_gourmet.go rename to modules/viking/model_viking.go index 5ceae76cb..4a01b4889 100644 --- a/modules/viking/model_gourmet.go +++ b/modules/viking/model_viking.go @@ -3,6 +3,7 @@ package viking import ( "go_dreamfactory/comm" "go_dreamfactory/lego/core" + "go_dreamfactory/lego/sys/redis" "go_dreamfactory/modules" "go_dreamfactory/pb" cfg "go_dreamfactory/sys/configure/structs" @@ -27,17 +28,14 @@ func (this *modelViking) Init(service core.IService, module core.IModule, comp c return } -// func (this *modelViking) getVikingList(uid string) (result *pb.DBViking, err error) { -// result = &pb.DBViking{} -// if err = this.Get(uid, result); err != nil { -// if redis.RedisNil != err { // 没有数据直接创建新的数据 -// return -// } -// } -// err = nil -// return result, err - -// } +func (this *modelViking) getVikingList(uid string) (result *pb.DBViking, err error) { + result = &pb.DBViking{} + if err = this.Get(uid, result); err != nil && redis.RedisNil != err { + return + } + err = nil + return result, err +} func (this *modelViking) modifyVikingDataByObjId(uid string, data map[string]interface{}) error { return this.Change(uid, data) diff --git a/pb/viking_db.pb.go b/pb/viking_db.pb.go index c1a44c6dd..8b9f6831b 100644 --- a/pb/viking_db.pb.go +++ b/pb/viking_db.pb.go @@ -26,12 +26,12 @@ type DBViking struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id" bson:"_id"` //ID - Uid string `protobuf:"bytes,2,opt,name=uid,proto3" json:"uid" bson:"uid"` //用户ID - ChallengeCount int32 `protobuf:"varint,3,opt,name=challengeCount,proto3" json:"challengeCount" bson:"challengeCount"` //挑战次数 - Boos map[int32]bool `protobuf:"bytes,4,rep,name=boos,proto3" json:"boos" protobuf_key:"varint,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3"` // key boos 类型 value 难度 - BuyCount int32 `protobuf:"varint,5,opt,name=buyCount,proto3" json:"buyCount" bson:"buyCount"` //购买次数 - CTime int64 `protobuf:"varint,6,opt,name=cTime,proto3" json:"cTime" bson:"cTime"` //修改时间 + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id" bson:"_id"` //ID + Uid string `protobuf:"bytes,2,opt,name=uid,proto3" json:"uid" bson:"uid"` //用户ID + ChallengeCount int32 `protobuf:"varint,3,opt,name=challengeCount,proto3" json:"challengeCount" bson:"challengeCount"` //挑战次数 + Boos map[int32]int32 `protobuf:"bytes,4,rep,name=boos,proto3" json:"boos" protobuf_key:"varint,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3"` // key boos 类型 value 难度 + BuyCount int32 `protobuf:"varint,5,opt,name=buyCount,proto3" json:"buyCount" bson:"buyCount"` //购买次数 + CTime int64 `protobuf:"varint,6,opt,name=cTime,proto3" json:"cTime" bson:"cTime"` //修改时间 } func (x *DBViking) Reset() { @@ -87,7 +87,7 @@ func (x *DBViking) GetChallengeCount() int32 { return 0 } -func (x *DBViking) GetBoos() map[int32]bool { +func (x *DBViking) GetBoos() map[int32]int32 { if x != nil { return x.Boos } @@ -126,7 +126,7 @@ var file_viking_viking_db_proto_rawDesc = []byte{ 0x01, 0x28, 0x03, 0x52, 0x05, 0x63, 0x54, 0x69, 0x6d, 0x65, 0x1a, 0x37, 0x0a, 0x09, 0x42, 0x6f, 0x6f, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, - 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x08, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, + 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, }