BuffEntityHorse.lua 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. local BuffEntityAnim = require("buff/BuffEntityAnim")
  2. local BuffEntityHorse = class("BuffEntitySneak", BuffEntityAnim)
  3. local optionsUtils = requireProxy("optionsUtils")
  4. function BuffEntityHorse:ctor(data)
  5. BuffEntityHorse.super.ctor(self,data)
  6. self._feature = data.param and data.param.feature
  7. self._bindMainHorseActor = nil
  8. self._isExit = data.param and data.param.isExit
  9. end
  10. function BuffEntityHorse:Tick(dt)
  11. BuffEntityHorse.super.Tick(self, dt)
  12. if self:IsInvalid() then
  13. return false
  14. end
  15. local mainPlayer = global.gamePlayerController:GetMainPlayer()
  16. if mainPlayer and self._bindMainHorseActor then
  17. local mainPosXY = mainPlayer:getPosition()
  18. local bindHorsePosXY = self._bindMainHorseActor:getPosition()
  19. if mainPosXY.x ~= bindHorsePosXY.x or mainPosXY.y ~= bindHorsePosXY.y then
  20. mainPlayer:setPosition(bindHorsePosXY.x, bindHorsePosXY.y)
  21. end
  22. if mainPlayer:GetMapX() ~= self._bindMainHorseActor:GetMapX() or mainPlayer:GetMapY() ~= self._bindMainHorseActor:GetMapY() then
  23. global.actorManager:SetActorMapXY( mainPlayer, self._bindMainHorseActor:GetMapX(), self._bindMainHorseActor:GetMapY() )
  24. global.Facade:sendNotification(global.NoticeTable.SceneFollowMainPlayer)
  25. end
  26. end
  27. end
  28. function BuffEntityHorse:UpdateParam(data)
  29. if not data then
  30. data = {}
  31. end
  32. if data.isExit then
  33. self._feature = {}
  34. self:disable()
  35. return
  36. end
  37. if self:IsInvalid() then
  38. self._isInvalid = false
  39. end
  40. self._feature = data.feature
  41. BuffEntityHorse.super.UpdateParam(self, data.param or data)
  42. local actor = global.actorManager:GetActor(self._actorID)
  43. if actor then
  44. self:HorseActor()
  45. end
  46. end
  47. function BuffEntityHorse:OnEnter()
  48. BuffEntityHorse.super.OnEnter(self)
  49. if self._isExit then
  50. self._feature = {}
  51. self:disable()
  52. return
  53. end
  54. self:HorseActor()
  55. -- 通知上马
  56. SLBridge:onLUAEvent(LUA_EVENT_HORSE_UP, {actorID = self._actorID})
  57. end
  58. function BuffEntityHorse:HorseActor()
  59. local actor = global.actorManager:GetActor(self._actorID)
  60. if not actor or not actor:IsPlayer() then
  61. return false
  62. end
  63. if actor:GetID() == actor:GetValueByKey(global.MMO.HORSE_MAIN) then
  64. self:MainHorseActor( actor )
  65. elseif actor:GetID() == actor:GetValueByKey(global.MMO.HORSE_COPILOT) then
  66. self:CopilotHorseActor( actor )
  67. end
  68. end
  69. function BuffEntityHorse:UpdateFeature( actor,feature )
  70. if not actor then
  71. return false
  72. end
  73. if not feature then
  74. feature = {}
  75. end
  76. local actorAttr = GetActorAttrByID(actor:GetID(), global.MMO.ACTOR_ATTR_FEATURE)
  77. actorAttr.mountID = feature.mountID
  78. actorAttr.mountEff = feature.mountEff
  79. actorAttr.mountCloth = feature.mountCloth
  80. actorAttr.hairID = feature.hairID
  81. -- 如果是双人马
  82. if actor:GetValueByKey(global.MMO.HORSE_COPILOT) then
  83. actorAttr.mountID = actorAttr.mountID > 0 and (actorAttr.mountID + actor:GetSexID() + 1) or actorAttr.mountID
  84. actorAttr.mountEff = actorAttr.mountEff > 0 and (actorAttr.mountEff + actor:GetSexID() + 1) or actorAttr.mountEff
  85. actorAttr.mountCloth = actorAttr.mountCloth > 0 and (actorAttr.mountCloth + actor:GetSexID() + 1) or actorAttr.mountCloth
  86. elseif feature.isDown then --如果是下马
  87. actorAttr.mountID = actorAttr.mountID > 0 and (actorAttr.mountID - actor:GetSexID() - 1) or actorAttr.mountID
  88. actorAttr.mountEff = actorAttr.mountEff > 0 and (actorAttr.mountEff - actor:GetSexID() - 1) or actorAttr.mountEff
  89. actorAttr.mountCloth = actorAttr.mountCloth > 0 and (actorAttr.mountCloth - actor:GetSexID() - 1) or actorAttr.mountCloth
  90. end
  91. SetActorAttrByID(actor:GetID(), global.MMO.ACTOR_ATTR_FEATURE, actorAttr)
  92. global.Facade:sendNotification( global.NoticeTable.DelayActorFeatureChange, actorAttr )
  93. end
  94. -- 主驾
  95. function BuffEntityHorse:MainHorseActor( actor )
  96. actor:GetNode():setVisible(true)
  97. -- Hp、Mp
  98. optionsUtils:refreshHUDHMpLabelVisible(actor)
  99. -- 血条
  100. optionsUtils:CheckHUDHpBarVisible(actor)
  101. -- 蓝条
  102. optionsUtils:CheckHUDMpBarVisible(actor)
  103. -- 内功条
  104. optionsUtils:CheckHUDNGBarVisible(actor)
  105. -- 人名、行会、称号、顶戴
  106. optionsUtils:refreshLabelVisible(actor)
  107. optionsUtils:refreshPlayerVisible(actor)
  108. optionsUtils:refreshPlayerBVisible(actor)
  109. optionsUtils:refreshLabelName(actor)
  110. -- 身上的特效
  111. global.ActorEffectManager:RefreshActorEffectVisible(self._actorID, true)
  112. -- 身上的buff特效
  113. global.BuffManager:UpdateBuffItemVisible(self._actorID, true)
  114. -- 颜色
  115. global.Facade:sendNotification(global.NoticeTable.DelayRefreshHUDLabel, {actor = actor, actorID = actor:GetID()})
  116. -- 调整hud位置
  117. global.HUDManager:SetHorseOffset(actor:GetID(), global.MMO.HUD_OFFSET_HORSE)
  118. global.HUDManager:SetHorseOffsetLabel(actor:GetID(), global.MMO.HUD_OFFSET_HORSE_LABEL)
  119. local hudTop = actor:GetHUDTop()
  120. local actorpos = actor:getPosition()
  121. global.HUDManager:setPosition(actor:GetID(), actorpos.x, actorpos.y + hudTop)
  122. self:UpdateFeature(actor, self._feature)
  123. end
  124. -- 副驾
  125. function BuffEntityHorse:CopilotHorseActor( actor )
  126. if actor:IsMainPlayer() then
  127. local mainHorseID = actor:GetValueByKey(global.MMO.HORSE_MAIN)
  128. if mainHorseID then
  129. self._bindMainHorseActor = global.actorManager:GetActor(mainHorseID)
  130. end
  131. end
  132. actor:GetNode():setVisible(false)
  133. -- Hp、Mp
  134. optionsUtils:refreshHUDHMpLabelVisible(actor)
  135. -- 血条
  136. optionsUtils:CheckHUDHpBarVisible(actor)
  137. -- 蓝条
  138. optionsUtils:CheckHUDMpBarVisible(actor)
  139. -- 内功条
  140. optionsUtils:CheckHUDNGBarVisible(actor)
  141. -- 人名、行会、称号、顶戴
  142. optionsUtils:refreshLabelVisible(actor)
  143. optionsUtils:refreshPlayerVisible(actor)
  144. optionsUtils:refreshPlayerBVisible(actor)
  145. optionsUtils:refreshLabelName(actor)
  146. -- 身上的特效
  147. global.ActorEffectManager:RefreshActorEffectVisible(self._actorID, false)
  148. -- 身上的buff特效
  149. global.BuffManager:UpdateBuffItemVisible(self._actorID, false)
  150. -- 颜色
  151. global.Facade:sendNotification(global.NoticeTable.DelayRefreshHUDLabel, {actor = actor, actorID = actor:GetID()})
  152. end
  153. function BuffEntityHorse:UnHorseActor()
  154. local actor = global.actorManager:GetActor(self._actorID)
  155. if not actor or not actor:IsPlayer() then
  156. local mainPlayer = global.gamePlayerController:GetMainPlayer()
  157. if self._actorID ~= mainPlayer:GetValueByKey(global.MMO.HORSE_MAIN) then
  158. return false
  159. end
  160. actor = mainPlayer
  161. self._actorID = mainPlayer:GetID()
  162. end
  163. actor:GetNode():setVisible(true)
  164. actor:dirtyAnimFlag()
  165. -- Hp、Mp
  166. optionsUtils:refreshHUDHMpLabelVisible(actor)
  167. -- 血条
  168. optionsUtils:CheckHUDHpBarVisible(actor)
  169. -- 蓝条
  170. optionsUtils:CheckHUDMpBarVisible(actor)
  171. -- 内功条
  172. optionsUtils:CheckHUDNGBarVisible(actor)
  173. -- 人名、行会、称号、顶戴
  174. optionsUtils:refreshLabelVisible(actor)
  175. optionsUtils:refreshPlayerVisible(actor)
  176. optionsUtils:refreshPlayerBVisible(actor)
  177. optionsUtils:refreshLabelName(actor)
  178. -- 身上的特效
  179. global.ActorEffectManager:RefreshActorEffectVisible(self._actorID, true)
  180. -- 身上的buff特效
  181. global.BuffManager:UpdateBuffItemVisible(self._actorID, true)
  182. -- 颜色
  183. global.Facade:sendNotification(global.NoticeTable.DelayRefreshHUDLabel, {actor = actor, actorID = actor:GetID()})
  184. -- 调整hud位置
  185. global.HUDManager:SetHorseOffset(actor:GetID())
  186. global.HUDManager:SetHorseOffsetLabel(actor:GetID())
  187. local hudTop = actor:GetHUDTop()
  188. local actorpos = actor:getPosition()
  189. global.HUDManager:setPosition(actor:GetID(), actorpos.x, actorpos.y + hudTop)
  190. self:UpdateFeature(actor, self._feature)
  191. end
  192. function BuffEntityHorse:OnExit()
  193. BuffEntityHorse.super.OnExit(self)
  194. self:UnHorseActor()
  195. -- 通知下马
  196. SLBridge:onLUAEvent(LUA_EVENT_HORSE_DOWN, {actorID = self._actorID})
  197. end
  198. return BuffEntityHorse