require("Envir/Market_Def/NpcLua/zh.lua") -- 个人封装函数
local bz_conf = {
["恢复宝珠(劣品)"] = {["元宝"]=1000, materials = {["玄铁矿石"]=10, ["魔魂内丹"]=1}, old_charm=nil},
["恢复宝珠(次品)"] = {["元宝"]=2000, materials = {["玄铁矿石"]=20, ["魔魂内丹"]=2}, old_charm="恢复宝珠(劣品)"},
["恢复宝珠(良品)"] = {["元宝"]=3000, materials = {["玄铁矿石"]=30, ["魔魂内丹"]=3}, old_charm="恢复宝珠(次品)"},
["恢复宝珠(优品)"] = {["元宝"]=4000, materials = {["玄铁矿石"]=40, ["魔魂内丹"]=4}, old_charm="恢复宝珠(良品)"},
["恢复宝珠(极品)"] = {["元宝"]=5000, materials = {["玄铁矿石"]=50, ["魔魂内丹"]=5}, old_charm="恢复宝珠(优品)"},
["恢复宝珠(精品)"] = {["元宝"]=6000, materials = {["玄铁矿石"]=60, ["魔魂内丹"]=6}, old_charm="恢复宝珠(极品)"},
["恢复宝珠(珍品)"] = {["元宝"]=7000, materials = {["玄铁矿石"]=70, ["魔魂内丹"]=7}, old_charm="恢复宝珠(精品)"},
["恢复宝珠(绝品)"] = {["元宝"]=8000, materials = {["玄铁矿石"]=80, ["魔魂内丹"]=8}, old_charm="恢复宝珠(珍品)"},
["恢复宝珠(神品)"] = {["元宝"]=9000, materials = {["玄铁矿石"]=90, ["魔魂内丹"]=9}, old_charm="恢复宝珠(绝品)"},
}
-- 检查是否满足条件
local function check_requirements(actor, req)
local checks = {
old_charm = function() return not req.old_charm or checkitemw(actor, req.old_charm, 1) end,
yb = function() return getyb(actor) >= req["元宝"] end,
items = function()
for itemName, count in pairs(req.materials) do -- 只遍历materials中的项目
if itemcount(actor, itemName) < count then
return false, itemName, count
end
end
return true
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_charm' then
sendmsg99(actor, string.format("<font color='#f0b42a'>系统提示:</font><font color='#ff0000'>身上佩戴%s才能锻造</font>", req.old_charm))
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["元宝"]))
end
return false
end
end
return true
end
---玩家点击宝珠进阶时执行
---@param actor userdata 点击npc的玩家
---@param charm string 下阶的宝珠名称
function click_bzdz(actor, charm)
charm = tostring(charm)
if not charm or charm == "" then
sendmsg9(actor, "对不起,游戏参数异常!", "#ff0000")
return false
end
if checkitemw(actor, "恢复宝珠(神品)", 1) then
sendmsg9(actor, "你佩戴的“恢复宝珠(神品)”无法进阶!", "#ff0000")
return false
end
local req = bz_conf[charm]
if not req then
sendmsg9(actor, "对不起,游戏参数不存在!", "#ff0000")
return false
end
-- 检查是否满足历练条件
if not check_requirements(actor, req) then
return false
end
-- 扣除元宝和物品
if not (subyb(actor, req["元宝"], "NPC宝珠锻造消耗元宝") and
takeitemex(actor, "玄铁矿石", req.materials["玄铁矿石"], 0, "宝珠玄铁矿石") and
takeitemex(actor, "魔魂内丹", req.materials["魔魂内丹"], 0, "宝珠魔魂内丹")
) then
sendmsg9(actor, "扣除材料失败,无法锻造宝珠!", "#ff0000")
return false
end
-- 删除掉上一级宝珠
if req.old_charm and req.old_charm ~= "" then
if not takew(actor, req.old_charm, 1, "宝珠锻造消耗上级") then
sendmsg9(actor, string.format("扣除宝珠%s失败,无法锻造升级!", req.old_charm), "#ff0000")
return false
end
end
if giveonitem(actor, 12, charm, 1, 370, "宝珠锻造获得" .. charm) then
sendmsg9(actor, "恭喜你宝珠进阶成功!", "#00ff00")
local npc = getcurrnpc(actor)
if npc then
opennpcshow(actor, getnpcindex(npc), 10)
end
else
sendmsg9(actor, "宝珠锻造失败!")
end
end