魔力宝贝

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz

[GP] Fide_auto.lua;--自动寻路

[复制链接]
发表于 前天 03:31 | 显示全部楼层 |阅读模式
---------------------------------------------配置项目---------------------------
--锦旗例子--StartGlobal_Event_Du = {333,334};2个编号的标志都必须开启
--如果此处设为0那么只要拥有Table里面的锦旗标志将默认就开启,如果为1那么必须拥有Table里面所有的锦旗标志才能开启
StartGlobal_Event_Type = nil;
--设置一个锦旗标志如果此标志无打开将在面板不显示此处为NPC可以多个锦棋,如果Table数据是nil将无限制StartGlobal_Event_Npc = nil;
StartGlobal_Event_Npc = nil;
--设置一个锦旗标志如果此标志无打开将在面板不显示此处为Warp可以多个锦棋,如果Table数据是nil将无限制
StartGlobal_Event_Warp = nil;
--设置一个锦旗标志如果此标志无打开将在面板不显示此处为迷宫可以多个锦棋,如果Table数据是nil将无限制
StartGlobal_Event_Du = nil;

--热键呼出设置F1 -F12 代表(1 -12)
local BossKey = 10; --F10快捷呼出默认
local BossKeyMsg = "$5F10"; --F10快捷呼出默认
-----------------------------------------配置结束------------------------------------


--集成处

local StartWarpTable = {};
local StartWalk = {MapType,MapId,StartX,StartY,EndX,EndY};
local WarpTable = {};

--集成over
local StartWalktemp = -1;

function Fide_Check_EndEvent(_CharIndex,Type)
        local CTable = StartGlobal_Event_Npc;
        if(Type == 1)then
                CTable = StartGlobal_Event_Warp;
        end
        if(Type == 2)then
                CTable =  StartGlobal_Event_Du;
        end
       
        if(CTable == nil )then
                return 1;
        end
        if(CTable == 0)then
                return 0;
        end
        local L;
        local Len = #CTable;
        if(StartGlobal_Event_Type == 0)then
                for L = 1,Len do
               
                        if(Char.EndEvent(_CharIndex, CTable[L]) == 1)then
                                CTable = nil;
                                return 1;
                        end
                end
        else
                local N = 0;
                for L = 1,Len do
                        if(Char.EndEvent(_CharIndex, CTable[L]) == 1)then
                                N = N + 1;
                        end
                end
                if(N == Len and Len ~=0 )then
                        CTable = nil;
                        return 1;
                end
        end
       
        CTable = nil;
        return 0;
end

function Fide_Send_Msg(fd,packet)
        local CharIndex = Protocol.GetCharByFd(fd)
       
        if(CharIndex < 0 )then
                return -1;
        end
       
        local Point = {MapId,Floor};
        Point.MapId = Char.GetData(CharIndex,3);
        Point.Floor = Char.GetData(CharIndex,4);
        local ObjIndexTable = Map.Fide_OBJ(Point.MapId,Point.Floor);
       
        if(ObjIndexTable == nil)then
                return -1;
        end
        local J = 0;
        local NpcTable = {};
        local dungeonTable = {};
        for J = 1,#ObjIndexTable do
                local Name = Char.GetData(ObjIndexTable[J],2000)
               
                if(Name ~= "" and Char.GetData(ObjIndexTable[J],0) ~= 3)then
                       
                        local Max = #NpcTable + 1;
                        NpcTable[Max] = {Name,Point};
                        NpcTable[Max].Name = Name
               
                        NpcTable[Max].Point = Char.GetData(ObjIndexTable[J],5)..","..Char.GetData(ObjIndexTable[J],6);
                end
        end

        local p1 = Char.GetWarp(CharIndex);
       
        if(p1 ~= -1 and p1 ~= "") then
            local p2 = Fide_lua_string_split(p1,",");--分割
                local i;
            for i=1,#p2 do
                if(p2[i] ~= "")then
                    local p3 = Fide_lua_string_split(p2[i],"|");--分割
                       
                    local Max = #dungeonTable + 1;
                        dungeonTable[Max] = {Name,Point};
                        dungeonTable[Max].Name = p3[5];
                       
                        dungeonTable[Max].Point =p3[3]..","..p3[4];
                        p3 = nil;
                end
            end
         p2 = nil;
        end
        if(Char.GetData(CharIndex,3)==1)then
                Fide_Send_Date(CharIndex,fd,NpcTable,WarpTable,dungeonTable,Point.Floor ,1);
        else
       
                Fide_Send_Date(CharIndex,fd,NpcTable,dungeonTable,dungeonTable,Point.Floor, 0);
        end
        NpcTable = nil;
        dungeonTable = nil;
        return -1;
end

function Fide_Send_Date(CharIndex,FD,LNpcTable,LWarpTable,LdungeonTable,Floor,type)
        local Str = string.format("OBJ Key %d %s ",BossKey,BossKeyMsg);
        Protocol.Send(FD,Str)
        local Buff = ""
        local Buff1 = "";
        local Buff2 = "";
        Protocol.Send(FD,"OBJ Fide Start")
        local J = 1;
        local TableC = {Fide_Check_EndEvent(CharIndex,0),Fide_Check_EndEvent(CharIndex,1),Fide_Check_EndEvent(CharIndex,2)}
        --local TableC = {0,0,0}


        if(TableC[1] == 0)then
                Buff = Buff..string.format("%s:%s|","","")
        else
                for J = 1,#LNpcTable do
                        Buff = Buff..string.format("%s:%s|",LNpcTable[J].Name,LNpcTable[J].Point)
                end
        end
       
        if(TableC[2] == 0)then
                Buff1 = Buff1..string.format("%s:%s|","","")
        else
       
                if(type == 0)then
                        for J = 1,#LWarpTable do
                                Buff1 = Buff1..string.format("%s:%s|",LWarpTable[J].Name,LWarpTable[J].Point)
                        end
                else
                        Buff1 = Buff1..string.format("%s:%s|","","")
                end

        end
       
        if(TableC[3] == 0 or LdungeonTable == nil)then
                Buff2 = Buff2..string.format("%s:%s|"," "," ")
        else
                if(type == 1)then
                        for J = 1,#LdungeonTable do
                                Buff2 = Buff2..string.format("%s:%s|",LdungeonTable[J].Name,LdungeonTable[J].Point)
                        end
                else
                        Buff2 = Buff2..string.format("%s:%s|"," "," ")
                end
        end
       
       
       
        local String = string.format("OBJ Fide Install %d %d %d %s||%s||%s",TableC[1],TableC[2],TableC[3],Buff,Buff1,Buff2);
       
        Protocol.Send(FD,String);
        Protocol.Send(FD,"OBJ Fide End")
        Buff = nil;
        Buff1 =nil;
        Buff2 = nil;
       
end



function File_DoWarp()
        local MM = 0;
        file = io.open("data/warp.txt","r");
        local TableName = {};
        local TableMapId = {};
        local TableX = {};
        local TableY = {};
        for line in file:lines() do
               
                if(lines~="")then
                        if(line ~="")then
                       
                                local TableDate = Fide_lua_string_split(line,"        ");
                               
                                if(TableDate~=nil and #TableDate == 7 and TableDate[2] ~="" and TableDate[3] ~="" and TableDate[4] ~="" and TableDate[5] ~="")then
                                       
                                        local MapName = Map.GetMapName(0, TableDate[5]);
                                        if(MapName ~=nil and MapName~="")then
                                       
                                                local TableName = Fide_lua_string_split(MapName,"|");
                                       
                                                        if(TableName~=nil )then
                                                                if(#TableName == 2)then
                                                                        MapName = TableName[1];
                                                                end
                                                                local Max = tonumber(TableDate[2]);
                                       
                                                                if(WarpTable[Max] == nil)then
                                                                        WarpTable[Max] = {};
                                                                end
                                                                MM = #WarpTable[Max] + 1;
                                                                WarpTable[Max][MM] = {Name,Point}
                                                                WarpTable[Max][MM].Name = MapName;
                                                                WarpTable[Max][MM].Point = TableDate[3]..","..TableDate[4];
                                                        end
                                        end
                                end
                        end
                        TableDate = nil;
                end
               
        end
        file:close()
end


function WalkDate(fd,CheckWarp,X,Y)
        if(StartWalktemp ~= -1)then
                Protocol.Send(fd,"OBJ Fide Trry 排队中请稍等")
               
                return -1;
        end
       
        if(X == nil or Y == nil or X < 0 or Y < 0 )then
                Protocol.Send(fd,"OBJ Fide Trry 输入坐标有误")
               
                return -1;

        end

        local CharIndex = Protocol.GetCharByFd(fd);

        if(CharIndex < 0)then

                return -1;

        end
        StartWalktemp = -1;
       
        StartWalk.MapType = Char.GetData(CharIndex,3);

        StartWalk.MapId = Char.GetData(CharIndex,4);

        StartWalk.StartX = Char.GetData(CharIndex,5);

        StartWalk.StartY = Char.GetData(CharIndex,6);

       

        StartWalk.EndX = X;

        StartWalk.EndY = Y;


        if(StartWalk.StartX == X and StartWalk.StartY == Y)then
                Protocol.Send(fd,"OBJ Fide Trry 起点终点不能设置一样")
                return -1;

        end
        if(CheckWarp == 3 or CheckWarp == 4)then
                CheckWarp = 1;--此处要判断是否为warp是的话跳出GP的循环判断
        else
                CheckWarp = 0;
        end
        Protocol.Send(fd,"OBJ Fide Msg 正在搜索路线..")
        local Handle = Map.Fide(nil,"FidePath_CallBackEvent_2",StartWalk.MapType,StartWalk.MapId,StartWalk.StartX,StartWalk.StartY,StartWalk.EndX,StartWalk.EndY,CheckWarp);
       
        --从东门走到伊尔村

        if(Handle == -1)then

                Protocol.Send(fd,"OBJ Fide Trry 当前终点坐标无法走动");

                return -1;

        end

        if(Handle == -2)then

                Protocol.Send(fd,"OBJ Fide Trry 当前终点坐标无法走动");

                return -1;

        end

        if(Handle == -3)then

                Protocol.Send(fd,"OBJ Fide Trry 坐标不存在");

                return -1;

        end

        StartWalktemp = CharIndex;
--        NLG.TalkToCli (CharIndex, Handle,4,1);
        return -1;

       

end



function Twritefile(path, content, mode)
      mode = mode or "w+b"
      local file = io.open(path, mode)
      if file then
        if file:write(content) == nil then return false end
        io.close(file)
        return true
      else
        return false
      end
end

function FidePath_CallBackEvent_2(Handle, MapID,floor,StartX,StartY,EndX,EndY,MaxX,MaxY,Cout,XTableList,YTableList)
        if(StartWalktemp == -1)then
                return;
        end       
    local Index = StartWalktemp;

        if(Index < 0)then
                StartWalktemp = -1;
                 print("数据出错");

                 return;

        end
        local fd = Protocol.GetFdByChar(Index);
    if(Cout <= 0 or XTableList == nil or YTableList == nil)then
                Protocol.Send(fd,"OBJ Fide Trry 无法通过走路到达");
                StartWalktemp = -1;
        return;
    end
    local Loopi = 1;
    local String = "";
    for Loopi = 1,Cout do
         String = String..string.format("|%d:%d|",XTableList[Loopi],YTableList[Loopi ]);
    end
        local fd = Protocol.GetFdByChar(Index);
        Send_Walk(fd,Cout,String);
        StartWalktemp = -1;
      XTableList = nil;
      YTableList = nil;
        Protocol.Send(fd,"OBJ Fide End")
end
function Send_Walk(fd, Type,Msg)   
       
        if(fd == nil or fd < 0)then
                return;
        end
       
        local SendBuf = string.format("Walk %d %s",Type,Msg);
        Protocol.Send(fd,SendBuf)
end

--WalkCkear();
File_DoWarp();

回复

使用道具 举报

Archiver|魔力研究社

GMT+8, 2025-5-12 14:06 , Processed in 0.119543 second(s), 23 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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