324 lines
13 KiB
Lua
324 lines
13 KiB
Lua
|
------------------------------------------------
|
|||
|
--作者: HJ
|
|||
|
--日期: 2021-03-03
|
|||
|
--文件: NewItemContianerSystem.lua
|
|||
|
--模块: NewItemContianerSystem
|
|||
|
--描述: 背包管理
|
|||
|
------------------------------------------------
|
|||
|
local L_ContianerModel = require("Logic.Item.ItemContianerModel")
|
|||
|
local L_ItemBase = CS.Thousandto.Code.Logic.ItemBase
|
|||
|
local NewItemContianerSystem = {
|
|||
|
CacheList = List:New(),
|
|||
|
ItemContianerDic = Dictionary:New(),
|
|||
|
}
|
|||
|
|
|||
|
--根据容器类型获取容器信息
|
|||
|
function NewItemContianerSystem:GetBackpackModelByType(type)
|
|||
|
return self.ItemContianerDic[type];
|
|||
|
end
|
|||
|
|
|||
|
--设置容器
|
|||
|
function NewItemContianerSystem:SetBackpackModelByType(type, model)
|
|||
|
if model and LuaContainerType.ITEM_LOCATION_COUNT > type then
|
|||
|
self.ItemContianerDic:Add(type, model);
|
|||
|
end
|
|||
|
end
|
|||
|
|
|||
|
--根据UID以及容器类型 获取物品信息
|
|||
|
function NewItemContianerSystem:GetItemByUID(type, uid)
|
|||
|
local retItem = nil;
|
|||
|
local bpModel = self:GetBackpackModelByType(type)
|
|||
|
if bpModel then
|
|||
|
retItem = bpModel:GetItemByUID(uid)
|
|||
|
end
|
|||
|
return retItem;
|
|||
|
end
|
|||
|
|
|||
|
function NewItemContianerSystem:GetItemListNOGC(type)
|
|||
|
self.CacheList:Clear()
|
|||
|
local bpModel = self:GetBackpackModelByType(type)
|
|||
|
if bpModel then
|
|||
|
bpModel.ItemsOfIndex:Foreach(function(k, v)
|
|||
|
if v then
|
|||
|
self.CacheList:Add(v)
|
|||
|
end
|
|||
|
end)
|
|||
|
end
|
|||
|
return self.CacheList
|
|||
|
end
|
|||
|
|
|||
|
--更新物品
|
|||
|
function NewItemContianerSystem:UpdateItemFromContainer(type, item, isNew, resonCode, pushEvent)
|
|||
|
if not resonCode then
|
|||
|
resonCode = 0
|
|||
|
end
|
|||
|
if pushEvent == nil then
|
|||
|
pushEvent = true
|
|||
|
end
|
|||
|
if item.cdTime and item.cdTime > 0 then
|
|||
|
item.cdTime = item.cdTime / 1000
|
|||
|
end
|
|||
|
local retIndex = -1;
|
|||
|
local bpModel = self:GetBackpackModelByType(type);
|
|||
|
if bpModel and item then
|
|||
|
local itemBase = nil;
|
|||
|
itemBase = LuaItemBase.CreateItemBaseByMsg(item)
|
|||
|
if itemBase and itemBase.Type == ItemType.ImmortalEquip and type == LuaContainerType.ITEM_LOCATION_BACKEQUIP then
|
|||
|
itemBase.Index = itemBase.Part;
|
|||
|
end
|
|||
|
itemBase.IsNew = isNew;
|
|||
|
|
|||
|
if (isNew and type == LuaContainerType.ITEM_LOCATION_BAG) then
|
|||
|
--引导检测
|
|||
|
GameCenter.GuideSystem:Check(GuideTriggerType.GetItem, item.itemModelId);
|
|||
|
end
|
|||
|
if itemBase then
|
|||
|
itemBase.ContainerType = type;
|
|||
|
if (type == LuaContainerType.ITEM_LOCATION_PETEQUIP or type == LuaContainerType.ITEM_LOCATION_MOUNTEQUIP or type == LuaContainerType.ITEM_LOCATION_DEVILEQUIP or type == LuaContainerType.ITEM_LOCATION_PEREAL or type == LuaContainerType.ITEM_LOCATION_IMMORTAL) then
|
|||
|
itemBase.Index = bpModel:GetNewImmortalEquipIndex();
|
|||
|
end
|
|||
|
local _oldCount = 0
|
|||
|
local _oldItem = bpModel:GetItemByUID(itemBase.DBID);
|
|||
|
if _oldItem ~= nil then
|
|||
|
_oldCount = _oldItem.Count
|
|||
|
end
|
|||
|
local _newCount = itemBase.Count
|
|||
|
retIndex = bpModel:UpdateItem(itemBase);
|
|||
|
if(type == LuaContainerType.ITEM_LOCATION_BAG or type == LuaContainerType.ITEM_LOCATION_IMMORTAL) then
|
|||
|
GameCenter.GetNewItemSystem:AddShowTips(itemBase, resonCode, _newCount - _oldCount)
|
|||
|
end
|
|||
|
end
|
|||
|
if pushEvent then
|
|||
|
self:UpdateContianerItems(type, itemBase);
|
|||
|
end
|
|||
|
end
|
|||
|
return retIndex;
|
|||
|
end
|
|||
|
|
|||
|
--更新物品时,向对应容器发送更新信息
|
|||
|
function NewItemContianerSystem:UpdateContianerItems(type, obj)
|
|||
|
if type == LuaContainerType.ITEM_LOCATION_BAG or type == LuaContainerType.ITEM_LOCATION_IMMORTAL then
|
|||
|
GameCenter.PushFixEvent(LogicEventDefine.EVENT_BACKFORM_ITEM_UPDATE, obj);
|
|||
|
elseif type == LuaContainerType.ITEM_LOCATION_STORAGE then
|
|||
|
GameCenter.PushFixEvent(LogicEventDefine.EVENT_STORAGE_ITEM_UPDATE, obj);
|
|||
|
elseif type == LuaContainerType.ITEM_LOCATION_EQUIP or type == LuaContainerType.ITEM_LOCATION_BACKEQUIP then
|
|||
|
GameCenter.PushFixEvent(LogicEventDefine.EVENT_EQUIPMENTFORM_ITEM_UPDATE, obj);
|
|||
|
elseif type == LuaContainerType.ITEM_LOCATION_CLEAR then
|
|||
|
GameCenter.PushFixEvent(LogicEventDefine.EID_EVENT_CLEARBAG_UPDATE, obj);
|
|||
|
end
|
|||
|
end
|
|||
|
|
|||
|
--删除道具
|
|||
|
function NewItemContianerSystem:DeleteItemFromContainer(type, uid)
|
|||
|
local bpModel = self:GetBackpackModelByType(type);
|
|||
|
if bpModel then
|
|||
|
local item = bpModel:GetItemByUID(uid)
|
|||
|
bpModel:DeleteItem(uid);
|
|||
|
|
|||
|
--删除一个物品成功后,需要关闭tips
|
|||
|
GameCenter.ItemTipsMgr:Close()
|
|||
|
|
|||
|
self:UpdateContianerItems(type, item);
|
|||
|
GameCenter.PushFixEvent(LogicEventDefine.EID_EVENT_BACKFORM_ITEM_UNSELCT);
|
|||
|
end
|
|||
|
end
|
|||
|
|
|||
|
--整理背包,客户端自行整理\
|
|||
|
function NewItemContianerSystem:SortBag(type)
|
|||
|
local bpModel = self:GetBackpackModelByType(type);
|
|||
|
if bpModel then
|
|||
|
bpModel:SortBag()
|
|||
|
end
|
|||
|
end
|
|||
|
|
|||
|
------------------------宠物装备网络消息begin--------------------------
|
|||
|
--宠物装备背包新增
|
|||
|
function NewItemContianerSystem:ResPetEquipAdd(result)
|
|||
|
if result.itemInfo then
|
|||
|
self:UpdateItemFromContainer(LuaContainerType.ITEM_LOCATION_PETEQUIP, result.itemInfo, true, result.reason, true);
|
|||
|
|
|||
|
--发送新物品消息
|
|||
|
local itemBase = self:GetItemByUID(LuaContainerType.ITEM_LOCATION_PETEQUIP, result.itemInfo.itemId);
|
|||
|
if itemBase == nil then
|
|||
|
return;
|
|||
|
end
|
|||
|
|
|||
|
--展示物品获取效果
|
|||
|
GameCenter.GetNewItemSystem:AddShowItem(result.reason, itemBase:GetCSObj(), itemBase.CfgID, itemBase.Count)
|
|||
|
end
|
|||
|
GameCenter.PushFixEvent(LogicLuaEventDefine.EVENT_PETEQUIP_BAGCHANGE);
|
|||
|
end
|
|||
|
|
|||
|
|
|||
|
--宠物装备背包删除
|
|||
|
function NewItemContianerSystem:ResPetEquipDelete(result)
|
|||
|
self:DeleteItemFromContainer(LuaContainerType.ITEM_LOCATION_PETEQUIP, result.itemId);
|
|||
|
GameCenter.PushFixEvent(LogicLuaEventDefine.EVENT_PETEQUIP_BAGCHANGE);
|
|||
|
end
|
|||
|
|
|||
|
--宠物装备背包物品信息,上线时推送给玩家
|
|||
|
function NewItemContianerSystem:ResPetEquipBagInfos(result)
|
|||
|
local imModel = self:GetBackpackModelByType(LuaContainerType.ITEM_LOCATION_PETEQUIP);
|
|||
|
if imModel == nil then
|
|||
|
imModel = L_ContianerModel:New()
|
|||
|
imModel.ContainerType = LuaContainerType.ITEM_LOCATION_PETEQUIP;
|
|||
|
self:SetBackpackModelByType(LuaContainerType.ITEM_LOCATION_PETEQUIP, imModel);
|
|||
|
end
|
|||
|
imModel:Clear();
|
|||
|
imModel.AllCount = 200;
|
|||
|
imModel.OpenedCount = 200;
|
|||
|
if result.itemInfoList then
|
|||
|
for i = 1, #result.itemInfoList do
|
|||
|
self:UpdateItemFromContainer(LuaContainerType.ITEM_LOCATION_PETEQUIP, result.itemInfoList[i], true, 0, true);
|
|||
|
end
|
|||
|
end
|
|||
|
GameCenter.PushFixEvent(LogicLuaEventDefine.EVENT_PETEQUIP_BAGCHANGE);
|
|||
|
end
|
|||
|
|
|||
|
------------------------宠物装备网络消息end--------------------------
|
|||
|
|
|||
|
------------------------坐骑装备网络消息begin--------------------------
|
|||
|
--坐骑装备背包新增
|
|||
|
function NewItemContianerSystem:ResHorseEquipAdd(result)
|
|||
|
if result.itemInfo then
|
|||
|
self:UpdateItemFromContainer(LuaContainerType.ITEM_LOCATION_MOUNTEQUIP, result.itemInfo, true, result.reason, true);
|
|||
|
|
|||
|
--发送新物品消息
|
|||
|
local itemBase = self:GetItemByUID(LuaContainerType.ITEM_LOCATION_MOUNTEQUIP, result.itemInfo.itemId);
|
|||
|
if itemBase == nil then
|
|||
|
return;
|
|||
|
end
|
|||
|
|
|||
|
--展示物品获取效果
|
|||
|
GameCenter.GetNewItemSystem:AddShowItem(result.reason, itemBase:GetCSObj(), itemBase.CfgID, itemBase.Count)
|
|||
|
end
|
|||
|
GameCenter.PushFixEvent(LogicLuaEventDefine.EVENT_MOUNTEQUIP_BAGCHANGE);
|
|||
|
end
|
|||
|
|
|||
|
|
|||
|
--坐骑装备背包删除
|
|||
|
function NewItemContianerSystem:ResHorseEquipDelete(result)
|
|||
|
self:DeleteItemFromContainer(LuaContainerType.ITEM_LOCATION_MOUNTEQUIP, result.itemId);
|
|||
|
GameCenter.PushFixEvent(LogicLuaEventDefine.EVENT_MOUNTEQUIP_BAGCHANGE);
|
|||
|
end
|
|||
|
|
|||
|
--坐骑装备背包物品信息,上线时推送给玩家
|
|||
|
function NewItemContianerSystem:ResHorseEquipBagInfos(result)
|
|||
|
local imModel = self:GetBackpackModelByType(LuaContainerType.ITEM_LOCATION_MOUNTEQUIP);
|
|||
|
if imModel == nil then
|
|||
|
imModel = L_ContianerModel:New()
|
|||
|
imModel.ContainerType = LuaContainerType.ITEM_LOCATION_MOUNTEQUIP;
|
|||
|
self:SetBackpackModelByType(LuaContainerType.ITEM_LOCATION_MOUNTEQUIP, imModel);
|
|||
|
end
|
|||
|
imModel:Clear();
|
|||
|
imModel.AllCount = 200;
|
|||
|
imModel.OpenedCount = 200;
|
|||
|
if result.itemInfoList then
|
|||
|
for i = 1, #result.itemInfoList do
|
|||
|
self:UpdateItemFromContainer(LuaContainerType.ITEM_LOCATION_MOUNTEQUIP, result.itemInfoList[i], true, 0, true);
|
|||
|
end
|
|||
|
end
|
|||
|
GameCenter.PushFixEvent(LogicLuaEventDefine.EVENT_MOUNTEQUIP_BAGCHANGE);
|
|||
|
end
|
|||
|
------------------------坐骑装备网络消息end--------------------------
|
|||
|
|
|||
|
------------------------魔魂装备网络消息begin--------------------------
|
|||
|
--魔魂装备背包新增
|
|||
|
function NewItemContianerSystem:ResDevilEquipAdd(result)
|
|||
|
if result.itemInfo then
|
|||
|
self:UpdateItemFromContainer(LuaContainerType.ITEM_LOCATION_DEVILEQUIP, result.itemInfo, true, result.reason, true);
|
|||
|
|
|||
|
--发送新物品消息
|
|||
|
local itemBase = self:GetItemByUID(LuaContainerType.ITEM_LOCATION_DEVILEQUIP, result.itemInfo.itemId);
|
|||
|
if itemBase == nil then
|
|||
|
return;
|
|||
|
end
|
|||
|
|
|||
|
--展示物品获取效果
|
|||
|
GameCenter.GetNewItemSystem:AddShowItem(result.reason, itemBase:GetCSObj(), itemBase.CfgID, itemBase.Count)
|
|||
|
end
|
|||
|
GameCenter.PushFixEvent(LogicLuaEventDefine.EID_EVENT_DEVILEQUIP_BAGCHANGE);
|
|||
|
end
|
|||
|
|
|||
|
|
|||
|
--魔魂装备背包删除
|
|||
|
function NewItemContianerSystem:ResDevilEquipDelete(result)
|
|||
|
self:DeleteItemFromContainer(LuaContainerType.ITEM_LOCATION_DEVILEQUIP, result.itemId);
|
|||
|
GameCenter.PushFixEvent(LogicLuaEventDefine.EID_EVENT_DEVILEQUIP_BAGCHANGE);
|
|||
|
end
|
|||
|
|
|||
|
--魔魂装备背包物品信息,上线时推送给玩家
|
|||
|
function NewItemContianerSystem:ResDevilEquipBagInfos(result)
|
|||
|
local imModel = self:GetBackpackModelByType(LuaContainerType.ITEM_LOCATION_DEVILEQUIP);
|
|||
|
if imModel == nil then
|
|||
|
imModel = L_ContianerModel:New()
|
|||
|
imModel.ContainerType = LuaContainerType.ITEM_LOCATION_DEVILEQUIP;
|
|||
|
self:SetBackpackModelByType(LuaContainerType.ITEM_LOCATION_DEVILEQUIP, imModel);
|
|||
|
end
|
|||
|
imModel:Clear();
|
|||
|
imModel.AllCount = 200;
|
|||
|
imModel.OpenedCount = 200;
|
|||
|
if result.itemInfoList then
|
|||
|
for i = 1, #result.itemInfoList do
|
|||
|
self:UpdateItemFromContainer(LuaContainerType.ITEM_LOCATION_DEVILEQUIP, result.itemInfoList[i], true, 0, true);
|
|||
|
end
|
|||
|
end
|
|||
|
GameCenter.PushFixEvent(LogicLuaEventDefine.EID_EVENT_DEVILEQUIP_BAGCHANGE);
|
|||
|
end
|
|||
|
------------------------魔魂装备网络消息end--------------------------
|
|||
|
|
|||
|
------------------------魂印背包网络消息begin------------------------
|
|||
|
--背包新增
|
|||
|
function NewItemContianerSystem:ResAddSoulArmorBall(result)
|
|||
|
if result.balls then
|
|||
|
for i = 1, #result.balls do
|
|||
|
self:UpdateItemFromContainer(LuaContainerType.ITEM_LOCATION_PEREAL, result.balls[i], true, result.reason, true);
|
|||
|
--发送新物品消息
|
|||
|
local itemBase = self:GetItemByUID(LuaContainerType.ITEM_LOCATION_PEREAL, result.balls[i].itemId);
|
|||
|
if itemBase == nil then
|
|||
|
return;
|
|||
|
end
|
|||
|
--展示物品获取效果
|
|||
|
GameCenter.GetNewItemSystem:AddShowItem(result.reason, itemBase:GetCSObj(), itemBase.CfgID, itemBase.Count)
|
|||
|
end
|
|||
|
end
|
|||
|
GameCenter.PushFixEvent(LogicLuaEventDefine.EVENT_SOULEQUIPPERAL_BAGCHANGE);
|
|||
|
end
|
|||
|
|
|||
|
--背包删除
|
|||
|
function NewItemContianerSystem:ResDelSoulArmorBall(result)
|
|||
|
if result.ids then
|
|||
|
for i = 1, #result.ids do
|
|||
|
self:DeleteItemFromContainer(LuaContainerType.ITEM_LOCATION_PEREAL, result.ids[i]);
|
|||
|
end
|
|||
|
end
|
|||
|
GameCenter.PushFixEvent(LogicLuaEventDefine.EVENT_SOULEQUIPPERAL_BAGCHANGE);
|
|||
|
end
|
|||
|
|
|||
|
--背包物品信息,上线时推送给玩家
|
|||
|
function NewItemContianerSystem:ResSoulArmorBag(result)
|
|||
|
local imModel = self:GetBackpackModelByType(LuaContainerType.ITEM_LOCATION_PEREAL);
|
|||
|
if imModel == nil then
|
|||
|
imModel = L_ContianerModel:New();
|
|||
|
imModel.ContainerType = LuaContainerType.ITEM_LOCATION_PEREAL
|
|||
|
self:SetBackpackModelByType(LuaContainerType.ITEM_LOCATION_PEREAL, imModel);
|
|||
|
end
|
|||
|
imModel:Clear();
|
|||
|
local gCfg = DataConfig.DataGlobal[GlobalName.Born_Bag_Num]
|
|||
|
if gCfg then
|
|||
|
local ar = Utils.SplitStr(gCfg.Params, '_')
|
|||
|
if #ar >= 2 then
|
|||
|
local AllNum = tonumber(ar[2]);
|
|||
|
imModel.AllCount = AllNum;
|
|||
|
imModel.OpenedCount = AllNum;
|
|||
|
end
|
|||
|
end
|
|||
|
if result.balls then
|
|||
|
for i = 1, #result.balls do
|
|||
|
self:UpdateItemFromContainer(LuaContainerType.ITEM_LOCATION_PEREAL, result.balls[i], true, 0, true);
|
|||
|
end
|
|||
|
end
|
|||
|
GameCenter.PushFixEvent(LogicLuaEventDefine.EVENT_SOULEQUIPPERAL_BAGCHANGE);
|
|||
|
end
|
|||
|
------------------------魂印背包网络消息end--------------------------
|
|||
|
return NewItemContianerSystem
|