require("Envir/Market_Def/NpcLua/zh.lua") -- 个人封装函数
local ldzsdata = {
["坚毅仙体"] = {yb = 200, items = {["烛龙之睛"] = 5}, old_title=nil, },
["赤阳仙体"] = {yb = 400, items = {["烛龙之睛"] = 10}, old_title="坚毅仙体"},
["浩气仙体"] = {yb = 600, items = {["烛龙之睛"] = 15}, old_title="赤阳仙体"},
["疾风仙体"] = {yb = 800, items = {["烛龙之睛"] = 20}, old_title="浩气仙体"},
["丹心神体"] = {yb = 1200, items = {["烛龙之睛"] = 25}, old_title="疾风仙体"},
["玄御神体"] = {yb = 1500, items = {["烛龙之睛"] = 30}, old_title="丹心神体"},
["太初神体"] = {yb = 1800, items = {["烛龙之睛"] = 35}, old_title="玄御神体"},
["紫霄圣体"] = {yb = 2200, items = {["烛龙之睛"] = 40}, old_title="太初神体"},
["净莲圣体"] = {yb = 2600, items = {["烛龙之睛"] = 45}, old_title="紫霄圣体"},
["灵尊圣体"] = {yb = 3000, items = {["烛龙之睛"] = 50}, 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 == 'items' then
sendmsg9(actor, string.format("<font color='#f0b42a'>系统提示:</font><font color='#ff0000'>需要%s%d个</font>", itemName, itemCount))
elseif key == 'old_title' then
sendmsg9(actor, string.format("<font color='#f0b42a'>系统提示:</font><font color='#ff0000'>需要拥有%s称号才能进行当前修身炼体</font>", req.old_title))
else
sendmsg9(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_ldzs(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 = ldzsdata[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, "炼体烛龙之睛")) 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), "#40ff05")
sendmsg0(actor, string.format("恭喜【%s】获得了%s称号", getname(actor), title), 252, 255)
close(actor)
local npc = getcurrnpc(actor)
if npc then
opennpcshow(actor, getnpcindex(npc), 10)
end
else
sendmsg9(actor, "炼体给予称号失败!")
end
end