查看: 89|回复: 7

[Lua] 装备回收NPC:按品级返金币 + 白名单保护

[复制链接]

46

主题

42

回帖

1212

积分

金牌会员

积分
1212
发表于 2026-6-6 10:17:31 | 显示全部楼层 |阅读模式
分享一个装备回收 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

点评

注意此写法为24年左右的引擎写法,现在的写法不同了,请看在线说明书查阅新写发  发表于 2026-6-9 15:03

2

主题

230

回帖

1932

积分

金牌会员

积分
1932
发表于 2026-6-6 22:04:16 | 显示全部楼层
独家版本后期最怕的不是功能少,而是脚本结构乱。

46

主题

42

回帖

1212

积分

金牌会员

积分
1212
楼主 发表于 2026-6-7 11:56:30 | 显示全部楼层
功能点:
1. 自动扫描背包装备。
2. 根据装备品质和等级计算回收金币。
3. 支持白名单保护,避免误回收关键装备。
4. 支持绑定锁、最低等级等基础过滤。

2

主题

230

回帖

1932

积分

金牌会员

积分
1932
发表于 2026-6-7 15:07:44 | 显示全部楼层
独家版本后期最怕的不是功能少,而是脚本结构乱。

25

主题

91

回帖

1467

积分

金牌会员

积分
1467
发表于 2026-6-8 10:18:22 | 显示全部楼层

功能点:
1. 自动扫描背包装备。
2. 根据装备品质和等级计算回收金币。
3. 支持白名单保护,避免误回收关键装备。
4. 支持绑定锁、最低等级等基础过滤。

15

主题

48

回帖

1271

积分

管理员

积分
1271
发表于 2026-6-8 10:28:33 | 显示全部楼层
qq154886255 发表于 2026-6-6 22:04
独家版本后期最怕的不是功能少,而是脚本结构乱。

你得往建议区发帖

21

主题

97

回帖

1305

积分

金牌会员

积分
1305
发表于 2026-6-10 20:14:18 | 显示全部楼层
你得往建议区发帖
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表