ActorPickerProxy.lua 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. local DebugProxy = requireProxy("DebugProxy")
  2. local ActorPickerProxy = class("ActorPickerProxy", DebugProxy)
  3. ActorPickerProxy.NAME = global.ProxyTable.ActorPicker
  4. function ActorPickerProxy:ctor()
  5. ActorPickerProxy.super.ctor(self)
  6. self.pickable = {}
  7. self.pickable.pickType = global.MMO.PICK_NONE
  8. self.pickable.actorPicked = 0
  9. self.pickable.xGridPicked = 0
  10. self.pickable.yGridPicked = 0
  11. self.pickable.touchWay = 0
  12. self.lastMouseInsideActor = nil
  13. self._lastMouseActorIsDropItem = false
  14. self.mouseMovePos = nil
  15. self.mouseMoveAble = true
  16. self._touchActorID = nil
  17. self._lastTouchActID = nil
  18. end
  19. function ActorPickerProxy:Cleanup()
  20. self.pickable.pickType = global.MMO.PICK_NONE
  21. self.pickable.actorPicked = 0
  22. self.pickable.xGridPicked = 0
  23. self.pickable.yGridPicked = 0
  24. self.pickable.touchWay = 0
  25. end
  26. function ActorPickerProxy:Assign(pickable)
  27. if pickable then
  28. self.pickable = pickable
  29. global.Facade:sendNotification(global.NoticeTable.PickerChange, self.pickable)
  30. end
  31. end
  32. function ActorPickerProxy:GetPickable()
  33. return self.pickable
  34. end
  35. function ActorPickerProxy:TouchWorldEvent(touchPos, touchWay, eventType)
  36. -- convert touch to world
  37. local touchPosInWorld = Screen2World(touchPos)
  38. -- pick
  39. local pickable = {}
  40. pickable.touchWay = touchWay
  41. pickable.eventType = eventType
  42. --按了守护按钮 英雄去守护
  43. local HeroPropertyProxy = global.Facade:retrieveProxy(global.ProxyTable.HeroPropertyProxy)
  44. if touchWay == global.MMO.MOVE_EVENT_TOUCH_AND_MOUSE_L and eventType == cc.Handler.EVENT_TOUCH_BEGAN and HeroPropertyProxy:HeroIsLogin() and HeroPropertyProxy:getGuardBtnState() then
  45. local MapPos = cc.p(global.sceneManager:WorldPos2MapPos(touchPosInWorld))
  46. HeroPropertyProxy:RequestTargetXY(MapPos.x, MapPos.y)
  47. HeroPropertyProxy:setGuardBtnState(false)
  48. return
  49. end
  50. -- ctrl + 右键 查看
  51. if touchWay == global.MMO.MOVE_EVENT_MOUSE_R and eventType == cc.Handler.EVENT_TOUCH_BEGAN and global.userInputController:IsPressedCtrl() then
  52. local actor = global.actorManager:Pick(touchPosInWorld)
  53. local mainPlayerID = global.gamePlayerController:GetMainPlayerID()
  54. if actor and not actor:IsDie() and (actor:IsPlayer() or actor:IsHumanoid()) and actor:GetID() ~= mainPlayerID then
  55. -- 当前禁止查看
  56. local mapProxy = global.Facade:retrieveProxy(global.ProxyTable.Map)
  57. if mapProxy:IsForbidVisitPlayer() then
  58. ShowSystemChat(GET_STRING(30001071), 255, 249)
  59. return
  60. end
  61. if actor:IsHumanoid() then --人形怪
  62. local disHeadLookHumanoid = tonumber(global.ConstantConfig.disHeadLookHumanoid) == 1
  63. if disHeadLookHumanoid then
  64. ShowSystemTips(GET_STRING(50000269))
  65. return
  66. end
  67. end
  68. local LookPlayerProxy = global.Facade:retrieveProxy(global.ProxyTable.LookPlayerProxy)
  69. LookPlayerProxy:RequestPlayerData(actor:GetID())
  70. return
  71. end
  72. end
  73. -- alt + 右键 快速私聊
  74. if touchWay == global.MMO.MOVE_EVENT_MOUSE_R and eventType == cc.Handler.EVENT_TOUCH_BEGAN and global.userInputController:IsPressedAlt() then
  75. local actor = global.actorManager:Pick(touchPosInWorld)
  76. local mainPlayerID = global.gamePlayerController:GetMainPlayerID()
  77. if actor and not actor:IsDie() and actor:IsPlayer() and actor:GetID() ~= mainPlayerID then
  78. global.Facade:sendNotification(global.NoticeTable.PrivateChatWithTarget, { name = actor:GetName(), uid = actor:GetID() })
  79. return
  80. end
  81. end
  82. -- alt + 鼠标左右键挖肉
  83. if global.userInputController:IsPressedAlt() then
  84. -- touchPosInWorld
  85. local inputProxy = global.Facade:retrieveProxy(global.ProxyTable.PlayerInputProxy)
  86. inputProxy:SetDigDest(touchPosInWorld)
  87. return
  88. end
  89. -- find pickable
  90. local actor = nil
  91. self._touchActorID = nil
  92. if touchWay == global.MMO.MOVE_EVENT_TOUCH_AND_MOUSE_L and eventType == cc.Handler.EVENT_TOUCH_BEGAN then
  93. if global.HUDManager.Pick then
  94. actor = global.HUDManager:Pick(touchPosInWorld)
  95. end
  96. if not actor then
  97. actor = global.actorManager:Pick(touchPosInWorld)
  98. end
  99. local mainPlayerID = global.gamePlayerController:GetMainPlayerID()
  100. local mainPlayer = global.gamePlayerController:GetMainPlayer()
  101. if actor then
  102. -- dead
  103. if actor:IsDie() then
  104. actor = nil
  105. elseif actor:IsDeath() then
  106. if self._lastTouchActID then
  107. global.HUDManager:setVisible(self._lastTouchActID, global.MMO.HUD_TYPE_BATCH_LABEL, global.MMO.HUD_LABEL_NAME, false)
  108. end
  109. if actor and actor:GetID() then
  110. global.HUDManager:setVisible(actor:GetID(), global.MMO.HUD_TYPE_BATCH_LABEL, global.MMO.HUD_LABEL_NAME, true)
  111. self._lastTouchActID = actor:GetID()
  112. self._touchActorID = actor:GetID()
  113. end
  114. actor = nil
  115. elseif actor:IsCave() then
  116. actor = nil
  117. end
  118. end
  119. -- ignore main player
  120. if actor and (actor:GetID() == mainPlayerID) then
  121. actor = nil
  122. end
  123. -- ignore pickup sprite
  124. if actor and actor:IsPickUpSprite() then
  125. actor = nil
  126. end
  127. if actor and not actor:IsAttackType() then
  128. actor = nil
  129. end
  130. if actor and not actor:IsPlayerAttacked() then
  131. actor = nil
  132. end
  133. -- ignore master is main player
  134. -- if actor and (actor:GetMasterID() == mainPlayerID) then
  135. -- actor = nil
  136. -- end
  137. end
  138. local dirtyFlag = false
  139. if actor then
  140. local actorType = actor:GetType()
  141. if actorType == global.MMO.ACTOR_MONSTER then -- monster
  142. dirtyFlag = true
  143. pickable.pickType = global.MMO.PICK_ACTOR_MONSTER
  144. pickable.actorPicked = actor:GetID()
  145. pickable.xGridPicked = actor:GetMapX()
  146. pickable.yGridPicked = actor:GetMapY()
  147. if actor:IsCollection() then
  148. pickable.pickType = global.MMO.PICK_ACTOR_COLLECTION
  149. elseif actor:IsDie() then
  150. if not global.isWinPlayMode or global.userInputController:IsPressedCtrl() then
  151. pickable.pickType = global.MMO.PICK_ACTOR_CORPSE
  152. end
  153. else
  154. pickable.pickType = global.MMO.PICK_ACTOR_MONSTER
  155. end
  156. elseif actorType == global.MMO.ACTOR_PLAYER then -- player
  157. dirtyFlag = true
  158. pickable.pickType = global.MMO.PICK_ACTOR_PLAYER
  159. pickable.actorPicked = actor:GetID()
  160. pickable.xGridPicked = actor:GetMapX()
  161. pickable.yGridPicked = actor:GetMapY()
  162. elseif actorType == global.MMO.ACTOR_NPC then -- NPC
  163. dirtyFlag = true
  164. pickable.pickType = global.MMO.PICK_ACTOR_NPC
  165. pickable.actorPicked = actor:GetID()
  166. pickable.xGridPicked = actor:GetMapX()
  167. pickable.yGridPicked = actor:GetMapY()
  168. elseif actorType == global.MMO.ACTOR_DROPITEM then -- NPC
  169. actor = nil
  170. end
  171. end
  172. if nil == actor then --Nothing was picked.
  173. local mapX, mapY = global.sceneManager:WorldPos2MapPos(touchPosInWorld)
  174. dirtyFlag = true
  175. pickable.pickType = global.MMO.PICK_MAP_GRID
  176. pickable.actorPicked = 0
  177. pickable.xGridPicked = mapX
  178. pickable.yGridPicked = mapY
  179. end
  180. if global.MMO.PICK_ACTOR_NPC == pickable.pickType or
  181. global.MMO.PICK_ACTOR_COLLECTION == pickable.pickType or -- always dirty NPC
  182. global.MMO.PICK_MAP_GRID == pickable.pickType then -- always dirty grid
  183. dirtyFlag = true
  184. end
  185. if dirtyFlag then
  186. self:Assign(pickable)
  187. end
  188. if not self._touchActorID then
  189. if self._lastTouchActID then
  190. global.HUDManager:setVisible(self._lastTouchActID, global.MMO.HUD_TYPE_BATCH_LABEL, global.MMO.HUD_LABEL_NAME, false)
  191. end
  192. end
  193. end
  194. function ActorPickerProxy:MouseMoveWorldEvent(touchPos)
  195. self.mouseMovePos = touchPos
  196. self:checkMouseMoveEvent()
  197. end
  198. function ActorPickerProxy:checkMouseMoveEvent()
  199. if not self.mouseMovePos or not self.mouseMoveAble then
  200. return false
  201. end
  202. -- convert touch to world
  203. local touchPosInWorld = Screen2World(self.mouseMovePos)
  204. -- find pickable
  205. -- actor manager only
  206. local actor = global.actorManager:Pick(touchPosInWorld, true)
  207. if nil == actor or actor:IsBorn() or actor:IsCave() or actor:GetValueByKey(global.MMO.HUD_SNEAK) then --Nothing was picked.
  208. if self.lastMouseInsideActor then
  209. -- 移出
  210. global.Facade:sendNotification(global.NoticeTable.MouseMoveOutActorSide, self.lastMouseInsideActor)
  211. self.lastMouseInsideActor = nil
  212. self._lastMouseActorIsDropItem = false
  213. end
  214. else
  215. if self.lastMouseInsideActor and self.lastMouseInsideActor ~= actor:GetID() then
  216. -- 移出
  217. global.Facade:sendNotification(global.NoticeTable.MouseMoveOutActorSide, self.lastMouseInsideActor)
  218. -- 移入
  219. self.lastMouseInsideActor = actor:GetID()
  220. self._lastMouseActorIsDropItem = actor:IsDropItem()
  221. global.Facade:sendNotification(global.NoticeTable.MouseMoveInActorSide, self.lastMouseInsideActor)
  222. if actor:IsDeath() then
  223. global.HUDManager:setVisible(self.lastMouseInsideActor, global.MMO.HUD_TYPE_BATCH_LABEL, global.MMO.HUD_LABEL_NAME, true)
  224. end
  225. elseif not self.lastMouseInsideActor then
  226. -- 移入
  227. self.lastMouseInsideActor = actor:GetID()
  228. self._lastMouseActorIsDropItem = actor:IsDropItem()
  229. global.Facade:sendNotification(global.NoticeTable.MouseMoveInActorSide, self.lastMouseInsideActor)
  230. if actor:IsDeath() then
  231. global.HUDManager:setVisible(self.lastMouseInsideActor, global.MMO.HUD_TYPE_BATCH_LABEL, global.MMO.HUD_LABEL_NAME, true)
  232. end
  233. end
  234. end
  235. self.mouseMoveAble = false
  236. PerformWithDelayGlobal(function()
  237. self.mouseMoveAble = true
  238. self:checkMouseMoveEvent()
  239. end, 0.1)
  240. end
  241. function ActorPickerProxy:GetLastMouseInsideActor()
  242. return self.lastMouseInsideActor
  243. end
  244. function ActorPickerProxy:GetLastMouseInsideActorIsDropItem()
  245. return self._lastMouseActorIsDropItem
  246. end
  247. function ActorPickerProxy:onRegister()
  248. global.gamePlayerController:RegisterLuaTouchHandler(handler(self, self.TouchWorldEvent))
  249. ActorPickerProxy.super.onRegister(self)
  250. end
  251. return ActorPickerProxy