GameActorSkillController.lua 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490
  1. local GameActorSkillController = class("GameActorSkillController")
  2. GameActorSkillController.NAME = "GameActorSkillController"
  3. function GameActorSkillController:ctor()
  4. self._jointCache = {}
  5. self:RegisterMsgHandler()
  6. self._klaunchQueue = {}
  7. self._mainPlayerAddDashTime = 0
  8. end
  9. function GameActorSkillController:destory()
  10. if GameActorSkillController.instance then
  11. GameActorSkillController.instance = nil
  12. end
  13. end
  14. function GameActorSkillController:Inst()
  15. if not GameActorSkillController.instance then
  16. GameActorSkillController.instance = GameActorSkillController.new()
  17. end
  18. return GameActorSkillController.instance
  19. end
  20. function GameActorSkillController:GetMainPlayerAddDashTime()
  21. return self._mainPlayerAddDashTime
  22. end
  23. function GameActorSkillController:SetMainPlayerAddDashTime(t)
  24. self._mainPlayerAddDashTime = t
  25. end
  26. local function handle_MSG_SC_PLAYER_SKILL_27_SUCCESS(msg)
  27. local msgHdr = msg:GetHeader()
  28. local msgLen = msg:GetDataLength()
  29. local actorID = msgLen > 0 and msg:GetData():ReadString(msgLen) or ""
  30. if not actorID then
  31. return nil
  32. end
  33. local mapX = msgHdr.param1
  34. local mapY = msgHdr.param2
  35. local dir = msgHdr.param3
  36. local time = msgHdr.recog
  37. local actor = global.actorManager:GetActor(actorID)
  38. if not actor then
  39. return -1
  40. end
  41. if actor:GetMapX() == mapX and actor:GetMapY() == mapY and not actor:IsPlayer() then
  42. return -1
  43. end
  44. if actor:IsMonster() then
  45. global.netMonsterController:handle_MSG_SC_PLAYER_SKILL_27_SUCCESS(actor, msgHdr)
  46. elseif actor:IsPlayer() then
  47. if actor:IsMainPlayer() then
  48. global.gamePlayerController:handle_MSG_SC_PLAYER_SKILL_27_SUCCESS(actor, msgHdr)
  49. else
  50. global.netPlayerController:handle_MSG_SC_PLAYER_SKILL_27_SUCCESS(actor, msgHdr)
  51. end
  52. end
  53. return 1
  54. end
  55. local function handle_MSG_SC_PLAYER_SKILL_27_BACKSTEP(msg)
  56. local msgHdr = msg:GetHeader()
  57. local msgLen = msg:GetDataLength()
  58. local actorID = msgLen > 0 and msg:GetData():ReadString(msgLen) or ""
  59. if not actorID then
  60. return nil
  61. end
  62. local mapX = msgHdr.param1
  63. local mapY = msgHdr.param2
  64. local dir = msgHdr.param3
  65. local time = msgHdr.recog
  66. local actor = global.actorManager:GetActor(actorID)
  67. if not actor then
  68. return -1
  69. end
  70. -- 时间不对
  71. if time <= 0 then
  72. return -1
  73. end
  74. if actor:IsMonster() then
  75. global.netMonsterController:handle_MSG_SC_PLAYER_SKILL_27_BACKSTEP(actor, msgHdr)
  76. elseif actor:IsPlayer() then
  77. if actor:IsMainPlayer() then
  78. global.gamePlayerController:handle_MSG_SC_PLAYER_SKILL_27_BACKSTEP(actor, msgHdr)
  79. else
  80. global.netPlayerController:handle_MSG_SC_PLAYER_SKILL_27_BACKSTEP(actor, msgHdr)
  81. end
  82. end
  83. return 1
  84. end
  85. function GameActorSkillController:handle_MSG_SC_SKILL_HIT_MISS(msg)
  86. local msgLen = msg:GetDataLength()
  87. local dataString = msg:GetData():ReadString(msgLen)
  88. self._hitMissUserID = dataString
  89. end
  90. function GameActorSkillController:getHitMissUserID()
  91. return self._hitMissUserID
  92. end
  93. function GameActorSkillController:resetHitMissUserID()
  94. self._hitMissUserID = nil
  95. end
  96. function GameActorSkillController:handle_MSG_SC_JOINT_SKILL_PRESENT(msg)
  97. -- local jsonData = ParseRawMsgToJson( msg )
  98. -- if not jsonData then
  99. -- return -1
  100. -- end
  101. local header = msg:GetHeader()
  102. local msgLen = msg:GetDataLength()
  103. local userid = ""
  104. local target = ""
  105. if msgLen>0 then
  106. local strs = msg:GetData():ReadString(msgLen)
  107. dump(strs,"strs____")
  108. local ss = string.split(strs,"#")
  109. userid = ss[1]
  110. if #ss>1 then
  111. table.remove(ss,1)
  112. target = table.concat(ss,"#")
  113. end
  114. end
  115. dump(header,"msgHdr____")
  116. dump(userid,"userid")
  117. dump(target,"target___")
  118. local magicid = header.recog
  119. local jsonData = {}
  120. jsonData.magicid =magicid
  121. jsonData.userid =userid
  122. jsonData.x = header.param1
  123. jsonData.y = header.param2
  124. jsonData.dir = header.param3
  125. jsonData.target = target
  126. local actorID = jsonData.userid
  127. local actor = global.actorManager:GetActor(actorID)
  128. if not actor then
  129. print("joint skill launcher is Miss!!!!!!!")
  130. return -1
  131. end
  132. if not actor:IsPlayer() then
  133. return -1
  134. end
  135. if actorID == global.gamePlayerController:GetMainPlayerID() then
  136. if actor:GetAction() == global.MMO.ACTION_WALK or actor:GetAction() == global.MMO.ACTION_RUN then
  137. table.insert(self._jointCache, jsonData)
  138. return -1
  139. end
  140. end
  141. self:launchJointSkill(jsonData)
  142. return 1
  143. end
  144. function GameActorSkillController:handle_MSG_SC_JOINT_SKILL_PRESENT_HIT(msg)
  145. local header = msg:GetHeader()
  146. local msgLen = msg:GetDataLength()
  147. local userid = ""
  148. if msgLen>0 then
  149. userid = msg:GetData():ReadString(msgLen)
  150. end
  151. dump(header,"handle_MSG_SC_JOINT_SKILL_PRESENT_HIT__")
  152. local actorID = userid
  153. local actor = global.actorManager:GetActor(actorID)
  154. if not actor then
  155. return -1
  156. end
  157. local skillID = header.param1
  158. local root = global.sceneGraphCtl:GetSceneNode(global.MMO.NODE_SKILL)
  159. local skillData = global.skillManager:getSkillDataByID(skillID)
  160. local animID
  161. local func = function(sender, eventType)
  162. sender:removeFromParent()
  163. end
  164. local anim
  165. repeat
  166. animID = skillData and skillData.hitID
  167. anim = global.FrameAnimManager:CreateSkillEffAnim(animID)
  168. root:addChild(anim)
  169. anim:setPosition(cc.pAdd(actor:getPosition(), global.MMO.PLAYER_AVATAR_OFFSET))
  170. anim:setLocalZOrder(animID)
  171. anim:Play(0, 0, true)
  172. anim:SetAnimEventCallback(func)
  173. if skillData.linkSkill and skillData.linkSkill >= 1 then
  174. skillData = global.skillManager:getSkillDataByID(skillData.linkSkill)
  175. else
  176. skillData = nil
  177. end
  178. until not skillData
  179. return 1
  180. end
  181. function GameActorSkillController:handle_MSG_SC_HERO_EFFECT(msg)
  182. local header = msg:GetHeader()
  183. local msgLen = msg:GetDataLength()
  184. local userid = ""
  185. if msgLen>0 then
  186. userid = msg:GetData():ReadString(msgLen)
  187. end
  188. local animID = header.param1
  189. -- dump(header,"header____")
  190. -- dump(userid,"userid__")
  191. local anim = global.FrameAnimManager:CreateSFXAnim( animID )
  192. local actor = global.actorManager:GetActor(userid)
  193. -- dump(actor,"actor__")
  194. local func = function(sender, eventType)
  195. sender:removeFromParent()
  196. end
  197. if actor then
  198. actor:GetNode():addChild( anim )
  199. anim:setLocalZOrder(animID)
  200. anim:Play(0, 0, true)
  201. anim:SetAnimEventCallback(func)
  202. end
  203. end
  204. function GameActorSkillController:launchJointSkill(jsonData)
  205. local actorID = jsonData.userid
  206. local targetID = jsonData.target or ""
  207. local srcX = jsonData.x or 0
  208. local srcY = jsonData.y or 0
  209. local hitX = jsonData.tx or 0
  210. local hitY = jsonData.ty or 0
  211. local dir = jsonData.dir or 0
  212. local skillID = jsonData.magicid
  213. local actor = global.actorManager:GetActor(actorID)
  214. if not actor then
  215. return -1
  216. end
  217. if not actor:IsPlayer() then
  218. return -1
  219. end
  220. -- 防止后退
  221. if actorID == global.gamePlayerController:GetMainPlayerID() then
  222. global.Facade:sendNotification(global.NoticeTable.InputIdle)
  223. -- local InputControllerClass = requireMediator( "role/PlayerInputController" )
  224. -- local inputController = global.Facade:retrieveMediator( InputControllerClass.NAME )
  225. --inputController:SetInputState( global.MMO.INPUT_STATE_LAUNCH )
  226. if CHECK_SETTING(global.MMO.SETTING_IDX_HERO_JOINT_SHAKE) == 1 then
  227. global.Facade:sendNotification( global.NoticeTable.ShakeScene)--震动
  228. end
  229. else
  230. -- some property
  231. local worldPos = global.sceneManager:MapPos2WorldPos(srcX, srcY, true)
  232. actor:SetDirection(dir)
  233. actor:setPosition(worldPos.x, worldPos.y)
  234. global.actorManager:SetActorMapXY( actor, srcX, srcY )
  235. end
  236. actor:StopAllAnimation()
  237. local skillProxy = global.Facade:retrieveProxy(global.ProxyTable.Skill)
  238. local skillConfig = skillProxy:FindConfigBySkillID(skillID)
  239. -- action
  240. local actorJob = actor:GetJobID()
  241. local action =
  242. {
  243. skillID = skillID,
  244. actor = actor,
  245. dir = dir,
  246. }
  247. if actorJob == global.MMO.ACTOR_PLAYER_JOB_FIGHTER then
  248. global.Facade:sendNotification(global.NoticeTable.ActorEnterAttackAction, action)
  249. else
  250. global.Facade:sendNotification(global.NoticeTable.ActorEnterSkillAction, action)
  251. end
  252. actor:SetConfirmed(true)
  253. -- skill present
  254. -- local presentID = string.format("%s%s", skillID, actorJob)
  255. -- presentID = tonumber(presentID)
  256. local present =
  257. {
  258. skillID = skillID,--presentID,
  259. launchX = actor:GetMapX(),
  260. launchY = actor:GetMapY(),
  261. hitX = hitX,
  262. hitY = hitY,
  263. dir = dir,
  264. param = targetID,
  265. --launchOnly = (not actor:IsHero()),
  266. skillStage = (not actor:IsHero() and 1 or nil),
  267. needFly = true,
  268. launcherID = actorID,
  269. }
  270. global.Facade:sendNotification(global.NoticeTable.RequestSkillPresent, present)
  271. end
  272. function GameActorSkillController:CheckKLaunchAble()
  273. return #self._klaunchQueue > 0
  274. end
  275. function GameActorSkillController:handle_MSG_SC_SERVER_SKILL_RESP(msg)
  276. local jsonData = ParseRawMsgToJson(msg)
  277. if not jsonData then
  278. return nil
  279. end
  280. dump(jsonData)
  281. table.insert(self._klaunchQueue, jsonData)
  282. end
  283. function GameActorSkillController:RequestLaunchServerSkill()
  284. -- 特殊处理的服务器触发技能,真神奇
  285. if #self._klaunchQueue == 0 then
  286. return nil
  287. end
  288. local mainPlayer = global.gamePlayerController:GetMainPlayer()
  289. if not mainPlayer then
  290. return nil
  291. end
  292. local sendData = table.remove(self._klaunchQueue, 1)
  293. SendTableToServer(global.MsgType.MSG_CS_SERVER_SKILL_LAUNCH, sendData)
  294. if sendData.MagId then
  295. local skillProxy = global.Facade:retrieveProxy(global.ProxyTable.Skill)
  296. local skillConfig = skillProxy:FindConfigBySkillID(sendData.MagId)
  297. if skillConfig then
  298. -- present
  299. local present =
  300. {
  301. skillID = skillProxy:GetSkillPresentReplaceID(sendData.MagId),
  302. launchX = mainPlayer:GetMapX(),
  303. launchY = mainPlayer:GetMapY(),
  304. dir = mainPlayer:GetDirection(),
  305. skillStage = 1,
  306. launcherID = mainPlayer:GetID()
  307. }
  308. global.Facade:sendNotification(global.NoticeTable.RequestSkillPresent, present)
  309. -- action
  310. if sendData.Act == 1 then
  311. local action =
  312. {
  313. skillID = sendData.MagId,
  314. actor = mainPlayer,
  315. dir = mainPlayer:GetDirection(),
  316. ActionId = sendData.ActionId or skillProxy:GetActionID(sendData.MagId),
  317. }
  318. if skillConfig.action == 0 then
  319. -- 攻击
  320. global.Facade:sendNotification(global.NoticeTable.ActorEnterAttackAction, action)
  321. mainPlayer:SetConfirmed(true)
  322. elseif skillConfig.action == 1 then
  323. -- 施法
  324. global.Facade:sendNotification(global.NoticeTable.ActorEnterSkillAction, action)
  325. mainPlayer:SetConfirmed(true)
  326. end
  327. end
  328. -- 特殊 连击技能进CD
  329. local skillID = sendData.MagId
  330. if sendData.CD == 1 and skillProxy:IsComboSkill(skillID) then
  331. global.Facade:sendNotification(global.NoticeTable.ComboSkillEnterCD, skillID)
  332. end
  333. end
  334. end
  335. end
  336. --十步一杀瞬移成功
  337. function GameActorSkillController:handle_MSG_SC_PLAYER_SKILL_82_SUCCESS(msg)
  338. local msgHdr = msg:GetHeader()
  339. local msgLen = msg:GetDataLength()
  340. if msgLen <= 0 then
  341. return -1
  342. end
  343. local data = msg:GetData()
  344. local userID = msg:GetData():ReadString(msgLen)
  345. local actor = global.actorManager:GetActor( userID )
  346. if not actor then
  347. return -1
  348. end
  349. if not actor:IsPlayer() then
  350. return -1
  351. end
  352. local mapX = msgHdr.param1
  353. local mapY = msgHdr.param2
  354. if mapX == actor:GetMapX() and mapY == actor:GetMapY() then
  355. return -1
  356. end
  357. if actor:IsMainPlayer() then
  358. global.gamePlayerController:handle_MSG_SC_PLAYER_SKILL_82_SUCCESS(actor, msgHdr)
  359. else
  360. global.netPlayerController:handle_MSG_SC_PLAYER_SKILL_82_SUCCESS(actor, msgHdr)
  361. end
  362. return 1
  363. end
  364. -- 擒龙手瞬移
  365. function GameActorSkillController:handle_MSG_SC_PLAYER_SKILL_71_SUCCESS (msg)
  366. local msgHdr = msg:GetHeader()
  367. local msgLen = msg:GetDataLength()
  368. if msgLen <= 0 then
  369. return -1
  370. end
  371. local data = msg:GetData()
  372. local dataStr = msg:GetData():ReadString(msgLen)
  373. local dataArray = string.split(dataStr or "","#") -- 受击者#施法者
  374. local userID = dataArray[1]
  375. local actor = global.actorManager:GetActor( userID )
  376. if not actor then
  377. return -1
  378. end
  379. local mapX = msgHdr.param1
  380. local mapY = msgHdr.param2
  381. if mapX == actor:GetMapX() and mapY == actor:GetMapY() then
  382. return -1
  383. end
  384. if actor:IsMonster() then
  385. global.netMonsterController:handle_MSG_SC_PLAYER_SKILL_71_SUCCESS(actor,msgHdr)
  386. elseif actor:IsPlayer() then
  387. if actor:IsMainPlayer() then
  388. global.gamePlayerController:handle_MSG_SC_PLAYER_SKILL_71_SUCCESS(actor, msgHdr)
  389. else
  390. global.netPlayerController:handle_MSG_SC_PLAYER_SKILL_71_SUCCESS(actor, msgHdr)
  391. end
  392. end
  393. if global.gamePlayerController:GetMainPlayerID() == dataArray[2] then
  394. local PlayerInputProxy = global.Facade:retrieveProxy(global.ProxyTable.PlayerInputProxy)
  395. PlayerInputProxy:ClearMove()
  396. end
  397. return 1
  398. end
  399. function GameActorSkillController:RegisterMsgHandler()
  400. local msgType = global.MsgType
  401. LuaRegisterMsgHandler(msgType.MSG_SC_PLAYER_SKILL_27_SUCCESS, handle_MSG_SC_PLAYER_SKILL_27_SUCCESS)
  402. LuaRegisterMsgHandler(msgType.MSG_SC_PLAYER_SKILL_27_BACKSTEP, handle_MSG_SC_PLAYER_SKILL_27_BACKSTEP)
  403. LuaRegisterMsgHandler(msgType.MSG_SC_SKILL_HIT_MISS, handler(self, self.handle_MSG_SC_SKILL_HIT_MISS))-- 飞行技能命中失败
  404. LuaRegisterMsgHandler(msgType.MSG_SC_PLAYER_SKILL_82_SUCCESS, handler(self, self.handle_MSG_SC_PLAYER_SKILL_82_SUCCESS)) --十步一杀瞬移成功
  405. LuaRegisterMsgHandler(msgType.MSG_SC_PLAYER_SKILL_71_SUCCESS, handler(self, self.handle_MSG_SC_PLAYER_SKILL_71_SUCCESS)) --擒龙手
  406. LuaRegisterMsgHandler(msgType.MSG_SC_JOINTATTACK_HERO, handler(self, self.handle_MSG_SC_JOINT_SKILL_PRESENT)) -- 合击
  407. LuaRegisterMsgHandler(msgType.MSG_SC_EXTRA_EFFECT, handler(self, self.handle_MSG_SC_JOINT_SKILL_PRESENT_HIT)) -- 合击击中特效
  408. LuaRegisterMsgHandler( msgType.MSG_SC_HERO_EFFECT, handler( self, self.handle_MSG_SC_HERO_EFFECT) ) -- 英雄专属特效
  409. local function ActCompleted(actor, act)
  410. if actor and (act == global.MMO.ACTION_WALK or act == global.MMO.ACTION_RUN) then
  411. for i, v in ipairs(self._jointCache) do
  412. if v.userid == actor:GetID() then
  413. self:launchJointSkill(v)
  414. table.remove(self._jointCache, i)
  415. global.gamePlayerController.mInputEnable = false
  416. break
  417. end
  418. end
  419. end
  420. end
  421. global.gamePlayerController:AddHandleOnActCompleted(ActCompleted)
  422. LuaRegisterMsgHandler(msgType.MSG_SC_SERVER_SKILL_RESP, handler(self, self.handle_MSG_SC_SERVER_SKILL_RESP))-- 服务器触发的技能,牛逼
  423. end
  424. function GameActorSkillController:Cleanup()
  425. end
  426. return GameActorSkillController