package timer import ( "context" "go_dreamfactory/comm" "go_dreamfactory/lego/base" "go_dreamfactory/lego/core" "go_dreamfactory/lego/core/cbase" "go_dreamfactory/lego/sys/log" "go_dreamfactory/lego/sys/timewheel" "go_dreamfactory/modules" "go_dreamfactory/pb" "go_dreamfactory/sys/configure" cfg "go_dreamfactory/sys/configure/structs" "time" ) // 此组件废弃 type CaravanRank struct { cbase.ModuleBase modules.MCompModel service base.IRPCXService module *Timer cTimerObj *timewheel.Task } const ( game_global = "game_global.json" //全局配置表 ) //组件初始化接口 func (this *CaravanRank) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) { this.TableName = comm.TableCaravan this.MCompModel.Init(service, module, comp, options) this.module = module.(*Timer) this.service = service.(base.IRPCXService) err = this.LoadConfigure(game_global, cfg.NewGameGlobal) return } func (this *CaravanRank) LoadConfigure(name string, fn interface{}) (err error) { return configure.RegisterConfigure(name, fn, nil) } //读取配置数据 func (this *CaravanRank) GetConfigure(name string) (v interface{}, err error) { return configure.GetConfigure(name) } //全局配置 func (this *CaravanRank) GetGlobalConf() *cfg.GameGlobalData { var ( configure *cfg.GameGlobal ok bool ) if v, err := this.GetConfigure(game_global); err != nil { log.Errorf("get global conf err:%v", err) return nil } else { if configure, ok = v.(*cfg.GameGlobal); !ok { log.Errorf("%T no is *cfg.Game_global", v) return nil } } return configure.GetDataList()[0] // 返回对象信息 } func (this *CaravanRank) Start() (err error) { err = this.MCompModel.Start() opentime := this.service.GetOpentime().Unix() this.module.Debugf("%d", opentime) //cron.AddFunc("30 10 1 * * ?", this.TimerSeason) this.module.Debugf("--%d", time.Now().Unix()) seasonTime := this.GetGlobalConf().BusinessRewardday if configure.Now().Unix() < opentime { // 开服时间是未来可能存在问题 return } subTime := int32(configure.Now().Unix() - opentime) if subTime < seasonTime { this.cTimerObj = timewheel.Add(time.Second*time.Duration(subTime), this.TimerSeason, nil) } else { s := configure.Now().Unix() - (configure.Now().Unix()-opentime)%int64(subTime) + int64(seasonTime) this.cTimerObj = timewheel.Add(time.Second*time.Duration(s), this.TimerSeason, nil) } return } func (this *CaravanRank) TimerSeason(task *timewheel.Task, args ...interface{}) { this.module.Debugf("==%d", time.Now().Unix()) if _, err := this.service.RpcGo(context.Background(), comm.Service_Worker, string(comm.Rpc_ModuleCaravanSettlement), pb.EmptyReq{}, nil, ); err != nil { this.module.Errorln(err) } if this.cTimerObj != nil { timewheel.Remove(this.cTimerObj) } // 重新开启一个时间轮 this.cTimerObj = timewheel.Add(time.Second*time.Duration(this.GetGlobalConf().BusinessRewardday), this.TimerSeason, nil) }