|
|
- require("game.autoFight.AutoFightManager")
- require("game.autoFight.AutoFightTips")
- require("game.autoFight.BufferTipsItem")
-
- AutoFightController = AutoFightController or BaseClass(BaseController)
- AutoFightController.AutoStateType = {
- AUTO_FIGHT = 1,
- AUTO_FINDWAY = 2,
- NONE = 0,
- }
-
- function AutoFightController:__init()
- AutoFightController.Instance = self
- self.ask_automf_view = nil
- self.auto_state_tip_view = nil --在屏幕中间显示“正在挂机”和正在寻路的图片
- self:AddAllEvents()
- self.model = AutoFightManager:getInstance()
- self.model.auto_state = AutoFightController.AutoStateType.NONE
- self.show_alert_wait_time = 40
- self.last_show_alert_time = 0
- self.fly_data = {}
- end
-
- function AutoFightController:getInstance()
- if AutoFightController.Instance == nil then
- AutoFightController.New()
- end
- return AutoFightController.Instance
- end
-
- function AutoFightController:__delete()
- end
-
- function AutoFightController:AddAllEvents()
- local function findway_ended_func()
- self.model:SetAutoFindWayState(false)
- end
- local function findway_started_func()
- --发起寻路要取消自动战斗
- GlobalEventSystem:Fire(EventName.STOPAUTOFIGHT)
- self.model:SetAutoFindWayState(true)
- end
-
- GlobalEventSystem:Bind(EventName.FINDWAY_ENDED, findway_ended_func)
- GlobalEventSystem:Bind(EventName.FINDWAY_STARTED, findway_started_func)
-
- local function game_start_func()
- self.model.game_running = true
- end
- local function game_stoped()
- self.model.game_running = false
- end
- GlobalEventSystem:Bind(EventName.GAME_START, game_start_func)
- GlobalEventSystem:Bind(EventName.GAME_SERVER_DISCONNECTED, game_stoped)
-
- local function open_tips_view()
- self:OpenAutoFightTipsView()
- end
- GlobalEventSystem:Bind(EventName.OPEN_FIGHT_TIPS_VIEW, open_tips_view)
-
- local function close_tips_view()
- if self.autoFightTips and self.autoFightTips:HasOpen() then
- self.autoFightTips:Close()
- end
- end
- GlobalEventSystem:Bind(EventName.CLOSE_FIGHT_TIPS_VIEW, close_tips_view)
-
- --监听玩家摇杆和键盘操作
- local function joy_stick_dragend()
- if Scene.Instance.main_role and self.model.auto_fight_state then
- self.model:CacheAutoFightPos()
- self.model:CacheGoToPos()
- findway_ended_func()
- end
- end
- GlobalEventSystem:Bind(UIJoyStick.EVENT_TOUCH_END, joy_stick_dragend)
-
-
- local function onSceneStart() --切换地图后,新地图的初始位置为新的挂机点
- if self.model:GetAutoFightState() then
- self.model:CacheAutoFightPos()
- end
- end
- GlobalEventSystem:Bind(SceneManager.START,onSceneStart)
-
- local function onSceneStart2() --切换地图后,新地图的初始位置为新的挂机点
- if self.model:GetAutoFightState() then
- self.model:CacheAutoFightPos()
- end
- local main_role = Scene.Instance:GetMainRole()
- if not main_role then
- return
- end
- if SceneManager.Instance:IsDungeonScene() then
- self.model.next_fly_pos = main_role.real_pos
- if SceneManager.Instance:IsGuildGuardDungeon() then
- self.fly_data.callback = function()
- GlobalEventSystem:Fire(EventName.STARTAUTOFIGHT)
- end
- else
- self.fly_data.callback = function()
- if BaseDungeonModel:getInstance().wait_load_find_way_fun then
- local main_role = Scene.Instance:GetMainRole()
- main_role.is_shoe_flying = false
- BaseDungeonModel:getInstance().wait_load_find_way_fun()
- BaseDungeonModel:getInstance().wait_load_find_way_fun = nil
- end
- --GlobalEventSystem:Fire(EventName.STARTAUTOFIGHT, false, true)
- end
- end
- elseif SceneManager.Instance:IsDungeonScene(SceneManager.Instance:GetLastSceneId()) then
- self.model.next_fly_pos = main_role.real_pos
- self.fly_data.callback = nil
- else
- self.model.next_fly_pos = main_role.real_pos
- -- self.fly_data.callback = nil
- end
- --要先把坐骑下了
- if self.model.next_fly_pos then
- if self.model.next_fly_pos.x == 0 and self.model.next_fly_pos.y == 0 then
- self.model.next_fly_pos.x = main_role.vo.pos_x
- self.model.next_fly_pos.y = main_role.vo.pos_y
- end
- -- --main_role:SetModelHideFlag(SceneObj.ModelHideFlag.Fly, false)
- 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)
- if SceneManager:getInstance():IsBlockXY(self.model.next_fly_pos.x / SceneObj.LogicRealRatio.x, self.model.next_fly_pos.y / SceneObj.LogicRealRatio.y) then
- local sceneInfo = SceneManager:getInstance():GetSceneInfo()
- if sceneInfo and sceneInfo.x and sceneInfo.y then
- 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)))
- end
- end
-
- --判断是无缝切换则直接触发
- if SceneManager.Instance:NoLoadingViewScene() then
- --服务端限制了不能连续触发2次,在12002后修正位置就行了
- -- main_role:SetRealPos(self.model.next_fly_pos.x, self.model.next_fly_pos.y, true)
- -- GlobalEventSystem:Fire(SceneEventType.MOVEREQUEST, self.model.next_fly_pos.x, self.model.next_fly_pos.y, MOVE_TYPE.BLINK)
- -- if self.fly_data.callback then
- -- self.fly_data.callback()
- -- self.fly_data.callback = nil
- -- end
- else
-
- --新手进入游戏要做落地表现
- if RoleManager and RoleManager.Instance and RoleManager.Instance.mainRoleInfo.level == 1 then
- self.fly_data.callback = function()
- GlobalEventSystem:Fire(EventName.PLAY_ENTER_GUIDE_START_VIEW)
- end
- end
-
- local need_delay = false
- local delay_time = nil
- local playerLv = RoleManager:getInstance():GetMainRoleVo().level
- if playerLv <= 120 and SceneManager.Instance:IsMission() then
- delay_time = 0.2
- need_delay = true
- end
-
- --通过传送门切场景
- -- if self.model.is_transfer_out then
- -- self.model.is_transfer_out = false
- -- if need_delay then
- -- setTimeout(function ()
- -- local main_role = Scene.Instance:GetMainRole()
- -- if not main_role then
- -- return
- -- end
- -- self.model:SetChangeSceneFlyTime(Status.NowTime)
- -- main_role:DoTransfer(self.model.next_fly_pos, 1,self.fly_data.callback)
- -- end,delay_time)
- -- else
- -- self.model:SetChangeSceneFlyTime(Status.NowTime)
- -- main_role:DoTransfer(self.model.next_fly_pos, 1,self.fly_data.callback)
- -- end
- -- else
- if need_delay then
- main_role:SetModelHideFlag(SceneObj.ModelHideFlag.ServerHide, true)
- setTimeout(function ()
- local main_role = Scene.Instance:GetMainRole()
- if not main_role then
- return
- end
- self.model:SetChangeSceneFlyTime(Status.NowTime)
- main_role:SetModelHideFlag(SceneObj.ModelHideFlag.ServerHide, false)
- main_role:DoFlyShoeEffect(self.model.next_fly_pos, 1,self.fly_data.callback)
- end,delay_time)
- else
- self.model:SetChangeSceneFlyTime(Status.NowTime)
- main_role:DoFlyShoeEffect(self.model.next_fly_pos, 1,self.fly_data.callback)
- end
- -- end
- end
- self.model.next_fly_pos = nil
- end
- end
- GlobalEventSystem:Bind(EventName.SCENE_LOAD_VIEW_COMPLETE,onSceneStart2)
-
- local function click_fly_shoe()
- if not AutoFightManager:getInstance().fly_shoe_data then
- return
- end
- local fly_data = AutoFightManager:getInstance().fly_shoe_data
- -- PrintTable(fly_data)
- GlobalEventSystem:Fire(EventName.USE_FLY_SHOE,fly_data.scene_id,fly_data.x,fly_data.y,fly_data.callback)
- end
- GlobalEventSystem:Bind(EventName.CLICK_FLY_SHOE_BTN, click_fly_shoe)
-
- local function use_fly_shoe(scene_id,x,y,callback,is_free,not_check_door,is_task, auto_find)
- self:FlyToPos(scene_id, x, y,callback,is_free,not_check_door,is_task, auto_find)
- end
- GlobalEventSystem:Bind(EventName.USE_FLY_SHOE,use_fly_shoe)
-
- local success_return = function ()
- self:MainRoleFly()
- end
- GlobalEventSystem:Bind(SceneEventType.REQUEST_USE_FLY_SHOE_RETURN, success_return)
- end
-
-
- --自动挂机时间,经验状态tips
- function AutoFightController:OpenAutoFightTipsView()
- if self.autoFightTips == nil then
- self.autoFightTips = AutoFightTips.New()
- end
- self.autoFightTips:Open()
- end
-
- --飞鞋请求
- --is_free 是否免费使用飞鞋(某些玩法可以免费飞)
- function AutoFightController:FlyToPos(scene_id,x,y,callback,is_free,not_check_door,is_task, auto_find)
- local main_role = Scene.Instance:GetMainRole()
- if not main_role then
- return
- end
- local vo = {}
- vo.scene_id = scene_id
- if MapModel:getInstance():CanEnterScene(vo) == false then
- Message.show("场景暂未开放")
- return
- end
- if main_role:IsInState(PoseState.FLY_SHOE) then
- Message.show("使用飞鞋中")
- return
- end
- if not SceneManager:getInstance():IsCanUseFlyShoeScene() then
- Message.show("非主城和野外安全区,不能使用飞鞋")
- return
- end
-
- if main_role then
- local main_role_buff = main_role.buff_manager
- if main_role_buff:HasBuffControl() then
- Message.show("当前状态不能传送")
- return
- end
- end
-
- --三秒都没返回 才可以重新请求
- if Status.NowTime - self.model.fly_require_time < 0.5 and not is_free then
- Message.show("飞鞋使用太频繁,请稍后再试")
- return
- end
- if not not_check_door then
- local door = Scene.Instance:GetExitByPoint(Scene.Instance:GetMainRole():GetLogicPos())
- if door then
- Message.show("已经在传送点附近")
- return
- end
- end
-
- self.fly_data.scene_id = scene_id
- self.fly_data.x = x
- self.fly_data.y = y
- self.fly_data.callback = callback
-
- --如果数免费,就直接过去,不走后面的小飞鞋判断
- if is_free then
- self:MainRoleFly(is_task, is_free, auto_find)
- return
- end
- local main_role_info = RoleManager.Instance.mainRoleInfo
- local number = GoodsModel.Instance:GetTypeGoodsNum(AutoFightManager.FlyGoodsID)
-
- if number <= 0 and (not VipModel:getInstance():CanFreeUseShoe()) then
- Message.show("小飞鞋不足,成为特权可免费传送哦!")
- return
- end
- -- GlobalEventSystem:Fire(SceneEventType.USE_FLY_SHOE)
- -- GlobalEventSystem:Fire(SceneEventType.USE_FLY_SHOE,scene_id,x,y)
- print("tanar: AutoFightController [285] =========== REQUEST_USE_FLY_SHOE", scene_id,x,y)
- GlobalEventSystem:Fire(SceneEventType.REQUEST_USE_FLY_SHOE, scene_id,x,y)
- -- GlobalEventSystem:Fire(SceneEventType.REQUEST_USE_FLY_SHOE_RETURN)
-
- end
-
- function AutoFightController:MainRoleFly(is_task, is_free, auto_find)
- if SceneManager:getInstance():IsRefineDungeon() then
- return
- end
- if not auto_find then
- OperateManager.Instance:StopMove(true)
- GlobalEventSystem:Fire(EventName.FINDWAY_ENDED)
- GlobalEventSystem:Fire(EventName.CLOSE_MAPPANEL_VIEW)
- end
- -- GlobalEventSystem:Fire(EventName.CLOSE_WORLD_MAP_VIEW)
- --开始飞 需要关掉的界面侦听该事件
- -- GlobalEventSystem:Fire(EventName.SHOE_START_FLY)
- self.model.fly_require_time = Status.NowTime
- local scene_id = SceneManager.Instance:GetSceneId()
- local main_role = Scene.Instance:GetMainRole()
- if main_role:IsInState(PoseState.FLY_SHOE_EFFECT) then
- return
- end
-
- if not self.fly_data or not self.fly_data.x or not self.fly_data.y then
- return
- end
-
- local pos = co.Vector2(self.fly_data.x, self.fly_data.y)
-
- local distance = GameMath.GetDistance(pos.x, pos.y, main_role.real_pos.x, main_role.real_pos.y, true)
- print('Ych:AutoFightController.lua[382] data', distance)
- self.model.next_fly_pos = nil
- self.model.is_flying_shoe = true
-
- if self.fly_data.scene_id == scene_id then
- local start_height = Scene.Instance:GetZoneHeight(main_role.real_pos.x / SceneObj.LogicRealRatio.x,main_role.real_pos.y / SceneObj.LogicRealRatio.y) --起跳点的高度
- local end_height = Scene.Instance:GetZoneHeight(pos.x / SceneObj.LogicRealRatio.x, pos.y / SceneObj.LogicRealRatio.y) --落地点的高度
- if distance > FLY_SHOE_DISTANCE.ThreeJumpDistance or (end_height - start_height) > 5 or (start_height - end_height ) > 5 then
- -------------------------
- --请注意SceneController.lua的SceneEventType.REQUEST_USE_FLY_SHOE事件绑定里面有同样的条件判断
- --改这里注意顺便改SceneController.lua
- -------------------------
- self.last_fly_pos = pos
-
- local second_callback = function( ... )
- if pos.x == self.last_fly_pos.x and pos.y == self.last_fly_pos.y then
- if self.fly_data.callback then
- self.fly_data.callback()
- end
- local main_role = Scene.Instance:GetMainRole()
- if main_role and main_role.need_dead_after_fly_shoe then
- setTimeout(function ()
- local main_role = Scene.Instance:GetMainRole()
- if main_role then
- main_role.need_dead_after_fly_shoe = false
- --这里需要重置下is_dead 因为之前可能变为true 导致进不去死亡状态
- main_role.is_dead = false
- main_role:ForceDoDead()
- end
- end,0.1)
- end
- if TaskModel:getInstance().fly_end_need_task then
- TaskModel:getInstance().fly_end_need_task = nil
- GlobalEventSystem:Fire(EventName.FORCE_TO_DO_TASK, true)
- end
- end
- end
-
- local first_callback = function()
- main_role:DoFlyShoeEffect(pos, 1, second_callback)
- setTimeout(function ()
- local main_role = Scene.Instance:GetMainRole()
- if main_role then
- local x,y = main_role:GetRealPos()
- main_role:SetFollowObjShowState(true,SceneObj.ModelHideFlag.IndependentHide)
- end
- end,0.5)
- end
- main_role:SetFollowObjShowState(false,SceneObj.ModelHideFlag.IndependentHide)
- main_role:DoFlyShoeEffect(pos, 2, first_callback)
-
- else
- if distance < FLY_SHOE_DISTANCE.NormalMoveDistance then
- local findVo = FindVo.New()
- findVo.type = FindVo.POINT
- findVo.sceneId = self.fly_data.scene_id
- findVo.x = self.fly_data.x/ SceneObj.LogicRealRatio.x
- findVo.y = self.fly_data.y/ SceneObj.LogicRealRatio.y
- findVo.call_back = self.fly_data.callback
- GlobalEventSystem:Fire(EventName.FIND, findVo)
- else
- GlobalEventSystem:Fire(SceneEventType.TASK_MUL_JUMP, pos, self.fly_data.callback, nil, nil, true)
- end
- end
- else
- --传送类型(0服务端传送 1使用小飞鞋(包括免费)2场景出生点(不走传送门坐标) 3任务小飞鞋完全免费)
- local scene_id = self.fly_data.scene_id
- if scene_id ~= 0 then
- if is_free then
- --飞鞋类型3:完全免费
- SceneController.Instance:requestChangeScene(scene_id, 0, 3, pos.x, pos.y)
- self.model.next_fly_pos = pos
- return
- end
-
- if is_task then
- --飞鞋类型3:完全免费
- SceneController.Instance:requestChangeScene(scene_id, 0, 3, pos.x, pos.y)
- else
- SceneController.Instance:requestChangeScene(scene_id, 0, 1, pos.x, pos.y)
- end
- self.model.next_fly_pos = pos
- end
- end
-
- end
-
- function AutoFightController:GetFlyData( )
- return self.fly_data
- end
|