181 lines
4.7 KiB
Lua
181 lines
4.7 KiB
Lua
-- 背包模块
|
||
Bag = {}
|
||
|
||
|
||
|
||
----* 解锁背包格子
|
||
function closedbagitemclick(actor)
|
||
local count = GetBagMaxCount(actor)
|
||
if count < 126 then
|
||
Func.messagebox(actor, "解锁背包格子需要:#251|千年玄石x1#215|\\是否确认解锁?#249", "@diysetbagcount", "@exit", 16)
|
||
end
|
||
end
|
||
|
||
function diysetbagcount(actor)
|
||
local count = GetBagMaxCount(actor)
|
||
if count < 126 then
|
||
if takeitem(actor, "千年玄石", 1) then
|
||
setbagcount(actor, count + 1)
|
||
else
|
||
Func.sendmsg9(actor, "[提示]:#70|千年玄石#215|不足#251|1颗,#215|解锁失败!")
|
||
end
|
||
end
|
||
end
|
||
|
||
|
||
---* 解锁仓库格子
|
||
function Bag.changestorage(actor)
|
||
local count = getssize(actor)
|
||
if count < 240 then
|
||
Func.messagebox(actor, "解锁仓库格子需要:#251|千年玄石x1#215|\\是否确认解锁?#249", "@diysetstoragecount", "@exit", 16)
|
||
end
|
||
end
|
||
|
||
|
||
function diysetstoragecount(actor)
|
||
local count = getssize(actor)
|
||
if count < 240 then
|
||
if takeitem(actor, "千年玄石", 1) then
|
||
changestorage(actor, 1)
|
||
openstorage(actor)
|
||
openstorage(actor)
|
||
else
|
||
Func.sendmsg9(actor, "[提示]:#70|千年玄石#215|不足#251|1颗,#215|解锁失败!")
|
||
end
|
||
end
|
||
end
|
||
|
||
|
||
|
||
|
||
-- 获取物品数量
|
||
---@param actor userdata 角色对象
|
||
---@param idx number 物品索引
|
||
---@return number 物品数量
|
||
function Bag.getItemNumByIdx(actor, idx)
|
||
local count = 0
|
||
local item_num = getbaseinfo(actor, ConstCfg.gbase.bag_num)
|
||
for i = 0, item_num - 1 do
|
||
local itemobj = getiteminfobyindex(actor, i)
|
||
local itemidx = getiteminfo(actor, itemobj, ConstCfg.iteminfo.idx)
|
||
if itemidx == idx then
|
||
local item_mun = getiteminfo(actor, itemobj, ConstCfg.iteminfo.overlap)
|
||
if item_mun == 0 then
|
||
item_mun = 1
|
||
end
|
||
count = count + item_mun
|
||
end
|
||
end
|
||
|
||
return count
|
||
end
|
||
|
||
-- 检查物品数量
|
||
---@param actor userdata 角色对象
|
||
---@param idx number 物品索引
|
||
---@param num number 物品数量(可选,默认为1)
|
||
---@return boolean 是否拥有足够数量的物品
|
||
function Bag.checkItemNumByIdx(actor, idx, num)
|
||
num = num or 1
|
||
local count = Bag.getItemNumByIdx(actor, idx)
|
||
return count >= num
|
||
end
|
||
|
||
-- 获取背包空格数量
|
||
---@param actor userdata 角色对象
|
||
---@return number 背包空格数量
|
||
function Bag.getBagEmptyNum(actor)
|
||
local item_num = getbaseinfo(actor, ConstCfg.gbase.bag_num)
|
||
return ConstCfg.bagcellnum - item_num
|
||
end
|
||
|
||
-- 检查背包空格数量
|
||
---@param actor userdata 角色对象
|
||
---@param num number 所需空格数量
|
||
---@return boolean 是否拥有足够数量的空格
|
||
function Bag.checkBagEmptyNum(actor, num)
|
||
local empty_num = Bag.getBagEmptyNum(actor)
|
||
return empty_num >= num
|
||
end
|
||
|
||
-- 检查背包是否足够给予物品 items
|
||
---@param actor userdata 角色对象
|
||
---@param items table 物品列表,每个元素包含物品索引和数量
|
||
---@return boolean 是否拥有足够数量的空格
|
||
function Bag.checkBagEmptyItems(actor, items)
|
||
local bagEmptyNum = Bag.getBagEmptyNum(actor)
|
||
local needEmptyNum = 0
|
||
for _, item in ipairs(items) do
|
||
local idx, num = item[1], item[2]
|
||
if not Item.isCurrency(idx) then --物品 装备
|
||
needEmptyNum = needEmptyNum + 1
|
||
end
|
||
end
|
||
return bagEmptyNum >= needEmptyNum
|
||
end
|
||
|
||
-- 获取背包中某件物品对象
|
||
---@param actor userdata 角色对象
|
||
---@param idx number 物品索引
|
||
---@return userdata 物品对象
|
||
function Bag.getItemObjByIdx(actor, idx)
|
||
local item_num = getbaseinfo(actor, ConstCfg.gbase.bag_num)
|
||
for i = 0, item_num - 1 do
|
||
local itemobj = getiteminfobyindex(actor, i)
|
||
local itemidx = getiteminfo(actor, itemobj, ConstCfg.iteminfo.idx)
|
||
if itemidx == idx then
|
||
return itemobj
|
||
end
|
||
end
|
||
end
|
||
|
||
-- 获取背包中某件物品唯一id
|
||
---@param actor userdata 角色对象
|
||
---@param idx number 物品索引
|
||
---@return number 物品唯一id
|
||
function Bag.getItemMakeIdByIdx(actor, idx)
|
||
local itemobj = Bag.getItemObjByIdx(actor, idx)
|
||
if not itemobj then return end
|
||
return getiteminfo(actor, itemobj, ConstCfg.iteminfo.id)
|
||
end
|
||
|
||
-- 检查背包是否有某件物品的数量通过唯一id
|
||
---@param actor userdata 角色对象
|
||
---@param makeindex number 物品唯一id
|
||
---@param num number 物品数量(可选,默认为1)
|
||
---@return boolean 是否拥有足够数量的物品
|
||
function Bag.checkItemNumByMakeIndex(actor, makeindex, num)
|
||
num = num or 1
|
||
|
||
local item_num = getbaseinfo(actor, ConstCfg.gbase.bag_num)
|
||
for i = 0, item_num - 1 do
|
||
local itemobj = getiteminfobyindex(actor, i)
|
||
local itemmakeid = getiteminfo(actor, itemobj, ConstCfg.iteminfo.id)
|
||
if itemmakeid == makeindex then
|
||
if num > 1 then
|
||
local overlap = getiteminfo(actor, itemobj, ConstCfg.iteminfo.overlap)
|
||
if overlap < num then return false end
|
||
end
|
||
return true
|
||
end
|
||
end
|
||
|
||
return false
|
||
end
|
||
|
||
-- 获取背包中某件物品对象通过唯一ID
|
||
---@param actor userdata 角色对象
|
||
---@param makeindex number 物品唯一id
|
||
---@return userdata 物品对象
|
||
function Bag.getItemObjByMakeIndex(actor, makeindex)
|
||
local item_num = getbaseinfo(actor, ConstCfg.gbase.bag_num)
|
||
for i = 0, item_num - 1 do
|
||
local itemobj = getiteminfobyindex(actor, i)
|
||
local itemmakeindex = getiteminfo(actor, itemobj, ConstCfg.iteminfo.id)
|
||
if itemmakeindex == makeindex then
|
||
return itemobj
|
||
end
|
||
end
|
||
end
|
||
|
||
return Bag
|