bayuMIR/Mirserver/Mir200/Envir/QuestDiary/游戏功能/A0_通用类/装备回收.lua
2026-06-18 02:06:14 +08:00

127 lines
3.6 KiB
Lua

HuiShouOBJ = Up_BaseClass:new()
HuiShouOBJ._name = "HuiShouOBJ"
-- 配置文件
HuiShouOBJ.tbl = Func.require("cfg_装备回收")
local function HuiShouOBJ_for()
local tbl = {}
local item = {}
for i, v in ipairs(HuiShouOBJ.tbl or {}) do
if not tbl[v.clssID] then
tbl[v.clssID] = {}
end
table.insert(tbl[v.clssID], v)
item[v.Name] = v
end
return tbl, item
end
HuiShouOBJ.cfg, HuiShouOBJ.item = HuiShouOBJ_for()
-- ---* 加入上线同步数据
Player.sycCfg[HuiShouOBJ._name] = HuiShouOBJ.cfg
for i, v in ipairs(HuiShouOBJ.id or {}) do
Npc.clicknpcCfg[v] = HuiShouOBJ
end
HuiShouOBJ.check = {
[1] = function(actor)
if getflagstatus(actor, VarCfg.Falg_tequan) == 0 then
return false
else
return true
end
end
}
function HuiShouOBJ:auto(actor, p1, p2, p3, data)
local itemData = data[1]
---* 物品回收
local givestbl = {}
for k, v in pairs(itemData or {}) do
local ItemName = getiteminfo(actor, v, ConstCfg.iteminfo.name)
if self.item[ItemName] then
local cfg = self.item[ItemName]
local _bool = true
if cfg.check then
local func = self.check[cfg.check]
if func then
_bool = func(actor)
end
end
if _bool then
local _num = getiteminfo(actor, v, 5)
_num = _num > 0 and _num or 1
if delitembymakeindex(actor, v, _num, "装备回收") then
for _, give in ipairs(cfg.Gives or {}) do
givestbl[give[1]] = (givestbl[give[1]] or 0) + (give[2] * _num)
end
if cfg.RandomGivesName then
local _random = math.random(1, #cfg.RandomGivesName)
local random_give_name = cfg.RandomGivesName[_random]
givestbl[random_give_name[1]] = (givestbl[random_give_name[1]] or 0) + (random_give_name[2] * _num)
end
for _, give in ipairs(cfg.GivesRandomNum or {}) do
givestbl[give[1]] = (givestbl[give[1]] or 0) + (math.random(give[2], give[3]) * _num)
end
end
end
end
end
local _falg = getflagstatus(actor, VarCfg.Falg_tequan) > 0 and true or false
local newGives = {}
if not _falg then
for k, v in pairs(givestbl or {}) do
local _index = getstditeminfo(k, ConstCfg.stditeminfo.idx)
if _index < 6 then
if string.find(k, "绑定", 1, true) == nil then
newGives["绑定" .. k] = (newGives["绑定" .. k] or 0) + v
else
newGives[k] = (newGives[k] or 0) + v
end
else
newGives[k] = (newGives[k] or 0) + v
end
end
else
newGives = givestbl
end
local huishoubeilv = getbaseinfo(actor, ConstCfg.gbase.custom_attr, 200)
local givestr = {}
for k, v in pairs(newGives or {}) do
local _index = getstditeminfo(k, ConstCfg.stditeminfo.idx)
if _index < 100 then
if _index == 1 or _index == 3 then
v = v + math.floor(v / 100 * huishoubeilv)
end
table.insert(givestr, string.format("%s#%d", k, v))
else
table.insert(givestr, string.format("%s#%d#%d", k, v, 370))
end
end
gives(actor, table.concat(givestr, "&"), "装备回收")
end
HuiShouOBJ.allowFunc = {"auto"}
return HuiShouOBJ