RequestLaunchCommand-win32.lua 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484
  1. local RequestLaunchCommand = class('RequestLaunchCommand', framework.SimpleCommand)
  2. local cjson = require("cjson")
  3. local proxyUtils = requireProxy("proxyUtils")
  4. local skillUtils = requireProxy("skillUtils")
  5. local function squLen( x, y )
  6. local maxv = math.max(math.abs(x), math.abs(y))
  7. return maxv * maxv
  8. end
  9. function RequestLaunchCommand:ctor()
  10. self._checkParamFunc = {}
  11. self._checkParamFunc[1] = handler(self, self.checkParam1)
  12. self._checkParamFunc[2] = handler(self, self.checkParam2)
  13. self._checkParamFunc[3] = handler(self, self.checkParam3)
  14. self._checkParamFunc[4] = handler(self, self.checkParam4)
  15. self._checkParamFunc[5] = handler(self, self.checkParam5)
  16. end
  17. function RequestLaunchCommand:getActorIDByMapPosition(mapPos)
  18. local worldPos = global.sceneManager:MapPos2WorldPos(mapPos.x, mapPos.y, true)
  19. local actor = global.actorManager:Pick(worldPos)
  20. if not actor then
  21. return nil
  22. end
  23. return actor:GetID()
  24. end
  25. function RequestLaunchCommand:checkParam1(param)
  26. local mainPlayer = global.gamePlayerController:GetMainPlayer()
  27. if not mainPlayer then
  28. return false
  29. end
  30. param.vecSrc = cc.p(mainPlayer:GetMapX(), mainPlayer:GetMapY())
  31. param.vecDst = cc.p(mainPlayer:GetMapX(), mainPlayer:GetMapY())
  32. param.dir = mainPlayer:GetDirection()
  33. return true
  34. end
  35. function RequestLaunchCommand:checkParam2(param)
  36. local mainPlayer = global.gamePlayerController:GetMainPlayer()
  37. if not mainPlayer then
  38. return false
  39. end
  40. param.vecSrc = cc.p(mainPlayer:GetMapX(), mainPlayer:GetMapY())
  41. param.vecDst = cc.p(mainPlayer:GetMapX(), mainPlayer:GetMapY())
  42. param.dir = mainPlayer:GetDirection()
  43. return true
  44. end
  45. function RequestLaunchCommand:checkParam3(param)
  46. local mainPlayer = global.gamePlayerController:GetMainPlayer()
  47. if not mainPlayer then
  48. return false
  49. end
  50. local inputProxy = global.Facade:retrieveProxy(global.ProxyTable.PlayerInputProxy)
  51. param.vecSrc = cc.p(mainPlayer:GetMapX(), mainPlayer:GetMapY())
  52. param.vecDst = inputProxy:GetLaunchTargetPos()
  53. param.targetID = inputProxy:GetLaunchTargetID()
  54. param.dir = skillUtils.calcLaunchDirection(param.vecDst, param.vecSrc)
  55. -- 增益型, 在自动释放或锁定释放时
  56. local SkillProxy = global.Facade:retrieveProxy(global.ProxyTable.Skill)
  57. local launchType = inputProxy:GetLaunchType()
  58. if SkillProxy:IsAdditionSkill(param.skillID) and (launchType == global.MMO.LAUNCH_TYPE_AUTO or launchType == global.MMO.LAUNCH_TYPE_LOCK) then
  59. param.vecDst = cc.p(mainPlayer:GetMapX(), mainPlayer:GetMapY())
  60. param.targetID = mainPlayer:GetID()
  61. param.dir = mainPlayer:GetDirection()
  62. end
  63. -- 选择目标点下目标
  64. if not param.targetID and inputProxy:GetLaunchTargetPos() then
  65. param.targetID = self:getActorIDByMapPosition(inputProxy:GetLaunchTargetPos())
  66. end
  67. return true
  68. end
  69. function RequestLaunchCommand:checkParam4(param)
  70. local mainPlayer = global.gamePlayerController:GetMainPlayer()
  71. if not mainPlayer then
  72. return false
  73. end
  74. local inputProxy = global.Facade:retrieveProxy(global.ProxyTable.PlayerInputProxy)
  75. -- 强攻
  76. local launchType = inputProxy:GetLaunchType()
  77. if launchType == global.MMO.LAUNCH_TYPE_ATTACK then
  78. param.vecSrc = cc.p(mainPlayer:GetMapX(), mainPlayer:GetMapY())
  79. param.vecDst = cc.p(mainPlayer:GetMapX(), mainPlayer:GetMapY())
  80. param.dir = inputProxy:getCursorWorldDirection()
  81. return true
  82. end
  83. -- 默认传入方向和传入坐标
  84. param.vecSrc = cc.p(mainPlayer:GetMapX(), mainPlayer:GetMapY())
  85. param.vecDst = inputProxy:GetLaunchTargetPos()
  86. param.targetID = inputProxy:GetLaunchTargetID()
  87. param.dir = skillUtils.calcLaunchDirection(param.vecDst, param.vecSrc)
  88. --
  89. if not param.targetID and inputProxy:GetLaunchTargetPos() then
  90. param.targetID = self:getActorIDByMapPosition(inputProxy:GetLaunchTargetPos())
  91. end
  92. -- 锁定攻击目标
  93. local attackTargetID = inputProxy:GetAttackTargetID()
  94. if attackTargetID then
  95. local targetActor = global.actorManager:GetActor(attackTargetID)
  96. if targetActor then
  97. param.vecDst = cc.p(targetActor:GetMapX(), targetActor:GetMapY())
  98. param.dir = skillUtils.calcLaunchDirection(param.vecDst, param.vecSrc)
  99. param.targetID = attackTargetID
  100. end
  101. end
  102. local isAttack = false
  103. if param.targetID then
  104. local targetActor = global.actorManager:GetActor(param.targetID)
  105. if targetActor then
  106. param.vecDst = cc.p(targetActor:GetMapX(), targetActor:GetMapY())
  107. param.dir = skillUtils.calcLaunchDirection(param.vecDst, param.vecSrc)
  108. isAttack = not targetActor:IsDeath() and not targetActor:IsDie() and true or false
  109. end
  110. end
  111. if param.skillID == 0 and not isAttack then
  112. return false
  113. end
  114. return true
  115. end
  116. function RequestLaunchCommand:checkParam5(param)
  117. local mainPlayer = global.gamePlayerController:GetMainPlayer()
  118. if not mainPlayer then
  119. return false
  120. end
  121. local inputProxy = global.Facade:retrieveProxy(global.ProxyTable.PlayerInputProxy)
  122. param.vecSrc = cc.p(mainPlayer:GetMapX(), mainPlayer:GetMapY())
  123. param.vecDst = inputProxy:GetLaunchTargetPos()
  124. param.targetID = inputProxy:GetLaunchTargetID()
  125. param.dir = skillUtils.calcLaunchDirection(param.vecDst, param.vecSrc)
  126. -- 没有传入目标,使用目标点
  127. if not param.targetID then
  128. param.targetID = self:getActorIDByMapPosition(inputProxy:GetLaunchTargetPos())
  129. end
  130. -- 判断目标是否是掉落物
  131. if param.targetID then
  132. local targetActor = global.actorManager:GetActor(param.targetID)
  133. if (targetActor and targetActor:IsDropItem()) or not proxyUtils.checkLaunchTargetByID(param.targetID) then
  134. param.targetID = nil
  135. end
  136. end
  137. -- 魔法锁定
  138. if not param.targetID then
  139. local magicTargetID = inputProxy:GetTargetID()
  140. if magicTargetID and CHECK_SETTING(37) == 1 then
  141. if proxyUtils.checkLaunchTargetByID(magicTargetID) then
  142. local targetActor = global.actorManager:GetActor(magicTargetID)
  143. if targetActor then
  144. param.targetID = magicTargetID
  145. param.vecDst = cc.p(targetActor:GetMapX(), targetActor:GetMapY())
  146. param.dir = skillUtils.calcLaunchDirection(param.vecDst, param.vecSrc)
  147. end
  148. end
  149. end
  150. end
  151. if param.targetID then
  152. local targetActor = global.actorManager:GetActor(param.targetID)
  153. if targetActor then
  154. param.vecDst = cc.p(targetActor:GetMapX(), targetActor:GetMapY())
  155. param.dir = skillUtils.calcLaunchDirection(param.vecDst, param.vecSrc)
  156. end
  157. end
  158. -- 魔法锁定
  159. local skillProxy = global.Facade:retrieveProxy(global.ProxyTable.Skill)
  160. local skillID = param.skillID
  161. local targetID = param.targetID
  162. if skillProxy:IsMagicLockSkill(skillID) and targetID and proxyUtils.checkLaunchTargetByID(targetID) and CHECK_SETTING(37) == 1 then
  163. inputProxy:SetTargetID(targetID)
  164. end
  165. return true
  166. end
  167. function RequestLaunchCommand:execute(note)
  168. local data = note:getBody()
  169. local skillID = data.skillID
  170. local inputDir = data.dir
  171. local inputDst = data.dest
  172. if not skillID then
  173. return nil
  174. end
  175. local player = global.gamePlayerController:GetMainPlayer()
  176. if not player then
  177. return nil
  178. end
  179. local inputProxy = global.Facade:retrieveProxy(global.ProxyTable.PlayerInputProxy)
  180. local skillProxy = global.Facade:retrieveProxy(global.ProxyTable.Skill)
  181. local autoProxy = global.Facade:retrieveProxy(global.ProxyTable.Auto)
  182. local priority = inputProxy:GetLaunchPriority()
  183. if skillProxy:IsComboSkill(skillID) then
  184. skillProxy:ClearComboLanunchID()
  185. end
  186. -- 请求释放参数
  187. local requestParam =
  188. {
  189. skillID = skillID,
  190. targetID = nil,
  191. dir = nil,
  192. vecSrc = nil,
  193. vecDst = nil,
  194. }
  195. if GUIFunction and GUIFunction.OnCheckAllowLaunchSkillBefore then
  196. if not GUIFunction:OnCheckAllowLaunchSkillBefore(skillID) then
  197. releasePrint("GUIFunction:OnCheckAllowLaunchSkill ban skillID ", skillID)
  198. inputProxy:ClearLaunch()
  199. return nil
  200. end
  201. end
  202. -- 1.check base condition( mp? cd? )
  203. local ret = skillProxy:CheckAbleToLaunch(skillID)
  204. if 1 ~= ret then
  205. inputProxy:ClearLaunch()
  206. return nil
  207. end
  208. -- 2.find skill info
  209. local skillConfig = skillProxy:FindConfigBySkillID(skillID)
  210. if not skillConfig then
  211. -- debug
  212. print("can not find skill info, check config !" .. skillID)
  213. inputProxy:ClearLaunch()
  214. return nil
  215. end
  216. -- 3.check target( targetID targetPos dir )
  217. local launchMode = skillProxy:GetLaunchMode(skillID)
  218. local checkParamFunc = self._checkParamFunc[launchMode]
  219. if not checkParamFunc or not checkParamFunc(requestParam) then
  220. inputProxy:ClearLaunch()
  221. return nil
  222. end
  223. if requestParam.targetID then
  224. local target = global.actorManager:GetActor(requestParam.targetID)
  225. if not target or target:IsDie() or target:IsDeath() then
  226. print("")
  227. end
  228. end
  229. -- 4.check attack range.
  230. local moveBestPos = (skillConfig.bestPos ~= 0)
  231. if nil == requestParam.targetID and requestParam.vecSrc.x == requestParam.vecDst.x and requestParam.vecSrc.y == requestParam.vecDst.y then
  232. moveBestPos = false
  233. end
  234. if moveBestPos then
  235. local srcX = requestParam.vecSrc.x
  236. local srcY = requestParam.vecSrc.y
  237. local dstX = requestParam.vecDst.x
  238. local dstY = requestParam.vecDst.y
  239. local targetID = requestParam.targetID
  240. -- move best pos to launch
  241. local launchX, launchY, moveX, moveY = skillUtils.findBestLaunchPos(skillID, targetID, srcX, srcY, dstX, dstY)
  242. if srcX ~= launchX or srcY ~= launchY then
  243. if srcX == moveX and srcY == moveY then
  244. moveX = launchX
  245. moveY = launchY
  246. end
  247. local dest = cc.p(moveX, moveY)
  248. dest.skillID = skillID
  249. dest.targetID = targetID
  250. dest.type = global.MMO.INPUT_MOVE_TYPE_LAUNCH
  251. global.Facade:sendNotification(global.NoticeTable.InputMove, dest)
  252. inputProxy:ResetLaunchDirty()
  253. -- check path points
  254. local points = inputProxy:GetPathFindPoints()
  255. if #points == 0 then
  256. -- ingore target
  257. if targetID then
  258. local target = global.actorManager:GetActor(targetID)
  259. if target then
  260. target:IgnoreActor(true)
  261. end
  262. end
  263. -- clear launch data
  264. autoProxy:ClearAutoLock()
  265. inputProxy:ClearLaunch()
  266. inputProxy:ClearTarget()
  267. end
  268. return nil
  269. end
  270. elseif skillProxy:IsForceDis(skillID) then
  271. local srcX = requestParam.vecSrc.x
  272. local srcY = requestParam.vecSrc.y
  273. local dstX = requestParam.vecDst.x
  274. local dstY = requestParam.vecDst.y
  275. local minLaunchDis = tonumber(skillProxy:GetMinDistance(skillID))
  276. local maxLaunchDis = tonumber(skillProxy:GetMaxDistance(skillID))
  277. if minLaunchDis and maxLaunchDis then
  278. local len = squLen( srcX - dstX, srcY - dstY )
  279. local minRange = minLaunchDis * minLaunchDis
  280. local maxRange = maxLaunchDis * maxLaunchDis
  281. if len < minRange or len > maxRange then
  282. inputProxy:ResetLaunchDirty()
  283. return nil
  284. end
  285. end
  286. end
  287. -- 5. check dir!
  288. if requestParam.dir == global.MMO.ORIENT_INVAILD then
  289. requestParam.dir = player:GetDirection()
  290. end
  291. -- 6. assist
  292. local AssistProxy = global.Facade:retrieveProxy(global.ProxyTable.AssistProxy)
  293. AssistProxy:autoDressEquipSkill(skillID)
  294. -- 7. request server
  295. -- debug
  296. -- print( "request server:", param1, GetTimeInMS() )
  297. -- dump(requestParam)
  298. local sendData = {
  299. skillID = skillID,
  300. dir = requestParam.dir,
  301. srcX = requestParam.vecSrc.x,
  302. srcY = requestParam.vecSrc.y,
  303. destX = requestParam.vecDst.x,
  304. destY = requestParam.vecDst.y,
  305. targetID = requestParam.targetID,
  306. }
  307. local netMsgID = (skillConfig.action == 0 and global.MsgType.MSG_CS_PLAYER_SKILL_ATTACK or global.MsgType.MSG_CS_PLAYER_SKILL_LAUNCH)
  308. local jsonStr = cjson.encode(sendData)
  309. LuaSendMsg(netMsgID, skillID, 0, 0, 0, jsonStr, string.len(jsonStr))
  310. -- dump(sendData)
  311. -- 7.enter cd
  312. if skillProxy:IsComboSkill(skillID) then
  313. global.Facade:sendNotification(global.NoticeTable.ComboSkillEnterCD, skillID)
  314. else
  315. global.Facade:sendNotification(global.NoticeTable.SkillEnterCD, skillID)
  316. end
  317. -- 8.enter action, and play skill effect immediately
  318. local action =
  319. {
  320. skillID = skillID,
  321. actor = player,
  322. dir = requestParam.dir,
  323. ActionId = skillProxy:GetActionID(skillID),
  324. }
  325. if skillID == global.MMO.SKILL_INDEX_YMCZ then
  326. -- 野蛮
  327. player:SetAction(global.MMO.ACTION_DASH_WAITING, true)
  328. elseif skillID == global.MMO.SKILL_INDEX_SBYS then
  329. -- 十步一杀
  330. player:SetAction(global.MMO.ACTION_DASH_WAITING, true)
  331. elseif skillID == global.MMO.SKILL_INDEX_DIG then
  332. -- 挖矿
  333. player:SetDirection(inputDir)
  334. player:SetAction(global.MMO.ACTION_MINING)
  335. -- 特殊处理下,挖矿时普通攻击进入CD,处理下挖矿的CD问题
  336. global.Facade:sendNotification(global.NoticeTable.SkillEnterCD, global.MMO.SKILL_INDEX_BASIC)
  337. elseif skillConfig.action == 0 then
  338. global.Facade:sendNotification(global.NoticeTable.ActorEnterAttackAction, action)
  339. elseif skillConfig.action == 1 then
  340. global.Facade:sendNotification(global.NoticeTable.ActorEnterSkillAction, action)
  341. end
  342. -- 刀刀刺杀
  343. -- 强攻不处理
  344. local presentSkillID = skillID
  345. if skillID == global.MMO.SKILL_INDEX_CSJS and CHECK_SETTING(global.MMO.SETTING_IDX_DAODAOCISHA) == 0 then
  346. local distance = inputProxy:calcMapDistance(requestParam.vecDst, requestParam.vecSrc)
  347. if distance < 2 then
  348. presentSkillID = global.MMO.SKILL_INDEX_BASIC
  349. end
  350. end
  351. -- 技能特效
  352. if skillID ~= global.MMO.SKILL_INDEX_DIG then
  353. local present =
  354. {
  355. skillID = skillProxy:GetSkillPresentReplaceID(presentSkillID),
  356. launchX = requestParam.vecSrc.x,
  357. launchY = requestParam.vecSrc.y,
  358. hitX = requestParam.vecDst.x,
  359. hitY = requestParam.vecDst.y,
  360. dir = requestParam.dir,
  361. skillStage = 1,
  362. launcherID = player:GetID()
  363. }
  364. global.Facade:sendNotification(global.NoticeTable.RequestSkillPresent, present)
  365. end
  366. -- 开关技能关闭
  367. if skillID == global.MMO.SKILL_INDEX_GSJS
  368. or skillID == global.MMO.SKILL_INDEX_LHJF
  369. or skillID == global.MMO.SKILL_INDEX_LYJF
  370. or skillID == global.MMO.SKILL_INDEX_LTJF
  371. or skillID == global.MMO.SKILL_INDEX_ZRJF
  372. or skillID == global.MMO.SKILL_INDEX_KTZ
  373. or skillID == global.MMO.SKILL_INDEX_ZHJS
  374. then
  375. skillProxy:SkillOff(skillID)
  376. end
  377. -- 普攻音效
  378. if presentSkillID == global.MMO.SKILL_INDEX_BASIC then
  379. global.Facade:sendNotification(global.NoticeTable.Audio_Play, {type=global.MMO.SND_TYPE_SKILL_ATTACK})
  380. --auto on skill 普攻
  381. if not skillProxy:IsOnSkill(global.MMO.SKILL_INDEX_CSJS) and CHECK_SETTING(global.MMO.SETTING_IDX_DAODAOCISHA) == 1 then
  382. skillProxy:RequestSkillOnoff(global.MMO.SKILL_INDEX_CSJS)
  383. end
  384. end
  385. -- 十步一杀 锁定自动释放
  386. if CHECK_SETTING(global.MMO.SETTING_IDX_ALWAYS_ATTACK) == 1 and skillID == global.MMO.SKILL_INDEX_SBYS then
  387. if not autoProxy:IsAutoLockState() and not autoProxy:IsAFKState() and skillProxy:IsLockTargetSkill(global.MMO.SKILL_INDEX_BASIC) then
  388. autoProxy:SetIsAutoLockState(true)
  389. autoProxy:SetAutoLockSkillID(global.MMO.SKILL_INDEX_BASIC)
  390. end
  391. end
  392. -- 更改选中目标
  393. local actorPickerProxy = global.Facade:retrieveProxy(global.ProxyTable.ActorPicker)
  394. local lastMouseInsideActor = actorPickerProxy:GetLastMouseInsideActor()
  395. if inputProxy:GetLaunchSkillID() == skillID and inputProxy:GetLaunchType() == global.MMO.LAUNCH_TYPE_USER and skillProxy:IsMagicLockSkill(skillID) and lastMouseInsideActor and lastMouseInsideActor ~= inputProxy:GetTargetID() then
  396. local actor = global.actorManager:GetActor(lastMouseInsideActor)
  397. local isChangeTarge = true
  398. if not actor then
  399. isChangeTarge = false
  400. elseif actor:IsNPC() then
  401. isChangeTarge = false
  402. elseif actor:IsDeath() or actor:IsDie() then
  403. isChangeTarge = false
  404. elseif lastMouseInsideActor == global.gamePlayerController:GetMainPlayerID() then
  405. isChangeTarge = false
  406. elseif actor:IsDropItem() then
  407. isChangeTarge = false
  408. end
  409. if isChangeTarge then
  410. inputProxy:SetTargetID( lastMouseInsideActor )
  411. end
  412. end
  413. skillProxy:ResetDelaySkillLaunch( skillID )
  414. -- clear launch data
  415. inputProxy:ClearLaunch()
  416. end
  417. return RequestLaunchCommand