entity.go 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. package model
  2. import (
  3. "roserver/baseserver/aoi"
  4. "roserver/serverproto"
  5. )
  6. type Entity struct {
  7. uid uint64 //uid
  8. ownerUid uint64 //拥有该实体的玩家ID
  9. realZone int32 //实际所在的服务器(发送协议使用)
  10. logicZone int32 //选择登录的区服(显示所在区服使用)
  11. position serverproto.Vector3 //实际位置
  12. lastPos serverproto.Vector3 //上次的实际位置
  13. direction *Direction3D
  14. isOnGround bool //是否在地面上
  15. topSpeed float32 //x,z轴最高移动速度
  16. topSpeedY float32 //y轴最高移动速度
  17. dirChangeTime uint64
  18. posChangeTime uint64
  19. ////
  20. selfObj *aoi.AoiObject //AOI坐标系统中的位置
  21. IsMaster bool
  22. unitType int32
  23. isHide bool
  24. showInfo *serverproto.PlayerShowInfo
  25. selfMapParam *serverproto.SelfCrossMapParam
  26. selfWitness *Witness
  27. UpdateCycle uint64
  28. }
  29. func NewEntity(uid uint64) *Entity {
  30. retEntity := &Entity{
  31. uid: uid,
  32. direction: &Direction3D{},
  33. selfMapParam: &serverproto.SelfCrossMapParam{},
  34. }
  35. return retEntity
  36. }
  37. func (this *Entity) isSummon() bool {
  38. return this.ownerUid > 0
  39. }
  40. func (this *Entity) setWitness(spaceMemory *SpaceMemory) {
  41. witness := &Witness{
  42. spaceMemory: spaceMemory,
  43. }
  44. this.selfWitness = witness
  45. witness.attach(this)
  46. }
  47. func (this *Entity) addPositionAndDirectionStream(msg *serverproto.UnitPosAndDir) {
  48. msg.Uid = this.uid
  49. msg.UType = this.unitType
  50. msg.Pos = &serverproto.Vector3{}
  51. *msg.Pos = this.position
  52. msg.Dir = &serverproto.Vector3{}
  53. *msg.Dir = this.direction.dir
  54. //msg.IsOnGround = this.isOnGround
  55. }
  56. func (this *Entity) onEnterSpace() {
  57. ssAckMsg := &serverproto.SSGCrossMapEnterAck{
  58. LineNum: this.selfWitness.spaceMemory.lineNum,
  59. MapType: this.selfWitness.spaceMemory.mapType,
  60. UnitInfo: &serverproto.UnitPosAndDir{},
  61. }
  62. this.addPositionAndDirectionStream(ssAckMsg.UnitInfo)
  63. this.selfWitness.sendToClient(ssAckMsg)
  64. this.selfWitness.syncEnterNtf()
  65. }
  66. func (this *Entity) onLeaveSpace(uidList []interface{}) {
  67. ssLeaveNtfMsg := &serverproto.SSGCrossMapLeaveNtf{}
  68. ssLeaveNtfMsg.UnitInfoList = append(ssLeaveNtfMsg.UnitInfoList,
  69. &serverproto.UnitPosAndDir{
  70. Uid: this.uid,
  71. Pos: &this.position,
  72. UType: this.unitType,
  73. })
  74. this.selfWitness.sendToClient(ssLeaveNtfMsg)
  75. this.selfWitness.leaveSpace(ssLeaveNtfMsg, uidList)
  76. }
  77. func (this *Entity) FillShowInfo(info *serverproto.PlayerShowInfo) {
  78. if this.showInfo != nil {
  79. *info = *this.showInfo
  80. }
  81. info = this.showInfo
  82. }
  83. //位置同步更新
  84. func (this *Entity) OnUpdateDataFromClient(msg *serverproto.SSGCrossMapSyncPosReq) {
  85. if msg.Pos == nil {
  86. msg.Pos = &zeroPosition
  87. }
  88. if msg.Dir == nil {
  89. msg.Dir = &serverproto.Vector3{}
  90. }
  91. this.selfWitness.OnUpdateDataFromClient(msg.Pos, msg.Dir)
  92. this.position = *msg.Pos
  93. this.direction.dir = *msg.Dir
  94. }
  95. func (this *Entity) UpdateEntityParamFromClient(msg *serverproto.SSGCrossMapSyncParamReq) {
  96. if this.selfWitness != nil {
  97. ssNtfMsg := &serverproto.SSGCrossMapSyncParamNtf{}
  98. ssNtfMsg.SyncUnitList = append(ssNtfMsg.SyncUnitList, &serverproto.UnitPosAndDir{
  99. Uid: this.selfWitness.selfEntity.uid,
  100. Pos: msg.Pos,
  101. Dir: msg.Dir,
  102. ParamId: msg.ParamId,
  103. })
  104. this.selfWitness.playerViewNtf(ssNtfMsg)
  105. //set direction
  106. if msg.Dir != nil {
  107. this.selfWitness.selfEntity.direction.dir = *msg.Dir
  108. }
  109. }
  110. }
  111. func (this *Entity) ShowChange(info *serverproto.PlayerShowInfo) bool {
  112. if info == nil {
  113. return false
  114. }
  115. if info.NickName != "" {
  116. this.showInfo.NickName = info.NickName
  117. }
  118. if info.FashionData != nil {
  119. this.showInfo.FashionData = info.FashionData
  120. }
  121. //MoveSet处理
  122. //地图形象显示变更通知
  123. changeNtfMsg := &serverproto.SSGCrossMapOtherUnitShowInfoNtf{}
  124. changeNtfMsg.ShowInfoList = append(changeNtfMsg.ShowInfoList, info)
  125. this.selfWitness.playerViewNtf(changeNtfMsg)
  126. return true
  127. }
  128. func (this *Entity) update(updateCycle uint64) {
  129. this.UpdateCycle = updateCycle
  130. this.selfWitness.OnUpdatePos(&this.position, &this.direction.dir)
  131. }