From 37fea2cb80023e39d1da374953a6e2d1f4b73c98 Mon Sep 17 00:00:00 2001 From: meixiongfeng <766881921@qq.com> Date: Tue, 14 Mar 2023 18:22:50 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=20=E8=80=97=E6=97=B6?= =?UTF-8?q?=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/hero/hero_test.go | 38 ++++++++++++++ modules/hero/model_hero.go | 4 ++ modules/modulebase.go | 3 +- modules/pagoda/comp_configure.go | 88 +++++++++++++++----------------- modules/smithy/comp_configure.go | 48 ----------------- 5 files changed, 86 insertions(+), 95 deletions(-) diff --git a/modules/hero/hero_test.go b/modules/hero/hero_test.go index dce0a1d87..eeead3176 100644 --- a/modules/hero/hero_test.go +++ b/modules/hero/hero_test.go @@ -101,7 +101,45 @@ func TimerStar() { //this.module.Debugf("=====%d,", time.Since(star).Milliseconds()) } +// 定义结构体 +type sumy struct { + a int + b string + // 嵌入字段 + float32 + bool + next *sumy +} + func Test_Main(t *testing.T) { + + // 值包装结构体 + d := reflect.ValueOf(sumy{ + next: &sumy{}, + }) + // 获取字段数量 + fmt.Println("NumField", d.NumField()) + // 获取索引为2的字段(float32字段) + floatField := d.Field(2) + // 输出字段类型 + fmt.Println("Field", floatField.Type()) + // 根据名字查找字段 + fmt.Println("FieldByName(\"b\").Type", d.FieldByName("b").Type()) + // 根据索引查找值中, next字段的int字段的值 + fmt.Println("FieldByIndex([]int{4, 0}).Type()", d.FieldByIndex([]int{4, 0}).Type()) + + var a int = 1024 + // 获取变量a的反射值对象 + valueOfA := reflect.ValueOf(a) + + fmt.Println(reflect.TypeOf(a), a) + typeofA := reflect.TypeOf(a).Elem().Kind() + // 获取interface{}类型的值, 通过类型断言转换 + var getA int = valueOfA.Interface().(int) + // 获取64位的值, 强制类型转换为int类型 + var getA2 int = int(valueOfA.Int()) + fmt.Println(getA, getA2, typeofA) + cron.AddFunc("0 0 5 /* * ?", TimerStar) //每月第一天5点执行一次 sz := make([]string, 0) for i := 0; i < 10; i++ { diff --git a/modules/hero/model_hero.go b/modules/hero/model_hero.go index 367746b65..81a4ce225 100644 --- a/modules/hero/model_hero.go +++ b/modules/hero/model_hero.go @@ -237,6 +237,8 @@ func (this *ModelHero) resetJuexingProperty(hero *pb.DBHero) { hero.JuexProperty[comm.Atk] += int32(math.Floor((float64(value) / 1000) * float64(hero.Property[comm.Atk]))) case comm.ResonanceDefPro: hero.JuexProperty[comm.Def] += int32(math.Floor((float64(value) / 1000) * float64(hero.Property[comm.Def]))) + default: + this.moduleHero.Errorf("unkonw Resonance property:%s", key) } } } @@ -603,7 +605,9 @@ func (this *ModelHero) AddCardExp(session comm.IUserSession, hero *pb.DBHero, ex // 玩家离线 清除缓存 func (this *ModelHero) RemoveUserHeroInfo(session comm.IUserSession) (err error) { + //star := configure.Now() this.BatchDelLists(session.GetUserId()) + //this.moduleHero.Debugf("=====%d,", time.Since(star).Milliseconds()) return } diff --git a/modules/modulebase.go b/modules/modulebase.go index 84b4eb170..97e6bca57 100644 --- a/modules/modulebase.go +++ b/modules/modulebase.go @@ -202,7 +202,8 @@ func (this *ModuleBase) SendMsgToUsers(mainType, subType string, msg proto.Messa data, _ := anypb.New(msg) for k, v := range gateways { for k1, v1 := range v { - ctx, _ := context.WithTimeout(context.Background(), time.Second*5) + + ctx, _ := context.WithTimeout(context.Background(), time.Second*5) // if _, err = this.service.AcrossClusterRpcGo(ctx, k, fmt.Sprintf("%s/%s", comm.Service_Gateway, k1), string(comm.Rpc_GatewaySendBatchMsg), &pb.BatchMessageReq{ UserSessionIds: v1, MainType: mainType, diff --git a/modules/pagoda/comp_configure.go b/modules/pagoda/comp_configure.go index 287d43410..b84c6b8c2 100644 --- a/modules/pagoda/comp_configure.go +++ b/modules/pagoda/comp_configure.go @@ -20,6 +20,7 @@ const ( ///配置管理基础组件 type configureComp struct { modules.MCompConfigure + module *Pagoda hlock sync.RWMutex _pagodaMap map[int64]*cfg.GamePagodaData _checkType map[int32][]*cfg.GamePassCheckData // key type @@ -28,6 +29,7 @@ type configureComp struct { //组件初始化接口 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) + this.module = module.(*Pagoda) err = this.LoadMultiConfigure(map[string]interface{}{ //game_pagoda: cfg.NewGame_pagoda, game_pagodaseasonreward: cfg.NewGamePagodaSeasonReward, @@ -35,35 +37,9 @@ func (this *configureComp) Init(service core.IService, module core.IModule, comp }) this._pagodaMap = make(map[int64]*cfg.GamePagodaData, 0) - configure.RegisterConfigure(game_pagoda, cfg.NewGamePagoda, func() { - if v, err := this.GetConfigure(game_pagoda); err == nil { - if configure, ok := v.(*cfg.GamePagoda); ok { - this.hlock.Lock() - defer this.hlock.Unlock() - for _, value := range configure.GetDataList() { - this._pagodaMap[int64(value.PagodaType<<16)+int64(value.LayerNum)] = value - } - return - } - } - log.Errorf("get game_pagoda conf err:%v", err) - return - }) + configure.RegisterConfigure(game_pagoda, cfg.NewGamePagoda, this.LoadPagodaData) this._checkType = make(map[int32][]*cfg.GamePassCheckData, 0) - configure.RegisterConfigure(game_passcheck, cfg.NewGamePassCheck, func() { - if v, err := this.GetConfigure(game_passcheck); err == nil { - if configure, ok := v.(*cfg.GamePassCheck); ok { - this.hlock.Lock() - defer this.hlock.Unlock() - for _, value := range configure.GetDataList() { - this._checkType[value.PasscheckType] = append(this._checkType[value.PasscheckType], value) - } - return - } - } - log.Errorf("get game_pagoda conf err:%v", err) - return - }) + configure.RegisterConfigure(game_passcheck, cfg.NewGamePassCheck, this.LoadPassCheck) _data := this.GetPagodaSeasonReward() fmt.Printf("%v", _data) @@ -96,22 +72,13 @@ func (this *configureComp) GetConfigure(name string) (v interface{}, err error) // 爬塔奖励 func (this *configureComp) GetPagodaRewardconfig(id int32) (data *cfg.GamePagodaTaskRewardData) { if v, err := this.GetConfigure(game_pagodataskreward); err == nil { - var ( - configure *cfg.GamePagodaTaskReward - ok bool - ) - if configure, ok = v.(*cfg.GamePagodaTaskReward); !ok { - log.Errorf("%T no is *cfg.Game_pagodaData", v) - return - } - - if data, ok = configure.GetDataMap()[id]; ok { - return + if configure, ok := v.(*cfg.GamePagodaTaskReward); ok { + return configure.Get(id) } } else { log.Errorf("get game_pagodataskreward conf err:%v", err) - return } + return } @@ -155,6 +122,7 @@ func (this *configureComp) GetPassCheckPointByTtype(cType int32) string { return data[0].PayId } } + this.module.Errorf("can't find PassCheckPointByTtype err Type:%d", cType) return "" } @@ -170,15 +138,43 @@ func (this *configureComp) GetPassCheckByID(id int32) *cfg.GamePassCheckData { // 获取 func (this *configureComp) GetPagodaSeasonReward() []*cfg.GamePagodaSeasonRewardData { - if v, err := this.GetConfigure(game_pagodaseasonreward); err == nil { - var ( - configure *cfg.GamePagodaSeasonReward - ok bool - ) - if configure, ok = v.(*cfg.GamePagodaSeasonReward); ok { + if configure, ok := v.(*cfg.GamePagodaSeasonReward); ok { return configure.GetDataList() } } + return nil } + +func (this *configureComp) LoadPagodaData() { + var err error + if v, err := this.GetConfigure(game_pagoda); err == nil { + if configure, ok := v.(*cfg.GamePagoda); ok { + this.hlock.Lock() + defer this.hlock.Unlock() + for _, value := range configure.GetDataList() { + this._pagodaMap[int64(value.PagodaType<<16)+int64(value.LayerNum)] = value + } + return + } + } + log.Errorf("get game_pagoda conf err:%v", err) + return +} + +func (this *configureComp) LoadPassCheck() { + var err error + if v, err := this.GetConfigure(game_passcheck); err == nil { + if configure, ok := v.(*cfg.GamePassCheck); ok { + this.hlock.Lock() + defer this.hlock.Unlock() + for _, value := range configure.GetDataList() { + this._checkType[value.PasscheckType] = append(this._checkType[value.PasscheckType], value) + } + return + } + } + log.Errorf("get game_pagoda conf err:%v", err) + return +} diff --git a/modules/smithy/comp_configure.go b/modules/smithy/comp_configure.go index 0d9156525..07797a477 100644 --- a/modules/smithy/comp_configure.go +++ b/modules/smithy/comp_configure.go @@ -259,51 +259,3 @@ func (this *configureComp) GetSmithyTask(taskId int32) (data *cfg.GameSmithyTask this.module.Errorf("GetSmithyTask notfound taskId:%d", taskId) return } - -// func (this *configureComp) GetSmithyDropData(dropId int32) (data []*cfg.GameSmithyDropData) { -// data = this._dropMap[dropId] -// return -// } - -// func (this *configureComp) GetSmithyDropReward(dropId int32) (result []*cfg.Gameatn) { -// result = make([]*cfg.Gameatn, 0) - -// data := this.GetSmithyDropData(dropId) -// if len(data) == 0 { -// return -// } -// szW := make([]int32, 0) -// for _, value := range data { -// szW = append(szW, value.P) -// } -// index := comm.GetRandW(szW) -// result = append(result, data[index].Prize...) - -// return -// } - -// func (this *configureComp) LoadSmithyDropData() { - -// if v, err := this.GetConfigure(game_smithyDrop); err == nil { -// if configure, ok := v.(*cfg.GameSmithyDrop); ok { -// this.hlock.Lock() -// defer this.hlock.Unlock() -// for _, value := range configure.GetDataList() { -// if value.Condition == 0 { -// this._dropMap[value.Dropid] = append(this._dropMap[value.Dropid], value) -// } else { -// key := value.Condition -// key = value.Dropid*100 + key -// this._dropMap[key] = append(this._dropMap[key], value) -// for _, v1 := range this._dropMap[value.Dropid] { -// this._dropMap[key] = append(this._dropMap[key], v1) -// } -// } -// } -// } - -// } else { -// log.Errorf("get game_pagoda conf err:%v", err) -// } -// return -// }