PlayerInputProxy.lua 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904
  1. local DebugProxy = requireProxy("DebugProxy")
  2. local PlayerInputProxy = class("PlayerInputProxy", DebugProxy)
  3. PlayerInputProxy.NAME = global.ProxyTable.PlayerInputProxy
  4. local cjson = require("cjson")
  5. local DirMaps =
  6. {
  7. {x = 0, y = -1, },
  8. {x = 1, y = -1, },
  9. {x = 1, y = 0, },
  10. {x = 1, y = 1, },
  11. {x = 0, y = 1, },
  12. {x = -1, y = 1, },
  13. {x = -1, y = 0, },
  14. {x = -1, y = -1, },
  15. }
  16. function PlayerInputProxy:ctor()
  17. PlayerInputProxy.super.ctor(self)
  18. self._movePermission = true
  19. ----------- target -------------
  20. self._targetID = nil
  21. self._lastTargetID = nil
  22. self._attackState = false -- 持续攻击状态 shift锁定
  23. self._attackTargetID = nil -- 持续攻击目标
  24. self._ownerPlayerID = nil -- 目标怪物归属的玩家id
  25. self._isTraceOwnerPlayer= false -- 自动追踪归属玩家
  26. ------------------------------
  27. ----------- move -------------
  28. self._moveDestPos = nil
  29. self._moveDirty = false
  30. self._moveType = global.MMO.INPUT_MOVE_TYPE_OTHER
  31. self._currMovePos = nil -- current move to pos
  32. self._pathFindPoints = nil
  33. self._currPathPoint = 0
  34. self._isMoveBlocked = false -- 寻路被
  35. self._launchNoWalkPos = nil -- 攻击时 走路不可通行的位置(强制刷新阻挡)
  36. ------------------------------
  37. ----------- skill -------------
  38. self._launchDirty = false
  39. self._skillID = nil
  40. self._launchPos = nil
  41. self._launchTargetID = nil
  42. self._launchType = global.MMO.LAUNCH_TYPE_USER
  43. self._launchPriority = global.MMO.LAUNCH_PRIORITY_SYSTEM
  44. ------------------------------
  45. ----------- collection -------------
  46. self._collectCount = 0
  47. ------------------------------
  48. ----------- dig coprse -------------
  49. self._coprseID = nil
  50. self._digDest = nil
  51. ------------------------------------
  52. ----------- mining -----------------
  53. self._miningDir = nil
  54. self._miningDest = nil
  55. ------------------------------------
  56. ----------- mouse touch ------------
  57. self._mouseTouchPos = nil
  58. self._mouseTouchWay = nil
  59. ------------------------------------
  60. ----------- mouse turn -------------
  61. self._mouseTurnDir = global.MMO.ORIENT_INVAILD
  62. ------------------------------------
  63. ----------- mouse target ID --------
  64. self._mouseOverTargetID = nil
  65. ------------------------------------
  66. end
  67. --------------- util -----------------
  68. function PlayerInputProxy:calcWorldDirection(dst, src)
  69. local angle = math.deg(cc.pToAngleSelf(cc.pSub(dst, src)))
  70. local ret = global.MMO.ORIENT_INVAILD
  71. if (angle > -22.5 and angle <= 22.5) then -- right
  72. ret = global.MMO.ORIENT_R
  73. elseif (angle > 22.5 and angle <= 67.5) then -- right up
  74. ret = global.MMO.ORIENT_RU
  75. elseif (angle > 67.5 and angle <= 112.5) then -- up
  76. ret = global.MMO.ORIENT_U
  77. elseif (angle > 112.5 and angle <= 157.5) then -- left up
  78. ret = global.MMO.ORIENT_LU
  79. elseif ((angle > 157.5 and angle <= 180) or (angle <= -157.5 and angle > -180)) then -- left
  80. ret = global.MMO.ORIENT_L
  81. elseif (angle <= -112.5 and angle > -157.5) then -- left down
  82. ret = global.MMO.ORIENT_LB
  83. elseif (angle <= -67.5 and angle > -112.5) then -- down
  84. ret = global.MMO.ORIENT_B
  85. elseif (angle <= -22.5 and angle > -67.5) then --right down
  86. ret = global.MMO.ORIENT_RB
  87. end
  88. return ret
  89. end
  90. function PlayerInputProxy:calcMapDirection(dst, src)
  91. local angle = math.deg(cc.pToAngleSelf(cc.pSub(dst, src)))
  92. local ret = global.MMO.ORIENT_INVAILD
  93. if (angle > -22.5 and angle <= 22.5) then -- right
  94. ret = global.MMO.ORIENT_R
  95. elseif (angle > 22.5 and angle <= 67.5) then -- right up
  96. ret = global.MMO.ORIENT_RB
  97. elseif (angle > 67.5 and angle <= 112.5) then -- up
  98. ret = global.MMO.ORIENT_B
  99. elseif (angle > 112.5 and angle <= 157.5) then -- left up
  100. ret = global.MMO.ORIENT_LB
  101. elseif ((angle > 157.5 and angle <= 180) or (angle <= -157.5 and angle > -180)) then -- left
  102. ret = global.MMO.ORIENT_L
  103. elseif (angle <= -112.5 and angle > -157.5) then -- left down
  104. ret = global.MMO.ORIENT_LU
  105. elseif (angle <= -67.5 and angle > -112.5) then -- down
  106. ret = global.MMO.ORIENT_U
  107. elseif (angle <= -22.5 and angle > -67.5) then --right down
  108. ret = global.MMO.ORIENT_RU
  109. end
  110. return ret
  111. end
  112. function PlayerInputProxy:calcMapDistance(dst, src)
  113. return math.max(math.abs(dst.x - src.x), math.abs(dst.y - src.y))
  114. end
  115. function PlayerInputProxy:getCursorWorldPosition()
  116. local cursorPos = global.userInputController:GetCursorPos()
  117. local worldPos = Screen2World(cursorPos)
  118. return worldPos
  119. end
  120. function PlayerInputProxy:getCursorWorldDirection()
  121. local mainPlayer = global.gamePlayerController:GetMainPlayer()
  122. if not mainPlayer then
  123. return global.MMO.ORIENT_INVAILD
  124. end
  125. local src = mainPlayer:getPosition()
  126. local dst = self:getCursorWorldPosition()
  127. return self:calcWorldDirection(dst, src)
  128. end
  129. function PlayerInputProxy:getCursorMapPosition()
  130. local cursorPos = global.userInputController:GetCursorPos()
  131. local worldPos = Screen2World(cursorPos)
  132. local mapX,mapY = global.sceneManager:WorldPos2MapPos(worldPos)
  133. return cc.p(mapX, mapY)
  134. end
  135. function PlayerInputProxy:DirToNormalizeVec2(dir)
  136. if dir <= 7 and dir >= 0 then
  137. return DirMaps[dir + 1]
  138. end
  139. return global.MMO.ORIENT_INVAILD
  140. end
  141. function PlayerInputProxy:getMainPlayerFaceDest()
  142. local mainPlayer = global.gamePlayerController:GetMainPlayer()
  143. if not mainPlayer then
  144. return cc.p(0, 0)
  145. end
  146. local normalize = self:DirToNormalizeVec2(mainPlayer:GetDirection())
  147. return cc.pAdd(cc.p(mainPlayer:GetMapX(), mainPlayer:GetMapY()), normalize)
  148. end
  149. function PlayerInputProxy:Vec2ToDir(vec)
  150. -- convert y
  151. if vec.y ~= 0 then
  152. vec.y = -vec.y
  153. end
  154. local constant = global.MMO
  155. if vec.x == 0 then
  156. if vec.y == 0 then
  157. return constant.ORIENT_INVAILD
  158. elseif vec.y > 0 then
  159. return constant.ORIENT_U
  160. else
  161. return constant.ORIENT_B
  162. end
  163. elseif vec.x > 0 then
  164. if vec.y == 0 then
  165. return constant.ORIENT_R
  166. elseif vec.y > 0 then
  167. return constant.ORIENT_RU
  168. else
  169. return constant.ORIENT_RB
  170. end
  171. else
  172. if vec.y == 0 then
  173. return constant.ORIENT_L
  174. elseif vec.y > 0 then
  175. return constant.ORIENT_LU
  176. else
  177. return constant.ORIENT_LB
  178. end
  179. end
  180. return global.MMO.ORIENT_INVAILD
  181. end
  182. function PlayerInputProxy:MergeVec2(vec)
  183. local ret = bit.lshift(vec.y, 16)
  184. ret = bit.bor(ret, vec.x)
  185. return ret
  186. end
  187. local function squLen(x, y)
  188. return x * x + y * y
  189. end
  190. local function findBestPos(sX, sY, dX, dY, range, enableFunc, minrange)
  191. local mapData = global.sceneManager:GetMapData2DPtr()
  192. if not mapData then
  193. return dX, dY
  194. end
  195. minrange = minrange or 0
  196. if not range or 0 >= range then
  197. return dX, dY
  198. end
  199. local result = {}
  200. local index = 1
  201. local x = nil
  202. local y = nil
  203. local bestIndex = nil
  204. local cost = global.MMO.MAX_CONST
  205. local seqR = range*range
  206. local seqMR = minrange*minrange
  207. -- 1.check origin
  208. local len = squLen(sX - dX, sY - dY)
  209. if (len <= seqR) and (len >= seqMR) and enableFunc(sX, sY, dX, dY) then
  210. return sX, sY
  211. end
  212. -- 2.check other
  213. for offY = -range, range do
  214. for offX = -range, range do
  215. x = dX + offX
  216. y = dY + offY
  217. if enableFunc(x, y, dX, dY) and mapData:isObstacle(x, y) == 0 then
  218. result[index] = cc.p(x, y)
  219. local len = squLen(sX - x, sY - y)
  220. if len < cost and squLen(x - dX, y - dY) >= seqMR then
  221. bestIndex = index
  222. cost = len
  223. end
  224. index = index + 1
  225. end
  226. end
  227. end
  228. if bestIndex and result[bestIndex] then
  229. return result[bestIndex].x, result[bestIndex].y
  230. end
  231. return dX, dY
  232. end
  233. function PlayerInputProxy:findBestSkillPos(sX, sY, dX, dY, range, enableFunc, minrange)
  234. local mapData = global.sceneManager:GetMapData2DPtr()
  235. if not mapData then
  236. return dX, dY
  237. end
  238. minrange = minrange or 0
  239. if not range or 0 >= range then
  240. return dX, dY
  241. end
  242. local seqR = range*range
  243. local seqMR = minrange*minrange
  244. local len = squLen(sX - dX, sY - dY)
  245. if (len <= seqR) and (len >= seqMR) and enableFunc(sX, sY, dX, dY) then
  246. return sX, sY
  247. end
  248. local items = {}
  249. local index = 1
  250. local bestI = nil
  251. local cost = global.MMO.MAX_CONST
  252. local x = nil
  253. local y = nil
  254. local lenA = nil
  255. local function isLine(p1, p2)
  256. if p1.x == p2.x or p1.y == p2.y then
  257. return true
  258. end
  259. return false
  260. end
  261. --
  262. local function calcDistance(dst, src)
  263. local dis = self:calcMapDistance(dst, src)
  264. dis = dis + (isLine(dst, src) and 0 or 0.1)
  265. return dis
  266. end
  267. -- 2.check other
  268. local lenS = nil
  269. local lenD = nil
  270. for offY = -range, range do
  271. for offX = -range, range do
  272. x = dX + offX
  273. y = dY + offY
  274. if enableFunc(x, y, dX, dY) and (mapData:isObstacle(x, y) == 0 or (x == sX and y == sY)) then
  275. lenS = calcDistance(cc.p(sX, sY), cc.p(x, y))
  276. lenD = calcDistance(cc.p(dX, dY), cc.p(x, y))
  277. lenA = (lenS*1.1) + lenD
  278. if lenA < cost and squLen(x - dX, y - dY) >= seqMR then
  279. bestI = index
  280. cost = lenA
  281. end
  282. items[index] = cc.p(x, y)
  283. index = index + 1
  284. end
  285. end
  286. end
  287. if bestI and items[bestI] then
  288. return items[bestI].x, items[bestI].y
  289. end
  290. return dX, dY
  291. end
  292. local function attackEnable(sX, sY, dX, dY)
  293. if sX == dX and sY == dY then
  294. return false
  295. end
  296. if sX == dX or sY == dY then
  297. return true
  298. end
  299. local slope = (dX - sX) / (dY - sY)
  300. return 1 == math.abs(slope)
  301. end
  302. local function skillEnable(sX, sY, dX, dY)
  303. return true
  304. end
  305. local function moveEnable(sX, sY, dX, dY)
  306. return true
  307. end
  308. function PlayerInputProxy:FindBestAttackPos(sX, sY, dX, dY, range, minRange)
  309. return self:findBestSkillPos(sX, sY, dX, dY, range, attackEnable, minRange)
  310. end
  311. function PlayerInputProxy:FindBestSkillPos(sX, sY, dX, dY, range, minRange)
  312. return findBestPos(sX, sY, dX, dY, range, skillEnable, minRange)
  313. end
  314. function PlayerInputProxy:FindBestMovePos(sX, sY, dX, dY, range)
  315. return findBestPos(sX, sY, dX, dY, range, moveEnable)
  316. end
  317. function PlayerInputProxy:IsMovePermission()
  318. return self._movePermission
  319. end
  320. function PlayerInputProxy:SetMovePermission(permission)
  321. self._movePermission = permission
  322. end
  323. --------------------- target ------------------------------
  324. function PlayerInputProxy:SetTargetID(targetID)
  325. self._lastTargetID = self._targetID
  326. self._targetID = targetID
  327. self:SetTraceOwnerPlayerState( false )
  328. global.Facade:sendNotification(global.NoticeTable.TargetChange, {targetID = targetID})
  329. SLBridge:onLUAEvent(LUA_EVENT_TARGET_CAHNGE, targetID)
  330. global.Facade:sendNotification(global.NoticeTable.TargetChange_After, {targetID = targetID})
  331. -- 记录上次目标
  332. if (nil == self._targetID) then
  333. if self._targetScheduleID then
  334. UnSchedule(self._targetScheduleID)
  335. self._targetScheduleID = nil
  336. end
  337. self._targetScheduleID = PerformWithDelayGlobal(function()
  338. self._lastTargetID = nil
  339. self._targetScheduleID = nil
  340. end, 5)
  341. end
  342. -- clear auto lock
  343. if nil == self._targetID then
  344. local autoProxy = global.Facade:retrieveProxy(global.ProxyTable.Auto)
  345. autoProxy:ClearAutoLock()
  346. autoProxy:ClearDu()
  347. end
  348. local actor = global.actorManager:GetActor(targetID)
  349. if not targetID or not actor then
  350. ssr.ssrBridge:OnTargetChange(nil)
  351. return
  352. end
  353. if actor:IsPlayer() or actor:IsMonster() then
  354. local type = actor:IsPlayer() and 1 or 2
  355. ssr.ssrBridge:OnTargetChange(targetID, actor:GetName(), actor:GetHP(), actor:GetMaxHP(), actor:GetLevel(), type, actor:GetMasterID(), actor:GetTypeIndex(), actor:GetMapX(), actor:GetMapY())
  356. else
  357. ssr.ssrBridge:OnTargetChange(nil)
  358. end
  359. end
  360. function PlayerInputProxy:SetOwnerPlayerID( ID )
  361. if ID == "" or ID == -1 then
  362. ID = nil
  363. end
  364. self._ownerPlayerID = ID
  365. global.Facade:sendNotification( global.NoticeTable.Layer_Monster_Belong_TargetChange,{targetID=ID or self._targetID} )
  366. end
  367. function PlayerInputProxy:GetOwnerPlayerID()
  368. return self._ownerPlayerID
  369. end
  370. function PlayerInputProxy:IsTraceOwnerPlayer()
  371. return self._isTraceOwnerPlayer == true
  372. end
  373. function PlayerInputProxy:SetTraceOwnerPlayerState( state )
  374. self._isTraceOwnerPlayer = state
  375. if self._ownerPlayerID then --是否有归属
  376. local mainPlayer = global.gamePlayerController:GetMainPlayer()
  377. if not mainPlayer then
  378. return
  379. end
  380. local AutoProxy = global.Facade:retrieveProxy( global.ProxyTable.Auto )
  381. local AutoController = global.Facade:retrieveMediator( "AutoController" )
  382. AutoProxy:SetIsAutoLockState( true )
  383. AutoController:checkLaunchSimpleSkill( mainPlayer )
  384. end
  385. global.Facade:sendNotification( global.NoticeTable.Layer_Monster_Belong_Select )
  386. end
  387. function PlayerInputProxy:GetTargetID()
  388. if self._isTraceOwnerPlayer then
  389. return self._ownerPlayerID or self._targetID
  390. end
  391. return self._targetID
  392. end
  393. function PlayerInputProxy:ClearTarget()
  394. self:SetTargetID(nil)
  395. end
  396. function PlayerInputProxy:GetLastTargetID()
  397. return self._lastTargetID
  398. end
  399. function PlayerInputProxy:SetAttackTargetID(targetID)
  400. self._attackTargetID = targetID
  401. global.Facade:sendNotification(global.NoticeTable.AttackTargetChange, {targetID = targetID})
  402. end
  403. function PlayerInputProxy:GetAttackTargetID()
  404. return self._attackTargetID
  405. end
  406. function PlayerInputProxy:ClearAttackTargetID()
  407. self:SetAttackTargetID(nil)
  408. end
  409. function PlayerInputProxy:SetAttackState(state)
  410. self._attackState = state
  411. end
  412. function PlayerInputProxy:IsAttackState()
  413. return self._attackState
  414. end
  415. --------------------- target end ------------------------------
  416. --------------------- move ------------------------------
  417. function PlayerInputProxy:SetCurrMovePos(pos)
  418. self._moveDirty = true
  419. self._currMovePos = pos
  420. end
  421. function PlayerInputProxy:GetCurrMovePos()
  422. return self._currMovePos
  423. end
  424. function PlayerInputProxy:IsMoveDirty()
  425. return self._moveDirty
  426. end
  427. function PlayerInputProxy:IsMoving()
  428. return self:IsMoveDirty() or self:GetCurrPathPoint() > 0
  429. end
  430. function PlayerInputProxy:GetMoveInterruptFlag()
  431. if not self._currMovePos then
  432. return false
  433. end
  434. return self._currMovePos.isInterrupt
  435. end
  436. function PlayerInputProxy:SetMoveInterruptFlag(flag)
  437. if self._currMovePos then
  438. self._currMovePos.isInterrupt = flag
  439. end
  440. end
  441. function PlayerInputProxy:SetCurrMoveType(type)
  442. self._moveType = type
  443. end
  444. function PlayerInputProxy:GetCurrMoveType()
  445. return self._moveType
  446. end
  447. function PlayerInputProxy:SetPathFindPoints(points)
  448. self._pathFindPoints = points
  449. self._moveDirty = nil
  450. local size = self:GetPathPointSize()
  451. self:SetCurrPathPoint(size)
  452. if size > 1 then
  453. -- move begin
  454. global.Facade:sendNotification(global.NoticeTable.FindPathPointsBegin)
  455. else
  456. -- move end
  457. global.Facade:sendNotification(global.NoticeTable.FindPathPointsEnd)
  458. end
  459. end
  460. function PlayerInputProxy:GetPathFindPoints()
  461. return self._pathFindPoints or {}
  462. end
  463. function PlayerInputProxy:GetPathPointSize()
  464. if self._pathFindPoints then
  465. return #self._pathFindPoints
  466. end
  467. return 0
  468. end
  469. function PlayerInputProxy:SetCurrPathPoint(curr)
  470. self._currPathPoint = curr
  471. end
  472. function PlayerInputProxy:GetCurrPathPoint()
  473. return self._currPathPoint
  474. end
  475. function PlayerInputProxy:ClearMove()
  476. self:SetCurrMoveType(global.MMO.INPUT_MOVE_TYPE_OTHER)
  477. self:SetPathFindPoints(nil)
  478. self._currMovePos = nil
  479. self._moveDirty = nil
  480. end
  481. function PlayerInputProxy:SetIsMoveBlocked(v)
  482. self._isMoveBlocked = v
  483. end
  484. function PlayerInputProxy:IsMoveBlocked()
  485. return self._isMoveBlocked
  486. end
  487. function PlayerInputProxy:SetLaunchNoWalkPos( pos )
  488. local mapData = global.sceneManager:GetMapData2DPtr()
  489. if not mapData then
  490. return nil
  491. end
  492. if self._launchNoWalkPos then
  493. mapData:setObstacle(self._launchNoWalkPos.x, self._launchNoWalkPos.y, 0)
  494. self._launchNoWalkPos = nil
  495. end
  496. if pos and self._moveType == global.MMO.INPUT_MOVE_TYPE_LAUNCH then
  497. if mapData:isObstacle(pos.x, pos.y) == 0 then
  498. self._launchNoWalkPos = pos
  499. mapData:setObstacle(self._launchNoWalkPos.x, self._launchNoWalkPos.y, 1)
  500. end
  501. end
  502. end
  503. function PlayerInputProxy:GetLaunchNoWalkPos()
  504. return self._launchNoWalkPos
  505. end
  506. --------------------- move end------------------------------
  507. --------------------- trun --------------------------------
  508. function PlayerInputProxy:SetMouseTurnDir(dir)
  509. self._mouseTurnDir = dir
  510. end
  511. function PlayerInputProxy:GetMouseTurnDir()
  512. return self._mouseTurnDir
  513. end
  514. function PlayerInputProxy:ClearMouseTurnDir()
  515. self._mouseTurnDir = global.MMO.ORIENT_INVAILD
  516. end
  517. function PlayerInputProxy:RequestActorTurn(dir)
  518. local mainPlayer = global.gamePlayerController:GetMainPlayer()
  519. if mainPlayer and dir and dir >= global.MMO.ORIENT_U and dir <= global.MMO.ORIENT_LU then
  520. local x = mainPlayer:GetMapX()
  521. local y = mainPlayer:GetMapY()
  522. local point = y * 65536 + x
  523. LuaSendMsg( global.MsgType.MSG_CS_MAIN_PLAYER_TURN, point, 0, dir)
  524. local mainPlayerID = mainPlayer:GetID()
  525. global.BuffManager:UpdateBuffSfxDir(mainPlayerID)
  526. global.ActorEffectManager:UpdateEffectDir(mainPlayer, mainPlayerID)
  527. end
  528. end
  529. --------------------- trun --------------------------------
  530. --------------------- skill --------------------------------
  531. function PlayerInputProxy:IsLaunchDirty()
  532. return self._launchDirty
  533. end
  534. function PlayerInputProxy:ResetLaunchDirty()
  535. self._launchDirty = false
  536. end
  537. function PlayerInputProxy:GetLaunchPriority()
  538. return self._launchPriority
  539. end
  540. function PlayerInputProxy:ClearLaunch()
  541. self._launchDirty = false
  542. self._skillID = nil
  543. self._launchPos = nil
  544. self._launchTargetID = nil
  545. self._launchPriority = global.MMO.LAUNCH_PRIORITY_SYSTEM
  546. self._launchType = global.MMO.LAUNCH_TYPE_USER
  547. end
  548. function PlayerInputProxy:SetLaunchSkillID(skillID, priority, launchType)
  549. self._launchDirty = nil ~= skillID
  550. self._skillID = skillID
  551. self._launchPriority = priority or global.MMO.LAUNCH_PRIORITY_SYSTEM
  552. self._launchType = launchType or global.MMO.LAUNCH_TYPE_USER
  553. end
  554. function PlayerInputProxy:GetLaunchSkillID()
  555. return self._skillID
  556. end
  557. function PlayerInputProxy:SetLaunchTargetPos(pos)
  558. self._launchPos = pos
  559. end
  560. function PlayerInputProxy:GetLaunchTargetPos()
  561. return self._launchPos
  562. end
  563. function PlayerInputProxy:SetLaunchTargetID(id)
  564. self._launchTargetID = id
  565. end
  566. function PlayerInputProxy:GetLaunchTargetID()
  567. return self._launchTargetID
  568. end
  569. function PlayerInputProxy:GetLaunchType()
  570. return self._launchType
  571. end
  572. --------------------- skill end ------------------------------
  573. --------------------- collect ------------------------------
  574. function PlayerInputProxy:GetCollectCount()
  575. return self._collectCount
  576. end
  577. function PlayerInputProxy:AddCollectCount()
  578. self._collectCount = self._collectCount + 1
  579. end
  580. function PlayerInputProxy:SubCollectCount()
  581. self._collectCount = self._collectCount - 1
  582. end
  583. --------------------- collect ------------------------------
  584. --------------------- dig corpse --------------------
  585. function PlayerInputProxy:GetCorpseID()
  586. return self._coprseID
  587. end
  588. function PlayerInputProxy:SetCorpseID(id)
  589. self._coprseID = id
  590. end
  591. function PlayerInputProxy:ClearCorpse()
  592. self._coprseID = nil
  593. end
  594. function PlayerInputProxy:GetDigDest()
  595. return self._digDest
  596. end
  597. function PlayerInputProxy:SetDigDest(dest)
  598. self._digDest = dest
  599. end
  600. function PlayerInputProxy:ClearDigDest()
  601. self:SetDigDest(nil)
  602. end
  603. --------------------- mining --------------------
  604. function PlayerInputProxy:GetMiningDir()
  605. return self._miningDir
  606. end
  607. function PlayerInputProxy:SetMiningDir(dir)
  608. self._miningDir = dir
  609. end
  610. function PlayerInputProxy:GetMiningDest()
  611. return self._miningDest
  612. end
  613. function PlayerInputProxy:SetMiningDest(dest)
  614. self._miningDest = dest
  615. end
  616. function PlayerInputProxy:ClearMining()
  617. self._miningDir = nil
  618. self._miningDest = nil
  619. end
  620. function PlayerInputProxy:IsLaunchMining( dest )
  621. if not dest then
  622. return false
  623. end
  624. local actor = global.actorManager:GetNPCActorByMapXY(dest.x,dest.y)
  625. if actor and actor:IsNPC() then
  626. return false
  627. end
  628. return true
  629. end
  630. --------------------- mouse touch ------------------
  631. function PlayerInputProxy:SetMouseTouchPos(pos)
  632. self._mouseTouchPos = pos
  633. end
  634. function PlayerInputProxy:GetMouseTouchPos()
  635. return self._mouseTouchPos
  636. end
  637. function PlayerInputProxy:SetMouseTouchWay(way)
  638. self._mouseTouchWay = way
  639. end
  640. function PlayerInputProxy:GetMouseTouchWay()
  641. return self._mouseTouchWay
  642. end
  643. function PlayerInputProxy:ClearMouseTouch()
  644. self._mouseTouchPos = nil
  645. self._mouseTouchWay = nil
  646. end
  647. --------------------- 挖矿 --------------------
  648. function PlayerInputProxy:CheckMiningAble()
  649. local EquipProxy = global.Facade:retrieveProxy(global.ProxyTable.Equip)
  650. local equipTypeConfig = EquipProxy:GetEquipTypeConfig()
  651. local equip = EquipProxy:GetEquipDataByPos(equipTypeConfig.Equip_Type_Weapon)
  652. if equip and equip.Shape == 19 and equip.Dura ~= nil and equip.Dura > 0 then
  653. return true
  654. end
  655. return false
  656. end
  657. function PlayerInputProxy:ClearMining()
  658. self._miningPos = nil
  659. self._miningDir = nil
  660. end
  661. function PlayerInputProxy:SetMiningPos(pos)
  662. self._miningPos = pos
  663. end
  664. function PlayerInputProxy:GetMiningPos()
  665. return self._miningPos
  666. end
  667. function PlayerInputProxy:GetMiningDir()
  668. return self._miningDir
  669. end
  670. function PlayerInputProxy:SetMiningDir(dir)
  671. self._miningDir = dir
  672. end
  673. --------------------- 挖矿 --------------------
  674. --------------------- collect begin ------------------------------
  675. function PlayerInputProxy:RequestCollect()
  676. local targetID = self:GetTargetID()
  677. if targetID then
  678. LuaSendMsg(global.MsgType.MSG_CS_COLLECT_REQUEST, 0, 0, 0, 0, targetID, string.len(targetID))
  679. end
  680. end
  681. function PlayerInputProxy:CompletedCollect()
  682. local targetID = self:GetTargetID()
  683. if targetID then
  684. LuaSendMsg(global.MsgType.MSG_CS_COLLECT_COMPLETED, 0, 0, 0, 0, targetID, string.len(targetID))
  685. end
  686. end
  687. function PlayerInputProxy:RequestDigCorpse(dir, id)
  688. local jsonData = {}
  689. jsonData.Dir = dir
  690. jsonData.ID = id
  691. local jsonStr = cjson.encode(jsonData)
  692. LuaSendMsg(global.MsgType.MSG_CS_PICK_CORPSE, 0, 0, 0, 0, jsonStr, string.len(jsonStr))
  693. end
  694. function PlayerInputProxy:handle_MSG_SC_COLLECT_COMPLETED(msg)
  695. local header = msg:GetHeader()
  696. if header.pram1 == 1 then --开始采集状态
  697. global.Facade:sendNotification(global.NoticeTable.CollectBegin)
  698. elseif header.param2 == 2 then --结束采集状态
  699. global.Facade:sendNotification(global.NoticeTable.CollectCompleted)
  700. end
  701. end
  702. --------------------- collect end ------------------------------
  703. function PlayerInputProxy:GetMouseOverTargetID()
  704. return self._mouseOverTargetID
  705. end
  706. function PlayerInputProxy:SetMouseOverTargetID(targetID)
  707. self._mouseOverTargetID = targetID
  708. end
  709. function PlayerInputProxy:onRegister()
  710. PlayerInputProxy.super.onRegister(self)
  711. LuaRegisterMsgHandler(global.MsgType.MSG_SC_COLLECT_COMPLETED, handler(self, self.handle_MSG_SC_COLLECT_COMPLETED))
  712. end
  713. return PlayerInputProxy