| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- package mapPlayer
- import (
- "f1-game/internal/data"
- "f1-game/internal/event"
- "f1-game/nodes/map/internal/db"
- mapFacade "f1-game/nodes/map/internal/facade"
- "f1-game/nodes/map/player/conscript"
- "f1-game/nodes/map/player/facility"
- "f1-game/nodes/map/player/hero"
- show "f1-game/nodes/map/player/show"
- "f1-game/nodes/map/player/storage"
- "f1-game/nodes/map/player/team"
- "time"
- )
- func (p *actorPlayer) startTimer() {
- if !p.isOnline {
- return
- }
- //移除所有定时器
- p.Timer().RemoveAll()
- // 添加跨天定时器
- p.Timer().AddFixedHour(int(data.Const.ResetTime), 0, 0, p.onCrossDayTimer)
- // 添加每秒定时器
- p.Timer().Add(1*time.Second, p.every1STimer)
- // 资源定时器
- p.Timer().Add(3*time.Second, p.every3STimer)
- }
- // onCrossDayTimer 跨天执行定时器
- func (p *actorPlayer) onCrossDayTimer() {
- // 不在线不处理跨天,等下次登录的时候处理
- if !p.isOnline {
- return
- }
- // 更新时间
- p.updateNowTime()
- playerTable := db.GetMapPlayerTable(p.playerID)
- // 跨天重置处理
- p.onReset(playerTable, false)
- p.Debug("[crossDay] isOnline = %v", p.isOnline)
- }
- // oneSecondTimer 每1秒定时器
- func (p *actorPlayer) every1STimer() {
- if !p.isOnline {
- return
- }
- p.updateNowTime()
- nowSecond := p.now.ToSecond()
- facility.Service().CheckQueue(p.playerID, nowSecond)
- conscript.Service().ConscriptSettle(p.playerID, nowSecond)
- // 检查守军状态
- playerTable := db.GetMapPlayerTable(p.playerID)
- if playerTable == nil {
- return
- }
- playerTable.CheckDefendStatus(nowSecond)
- // 城外征兵
- team.Service().TeamOutsideAutoTroopsTimer(p.playerID, nowSecond)
- // 定时检测是否可以城外征兵
- team.Service().CheckCanOutsideAutoTroopsTimer(p.playerID, p.now.ToSecond())
- }
- // threeSecondTimer 每3秒定时器
- func (p *actorPlayer) every3STimer() {
- playerTable := db.GetMapPlayerTable(p.playerID)
- if playerTable == nil {
- return
- }
- hero.Service().CheckAddEnergyTimer(playerTable, p.now.ToSecond())
- // 检查资源自动产出
- storage.Service().CheckAutoAdd(playerTable, p.now.ToSecond(), p.isOnline)
- // 检查主城显示过期
- show.Service().CheckMainCityShowExpire(playerTable, p.now.ToSecond())
- // 检查VIP是否过期
- if !playerTable.Vip.IsExpired && playerTable.Vip.ExpireTime < p.now.ToMillisecond() {
- // 设置过期状态
- playerTable.Vip.IsExpired = true
- playerTable.Save2Queue()
- }
- }
- // onReset 重置处理(每次登录、跨天触发)
- func (p *actorPlayer) onReset(playerTable *db.MapPlayerTable, byLogin bool) {
- playerTable.Stats.CheckReset(p.now)
- // 无需重置,则跳过
- if !playerTable.Stats.IsCanReset() {
- return
- }
- // 各系统模块执行重置
- mapFacade.ServiceOnReset(playerTable, p.now, byLogin)
- // 发送跨天重置事件
- p.PostEvent(event.NewPlayerReset(p.playerID))
- p.Warn("daily reset finish. playerID=%d", p.playerID)
- }
|