tibaiwan1888 发表于 2026-6-6 10:17:31

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

分享一个装备回收 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 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 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

qq154886255 发表于 2026-6-6 22:04:16

独家版本后期最怕的不是功能少,而是脚本结构乱。

tibaiwan1888 发表于 2026-6-7 11:56:30

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

qq154886255 发表于 2026-6-7 15:07:44

独家版本后期最怕的不是功能少,而是脚本结构乱。

jz9005 发表于 2026-6-8 10:18:22


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

40731803 发表于 2026-6-8 10:28:33

qq154886255 发表于 2026-6-6 22:04
独家版本后期最怕的不是功能少,而是脚本结构乱。

你得往建议区发帖

我爱嘟嘟 发表于 6 天前

你得往建议区发帖
页: [1]
查看完整版本: 装备回收NPC:按品级返金币 + 白名单保护