aoi_manager.go 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. package model
  2. import (
  3. "rocommon/util"
  4. "roserver/serverproto"
  5. )
  6. type RoleMapManager struct {
  7. aoiMapList map[uint64]*AoiMap //根据工会ID创建aoimap
  8. playerMapList map[uint64]*AoiMap //快速查找玩家所在的地图[cliID, AoiMap]
  9. playerUidList map[uint64]*MapRole
  10. updateTimer util.ServerTimer //主循环定时器
  11. //todo...
  12. // 所在服务器dump后的处理,玩家主动离线
  13. // 玩家进入地图时附带当前处于哪个服务器的信息,后续做dump(主动关闭服务器)处理
  14. }
  15. //同步地图个数(公会),主城是一个
  16. const MAX_AOI_MAP_NUM = 20
  17. func newAoiRoleMapManager() *RoleMapManager {
  18. roleMapMag := &RoleMapManager{}
  19. roleMapMag.aoiMapList = make(map[uint64]*AoiMap)
  20. roleMapMag.playerMapList = make(map[uint64]*AoiMap)
  21. roleMapMag.playerUidList = make(map[uint64]*MapRole)
  22. //主城
  23. roleMapMag.aoiMapList[0] = NewAoiMap(0)
  24. roleMapMag.updateTimer = util.NewDurationTimer(util.GetCurrentTime(), 300)
  25. return roleMapMag
  26. }
  27. func (this *RoleMapManager) GetAoiMap(mapType int32, guildId uint64) *AoiMap {
  28. if mapType == 0 {
  29. return this.aoiMapList[0]
  30. } else {
  31. if aoi, ok := this.aoiMapList[guildId]; ok {
  32. return aoi
  33. } else {
  34. aoi := NewAoiMap(guildId)
  35. aoi.mapType = mapType
  36. this.aoiMapList[guildId] = aoi
  37. return aoi
  38. }
  39. }
  40. }
  41. func (this *RoleMapManager) Move(pos *serverproto.Position, cliId uint64) {
  42. //服务器根据固定时间做更新操作,移动包还是下发给客户端
  43. player, ok := this.playerMapList[cliId]
  44. if ok {
  45. player.PlayerMove(pos, cliId)
  46. }
  47. }
  48. func (this *RoleMapManager) Leave(cliId uint64, serviceId string) (uint64, bool) {
  49. player, ok := this.playerMapList[cliId]
  50. if ok {
  51. return player.PlayerLeave(cliId)
  52. }
  53. return 0, false
  54. }
  55. func (this *RoleMapManager) Update(ms uint64) {
  56. if !this.updateTimer.IsStart() || !this.updateTimer.IsExpired(ms) {
  57. return
  58. }
  59. for _, aoiMap := range this.aoiMapList {
  60. aoiMap.Update(ms)
  61. }
  62. }
  63. //显示形象变更
  64. func (this *RoleMapManager) MapRoleChangeShow(cliId uint64, showInfo *serverproto.PlayerShowInfo) {
  65. tempMap, ok := this.playerMapList[cliId]
  66. if ok {
  67. tempMap.PlayerShowChange(cliId, showInfo)
  68. }
  69. }
  70. //播放动画action
  71. func (this *RoleMapManager) MapRoleDoAction(cliId, uid uint64, actionId int32, pos *serverproto.Position) {
  72. tempMap, ok := this.playerMapList[cliId]
  73. if ok {
  74. tempMap.MapRoleDoAction(cliId, uid, actionId, pos)
  75. }
  76. }
  77. //设置npc显示
  78. func (this *RoleMapManager) SummonSetVisible(summonId uint64, visible bool) {
  79. if this.aoiMapList[0] != nil {
  80. this.aoiMapList[0].SummonSetVisible(summonId, visible)
  81. }
  82. }
  83. func (this *RoleMapManager) FillAoiPlayerShowInfo(info *serverproto.PlayerShowInfo) bool {
  84. player, ok := this.playerUidList[info.Uid]
  85. if !ok {
  86. return false
  87. }
  88. *info = *player.showInfo
  89. return true
  90. }