Files
Main/Assets/GameAssets/Resources/Lua/Logic/Shop/ShopItemContainer.lua
2025-01-25 04:38:09 +08:00

101 lines
2.8 KiB
Lua
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

------------------------------------------------
--作者:何健
--日期2019-07-05
--文件ShopItemContainer.lua
--模块ShopItemContainer
--描述:各种商店的容器,包含了所有商店基本操作和数据
------------------------------------------------
local ShopItemContainer = {
--商店类型
ShopType = nil,
--物品容器
ItemContainer = nil,
--商店页面容器
ShopPageList = nil,
--下一个刷新时间
NextTimes = nil,
--当前刷新次数
CurUpdateTimes = nil,
}
--创建容器对象
function ShopItemContainer:New(type)
local _m = Utils.DeepCopy(self)
_m.ShopType = type
_m.ItemContainer = Dictionary:New()
_m.ShopPageList = List:New()
return _m
end
--更新商品容器
function ShopItemContainer:UpdateItem(item, page, occ)
if item ~= nil then
local _shopItems = nil
_shopItems = self.ItemContainer[page]
if _shopItems == nil then
_shopItems = Dictionary:New()
self.ItemContainer:Add(page, _shopItems)
end
if _shopItems ~= nil and item:CheckOcc(occ) and item:CheckOpenTime() then
local _tmpItem = nil;
_tmpItem = _shopItems[item.SellId]
if _tmpItem ~= nil then
_shopItems[item.SellId] = item
else
_shopItems:Add(item.SellId, item)
end
self.ItemContainer[page] = _shopItems
end
end
end
function ShopItemContainer:Sort(page)
local _shopItems = nil
_shopItems = self.ItemContainer[page]
if _shopItems ~= nil then
for k, v in pairs(_shopItems) do
if v.LimitType > 0 then
if v.AlreadyBuyNum >= v.BuyLimit and v.BuyLimit > 0 and v.Index <= 99999 then
v.Index = v.Index + 99999
end
end
end
_shopItems:SortValue(function(a, b)
return a.Index < b.Index
end)
self.ItemContainer[page] = _shopItems
end
end
--删除商品
function ShopItemContainer:DeleteItem(key, page)
if self.ItemContainer[page] ~= nil then
self.ItemContainer[page]:Remove(key)
end
end
function ShopItemContainer:AddShopPage(page)
if page > 0 and not self.ShopPageList:Contains(page) then
self.ShopPageList:Add(page)
end
end
function ShopItemContainer:ClearShopPage()
self.ShopPageList:Clear()
end
function ShopItemContainer:ClearShopByPage(page)
if self.ItemContainer:ContainsKey(page) then
self.ItemContainer[page]:Clear()
end
end
function ShopItemContainer:GetShopItemDic(page)
local _shopItems = Dictionary:New()
if self.ItemContainer:ContainsKey(page) then
_shopItems = self.ItemContainer[page]
end
return _shopItems
end
return ShopItemContainer