netActorController.lua 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817
  1. local netActorController = class("netActorController")
  2. netActorController.NAME = "netActorController"
  3. local actorUtils = requireProxy( "actorUtils" )
  4. -- 状态队列
  5. local ACTION_CACHE =
  6. {
  7. WALK = 1, -- 走
  8. RUN = 2, -- 跑
  9. RIDE_RUN = 3, -- 坐骑 跑
  10. STUCK = 4, -- 受击
  11. SKILL_ACTION = 5, -- 魔法 纯动作
  12. SKILL_MAGIC = 6, -- 魔法 纯魔法 -- 无用
  13. SKILL_ACTION_MAGIC = 7, -- 魔法 动作 + 魔法
  14. DASH = 8, -- 野蛮
  15. ONDASH = 9, -- 被野蛮,被推开
  16. SBYS = 10, -- 十步一杀
  17. QLS = 11, -- 擒龙手
  18. SNEAK = 12, -- 潜行
  19. ZXC = 27, -- 追心刺
  20. }
  21. function netActorController:ctor()
  22. self.mHandleOnActCompleted = {}
  23. self.mHandleOnActBegin = {}
  24. self.mNextActionCache = {}
  25. end
  26. function netActorController:destory()
  27. end
  28. function netActorController:Init()
  29. end
  30. function netActorController:Cleanup(cleanHandler)
  31. if cleanHandler == nil then
  32. cleanHandler = true
  33. end
  34. if cleanHandler then
  35. self.mHandleOnActCompleted = {}
  36. self.mHandleOnActBegin = {}
  37. end
  38. self.mNextActionCache = {}
  39. end
  40. -----------------------------------------------------------------------------
  41. function netActorController:AddHandleOnActCompleted(func)
  42. table.insert(self.mHandleOnActCompleted, func)
  43. end
  44. function netActorController:AddHandleOnActBegin(func)
  45. table.insert(self.mHandleOnActBegin, func)
  46. end
  47. -----------------------------------------------------------------------------
  48. function netActorController:handleActionBegin(actor, act)
  49. -- Action begin handle.
  50. for k, v in pairs(self.mHandleOnActBegin) do
  51. v(actor, act)
  52. end
  53. end
  54. function netActorController:handleActionCompleted(actor, act)
  55. -- Action completion handle.
  56. for k, v in pairs(self.mHandleOnActCompleted) do
  57. v(actor, act)
  58. end
  59. --重置加速
  60. if actor:GetIsSpeedup() then
  61. actor:SetIsSpeedup(false)
  62. actor:dirtyAnimFlag()
  63. end
  64. if actor:GetIsFullSpeedup() then
  65. actor:SetIsFullSpeedup(false)
  66. actor:dirtyAnimFlag()
  67. end
  68. if actor:GetIsMoreFullSpeedup() then
  69. actor:SetIsMoreFullSpeedup(false)
  70. actor:dirtyAnimFlag()
  71. end
  72. if actor:GetIsMoreSpeedRate() then
  73. actor:SetIsMoreSpeedRate(false)
  74. actor:dirtyAnimFlag()
  75. end
  76. --确认
  77. actor:SetConfirmed(true)
  78. local isIdleAction = false
  79. local nextActionCache = self.mNextActionCache[actor:GetID()]
  80. if nextActionCache and nextActionCache[1] then
  81. local nextAction = table.remove(nextActionCache, 1)
  82. if nextActionCache[1] ~= nil and nextActionCache[1].act ~= ACTION_CACHE.STUCK then
  83. actor:SetIsSpeedup(true)
  84. actor:SetIsMoreSpeedRate(CHECK_SETTING(global.MMO.SETTING_IDX_MORE_FAST) == 1)
  85. -- 堆积的太多,更快的加速
  86. if nextActionCache[2] ~= nil and nextActionCache[3] ~= nil then
  87. actor:SetIsFullSpeedup(true)
  88. actor:SetIsMoreFullSpeedup(CHECK_SETTING(global.MMO.SETTING_IDX_MORE_FAST) == 1)
  89. end
  90. end
  91. if nextAction.act == ACTION_CACHE.STUCK then
  92. actor:SetAction(global.MMO.ACTION_STUCK)
  93. elseif nextAction.act == ACTION_CACHE.WALK then
  94. actor:SetMoveTo(nextAction.pos)
  95. actor:SetAction(global.MMO.ACTION_WALK)
  96. actor:SetConfirmed(true)
  97. elseif nextAction.act == ACTION_CACHE.SNEAK then
  98. actor:SetMoveTo(nextAction.pos)
  99. actor:SetAction(global.MMO.ACTION_ASSASSIN_SNEAK)
  100. actor:SetConfirmed(true)
  101. elseif nextAction.act == ACTION_CACHE.RUN then
  102. actor:SetMoveTo(nextAction.pos)
  103. actor:SetAction(global.MMO.ACTION_RUN)
  104. actor:SetConfirmed(true)
  105. elseif nextAction.act == ACTION_CACHE.RIDE_RUN then
  106. actor:SetMoveTo(nextAction.pos)
  107. actor:SetAction(global.MMO.ACTION_RIDE_RUN)
  108. actor:SetConfirmed(true)
  109. elseif nextAction.act == ACTION_CACHE.SKILL_ACTION then
  110. local SkillProxy = global.Facade:retrieveProxy(global.ProxyTable.Skill)
  111. SkillProxy:actorEnterAction(nextAction.jsonData, nextAction.isMagic)
  112. local SkillProxy = global.Facade:retrieveProxy(global.ProxyTable.Skill)
  113. SkillProxy:requestSkillPresent(nextAction.jsonData, 1)
  114. if nextAction.skillStage == 2 then
  115. local SkillProxy = global.Facade:retrieveProxy(global.ProxyTable.Skill)
  116. SkillProxy:requestSkillPresent(nextAction.jsonData, 2)
  117. end
  118. actor.skillStage = nextAction.skillStage
  119. actor.skillID = nextAction.jsonData.MagicID
  120. elseif nextAction.act == ACTION_CACHE.SKILL_ACTION_MAGIC then
  121. local SkillProxy = global.Facade:retrieveProxy(global.ProxyTable.Skill)
  122. SkillProxy:actorEnterAction(nextAction.jsonData, nextAction.isMagic)
  123. SkillProxy:requestSkillPresent(nextAction.jsonData, 3)
  124. elseif nextAction.act == ACTION_CACHE.DASH then
  125. local msgHdr = nextAction.msgHdr
  126. local mapX = msgHdr.param1
  127. local mapY = msgHdr.param2
  128. local dir = msgHdr.param3
  129. local time = msgHdr.recog * 0.001
  130. local sMapX = 0
  131. local sMapY = 0
  132. if H16Bit(msgHdr.param1) > 0 and H16Bit(msgHdr.param2) > 0 then
  133. mapX = L16Bit(msgHdr.param1)
  134. mapY = H16Bit(msgHdr.param1)
  135. sMapX = L16Bit(msgHdr.param2)
  136. sMapY = H16Bit(msgHdr.param2)
  137. end
  138. if ((mapX ~= actor:GetMapX() or mapY ~= actor:GetMapY())) and time > 0 then
  139. actorUtils.actorDash(actor, mapX, mapY, sMapX, sMapY, dir, time)
  140. else
  141. isIdleAction = true
  142. end
  143. elseif nextAction.act == ACTION_CACHE.ONDASH then
  144. local msgHdr = nextAction.msgHdr
  145. local mapX = msgHdr.param1
  146. local mapY = msgHdr.param2
  147. local dir = msgHdr.param3
  148. local time = msgHdr.recog
  149. local moveTime = L16Bit(time) * 0.001
  150. local idleTime = math.min(H16Bit(time) * 0.001, 5)
  151. local sMapX = 0
  152. local sMapY = 0
  153. if H16Bit(msgHdr.param1) > 0 and H16Bit(msgHdr.param2) > 0 then
  154. mapX = L16Bit(msgHdr.param1)
  155. mapY = H16Bit(msgHdr.param1)
  156. sMapX = L16Bit(msgHdr.param2)
  157. sMapY = H16Bit(msgHdr.param2)
  158. end
  159. if ((mapX ~= actor:GetMapX() or mapY ~= actor:GetMapY())) and moveTime > 0 then
  160. actorUtils.actorOnDash(actor, mapX, mapY, sMapX, sMapY, dir, moveTime, idleTime)
  161. else
  162. isIdleAction = true
  163. end
  164. elseif nextAction.act == ACTION_CACHE.SBYS then
  165. local msgHdr = nextAction.msgHdr
  166. local mapX = msgHdr.param1
  167. local mapY = msgHdr.param2
  168. local dir = msgHdr.param3
  169. if (mapX ~= actor:GetMapX() or mapY ~= actor:GetMapY()) then
  170. actorUtils.actorSBYS(actor, mapX, mapY, dir)
  171. else
  172. isIdleAction = true
  173. end
  174. elseif nextAction.act == ACTION_CACHE.QLS then
  175. local msgHdr = nextAction.msgHdr
  176. local mapX = msgHdr.param1
  177. local mapY = msgHdr.param2
  178. local dir = msgHdr.param3
  179. if (mapX ~= actor:GetMapX() or mapY ~= actor:GetMapY()) then
  180. actorUtils.actorQLS(actor, mapX, mapY, dir)
  181. else
  182. isIdleAction = true
  183. end
  184. elseif nextAction.act == ACTION_CACHE.ZXC then
  185. local msgHdr = nextAction.msgHdr
  186. local mapX = msgHdr.param1
  187. local mapY = msgHdr.param2
  188. local dir = H16Bit(msgHdr.param3) == 0 and L16Bit(msgHdr.param3) or L16Bit(msgHdr.param3)
  189. local time = msgHdr.recog * 0.001
  190. if ((mapX ~= actor:GetMapX() or mapY ~= actor:GetMapY())) and time > 0 then
  191. actorUtils.actorZhuiXinCi(actor, mapX, mapY, dir, time)
  192. else
  193. isIdleAction = true
  194. end
  195. else
  196. isIdleAction = true
  197. end
  198. elseif act == global.MMO.ACTION_DIE or act == global.MMO.ACTION_DEATH then
  199. elseif act == global.MMO.ACTION_CAVE then
  200. else
  201. isIdleAction = true
  202. end
  203. if isIdleAction then
  204. --移动优化
  205. if act == global.MMO.ACTION_WALK or act == global.MMO.ACTION_RUN or act == global.MMO.ACTION_RIDE_RUN or act == global.MMO.ACTION_ASSASSIN_SNEAK then
  206. actor:setPosition(actor.mTargePos.x, actor.mTargePos.y)
  207. end
  208. actor:SetAction(global.MMO.ACTION_IDLE)
  209. end
  210. end
  211. function netActorController:handleActionProcess(actor)
  212. end
  213. -----------------------------------------------------------------------------
  214. function netActorController:handleActorOutOfView(actor)
  215. self.mNextActionCache[actor:GetID()] = nil
  216. end
  217. function netActorController:handle_Die(actor, msgHdr, msgData)
  218. self:SyncLatestPosition(actor, false)
  219. self.mNextActionCache[actor:GetID()] = nil
  220. -- 死亡时不拉坐标了,会闪现
  221. global.actorManager:SetActorMapXY(actor, msgHdr.param1, msgHdr.param2)
  222. actor:stopAnimToFrame(nil)
  223. actor:SetAction(global.MMO.ACTION_DIE, true)
  224. end
  225. function netActorController:handle_DeathSkeleton(actor, msgHdr, msgData)
  226. self:SyncLatestPosition(actor, false)
  227. self.mNextActionCache[actor:GetID()] = nil
  228. -- 死亡时不拉坐标了,会闪现
  229. global.actorManager:SetActorMapXY(actor, msgHdr.param1, msgHdr.param2)
  230. actor:stopAnimToFrame(nil)
  231. actor:SetAction(global.MMO.ACTION_DEATH, true)
  232. end
  233. function netActorController:handle_Revive(actor, jsonData)
  234. self.mNextActionCache[actor:GetID()] = nil
  235. -- feature
  236. if jsonData.Hp and jsonData.MaxHp then
  237. actor:SetHPHUD(jsonData.Hp, jsonData.MaxHp)
  238. end
  239. -- To map grid position
  240. local actorPos = global.sceneManager:MapPos2WorldPos(jsonData.X, jsonData.Y, true)
  241. local action = actor:IsMonster() and global.MMO.ACTION_BORN or global.MMO.ACTION_IDLE
  242. actor:SetConfirmed(true)
  243. actor:SetIsArrived(true)
  244. actor:stopAnimToFrame(nil)
  245. actor:setPosition(actorPos.x, actorPos.y)
  246. actor:SetDirection(jsonData.Dir)
  247. actor:SetAction(action, true)
  248. actor:dirtyAnimFlag()
  249. global.actorManager:SetActorMapXY(actor, jsonData.X, jsonData.Y)
  250. local noticeData = {}
  251. noticeData.actor = actor
  252. noticeData.actorID = jsonData.UserID
  253. global.Facade:sendNotification(global.NoticeTable.ActorRevive, noticeData)
  254. end
  255. function netActorController:handleActorSitdown(actor, jsonData)
  256. -- 死亡状态无法切换
  257. if actor:IsDie() or actor:IsDeath() then
  258. return nil
  259. end
  260. if global.MMO.ACTION_IDLE == actor:GetAction() then
  261. actor:SetDirection(jsonData.Dir)
  262. actor:SetAction(global.MMO.ACTION_SITDOWN)
  263. else
  264. -- Another action is running
  265. local netAct = {}
  266. netAct.act = ACTION_CACHE.SITDOWN
  267. netAct.Dir = jsonData.Dir
  268. if self.mNextActionCache[actor:GetID()] == nil then
  269. self.mNextActionCache[actor:GetID()] = {}
  270. end
  271. table.insert(self.mNextActionCache[actor:GetID()], netAct)
  272. end
  273. self:CheckFastCurrentAction(actor)
  274. end
  275. function netActorController:handleActorMining(actor, jsonData)
  276. -- 死亡状态无法切换
  277. if actor:IsDie() or actor:IsDeath() then
  278. return nil
  279. end
  280. if global.MMO.ACTION_IDLE == actor:GetAction() then
  281. actor:SetDirection(jsonData.Dir)
  282. actor:SetAction(global.MMO.ACTION_MINING)
  283. else
  284. -- Another action is running
  285. local netAct = {}
  286. netAct.act = ACTION_CACHE.MINING
  287. netAct.Dir = jsonData.Dir
  288. if self.mNextActionCache[actor:GetID()] == nil then
  289. self.mNextActionCache[actor:GetID()] = {}
  290. end
  291. table.insert(self.mNextActionCache[actor:GetID()], netAct)
  292. end
  293. self:CheckFastCurrentAction(actor)
  294. end
  295. function netActorController:handle_MSG_SC_ACTOR_WALK(actor, msgHdr)
  296. -- 死亡状态无法切换
  297. if actor:IsDie() or actor:IsDeath() then
  298. return nil
  299. end
  300. local p = { x = msgHdr.param1, y = msgHdr.param2 }
  301. if global.MMO.ACTION_IDLE == actor:GetAction() then
  302. local act = global.MMO.ACTION_WALK
  303. if actor:GetValueByKey(global.MMO.ACT_SNEAK) then
  304. act = global.MMO.ACTION_ASSASSIN_SNEAK
  305. end
  306. actor:SetMoveTo(p)
  307. actor:SetAction(act)
  308. actor:SetConfirmed(true)
  309. else
  310. -- Another action is running
  311. local act = ACTION_CACHE.WALK
  312. if actor:GetValueByKey(global.MMO.ACT_SNEAK) then
  313. act = ACTION_CACHE.SNEAK
  314. end
  315. local netAct = {}
  316. netAct.act = act
  317. netAct.pos = p
  318. if self.mNextActionCache[actor:GetID()] == nil then
  319. self.mNextActionCache[actor:GetID()] = {}
  320. end
  321. table.insert(self.mNextActionCache[actor:GetID()], netAct)
  322. end
  323. self:CheckFastCurrentAction(actor)
  324. end
  325. function netActorController:handle_MSG_SC_ACTOR_RUN(actor, msgHdr)
  326. -- 死亡状态无法切换
  327. if actor:IsDie() or actor:IsDeath() then
  328. return nil
  329. end
  330. local p = { x = msgHdr.param1, y = msgHdr.param2 }
  331. if global.MMO.ACTION_IDLE == actor:GetAction() then
  332. actor:SetMoveTo(p)
  333. actor:SetAction(global.MMO.ACTION_RUN)
  334. actor:SetConfirmed(true)
  335. else
  336. -- Another action is running
  337. local netAct = {}
  338. netAct.act = ACTION_CACHE.RUN
  339. netAct.pos = p
  340. if self.mNextActionCache[actor:GetID()] == nil then
  341. self.mNextActionCache[actor:GetID()] = {}
  342. end
  343. table.insert(self.mNextActionCache[actor:GetID()], netAct)
  344. end
  345. self:CheckFastCurrentAction(actor)
  346. end
  347. function netActorController:handle_MSG_SC_ACTOR_RIDE_RUN(actor, msgHdr)
  348. -- 死亡状态无法切换
  349. if actor:IsDie() or actor:IsDeath() then
  350. return nil
  351. end
  352. local p = { x = msgHdr.param1, y = msgHdr.param2 }
  353. if global.MMO.ACTION_IDLE == actor:GetAction() then
  354. actor:SetMoveTo(p)
  355. actor:SetAction(global.MMO.ACTION_RIDE_RUN)
  356. actor:SetConfirmed(true)
  357. else
  358. -- Another action is running
  359. local netAct = {}
  360. netAct.act = ACTION_CACHE.RIDE_RUN
  361. netAct.pos = p
  362. if self.mNextActionCache[actor:GetID()] == nil then
  363. self.mNextActionCache[actor:GetID()] = {}
  364. end
  365. table.insert(self.mNextActionCache[actor:GetID()], netAct)
  366. end
  367. self:CheckFastCurrentAction(actor)
  368. end
  369. function netActorController:handle_MSG_SC_ACTOR_STUCK(actor)
  370. -- 死亡状态无法切换
  371. if actor:IsDie() or actor:IsDeath() then
  372. return nil
  373. end
  374. -- 受击弯腰,只保留一个
  375. if global.MMO.ACTION_IDLE == actor:GetAction() then
  376. actor:SetAction(global.MMO.ACTION_STUCK)
  377. else
  378. if self.mNextActionCache[actor:GetID()] == nil then
  379. self.mNextActionCache[actor:GetID()] = {}
  380. end
  381. local found = false
  382. for i, v in ipairs(self.mNextActionCache[actor:GetID()]) do
  383. if v.act == ACTION_CACHE.STUCK then
  384. found = true
  385. break
  386. end
  387. end
  388. if not found then
  389. local netAct = {}
  390. netAct.act = ACTION_CACHE.STUCK
  391. table.insert(self.mNextActionCache[actor:GetID()], netAct)
  392. end
  393. end
  394. self:CheckFastCurrentAction(actor)
  395. end
  396. function netActorController:handle_MSG_SC_NET_PLAYER_ATTACK(actor, msgHdr, jsonData)
  397. -- 死亡状态无法切换
  398. if actor:IsDie() or actor:IsDeath() then
  399. return nil
  400. end
  401. if actor:IsMonster() and msgHdr.param3 > 0 then
  402. return nil
  403. end
  404. if global.MMO.ACTION_IDLE == actor:GetAction() then
  405. local SkillProxy = global.Facade:retrieveProxy(global.ProxyTable.Skill)
  406. SkillProxy:actorEnterAction(jsonData, false)
  407. SkillProxy:requestSkillPresent(jsonData, 3)
  408. else
  409. -- Another action is running
  410. local netAct = {}
  411. netAct.act = ACTION_CACHE.SKILL_ACTION_MAGIC
  412. netAct.msgHdr = msgHdr
  413. netAct.jsonData = jsonData
  414. netAct.isMagic = false
  415. if self.mNextActionCache[actor:GetID()] == nil then
  416. self.mNextActionCache[actor:GetID()] = {}
  417. end
  418. table.insert(self.mNextActionCache[actor:GetID()], netAct)
  419. end
  420. self:CheckFastCurrentAction(actor)
  421. end
  422. function netActorController:handle_MSG_SC_PLAYER_SKILL_LAUNCH_SUCCESS(actor, msgHdr, jsonData)
  423. -- 死亡状态无法切换
  424. if actor:IsDie() or actor:IsDeath() then
  425. return nil
  426. end
  427. if global.MMO.ACTION_IDLE == actor:GetAction() then
  428. local SkillProxy = global.Facade:retrieveProxy(global.ProxyTable.Skill)
  429. SkillProxy:actorEnterAction(jsonData, true)
  430. SkillProxy:requestSkillPresent(jsonData, 1)
  431. actor.skillStage = 1
  432. actor.skillID = jsonData.MagicID
  433. else
  434. -- Another action is running
  435. local netAct = {}
  436. netAct.act = ACTION_CACHE.SKILL_ACTION
  437. netAct.jsonData = jsonData
  438. netAct.msgHdr = msgHdr
  439. netAct.isMagic = true
  440. netAct.skillStage = 1
  441. if self.mNextActionCache[actor:GetID()] == nil then
  442. self.mNextActionCache[actor:GetID()] = {}
  443. end
  444. table.insert(self.mNextActionCache[actor:GetID()], netAct)
  445. end
  446. self:CheckFastCurrentAction(actor)
  447. end
  448. function netActorController:handle_MSG_SC_PLAYER_SKILL_MAGIC_SUCCESS(actor, msgHdr, jsonData)
  449. -- 死亡状态无法切换
  450. if actor:IsDie() or actor:IsDeath() then
  451. return nil
  452. end
  453. if global.MMO.ACTION_IDLE == actor:GetAction() then
  454. local SkillProxy = global.Facade:retrieveProxy(global.ProxyTable.Skill)
  455. SkillProxy:requestSkillPresent(jsonData, 2)
  456. elseif (global.MMO.ACTION_ATTACK == actor:GetAction() or global.MMO.ACTION_SKILL == actor:GetAction() or CheckInSkillAction(actor:GetAction())) and actor.skillStage == 1 and actor.skillID == jsonData.MagicID then
  457. actor.skillStage = 2
  458. local SkillProxy = global.Facade:retrieveProxy(global.ProxyTable.Skill)
  459. SkillProxy:requestSkillPresent(jsonData, 2)
  460. else
  461. -- Another action is running
  462. if self.mNextActionCache[actor:GetID()] == nil then
  463. self.mNextActionCache[actor:GetID()] = {}
  464. end
  465. if jsonData.showSkillMaigc then
  466. local SkillProxy = global.Facade:retrieveProxy(global.ProxyTable.Skill)
  467. SkillProxy:requestSkillPresent(jsonData, 3)
  468. else
  469. for i, v in ipairs(self.mNextActionCache[actor:GetID()]) do
  470. if v.act == ACTION_CACHE.SKILL_ACTION and v.skillStage == 1 then
  471. v.msgHdr = msgHdr
  472. v.jsonData = jsonData
  473. v.skillStage = 2
  474. break
  475. end
  476. end
  477. end
  478. end
  479. end
  480. function netActorController:handle_MSG_SC_PLAYER_SKILL_27_SUCCESS(actor, msgHdr)
  481. -- 野蛮
  482. if actor:IsDie() or actor:IsDeath() then
  483. return nil
  484. end
  485. local mapX = msgHdr.param1
  486. local mapY = msgHdr.param2
  487. local dir = H16Bit(msgHdr.param3) == 0 and L16Bit(msgHdr.param3) or L16Bit(msgHdr.param3)
  488. local time = msgHdr.recog * 0.001
  489. local skillId = H16Bit(msgHdr.param3) > 0 and H16Bit(msgHdr.param3) or 0
  490. local sMapX = 0
  491. local sMapY = 0
  492. if H16Bit(msgHdr.param1) > 0 and H16Bit(msgHdr.param2) > 0 then
  493. mapX = L16Bit(msgHdr.param1)
  494. mapY = H16Bit(msgHdr.param1)
  495. sMapX = L16Bit(msgHdr.param2)
  496. sMapY = H16Bit(msgHdr.param2)
  497. end
  498. if skillId == 0 then
  499. if global.MMO.ACTION_IDLE == actor:GetAction() then
  500. if (mapX ~= actor:GetMapX() or mapY ~= actor:GetMapY()) and time > 0 then
  501. actorUtils.actorDash(actor, mapX, mapY, sMapX, sMapY, dir, time)
  502. else
  503. --执行野蛮失败撞墙动作
  504. actor:SetAction(global.MMO.ACTION_DASH_FAIL)
  505. end
  506. else
  507. if (mapX ~= actor:GetMapX() or mapY ~= actor:GetMapY()) and time > 0 then
  508. -- Another action is running
  509. local netAct = {}
  510. netAct.act = ACTION_CACHE.DASH
  511. netAct.msgHdr = msgHdr
  512. if self.mNextActionCache[actor:GetID()] == nil then
  513. self.mNextActionCache[actor:GetID()] = {}
  514. end
  515. table.insert(self.mNextActionCache[actor:GetID()], netAct)
  516. end
  517. end
  518. else
  519. if global.MMO.ACTION_IDLE == actor:GetAction() then
  520. if (mapX ~= actor:GetMapX() or mapY ~= actor:GetMapY()) and time > 0 then
  521. actorUtils.actorZhuiXinCi(actor, mapX, mapY, dir)
  522. end
  523. else
  524. -- Another action is running
  525. local netAct = {}
  526. netAct.act = ACTION_CACHE.ZXC
  527. netAct.msgHdr = msgHdr
  528. if self.mNextActionCache[actor:GetID()] == nil then
  529. self.mNextActionCache[actor:GetID()] = {}
  530. end
  531. table.insert(self.mNextActionCache[actor:GetID()], netAct)
  532. end
  533. end
  534. self:CheckFastCurrentAction(actor)
  535. end
  536. function netActorController:handle_MSG_SC_PLAYER_SKILL_27_BACKSTEP(actor, msgHdr)
  537. -- 被野蛮,被推开
  538. if actor:IsDie() or actor:IsDeath() then
  539. return nil
  540. end
  541. local mapX = msgHdr.param1
  542. local mapY = msgHdr.param2
  543. local dir = msgHdr.param3
  544. local time = msgHdr.recog
  545. local moveTime = L16Bit(time) * 0.001
  546. local idleTime = math.min(H16Bit(time) * 0.001, 5)
  547. local sMapX = 0
  548. local sMapY = 0
  549. if H16Bit(msgHdr.param1) > 0 and H16Bit(msgHdr.param2) > 0 then
  550. mapX = L16Bit(msgHdr.param1)
  551. mapY = H16Bit(msgHdr.param1)
  552. sMapX = L16Bit(msgHdr.param2)
  553. sMapY = H16Bit(msgHdr.param2)
  554. end
  555. if global.MMO.ACTION_IDLE == actor:GetAction() then
  556. if (mapX ~= actor:GetMapX() or mapY ~= actor:GetMapY()) and moveTime > 0 then
  557. actorUtils.actorOnDash(actor, mapX, mapY, sMapX, sMapY, dir, moveTime, idleTime)
  558. end
  559. else
  560. -- Another action is running
  561. local netAct = {}
  562. netAct.act = ACTION_CACHE.ONDASH
  563. netAct.msgHdr = msgHdr
  564. if self.mNextActionCache[actor:GetID()] == nil then
  565. self.mNextActionCache[actor:GetID()] = {}
  566. end
  567. table.insert(self.mNextActionCache[actor:GetID()], netAct)
  568. end
  569. self:CheckFastCurrentAction(actor)
  570. end
  571. function netActorController:handle_MSG_SC_PLAYER_SKILL_82_SUCCESS(actor, msgHdr)
  572. -- 十步一杀 瞬移
  573. if actor:IsDie() or actor:IsDeath() then
  574. return nil
  575. end
  576. local mapX = msgHdr.param1
  577. local mapY = msgHdr.param2
  578. local dir = msgHdr.param3
  579. if global.MMO.ACTION_IDLE == actor:GetAction() then
  580. if( mapX ~= actor:GetMapX() or mapY ~= actor:GetMapY()) then
  581. actorUtils.actorSBYS(actor, mapX, mapY, dir)
  582. end
  583. else
  584. -- Another action is running
  585. local netAct = {}
  586. netAct.act = ACTION_CACHE.SBYS
  587. netAct.msgHdr = msgHdr
  588. if self.mNextActionCache[actor:GetID()] == nil then
  589. self.mNextActionCache[actor:GetID()] = {}
  590. end
  591. table.insert(self.mNextActionCache[actor:GetID()], netAct)
  592. end
  593. self:CheckFastCurrentAction(actor)
  594. end
  595. function netActorController:handle_MSG_SC_PLAYER_SKILL_71_SUCCESS(actor, msgHdr)
  596. -- 擒龙手 瞬移
  597. if actor:IsDie() or actor:IsDeath() then
  598. return nil
  599. end
  600. local mapX = msgHdr.param1
  601. local mapY = msgHdr.param2
  602. local dir = msgHdr.param3
  603. if global.MMO.ACTION_IDLE == actor:GetAction() then
  604. if (mapX ~= actor:GetMapX() or mapY ~= actor:GetMapY()) then
  605. actorUtils.actorQLS(actor, mapX, mapY, dir)
  606. end
  607. else
  608. -- Another action is running
  609. local netAct = {}
  610. netAct.act = ACTION_CACHE.QLS
  611. netAct.msgHdr = msgHdr
  612. if self.mNextActionCache[actor:GetID()] == nil then
  613. self.mNextActionCache[actor:GetID()] = {}
  614. end
  615. table.insert(self.mNextActionCache[actor:GetID()], netAct)
  616. end
  617. self:CheckFastCurrentAction(actor)
  618. end
  619. function netActorController:handle_Move_Force(actor, jsonData)
  620. self.mNextActionCache[actor:GetID()] = nil
  621. local posOfAccepted = global.sceneManager:MapPos2WorldPos(jsonData.mapX, jsonData.mapY, true)
  622. actor:SetAction(global.MMO.ACTION_IDLE, true)
  623. actor.mIsArrived = true
  624. actor.mIsConfirmed = true
  625. actor:SetDirection(jsonData.dir)
  626. actor:setPosition(posOfAccepted.x, posOfAccepted.y)
  627. global.actorManager:SetActorMapXY(actor, jsonData.mapX, jsonData.mapY)
  628. end
  629. function netActorController:handle_FlyIn(actor, msgHdr)
  630. self.mNextActionCache[actor:GetID()] = nil
  631. local mapX = msgHdr.param1
  632. local mapY = msgHdr.param2
  633. local dir = msgHdr.param3
  634. local posOfAccepted = global.sceneManager:MapPos2WorldPos(mapX, mapY, true)
  635. actor:SetAction(global.MMO.ACTION_IDLE, true)
  636. actor:SetIsArrived(true)
  637. actor:SetConfirmed(true)
  638. actor:SetDirection(dir)
  639. actor:setPosition(posOfAccepted.x, posOfAccepted.y)
  640. global.actorManager:SetActorMapXY( actor, mapX, mapY )
  641. end
  642. function netActorController:handle_FlyIn2(actor, msgHdr)
  643. self.mNextActionCache[actor:GetID()] = nil
  644. local mapX = msgHdr.param1
  645. local mapY = msgHdr.param2
  646. local dir = msgHdr.param3
  647. local posOfAccepted = global.sceneManager:MapPos2WorldPos(mapX, mapY, true)
  648. actor:SetAction(global.MMO.ACTION_IDLE, true)
  649. actor:SetIsArrived(true)
  650. actor:SetConfirmed(true)
  651. actor:SetDirection(dir)
  652. actor:setPosition(posOfAccepted.x, posOfAccepted.y)
  653. global.actorManager:SetActorMapXY( actor, mapX, mapY )
  654. end
  655. function netActorController:cleanupCacheByActorID(actorID)
  656. self.mNextActionCache[actorID] = nil
  657. end
  658. function netActorController:SyncLatestPosition(actor, updateCurrPosition)
  659. local p1 = self.mNextActionCache[actor:GetID()]
  660. if p1 == nil then p1 = {} end
  661. local lastMoveAct = nil
  662. for k, v in pairs(p1) do
  663. local netAct = v
  664. if ACTION_CACHE.WALK == netAct.act or ACTION_CACHE.RUN == netAct.act or ACTION_CACHE.RIDE_RUN == netAct.act then
  665. lastMoveAct = netAct
  666. end
  667. end
  668. if lastMoveAct then
  669. local mapX = lastMoveAct.pos.x
  670. local mapY = lastMoveAct.pos.y
  671. local targetPos = global.sceneManager:MapPos2WorldPos(mapX, mapY, true)
  672. actor:setPosition(targetPos.x, targetPos.y)
  673. global.actorManager:SetActorMapXY(actor, mapX, mapY)
  674. elseif updateCurrPosition then
  675. if actor.mCurrentActT > 0.0001 then
  676. actor:SetCurrActTime(0)
  677. local mapX = actor:GetMapX()
  678. local mapY = actor:GetMapY()
  679. local targetPos = global.sceneManager:MapPos2WorldPos(mapX, mapY, true)
  680. actor:setPosition(targetPos.x, targetPos.y)
  681. end
  682. end
  683. -- reset state
  684. actor:SetIsArrived(true)
  685. actor:SetConfirmed(true)
  686. end
  687. function netActorController:CheckFastCurrentAction(actor)
  688. -- if not ((actor:IsPlayer() or actor:IsMonster())) then
  689. -- return
  690. -- end
  691. -- if global.MMO.ACTION_IDLE == actor:GetAction() then
  692. -- return
  693. -- end
  694. end
  695. function netActorController:handle_ActorMapXYChange(actor, mapX, mapY)
  696. global.Facade:sendNotification(global.NoticeTable.ActorMapXYChange, { actor = actor, actorID = actor:GetID() })
  697. end
  698. function netActorController:handle_MSG_SC_NET_MONSTER_BORN(actor, msgHdr, msgData)
  699. end
  700. function netActorController:handle_MSG_SC_NET_MONSTER_CAVE(actor, msgHdr, msgData)
  701. end
  702. return netActorController