|
发表于 2024-7-20 23:15:51
|
查看: 879 |
回复: 0
- --获取配置文件中....本场景自动寻路数据的起始与结束位置....
- --参考 048-遍历传送点和NPC - test.lua
- local print=myprint
- local g_TabListDataTablePtr={}
- --MenuName 任务名
- function SelectNpcMenu(MenuName)
- local strType,strState,strScriptId,strExtra,strTemp
- --NPC对话框内 项的数量
- local nEventListNum = DataPool:GetNPCEventList_Num();
- print("数量",nEventListNum)
- for i=1, nEventListNum do
- strType,strState,strScriptId,strExtra,strTemp = DataPool:GetNPCEventList_Item(i-1);
- print(i,"NPC对话列表",strType,strState,strScriptId,strExtra,strTemp )
- if strType=='id' and MenuName == strTemp then
- print("选择",MenuName,tonumber(-1),tonumber(strScriptId),tonumber(strExtra))
- QuestFrameOptionClicked(tonumber(-1),tonumber(strScriptId),tonumber(strExtra))
- break;
- end
- end
- return strScriptId,strExtra,strTemp
- end
-
- -- 城市 --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("干光豪")
- SelectNpcMenu("蜂毒")
- print("OK+++++++++++++++++")
复制代码
|
|