player_timer.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package player
  2. import (
  3. "f1-game/internal/data"
  4. "f1-game/nodes/game/player/chapter"
  5. "f1-game/nodes/game/player/lord"
  6. "f1-game/nodes/game/player/vip"
  7. "time"
  8. )
  9. func (p *actorPlayer) startTimer() {
  10. if !p.isOnline {
  11. return
  12. }
  13. //移除所有定时器
  14. p.Timer().RemoveAll()
  15. // 添加跨天定时器
  16. p.Timer().AddFixedHour(int(data.Const.ResetTime), 0, 0, p.onCrossDayTimer)
  17. // 添加每秒定时器
  18. p.Timer().Add(1*time.Second, p.every1STimer)
  19. // 资源定时器
  20. p.Timer().Add(3*time.Second, p.every3STimer)
  21. }
  22. // onCrossDayTimer 跨天执行定时器
  23. func (p *actorPlayer) onCrossDayTimer() {
  24. // 不在线不处理跨天,等下次登录的时候处理
  25. if !p.isOnline {
  26. return
  27. }
  28. // 更新时间
  29. p.updateNowTime()
  30. // 跨天重置处理
  31. p.onReset(p.PlayerTable(), false)
  32. p.Debug("[crossDay] isOnline = %v", p.isOnline)
  33. }
  34. // oneSecondTimer 每1秒定时器
  35. func (p *actorPlayer) every1STimer() {
  36. if !p.isOnline {
  37. return
  38. }
  39. p.updateNowTime()
  40. nowSecond := p.now.ToSecond()
  41. chapter.Service().StaminaRecoverTimer(p.playerID, nowSecond)
  42. lord.Service().CheckShowExpireTimer(p.playerID, nowSecond)
  43. vip.Service().CheckVipExpired(p.playerID)
  44. }
  45. // threeSecondTimer 每3秒定时器
  46. func (p *actorPlayer) every3STimer() {
  47. p.checkFriendSend()
  48. }