PickerChangeCommand.lua 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. local PickerChangeCommand = class('PickerChangeCommand', framework.SimpleCommand)
  2. local proxyUtils = requireProxy("proxyUtils")
  3. local function squLen(x, y)
  4. return x * x + y * y
  5. end
  6. function PickerChangeCommand:ctor()
  7. end
  8. function PickerChangeCommand:execute(note)
  9. local pick = note:getBody()
  10. if nil == pick then
  11. return
  12. end
  13. if pick.pickType ~= global.MMO.PICK_ACTOR_NPC then
  14. -- 有选中范围技能
  15. local inptuProxy = global.Facade:retrieveProxy(global.ProxyTable.PlayerInputProxy)
  16. local SkillProxy = global.Facade:retrieveProxy(global.ProxyTable.Skill)
  17. local mainPlayer = global.gamePlayerController:GetMainPlayer()
  18. if SkillProxy:GetSelectSkill() then
  19. local skillID = SkillProxy:GetSelectSkill()
  20. local destPos = {x = pick.xGridPicked, y = pick.yGridPicked}
  21. global.Facade:sendNotification(global.NoticeTable.UserInputLaunch, {skillID = skillID, destPos = destPos})
  22. return nil
  23. end
  24. else
  25. local SkillProxy = global.Facade:retrieveProxy(global.ProxyTable.Skill)
  26. if SkillProxy:GetSelectSkill() then
  27. SkillProxy:ClearSelectSkill()
  28. end
  29. end
  30. if pick.pickType == global.MMO.PICK_MAP_GRID then
  31. self:onPickGrid(pick)
  32. elseif pick.pickType == global.MMO.PICK_ACTOR_PLAYER then
  33. self:onPickPlayer(pick)
  34. elseif pick.pickType == global.MMO.PICK_ACTOR_MONSTER then
  35. self:onPickMosnter(pick)
  36. elseif pick.pickType == global.MMO.PICK_ACTOR_NPC then
  37. self:onPickNpc(pick)
  38. elseif pick.pickType == global.MMO.PICK_ACTOR_COLLECTION then
  39. self:onPickCollection(pick)
  40. elseif pick.pickType == global.MMO.PICK_ACTOR_CORPSE then
  41. self:onPickCorpse(pick)
  42. end
  43. end
  44. function PickerChangeCommand:onPickGrid(pick)
  45. local mainPlayer = global.gamePlayerController:GetMainPlayer()
  46. if not mainPlayer then
  47. return
  48. end
  49. if pick.touchWay == global.MMO.MOVE_EVENT_TOUCH_AND_MOUSE_L and pick.eventType == cc.Handler.EVENT_TOUCH_BEGAN then
  50. -- scene effect
  51. global.Facade:sendNotification(global.NoticeTable.MapPickCursorPosChange, pick)
  52. end
  53. -- attack target id
  54. if pick.touchWay == global.MMO.MOVE_EVENT_TOUCH_AND_MOUSE_L then
  55. local PlayerInputProxy = global.Facade:retrieveProxy(global.ProxyTable.PlayerInputProxy)
  56. PlayerInputProxy:SetAttackState(false)
  57. PlayerInputProxy:ClearAttackTargetID()
  58. --minming
  59. if PlayerInputProxy:CheckMiningAble() then
  60. local sX = mainPlayer:GetMapX()
  61. local sY = mainPlayer:GetMapY()
  62. local dX = pick.xGridPicked
  63. local dY = pick.yGridPicked
  64. -- local len = squLen(sX - dX, sY - dY)
  65. local dir = PlayerInputProxy:Vec2ToDir(cc.pSub(cc.p(dX, dY), cc.p(sX, sY)))
  66. if dir < global.MMO.ORIENT_U or dir > global.MMO.ORIENT_LU then
  67. dir = nil
  68. end
  69. local dest = cc.p(sX, sY)
  70. if dir then
  71. local vec2 = PlayerInputProxy:DirToNormalizeVec2(dir)
  72. if vec2 and next(vec2) then
  73. dest = cc.pAdd(dest, vec2)
  74. end
  75. end
  76. local state = false
  77. if global.sceneManager:GetMapData2DPtr():isObstacle(dest.x, dest.y) ~= 0 or global.userInputController:IsPressedShift() then
  78. global.Facade:sendNotification(global.NoticeTable.UserInputMining, {dir=dir, dest=dest})
  79. return
  80. end
  81. end
  82. -- force attack
  83. if global.userInputController:IsPressedShift() then
  84. global.Facade:sendNotification(global.NoticeTable.LaunchAttackSkill)
  85. return nil
  86. else
  87. if global.dropItemController:PickMainPlayerPosItem( {mapX = pick.xGridPicked, mapY = pick.yGridPicked} ) then
  88. return
  89. end
  90. end
  91. end
  92. -- clear auto data
  93. local autoProxy = global.Facade:retrieveProxy(global.ProxyTable.Auto)
  94. local allowInput = autoProxy:TryExitAutoFight()
  95. if allowInput then
  96. local isInputTurnDir = false
  97. if pick.touchWay == global.MMO.MOVE_EVENT_MOUSE_R and pick.eventType == cc.Handler.EVENT_TOUCH_BEGAN then
  98. -- input turn
  99. local sX = mainPlayer:GetMapX()
  100. local sY = mainPlayer:GetMapY()
  101. local dX = pick.xGridPicked
  102. local dY = pick.yGridPicked
  103. local len = squLen(sX - dX, sY - dY)
  104. local range = 2
  105. if (len <= range) then
  106. isInputTurnDir = true
  107. end
  108. end
  109. if isInputTurnDir then
  110. -- input turn
  111. local PlayerInputProxy = global.Facade:retrieveProxy(global.ProxyTable.PlayerInputProxy)
  112. local direction = PlayerInputProxy:getCursorWorldDirection()
  113. PlayerInputProxy:SetMouseTurnDir(direction)
  114. else
  115. -- input move
  116. local PlayerInputProxy = global.Facade:retrieveProxy(global.ProxyTable.PlayerInputProxy)
  117. PlayerInputProxy:SetMouseTouchPos(cc.p(pick.xGridPicked, pick.yGridPicked))
  118. PlayerInputProxy:SetMouseTouchWay(pick.touchWay)
  119. end
  120. else
  121. global.Facade:sendNotification(global.NoticeTable.SystemTips, GET_STRING(800001))
  122. end
  123. end
  124. function PickerChangeCommand:onPickNpc(pick)
  125. -- attack target id
  126. if pick.touchWay == global.MMO.MOVE_EVENT_TOUCH_AND_MOUSE_L then
  127. local PlayerInputProxy = global.Facade:retrieveProxy(global.ProxyTable.PlayerInputProxy)
  128. PlayerInputProxy:SetAttackState(false)
  129. PlayerInputProxy:ClearAttackTargetID()
  130. -- force attack
  131. if global.userInputController:IsPressedShift() then
  132. if GUIFunction and GUIFunction.CheckShiftTarget and GUIFunction:CheckShiftTarget(pick.actorPicked) then
  133. return nil
  134. end
  135. global.Facade:sendNotification(global.NoticeTable.LaunchAttackSkill)
  136. return nil
  137. end
  138. end
  139. -- change target
  140. local inputProxy = global.Facade:retrieveProxy(global.ProxyTable.PlayerInputProxy)
  141. inputProxy:SetTargetID(pick.actorPicked, global.MMO.SELETE_TARGET_TYPE_PICK)
  142. -- click npc
  143. local npcProxy = global.Facade:retrieveProxy(global.ProxyTable.NPC)
  144. if npcProxy then
  145. npcProxy:CheckTalk(pick.actorPicked, false)
  146. end
  147. end
  148. function PickerChangeCommand:onPickMosnter(pick)
  149. -- attack target id
  150. if pick.touchWay == global.MMO.MOVE_EVENT_TOUCH_AND_MOUSE_L and pick.eventType == cc.Handler.EVENT_TOUCH_BEGAN then
  151. local PlayerInputProxy = global.Facade:retrieveProxy(global.ProxyTable.PlayerInputProxy)
  152. PlayerInputProxy:SetAttackState(true)
  153. PlayerInputProxy:SetAttackTargetID(pick.actorPicked)
  154. -- force attack
  155. if global.userInputController:IsPressedShift() then
  156. if GUIFunction and GUIFunction.CheckShiftTarget and GUIFunction:CheckShiftTarget(pick.actorPicked) then
  157. return nil
  158. end
  159. global.Facade:sendNotification(global.NoticeTable.LaunchAttackSkill)
  160. return nil
  161. end
  162. end
  163. -- change target
  164. local inputProxy = global.Facade:retrieveProxy(global.ProxyTable.PlayerInputProxy)
  165. local isChangTarget = pick.actorPicked ~= inputProxy:GetTargetID()
  166. inputProxy:SetTargetID(pick.actorPicked, global.MMO.SELETE_TARGET_TYPE_PICK)
  167. if isChangTarget and inputProxy:GetCurrMoveType() == global.MMO.INPUT_MOVE_TYPE_LAUNCH and inputProxy:GetCurrPathPoint() > 0 then
  168. inputProxy:ClearMove()
  169. end
  170. end
  171. function PickerChangeCommand:onPickCollection(pick)
  172. -- attack target id
  173. if pick.touchWay == global.MMO.MOVE_EVENT_TOUCH_AND_MOUSE_L then
  174. local PlayerInputProxy = global.Facade:retrieveProxy(global.ProxyTable.PlayerInputProxy)
  175. PlayerInputProxy:SetAttackState(false)
  176. -- force attack
  177. if global.userInputController:IsPressedShift() then
  178. if GUIFunction and GUIFunction.CheckShiftTarget and GUIFunction:CheckShiftTarget(pick.actorPicked) then
  179. return nil
  180. end
  181. global.Facade:sendNotification(global.NoticeTable.LaunchAttackSkill)
  182. return nil
  183. end
  184. end
  185. local inputProxy = global.Facade:retrieveProxy(global.ProxyTable.PlayerInputProxy)
  186. if pick.actorPicked ~= inputProxy:GetTargetID() then
  187. -- change target
  188. inputProxy:SetTargetID(pick.actorPicked, global.MMO.SELETE_TARGET_TYPE_PICK)
  189. end
  190. global.Facade:sendNotification(global.NoticeTable.AutoFindCollection)
  191. end
  192. function PickerChangeCommand:onPickPlayer(pick)
  193. -- baitan
  194. local playerId = pick.actorPicked
  195. local palyerActor = global.actorManager:GetActor(playerId)
  196. if palyerActor and palyerActor:IsStallStatus() then
  197. local StallProxy = global.Facade:retrieveProxy(global.ProxyTable.StallProxy)
  198. StallProxy:RequestItemList(playerId)
  199. return
  200. end
  201. -- attack target id
  202. if pick.touchWay == global.MMO.MOVE_EVENT_TOUCH_AND_MOUSE_L and pick.eventType == cc.Handler.EVENT_TOUCH_BEGAN then
  203. -- attack state
  204. local attackState = true
  205. local attackTargetID = pick.actorPicked
  206. local PlayerInputProxy = global.Facade:retrieveProxy(global.ProxyTable.PlayerInputProxy)
  207. PlayerInputProxy:SetAttackState(attackState)
  208. PlayerInputProxy:SetAttackTargetID(attackTargetID)
  209. -- force attack
  210. if global.userInputController:IsPressedShift() then
  211. if GUIFunction and GUIFunction.CheckShiftTarget and GUIFunction:CheckShiftTarget(pick.actorPicked) then
  212. return nil
  213. end
  214. global.Facade:sendNotification(global.NoticeTable.LaunchAttackSkill)
  215. return nil
  216. end
  217. end
  218. -- change target
  219. if palyerActor and not palyerActor:GetValueByKey(global.MMO.HUD_SNEAK) then
  220. local inputProxy = global.Facade:retrieveProxy(global.ProxyTable.PlayerInputProxy)
  221. local isChangTarget = pick.actorPicked ~= inputProxy:GetTargetID()
  222. inputProxy:SetTargetID(pick.actorPicked, global.MMO.SELETE_TARGET_TYPE_PICK)
  223. if isChangTarget and inputProxy:GetCurrMoveType() == global.MMO.INPUT_MOVE_TYPE_LAUNCH and inputProxy:GetCurrPathPoint() > 0 then
  224. inputProxy:ClearMove()
  225. end
  226. end
  227. end
  228. function PickerChangeCommand:onPickCorpse(pick)
  229. global.Facade:sendNotification(global.NoticeTable.UserInputCorpse, {corpseID = pick.actorPicked})
  230. end
  231. return PickerChangeCommand