TianGuanOBJ = Up_BaseClass:new()
TianGuanOBJ._name = "TianGuanOBJ"
-- NPCID
TianGuanOBJ.id = { 88 }
for i, v in ipairs(TianGuanOBJ.id or {}) do
Npc.clicknpcCfg[v] = TianGuanOBJ
end
-- 配置文件
TianGuanOBJ.cfg = {
[1] = {
{ "金币", 2000, 1 },
},
[2] = {
{ "元宝", 88, 1 },
},
}
---* 加入上线同步数据
-- Player.sycCfg[TianGuanOBJ._name] = TianGuanOBJ.cfg
TianGuanOBJ.CaChe = {}
---* 允许前端调用的函数
TianGuanOBJ.allowFunc = { "up", "selfgotolevel" }
TianGuanOBJ.UpFunc = {
"publicTianguan", "selfTianguan",
}
function TianGuanOBJ:up(actor, p1, p2, p3, data)
if not Npc.CheckNPCRange(actor, 88) then
return
end
local id = data[1]
if not data or not id then
return
end
TianGuanOBJ[self.UpFunc[id]](self, actor)
end
---* 进入公共天关
function TianGuanOBJ:publicTianguan(actor)
if not Npc.CheckNPCRange(actor, 88) then
return
end
if Func.takeitmes(actor, self.cfg[1], true, true) then
Message:SubLink(actor, self._name .. "_CloseWin")
MapCfg.gotomap(actor, "天关第1层")
end
end
local function TianGuanOBJ_public_xh()
local tbl = {}
for i = 1, 20, 1 do
tbl[i] = {
{ "金币", 2000, 1 },
}
end
for i = 21, 100, 1 do
tbl[i] = {
{ "灵符", 1, 0 },
}
end
return tbl
end
TianGuanOBJ.public_xh = TianGuanOBJ_public_xh()
----* 公共天关地图NPC
function TianGuanOBJ:publicMian(actor, npcid)
if not npcid or not Npc.CheckNPCRange(actor, npcid) then
return
end
local npcobj = getnpcbyindex(npcidx)
local MapName = getbaseinfo(npcobj, ConstCfg.gbase.mapid)
local tianguanLevel = tonumber(string.match(MapName, "%d+")) or 0
local xh = TianGuanOBJ.public_xh[tianguanLevel]
local _str = {}
table.insert(_str, " ")
table.insert(_str, "")
table.insert(_str, "")
table.insert(_str, " ")
table.insert(_str, " ")
table.insert(_str, "")
table.insert(_str, "")
table.insert(_str, "")
table.insert(_str,
"<第" .. tianguanLevel .. "关/FCOLOR=254>>")
table.insert(_str, " ")
table.insert(_str, "")
table.insert(_str, "")
table.insert(_str,
"")
local _newxh = {}
for i, v in ipairs(xh or {}) do
table.insert(_newxh, string.format("%sx%d", v[1], v[2]))
end
table.insert(_str, "")
say(actor, table.concat(_str))
end
function tianguan_touzi(actor, npcid)
TianGuanOBJ:publicNpcMian(actor, npcid)
end
function TianGuanOBJ:publicNpcMian(actor, npcid)
if not npcid or not Npc.CheckNPCRange(actor, npcid) then
return
end
local npcobj = getnpcbyindex(npcidx)
local MapName = getbaseinfo(npcobj, ConstCfg.gbase.mapid)
local tianguanLevel = tonumber(string.match(MapName, "%d+")) or 0
if Func.takeitmes(actor, TianGuanOBJ.public_xh[tianguanLevel], true, true) then
if tianguanLevel > 20 then
Sys.addint(VarCfg.sys.int["天关灵符奖池"], 1)
end
setflagstatus(actor, VarCfg.Falg_fangshua, 1)
Player.setint(actor, "D0", math.random(1, 6))
playdice(actor, 1, "@tianguan_gotopublic," .. tianguanLevel)
end
end
function tianguan_gotopublic(actor, tgId)
if getflagstatus(actor, VarCfg.Falg_fangshua) == 1 then
tgId = tonumber(tgId) + Player.getint(actor, "D0")
tgId = tgId > 100 and tgId - 100 or tgId
MapCfg.gotomap(actor, string.format("天关第%d层", tgId), 25, 32)
setflagstatus(actor, VarCfg.Falg_fangshua, 0)
end
end
local function TianGuanOBJ_public_jiangchi()
local tbl = {}
for i = 96, 99, 1 do
tbl[i] = 10
end
tbl[100] = 20
return tbl
end
TianGuanOBJ.public_jiangchi = TianGuanOBJ_public_jiangchi()
----* 公共副本 击杀分享奖池灵符
local function TianGuanOBJ_killMon(actor, mon, itype, kill, monName, mapID)
local number = tonumber(mapID:match("^天关第(%d+)层$")) or 0
if number > 0 then
if TianGuanOBJ.public_jiangchi[number] then
local jiangchi = Sys.getint(VarCfg.sys.int["天关灵符奖池"]) or 0
if jiangchi > 10 then
local giveNum = math.floor(jiangchi / 100 * TianGuanOBJ.public_jiangchi[number])
Sys.setint(VarCfg.sys.int["天关灵符奖池"], jiangchi - giveNum)
Func.mailitem(actor, { { "灵符", giveNum, 350 } }, "勇闯天关-奖池分享")
end
end
end
end
TianGuanOBJ.privateMapMon = Func.require("cfg_个人天关刷新表")
TianGuanOBJ.createNpcid = 50000
---* 个人天关进入
function TianGuanOBJ:selfTianguan(actor)
local gotoBool = Player.getTLint(actor, VarCfg.Player.TL.int["个人天关进入"]) or 0
if gotoBool > 0 then
Func.sendmsg9(actor, "[勇闯天关]:#70|今日已经闯过天关了,请明日再来!")
return
end
if Func.takeitmes(actor, self.cfg[2], true, true) then
if addbuff(actor, 10023) then
Player.setTLint(actor, VarCfg.Player.TL.int["个人天关进入"], 1)
self:selfgoto(actor, 1)
end
end
end
---* 进入个人天关
---* 玩家对象
---* 进入层级
function TianGuanOBJ:selfgoto(actor, level)
local _bool, mapid = self:addMirMap(actor, "个人天关", "个人天关第" .. level .. "层")
if _bool and mapid then
local Moncfg = TianGuanOBJ.privateMapMon[level].mon
-- LOGDump(Moncfg)
for i, v in ipairs(Moncfg or {}) do
genmon(mapid, 15, 19, v[1], 1, v[2], 249)
end
Message:SubLink(actor, self._name .. "_CloseWin")
local npcInfo = {
["Idx"] = TianGuanOBJ.createNpcid, -- 自定义NPC的Idx,NPC点击触发时,触发参数会传回Idx值
["npcname"] = "天关接待员", -- NPC名称
["appr"] = 8, -- NPC外形效果
["script"] = '个人天关', -- NPC相关脚本名称,表示Envir\Market_def\NewNPC.txt
["limit"] = 65535, -- 生命周期 (秒)
["dir"] = 1, --npc朝向(0-7)
}
createnpc(mapid, 19, 16, tbl2json(npcInfo))
TianGuanOBJ.createNpcid = TianGuanOBJ.createNpcid + 1
MapCfg.gotomap(actor, mapid, 10, 25)
end
end
---* 打开个人天关main
function TianGuanOBJ:selfNpcMian(actor, npcID)
local npcobj = getnpcbyindex(npcidx)
local MapName = getbaseinfo(npcobj, ConstCfg.gbase.mapid)
local tianguanLevel = tonumber(string.match(MapName, "%d+")) or 0
local data = {}
data = {
npcid = npcID,
cfg = {
level = tianguanLevel,
},
}
Message:SubLink(actor, "SelfTianGuanOBJ_main", data)
end
---* 天关进入下一层
function TianGuanOBJ:selfgotolevel(actor, p1, p2, p3, data)
local id = data[1]
if not data or not id then
return
end
local npcobj = getnpcbyindex(npcidx)
local MapName = getbaseinfo(npcobj, ConstCfg.gbase.mapid)
local MonNum = getmoncount(MapName, -1, true)
if MonNum > 0 then
return Func.sendmsg9(actor, "请先清理此地图的怪物吧!")
end
local tianguanLevel = tonumber(string.match(MapName, "%d+")) or 0
if tianguanLevel >= #self.privateMapMon then
Func.sendmsg9(actor, "[个人天关]:#70|您已经通关了哦~现在送你回城!")
MapCfg.gotomap(actor, "3", 333, 333, 1)
return
end
if id == 1 then
self:selfgoto(actor, tianguanLevel + 1)
return
elseif id == 2 then
if Func.takeitmes(actor, { { "元宝", 30, 1 } }, true, true) then
local _random = math.random(2, 3)
local _level = tianguanLevel + _random
self:selfgoto(actor, math.min(_level, 50))
end
end
end
---* 个人天关击杀怪物倒计时1分钟自动进入下一关
local function TianGuanOBJ_selfTianguankillMon(actor, mon, itype, kill, monName, mapID)
if string.find(mapID, "个人天关", 1, true) ~= nil then
addbuff(actor, 10024)
end
end
GameEvent.add(EventCfg.onKillMon, function(actor, mon, itype, kill, monName, mapID)
TianGuanOBJ_killMon(actor, mon, itype, kill, monName, mapID)
TianGuanOBJ_selfTianguankillMon(actor, mon, itype, kill, monName, mapID)
end, TianGuanOBJ)
return TianGuanOBJ