385 lines
11 KiB
Lua
385 lines
11 KiB
Lua
NPCGotoMapOBJ = Up_BaseClass:new()
|
|
|
|
|
|
NPCGotoMapOBJ._name = "NPCGotoMapOBJ"
|
|
|
|
|
|
-- 配置文件
|
|
NPCGotoMapOBJ.cfg = Func.require("cfg_地图进入NPC")
|
|
|
|
local function NPCGotoMapOBJ_mapid(pos)
|
|
if type(pos) == "table" then
|
|
return pos[1]
|
|
end
|
|
return pos
|
|
end
|
|
|
|
local function NPCGotoMapOBJ_addmap(mapcfg, mapid, cfg, npcid, id)
|
|
if not mapid then
|
|
return
|
|
end
|
|
mapcfg[mapid] = { cfg = cfg, npcid = npcid, id = id, mapid = mapid }
|
|
end
|
|
|
|
local function NPCGotoMapOBJ_for()
|
|
local tbl = {}
|
|
local id = {}
|
|
local leavemap = {}
|
|
local mapcfg = {}
|
|
for i, v in ipairs(NPCGotoMapOBJ.cfg) do
|
|
table.insert(id, v.npcid)
|
|
if not tbl[v.npcid] then
|
|
tbl[v.npcid] = {}
|
|
end
|
|
|
|
table.insert(tbl[v.npcid], v)
|
|
local cfgid = #tbl[v.npcid]
|
|
|
|
NPCGotoMapOBJ_addmap(mapcfg, NPCGotoMapOBJ_mapid(v.pos), v, v.npcid, cfgid)
|
|
for _, pos in ipairs(v.randompos or {}) do
|
|
NPCGotoMapOBJ_addmap(mapcfg, NPCGotoMapOBJ_mapid(pos), v, v.npcid, cfgid)
|
|
end
|
|
|
|
if v.LeaveMapCD then
|
|
if v.pos then
|
|
if type(v.pos) == "table" then
|
|
leavemap[v.pos[1]] = { name = v.name, cd = v.LeaveMapCD }
|
|
else
|
|
leavemap[v.pos] = { name = v.name, cd = v.LeaveMapCD }
|
|
end
|
|
end
|
|
|
|
if v.randompos then
|
|
for _, pos in ipairs(v.randompos) do
|
|
if type(pos) == "table" then
|
|
leavemap[pos[1]] = { name = v.name, cd = v.LeaveMapCD }
|
|
else
|
|
leavemap[pos] = { name = v.name, cd = v.LeaveMapCD }
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
return tbl, id, leavemap, mapcfg
|
|
end
|
|
|
|
NPCGotoMapOBJ.npcid, NPCGotoMapOBJ.id, NPCGotoMapOBJ.LeaveMapCD, NPCGotoMapOBJ.mapid = NPCGotoMapOBJ_for()
|
|
|
|
|
|
-- ---* 加入上线同步数据
|
|
-- Player.sycCfg[NPCGotoMapOBJ._name] = NPCGotoMapOBJ.cfg
|
|
|
|
for i, v in ipairs(NPCGotoMapOBJ.id or {}) do
|
|
Npc.clicknpcCfg[v] = NPCGotoMapOBJ
|
|
end
|
|
|
|
|
|
function NPCGotoMapOBJ:main(actor, ...)
|
|
local info = { ... }
|
|
|
|
local data = {}
|
|
data.npcid = info[1]
|
|
data.cfg = self.npcid[info[1]]
|
|
|
|
if data.cfg[1].parent then
|
|
self:up(actor, nil, nil, nil, { { npcid = data.npcid, id = 1 } })
|
|
else
|
|
Message:SubLink(actor, self._name .. "_main", data)
|
|
end
|
|
end
|
|
|
|
|
|
function NPCGotoMapOBJ:up(actor, p1, p2, p3, data)
|
|
if not data then
|
|
self:violation(actor)
|
|
return
|
|
end
|
|
local npcid = data[1].npcid
|
|
local id = data[1].id
|
|
|
|
if not Npc.CheckNPCRange(actor, npcid) then
|
|
return
|
|
end
|
|
local cfg = self.npcid[npcid][id]
|
|
|
|
|
|
if cfg.LeaveMapCD then
|
|
local _time = Player.getint(actor, cfg.name)
|
|
if os.time() - _time < cfg.LeaveMapCD then
|
|
Func.sendmsg9(actor, string.format("[%s]#70|此地图进入CD%d秒,请稍等#251|%d秒后重试#215|.", cfg.name, cfg.LeaveMapCD, cfg.LeaveMapCD - (os.time() - _time)))
|
|
return
|
|
end
|
|
end
|
|
|
|
local check_bool = self:checkgotomap(actor, npcid, id)
|
|
|
|
|
|
|
|
if check_bool then
|
|
if cfg.dalu then
|
|
local dalu = Player.getint(actor, VarCfg.Player.int["大陆开荒"]) or 0
|
|
if dalu < cfg.dalu then
|
|
Player.setint(actor, VarCfg.Player.int["大陆开荒"], cfg.dalu)
|
|
end
|
|
end
|
|
|
|
|
|
if cfg.varcale then
|
|
for i, v in ipairs(cfg.varcale or {}) do
|
|
if npcid == 26 and checkitemw(actor,"九秘珠",1) then
|
|
break
|
|
end
|
|
local var = v[2]
|
|
local calss = v[1]
|
|
local _value = Player.getVar(actor, var, calss)
|
|
Player.setVar(actor, var, _value + v[3], calss)
|
|
end
|
|
end
|
|
|
|
local limitedMapId = nil
|
|
if type(cfg.pos) == "table" then
|
|
limitedMapId = cfg.pos[1]
|
|
MapCfg.gotomap(actor, cfg.pos[1], cfg.pos[2], cfg.pos[3])
|
|
else
|
|
limitedMapId = cfg.pos
|
|
MapCfg.gotomap(actor, cfg.pos)
|
|
end
|
|
|
|
if cfg.randompos then
|
|
local _random = math.random(1, #cfg.randompos)
|
|
if type(cfg.randompos[_random]) == "table" then
|
|
limitedMapId = cfg.randompos[_random][1]
|
|
MapCfg.gotomap(actor, cfg.randompos[_random][1], cfg.randompos[_random][2], cfg.randompos[_random][3])
|
|
else
|
|
limitedMapId = cfg.randompos[_random]
|
|
MapCfg.gotomap(actor, cfg.randompos[_random])
|
|
end
|
|
end
|
|
|
|
if cfg.limitedTime and limitedMapId and tostring(getbaseinfo(actor, ConstCfg.gbase.mapid)) == tostring(limitedMapId) then
|
|
self:startLimitedTime(actor, limitedMapId, cfg.limitedTime)
|
|
else
|
|
self:clearLimitedTime(actor)
|
|
end
|
|
if cfg.sendmsg then
|
|
Func.sendmsg(actor,
|
|
string.format("[地图传送]:#70|勇士#255|[%s]#215|闯入了#255|%s#215|%s!#255", Player.getname(actor), cfg.name,
|
|
cfg.sendmsg), 1)
|
|
end
|
|
end
|
|
end
|
|
|
|
function NPCGotoMapOBJ:getMapCfg(mapid)
|
|
if not mapid then
|
|
return nil
|
|
end
|
|
return self.mapid[mapid] or self.mapid[tostring(mapid)] or self.mapid[tonumber(mapid)]
|
|
end
|
|
|
|
function NPCGotoMapOBJ:getLimitedMap(actor)
|
|
return Player.gettempstr(actor, VarCfg.Player.temp.str["地图限时地图"]) or ""
|
|
end
|
|
|
|
function NPCGotoMapOBJ:getLimitedEndTime(actor)
|
|
return Player.gettempint(actor, VarCfg.Player.temp.int["地图限时结束"]) or 0
|
|
end
|
|
|
|
function NPCGotoMapOBJ:sendLimitedTimeMsg(actor, remain, showTime)
|
|
remain = math.max(0, tonumber(remain) or 0)
|
|
showTime = tonumber(showTime) or 10
|
|
senddelaymsg(actor, string.format("[地图计时]: 剩余%d秒, 时间到将强制离开地图.", remain), showTime, 250, 1, nil, 0)
|
|
end
|
|
|
|
function NPCGotoMapOBJ:clearLimitedTime(actor)
|
|
local timerId = VarCfg.Timer["地图限时巡检"]
|
|
if timerId and hastimer(actor, timerId) then
|
|
setofftimer(actor, timerId)
|
|
end
|
|
Player.settempstr(actor, VarCfg.Player.temp.str["地图限时地图"], "")
|
|
Player.settempint(actor, VarCfg.Player.temp.int["地图限时结束"], 0)
|
|
end
|
|
|
|
function NPCGotoMapOBJ:startLimitedTime(actor, mapid, limitedTime)
|
|
limitedTime = tonumber(limitedTime) or 0
|
|
if limitedTime <= 0 or not mapid then
|
|
self:clearLimitedTime(actor)
|
|
return
|
|
end
|
|
|
|
local staySeconds = limitedTime * 60
|
|
local endTime = os.time() + staySeconds
|
|
Player.settempstr(actor, VarCfg.Player.temp.str["地图限时地图"], tostring(mapid))
|
|
Player.settempint(actor, VarCfg.Player.temp.int["地图限时结束"], endTime)
|
|
|
|
local timerId = VarCfg.Timer["地图限时巡检"]
|
|
if timerId and not hastimer(actor, timerId) then
|
|
setontimer(actor, timerId, 1, 0)
|
|
end
|
|
self:sendLimitedTimeMsg(actor, staySeconds, 10)
|
|
end
|
|
|
|
function NPCGotoMapOBJ:onLimitedTimer(actor)
|
|
local limitedMapId = self:getLimitedMap(actor)
|
|
local endTime = self:getLimitedEndTime(actor)
|
|
if limitedMapId == "" or endTime <= 0 then
|
|
self:clearLimitedTime(actor)
|
|
return
|
|
end
|
|
|
|
local curMap = getbaseinfo(actor, ConstCfg.gbase.mapid)
|
|
if tostring(curMap) ~= tostring(limitedMapId) then
|
|
self:clearLimitedTime(actor)
|
|
return
|
|
end
|
|
|
|
local remain = endTime - os.time()
|
|
if remain <= 0 then
|
|
self:clearLimitedTime(actor)
|
|
Func.sendmsg9(actor, "[提示]:#70|地图停留时间已到,即将强制离开地图!")
|
|
mapmove(actor, 3, 330, 330)
|
|
return
|
|
end
|
|
|
|
if remain <= 10 then
|
|
self:sendLimitedTimeMsg(actor, remain, 2)
|
|
elseif remain % 10 == 0 then
|
|
self:sendLimitedTimeMsg(actor, remain, 10)
|
|
end
|
|
end
|
|
|
|
function NPCGotoMapOBJ:checkCfg(actor, cfg, isTake, silent)
|
|
if not cfg then
|
|
return true
|
|
end
|
|
|
|
local check_bool = true
|
|
if cfg.check and cfg.check_2 then
|
|
local check_1 = Func.checkcontion(actor, cfg.check, false, not silent)
|
|
local check_2 = Func.checkcontion(actor, cfg.check_2, false, not silent)
|
|
if not check_1 and not check_2 then
|
|
check_bool = false
|
|
end
|
|
end
|
|
|
|
|
|
|
|
if cfg.check and not cfg.check_2 then
|
|
if not Func.checkcontion(actor, cfg.check, false, not silent) then
|
|
check_bool = false
|
|
end
|
|
end
|
|
|
|
|
|
|
|
if not check_bool then
|
|
-- Func.sendmsg9(actor, "[地图传送]:#70|进入条件不足,请检测!")
|
|
return false
|
|
end
|
|
|
|
if cfg.xh and isTake ~= false then
|
|
if Func.takeitmes(actor, cfg.xh, true, true) then
|
|
return true
|
|
else
|
|
return false
|
|
end
|
|
end
|
|
return true
|
|
end
|
|
|
|
function NPCGotoMapOBJ:checkgotomapByMapId(actor, mapid, isTake, silent)
|
|
local data = self:getMapCfg(mapid)
|
|
if not data then
|
|
return true
|
|
end
|
|
return self:checkCfg(actor, data.cfg, isTake, silent)
|
|
end
|
|
|
|
function NPCGotoMapOBJ:checkgotomap(actor, npcid, id)
|
|
if not npcid or not id then
|
|
self:violation(actor)
|
|
return
|
|
end
|
|
|
|
local cfg = self.npcid[npcid][id]
|
|
return self:checkCfg(actor, cfg, true)
|
|
end
|
|
|
|
---* 打开仓库
|
|
function NPCGotoMapOBJ:opencanggku(actor)
|
|
openstorage(actor)
|
|
end
|
|
|
|
---* 开始挂机
|
|
function NPCGotoMapOBJ:startAuto(actor)
|
|
local _map = getbaseinfo(actor, ConstCfg.gbase.mapid)
|
|
if MapCfg.dalumap[_map] and MapCfg.dalumap[_map].Auto then
|
|
Player.settempint(actor, VarCfg.playerTemp.int.guaji, 0)
|
|
Func.sendmsg9(actor, "当前地图禁止挂机!")
|
|
return
|
|
end
|
|
Player.settempint(actor, VarCfg.playerTemp.int.guaji, 1)
|
|
startautoattack(actor)
|
|
end
|
|
|
|
---* 停止挂机
|
|
function NPCGotoMapOBJ:endAuto(actor)
|
|
Player.settempint(actor, VarCfg.playerTemp.int.guaji, 0)
|
|
stopautoattack(actor)
|
|
end
|
|
|
|
---* 立即传送
|
|
function NPCGotoMapOBJ:findmove(actor)
|
|
local _map = getbaseinfo(actor, ConstCfg.gbase.mapid)
|
|
local x = tonumber(getconst(actor, "<$ToPointX>")) or 0
|
|
local y = tonumber(getconst(actor, "<$ToPointY>")) or 0
|
|
|
|
if MapCfg.dalumap[_map] and MapCfg.dalumap[_map].findmove then
|
|
Func.sendmsg9(actor, "当前地图禁止传送!")
|
|
return
|
|
end
|
|
|
|
if x == 0 or y == 0 then
|
|
Func.sendmsg9(actor, "请先设置传送坐标!")
|
|
return
|
|
end
|
|
|
|
if gridattr(_map, x, y, 1) then
|
|
local nowtime = os.time()
|
|
if getgmlevel(actor) < 10 then
|
|
local _cd = Player.getint(actor, VarCfg.Player.int["寻路传送"]) or 0
|
|
if nowtime < _cd then
|
|
Func.sendmsg9(actor, string.format("传送冷却时间:#251|%d秒#215|!#251", _cd - nowtime))
|
|
return
|
|
end
|
|
end
|
|
local DeCd = getbaseinfo(actor, ConstCfg.gbase.custom_attr, 253) or 0
|
|
Player.setint(actor, VarCfg.Player.int["寻路传送"], nowtime + (ConstCfg.FindMoveCd - DeCd))
|
|
MapCfg.gotomap(actor, _map, x, y)
|
|
else
|
|
Func.sendmsg9(actor, "当前坐标不可达!")
|
|
end
|
|
end
|
|
|
|
function call_map_time_back(actor)
|
|
senddelaymsg(actor, string.format("[地图计时]:倒计时:%ds,将强制离开地图.", querymoney(actor, 21)), 1, 250, 1, nil, 0)
|
|
end
|
|
|
|
---* 离开地图事件
|
|
function NPCGotoMapOBJ.LeaveMapEvent(actor, mapId, x, y, mapId2)
|
|
if NPCGotoMapOBJ.LeaveMapCD[mapId] then
|
|
Player.setint(actor, NPCGotoMapOBJ.LeaveMapCD[mapId].name, os.time())
|
|
end
|
|
|
|
if tostring(NPCGotoMapOBJ:getLimitedMap(actor)) == tostring(mapId) then
|
|
NPCGotoMapOBJ:clearLimitedTime(actor)
|
|
end
|
|
end
|
|
|
|
GameEvent.add(EventCfg.goLeaveMap, NPCGotoMapOBJ.LeaveMapEvent, NPCGotoMapOBJ)
|
|
GameEvent.add(EventCfg.onExitGame, function(actor)
|
|
NPCGotoMapOBJ:clearLimitedTime(actor)
|
|
end, NPCGotoMapOBJ)
|
|
|
|
|
|
NPCGotoMapOBJ.allowFunc = {"up", "main"}
|
|
return NPCGotoMapOBJ
|