| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560 |
- local RemoteProxy = requireProxy("remote/RemoteProxy")
- local AssistProxy = class("AssistProxy", RemoteProxy)
- AssistProxy.NAME = global.ProxyTable.AssistProxy
- local proxyUtils = requireProxy( "proxyUtils" )
- local cjson = require("cjson")
- -- StdMode=25 Shape=1 灰色药粉
- -- StdMode=25 Shape=2 黄色药粉
- -- StdMode=25 Shape=5 护身符
- -- 使用护身符的技能
- local function isHSFSkill(skillID)
- local skills = {13, 14, 15, 16, 17, 18, 19, 30, 55, 57,76}
- for key, value in pairs(skills) do
- if value == skillID then
- return true
- end
- end
- return false
- end
- -- 使用毒的技能
- local function isDUSkill(skillID)
- local skills = {6, 51}
- for key, value in pairs(skills) do
- if value == skillID then
- return true
- end
- end
- return false
- end
- -- 是护身符
- local function isHSFItem(item)
- if not item then
- return false
- end
- return item.StdMode == 25 and item.Shape == 5
- end
- -- 是毒药粉
- local function isDUItem(item)
- if not item then
- return false
- end
- return item.StdMode == 25 and (item.Shape == 1 or item.Shape == 2)
- end
- -- 通过 stdmode和 shape从背包找物品
- local function findBagItem(stdMode, shape)
- local BagProxy = global.Facade:retrieveProxy(global.ProxyTable.Bag)
- local items = BagProxy:GetBagData()
- for _, item in pairs(items) do
- if item.StdMode == stdMode and item.Shape == shape then
- return item
- end
- end
- return nil
- end
- function AssistProxy:ctor()
- AssistProxy.super.ctor(self)
- self._offlineState = false
- self._isFindMapMonster = false
- self._isFindMapMonsterFail = false
- self._requestMonsterFlag = false
- self._nextAutoEquipShape = nil -- 上次挂机时使用的是什么药粉
- end
- function AssistProxy:onRegister()
- AssistProxy.super.onRegister(self)
-
- local msgType = global.MsgType
- end
- function AssistProxy:checkIsBusy()
- local mainPlayer = global.gamePlayerController:GetMainPlayer()
- local mapData = global.sceneManager:GetMapData2DPtr()
- if not mapData or not mainPlayer then
- print("000")
- return true
- end
- local facade = global.Facade
- local inputProxy = facade:retrieveProxy(global.ProxyTable.PlayerInputProxy)
- local autoProxy = facade:retrieveProxy(global.ProxyTable.Auto)
- -- afk
- if autoProxy:IsAFKState() then
- return false
- end
- -- 有掉落物可以捡
- if autoProxy:IsCanAutoPick() then
- return true
- end
- -- 不可以移动
- if not inputProxy:IsMovePermission()then
- return true
- end
- -- 移动中断
- if inputProxy:GetMoveInterruptFlag() then
- return true
- end
- -- 移动中
- if (inputProxy:IsMoveDirty() or inputProxy:GetCurrPathPoint() > 0) then
- return true
- end
-
- return false
- end
- function AssistProxy:CheckDu(type)--1 绿 2 红
- local MapProxy = global.Facade:retrieveProxy(global.ProxyTable.Map)
- local dresstype = MapProxy:GetUseAmuletType() --0 穿戴 1 背包 2 无
- local EquipProxy = global.Facade:retrieveProxy(global.ProxyTable.Equip)
- local EquipType = EquipProxy:GetEquipTypeConfig()
- local dressEquip = EquipProxy:GetEquipDataByPos(EquipType.Equip_Type_Bujuk)
- if dresstype == 2 then
- return true
- end
- if type == 1 then
- if dressEquip then
- return dressEquip.Shape == 1 or findBagItem(25, 1)
- else
- return findBagItem(25, 1)
- end
- elseif type == 2 then
- if dressEquip then
- return dressEquip.Shape == 2 or findBagItem(25, 2)
- else
- return findBagItem(25, 2)
- end
- end
- end
- function AssistProxy:autoDressEquipSkill(skillID)
- -- 0(穿戴) 才需要自动穿
- local MapProxy = global.Facade:retrieveProxy(global.ProxyTable.Map)
- if MapProxy:GetUseAmuletType() ~= 0 then
- return false
- end
- -- 自动红绿毒
- if not (isHSFSkill(skillID) or isDUSkill(skillID)) then
- return false
- end
- -- 装备位置 9
- -- step1 符/毒,
- -- 符,判断当前是否包含符子串, 是.不管 否.背包找,找到就换
- -- 毒,灰/黄毒轮换,换为符之后重置
- -- 挂机,用与上次 灰/黄 药粉不一样的装备
- local AutoProxy = global.Facade:retrieveProxy( global.ProxyTable.Auto )
- local isAFKState = AutoProxy:IsAFKState()
- local EquipProxy = global.Facade:retrieveProxy(global.ProxyTable.Equip)
- local EquipType = EquipProxy:GetEquipTypeConfig()
- local dressEquip = EquipProxy:GetEquipDataByPos(EquipType.Equip_Type_Bujuk)
- local replaceItem = nil
- local autoShapeDU1 = 1
- local autoShapeDU2 = 2
- if isAFKState then
- self._nextAutoEquipShape = self._nextAutoEquipShape or 1
- autoShapeDU1 = self._nextAutoEquipShape
- autoShapeDU2 = 3 - autoShapeDU1
- else
- self._nextAutoEquipShape = nil
- end
- if isHSFSkill(skillID) and CHECK_SETTING(40) == 1 then
- -- 符
- if not isHSFItem(dressEquip) then
- replaceItem = findBagItem(25, 5)
- end
- elseif isDUSkill(skillID) and CHECK_SETTING(40) == 1 then
- -- 毒
- if dressEquip and dressEquip.StdMode == 25 then
- if dressEquip.Shape == 5 then
- replaceItem = findBagItem(25, autoShapeDU1) or findBagItem(25, autoShapeDU2)
- elseif dressEquip.Shape == 1 then
- replaceItem = findBagItem(25, 2)
-
- elseif dressEquip.Shape == 2 then
- replaceItem = findBagItem(25, 1)
- end
- else
- replaceItem = findBagItem(25, autoShapeDU1) or findBagItem(25, autoShapeDU2)
- end
- end
- if replaceItem then
- local ItemUseProxy = global.Facade:retrieveProxy(global.ProxyTable.ItemUseProxy)
- ItemUseProxy:UseItem(replaceItem)
- if isAFKState and (replaceItem.Shape == 1 or replaceItem.Shape == 2) then
- self._nextAutoEquipShape = 3 - replaceItem.Shape
- end
- end
- end
- function AssistProxy:checkDressEquipSkillID(skillID)
- if not (isHSFSkill(skillID) or isDUSkill(skillID)) then
- return true
- end
- local EquipProxy = global.Facade:retrieveProxy(global.ProxyTable.Equip)
- local EquipType = EquipProxy:GetEquipTypeConfig()
- local dressEquip = EquipProxy:GetEquipDataByPos(EquipType.Equip_Type_Bujuk)
- -- 没穿
- if not dressEquip then
- return false
- end
- -- 符
- if isHSFSkill(skillID) and isHSFItem(dressEquip) then
- return true
- end
-
- -- 毒
- if isDUSkill(skillID) and isDUItem(dressEquip) then
- return true
- end
- return false
- end
- function AssistProxy:checkBagEquipSkillID(skillID)
- -- 背包中是否有释放技能装备
- if not (isHSFSkill(skillID) or isDUSkill(skillID)) then
- return true
- end
- -- 符
- if isHSFSkill(skillID) and findBagItem(25, 5) then
- return true
- end
-
- -- 毒
- if isDUSkill(skillID) and (findBagItem(25, 1) or findBagItem(25, 2)) then
- return true
- end
- return false
- end
- -------------------------------------------------
- -- 自动挂机
- function AssistProxy:setOfflineState(state)
- self._offlineState = state
- end
- function AssistProxy:getOfflineState()
- return self._offlineState
- end
- function AssistProxy:resetOfflineState()
- self:setOfflineState(false)
- self:resetOfflineSchedule()
- end
- function AssistProxy:resetOfflineSchedule()
- if self._offlineScheduleID then
- UnSchedule(self._offlineScheduleID)
- self._offlineScheduleID = nil
- end
- end
- function AssistProxy:checkOfflineAble()
- local mainPlayer = global.gamePlayerController:GetMainPlayer()
- local mapData = global.sceneManager:GetMapData2DPtr()
- if not mapData or not mainPlayer then
- return false
- end
- local facade = global.Facade
- local inputProxy = facade:retrieveProxy(global.ProxyTable.PlayerInputProxy)
- local autoProxy = facade:retrieveProxy(global.ProxyTable.Auto)
- -- 有掉落物可以捡 (并且 不满足 范围内有足够怪物 小精灵 不是一个个拾取 )
- if autoProxy:IsCanAutoPick() and not proxyUtils:checkIsEnoughMonster() and not proxyUtils:checkIsPlayerAbandonPickup() then
- return false
- end
- -- afk
- if not autoProxy:IsAFKState() then
- return false
- end
-
- -- 当前有目标
- if inputProxy:GetTargetID() then
- return false
- end
- -- 不可以移动
- if not inputProxy:IsMovePermission()then
- return false
- end
- -- 移动中断
- if inputProxy:GetMoveInterruptFlag() then
- return false
- end
- -- 移动中
- if (inputProxy:IsMoveDirty() or inputProxy:GetCurrPathPoint() > 0) then
- return false
- end
-
- return true
- end
- function AssistProxy:checkAimlessMove()
- if false == self:checkOfflineAble() then
- self:resetOfflineState()
- return false
- end
- --
- if self._offlineScheduleID then
- return false
- end
- local function callback()
- self._offlineScheduleID = nil
- if false == self:checkOfflineAble() then
- return
- end
- local mainPlayer = global.gamePlayerController:GetMainPlayer()
- local mapData = global.sceneManager:GetMapData2DPtr()
- if not mapData or not mainPlayer then
- return nil
- end
- local mapRows = mapData:getMapDataRows()
- local mapCols = mapData:getMapDataCols()
- local minR = math.ceil(math.min(mapRows, mapCols) / 2) --取地图较小边的一半 防止地图过小 傻太久
- local range = math.min(50, minR)
- local getNotObstacle = function(x ,y)--在目标和周围一格找
- local isNotObstacle = false
- local t = {
- {x = 0, y = 0},
- {x = -1, y = 1},
- {x = 0, y = 1},
- {x = 1, y = 1},
- {x = 1, y = 0},
- {x = 1, y = 1},
- {x = 0, y = -1},
- {x = -1, y = -1},
- {x = -1, y = 0}
- }
- local _x,_y
- for i, v in ipairs(t) do
- _x = x + v.x
- _y = y + v.y
- isNotObstacle = mapData:isObstacle(_x, _y) == 0
- if isNotObstacle then
- return cc.p(_x, _y)
- end
- end
- return nil
- end
- -- 最多找五次
- local counting = 0
- while true do
- counting = counting + 1
- if counting >= 5 then
- break
- end
- -- 找一个随机位置
- local srcX = mainPlayer:GetMapX()
- local srcY = mainPlayer:GetMapY()
- local dstX = Random(srcX-range, srcX+range)
- local dstY = Random(srcY-range, srcY+range)
- --视野边界 减少无效随机 原X+Y > 20
- if math.abs(dstX-srcX) >= 7 or math.abs(dstY-srcY) >= 7 then
- local dstPos = getNotObstacle(dstX,dstY)
- if dstPos then
- dstX = dstPos.x
- dstY = dstPos.y
- -- auto move
- local mapProxy = global.Facade:retrieveProxy(global.ProxyTable.Map)
- local mapID = mapProxy:GetMapID()
- local movePos =
- {
- mapID = mapID,
- x = dstX,
- y = dstY,
- type = global.MMO.INPUT_MOVE_TYPE_AUTOMOVE,
- range = SL:GetMetaValue("GAME_DATA","AutoMoveRange_Monster")
- }
- global.Facade:sendNotification(global.NoticeTable.InputMove, movePos)
-
- self:setOfflineState(true)
-
- break
- end
- end
- end
- end
- self._offlineScheduleID = PerformWithDelayGlobal(callback, 0.1)
- local values = GET_SETTING(global.MMO.SETTING_IDX_NO_MONSTAER_USE,true)
- if values[1] == 1 then
- if self._noMonsterScheduleID then
- return
- end
- local num = tonumber(values[2]) or 999
- self._noMonsterScheduleID = PerformWithDelayGlobal(function ()
- local autoProxy = global.Facade:retrieveProxy(global.ProxyTable.Auto)
- if not autoProxy:IsAFKState() then--不处于挂机状态 取消定时器
- self:resetNoMonsterSchedule()
- return false
- end
- local autoUseItem = function(items)
- local proxyUtils = requireProxy( "proxyUtils" )
- local ItemUseProxy = global.Facade:retrieveProxy(global.ProxyTable.ItemUseProxy)
- for _, itemIndex in ipairs(items) do
- local unpack = proxyUtils.unpackDrugByIndex(itemIndex)
- if unpack then
- return true
- end
- local item = proxyUtils.findItemByIndex(itemIndex)
- if item then
- ItemUseProxy:UseItem(item)
- return true
- end
- end
- return false
- end
- local index = tonumber(values[3])
- if index then
- autoUseItem({index})
- end
- self:resetNoMonsterSchedule()
- end, num)
- end
-
- return true
- end
- function AssistProxy:resetNoMonsterSchedule()
- if self._noMonsterScheduleID then
- UnSchedule(self._noMonsterScheduleID)
- self._noMonsterScheduleID = nil
- end
- end
- -------------------------------------------------
- -------------------------------------------------
- -- 向服务器找怪
- function AssistProxy:findMapMonster()
- self:RequestFindMapMonster()
- end
- function AssistProxy:isFindMapMonster()
- return self._isFindMapMonster
- end
- function AssistProxy:resetFindMapMonster()
- self._isFindMapMonsterFail = false
- self._isFindMapMonster = false
- end
- function AssistProxy:dirtyFindMapMonster()
- self._isFindMapMonster = true
- end
- function AssistProxy:isFindMapMonsterFail()
- return self._isFindMapMonsterFail
- end
- function AssistProxy:isRequestMonsterFlag()
- return self._requestMonsterFlag
- end
- -------------------------------------------------
- -- 自动找怪
- function AssistProxy:RequestFindMapMonster()
- LuaSendMsg(global.MsgType.MSG_CS_FIND_MAP_MONSTER)
- self._requestMonsterFlag = true
- self._isFindMapMonsterFail = false
- --
- if self._findMapTargetScheduleID then
- UnSchedule(self._findMapTargetScheduleID)
- self._findMapTargetScheduleID = nil
- end
- self._findMapTargetScheduleID = PerformWithDelayGlobal(function()
- self._requestMonsterFlag = false
- self:resetFindMapMonster()
- end, 2)
- print("+++++++++++++++++++++++++++++ find map target")
- end
- function AssistProxy:handle_MSG_SC_FIND_MAP_MONSTER(msg)
- local header = msg:GetHeader()
- local x = header.recog
- local y = header.param1
- dump(header)
- if x == 0 and y == 0 then
- self._requestMonsterFlag = false
- self._isFindMapMonsterFail = true
- return false
- end
- self._requestMonsterFlag = false
- self._isFindMapMonsterFail = false
- -- auto move
- local mapProxy = global.Facade:retrieveProxy(global.ProxyTable.Map)
- local mapID = mapProxy:GetMapID()
- local movePos =
- {
- mapID = mapID,
- x = x,
- y = y,
- type = global.MMO.INPUT_MOVE_TYPE_AUTOMOVE,
- range = SL:GetMetaValue("GAME_DATA","AutoMoveRange_Monster")
- }
- global.Facade:sendNotification(global.NoticeTable.InputMove, movePos)
- self:dirtyFindMapMonster()
- end
- function AssistProxy:RegisterMsgHandler()
- AssistProxy.super.RegisterMsgHandler(self)
- local msgType = global.MsgType
- LuaRegisterMsgHandler(msgType.MSG_SC_FIND_MAP_MONSTER, handler(self, self.handle_MSG_SC_FIND_MAP_MONSTER)) -- 全图找怪
- end
- return AssistProxy
|