AssistProxy.lua 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560
  1. local RemoteProxy = requireProxy("remote/RemoteProxy")
  2. local AssistProxy = class("AssistProxy", RemoteProxy)
  3. AssistProxy.NAME = global.ProxyTable.AssistProxy
  4. local proxyUtils = requireProxy( "proxyUtils" )
  5. local cjson = require("cjson")
  6. -- StdMode=25 Shape=1 灰色药粉
  7. -- StdMode=25 Shape=2 黄色药粉
  8. -- StdMode=25 Shape=5 护身符
  9. -- 使用护身符的技能
  10. local function isHSFSkill(skillID)
  11. local skills = {13, 14, 15, 16, 17, 18, 19, 30, 55, 57,76}
  12. for key, value in pairs(skills) do
  13. if value == skillID then
  14. return true
  15. end
  16. end
  17. return false
  18. end
  19. -- 使用毒的技能
  20. local function isDUSkill(skillID)
  21. local skills = {6, 51}
  22. for key, value in pairs(skills) do
  23. if value == skillID then
  24. return true
  25. end
  26. end
  27. return false
  28. end
  29. -- 是护身符
  30. local function isHSFItem(item)
  31. if not item then
  32. return false
  33. end
  34. return item.StdMode == 25 and item.Shape == 5
  35. end
  36. -- 是毒药粉
  37. local function isDUItem(item)
  38. if not item then
  39. return false
  40. end
  41. return item.StdMode == 25 and (item.Shape == 1 or item.Shape == 2)
  42. end
  43. -- 通过 stdmode和 shape从背包找物品
  44. local function findBagItem(stdMode, shape)
  45. local BagProxy = global.Facade:retrieveProxy(global.ProxyTable.Bag)
  46. local items = BagProxy:GetBagData()
  47. for _, item in pairs(items) do
  48. if item.StdMode == stdMode and item.Shape == shape then
  49. return item
  50. end
  51. end
  52. return nil
  53. end
  54. function AssistProxy:ctor()
  55. AssistProxy.super.ctor(self)
  56. self._offlineState = false
  57. self._isFindMapMonster = false
  58. self._isFindMapMonsterFail = false
  59. self._requestMonsterFlag = false
  60. self._nextAutoEquipShape = nil -- 上次挂机时使用的是什么药粉
  61. end
  62. function AssistProxy:onRegister()
  63. AssistProxy.super.onRegister(self)
  64. local msgType = global.MsgType
  65. end
  66. function AssistProxy:checkIsBusy()
  67. local mainPlayer = global.gamePlayerController:GetMainPlayer()
  68. local mapData = global.sceneManager:GetMapData2DPtr()
  69. if not mapData or not mainPlayer then
  70. print("000")
  71. return true
  72. end
  73. local facade = global.Facade
  74. local inputProxy = facade:retrieveProxy(global.ProxyTable.PlayerInputProxy)
  75. local autoProxy = facade:retrieveProxy(global.ProxyTable.Auto)
  76. -- afk
  77. if autoProxy:IsAFKState() then
  78. return false
  79. end
  80. -- 有掉落物可以捡
  81. if autoProxy:IsCanAutoPick() then
  82. return true
  83. end
  84. -- 不可以移动
  85. if not inputProxy:IsMovePermission()then
  86. return true
  87. end
  88. -- 移动中断
  89. if inputProxy:GetMoveInterruptFlag() then
  90. return true
  91. end
  92. -- 移动中
  93. if (inputProxy:IsMoveDirty() or inputProxy:GetCurrPathPoint() > 0) then
  94. return true
  95. end
  96. return false
  97. end
  98. function AssistProxy:CheckDu(type)--1 绿 2 红
  99. local MapProxy = global.Facade:retrieveProxy(global.ProxyTable.Map)
  100. local dresstype = MapProxy:GetUseAmuletType() --0 穿戴 1 背包 2 无
  101. local EquipProxy = global.Facade:retrieveProxy(global.ProxyTable.Equip)
  102. local EquipType = EquipProxy:GetEquipTypeConfig()
  103. local dressEquip = EquipProxy:GetEquipDataByPos(EquipType.Equip_Type_Bujuk)
  104. if dresstype == 2 then
  105. return true
  106. end
  107. if type == 1 then
  108. if dressEquip then
  109. return dressEquip.Shape == 1 or findBagItem(25, 1)
  110. else
  111. return findBagItem(25, 1)
  112. end
  113. elseif type == 2 then
  114. if dressEquip then
  115. return dressEquip.Shape == 2 or findBagItem(25, 2)
  116. else
  117. return findBagItem(25, 2)
  118. end
  119. end
  120. end
  121. function AssistProxy:autoDressEquipSkill(skillID)
  122. -- 0(穿戴) 才需要自动穿
  123. local MapProxy = global.Facade:retrieveProxy(global.ProxyTable.Map)
  124. if MapProxy:GetUseAmuletType() ~= 0 then
  125. return false
  126. end
  127. -- 自动红绿毒
  128. if not (isHSFSkill(skillID) or isDUSkill(skillID)) then
  129. return false
  130. end
  131. -- 装备位置 9
  132. -- step1 符/毒,
  133. -- 符,判断当前是否包含符子串, 是.不管 否.背包找,找到就换
  134. -- 毒,灰/黄毒轮换,换为符之后重置
  135. -- 挂机,用与上次 灰/黄 药粉不一样的装备
  136. local AutoProxy = global.Facade:retrieveProxy( global.ProxyTable.Auto )
  137. local isAFKState = AutoProxy:IsAFKState()
  138. local EquipProxy = global.Facade:retrieveProxy(global.ProxyTable.Equip)
  139. local EquipType = EquipProxy:GetEquipTypeConfig()
  140. local dressEquip = EquipProxy:GetEquipDataByPos(EquipType.Equip_Type_Bujuk)
  141. local replaceItem = nil
  142. local autoShapeDU1 = 1
  143. local autoShapeDU2 = 2
  144. if isAFKState then
  145. self._nextAutoEquipShape = self._nextAutoEquipShape or 1
  146. autoShapeDU1 = self._nextAutoEquipShape
  147. autoShapeDU2 = 3 - autoShapeDU1
  148. else
  149. self._nextAutoEquipShape = nil
  150. end
  151. if isHSFSkill(skillID) and CHECK_SETTING(40) == 1 then
  152. -- 符
  153. if not isHSFItem(dressEquip) then
  154. replaceItem = findBagItem(25, 5)
  155. end
  156. elseif isDUSkill(skillID) and CHECK_SETTING(40) == 1 then
  157. -- 毒
  158. if dressEquip and dressEquip.StdMode == 25 then
  159. if dressEquip.Shape == 5 then
  160. replaceItem = findBagItem(25, autoShapeDU1) or findBagItem(25, autoShapeDU2)
  161. elseif dressEquip.Shape == 1 then
  162. replaceItem = findBagItem(25, 2)
  163. elseif dressEquip.Shape == 2 then
  164. replaceItem = findBagItem(25, 1)
  165. end
  166. else
  167. replaceItem = findBagItem(25, autoShapeDU1) or findBagItem(25, autoShapeDU2)
  168. end
  169. end
  170. if replaceItem then
  171. local ItemUseProxy = global.Facade:retrieveProxy(global.ProxyTable.ItemUseProxy)
  172. ItemUseProxy:UseItem(replaceItem)
  173. if isAFKState and (replaceItem.Shape == 1 or replaceItem.Shape == 2) then
  174. self._nextAutoEquipShape = 3 - replaceItem.Shape
  175. end
  176. end
  177. end
  178. function AssistProxy:checkDressEquipSkillID(skillID)
  179. if not (isHSFSkill(skillID) or isDUSkill(skillID)) then
  180. return true
  181. end
  182. local EquipProxy = global.Facade:retrieveProxy(global.ProxyTable.Equip)
  183. local EquipType = EquipProxy:GetEquipTypeConfig()
  184. local dressEquip = EquipProxy:GetEquipDataByPos(EquipType.Equip_Type_Bujuk)
  185. -- 没穿
  186. if not dressEquip then
  187. return false
  188. end
  189. -- 符
  190. if isHSFSkill(skillID) and isHSFItem(dressEquip) then
  191. return true
  192. end
  193. -- 毒
  194. if isDUSkill(skillID) and isDUItem(dressEquip) then
  195. return true
  196. end
  197. return false
  198. end
  199. function AssistProxy:checkBagEquipSkillID(skillID)
  200. -- 背包中是否有释放技能装备
  201. if not (isHSFSkill(skillID) or isDUSkill(skillID)) then
  202. return true
  203. end
  204. -- 符
  205. if isHSFSkill(skillID) and findBagItem(25, 5) then
  206. return true
  207. end
  208. -- 毒
  209. if isDUSkill(skillID) and (findBagItem(25, 1) or findBagItem(25, 2)) then
  210. return true
  211. end
  212. return false
  213. end
  214. -------------------------------------------------
  215. -- 自动挂机
  216. function AssistProxy:setOfflineState(state)
  217. self._offlineState = state
  218. end
  219. function AssistProxy:getOfflineState()
  220. return self._offlineState
  221. end
  222. function AssistProxy:resetOfflineState()
  223. self:setOfflineState(false)
  224. self:resetOfflineSchedule()
  225. end
  226. function AssistProxy:resetOfflineSchedule()
  227. if self._offlineScheduleID then
  228. UnSchedule(self._offlineScheduleID)
  229. self._offlineScheduleID = nil
  230. end
  231. end
  232. function AssistProxy:checkOfflineAble()
  233. local mainPlayer = global.gamePlayerController:GetMainPlayer()
  234. local mapData = global.sceneManager:GetMapData2DPtr()
  235. if not mapData or not mainPlayer then
  236. return false
  237. end
  238. local facade = global.Facade
  239. local inputProxy = facade:retrieveProxy(global.ProxyTable.PlayerInputProxy)
  240. local autoProxy = facade:retrieveProxy(global.ProxyTable.Auto)
  241. -- 有掉落物可以捡 (并且 不满足 范围内有足够怪物 小精灵 不是一个个拾取 )
  242. if autoProxy:IsCanAutoPick() and not proxyUtils:checkIsEnoughMonster() and not proxyUtils:checkIsPlayerAbandonPickup() then
  243. return false
  244. end
  245. -- afk
  246. if not autoProxy:IsAFKState() then
  247. return false
  248. end
  249. -- 当前有目标
  250. if inputProxy:GetTargetID() then
  251. return false
  252. end
  253. -- 不可以移动
  254. if not inputProxy:IsMovePermission()then
  255. return false
  256. end
  257. -- 移动中断
  258. if inputProxy:GetMoveInterruptFlag() then
  259. return false
  260. end
  261. -- 移动中
  262. if (inputProxy:IsMoveDirty() or inputProxy:GetCurrPathPoint() > 0) then
  263. return false
  264. end
  265. return true
  266. end
  267. function AssistProxy:checkAimlessMove()
  268. if false == self:checkOfflineAble() then
  269. self:resetOfflineState()
  270. return false
  271. end
  272. --
  273. if self._offlineScheduleID then
  274. return false
  275. end
  276. local function callback()
  277. self._offlineScheduleID = nil
  278. if false == self:checkOfflineAble() then
  279. return
  280. end
  281. local mainPlayer = global.gamePlayerController:GetMainPlayer()
  282. local mapData = global.sceneManager:GetMapData2DPtr()
  283. if not mapData or not mainPlayer then
  284. return nil
  285. end
  286. local mapRows = mapData:getMapDataRows()
  287. local mapCols = mapData:getMapDataCols()
  288. local minR = math.ceil(math.min(mapRows, mapCols) / 2) --取地图较小边的一半 防止地图过小 傻太久
  289. local range = math.min(50, minR)
  290. local getNotObstacle = function(x ,y)--在目标和周围一格找
  291. local isNotObstacle = false
  292. local t = {
  293. {x = 0, y = 0},
  294. {x = -1, y = 1},
  295. {x = 0, y = 1},
  296. {x = 1, y = 1},
  297. {x = 1, y = 0},
  298. {x = 1, y = 1},
  299. {x = 0, y = -1},
  300. {x = -1, y = -1},
  301. {x = -1, y = 0}
  302. }
  303. local _x,_y
  304. for i, v in ipairs(t) do
  305. _x = x + v.x
  306. _y = y + v.y
  307. isNotObstacle = mapData:isObstacle(_x, _y) == 0
  308. if isNotObstacle then
  309. return cc.p(_x, _y)
  310. end
  311. end
  312. return nil
  313. end
  314. -- 最多找五次
  315. local counting = 0
  316. while true do
  317. counting = counting + 1
  318. if counting >= 5 then
  319. break
  320. end
  321. -- 找一个随机位置
  322. local srcX = mainPlayer:GetMapX()
  323. local srcY = mainPlayer:GetMapY()
  324. local dstX = Random(srcX-range, srcX+range)
  325. local dstY = Random(srcY-range, srcY+range)
  326. --视野边界 减少无效随机 原X+Y > 20
  327. if math.abs(dstX-srcX) >= 7 or math.abs(dstY-srcY) >= 7 then
  328. local dstPos = getNotObstacle(dstX,dstY)
  329. if dstPos then
  330. dstX = dstPos.x
  331. dstY = dstPos.y
  332. -- auto move
  333. local mapProxy = global.Facade:retrieveProxy(global.ProxyTable.Map)
  334. local mapID = mapProxy:GetMapID()
  335. local movePos =
  336. {
  337. mapID = mapID,
  338. x = dstX,
  339. y = dstY,
  340. type = global.MMO.INPUT_MOVE_TYPE_AUTOMOVE,
  341. range = SL:GetMetaValue("GAME_DATA","AutoMoveRange_Monster")
  342. }
  343. global.Facade:sendNotification(global.NoticeTable.InputMove, movePos)
  344. self:setOfflineState(true)
  345. break
  346. end
  347. end
  348. end
  349. end
  350. self._offlineScheduleID = PerformWithDelayGlobal(callback, 0.1)
  351. local values = GET_SETTING(global.MMO.SETTING_IDX_NO_MONSTAER_USE,true)
  352. if values[1] == 1 then
  353. if self._noMonsterScheduleID then
  354. return
  355. end
  356. local num = tonumber(values[2]) or 999
  357. self._noMonsterScheduleID = PerformWithDelayGlobal(function ()
  358. local autoProxy = global.Facade:retrieveProxy(global.ProxyTable.Auto)
  359. if not autoProxy:IsAFKState() then--不处于挂机状态 取消定时器
  360. self:resetNoMonsterSchedule()
  361. return false
  362. end
  363. local autoUseItem = function(items)
  364. local proxyUtils = requireProxy( "proxyUtils" )
  365. local ItemUseProxy = global.Facade:retrieveProxy(global.ProxyTable.ItemUseProxy)
  366. for _, itemIndex in ipairs(items) do
  367. local unpack = proxyUtils.unpackDrugByIndex(itemIndex)
  368. if unpack then
  369. return true
  370. end
  371. local item = proxyUtils.findItemByIndex(itemIndex)
  372. if item then
  373. ItemUseProxy:UseItem(item)
  374. return true
  375. end
  376. end
  377. return false
  378. end
  379. local index = tonumber(values[3])
  380. if index then
  381. autoUseItem({index})
  382. end
  383. self:resetNoMonsterSchedule()
  384. end, num)
  385. end
  386. return true
  387. end
  388. function AssistProxy:resetNoMonsterSchedule()
  389. if self._noMonsterScheduleID then
  390. UnSchedule(self._noMonsterScheduleID)
  391. self._noMonsterScheduleID = nil
  392. end
  393. end
  394. -------------------------------------------------
  395. -------------------------------------------------
  396. -- 向服务器找怪
  397. function AssistProxy:findMapMonster()
  398. self:RequestFindMapMonster()
  399. end
  400. function AssistProxy:isFindMapMonster()
  401. return self._isFindMapMonster
  402. end
  403. function AssistProxy:resetFindMapMonster()
  404. self._isFindMapMonsterFail = false
  405. self._isFindMapMonster = false
  406. end
  407. function AssistProxy:dirtyFindMapMonster()
  408. self._isFindMapMonster = true
  409. end
  410. function AssistProxy:isFindMapMonsterFail()
  411. return self._isFindMapMonsterFail
  412. end
  413. function AssistProxy:isRequestMonsterFlag()
  414. return self._requestMonsterFlag
  415. end
  416. -------------------------------------------------
  417. -- 自动找怪
  418. function AssistProxy:RequestFindMapMonster()
  419. LuaSendMsg(global.MsgType.MSG_CS_FIND_MAP_MONSTER)
  420. self._requestMonsterFlag = true
  421. self._isFindMapMonsterFail = false
  422. --
  423. if self._findMapTargetScheduleID then
  424. UnSchedule(self._findMapTargetScheduleID)
  425. self._findMapTargetScheduleID = nil
  426. end
  427. self._findMapTargetScheduleID = PerformWithDelayGlobal(function()
  428. self._requestMonsterFlag = false
  429. self:resetFindMapMonster()
  430. end, 2)
  431. print("+++++++++++++++++++++++++++++ find map target")
  432. end
  433. function AssistProxy:handle_MSG_SC_FIND_MAP_MONSTER(msg)
  434. local header = msg:GetHeader()
  435. local x = header.recog
  436. local y = header.param1
  437. dump(header)
  438. if x == 0 and y == 0 then
  439. self._requestMonsterFlag = false
  440. self._isFindMapMonsterFail = true
  441. return false
  442. end
  443. self._requestMonsterFlag = false
  444. self._isFindMapMonsterFail = false
  445. -- auto move
  446. local mapProxy = global.Facade:retrieveProxy(global.ProxyTable.Map)
  447. local mapID = mapProxy:GetMapID()
  448. local movePos =
  449. {
  450. mapID = mapID,
  451. x = x,
  452. y = y,
  453. type = global.MMO.INPUT_MOVE_TYPE_AUTOMOVE,
  454. range = SL:GetMetaValue("GAME_DATA","AutoMoveRange_Monster")
  455. }
  456. global.Facade:sendNotification(global.NoticeTable.InputMove, movePos)
  457. self:dirtyFindMapMonster()
  458. end
  459. function AssistProxy:RegisterMsgHandler()
  460. AssistProxy.super.RegisterMsgHandler(self)
  461. local msgType = global.MsgType
  462. LuaRegisterMsgHandler(msgType.MSG_SC_FIND_MAP_MONSTER, handler(self, self.handle_MSG_SC_FIND_MAP_MONSTER)) -- 全图找怪
  463. end
  464. return AssistProxy