源战役客户端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

411 lines
15 KiB

  1. require("game.autoFight.AutoFightManager")
  2. require("game.autoFight.AutoFightTips")
  3. require("game.autoFight.BufferTipsItem")
  4. AutoFightController = AutoFightController or BaseClass(BaseController)
  5. AutoFightController.AutoStateType = {
  6. AUTO_FIGHT = 1,
  7. AUTO_FINDWAY = 2,
  8. NONE = 0,
  9. }
  10. function AutoFightController:__init()
  11. AutoFightController.Instance = self
  12. self.ask_automf_view = nil
  13. self.auto_state_tip_view = nil --在屏幕中间显示“正在挂机”和正在寻路的图片
  14. self:AddAllEvents()
  15. self.model = AutoFightManager:getInstance()
  16. self.model.auto_state = AutoFightController.AutoStateType.NONE
  17. self.show_alert_wait_time = 40
  18. self.last_show_alert_time = 0
  19. self.fly_data = {}
  20. end
  21. function AutoFightController:getInstance()
  22. if AutoFightController.Instance == nil then
  23. AutoFightController.New()
  24. end
  25. return AutoFightController.Instance
  26. end
  27. function AutoFightController:__delete()
  28. end
  29. function AutoFightController:AddAllEvents()
  30. local function findway_ended_func()
  31. self.model:SetAutoFindWayState(false)
  32. end
  33. local function findway_started_func()
  34. --发起寻路要取消自动战斗
  35. GlobalEventSystem:Fire(EventName.STOPAUTOFIGHT)
  36. self.model:SetAutoFindWayState(true)
  37. end
  38. GlobalEventSystem:Bind(EventName.FINDWAY_ENDED, findway_ended_func)
  39. GlobalEventSystem:Bind(EventName.FINDWAY_STARTED, findway_started_func)
  40. local function game_start_func()
  41. self.model.game_running = true
  42. end
  43. local function game_stoped()
  44. self.model.game_running = false
  45. end
  46. GlobalEventSystem:Bind(EventName.GAME_START, game_start_func)
  47. GlobalEventSystem:Bind(EventName.GAME_SERVER_DISCONNECTED, game_stoped)
  48. local function open_tips_view()
  49. self:OpenAutoFightTipsView()
  50. end
  51. GlobalEventSystem:Bind(EventName.OPEN_FIGHT_TIPS_VIEW, open_tips_view)
  52. local function close_tips_view()
  53. if self.autoFightTips and self.autoFightTips:HasOpen() then
  54. self.autoFightTips:Close()
  55. end
  56. end
  57. GlobalEventSystem:Bind(EventName.CLOSE_FIGHT_TIPS_VIEW, close_tips_view)
  58. --监听玩家摇杆和键盘操作
  59. local function joy_stick_dragend()
  60. if Scene.Instance.main_role and self.model.auto_fight_state then
  61. self.model:CacheAutoFightPos()
  62. self.model:CacheGoToPos()
  63. findway_ended_func()
  64. end
  65. end
  66. GlobalEventSystem:Bind(UIJoyStick.EVENT_TOUCH_END, joy_stick_dragend)
  67. local function onSceneStart() --切换地图后,新地图的初始位置为新的挂机点
  68. if self.model:GetAutoFightState() then
  69. self.model:CacheAutoFightPos()
  70. end
  71. end
  72. GlobalEventSystem:Bind(SceneManager.START,onSceneStart)
  73. local function onSceneStart2() --切换地图后,新地图的初始位置为新的挂机点
  74. if self.model:GetAutoFightState() then
  75. self.model:CacheAutoFightPos()
  76. end
  77. local main_role = Scene.Instance:GetMainRole()
  78. if not main_role then
  79. return
  80. end
  81. if SceneManager.Instance:IsDungeonScene() then
  82. self.model.next_fly_pos = main_role.real_pos
  83. if SceneManager.Instance:IsGuildGuardDungeon() then
  84. self.fly_data.callback = function()
  85. GlobalEventSystem:Fire(EventName.STARTAUTOFIGHT)
  86. end
  87. else
  88. self.fly_data.callback = function()
  89. if BaseDungeonModel:getInstance().wait_load_find_way_fun then
  90. local main_role = Scene.Instance:GetMainRole()
  91. main_role.is_shoe_flying = false
  92. BaseDungeonModel:getInstance().wait_load_find_way_fun()
  93. BaseDungeonModel:getInstance().wait_load_find_way_fun = nil
  94. end
  95. --GlobalEventSystem:Fire(EventName.STARTAUTOFIGHT, false, true)
  96. end
  97. end
  98. elseif SceneManager.Instance:IsDungeonScene(SceneManager.Instance:GetLastSceneId()) then
  99. self.model.next_fly_pos = main_role.real_pos
  100. self.fly_data.callback = nil
  101. else
  102. self.model.next_fly_pos = main_role.real_pos
  103. -- self.fly_data.callback = nil
  104. end
  105. --要先把坐骑下了
  106. if self.model.next_fly_pos then
  107. if self.model.next_fly_pos.x == 0 and self.model.next_fly_pos.y == 0 then
  108. self.model.next_fly_pos.x = main_role.vo.pos_x
  109. self.model.next_fly_pos.y = main_role.vo.pos_y
  110. end
  111. -- --main_role:SetModelHideFlag(SceneObj.ModelHideFlag.Fly, false)
  112. print("-+-------场景开始,fly down-------:", SceneManager:getInstance():IsBlockXY(self.model.next_fly_pos.x / SceneObj.LogicRealRatio.x, self.model.next_fly_pos.y / SceneObj.LogicRealRatio.y), self.model.next_fly_pos.x / SceneObj.LogicRealRatio.x, self.model.next_fly_pos.y / SceneObj.LogicRealRatio.y)
  113. if SceneManager:getInstance():IsBlockXY(self.model.next_fly_pos.x / SceneObj.LogicRealRatio.x, self.model.next_fly_pos.y / SceneObj.LogicRealRatio.y) then
  114. local sceneInfo = SceneManager:getInstance():GetSceneInfo()
  115. if sceneInfo and sceneInfo.x and sceneInfo.y then
  116. self.model.next_fly_pos.x, self.model.next_fly_pos.y = SourceOperateMove.FindNearestPos(co.TableXY(self.model.next_fly_pos.x, self.model.next_fly_pos.y), co.TableXY(tonumber(sceneInfo.x), tonumber(sceneInfo.y)))
  117. end
  118. end
  119. --判断是无缝切换则直接触发
  120. if SceneManager.Instance:NoLoadingViewScene() then
  121. --服务端限制了不能连续触发2次,在12002后修正位置就行了
  122. -- main_role:SetRealPos(self.model.next_fly_pos.x, self.model.next_fly_pos.y, true)
  123. -- GlobalEventSystem:Fire(SceneEventType.MOVEREQUEST, self.model.next_fly_pos.x, self.model.next_fly_pos.y, MOVE_TYPE.BLINK)
  124. -- if self.fly_data.callback then
  125. -- self.fly_data.callback()
  126. -- self.fly_data.callback = nil
  127. -- end
  128. else
  129. --新手进入游戏要做落地表现
  130. if RoleManager and RoleManager.Instance and RoleManager.Instance.mainRoleInfo.level == 1 then
  131. self.fly_data.callback = function()
  132. GlobalEventSystem:Fire(EventName.PLAY_ENTER_GUIDE_START_VIEW)
  133. end
  134. end
  135. local need_delay = false
  136. local delay_time = nil
  137. local playerLv = RoleManager:getInstance():GetMainRoleVo().level
  138. if playerLv <= 120 and SceneManager.Instance:IsMission() then
  139. delay_time = 0.2
  140. need_delay = true
  141. end
  142. --通过传送门切场景
  143. -- if self.model.is_transfer_out then
  144. -- self.model.is_transfer_out = false
  145. -- if need_delay then
  146. -- setTimeout(function ()
  147. -- local main_role = Scene.Instance:GetMainRole()
  148. -- if not main_role then
  149. -- return
  150. -- end
  151. -- self.model:SetChangeSceneFlyTime(Status.NowTime)
  152. -- main_role:DoTransfer(self.model.next_fly_pos, 1,self.fly_data.callback)
  153. -- end,delay_time)
  154. -- else
  155. -- self.model:SetChangeSceneFlyTime(Status.NowTime)
  156. -- main_role:DoTransfer(self.model.next_fly_pos, 1,self.fly_data.callback)
  157. -- end
  158. -- else
  159. if need_delay then
  160. main_role:SetModelHideFlag(SceneObj.ModelHideFlag.ServerHide, true)
  161. setTimeout(function ()
  162. local main_role = Scene.Instance:GetMainRole()
  163. if not main_role then
  164. return
  165. end
  166. self.model:SetChangeSceneFlyTime(Status.NowTime)
  167. main_role:SetModelHideFlag(SceneObj.ModelHideFlag.ServerHide, false)
  168. main_role:DoFlyShoeEffect(self.model.next_fly_pos, 1,self.fly_data.callback)
  169. end,delay_time)
  170. else
  171. self.model:SetChangeSceneFlyTime(Status.NowTime)
  172. main_role:DoFlyShoeEffect(self.model.next_fly_pos, 1,self.fly_data.callback)
  173. end
  174. -- end
  175. end
  176. self.model.next_fly_pos = nil
  177. end
  178. end
  179. GlobalEventSystem:Bind(EventName.SCENE_LOAD_VIEW_COMPLETE,onSceneStart2)
  180. local function click_fly_shoe()
  181. if not AutoFightManager:getInstance().fly_shoe_data then
  182. return
  183. end
  184. local fly_data = AutoFightManager:getInstance().fly_shoe_data
  185. -- PrintTable(fly_data)
  186. GlobalEventSystem:Fire(EventName.USE_FLY_SHOE,fly_data.scene_id,fly_data.x,fly_data.y,fly_data.callback)
  187. end
  188. GlobalEventSystem:Bind(EventName.CLICK_FLY_SHOE_BTN, click_fly_shoe)
  189. local function use_fly_shoe(scene_id,x,y,callback,is_free,not_check_door,is_task, auto_find)
  190. self:FlyToPos(scene_id, x, y,callback,is_free,not_check_door,is_task, auto_find)
  191. end
  192. GlobalEventSystem:Bind(EventName.USE_FLY_SHOE,use_fly_shoe)
  193. local success_return = function ()
  194. self:MainRoleFly()
  195. end
  196. GlobalEventSystem:Bind(SceneEventType.REQUEST_USE_FLY_SHOE_RETURN, success_return)
  197. end
  198. --自动挂机时间,经验状态tips
  199. function AutoFightController:OpenAutoFightTipsView()
  200. if self.autoFightTips == nil then
  201. self.autoFightTips = AutoFightTips.New()
  202. end
  203. self.autoFightTips:Open()
  204. end
  205. --飞鞋请求
  206. --is_free 是否免费使用飞鞋(某些玩法可以免费飞)
  207. function AutoFightController:FlyToPos(scene_id,x,y,callback,is_free,not_check_door,is_task, auto_find)
  208. local main_role = Scene.Instance:GetMainRole()
  209. if not main_role then
  210. return
  211. end
  212. local vo = {}
  213. vo.scene_id = scene_id
  214. if MapModel:getInstance():CanEnterScene(vo) == false then
  215. Message.show("场景暂未开放")
  216. return
  217. end
  218. if main_role:IsInState(PoseState.FLY_SHOE) then
  219. Message.show("使用飞鞋中")
  220. return
  221. end
  222. if not SceneManager:getInstance():IsCanUseFlyShoeScene() then
  223. Message.show("非主城和野外安全区,不能使用飞鞋")
  224. return
  225. end
  226. if main_role then
  227. local main_role_buff = main_role.buff_manager
  228. if main_role_buff:HasBuffControl() then
  229. Message.show("当前状态不能传送")
  230. return
  231. end
  232. end
  233. --三秒都没返回 才可以重新请求
  234. if Status.NowTime - self.model.fly_require_time < 0.5 and not is_free then
  235. Message.show("飞鞋使用太频繁,请稍后再试")
  236. return
  237. end
  238. if not not_check_door then
  239. local door = Scene.Instance:GetExitByPoint(Scene.Instance:GetMainRole():GetLogicPos())
  240. if door then
  241. Message.show("已经在传送点附近")
  242. return
  243. end
  244. end
  245. self.fly_data.scene_id = scene_id
  246. self.fly_data.x = x
  247. self.fly_data.y = y
  248. self.fly_data.callback = callback
  249. --如果数免费,就直接过去,不走后面的小飞鞋判断
  250. if is_free then
  251. self:MainRoleFly(is_task, is_free, auto_find)
  252. return
  253. end
  254. local main_role_info = RoleManager.Instance.mainRoleInfo
  255. local number = GoodsModel.Instance:GetTypeGoodsNum(AutoFightManager.FlyGoodsID)
  256. if number <= 0 and (not VipModel:getInstance():CanFreeUseShoe()) then
  257. Message.show("小飞鞋不足,成为特权可免费传送哦!")
  258. return
  259. end
  260. -- GlobalEventSystem:Fire(SceneEventType.USE_FLY_SHOE)
  261. -- GlobalEventSystem:Fire(SceneEventType.USE_FLY_SHOE,scene_id,x,y)
  262. print("tanar: AutoFightController [285] =========== REQUEST_USE_FLY_SHOE", scene_id,x,y)
  263. GlobalEventSystem:Fire(SceneEventType.REQUEST_USE_FLY_SHOE, scene_id,x,y)
  264. -- GlobalEventSystem:Fire(SceneEventType.REQUEST_USE_FLY_SHOE_RETURN)
  265. end
  266. function AutoFightController:MainRoleFly(is_task, is_free, auto_find)
  267. if SceneManager:getInstance():IsRefineDungeon() then
  268. return
  269. end
  270. if not auto_find then
  271. OperateManager.Instance:StopMove(true)
  272. GlobalEventSystem:Fire(EventName.FINDWAY_ENDED)
  273. GlobalEventSystem:Fire(EventName.CLOSE_MAPPANEL_VIEW)
  274. end
  275. -- GlobalEventSystem:Fire(EventName.CLOSE_WORLD_MAP_VIEW)
  276. --开始飞 需要关掉的界面侦听该事件
  277. -- GlobalEventSystem:Fire(EventName.SHOE_START_FLY)
  278. self.model.fly_require_time = Status.NowTime
  279. local scene_id = SceneManager.Instance:GetSceneId()
  280. local main_role = Scene.Instance:GetMainRole()
  281. if main_role:IsInState(PoseState.FLY_SHOE_EFFECT) then
  282. return
  283. end
  284. if not self.fly_data or not self.fly_data.x or not self.fly_data.y then
  285. return
  286. end
  287. local pos = co.Vector2(self.fly_data.x, self.fly_data.y)
  288. local distance = GameMath.GetDistance(pos.x, pos.y, main_role.real_pos.x, main_role.real_pos.y, true)
  289. print('Ych:AutoFightController.lua[382] data', distance)
  290. self.model.next_fly_pos = nil
  291. self.model.is_flying_shoe = true
  292. if self.fly_data.scene_id == scene_id then
  293. local start_height = Scene.Instance:GetZoneHeight(main_role.real_pos.x / SceneObj.LogicRealRatio.x,main_role.real_pos.y / SceneObj.LogicRealRatio.y) --起跳点的高度
  294. local end_height = Scene.Instance:GetZoneHeight(pos.x / SceneObj.LogicRealRatio.x, pos.y / SceneObj.LogicRealRatio.y) --落地点的高度
  295. if distance > FLY_SHOE_DISTANCE.ThreeJumpDistance or (end_height - start_height) > 5 or (start_height - end_height ) > 5 then
  296. -------------------------
  297. --请注意SceneController.lua的SceneEventType.REQUEST_USE_FLY_SHOE事件绑定里面有同样的条件判断
  298. --改这里注意顺便改SceneController.lua
  299. -------------------------
  300. self.last_fly_pos = pos
  301. local second_callback = function( ... )
  302. if pos.x == self.last_fly_pos.x and pos.y == self.last_fly_pos.y then
  303. if self.fly_data.callback then
  304. self.fly_data.callback()
  305. end
  306. local main_role = Scene.Instance:GetMainRole()
  307. if main_role and main_role.need_dead_after_fly_shoe then
  308. setTimeout(function ()
  309. local main_role = Scene.Instance:GetMainRole()
  310. if main_role then
  311. main_role.need_dead_after_fly_shoe = false
  312. --这里需要重置下is_dead 因为之前可能变为true 导致进不去死亡状态
  313. main_role.is_dead = false
  314. main_role:ForceDoDead()
  315. end
  316. end,0.1)
  317. end
  318. if TaskModel:getInstance().fly_end_need_task then
  319. TaskModel:getInstance().fly_end_need_task = nil
  320. GlobalEventSystem:Fire(EventName.FORCE_TO_DO_TASK, true)
  321. end
  322. end
  323. end
  324. local first_callback = function()
  325. main_role:DoFlyShoeEffect(pos, 1, second_callback)
  326. setTimeout(function ()
  327. local main_role = Scene.Instance:GetMainRole()
  328. if main_role then
  329. local x,y = main_role:GetRealPos()
  330. main_role:SetFollowObjShowState(true,SceneObj.ModelHideFlag.IndependentHide)
  331. end
  332. end,0.5)
  333. end
  334. main_role:SetFollowObjShowState(false,SceneObj.ModelHideFlag.IndependentHide)
  335. main_role:DoFlyShoeEffect(pos, 2, first_callback)
  336. else
  337. if distance < FLY_SHOE_DISTANCE.NormalMoveDistance then
  338. local findVo = FindVo.New()
  339. findVo.type = FindVo.POINT
  340. findVo.sceneId = self.fly_data.scene_id
  341. findVo.x = self.fly_data.x/ SceneObj.LogicRealRatio.x
  342. findVo.y = self.fly_data.y/ SceneObj.LogicRealRatio.y
  343. findVo.call_back = self.fly_data.callback
  344. GlobalEventSystem:Fire(EventName.FIND, findVo)
  345. else
  346. GlobalEventSystem:Fire(SceneEventType.TASK_MUL_JUMP, pos, self.fly_data.callback, nil, nil, true)
  347. end
  348. end
  349. else
  350. --传送类型(0服务端传送 1使用小飞鞋(包括免费)2场景出生点(不走传送门坐标) 3任务小飞鞋完全免费)
  351. local scene_id = self.fly_data.scene_id
  352. if scene_id ~= 0 then
  353. if is_free then
  354. --飞鞋类型3:完全免费
  355. SceneController.Instance:requestChangeScene(scene_id, 0, 3, pos.x, pos.y)
  356. self.model.next_fly_pos = pos
  357. return
  358. end
  359. if is_task then
  360. --飞鞋类型3:完全免费
  361. SceneController.Instance:requestChangeScene(scene_id, 0, 3, pos.x, pos.y)
  362. else
  363. SceneController.Instance:requestChangeScene(scene_id, 0, 1, pos.x, pos.y)
  364. end
  365. self.model.next_fly_pos = pos
  366. end
  367. end
  368. end
  369. function AutoFightController:GetFlyData( )
  370. return self.fly_data
  371. end