bayuMIR/Mirserver/Mir200/Envir/Extension/UtilServer/Npc.lua
2026-06-21 21:55:53 +08:00

76 lines
1.8 KiB
Lua

Npc = {}
----* 注册npc点击初始化
Npc.clicknpcCfg = {}
----* 注册点击NPC
function clicknpc(actor, npcID, sScript)
Func.sendmsg9(actor, "点击NPC:" .. npcID)
if MainLineTaskOBJ and MainLineTaskOBJ.onVisitNpc then
MainLineTaskOBJ:onVisitNpc(actor, npcID, sScript)
end
if sScript == "天关接待员" then
TianGuanOBJ:publicMian(actor, npcID)
return
end
if sScript == "个人天关" then
TianGuanOBJ:selfNpcMian(actor, npcID)
return
end
if sScript == "影之道传送" then
ShabaKeOBJ:shadowTransfer(actor)
return
end
if sScript == "赤月祭坛" then
MapCfg.gotomap(actor, "赤月祭坛")
return
end
---* 分发点击NPC消息
local cfg = Npc.clicknpcCfg[npcID]
if not cfg or not cfg.main then return end
cfg:main(actor, npcID)
end
--检查一个对象的范围
function Npc.CheckRange(obj, x, y, range)
local cur_x, cur_y = getbaseinfo(obj, ConstCfg.gbase.x), getbaseinfo(obj, ConstCfg.gbase.y)
local min_x, max_x = x - range, x + range
local min_y, max_y = y - range, y + range
if (cur_x >= min_x) and (cur_x <= max_x) and
(cur_y >= min_y) and (cur_y <= max_y) then
return true
end
return false
end
--检查自己与npc的距离
function Npc.CheckNPCRange(actor, npcidx, range)
range = range or 15
local npcobj = getnpcbyindex(npcidx)
if npcobj == "0" then
return false
end
local npc_mapid = getbaseinfo(npcobj, ConstCfg.gbase.mapid)
local my_mapid = getbaseinfo(actor, ConstCfg.gbase.mapid)
if npc_mapid ~= my_mapid then return false end
local npc_x = getbaseinfo(npcobj, ConstCfg.gbase.x)
local npc_y = getbaseinfo(npcobj, ConstCfg.gbase.y)
return Npc.CheckRange(actor, npc_x, npc_y, range)
end
return Npc