|
发表于 2024-7-20 00:32:15
|
查看: 902 |
回复: 0
--获取配置文件中....本场景自动寻路数据的起始与结束位置....
--参考 048-遍历传送点和NPC - test.lua
local print=myprint
local g_TabListDataTablePtr={}
-- 城市 --1 全部,2功能,3商店,4任务
function GetPosForNpc(NpcName)
local tabIndex=1 --全部
print("开始遍历++++++++++++++")
local curTabType = TabIndex2TabType(tabIndex);
local nStart, nEnd = DataPool:GetAutoSearchSceneStartEnd( GetSceneID() )
print('nStart=',nStart,'nEnd=',nEnd)
if nStart == -1 then return false; end
--填充本场景自动寻路数据的ID和优先级到表格....
local tblPriority = {};
local nCount = nEnd - nStart + 1;
local k = 1;
for i=nStart, nEnd do
--print(i)
tblPriority[k] = {};
tblPriority[k].id = i;
tblPriority[k].pri = DataPool:GetAutoSearchPriority(i);
k = k + 1;
end
--按优先级对表格进行排序....
--算法有点不好理解....策划要求权值相同的排序后相对位置不能改变....就先这么写了....
local temp1,temp2;
for m=nCount, 1, -1 do
for n=m-1, 1, -1 do
if tblPriority[m].pri >= tblPriority[n].pri then
temp1 = tblPriority[m].id;
temp2 = tblPriority[m].pri;
tblPriority[m].id = tblPriority[n].id;
tblPriority[m].pri = tblPriority[n].pri;
tblPriority[n].id = temp1;
tblPriority[n].pri = temp2;
end
end
end
--按排序后的ID顺序将自动寻路的数据加到本Tab页的自动寻路数据表中....
local curTabType = TabIndex2TabType(tabIndex);
local x, y, name, tooltips, info, tabtype;
k = 1;
for i=1, nCount do
x, y, name, tooltips, info, tabtype = DataPool:GetAutoSearch( tblPriority[nCount-i+1].id );
if 0 == curTabType or curTabType == tabtype then
g_TabListDataTablePtr[k] = {};
g_TabListDataTablePtr[k].ID = tblPriority[nCount-i+1].id;
g_TabListDataTablePtr[k].nPosX = x;
g_TabListDataTablePtr[k].nPosY = y;
g_TabListDataTablePtr[k].strName = name;
g_TabListDataTablePtr[k].strToolTips = tooltips;
g_TabListDataTablePtr[k].strInfo = info;
--g_TabListDataTablePtr[k].strInfo = tostring(tblPriority[nCount-i+1].pri)..","..tostring(tblPriority[nCount-i+1].id);
k = k + 1;
end
end
--end --end of (if not g_TabListDataTablePtr then)
local nTabListCount = table.getn( g_TabListDataTablePtr );
----PushDebugMessage("count ="..tostring(nTabListCount) )
--print("nTabListCount=",nTabListCount)
for i=1, nTabListCount do
--AutoSearch_List:AddNewItem( g_TabListDataTablePtr[i].strName, 0, i-1 );
--AutoSearch_List:AddNewItem( g_TabListDataTablePtr[i].strInfo, 1, i-1 );
--AutoSearch_List:SetRowTooltip( i-1, g_TabListDataTablePtr[i].strToolTips );
--g_TabListDataTablePtr[k].nPosX
local items=g_TabListDataTablePtr
if(NpcName==items[i].strName or NpcName==items[i].strInfo or NpcName==items[i].strToolTips ) then
print(tostring(i),items[i].strName,items[i].strInfo,items[i].strToolTips,items[i].nPosX,items[i].nPosY)
return items[i].nPosX,items[i].nPosY
end
end
--]]
print("完成遍历++++++++++++++>>>")
return nil,nil ;
end --function
function NpcDialogIsShow()
return Quest_Env.this:IsVisible()
end
function AutoRunToNpc(name)
local x,y=GetPosForNpc(name)
--自动移动到指定位置
print("AutoRunToNpc 自动移动到指定位置",name,x,y)
SetAutoRunTargetNPCName(name)--如 SetAutoRunTargetNPCName"干光豪")
local ret = AutoRunToTarget( x, y );
if ret == 0 then
PushDebugMessage("自动寻路无法到达目标点") --无法移动到指定位置 自动寻路无法到达目标点
end
return NpcDialogIsShow; --非0表示可以到达
end
local isok=AutoRunToNpc("干光豪")
print("是否能够移动到指定位置:",isok)
|
游戏安全课程 学员办理咨询联系QQ150330575 手机 139 9636 2600 免费课程 在 www.bilibili.com 搜 郁金香灬老师
|
|