|
|
分享一个装备回收 NPC 的基础模板,适合放在土城 NPC 或回收管理员里。
功能点:
1. 自动扫描背包装备。
2. 根据装备品质和等级计算回收金币。
3. 支持白名单保护,避免误回收关键装备。
4. 支持绑定锁、最低等级等基础过滤。
背包读取、删除物品、发金币这些接口在不同版本里可能不一样,替换 VvApi 里的 TODO 即可。
-- EquipRecycle.lua
-- 装备回收:按品级返还货币,支持绑定/白名单/最低等级保护
local VvApi = {}
function VvApi.getPlayerName(player)
return player.name
end
function VvApi.getBagItems(player)
-- TODO: 替换为获取背包物品列表
return player.bag or {}
end
function VvApi.removeItem(player, uid, count)
-- TODO: 替换为删除指定唯一ID物品
print("remove item", uid, count)
end
function VvApi.addMoney(player, amount)
print("add money", VvApi.getPlayerName(player), amount)
end
function VvApi.sendMsg(player, msg)
print(msg)
end
local EquipRecycle = {}
EquipRecycle.config = {
minLevel = 20,
protectNames = {
["传送戒指"] = true,
["复活戒指"] = true,
["会员凭证"] = true,
},
priceByQuality = {
common = 1000,
rare = 5000,
epic = 30000,
legend = 100000,
},
}
local function canRecycle(item)
if not item then return false end
if not item.isEquip then return false end
if item.bindLocked then return false end
if EquipRecycle.config.protectNames[item.name] then return false end
if (item.level or 0) < EquipRecycle.config.minLevel then return false end
return true
end
local function calcPrice(item)
local quality = item.quality or "common"
local base = EquipRecycle.config.priceByQuality[quality] or EquipRecycle.config.priceByQuality.common
local levelBonus = math.max(item.level or 0, 1)
return base + levelBonus * 100
end
function EquipRecycle.recycleAll(player)
local totalMoney = 0
local totalCount = 0
for _, item in ipairs(VvApi.getBagItems(player)) do
if canRecycle(item) then
local price = calcPrice(item)
VvApi.removeItem(player, item.uid, 1)
totalMoney = totalMoney + price
totalCount = totalCount + 1
end
end
if totalCount == 0 then
VvApi.sendMsg(player, "没有可回收的装备。")
return false
end
VvApi.addMoney(player, totalMoney)
VvApi.sendMsg(player, "成功回收 " .. totalCount .. " 件装备,获得金币 " .. totalMoney .. "。")
return true
end
return EquipRecycle
|
|