找回密码
 注册
搜索
查看: 1256|回复: 22

岛主说的武当前置搜索,补充一下搜索距离的获取。

[复制链接]
门派:明教
发表于 2018-12-25 03:45:59 | 显示全部楼层 |阅读模式
wudang.lua——

function wudangConsider(n,l,w)
        local x
    nobusy=1
    job.time.b=os.time()
    job.last='wudang'
    job.target=Trim(w[4])
    job.killer={}
    job.killer[job.target]=true
    job.where=Trim(w[5])
        --Note(job.where)
        if string.find(job.where,"周围") then
           local l_cnt = string.find(job.where,"周围")
           job.where=string.sub(job.where,1,l_cnt-1)
        end
        if string.find(Trim(w[5]),"里之内") then
                x=string.find(Trim(w[5]),"里之内")
                wd_distance=trans(string.sub(Trim(w[5]),x-2,x-1))
        else
            wd_distance=4
        end

    job.room,job.area=getAddr(job.where)
        --if job.area=="明教" and string.find(job.room,"字门") then
        --        job.room="紫杉林"
        --end
end

困难在于文字的距离怎么转化成数字的距离,另外怎么截取到目标字符段,花了一晚上研究,现在是凌晨3:30,终于可以安心地睡觉了。

log——
http://www.sjever.net/bbs/forum.php?mod=viewthread&tid=217232

说句题外话:
岛主这个投喂有一些东西没交代清楚,比如wd_distance怎么获取,我当然可以问他,这样我会比较轻松,他也许会告诉我,也许不会。

我这人的脾气,除非我自己先努力研究过了,真是没任何办法了,我才会张嘴求别人!

现在我自己解决了这个问题,我从晚上11点,研究到了凌晨3:30,我觉得收获很大,因为破解问题的过程,让我更加深了对lua的理解。

有时候我看到一些人,没有经过一定的思考,甚至唾手可得的东西,也不愿自己花一丝精力,就觉得问别人更轻松。。。那,别人也可以有权不告诉你!
门派:桃花岛
发表于 2018-12-25 12:55:07 | 显示全部楼层
好样的,师兄!                           
门派:明教
 楼主| 发表于 2018-12-25 13:02:01 | 显示全部楼层

没什么,都是同门,这点贡献是应该的!

毕竟这是比较难的编程,不能指望人人都能花四五个小时去钻研这个,也就是我这样的变态能钻进去。

大家问我这个,我就是花一个小时给大家讲解,我也很乐意。

我生气的是,动动手指能找到的东西,还要来问我!别说是同门,是朋友,是我亲爹亲妈,我也都不客气!

这就是我的脾气。
门派:桃花岛
发表于 2018-12-25 19:01:24 | 显示全部楼层
师兄你看看我这段wudang里的, 不大一样。。 是不是已经加了

function wudangConsider(n,l,w)
    nobusy=1
        wd_distance=3
    job.time.b=os.time()
    job.last='wudang'
        wdfanwei ="不知道"
    job.target=Trim(w[4])
    job.killer={}
    job.killer[job.target]=true
    job.where=Trim(w[5])
        --Note(job.where)
        if string.find(job.where,"里之") then
           local l_cnt = string.find(job.where,"里之")
           wdjob_distance=string.sub(job.where,l_cnt-4,l_cnt-1)
        end       
        if string.find(job.where,"周围") then
           local l_cnt = string.find(job.where,"周围")
           job.where=string.sub(job.where,1,l_cnt-1)
           --Note(job.where)
        end
                if wdjob_distance =="圆一" then
                        wdfanwei=1
                        wd_distance=2
            --if  string.find(job.where,"杭州") or string.find(job.where,"苏州") or string.find(job.where,"丐帮") or string.find(job.where,"福州") or string.find(job.where,"宁波") or string.find(job.where,"莆田") or string.find(job.where,"嘉兴") or string.find(job.where,"归云庄") then
                  --wd_distance=1
                    --else
                                  --wd_distance=1
                        --end
        end
                if wdjob_distance =="圆二" then
                        wdfanwei=2
                        wd_distance=3
            --if  string.find(job.where,"杭州") or string.find(job.where,"苏州") or string.find(job.where,"丐帮") or string.find(job.where,"福州") or string.find(job.where,"宁波") or string.find(job.where,"莆田") or string.find(job.where,"嘉兴") or string.find(job.where,"归云庄") then
                  --wd_distance=1
                    --else
                                  --wd_distance=1
                        --end
        end               
        if wdjob_distance =="圆三" then
                        wdfanwei=3
                        wd_distance=3
            --if  string.find(job.where,"杭州") or string.find(job.where,"苏州") or string.find(job.where,"丐帮") or string.find(job.where,"福州") or string.find(job.where,"宁波") or string.find(job.where,"莆田") or string.find(job.where,"嘉兴") or string.find(job.where,"归云庄") then
                  --wd_distance=1
                    --else
                                  --wd_distance=1
                        --end
        end               
        if wdjob_distance =="圆四" then
                        wdfanwei=4
                        wd_distance=4
            --if  string.find(job.where,"杭州") or string.find(job.where,"苏州") or string.find(job.where,"丐帮") or string.find(job.where,"福州") or string.find(job.where,"宁波") or string.find(job.where,"莆田") or string.find(job.where,"嘉兴") or string.find(job.where,"归云庄") then
                  --wd_distance=1
                    --else
                                  --wd_distance=1
                        --end
        end               
        if wdjob_distance =="圆五" then
            --if  string.find(job.where,"杭州") or string.find(job.where,"苏州") or string.find(job.where,"丐帮") or string.find(job.where,"福州") or string.find(job.where,"宁波") or string.find(job.where,"莆田") or string.find(job.where,"嘉兴") or string.find(job.where,"归云庄") then
                  --wd_distance=4
                    --else
                                  --wd_distance=4
                        --end
        end
                job.room,job.area=getAddr(job.where)
               
        if string.find(job.where,"天字门") or string.find(job.where,"地字门") or string.find(job.where,"风字门") or string.find(job.where,"雷字门") then
                 job.where = "明教紫杉林"
        end       

        if job.area=="华山" and string.find(job.room,"石洞") and not Bag['绳子'] then
                job.room="山涧"
        end       
       
        if string.find(job.where,"心禅堂") then
                job.room="心禅坪"
        end       
        if string.find(job.where,"苏州城闺房") then
                job.room="翰林府院"
        end       
        if string.find(job.where,"梅庄西湖边") then
                 wdmz=1
        end               
        if string.find(job.where,"伊犁城") then
                return wdwaitdazuo()
        end       
    if string.find(job.where,"石窟") then
                 jqgsk=1
        end               

end
门派:明教
 楼主| 发表于 2018-12-25 20:14:08 | 显示全部楼层
cxls@tj 发表于 2018-12-25 19:01
师兄你看看我这段wudang里的, 不大一样。。 是不是已经加了

function wudangConsider(n,l,w)

你这个比我的那个还高级多了!对多种情况都有判断,不过这只是提取到了关键字,具体搜索脚步放慢了没有,还得看lujing.lua里的path_create内的内容,也就是岛主说的内容。
门派:明教
 楼主| 发表于 2018-12-25 20:23:24 | 显示全部楼层
宋远桥在你的耳边悄声说道:据说河南盗贼李奇正在明教洪水旗周围方圆 里之内捣乱,你马上去给我巡视一圈。

一个汉字是由2个字符组成的,我的程序是从“里之内”往前查找,l_cnt-2,l_cnt-1,就是说从“里”这个字往前推半格,再往前推半格,也就找到了“二”这个字。

        if string.find(job.where,"里之") then
           local l_cnt = string.find(job.where,"里之")
           wdjob_distance=string.sub(job.where,l_cnt-4,l_cnt-1)
        end

你这个是l_cnt-4,l_cnt-1,也就是往前推了4个半格,你取到了2个字,也就是“圆二”这两个字。

                if wdjob_distance =="圆二" then
                        wdfanwei=2
                        wd_distance=3

你这个是担心识别错误,所以用2个字判断,如果是“圆二”,搜索范围就是2,否则就是3.

我那里用了trans函数,可以把汉字的“二”转化成数字的“2”,所以就直接取到范围了。

嗯。。。程序大致就是这样,知道原理和语法后,其实很简单的!
门派:桃花岛
发表于 2018-12-25 21:57:20 | 显示全部楼层
kkfromch@tj 发表于 2018-12-25 20:14
你这个比我的那个还高级多了!对多种情况都有判断,不过这只是提取到了关键字,具体搜索脚步放慢了没有, ...

你看看我的,我怎么感觉和岛主的一样:

function path_create()
    local l_set
    local l_num=0
    local l_cnt=1
        local l_cntt=1
    road.detail={}
    l_sett=0
        l_settt=0
    l_path=path_cal()
    --Note(l_path)
    if type(l_path)~='string' then
       if math.random(1,4)==1 then
          l_path='stand;out;northeast;northwest;southeast;southwest;south;south;south;south;south'
       elseif math.random(1,4)==2 then
          l_path='stand;out;northeast;northwest;southeast;southwest;east;east;east;east;east;east'
       elseif math.random(1,4)==3 then
          l_path='stand;out;northeast;northwest;southeast;southwest;west;west;west;west;west;west'
       else
          l_path='stand;out;northeast;northwest;southeast;southwest;north;north;north;north;north'
       end
    end
    l_set=utils.split(l_path,';')  --一个alias里有几个命令
        l_settt=table.getn(l_set)
        --print(l_path)
        if wdgostart==1 then
          if l_settt<= wd_distance then l_settt=wd_distance end
      for i=1,table.getn(l_set) do
                if i<l_settt-wd_distance-2 then
            if string.find(l_set,'#') then
                    if l_num>0 then
                      l_cnt=l_cnt+1
                end
                    road.detail[l_cnt]=l_set
                    l_cnt=l_cnt+1
                    l_num=0
                else
                    if l_num==0 then
                      road.detail[l_cnt]=l_set
                    else
                      road.detail[l_cnt]=road.detail[l_cnt]..';'..l_set
                end
                    l_num=l_num+1
                    if l_num>road.steps then
                       l_cnt=l_cnt+1
                       l_num=0
                    end
            end
                else
           if string.find(l_set,'#') then
                    if l_num>0 then
                      l_cnt=l_cnt+1
                end
                    road.detail[l_cnt]=l_set
                    l_cnt=l_cnt+1
                    l_num=0
                else
                    if l_num==0 then
                      road.detail[l_cnt]=l_set
                    else
                      road.detail[l_cnt]=road.detail[l_cnt]..';'..l_set
                end
                    l_num=l_num+1
                    if l_num>0 then
                       l_cnt=l_cnt+1
                       l_num=0
                    end
            end
                end
      end
        else
            for i=1,table.getn(l_set) do
          if string.find(l_set,'#') then
                if l_num>0 then
                  l_cnt=l_cnt+1
            end
                road.detail[l_cnt]=l_set
                l_cnt=l_cnt+1
                l_num=0
              else
                if l_num==0 then
                  road.detail[l_cnt]=l_set
                else
                  road.detail[l_cnt]=road.detail[l_cnt]..';'..l_set
            end
                l_num=l_num+1
                if l_num>road.steps then
                   l_cnt=l_cnt+1
                   l_num=0
                end
          end
        end
        end
end
       
门派:明教
 楼主| 发表于 2018-12-25 22:01:35 | 显示全部楼层
一样的,我看了看一模一样,放心用吧!

只要不出现武当找不到npc,而且你的武当任务做得比较快,那就没问题!

机器人确实很好的。
门派:桃花岛
发表于 2018-12-25 22:06:20 | 显示全部楼层
kkfromch@tj 发表于 2018-12-25 22:01
一样的,我看了看一模一样,放心用吧!

只要不出现武当找不到npc,而且你的武当任务做得比较快,那就没 ...

也就是我这个补丁早打上了,还有wdgostart 的变量也在sujian.lua 有,初始赋值为0.  这个对的吧?
门派:明教
 楼主| 发表于 2018-12-25 22:09:40 | 显示全部楼层
cxls@tj 发表于 2018-12-25 22:06
也就是我这个补丁早打上了,还有wdgostart 的变量也在sujian.lua 有,初始赋值为0.  这个对的吧?

给0,给4都行,岛主说如果没说范围,默认就是4.

我估计你程序会自动判断,不说范围就让范围是4了。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|书剑永恒MUD ( 闽ICP备14012032号|闽公网安备 35050202000162号 )

GMT+8, 2025-7-17 17:19 , Processed in 0.036807 second(s), 26 queries .

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

快速回复 返回顶部 返回列表