diff --git a/bin/json/game_seasonloop.json b/bin/json/game_seasonloop.json new file mode 100644 index 000000000..7d9536e78 --- /dev/null +++ b/bin/json/game_seasonloop.json @@ -0,0 +1,21 @@ +[ + { + "key": 2, + "disposable_loop": [ + 201, + 203, + 202, + 204, + 203, + 202, + 201, + 204 + ], + "fixed_loop": [ + 201, + 202, + 203, + 204 + ] + } +] \ No newline at end of file diff --git a/modules/hero/api.go b/modules/hero/api.go index 816def5ed..98810e07e 100644 --- a/modules/hero/api.go +++ b/modules/hero/api.go @@ -2,12 +2,11 @@ package hero import ( "go_dreamfactory/lego/core" - "go_dreamfactory/lego/core/cbase" "go_dreamfactory/modules" ) type apiComp struct { - cbase.ModuleCompBase + //cbase.ModuleCompBase modules.MCompGate service core.IService module *Hero diff --git a/modules/hero/api_fusion.go b/modules/hero/api_fusion.go index 1ad308662..a0d9bf381 100644 --- a/modules/hero/api_fusion.go +++ b/modules/hero/api_fusion.go @@ -72,11 +72,11 @@ func (this *apiComp) Fusion(session comm.IUserSession, req *pb.HeroFusionReq) (c } // 获得新卡 newHero, err := this.module.modelHero.createHeroOverlying(session.GetUserId(), conf.Hero, 1) - if err != nil { + if err == nil { + session.SendMsg(string(this.module.GetType()), HeroFusionResp, &pb.HeroFusionResp{Heroid: conf.Hero}) ChangeList = append(ChangeList, newHero) } session.SendMsg(string(this.module.GetType()), "change", &pb.HeroChangePush{List: ChangeList}) - session.SendMsg(string(this.module.GetType()), HeroFusionResp, &pb.HeroFusionResp{Heroid: conf.Hero}) return } diff --git a/modules/timer/chat.go b/modules/timer/chat.go index fcdcde899..a4753f69a 100644 --- a/modules/timer/chat.go +++ b/modules/timer/chat.go @@ -14,6 +14,7 @@ import ( "go_dreamfactory/lego/sys/cron" "go_dreamfactory/lego/sys/log" + "go.mongodb.org/mongo-driver/bson" "google.golang.org/protobuf/types/known/anypb" ) @@ -77,6 +78,7 @@ func (this *ChatComp) Start() (err error) { } } }) + this.module.chat.module.rank.DB.Find("heor", bson.M{}) return } diff --git a/modules/timer/forum.go b/modules/timer/forum.go index e6be0086a..b3844a94c 100644 --- a/modules/timer/forum.go +++ b/modules/timer/forum.go @@ -10,22 +10,21 @@ import ( /* 装备模块 API */ -type forumComp struct { +type ForumComp struct { modules.MCompModel service core.IService } -//组件初始化接口 -func (this *forumComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) { +func (this *ForumComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) { - this.TableName = comm.TablePagodaRecord + this.TableName = comm.TableHuntingRankList this.MCompModel.Init(service, module, comp, options) this.service = service return } -func (this *forumComp) Start() (err error) { +func (this *ForumComp) Start() (err error) { err = this.MCompModel.Start() - //cron.AddFunc("*/5 * * * * ?", this.Timer) //每五秒执行一次 + //cron.AddFunc("*/60 * * * * ?", this.Timer) //每60s执行一次 return } diff --git a/modules/timer/module.go b/modules/timer/module.go index 92c34bc2b..771bf6486 100644 --- a/modules/timer/module.go +++ b/modules/timer/module.go @@ -27,6 +27,8 @@ type Timer struct { rank2 *VikingRank rank3 *HuntingRank chat *ChatComp //俩天系统定时任务 + season *SeasonPagoda + forum *ForumComp } //模块名 @@ -59,6 +61,8 @@ func (this *Timer) OnInstallComp() { this.rank2 = this.RegisterComp(new(VikingRank)).(*VikingRank) this.rank3 = this.RegisterComp(new(HuntingRank)).(*HuntingRank) this.chat = this.RegisterComp(new(ChatComp)).(*ChatComp) + this.season = this.RegisterComp(new(SeasonPagoda)).(*SeasonPagoda) + } //日志 diff --git a/modules/timer/season.go b/modules/timer/season.go index 31e962b55..5d2703aa5 100644 --- a/modules/timer/season.go +++ b/modules/timer/season.go @@ -1,23 +1,38 @@ package timer import ( + "context" + "fmt" "go_dreamfactory/comm" "go_dreamfactory/modules" + "go_dreamfactory/pb" + "go_dreamfactory/sys/configure" + cfg "go_dreamfactory/sys/configure/structs" "time" "go_dreamfactory/lego/core" + "go_dreamfactory/lego/core/cbase" "go_dreamfactory/lego/sys/cron" + "go_dreamfactory/lego/sys/log" + + "go.mongodb.org/mongo-driver/bson" +) + +var ( + game_seasonloop = "game_seasonloop.json" ) type SeasonPagoda struct { + cbase.ModuleCompBase + modules.MCompConfigure modules.MCompModel service core.IService - dbName string module *Timer } //组件初始化接口 func (this *SeasonPagoda) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) { + this.MCompConfigure.Init(service, module, comp, options) this.TableName = comm.TableSeasonPagoda this.MCompModel.Init(service, module, comp, options) this.service = service @@ -27,14 +42,66 @@ func (this *SeasonPagoda) Init(service core.IService, module core.IModule, comp func (this *SeasonPagoda) Start() (err error) { err = this.MCompModel.Start() + err = this.MCompConfigure.Start() + configure.RegisterConfigure(game_seasonloop, cfg.NewGameSeasonLoop, nil) cron.AddFunc("0 0 23 L * ?", this.TimerSeasonOver) //每月最后一天23点执行一次 cron.AddFunc("0 0 5 /* * ?", this.TimerSeasonStar) //每月第一天5点执行一次 + + // _data := this.GetSeasonLoop(2) + // this.module.Debugf("%v", _data) + + // this.TimerSeasonOver() return } +func (this *SeasonPagoda) GetSeasonLoop(id int32) *cfg.GameSeasonLoopData { + + if v, err := this.GetConfigure(game_seasonloop); err != nil { + log.Errorf("get global conf err:%v", err) + return nil + } else { + if configure, ok := v.(*cfg.GameSeasonLoop); ok { + return configure.Get(id) + } + log.Errorf("%T no is *cfg.Game_global", v) + return nil + } +} // // 赛季塔结束 func (this *SeasonPagoda) TimerSeasonOver() { this.module.Debugf("TimerSeasonOver:%d", time.Now().Unix()) + // 修改 + conf := this.GetSeasonLoop(2) + rest, err := this.DB.Find(comm.TableServerData, bson.M{}) + if err != nil { + serverData := &pb.DBServerData{} + for rest.Next(context.TODO()) { + rest.Decode(serverData) + if serverData.FixedLoop == 0 { + if len(conf.DisposableLoop) >= int(serverData.DisposableLoop) && len(conf.FixedLoop) > 0 { // 开始执行循环逻辑 + serverData.FixedLoop = 1 + serverData.DisposableLoop = 0 + serverData.SeasonType = conf.FixedLoop[int(serverData.FixedLoop)-1] + } else { + serverData.DisposableLoop++ + serverData.SeasonType = conf.DisposableLoop[int(serverData.DisposableLoop)-1] + } + + } else { // 循环 + if len(conf.FixedLoop) >= int(serverData.FixedLoop) { + serverData.FixedLoop = 1 + } else { + serverData.FixedLoop++ + } + serverData.SeasonType = conf.FixedLoop[int(serverData.FixedLoop)-1] + } + + fmt.Printf("%v", serverData) + break + } + + this.DB.UpdateOne(comm.TableServerData, bson.M{}, serverData) + } } // 赛季塔开始 diff --git a/services/worker/main.go b/services/worker/main.go index 4d97b6147..f5eec88e5 100644 --- a/services/worker/main.go +++ b/services/worker/main.go @@ -120,6 +120,14 @@ func (this *Service) InitSys() { conn, err := db.Local() if err == nil { model := db.NewDBModel(comm.TableServerData, 0, conn) + // rest, err1 := model.DB.Find(comm.TableServerData, bson.M{}) + // server1 := &pb.DBServerData{} + // for rest.Next(context.TODO()) { + // rest.Decode(server1) + // fmt.Printf("%v", server1) + // break + // } + _len, err1 := model.DB.CountDocuments(comm.TableServerData, bson.M{}) if err1 != nil && _len > 0 { fmt.Printf("%v,%v", _len, err1) diff --git a/sys/configure/structs/Game.SeasonLoop.go b/sys/configure/structs/Game.SeasonLoop.go new file mode 100644 index 000000000..88a4b39d0 --- /dev/null +++ b/sys/configure/structs/Game.SeasonLoop.go @@ -0,0 +1,42 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +package cfg + +type GameSeasonLoop struct { + _dataMap map[int32]*GameSeasonLoopData + _dataList []*GameSeasonLoopData +} + +func NewGameSeasonLoop(_buf []map[string]interface{}) (*GameSeasonLoop, error) { + _dataList := make([]*GameSeasonLoopData, 0, len(_buf)) + dataMap := make(map[int32]*GameSeasonLoopData) + for _, _ele_ := range _buf { + if _v, err2 := DeserializeGameSeasonLoopData(_ele_); err2 != nil { + return nil, err2 + } else { + _dataList = append(_dataList, _v) + dataMap[_v.Key] = _v + } + } + return &GameSeasonLoop{_dataList:_dataList, _dataMap:dataMap}, nil +} + +func (table *GameSeasonLoop) GetDataMap() map[int32]*GameSeasonLoopData { + return table._dataMap +} + +func (table *GameSeasonLoop) GetDataList() []*GameSeasonLoopData { + return table._dataList +} + +func (table *GameSeasonLoop) Get(key int32) *GameSeasonLoopData { + return table._dataMap[key] +} + + diff --git a/sys/configure/structs/Game.SeasonLoopData.go b/sys/configure/structs/Game.SeasonLoopData.go new file mode 100644 index 000000000..79ec69c1d --- /dev/null +++ b/sys/configure/structs/Game.SeasonLoopData.go @@ -0,0 +1,65 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +package cfg + +import "errors" + +type GameSeasonLoopData struct { + Key int32 + DisposableLoop []int32 + FixedLoop []int32 +} + +const TypeId_GameSeasonLoopData = 1327247853 + +func (*GameSeasonLoopData) GetTypeId() int32 { + return 1327247853 +} + +func (_v *GameSeasonLoopData)Deserialize(_buf map[string]interface{}) (err error) { + { var _ok_ bool; var _tempNum_ float64; if _tempNum_, _ok_ = _buf["key"].(float64); !_ok_ { err = errors.New("key error"); return }; _v.Key = int32(_tempNum_) } + { + var _arr_ []interface{} + var _ok_ bool + if _arr_, _ok_ = _buf["disposable_loop"].([]interface{}); !_ok_ { err = errors.New("disposable_loop error"); return } + + _v.DisposableLoop = make([]int32, 0, len(_arr_)) + + for _, _e_ := range _arr_ { + var _list_v_ int32 + { var _ok_ bool; var _x_ float64; if _x_, _ok_ = _e_.(float64); !_ok_ { err = errors.New("_list_v_ error"); return }; _list_v_ = int32(_x_) } + _v.DisposableLoop = append(_v.DisposableLoop, _list_v_) + } + } + + { + var _arr_ []interface{} + var _ok_ bool + if _arr_, _ok_ = _buf["fixed_loop"].([]interface{}); !_ok_ { err = errors.New("fixed_loop error"); return } + + _v.FixedLoop = make([]int32, 0, len(_arr_)) + + for _, _e_ := range _arr_ { + var _list_v_ int32 + { var _ok_ bool; var _x_ float64; if _x_, _ok_ = _e_.(float64); !_ok_ { err = errors.New("_list_v_ error"); return }; _list_v_ = int32(_x_) } + _v.FixedLoop = append(_v.FixedLoop, _list_v_) + } + } + + return +} + +func DeserializeGameSeasonLoopData(_buf map[string]interface{}) (*GameSeasonLoopData, error) { + v := &GameSeasonLoopData{} + if err := v.Deserialize(_buf); err == nil { + return v, nil + } else { + return nil, err + } +} diff --git a/sys/configure/structs/Tables.go b/sys/configure/structs/Tables.go index c69d33edc..db10b6b11 100644 --- a/sys/configure/structs/Tables.go +++ b/sys/configure/structs/Tables.go @@ -63,6 +63,7 @@ type Tables struct { Opencond *GameOpencond Stroy *GameStroy Pagoda *GamePagoda + SeasonLoop *GameSeasonLoop PagodaTaskReward *GamePagodaTaskReward PagodaSeasonReward *GamePagodaSeasonReward Rdtask *GameRdtask @@ -430,6 +431,12 @@ func NewTables(loader JsonLoader) (*Tables, error) { if tables.Pagoda, err = NewGamePagoda(buf) ; err != nil { return nil, err } + if buf, err = loader("game_seasonloop") ; err != nil { + return nil, err + } + if tables.SeasonLoop, err = NewGameSeasonLoop(buf) ; err != nil { + return nil, err + } if buf, err = loader("game_pagodataskreward") ; err != nil { return nil, err }