aoi_map.go 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. package model
  2. import (
  3. "roserver/baseserver/aoi"
  4. "roserver/baseserver/model"
  5. "roserver/serverproto"
  6. )
  7. type MapUnitType int32
  8. const (
  9. MAX_SEND_NUM = 20 * 2
  10. UnityType_Player MapUnitType = 1
  11. UnityType_Boss MapUnitType = 2
  12. UnityType_Other MapUnitType = 3
  13. )
  14. type AoiMap struct {
  15. aoi *aoi.Aoi
  16. mapType int32
  17. mapDynamicId uint64 //公会AOI Id
  18. playerMap map[uint64]*MapRole //[uuid,MapRole]
  19. playerCliMap map[uint64]*MapRole //[cliSessionID,MapRole] not uuid
  20. }
  21. func NewAoiMap(id uint64) *AoiMap {
  22. aoiMap := &AoiMap{
  23. mapDynamicId: id,
  24. }
  25. aoiMap.aoi = aoi.NewAoi()
  26. aoiMap.playerMap = make(map[uint64]*MapRole, 2000)
  27. aoiMap.playerCliMap = make(map[uint64]*MapRole, 2000)
  28. return aoiMap
  29. }
  30. var zeroPosition = serverproto.Position{}
  31. //todo
  32. // 暂时没有处理发送策略,先实现测试效率,后续再根据策略调整,发送哪些玩家的数据
  33. func (this *AoiMap) PlayerEnterMap(pos *serverproto.Position, uid uint64, cli *model.ClientID, unitType int32,
  34. showInfo *serverproto.PlayerShowInfo, isMaster bool) *MapRole {
  35. if pos == nil {
  36. pos = &serverproto.Position{}
  37. }
  38. player, ok := this.playerMap[uid]
  39. if !ok {
  40. player = newMapRole(uid, pos, this, 0)
  41. player.bTestSend = true
  42. player.unitType = unitType
  43. this.playerMap[uid] = player
  44. this.playerCliMap[cli.SessID] = player
  45. } else {
  46. player.pos = *pos
  47. }
  48. player.showInfo = showInfo
  49. player.IsMaster = isMaster
  50. //移除之前的cliId对应数据
  51. if player.cliID.SessID != 0 && player.cliID.SessID != cli.SessID {
  52. delete(RoleMapMag.playerMapList, player.cliID.SessID)
  53. }
  54. player.cliID = *cli
  55. player.selfObj = this.aoi.Enter(uid, player.pos.X, player.pos.Y, player.pos.Z, true, player.IsMaster)
  56. player.syncSurrounding()
  57. //用户快速查找
  58. RoleMapMag.playerMapList[player.cliID.SessID] = this
  59. RoleMapMag.playerUidList[player.uid] = player
  60. return player
  61. }
  62. func (this *AoiMap) NpcEnterMap(pos *serverproto.Position, uid, ownerPlayerUid uint64, isHide bool, unitType int32) bool {
  63. //if pos == nil {
  64. // pos = &serverproto.Position{}
  65. //}
  66. //player, ok := this.playerMap[ownerPlayerUid]
  67. //if !ok {
  68. // util.DebugF("[NpcEnterMap] ownerPlayer not find", ownerPlayerUid)
  69. // return false
  70. //}
  71. //
  72. //npc := newMapRole(uid, pos, this, ownerPlayerUid)
  73. //npc.unitType = unitType
  74. //npc.isHide = isHide
  75. //npc.IsMaster = false
  76. //this.playerMap[uid] = npc
  77. //npc.selfObj = this.aoi.Enter(uid, npc.pos.X, npc.pos.Y, npc.pos.Z, true, npc.IsMaster)
  78. //
  79. ////对其他人隐藏,通知自己
  80. //if isHide {
  81. // enterSelfNtfMsg := &serverproto.SCPlayerEnterNtf{}
  82. // enterSelfNtfMsg.Players = append(enterSelfNtfMsg.Players, &serverproto.Player{
  83. // Uid: uid,
  84. // Pos: pos,
  85. // UType: npc.unitType,
  86. // })
  87. // player.SendGate(enterSelfNtfMsg, nil, true)
  88. //} else {
  89. // npc.summonSyncSurrounding()
  90. //}
  91. //
  92. //util.DebugF("[NpcEnterMap] enter success owner:%v uid:%v", ownerPlayerUid, uid)
  93. return true
  94. }
  95. func (this *AoiMap) PlayerMove(pos *serverproto.Position, cliId uint64) {
  96. if pos == nil {
  97. pos = &zeroPosition
  98. }
  99. player, ok := this.playerCliMap[cliId]
  100. if !ok {
  101. return
  102. }
  103. player.playerMove(pos)
  104. }
  105. func (this *AoiMap) PlayerMoveTo(pos *serverproto.Position, uid uint64) {
  106. if pos == nil {
  107. pos = &zeroPosition
  108. }
  109. player, ok := this.playerMap[uid]
  110. if !ok {
  111. return
  112. }
  113. player.targetPos = *pos
  114. //todo...
  115. }
  116. func (this *AoiMap) PlayerLeave(cliId uint64) (uint64, bool) {
  117. player, ok := this.playerCliMap[cliId]
  118. if !ok {
  119. return 0, false
  120. }
  121. delete(this.playerMap, player.uid)
  122. delete(this.playerCliMap, player.cliID.SessID)
  123. delete(RoleMapMag.playerUidList, player.uid)
  124. delete(RoleMapMag.playerMapList, player.cliID.SessID)
  125. return player.uid, player.playerLeave()
  126. }
  127. func (this *AoiMap) NpcLeave(uid uint64) bool {
  128. player, ok := this.playerMap[uid]
  129. if !ok {
  130. return false
  131. }
  132. delete(this.playerMap, player.uid)
  133. delete(RoleMapMag.playerUidList, player.uid)
  134. return player.playerLeave()
  135. }
  136. func (this *AoiMap) PlayerShowChange(cliId uint64, info *serverproto.PlayerShowInfo) bool {
  137. player, ok := this.playerCliMap[cliId]
  138. if !ok {
  139. return false
  140. }
  141. return player.showChange(info)
  142. }
  143. func (this *AoiMap) MapRoleDoAction(cliId, uid uint64, actionId int32, pos *serverproto.Position) bool {
  144. player, ok := this.playerCliMap[cliId]
  145. if !ok {
  146. return false
  147. }
  148. return player.mapDoDoAction(actionId, pos)
  149. }
  150. func (this *AoiMap) SummonSetVisible(summonId uint64, visible bool) {
  151. player := this.getPlayer(summonId)
  152. if player != nil && player.isHide != !visible {
  153. player.isHide = !visible
  154. player.summonVisibleSyncSurrounding()
  155. }
  156. }
  157. func (this *AoiMap) getPlayer(uid uint64) *MapRole {
  158. if player, ok := this.playerMap[uid]; ok {
  159. return player
  160. }
  161. return nil
  162. }
  163. func (this *AoiMap) getPlayerByCliId(cliId uint64) *MapRole {
  164. if player, ok := this.playerCliMap[cliId]; ok {
  165. return player
  166. }
  167. return nil
  168. }
  169. func (this *AoiMap) Update(ms uint64) {
  170. for id, _ := range this.playerMap {
  171. if this.playerMap[id] == nil {
  172. continue
  173. }
  174. //this.playerMap[id].TestUpdate()
  175. }
  176. }