| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177 |
- package model
- import (
- "rocommon/service"
- "rocommon/util"
- "roserver/baseserver/model"
- "roserver/serverproto"
- "time"
- )
- type StRuneShopExploreManager struct {
- *serverproto.StRecRound
- curRound int32 // 当前场次
- endTime uint64 // 结束时间
- startTime uint64 // 开始时间
- bClose bool // 所有活動結束
- bInit bool // 初始化完成
- db *model.StRuneShopExplore
- }
- //type StRecRound struct {
- // overRound int32 // 结束场次
- // overtime uint64 // 结束时间
- //}
- func NewRuneShopExploreManager() *StRuneShopExploreManager {
- m := &StRuneShopExploreManager{bClose: false, bInit: false, StRecRound: nil}
- return m
- }
- func (this *StRuneShopExploreManager) IsOpen() bool {
- return !this.bClose && util.GetCurrentTime() >= this.startTime
- //return this.curRound > 0
- }
- func (this *StRuneShopExploreManager) IsValid() bool {
- return this.bInit
- }
- func (this *StRuneShopExploreManager) reset() {
- this.curRound = 0
- this.startTime = 0
- this.endTime = 0
- this.db = nil
- }
- func (this *StRuneShopExploreManager) GetCurDb() *model.StRuneShopExplore {
- if !this.IsOpen() {
- return nil
- }
- return this.db
- }
- func (this StRuneShopExploreManager) GetStartTime() uint64 {
- return this.startTime
- }
- func (this StRuneShopExploreManager) GetEndTime() uint64 {
- return this.endTime
- }
- func (this StRuneShopExploreManager) GetCurRound() int32 {
- return this.curRound
- }
- func (this *StRuneShopExploreManager) Close() {
- this.OverRound = this.curRound
- this.OverTime = this.endTime
- this.StartIngTime = 0
- this.Sava()
- this.reset()
- for _, role := range RoleMag.channelRoleList {
- if role.GetState() != ROLE_STATE_ONLINE {
- continue
- }
- roleRune := role.(*Role).GetRoleRune()
- if roleRune == nil {
- continue
- }
- roleRune.RuneExploreEndAward()
- }
- }
- func (this StRuneShopExploreManager) GetNextStartTime() uint64 {
- if this.bClose {
- return 0
- }
- round := this.curRound + 1
- //if this.IsOpen() {
- // round += 1
- //}
- db := model.GetRuneExploreDataByRound(round)
- if db == nil {
- return 0
- }
- loc := util.GetLoc()
- curDay := util.GetDayByTimeStr2(this.endTime)
- strStartTime := curDay.AddDate(0, 0, int(db.SellingBegin())).In(loc).Format(util.DATE_FORMAT1) + " " + db.StartTime()
- tTime := util.GetTimeByStr(strStartTime)
- return uint64(tTime.Unix() * 1000)
- }
- func (this *StRuneShopExploreManager) init() {
- if this.StRecRound == nil {
- return
- }
- //this.StRecRound = &serverproto.StRecRound{}
- //curDay := util.GetDayByTimeStr2(service.GetServiceStartupTime())
- curTime := util.GetCurrentTimeNow()
- this.bClose = true
- this.bInit = true
- loc := util.GetLoc()
- //var recRound int32 = 0
- // 按时间顺序排序好的列表
- for _, v := range model.DbRuneShopExplore {
- if v.GetRound() <= this.OverRound {
- continue
- }
- if this.OverTime <= 0 {
- this.OverTime = service.GetServiceStartupTime()
- }
- var startT time.Time
- if this.StartIngTime > 0 { // 正在开启中的
- startT = util.GetTimeByUint64(this.StartIngTime)
- } else {
- strStartTime := util.GetDayByTimeStr2(this.OverTime).AddDate(0, 0, int(v.SellingBegin())).In(loc).Format(util.DATE_FORMAT1) + " " + v.StartTime()
- sTime := util.GetTimeByStr(strStartTime)
- if curTime.Before(sTime) {
- startT = sTime // 活动未开启的
- } else {
- startT = curTime // 已经开启的重新开始
- }
- }
- closeTime := startT.AddDate(0, 0, int(v.SellingDuration()-1)).In(loc).Format(util.DATE_FORMAT1) + " " + v.CloseTime()
- eTime := util.GetTimeByStr(closeTime)
- endTime := uint64(eTime.Unix() * 1000)
- startTime := uint64(startT.Unix() * 1000)
- this.startTime = startTime
- this.StartIngTime = startTime
- this.endTime = endTime
- this.db = v
- this.curRound = v.GetRound()
- this.bClose = false
- break
- }
- //if this.OverRound <= 0 {
- // this.OverRound = recRound
- //}
- this.Sava()
- 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()))
- }
- func (this *StRuneShopExploreManager) Sava() {
- SendDb(&serverproto.SSServerCompetitionInfoSaveNtf{RoundInfo: this.StRecRound})
- }
- func (this *StRuneShopExploreManager) Update(ms uint64) {
- if this.bClose {
- return
- }
- if this.startTime == 0 {
- this.init()
- return
- }
- if this.startTime > ms {
- return
- }
- if !this.IsOpen() {
- return
- }
- if ms >= this.endTime {
- this.Close()
- return
- }
- }
|