00003 不思议迷宫.0009.9:命运之链

来源:互联网 发布:h5视频网站源码 编辑:程序博客网 时间:2024/04/28 12:53

00003 不思议迷宫.0009.9:命运之链

         我不知道别人的怎么样,反正在我的手机们上,仅在该功能刚出来时找到过其他玩家。然后,官方说部分玩家该功能不能用,修复了。可惜的是,自从这个“修复”之后,我就再也没找到过任何其他玩家。你说我在住处没找到也就算了,毕竟在郊区;可是我在上海六院也没找到,你说这到底是啥情况?在家里,Wifi4G都试过,在六院,用的是iShanghai。我听说别人说,在模拟器中,将定位修改为北京的那个TAM,就能找到人了。我就在模拟器中试了试,果然如此。哈哈,那我就来改改吧,全部、直接定位到TAM

         首先要找找“命运石柱”功能的实现代码。

         “命运石柱”在主地图界面src/game/ui/form/main/UIMainMap.luac中。找到函数registerTouchEvent

function UIMainMap:registerTouchEvent()

    ……

 

    -- 命运的链

    local fateIcon = findChildByName(self.node, "map/fate/fate_icon/icon");

    self.fatePanel = findChildByName(self.node, "map/fate");

    local function onFateClick(sender, eventType)

        if true ~= LocationM.prepare() then

            return;

        end

        require "game/ui/form/fate_chain/UIFateChain"

        UIMgr.getCurrentScene():removeFormByName("UIFateChain");

        local uiForm = UIFateChain.create();

        UIMgr.getCurrentScene():addForm(uiForm);

        AudioM.playFx("ui_open1");

    end

    self:registerEnterClick(self.fatePanel, fateIcon, onFateClick);

    self:registerEnterClick(fateIcon, fateIcon, onFateClick);

end

         命运之链的具体实现是game/ui/form/fate_chain/UIFateChain。在这个界面中,当玩家点击“放大镜”图表时,便开始搜索附近的玩家。跟进,继续找函数registerTouchEvent

function UIFateChain:registerTouchEvent()

    ……

 

    -- 查询

    local searchNode = findChildByName(self.node, "bg/search");

    local function onSearchClick(sender, eventType)

        if eventType == ccui.TouchEventType.ended then

            AudioM.playFx("workshop_material");

            --尝试查询

            self:searchEventUpdate();

            self:startFateChain();

        end

    end

    searchNode:addTouchEventListener(onSearchClick);

end

         回调很简单,主要就两个函数, self:searchEventUpdate()self:startFateChain(),后者更像:

-- 玩家发起搜索

function UIFateChain:startFateChain()

    ……

 

    local function updateLocation()

        FateChainM.startFateChain();

 

        -- 每隔10s更新定位信息

        performWithDelay(self.node, updateLocation, 10);

    end

 

    -- 先发起定位

    updateLocation();

 

    local function delay()

        self.search = true;

        if FateChainM.getCurState() == FATE_CHAIN_STATE_FREE then

            --如果是空闲状态,则尝试搜索

            FateChainM.doSearch();

        end

        -- 每隔5s搜索一次

        performWithDelay(self.node, delay, 5);

    end

 

    -- 5s后开始搜索

    performWithDelay(self.node, delay, 5);

end

         函数的前半部分代码的作用就是“每隔10s更新定位信息”,这是注释说的。如果没有这个注释,我TM得看半天,看看那循环递归,欺负我人老了反应迟钝是不是?直接用个shceduler会死啊?

         真正的搜索代码在后半部分:FateChainM.doSearch()

function doSearch()

    LocationM.getNearbyPlayers(receiveData, SEARCH_LIMIT_NUM);

end

         又跑LocationM.getNearbyPlayers这去了:

-- 获取周围其他玩家信息

-- 该接口调用频率不要小于3

function getNearbyPlayers(callback, limitNum)

    -- 获取周围八个格子的geohash编码

    local hashStrList = getGeoHashStr();

 

    if #hashStrList == 0 then

        return;

    end

 

    -- 从服务器请求这9个格子内的玩家

    Operation.cmd_get_nearby_infos(hashStrList, curVersion, limitNum);

 

    -- 设置回调

    getNearbyFunc = callback;

end

         “获取周围个格子的geohash编码”、“从服务器请求这9个格子内的玩家”,突然之间不知道怎么理解了,为什么上面是8、下面就是9了?不管了,反正大意明白了,getGeoHashStr中就是我们所要关心的位置信息。

-- 获取9格编码

function getGeoHashStr()

    if curGeoHashStr == "" then

        return {};

    end

 

    local hashStrList = GeoHash.neighbours(curGeoHashStr);

    hashStrList = table.values(hashStrList);

    table.insert(hashStrList, 1, curGeoHashStr);

    return hashStrList;

end

         “获取9格编码”,看到这个我大概明白了上面注释的意思,正确的说法应当是“获取周围个格子的geohash编码、以及玩家当前格子的geohash编码”。

         重要的是curGeoHashStr,它是一个local,查找赋值,只有一处:

-- 获取坐标回调

function onSuccess(lat, lon)

    -- 生成geohash串,上报到服务器

    local fullHashStr = GeoHash.encode(lat, lon);

 

    -- 截取精度位数

    curGeoHashStr = string.sub(fullHashStr, 1, curPrecision);

 

    -- 上报给服务器

    Operation.cmd_upload_location_data(curGeoHashStr, fullHashStr);

end

         简单了,我们只要在这个函数中将fullHashStr修改为我们所要设置的值即可,或者修改latlon也行。

         用百度地图或者其他什么地图,查一下TAM的经纬度,传给GeoHash.encode,搞定。

         如有需要,可进群161355323下载补丁或安装程序。

0 0