gamePlayerController.lua 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702
  1. local gamePlayerController = class("gamePlayerController")
  2. local Queue = requireUtil( "queue" )
  3. gamePlayerController.NAME = "gamePlayerController"
  4. local actorUtils = requireProxy( "actorUtils" )
  5. local moveMsgType =
  6. {
  7. [global.MMO.ACTION_WALK] = global.MsgType.MSG_CS_MAIN_PLAYER_WALK,
  8. [global.MMO.ACTION_RUN] = global.MsgType.MSG_CS_MAIN_PLAYER_RUN,
  9. [global.MMO.ACTION_RIDE_RUN] = global.MsgType.MSG_CS_MAIN_PLAYER_RIDE_RUN,
  10. [global.MMO.ACTION_ASSASSIN_SNEAK] = global.MsgType.MSG_CS_MAIN_PLAYER_WALK,
  11. }
  12. local moveStep =
  13. {
  14. [global.MMO.ACTION_WALK] = 1,
  15. [global.MMO.ACTION_RUN] = 2,
  16. [global.MMO.ACTION_RIDE_RUN] = 3,
  17. [global.MMO.ACTION_ASSASSIN_SNEAK] = 1,
  18. }
  19. function gamePlayerController:ctor()
  20. self.mMainPlayerID = global.MMO.ACTOR_ID_INVALID
  21. self.mMainPlayerActor = nil
  22. self.mLuaTouchHandler = -1
  23. self.mLuaInputHandler = -1
  24. self.mHandleOnActCompleted = {}
  25. self.mHandleOnActBegin = {}
  26. self.mActQueue = Queue.new()
  27. self.mInputEnable = true
  28. self:Init()
  29. self:RegisterMsgHandler()
  30. end
  31. function gamePlayerController:destory()
  32. if gamePlayerController.instance then
  33. gamePlayerController.instance = nil
  34. end
  35. end
  36. function gamePlayerController:Inst()
  37. if not gamePlayerController.instance then
  38. gamePlayerController.instance = gamePlayerController.new()
  39. end
  40. return gamePlayerController.instance
  41. end
  42. function gamePlayerController:Init()
  43. end
  44. -----------------------------------------------------------------------------
  45. function gamePlayerController:RegisterMsgHandler()
  46. LuaRegisterMsgHandler( global.MsgType.MSG_SC_PLAYER_CHANGE_ID, handler( self, self.handle_MSG_SC_PLAYER_CHANGE_ID ) )
  47. LuaRegisterMsgHandler( global.MsgType.MSG_SC_NET_PLAYER_MOVE_FAIL, handler( self, self.handle_MSG_SC_NET_PLAYER_MOVE_FAIL ) )
  48. LuaRegisterMsgHandler( global.MsgType.MSG_SC_ACTION_CONFIREM_SUCCESS , handler( self, self.handle_MSG_SC_ACTION_CONFIRM ) )
  49. LuaRegisterMsgHandler( global.MsgType.MSG_SC_SKILL_ACTION_CONFIRM_SUCCESS , handler( self, self.handle_MSG_SC_SKILL_ACTION_CONFIRM ) )
  50. end
  51. -----------------------------------------------------------------------------
  52. function gamePlayerController:HandleTouchEndEvent(touchPos, touchWay, eventType)
  53. local ItemMoveProxy = global.Facade:retrieveProxy(global.ProxyTable.ItemMoveProxy)
  54. local state = ItemMoveProxy:GetMovingItemState()
  55. if state then
  56. return
  57. end
  58. self:NotifyLuaTouchEvent( touchPos, touchWay, eventType)
  59. end
  60. -----------------------------------------------------------------------------
  61. function gamePlayerController:handleActionBegin(actor, actBegin)
  62. if nil == self.mMainPlayerActor then
  63. return -1
  64. end
  65. if actBegin == global.MMO.ACTION_WALK or actBegin == global.MMO.ACTION_ASSASSIN_SNEAK or actBegin == global.MMO.ACTION_RUN or actBegin == global.MMO.ACTION_RIDE_RUN then
  66. -- Store last point for moving confirmation
  67. local MapProxy = global.Facade:retrieveProxy(global.ProxyTable.Map)
  68. local mapID = MapProxy:GetMapID()
  69. local msgType = moveMsgType[actBegin]
  70. -- 检测服务器开关
  71. if actBegin == global.MMO.ACTION_RUN and CHECK_SERVER_OPTION(global.MMO.SERVER_RUN_ONE) then
  72. msgType = global.MsgType.MSG_CS_WALKEX
  73. end
  74. local dir = self.mMainPlayerActor:GetDirection()
  75. local player = self.mMainPlayerActor
  76. local point = player:GetMapY() * 65536 + player:GetMapX()
  77. local lastPoint = player:GetLastMapY() * 65536 + player:GetLastMapX()
  78. LuaSendMsg( msgType, point, 0, dir, lastPoint, mapID, string.len(mapID) )
  79. end
  80. self:OnActionBegin(actor, actBegin)
  81. -- Action begin handle.
  82. for k,v in pairs(self.mHandleOnActBegin) do
  83. v(actor, actBegin)
  84. end
  85. end
  86. -----------------------------------------------------------------------------
  87. function gamePlayerController:OnActionBegin(actor, actBegin)
  88. if actBegin == global.MMO.ACTION_WALK or actBegin == global.MMO.ACTION_RUN or actBegin == global.MMO.ACTION_RIDE_RUN then
  89. global.Facade:sendNotification(global.NoticeTable.Audio_Play, {type=global.MMO.SND_TYPE_ACT_MOVE, index=actBegin, isRide=actor:GetHorseMasterID()})
  90. ssr.ssrBridge:OnActionBegin(actBegin)
  91. end
  92. if actBegin ~= global.MMO.ACTION_IDLE then
  93. global.Facade:sendNotification( global.NoticeTable.MainPlayerActionBegan, actBegin )
  94. end
  95. end
  96. -----------------------------------------------------------------------------
  97. function gamePlayerController:OnActionCompleted(actor, actCompleted)
  98. local nextAct = nil
  99. local actData = nil
  100. if not self.mActQueue:empty() then
  101. local act = self.mActQueue:pop()
  102. nextAct = act.act
  103. actData = act.data
  104. self.mInputEnable = false
  105. else
  106. self.mInputEnable = true
  107. end
  108. if nextAct then
  109. self:executeAction(nextAct, actData)
  110. end
  111. if actCompleted ~= global.MMO.ACTION_IDLE then
  112. global.Facade:sendNotification( global.NoticeTable.MainPlayerActionEnded, actCompleted )
  113. end
  114. end
  115. -----------------------------------------------------------------------------
  116. function gamePlayerController:handleActionCompleted(actor, actCompleted)
  117. self:OnActionCompleted( actor, actCompleted )
  118. -- Action completion handle.
  119. for k,v in pairs(self.mHandleOnActCompleted) do
  120. v(actor, actCompleted)
  121. end
  122. if actCompleted == 27 then
  123. print("真正释放特效.................")
  124. end
  125. self:ProcessLuaInput( actor, actCompleted )
  126. if actCompleted == global.MMO.ACTION_WALK or actCompleted == global.MMO.ACTION_RUN or actCompleted == global.MMO.ACTION_RIDE_RUN then
  127. local currAct = actor:GetAction()
  128. if currAct ~= global.MMO.ACTION_ASSASSIN_SNEAK and currAct ~= global.MMO.ACTION_WALK and currAct ~= global.MMO.ACTION_RUN and currAct ~= global.MMO.ACTION_RIDE_RUN then
  129. actor:setPosition( actor.mTargePos.x, actor.mTargePos.y )
  130. end
  131. if actor:IsMoveEff() and SL:GetMetaValue("GAME_DATA", "disable_footprint_effect") ~= 1 then
  132. local lastMapX = actor:GetLastMapX()
  133. local lastMapY = actor:GetLastMapY()
  134. local skipWalk = actor:GetMoveEffSkipWalk()
  135. local skipSwitch = actor:GetEffSkipWalkSwitch() or 0
  136. actor:SetMoveEffSkipWalk(not skipWalk and skipSwitch == 0)
  137. if lastMapX == 0xFFFF or lastMapY == 0xFFFF or (actCompleted == global.MMO.ACTION_WALK and skipWalk) then
  138. return
  139. end
  140. global.gameMapController:addEffectToMap(actor:GetMoveEff(), lastMapX, lastMapY)
  141. end
  142. elseif actCompleted == global.MMO.ACTION_ASSASSIN_SNEAK then
  143. local currAct = actor:GetAction()
  144. if currAct ~= global.MMO.ACTION_ASSASSIN_SNEAK and currAct ~= global.MMO.ACTION_WALK and currAct ~= global.MMO.ACTION_RUN and currAct ~= global.MMO.ACTION_RIDE_RUN then
  145. actor:setPosition( actor.mTargePos.x, actor.mTargePos.y )
  146. end
  147. end
  148. end
  149. -----------------------------------------------------------------------------
  150. function gamePlayerController:handleActionProcess(actor, act, dt)
  151. if act ~= global.MMO.ACTION_IDLE then
  152. global.Facade:sendNotification( global.NoticeTable.MainPlayerActionProcess, act )
  153. end
  154. end
  155. -----------------------------------------------------------------------------
  156. function gamePlayerController:BindMainActor(player)
  157. self.mMainPlayerActor = player
  158. --
  159. local mainPlayerID = player:GetID()
  160. print( "main player ID", mainPlayerID )
  161. self:SetMainPlayerID( mainPlayerID )
  162. global.playerManager:SetMainPlayerID( mainPlayerID )
  163. -- set is mainPlayer
  164. self.mMainPlayerActor:SetIsMainPlayer(true)
  165. -- To map grid position.
  166. local mapX = player:GetMapX()
  167. local mapY = player:GetMapY()
  168. local worldPos = global.sceneManager:MapPos2WorldPos( mapX, mapY, true )
  169. player:setPosition( worldPos.x, worldPos.y )
  170. -- Action listener
  171. self.mMainPlayerActor:SetGameActorActionHandler ( self )
  172. global.Facade:sendNotification( global.NoticeTable.BindMainPlayer, player )
  173. SLBridge:onLUAEvent(LUA_EVENT_BIND_MAINPLAYER)
  174. if global.Platform == cc.PLATFORM_OS_WINDOWS then
  175. print( "bind main player:"..player:GetID() )
  176. end
  177. end
  178. -----------------------------------------------------------------------------
  179. function gamePlayerController:Cleanup()
  180. self.mMainPlayerID = global.MMO.ACTOR_ID_INVALID
  181. self.mMainPlayerActor = nil
  182. self.mHandleOnActCompleted = {}
  183. self.mHandleOnActBegin = {}
  184. self.mLuaTouchHandler = -1
  185. self.mLuaInputHandler = -1
  186. self.mInputEnable = true
  187. end
  188. function gamePlayerController:CleanupMainPlayer()
  189. self.mMainPlayerID = global.MMO.ACTOR_ID_INVALID
  190. self.mMainPlayerActor = nil
  191. end
  192. -----------------------------------------------------------------------------
  193. function gamePlayerController:handle_MSG_SC_ACTION_CONFIRM(msg)
  194. if nil == self.mMainPlayerActor then
  195. return -1
  196. end
  197. self.mMainPlayerActor:SetConfirmed(true)
  198. -- self.mMainPlayerActor:SetDashWaiting(false)
  199. return 1
  200. end
  201. function gamePlayerController:handle_MSG_SC_SKILL_ACTION_CONFIRM( msg )
  202. if nil == self.mMainPlayerActor then
  203. return -1
  204. end
  205. local isConfirmed = true
  206. local msgLen = msg:GetDataLength()
  207. if msgLen > 0 then
  208. local msgHdr = msg:GetHeader()
  209. local dataString = msg:GetData():ReadString(msgLen)
  210. isConfirmed = dataString == self.mMainPlayerActor:GetID()
  211. end
  212. if isConfirmed then
  213. self.mMainPlayerActor:SetConfirmed(true)
  214. self.mMainPlayerActor:SetDashWaiting(false)
  215. end
  216. return 1
  217. end
  218. -----------------------------------------------------------------------------
  219. function gamePlayerController:OnChangeScene( mapX, mapY )
  220. if not self.mMainPlayerActor then
  221. return
  222. end
  223. if self.mMainPlayerActor:IsDie() or self.mMainPlayerActor:IsDeath() then
  224. return
  225. end
  226. -- Set player to new map position.
  227. local actorPos = global.sceneManager:MapPos2WorldPos( mapX, mapY, true )
  228. self.mMainPlayerActor:SetAction(global.MMO.ACTION_IDLE)
  229. self.mMainPlayerActor:setPosition(actorPos.x, actorPos.y)
  230. global.actorManager:SetActorMapXY( self.mMainPlayerActor, mapX, mapY )
  231. -- stop player
  232. self.mMainPlayerActor:SetIsArrived(true)
  233. self.mMainPlayerActor:SetConfirmed(true)
  234. self.mMainPlayerActor:SetDashWaiting(false)
  235. --
  236. global.Facade:sendNotification(global.NoticeTable.PlayerMapPosChange)
  237. SLBridge:onLUAEvent("LUA_EVENT_PLAYER_MAPPOS_CHANGE")
  238. return 1
  239. end
  240. -----------------------------------------------------------------------------
  241. function gamePlayerController:handle_Die( mainPlayerActor, msgHdr )
  242. -- Force stop player
  243. mainPlayerActor.mIsArrived = true
  244. mainPlayerActor:SetConfirmed(true)
  245. mainPlayerActor:SetDashWaiting(false)
  246. mainPlayerActor.mOrient = msgHdr.param3
  247. local targetPos = global.sceneManager:MapPos2WorldPos( mainPlayerActor.mCurrMapX,
  248. mainPlayerActor.mCurrMapY,
  249. true )
  250. mainPlayerActor:setPosition( targetPos.x, targetPos.y )
  251. mainPlayerActor:SetAction( global.MMO.ACTION_DIE )
  252. global.actorManager:SetActorMapXY( mainPlayerActor, msgHdr.param1,msgHdr.param2 )
  253. return 1
  254. end
  255. -----------------------------------------------------------------------------
  256. function gamePlayerController:handle_MSG_SC_NET_PLAYER_MOVE_FAIL(msg)
  257. local mainPlayer = self:GetMainPlayer()
  258. if nil == mainPlayer then
  259. return -1
  260. end
  261. if mainPlayer:IsDie() or mainPlayer:IsDeath() then
  262. return
  263. end
  264. local msgHdr = msg:GetHeader()
  265. -- 通知抛弃
  266. print(string.format( "!!!!!!!!!!!!!!!!!!!! move fail11111:%d. [%d, %d] ---> [%d, %d]", msgHdr.recog, mainPlayer:GetMapX(), mainPlayer:GetMapY(), msgHdr.param1, msgHdr.param2 ))
  267. if msgHdr.recog >= 40 then
  268. return -1
  269. end
  270. print(string.format( "!!!!!!!!!!!!!!!!!!!! move fail:%d. [%d, %d] ---> [%d, %d]", msgHdr.recog, mainPlayer:GetMapX(), mainPlayer:GetMapY(), msgHdr.param1, msgHdr.param2 ))
  271. if mainPlayer:IsOnPush() and mainPlayer:GetMapX() == msgHdr.param1 and mainPlayer:GetMapY() == msgHdr.param2 then
  272. return -1
  273. end
  274. local posOfAccepted = global.sceneManager:MapPos2WorldPos(msgHdr.param1, msgHdr.param2, true)
  275. mainPlayer:SetDirection(msgHdr.param3)
  276. mainPlayer:setPosition(posOfAccepted.x, posOfAccepted.y)
  277. mainPlayer:SetIsArrived(true)
  278. mainPlayer:SetConfirmed(true)
  279. global.actorManager:SetActorMapXY( mainPlayer, msgHdr.param1,msgHdr.param2 )
  280. -- 28号消息,recog=1的时候,可以立刻走,其他等待一下
  281. if msgHdr.recog == 1 then
  282. -- 拉回时等状态时间结束
  283. local currentActT = mainPlayer.mCurrentActT
  284. mainPlayer:SetAction(global.MMO.ACTION_IDLE_LOCK)
  285. mainPlayer.mCurrentActT = currentActT
  286. else
  287. -- 拉回时等状态时间结束
  288. local currentActT = mainPlayer.mCurrentActT
  289. mainPlayer:SetAction(global.MMO.ACTION_IDLE_LOCK)
  290. mainPlayer.mCurrentActT = currentActT
  291. end
  292. return 1
  293. end
  294. -----------------------------------------------------------------------------
  295. function gamePlayerController:handle_MSG_SC_PLAYER_CHANGE_ID(msg)
  296. local jsonData = ParseRawMsgToJson( msg )
  297. if not jsonData then
  298. return -1
  299. end
  300. local actorID = jsonData.UserID
  301. if self.mMainPlayerID == actorID then
  302. return 1
  303. end
  304. global.actorManager:RefreshActorID( self.mMainPlayerID, actorID )
  305. global.playerManager:SetMainPlayerID( actorID )
  306. self.mMainPlayerID = actorID
  307. return 1
  308. end
  309. -----------------------------------------------------------------------------
  310. function gamePlayerController:handle_MSG_SC_ACTOR_STUCK()
  311. if nil == self.mMainPlayerActor then
  312. return -1
  313. end
  314. local player = self.mMainPlayerActor
  315. -- 死亡状态无法切换
  316. if player:IsDie() or player:IsDeath() then
  317. return
  318. end
  319. if global.MMO.ACTION_IDLE == player:GetAction() then
  320. player:SetAction(global.MMO.ACTION_STUCK)
  321. else
  322. self:pushAction(global.MMO.ACTION_STUCK)
  323. end
  324. return 1
  325. end
  326. -----------------------------------------------------------------------------
  327. function gamePlayerController:handle_MSG_SC_NET_PLAYER_ATTACK(actor, msgHdr, jsonData)
  328. -- 死亡状态无法切换
  329. if actor:IsDie() or actor:IsDeath() then
  330. return nil
  331. end
  332. -- local SkillProxy = global.Facade:retrieveProxy(global.ProxyTable.Skill)
  333. -- SkillProxy:actorEnterAction(jsonData, msgHdr, false)
  334. -- SkillProxy:requestSkillPresent(jsonData, 1)
  335. -- SkillProxy:requestSkillPresent(jsonData, 2)
  336. end
  337. -----------------------------------------------------------------------------
  338. -----------------------------------------------------------------------------
  339. function gamePlayerController:handle_MSG_SC_PLAYER_SKILL_LAUNCH_SUCCESS(actor, msgHdr, jsonData)
  340. -- 死亡状态无法切换
  341. if actor:IsDie() or actor:IsDeath() then
  342. return
  343. end
  344. local SkillProxy = global.Facade:retrieveProxy(global.ProxyTable.Skill)
  345. SkillProxy:actorEnterAction(jsonData, true)
  346. end
  347. -----------------------------------------------------------------------------
  348. -----------------------------------------------------------------------------
  349. function gamePlayerController:handle_MSG_SC_PLAYER_SKILL_MAGIC_SUCCESS(actor, msgHdr, jsonData)
  350. -- 死亡状态无法切换
  351. if actor:IsDie() or actor:IsDeath() then
  352. return nil
  353. end
  354. local SkillProxy = global.Facade:retrieveProxy(global.ProxyTable.Skill)
  355. SkillProxy:requestSkillPresent(jsonData, 2)
  356. end
  357. -----------------------------------------------------------------------------
  358. -----------------------------------------------------------------------------
  359. function gamePlayerController:handle_MSG_SC_PLAYER_SKILL_27_SUCCESS(actor, msgHdr)
  360. -- 野蛮
  361. if actor:IsDie() or actor:IsDeath() then
  362. return nil
  363. end
  364. local mapX = msgHdr.param1
  365. local mapY = msgHdr.param2
  366. local dir = H16Bit(msgHdr.param3) == 0 and L16Bit(msgHdr.param3) or L16Bit(msgHdr.param3)
  367. local time = msgHdr.recog * 0.001
  368. local skillId = H16Bit(msgHdr.param3) > 0 and H16Bit(msgHdr.param3) or 0
  369. -- 坐标不对
  370. if (mapX == actor:GetMapX() and mapY == actor:GetMapY()) or time == 0 then
  371. --执行野蛮失败撞墙动作
  372. actor:SetAction(global.MMO.ACTION_DASH_FAIL)
  373. return
  374. end
  375. -- 野蛮时间需要加上动作补间
  376. local addTime = global.GameActorSkillController:GetMainPlayerAddDashTime()
  377. time = time + addTime
  378. global.GameActorSkillController:SetMainPlayerAddDashTime(0)
  379. local sMapX = 0
  380. local sMapY = 0
  381. if H16Bit(msgHdr.param1) > 0 and H16Bit(msgHdr.param2) > 0 then
  382. mapX = L16Bit(msgHdr.param1)
  383. mapY = H16Bit(msgHdr.param1)
  384. sMapX = L16Bit(msgHdr.param2)
  385. sMapY = H16Bit(msgHdr.param2)
  386. end
  387. -- 防止野蛮后后退
  388. global.Facade:sendNotification(global.NoticeTable.ClearAllInputState)
  389. global.Facade:sendNotification(global.NoticeTable.InputIdle)
  390. if skillId == 0 then
  391. actorUtils.actorDash(actor, mapX, mapY, sMapX, sMapY, dir, time)
  392. else
  393. actorUtils.actorZhuiXinCi(actor, mapX, mapY, dir, time)
  394. end
  395. end
  396. -----------------------------------------------------------------------------
  397. -----------------------------------------------------------------------------
  398. function gamePlayerController:handle_MSG_SC_PLAYER_SKILL_27_BACKSTEP(actor, msgHdr)
  399. -- 被野蛮,被推开
  400. if actor:IsDie() or actor:IsDeath() then
  401. return nil
  402. end
  403. local mapX = msgHdr.param1
  404. local mapY = msgHdr.param2
  405. local dir = msgHdr.param3
  406. local time = msgHdr.recog
  407. -- 坐标不对
  408. if time <= 0 then
  409. return nil
  410. end
  411. -- 防止野蛮后后退
  412. global.Facade:sendNotification(global.NoticeTable.ClearAllInputState)
  413. global.Facade:sendNotification(global.NoticeTable.InputIdle)
  414. local sMapX = 0
  415. local sMapY = 0
  416. if H16Bit(msgHdr.param1) > 0 and H16Bit(msgHdr.param2) > 0 then
  417. mapX = L16Bit(msgHdr.param1)
  418. mapY = H16Bit(msgHdr.param1)
  419. sMapX = L16Bit(msgHdr.param2)
  420. sMapY = H16Bit(msgHdr.param2)
  421. end
  422. local moveTime = L16Bit(time) * 0.001
  423. local idleTime = math.min(H16Bit(time) * 0.001, 5)
  424. actorUtils.actorOnDash(actor, mapX, mapY, sMapX, sMapY, dir, moveTime, idleTime)
  425. end
  426. -----------------------------------------------------------------------------
  427. -----------------------------------------------------------------------------
  428. function gamePlayerController:handle_MSG_SC_PLAYER_SKILL_82_SUCCESS(actor, msgHdr)
  429. -- 十步一杀 瞬移
  430. if actor:IsDie() or actor:IsDeath() then
  431. return nil
  432. end
  433. local mapX = msgHdr.param1
  434. local mapY = msgHdr.param2
  435. local dir = msgHdr.param3
  436. -- 坐标不对
  437. if (mapX == actor:GetMapX() and mapY == actor:GetMapY()) then
  438. return
  439. end
  440. -- 清理所有输入状态
  441. global.Facade:sendNotification(global.NoticeTable.ClearAllInputState)
  442. global.Facade:sendNotification(global.NoticeTable.InputIdle)
  443. -- 关闭技能
  444. local SkillProxy = global.Facade:retrieveProxy( global.ProxyTable.Skill )
  445. if SkillProxy:GetSelectSkill() == global.MMO.SKILL_INDEX_SBYS then
  446. SkillProxy:ClearSelectSkill()
  447. end
  448. -- 进入十步一杀技能表现
  449. actorUtils.actorSBYS(actor, mapX, mapY, dir)
  450. end
  451. -----------------------------------------------------------------------------
  452. -----------------------------------------------------------------------------
  453. function gamePlayerController:handle_MSG_SC_PLAYER_SKILL_71_SUCCESS(actor, msgHdr)
  454. -- 擒龙手 瞬移
  455. if actor:IsDie() or actor:IsDeath() then
  456. return nil
  457. end
  458. local mapX = msgHdr.param1
  459. local mapY = msgHdr.param2
  460. local dir = msgHdr.param3
  461. -- 坐标不对
  462. if (mapX == actor:GetMapX() and mapY == actor:GetMapY()) then
  463. return
  464. end
  465. actorUtils.actorQLS(actor, mapX, mapY, dir)
  466. end
  467. -----------------------------------------------------------------------------
  468. -----------------------------------------------------------------------------
  469. function gamePlayerController:NotifyLuaTouchEvent(touch, touchWay, eventType)
  470. if -1 ~= self.mLuaTouchHandler then
  471. self.mLuaTouchHandler(touch, touchWay, eventType)
  472. end
  473. end
  474. -----------------------------------------------------------------------------
  475. function gamePlayerController:ProcessLuaInput(actor, actCompleted)
  476. if -1 ~= self.mLuaInputHandler and actCompleted ~= global.MMO.ACTION_DIE and self.mInputEnable then
  477. self.mLuaInputHandler(actor, actCompleted)
  478. end
  479. end
  480. -----------------------------------------------------------------------------
  481. function gamePlayerController:clearActQueue()
  482. self.mActQueue:clear()
  483. end
  484. function gamePlayerController:pushAction(act, data)
  485. if nil == self.mMainPlayerActor then
  486. return -1
  487. end
  488. if nil == act then
  489. return -2
  490. end
  491. if false == (act >= global.MMO.ACTION_IDLE and act <= global.MMO.ACTION_MAX) then
  492. return -3
  493. end
  494. if global.MMO.ACTION_IDLE == self.mMainPlayerActor:GetAction() then
  495. self:executeAction(act, data)
  496. else
  497. self.mActQueue:push({act = act, data = data})
  498. end
  499. return 1
  500. end
  501. function gamePlayerController:executeAction(act, data)
  502. if nil == self.mMainPlayerActor then
  503. return -1
  504. end
  505. self.mMainPlayerActor:SetAction(act)
  506. if data then
  507. -- on callback
  508. if data.callback then
  509. data.callback()
  510. end
  511. end
  512. end
  513. function gamePlayerController:GetMainPlayer()
  514. return self.mMainPlayerActor
  515. end
  516. function gamePlayerController:SetMainPlayerID( id )
  517. self.mMainPlayerID = id
  518. end
  519. function gamePlayerController:GetMainPlayerID()
  520. return self.mMainPlayerID
  521. end
  522. function gamePlayerController:AddHandleOnActCompleted(func)
  523. table.insert(self.mHandleOnActCompleted, func)
  524. end
  525. function gamePlayerController:AddHandleOnActBegin(func)
  526. table.insert(self.mHandleOnActBegin, func)
  527. end
  528. function gamePlayerController:RegisterLuaTouchHandler(appHandler)
  529. self.mLuaTouchHandler = appHandler
  530. end
  531. function gamePlayerController:RegisterLuaInputHandler(inputHandler)
  532. self.mLuaInputHandler = inputHandler
  533. end
  534. function gamePlayerController:SetBindHorseActor( actor )
  535. self.mHorseActor = actor
  536. end
  537. function gamePlayerController:GetBindHorseActor()
  538. if not self.mHorseActor or tolua.isnull(self.mHorseActor:GetNode()) then
  539. self.mHorseActor = nil
  540. end
  541. return self.mHorseActor
  542. end
  543. function gamePlayerController:handle_Revive(actor, jsonData)
  544. -- feature
  545. if jsonData.Hp and jsonData.MaxHp then
  546. actor:SetHPHUD(jsonData.Hp, jsonData.MaxHp)
  547. end
  548. -- To map grid position
  549. local worldPos = global.sceneManager:MapPos2WorldPos(jsonData.X, jsonData.Y, true)
  550. actor:SetConfirmed(true)
  551. actor:SetIsArrived(true)
  552. actor:stopAnimToFrame(nil)
  553. actor:setPosition(worldPos.x, worldPos.y)
  554. actor:SetDirection(jsonData.Dir)
  555. actor:SetAction(global.MMO.ACTION_IDLE, true)
  556. actor:dirtyAnimFlag()
  557. global.actorManager:SetActorMapXY(actor, jsonData.X, jsonData.Y)
  558. -- 刷新主玩家安全区
  559. local MapProxy = global.Facade:retrieveProxy(global.ProxyTable.Map)
  560. MapProxy:UpdateInSafeAreaState()
  561. local PlayerPropertyProxy = global.Facade:retrieveProxy(global.ProxyTable.PlayerProperty)
  562. PlayerPropertyProxy:setAlive(true)
  563. global.Facade:sendNotification(global.NoticeTable.Audio_Stop_BGM)
  564. local noticeData = {}
  565. noticeData.actor = actor
  566. noticeData.actorID = jsonData.UserID
  567. global.Facade:sendNotification(global.NoticeTable.ActorRevive, noticeData)
  568. global.Facade:sendNotification(global.NoticeTable.SceneFollowMainPlayer)
  569. end
  570. function gamePlayerController:handle_Move_Force( actor,jsonData )
  571. self:clearActQueue()
  572. if actor:IsDie() or actor:IsDeath() then
  573. return
  574. end
  575. local posOfAccepted = global.sceneManager:MapPos2WorldPos(jsonData.mapX, jsonData.mapY, true)
  576. actor:SetAction(global.MMO.ACTION_IDLE, true)
  577. actor.mIsArrived = true
  578. actor.mIsConfirmed = true
  579. actor:SetDirection(jsonData.dir)
  580. actor:setPosition(posOfAccepted.x, posOfAccepted.y)
  581. global.actorManager:SetActorMapXY( actor, jsonData.mapX, jsonData.mapY )
  582. global.Facade:sendNotification(global.NoticeTable.SceneFollowMainPlayer)
  583. end
  584. return gamePlayerController