AutoFightManager= AutoFightManager or BaseClass(EventDispatcher) local AutoFightManager = AutoFightManager local math_random = math.random AutoFightManager.CHANGE_AUTO_FIGHT_STATE = "CHANGE_AUTO_FIGHT_STATE" AutoFightManager.CHANGE_AUTO_FIND_WAY_STATE = "CHANGE_AUTO_FIND_WAY_STATE" AutoFightManager.UPDATE_EXPERIENCE_DATA = "UPDATE_EXPERIENCE_DATA" --更新自动挂机数据,历练经验时间 AutoFightManager.CLOSE_AUTO_FIGHT_TIP = "CLOSE_AUTO_FIGHT_TIP" --关闭挂机buff tips界面 AutoFightManager.TIME_GOODS = 240402 --时光卷轴 AutoFightManager.KAO_ROU = 230201 --神秘烤肉 AutoFightManager.FlyGoodsID = 102602 --飞鞋物品 function AutoFightManager:__init() AutoFightManager.Instance=self self.auto_fight_state = false--是否开启自动打怪 self.auto_find_way_state = false --是否在自动寻路状态,在挂机的过程中,自动寻路优先 -- 怪物列表 self.monsterList = nil self.is_temp_mode = false --是否临时手动中 self.now_auto_fight_buff = nil --挂机buff数据 self.auto_fight_cache_pos = {x = 0, y = 0} --开启自动挂机的时候记录下位置 self.not_show_buy_alert = false --不提示购买烤肉 self.game_running = false self.go_to_pos = nil --技能技能后摇没结束前的移动坐标 self.not_show_alert = false --本次登录是否不在显示开启10倍经验提醒界面 self.last_show_alert_bone_fire_id = nil --上次弹提醒界面对应的篝火id self.auto_begin_x = 0 --记录开始挂机前的坐标 self.auto_begin_y = 0 self.next_fly_pos = nil --飞鞋位置 self.fly_require_time = 0 --上次使用飞鞋时间 self.fly_shoe_data = nil --飞鞋寻路数据 self.is_flying_shoe = false -- 正在使用小飞鞋 self.change_scene_fly_time = 0 --切场景使用飞鞋的时间 self.is_transfer_out = false --是否通过传送门传送走 end function AutoFightManager:__delete() end function AutoFightManager:getInstance() if AutoFightManager.Instance==nil then AutoFightManager.New() end return AutoFightManager.Instance end function AutoFightManager:GetBeginAutoPos( ) return self.auto_begin_x, self.auto_begin_y end function AutoFightManager:SetBeginAutoPos( x, y ) self.auto_begin_x = x self.auto_begin_y = y end --设置挂机配置里面选定的怪物 function AutoFightManager:SetMonsterList(val) self.monsterList = val end --获取挂机配置的里面设定的怪物 function AutoFightManager:GetmonsterList() return self.monsterList end --自动挂机状态,开启之后停止寻路 function AutoFightManager:SetAutoFightState(value) if value ~= self.auto_fight_state then self.auto_fight_state = value GlobalEventSystem:Fire(AutoFightManager.CHANGE_AUTO_FIGHT_STATE) end end --获取是否在自动挂机的状态值 function AutoFightManager:GetAutoFightState() return self.auto_fight_state end --自动寻路状态,开启之后停止挂机 function AutoFightManager:SetAutoFindWayState(value) if self.auto_find_way_state ~= value then self.auto_find_way_state = value GlobalEventSystem:Fire(AutoFightManager.CHANGE_AUTO_FIND_WAY_STATE) end end --获取自动寻路状态值 function AutoFightManager:GetAutoFindWayState( ) return self.auto_find_way_state end --开始自动战斗 function AutoFightManager:StartAutoFight(not_save_cookies) self:SetAutoFightState(true) -- 设置自动战斗状态为true -- if not_save_cookies == nil or not_save_cookies == false then -- self:SetAutoFightStateCookie(true) -- end end -- 停止自动战斗 function AutoFightManager:StopAutoFight(not_save_cookies) self:SetAutoFightState(false) -- if not_save_cookies == nil or not_save_cookies == false then -- self:SetAutoFightStateCookie(false) -- end end --设置挂机cookie function AutoFightManager:SetAutoFightStateCookie(bool) CookieWrapper.Instance:SaveCookie(CookieLevelType.Account, CookieTimeType.TYPE_ALWAYS, CookieKey.AUTO_FIGHT_STATE, bool) end --获取挂机cookie function AutoFightManager:GetAutoFightStateCookie() return CookieWrapper.Instance:GetCookie(CookieLevelType.Account, CookieKey.AUTO_FIGHT_STATE) end --把挂机攻击优先状态保存入cookies function AutoFightManager:SetAttackFirstCookies(_unLimit, _npcFirst, _roleFirst) local list = {unLimit = _unLimit, npcFirst = _npcFirst, roleFirst = _roleFirst} CookieWrapper.Instance:SaveCookie(CookieLevelType.Account, CookieTimeType.TYPE_ALWAYS, CookieKey.AUTO_FIGHT_ATTACK_FIRST_STATE, list) end --从cookies中获取挂机攻击优先状态 function AutoFightManager:GetAttackFirstCookies() local state_list = CookieWrapper.Instance:GetCookie(CookieLevelType.Account, CookieKey.AUTO_FIGHT_ATTACK_FIRST_STATE) if state_list == nil then return false, true, false else return state_list.unLimit, state_list.npcFirst, state_list.roleFirst end end --把挂机中吃烤肉状态保存入cookies function AutoFightManager:SetAutoEatCookies(_autoEat, _autoBuy) local list = {autoEat = _autoEat, autoBuy = _autoBuy} CookieWrapper.Instance:SaveCookie(CookieLevelType.Account, CookieTimeType.TYPE_ALWAYS, CookieKey.AUTO_EAT_STATE, list) end --从cookies中获取挂机中吃烤肉状态 function AutoFightManager:GetAutoEatCookies() local state_list = CookieWrapper.Instance:GetCookie(CookieLevelType.Account, CookieKey.AUTO_EAT_STATE) if state_list == nil then return true, false else return state_list.autoEat, state_list.autoBuy end end function AutoFightManager:SetAutoFightBuff(data) self.now_auto_fight_buff = data self:Fire(AutoFightManager.UPDATE_EXPERIENCE_DATA) self:ShowExperienceIcon(self.now_auto_fight_buff.time) end --是否吃了烤肉 function AutoFightManager:HaveBuff(buff_list) if buff_list then if #buff_list > 0 then self:ShowExperienceIcon() end end end function AutoFightManager:ShowExperienceIcon(time) GlobalEventSystem:Fire(EventName.UPDATE_BUFF_VIEW) end --保存下开始自动挂机的位置 function AutoFightManager:CacheAutoFightPos(x, y) if Scene.Instance:GetMainRole() then local real_x, real_y = Scene.Instance:GetMainRole():GetRealPos() if real_x ~= 0 and real_y ~= 0 then local x = x local y = y if x == nil or y == nil then x = real_x y = real_y end self.auto_fight_cache_pos.x = x self.auto_fight_cache_pos.y = y -- print("自动挂机记录下的坐标是==========:", x, y) end Scene.Instance:ClearLastAttack() end end --判断技能是否是允许自动释放状态,默认是允许 function AutoFightManager:FindSkillIsAuto(id) local is_auto = true if self.auto_skill_list then local result = self.auto_skill_list[id] --只有手动取消勾选过的,才剔除 if result and result == 0 then is_auto = false end return is_auto end self.auto_skill_list = self.auto_skill_list or {} local is_auto = true if SkillManager:getInstance():GetHitSkillVo() and id == SkillManager:getInstance():GetHitSkillVo().id and is_auto then --羁绊技能默认不自动勾选 is_auto = true end local auto_skill_list = CookieWrapper.Instance:GetCookie(CookieLevelType.Account, CookieKey.AUTO_FIAGHT_SKILL_LIST) if auto_skill_list then for i,v in ipairs(auto_skill_list) do self.auto_skill_list[v.id] = v.state and 1 or 0 if v.id == id then is_auto = v.state end end end return is_auto end --保存自动挂机的技能设置 function AutoFightManager:SetAutoFightSkillList(id, state) self.auto_skill_list = self.auto_skill_list or {} if id then local result = state and 1 or 0 self.auto_skill_list[id] = result end local auto_skill_list = CookieWrapper.Instance:GetCookie(CookieLevelType.Account, CookieKey.AUTO_FIAGHT_SKILL_LIST) local find = false if auto_skill_list then for i,v in ipairs(auto_skill_list) do if v.id == id then find = true v.state = state break end end else auto_skill_list = {} end if find == false then local list = {} list.id = id list.state = state table.insert(auto_skill_list, list) end CookieWrapper.Instance:SaveCookie(CookieLevelType.Account, CookieTimeType.TYPE_ALWAYS, CookieKey.AUTO_FIAGHT_SKILL_LIST, auto_skill_list) CookieWrapper.Instance:WriteAll() end --获取优先攻击哪类目标 function AutoFightManager:GetTargetFirstAttack() local unLimit, npcFirst, roleFirst = self:GetAttackFirstCookies() if unLimit then return Scene.FIND_TARGET_TYPE.all end if npcFirst then return Scene.FIND_TARGET_TYPE.monster end if roleFirst then return Scene.FIND_TARGET_TYPE.role end return Scene.FIND_TARGET_TYPE.all end --登录后设置为上次挂机状态 function AutoFightManager:SceneStartRestoreAutoState() local state = self:GetAutoFightStateCookie() if state == nil or state == false then return false end return state end --挂机过程中,玩家点击地图或地面,保存下坐标,技能后摇结束后,前往该坐标 function AutoFightManager:CacheGoToPos(x, y, scene_id) if x == nil and y == nil then self.go_to_pos = false else self.go_to_pos = {x = x, y = y, scene_id = scene_id} end end --根据玩家等级获取自动挂机的场景和怪物堆 function AutoFightManager:GetAutoFightSceneAndMonster(role_lv,scene_Id) local target_cfg = nil for i,v in ipairs(Config.ConfigWorldMon.AutoFightAera) do if role_lv >= v.role_lv then target_cfg = v -- break end end local scene_id = nil local monster_id = nil local pos = nil if target_cfg then if target_cfg.scene and #target_cfg.scene > 0 then local rmd = scene_Id or target_cfg.scene[math_random(1, #target_cfg.scene)] local cfg = Config.ConfigWorldMon.SceneMons[rmd] local len = TableSize(cfg.mon_list) if cfg and len > 0 then scene_id = cfg.scene_id local obj = {} for k,v in pairs(cfg.mon_list) do local tmp = {} tmp.id = v.id table.insert(obj, tmp) end local random_id = obj[math_random(1, len)].id if random_id then local heap_cfg = cfg.mon_list[random_id] if heap_cfg and #heap_cfg.way_point > 0 then monster_id = heap_cfg.id pos = heap_cfg.way_point[math_random(1, #heap_cfg.way_point)] end end end end end return scene_id, monster_id, pos end --大多数活动,需要在安全区域和主城洛兰王国才能报名、参加活动,进入到活动场景 --在野外场景需要寻路到安全区 function AutoFightManager:FindSafePosAndGoActivity(call_back) local real_pos_x, real_pos_y = Scene.Instance:GetMainRole():GetRealPos() if SceneManager:getInstance():IsOutdoorScene() and not SceneManager:getInstance():IsSafePos(real_pos_x, real_pos_y) then local birth_x, birth_y = SceneManager.Instance:GetSceneBirthPos() if birth_x and birth_y then Message.show("战斗状态不可参加,正寻路到安全区") GlobalEventSystem:Fire(EventName.STOPAUTOFIGHT, false, true)--寻路要先切换掉自动挂机状态 if self.timer then GlobalTimerQuest:CancelQuest(self.timer) self.timer = nil end local main_role = Scene.Instance:GetMainRole() if main_role and main_role:CanMove() then self:GoFun(birth_x, birth_y, call_back) else local timer_func = function () if main_role and main_role:CanMove() then self:GoFun(birth_x, birth_y, call_back) if self.timer then GlobalTimerQuest:CancelQuest(self.timer) self.timer = nil end end end self.timer = GlobalTimerQuest:AddPeriodQuest(timer_func, 0.1, -1) end end end end function AutoFightManager:GoFun(birth_x, birth_y, call_back) if birth_x and birth_y then local findVo = FindVo.New() findVo.type = FindVo.POINT findVo.sceneId = SceneManager.Instance:GetSceneId() findVo.id = 0 findVo.x = birth_x / SceneObj.LogicRealRatio.x findVo.y = birth_y / SceneObj.LogicRealRatio.y findVo.call_back = call_back print("------野外场景的安全区-------", findVo.sceneId, findVo.x, findVo.y) GlobalEventSystem:Fire(EventName.FIND,findVo) if self.event_id then GlobalEventSystem:UnBind(self.event_id) self.event_id = nil end --脱离战斗状态5秒,允许进入活动 local quit_fun = function () if call_back then call_back() if self.event_id then GlobalEventSystem:UnBind(self.event_id) self.event_id = nil end call_back = nil if findVo then findVo.call_back = nil end end end self.event_id = GlobalEventSystem:Bind(EventName.QUIT_FIGHT_STATE, quit_fun) end end function AutoFightManager:StartOutdoorXiuLian(scene_Id,monster_Id,position) local scene_id, monster_id, pos = nil,nil,nil if scene_Id and monster_Id and position then scene_id, monster_id, pos = scene_Id,monster_Id,position else scene_id, monster_id, pos = AutoFightManager:getInstance():GetAutoFightSceneAndMonster(RoleManager.Instance.mainRoleInfo.level) end if scene_id and monster_id and pos then local findVo = FindVo.New() -- findVo.type = FindVo.MONSTER findVo.type = FindVo.POINT findVo.sceneId = scene_id findVo.id = monster_id findVo.x = pos.x / SceneObj.LogicRealRatio.x findVo.y = pos.y / SceneObj.LogicRealRatio.y findVo.call_type = FindVo.CallType.FiledGuaJi print("-------随机挂机点-------", findVo.sceneId, findVo.id, findVo.x, findVo.y) findVo.call_back = function () GlobalEventSystem:Fire(EventName.STARTAUTOFIGHT) if RoleManager.Instance.mainRoleInfo.team_id == 0 then local function ok() GlobalEventSystem:Fire(EventName.OPEN_AROUND_TEAM_VIEW) end Alert.show("是否查看附近队伍加入挂机?",Alert.Type.One,ok) end end if self.timer then GlobalTimerQuest:CancelQuest(self.timer) self.timer = nil end local main_role = Scene.Instance:GetMainRole() if main_role and main_role:CanMove() then GlobalEventSystem:Fire(EventName.FIND,findVo) else local timer_func = function () if main_role and main_role:CanMove() then GlobalEventSystem:Fire(EventName.FIND,findVo) if self.timer then GlobalTimerQuest:CancelQuest(self.timer) self.timer = nil end end end self.timer = GlobalTimerQuest:AddPeriodQuest(timer_func, 0.1, -1) end else Message.show("您等级太高了,找不到合适的挂机区域") end end --寻路的过程中,在战斗状态下不能切场景, function AutoFightManager:FindVoCallTypeFun(_type) if _type == FindVo.CallType.FiledGuaJi then --野外挂机 local call = function () self:StartOutdoorXiuLian() end self:FindSafePosAndGoActivity(call) end end function AutoFightManager:SetFlyData(scene_id,x,y,callback) if scene_id then self.fly_shoe_data = {} self.fly_shoe_data.scene_id = scene_id self.fly_shoe_data.x = x self.fly_shoe_data.y = y self.fly_shoe_data.callback = callback else self.fly_shoe_data = nil end end function AutoFightManager:SetChangeSceneFlyTime(time) self.change_scene_fly_time = time end function AutoFightManager:GetChangeSceneFlyTime() return self.change_scene_fly_time end --定点挂机指定坐标,否则取人物当前坐标为定点坐标 function AutoFightManager:SetFixedPointPos( tablexy ) self.fixed_point = tablexy end function AutoFightManager:GetFixedPointPos( ) return self.fixed_point end