runeExplore_mgr.go 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. package model
  2. import (
  3. "rocommon/service"
  4. "rocommon/util"
  5. "roserver/baseserver/model"
  6. "roserver/serverproto"
  7. "time"
  8. )
  9. type StRuneShopExploreManager struct {
  10. *serverproto.StRecRound
  11. curRound int32 // 当前场次
  12. endTime uint64 // 结束时间
  13. startTime uint64 // 开始时间
  14. bClose bool // 所有活動結束
  15. bInit bool // 初始化完成
  16. db *model.StRuneShopExplore
  17. }
  18. //type StRecRound struct {
  19. // overRound int32 // 结束场次
  20. // overtime uint64 // 结束时间
  21. //}
  22. func NewRuneShopExploreManager() *StRuneShopExploreManager {
  23. m := &StRuneShopExploreManager{bClose: false, bInit: false, StRecRound: nil}
  24. return m
  25. }
  26. func (this *StRuneShopExploreManager) IsOpen() bool {
  27. return !this.bClose && util.GetCurrentTime() >= this.startTime
  28. //return this.curRound > 0
  29. }
  30. func (this *StRuneShopExploreManager) IsValid() bool {
  31. return this.bInit
  32. }
  33. func (this *StRuneShopExploreManager) reset() {
  34. this.curRound = 0
  35. this.startTime = 0
  36. this.endTime = 0
  37. this.db = nil
  38. }
  39. func (this *StRuneShopExploreManager) GetCurDb() *model.StRuneShopExplore {
  40. if !this.IsOpen() {
  41. return nil
  42. }
  43. return this.db
  44. }
  45. func (this StRuneShopExploreManager) GetStartTime() uint64 {
  46. return this.startTime
  47. }
  48. func (this StRuneShopExploreManager) GetEndTime() uint64 {
  49. return this.endTime
  50. }
  51. func (this StRuneShopExploreManager) GetCurRound() int32 {
  52. return this.curRound
  53. }
  54. func (this *StRuneShopExploreManager) Close() {
  55. this.OverRound = this.curRound
  56. this.OverTime = this.endTime
  57. this.StartIngTime = 0
  58. this.Sava()
  59. this.reset()
  60. for _, role := range RoleMag.channelRoleList {
  61. if role.GetState() != ROLE_STATE_ONLINE {
  62. continue
  63. }
  64. roleRune := role.(*Role).GetRoleRune()
  65. if roleRune == nil {
  66. continue
  67. }
  68. roleRune.RuneExploreEndAward()
  69. }
  70. }
  71. func (this StRuneShopExploreManager) GetNextStartTime() uint64 {
  72. if this.bClose {
  73. return 0
  74. }
  75. round := this.curRound + 1
  76. //if this.IsOpen() {
  77. // round += 1
  78. //}
  79. db := model.GetRuneExploreDataByRound(round)
  80. if db == nil {
  81. return 0
  82. }
  83. loc := util.GetLoc()
  84. curDay := util.GetDayByTimeStr2(this.endTime)
  85. strStartTime := curDay.AddDate(0, 0, int(db.SellingBegin())).In(loc).Format(util.DATE_FORMAT1) + " " + db.StartTime()
  86. tTime := util.GetTimeByStr(strStartTime)
  87. return uint64(tTime.Unix() * 1000)
  88. }
  89. func (this *StRuneShopExploreManager) init() {
  90. if this.StRecRound == nil {
  91. return
  92. }
  93. //this.StRecRound = &serverproto.StRecRound{}
  94. //curDay := util.GetDayByTimeStr2(service.GetServiceStartupTime())
  95. curTime := util.GetCurrentTimeNow()
  96. this.bClose = true
  97. this.bInit = true
  98. loc := util.GetLoc()
  99. //var recRound int32 = 0
  100. // 按时间顺序排序好的列表
  101. for _, v := range model.DbRuneShopExplore {
  102. if v.GetRound() <= this.OverRound {
  103. continue
  104. }
  105. if this.OverTime <= 0 {
  106. this.OverTime = service.GetServiceStartupTime()
  107. }
  108. var startT time.Time
  109. if this.StartIngTime > 0 { // 正在开启中的
  110. startT = util.GetTimeByUint64(this.StartIngTime)
  111. } else {
  112. strStartTime := util.GetDayByTimeStr2(this.OverTime).AddDate(0, 0, int(v.SellingBegin())).In(loc).Format(util.DATE_FORMAT1) + " " + v.StartTime()
  113. sTime := util.GetTimeByStr(strStartTime)
  114. if curTime.Before(sTime) {
  115. startT = sTime // 活动未开启的
  116. } else {
  117. startT = curTime // 已经开启的重新开始
  118. }
  119. }
  120. closeTime := startT.AddDate(0, 0, int(v.SellingDuration()-1)).In(loc).Format(util.DATE_FORMAT1) + " " + v.CloseTime()
  121. eTime := util.GetTimeByStr(closeTime)
  122. endTime := uint64(eTime.Unix() * 1000)
  123. startTime := uint64(startT.Unix() * 1000)
  124. this.startTime = startTime
  125. this.StartIngTime = startTime
  126. this.endTime = endTime
  127. this.db = v
  128. this.curRound = v.GetRound()
  129. this.bClose = false
  130. break
  131. }
  132. //if this.OverRound <= 0 {
  133. // this.OverRound = recRound
  134. //}
  135. this.Sava()
  136. util.DebugF("战令开始时间: %v, 结束时间:%v, 下一场时间:%v, 场次:%v, 记录数据{%v} 服务器启动时间:%v", util.GetTimeByUint64(this.startTime), util.GetTimeByUint64(this.endTime), util.GetTimeByUint64(this.GetNextStartTime()), this.curRound, this.StRecRound, util.GetTimeByUint64(service.GetServiceStartupTime()))
  137. }
  138. func (this *StRuneShopExploreManager) Sava() {
  139. SendDb(&serverproto.SSServerCompetitionInfoSaveNtf{RoundInfo: this.StRecRound})
  140. }
  141. func (this *StRuneShopExploreManager) Update(ms uint64) {
  142. if this.bClose {
  143. return
  144. }
  145. if this.startTime == 0 {
  146. this.init()
  147. return
  148. }
  149. if this.startTime > ms {
  150. return
  151. }
  152. if !this.IsOpen() {
  153. return
  154. }
  155. if ms >= this.endTime {
  156. this.Close()
  157. return
  158. }
  159. }