105 lines
2.6 KiB
Go
105 lines
2.6 KiB
Go
package timer
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/base"
|
|
"go_dreamfactory/lego/core"
|
|
"go_dreamfactory/lego/core/cbase"
|
|
"go_dreamfactory/lego/sys/cron"
|
|
"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"
|
|
"go_dreamfactory/sys/db"
|
|
"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) {
|
|
if db.IsCross() {
|
|
return
|
|
}
|
|
err = this.MCompModel.Start()
|
|
opentime := this.service.GetOpentime().Unix()
|
|
if configure.Now().Unix() < opentime { // 开服时间是未来可能存在问题
|
|
return
|
|
}
|
|
//获取时分秒
|
|
currentTime := time.Unix(opentime, 0)
|
|
m := currentTime.Minute()
|
|
s := currentTime.Second()
|
|
h := currentTime.Hour()
|
|
day := this.GetGlobalConf().BusinessRewardday
|
|
cronStr := fmt.Sprintf("%d %d %d */%d * ?", m, s, h, day) //
|
|
this.module.Debugf("cron start: %s", cronStr)
|
|
cron.AddFunc(cronStr, this.TimerSeason)
|
|
//this.TimerSeason()
|
|
return
|
|
}
|
|
|
|
func (this *CaravanRank) TimerSeason() {
|
|
this.module.Debugf("TimerSeason start: %d", configure.Now().Unix())
|
|
if err := this.service.RpcCall(
|
|
context.Background(),
|
|
comm.Service_Worker,
|
|
string(comm.Rpc_ModuleCaravanSettlement),
|
|
pb.EmptyReq{},
|
|
nil,
|
|
); err != nil {
|
|
this.module.Errorln(err)
|
|
}
|
|
}
|