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

313 lines
11 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-08
--文件ShopManager.lua
--模块ShopManager
--描述:商店逻辑及数据管理类
------------------------------------------------
local L_ShopData = require("Logic.Shop.ShopData")
local L_HouseShopData = require("Logic.Shop.HouseShopData")
local L_ShopContainer = require("Logic.Shop.ShopItemContainer")
local ShopManager = {
ShopContainer = Dictionary:New(),
LabelIDDic = Dictionary:New(),
ShopCfgDic = Dictionary:New(),
--社区商城的商品列表 以商品ID为索引
HouseShopDic = Dictionary:New(),
--社区商城商品ID列表 以商城ID为索引
HouseTypeDic = Dictionary:New(),
IsBuyComfirm = true,
IsBuyComfirmForHouse = true,
}
--加载
function ShopManager:Initialize()
self.IsBuyComfirm = true
self.IsBuyComfirmForHouse = true
self.HouseShopDic = Dictionary:New()
self.HouseTypeDic = Dictionary:New()
end
--卸载
function ShopManager:UnInitialize()
self.ShopContainer:Clear()
self.HouseShopDic:Clear()
self.HouseTypeDic:Clear()
end
--初始化数据字典
function ShopManager:InitShopLabelDic()
if #self.ShopCfgDic > 0 then
return
end
DataConfig.DataShopMaket:Foreach(function(k, v)
if not self.LabelIDDic:ContainsKey(v.LabelID) then
self.LabelIDDic:Add(v.LabelID, v.Type)
end
if self.ShopCfgDic:ContainsKey(v.LabelID) then
self.ShopCfgDic[v.LabelID]:Add(v)
else
local _list = List:New()
_list:Add(v)
self.ShopCfgDic:Add(v.LabelID, _list)
end
end)
end
--获取当前VIP特权折扣
function ShopManager:GetCurDisCount()
local _disCount = 10
local _cfg = DataConfig.DataVIPTrueRecharge[GameCenter.VipSystem:GetCurTrueVipCfgId()]
if _cfg then
if _cfg.TrueRewardPowerPra and string.len(_cfg.TrueRewardPowerPra) > 0 then
local _ar = Utils.SplitStr(_cfg.TrueRewardPowerPra, ';')
for i = 1, #_ar do
local _single = Utils.SplitNumber(_ar[i], '_')
if #_single >= 3 and _single[1] == 28 then
_disCount = _single[3]
end
end
end
end
return _disCount
end
--查看商店是否是本地商店
function ShopManager:GetLabelIsLocal(page)
self:InitShopLabelDic()
if self.LabelIDDic:ContainsKey(page) then
return self.LabelIDDic[page] == 0
end
return false
end
--获取对应的商店容器
function ShopManager:GetShopItemContainer(type)
local _spContainer = self.ShopContainer[type]
if not _spContainer then
_spContainer = L_ShopContainer:New(type)
self.ShopContainer:Add(type, _spContainer)
end
return _spContainer
end
--更新对应商店容器
function ShopManager:UpdateShopItemInContainer(itemInfo, page, type, sort, occ)
local _spContainer = self:GetShopItemContainer(type)
if _spContainer ~= nil and itemInfo ~= nil then
if itemInfo.sellId ~= nil then
_spContainer:UpdateItem(L_ShopData:NewWithData(itemInfo), page)
elseif itemInfo.GuildShopLvlStart then
_spContainer:UpdateItem(L_ShopData:NewWithCfg(itemInfo), page, occ)
else
_spContainer:UpdateItem(L_ShopData:New(itemInfo), page)
end
if sort then
_spContainer:Sort(page)
end
end
end
--设置商店物品列表的基础数据
function ShopManager:SetShopItemByContainer(page, type, sort)
self:InitShopLabelDic()
local _spContainer = self:GetShopItemContainer(type)
local _lp = GameCenter.GameSceneSystem:GetLocalPlayer()
local _shopLv = GameCenter.GuildSystem:OnGetGuildLevel(GuildBuildEnum.GuildShop)
if _spContainer ~= nil and _lp then
if self.ShopCfgDic:ContainsKey(page) then
local _list = self.ShopCfgDic[page]
for i = 1, #_list do
if _lp.Level >= _list[i].Level and _shopLv >= _list[i].GuildShopLvlStart and _shopLv <= _list[i].GuildShopLvlEND then
self:UpdateShopItemInContainer(_list[i], page, type, false, _lp.IntOcc)
end
end
end
end
end
--删除商品容器中的商品
function ShopManager:DeleteShopItemInContainer(sellId, page, type)
local _spContainer = self:GetShopItemContainer(type)
if _spContainer ~= nil then
_spContainer:DeleteItem(sellId, page)
end
end
--改变商品容器中的商品购买数
function ShopManager:ChangeShopItemInContainer(sellId, page, type, overBuyNo, sort)
local _spContainer = self:GetShopItemContainer(type)
if _spContainer ~= nil then
local _itemDic = _spContainer:GetShopItemDic(page)
if _itemDic:ContainsKey(sellId) then
_itemDic[sellId].AlreadyBuyNum = overBuyNo
_itemDic[sellId]:SetAddPrice()
end
if sort then
_spContainer:Sort(page)
end
end
end
--请求商品列表
--shopid 商城大标签
--labelid 子商城标签
function ShopManager:ReqShopItemList(shopId, labelId)
GameCenter.Network.Send("MSG_Shop.ReqShopList", {shopId = shopId, labelId = labelId, gradeLimit = 0})
end
--商品列表下发
function ShopManager:GS2U_ResShopItemList(result)
if result then
local _spContainer = nil
local _type = result.shopId
local _lp = GameCenter.GameSceneSystem:GetLocalPlayer()
_spContainer = self:GetShopItemContainer(_type)
if _spContainer and _lp then
_spContainer:ClearShopByPage(result.labelId)
if result.itemList then
for idx = 1, #result.itemList do
local shopItem = result.itemList[idx]
self:UpdateShopItemInContainer(shopItem, result.labelId, _type, false, _lp.IntOcc)
end
end
if result.dataList then
for idx = 1, #result.dataList do
local shopItem = result.dataList[idx]
if self:GetLabelIsLocal(result.labelId) then
local _cfg = DataConfig.DataShopMaket[shopItem.sellId]
if _cfg then
self:UpdateShopItemInContainer(_cfg, result.labelId, _type, false, _lp.IntOcc)
end
end
self:ChangeShopItemInContainer(shopItem.sellId, result.labelId, _type, shopItem.buyNum)
end
end
_spContainer:Sort(result.labelId)
end
GameCenter.PushFixEvent(LogicLuaEventDefine.EID_EVENT_SHOPFORM_UPDATEPAGE, result.labelId, true)
end
end
--商品购买次数更新
function ShopManager:SyncShopData(result)
self:ChangeShopItemInContainer(result.data.sellId, result.labelId, result.shopId, result.data.buyNum, true)
GameCenter.PushFixEvent(LogicLuaEventDefine.EID_EVENT_SHOPFORM_UPDATEPAGE, result.labelId)
end
--购买成功
function ShopManager:GS2U_ResBuySuccess(result)
Utils.ShowPromptByEnum("C_SHOP_TIPS_BUYSUXESSSSSS")
CS.Thousandto.Core.Asset.AudioPlayer.PlayUI("snd_ui_wupingoumai")
end
--购买失败
function ShopManager:ResBuyFailure(result)
if result then
if result.reason == 1 then
Utils.ShowPromptByEnum("NonexistentGoods")
elseif result.reason == 2 then
Utils.ShowPromptByEnum("NonexistentItems")
elseif result.reason == 3 then
Utils.ShowPromptByEnum("GoodsSoldOut")
elseif result.reason == 4 then
Utils.ShowPromptByEnum("BuyFailByLevelLower")
elseif result.reason == 5 then
Utils.ShowPromptByEnum("BuyFailBySectLower")
elseif result.reason == 6 then
Utils.ShowPromptByEnum("BuyFailByMilitaryLower")
elseif result.reason == 7 then
Utils.ShowPromptByEnum("BuyFailVipLevelLower")
elseif result.reason == 8 then
Utils.ShowPromptByEnum("BuyFailByNoMoney")
elseif result.reason == 10 then
Utils.ShowPromptByEnum("BuyFailByBagNoSpace")
end
end
end
--商店标签列表
function ShopManager:GS2U_ResShopSubList(result)
if result and result.sublist then
for idx = 1, #result.sublist do
local subMess = result.sublist[idx]
local _type = subMess.shopId
local _spContainer = nil
_spContainer = self:GetShopItemContainer(_type)
if _spContainer then
_spContainer:ClearShopPage()
for jdx = 1, #subMess.labelList do
_spContainer:AddShopPage(subMess.labelList[jdx])
end
end
end
GameCenter.PushFixEvent(LogicLuaEventDefine.EID_EVENT_SHOPFORM_UPDATEPAGEBTN)
end
end
--更新单个商品
function ShopManager:ResFreshItemInfo(result)
if result then
self:UpdateShopItemInContainer(result.itemInfo, result.itemInfo.labelId, result.itemInfo.shopId, true)
GameCenter.PushFixEvent(LogicLuaEventDefine.EID_EVENT_SHOPFORM_UPDATEPAGE, result.itemInfo.labelId)
end
end
--根据Functionstarid打开商城界面
function ShopManager:OpenShopMallPanel(functionID, param)
local _funcInfo = GameCenter.MainFunctionSystem:GetFunctionInfo(functionID)
if _funcInfo then
if _funcInfo.Parent.ID == FunctionStartIdCode.GoldShop then
GameCenter.PushFixEvent(UIEventDefine.UIShopMallForm_OPEN, {ShopPanelEnum.GoldShop, functionID, param})
end
if _funcInfo.Parent.ID == FunctionStartIdCode.ExchangeShop then
GameCenter.PushFixEvent(UIEventDefine.UIShopMallForm_OPEN, {ShopPanelEnum.ExchangeShop, functionID, param})
end
end
end
--社区商城列表下发
function ShopManager:ResHomeShopGoods(msg)
if msg.goods then
self.HouseShopDic:Clear()
self.HouseTypeDic:Clear()
for i = 1, #msg.goods do
local _item = L_HouseShopData:New(msg.goods[i].goodsId, msg.goods[i].remain)
if _item then
self.HouseShopDic:Add(_item.SellId, _item)
if self.HouseTypeDic:ContainsKey(_item.ShopID) then
self.HouseTypeDic[_item.ShopID]:Add(_item.SellId)
else
local _list = List:New()
_list:Add(_item.SellId)
self.HouseTypeDic:Add(_item.ShopID, _list)
end
end
end
end
GameCenter.PushFixEvent(LogicLuaEventDefine.EID_EVENT_HOUSESHOP_UPDATE)
end
--社区商城商品更新
function ShopManager:ResUpdateHomeShopGoods(msg)
if msg.goods then
local _item = L_HouseShopData:New(msg.goods.goodsId, msg.goods.remain)
if _item then
if self.HouseShopDic:ContainsKey(_item.SellId) then
self.HouseShopDic[_item.SellId] = _item
else
self.HouseShopDic:Add(_item.SellId, _item)
if self.HouseTypeDic:ContainsKey(_item.ShopID) then
self.HouseTypeDic[_item.ShopID]:Add(_item.SellId)
else
local _list = List:New()
_list:Add(_item.SellId)
self.HouseTypeDic:Add(_item.ShopID, _list)
end
end
end
end
GameCenter.PushFixEvent(LogicLuaEventDefine.EID_EVENT_HOUSESHOPDATA_UPDATE)
end
return ShopManager