require("Envir/Market_Def/NpcLua/zh.lua") -- 个人封装函数
local jhlldata = {
["小试牛刀"] = {yb = 200, items = {["七彩结晶"] = 5}, old_title=nil, attr = "攻魔道+(2-2),杀怪爆率+1%"},
["初入江湖"] = {yb = 400, items = {["七彩结晶"] = 10}, old_title="小试牛刀", attr = "攻魔道+(4-4),杀怪爆率+2%"},
["渐露锋芒"] = {yb = 600, items = {["七彩结晶"] = 15}, old_title="初入江湖", attr = "攻魔道+(6-6),杀怪爆率+3%"},
["小有名气"] = {yb = 800, items = {["七彩结晶"] = 20}, old_title="渐露锋芒", attr = "攻魔道+(8-8),杀怪爆率+4%"},
["名动一方"] = {yb = 1200, items = {["七彩结晶"] = 25}, old_title="小有名气", attr = "攻魔道+(10-10),杀怪爆率+5%"},
["天下闻名"] = {yb = 1500, items = {["七彩结晶"] = 30}, old_title="名动一方", attr = "攻魔道+(12-12),杀怪爆率+6%"},
["功成名就"] = {yb = 1800, items = {["七彩结晶"] = 35}, old_title="天下闻名", attr = "攻魔道+(14-14),杀怪爆率+7%"},
["一代宗师"] = {yb = 2200, items = {["七彩结晶"] = 40}, old_title="功成名就", attr = "攻魔道+(16-16),杀怪爆率+8%"},
["登峰造极"] = {yb = 2600, items = {["七彩结晶"] = 45}, old_title="一代宗师", attr = "攻魔道+(18-18),杀怪爆率+9%"},
["超凡入圣"] = {yb = 3000, items = {["七彩结晶"] = 50}, old_title="登峰造极", attr = "攻魔道+(20-20),杀怪爆率+10%"},
}
-- 检查是否满足历练条件
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_jhll(actor, title)
title = tostring(title)
if not title or title == "" then
sendmsg9(actor, "历练的称号为空!")
return false
end
if checktitle(actor, "超凡入圣") then
sendmsg9(actor, "你已经获得超凡入圣,无法继续历练!")
return false
end
local conf = jhlldata[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), "#00ff00")
local npc = getcurrnpc(actor)
if npc then
opennpcshow(actor, getnpcindex(npc), 10)
end
else
sendmsg9(actor, "历练给予称号失败!")
end
end