bayuMIR/Mirserver/Mir200/Envir/QuestDiary/游戏功能/A2_二大陆/勇闯天关.lua
2026-06-18 02:06:14 +08:00

305 lines
8.8 KiB
Lua
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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, "<Img|bg=1|esc=1|show=0|move=0|loadDelay=1|reset=1|img=custom/26/box/bg.png>")
table.insert(_str, "<Layout|x=545|y=0|width=80|height=80|link=@exit>")
table.insert(_str, "<Button|x=488.0|y=1.0|nimg=public/1900000510.png|pimg=public/1900000511.png|link=@exit>")
table.insert(_str, "<Img|x=116.0|y=26.0|esc=0|img=custom/26/box/toptitle.png>")
table.insert(_str, "<Img|x=26.0|y=56.0|esc=0|img=custom/26/box/xian.png>")
table.insert(_str, "<Text|x=198.0|y=24.0|color=255|size=18|text=公共天关>")
table.insert(_str, "<Text|x=93.0|y=120.0|color=251|size=18|text=您可以直接通过摇骰子进行下面的闯关>")
table.insert(_str, "<Text|x=131.0|y=149.0|color=251|size=18|text=摇到几点即可进入下面的关卡>")
table.insert(_str,
"<RText|x=172.0|y=79.0|color=255|size=18|text=<当前天关:/FCOLOR=255><第" .. tianguanLevel .. "关/FCOLOR=254>>")
table.insert(_str, "<Img|x=170.0|y=221.0|esc=0|img=custom/26/box/falg.png>")
table.insert(_str, "<Text|x=197.0|y=219.0|color=251|size=18|text=立即投掷|link=@tianguan_touzi," .. npcid .. ">")
table.insert(_str, "<Text|x=162.0|y=186.0|color=255|size=18|text=消耗:>")
table.insert(_str,
"<ItemShow|x=190.0|y=163.0|width=70|height=70|itemanme=" ..
xh[1][1] .. "|itemcount=1|scale=0.6|bgtype=0|showtips=1>")
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, "<Text|x=243.0|y=186.0|color=255|size=18|text=" .. table.concat(_newxh, "") .. ">")
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的IdxNPC点击触发时触发参数会传回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