require("Envir/Market_Def/NpcLua/zh.lua") -- 个人封装函数
local qjbmdata = {
["启脉"] = {yb = 1000, items = {["烛龙之睛"] = 10, ["魔魂内丹"] = 1}, old_title=nil},
["督脉"] = {yb = 2000, items = {["烛龙之睛"] = 20, ["魔魂内丹"] = 2}, old_title="启脉"},
["任脉"] = {yb = 3000, items = {["烛龙之睛"] = 30, ["魔魂内丹"] = 3}, old_title="督脉"},
["冲脉"] = {yb = 4000, items = {["烛龙之睛"] = 40, ["魔魂内丹"] = 4}, old_title="任脉"},
["带脉"] = {yb = 5000, items = {["烛龙之睛"] = 50, ["魔魂内丹"] = 5}, old_title="冲脉"},
["阳维脉"] = {yb = 6000, items = {["烛龙之睛"] = 60, ["魔魂内丹"] = 6}, old_title="带脉"},
["阴维脉"] = {yb = 7000, items = {["烛龙之睛"] = 70, ["魔魂内丹"] = 7}, old_title="阳维脉"},
["阳蹻脉"] = {yb = 8000, items = {["烛龙之睛"] = 80, ["魔魂内丹"] = 8}, old_title="阴维脉"},
["阴蹻脉"] = {yb = 10000, items = {["烛龙之睛"] = 100, ["魔魂内丹"] = 10}, old_title="阳蹻脉"},
}
-- 检查是否满足奇经八脉条件
local function check_requirements(actor, req)
local checks = {
yb = function() return getyb(actor) >= req.yb end,
items = function()
for itemName, count in pairs(req.items) do
if itemcount(actor, itemName) < count then
return false, itemName, count
end
end
return true
end,
old_title = function() return not req.old_title or checktitle(actor, req.old_title) end
}
-- Check each requirement and send appropriate message if failed
for key, check in pairs(checks) do
local success, itemName, itemCount = check()
if not success then
if key == 'old_title' then
sendmsg99(actor, string.format("<font color='#f0b42a'>系统提示:</font><font color='#ff0000'>系统提示:需要打通%s才能打通当前经脉</font>", req.old_title))
elseif key == 'items' then
sendmsg99(actor, string.format("<font color='#f0b42a'>系统提示:</font><font color='#ff0000'>需要%s%d个</font>", itemName, itemCount))
else
sendmsg99(actor, string.format("<font color='#f0b42a'>系统提示:</font><font color='#ff0000'>%s不足%d</font>", "元宝", req.yb))
end
return false
end
end
return true
end
function click_qjbm(actor, title)
title = tostring(title)
if not title or title == "" then
sendmsg9(actor, "奇经八脉的称号为空!")
return false
end
if checktitle(actor, "阴蹻脉") then
sendmsg9(actor, "你的经脉已全部打通", "#ff0000")
return false
end
local conf = qjbmdata[title]
if not conf then
sendmsg9(actor, "你奇经八脉的称号不存在!")
return false
end
-- 检查是否满足奇经八脉条件
if not check_requirements(actor, conf) then
return false
end
-- 扣除元宝和物品
if not (subyb(actor, conf.yb, "NPC奇经八脉消耗元宝") and
takeitemex(actor, "烛龙之睛", conf.items["烛龙之睛"], 0, "奇经八脉烛龙之睛") and
takeitemex(actor, "魔魂内丹", conf.items["魔魂内丹"], 0, "奇经八脉魔魂内丹")
) then
sendmsg9(actor, "扣除材料失败,无法打通经脉!")
return false
end
-- 删除掉上一级奇经八脉称号
if conf.old_title then
deprivetitle(actor, conf.old_title)
end
if confertitle(actor, title) then
sendmsg9(actor, string.format("恭喜你成功获得奇经八脉称号〖%s〗", title), "#ff00ff")
sendmsg0(actor, string.format("恭喜[%s]成功打通[%s)>],实力得到更进一步的增强!", getname(actor), title), 253, 0)
local npc = getcurrnpc(actor)
if npc then
opennpcshow(actor, getnpcindex(npc), 10)
end
else
sendmsg9(actor, "奇经八脉给予称号失败!")
end
end