|
@@ -0,0 +1,115 @@
|
|
|
|
|
+package model
|
|
|
|
|
+
|
|
|
|
|
+import (
|
|
|
|
|
+ "rocommon/util"
|
|
|
|
|
+ "roserver/baseserver/model"
|
|
|
|
|
+ "roserver/serverproto"
|
|
|
|
|
+ "time"
|
|
|
|
|
+)
|
|
|
|
|
+
|
|
|
|
|
+type TowerManager struct {
|
|
|
|
|
+ updateTimer util.ServerTimer //更新定时器
|
|
|
|
|
+ initStartUp bool
|
|
|
|
|
+ seasonStartTime, seasonEndTime time.Time
|
|
|
|
|
+ refreshTime time.Time
|
|
|
|
|
+ day int32 //周期
|
|
|
|
|
+ isRefresh bool //已经有玩家到达1000层可以增加周期
|
|
|
|
|
+ initFromDb bool
|
|
|
|
|
+ initFromDb2 bool
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+func newTowerMag() *TowerManager {
|
|
|
|
|
+ mag := &TowerManager{
|
|
|
|
|
+ day: 1,
|
|
|
|
|
+ }
|
|
|
|
|
+ mag.updateTimer = util.NewDurationTimer(util.GetCurrentTime(), 5000)
|
|
|
|
|
+ return mag
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+func (this *TowerManager) init(ms uint64) {
|
|
|
|
|
+ nowTime := util.GetTimeByUint64(ms)
|
|
|
|
|
+ if nowTime.Before(this.seasonEndTime) {
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+ //msg := &serverproto.SSCrossYuanHangTrialRankUpdateReq{}
|
|
|
|
|
+ //SendCrossService(msg)
|
|
|
|
|
+ util.ErrorF("tower rank refresh time:%v", nowTime)
|
|
|
|
|
+ //this.refreshTime = nowTime
|
|
|
|
|
+ this.seasonEndTime = this.seasonEndTime.AddDate(0, 0, 7)
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+// 成功发送消息返回true
|
|
|
|
|
+func (this *TowerManager) initTowerWjInfoFromDB() bool {
|
|
|
|
|
+ //util.InfoF("initCompetitionInfoFromDB send to db")
|
|
|
|
|
+ ssReqMsg := &serverproto.SSGetServerCompetitionReq{}
|
|
|
|
|
+ if SendDb(ssReqMsg) {
|
|
|
|
|
+ return true
|
|
|
|
|
+ }
|
|
|
|
|
+ return false
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+// 获取当前已经开启的赛季ID(from db)
|
|
|
|
|
+func (this *TowerManager) DoUpdateTowerInfoFromDB(ssAckMsg *serverproto.SSGetServerCompetitionAck) {
|
|
|
|
|
+ this.initFromDb = true
|
|
|
|
|
+ if ssAckMsg.TowerInfo != nil {
|
|
|
|
|
+ TowerMag.day = ssAckMsg.TowerInfo.Day
|
|
|
|
|
+ TowerMag.isRefresh = ssAckMsg.TowerInfo.IsRefresh
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+func getThisWeekendAt23PM() time.Time {
|
|
|
|
|
+ now := time.Now()
|
|
|
|
|
+
|
|
|
|
|
+ // 计算到本周日的天数差(Sunday=0,Monday=1...)
|
|
|
|
|
+ daysUntilSunday := (7 - int(now.Weekday())) % 7
|
|
|
|
|
+
|
|
|
|
|
+ // 本周日 23:00:00
|
|
|
|
|
+ weekendAt23PM := time.Date(
|
|
|
|
|
+ now.Year(),
|
|
|
|
|
+ now.Month(),
|
|
|
|
|
+ now.Day()+daysUntilSunday, // 跳到周日
|
|
|
|
|
+ 23, 0, 0, 0, // 23:00:00
|
|
|
|
|
+ now.Location(),
|
|
|
|
|
+ )
|
|
|
|
|
+
|
|
|
|
|
+ return weekendAt23PM
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+func (this *TowerManager) getSeasonTime(seasonId int32) (time.Time, time.Time) {
|
|
|
|
|
+ resetTime := int64((model.ConvertArenaSeason.Reset + 1) * HourMs)
|
|
|
|
|
+ diffDurationDay := model.ConvertArenaSeason.DiffDurationDay
|
|
|
|
|
+ deltaTime := (diffDurationDay + resetTime) * int64(seasonId-1)
|
|
|
|
|
+
|
|
|
|
|
+ loc := util.GetLoc()
|
|
|
|
|
+ startTime := time.Unix(model.ConvertArenaSeason.StartTime.Unix()+deltaTime, 0).In(loc)
|
|
|
|
|
+ endTime := time.Unix(model.ConvertArenaSeason.EndTime.Unix()+deltaTime, 0).In(loc)
|
|
|
|
|
+ return startTime, endTime
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+func (this *TowerManager) Update(ms uint64) {
|
|
|
|
|
+ if !this.initStartUp {
|
|
|
|
|
+ //获取本周星期weekday的时间戳作为排行榜刷新时间
|
|
|
|
|
+ this.seasonEndTime = getThisWeekendAt23PM()
|
|
|
|
|
+ this.initStartUp = true
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ if !this.initFromDb {
|
|
|
|
|
+ if this.initTowerWjInfoFromDB() {
|
|
|
|
|
+ this.initFromDb = true
|
|
|
|
|
+ }
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+ if !this.initFromDb2 {
|
|
|
|
|
+ this.initFromDb = false
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+ this.init(ms)
|
|
|
|
|
+
|
|
|
|
|
+ //if this.initStartUp && this.updateTimer.IsStart() && this.updateTimer.IsExpired(ms) {
|
|
|
|
|
+ // if len(ServerStateCacheList) <= 0 {
|
|
|
|
|
+ // ssStateMsg := &serverproto.SSGetGServerStateReq{
|
|
|
|
|
+ // ServerType: model.SERVICE_NODE_TYPE_GLOBALCROSSMAP,
|
|
|
|
|
+ // }
|
|
|
|
|
+ // SendSocial(ssStateMsg)
|
|
|
|
|
+ // }
|
|
|
|
|
+ //}
|
|
|
|
|
+}
|