441 lines
16 KiB
Lua
441 lines
16 KiB
Lua
------------------------------------------------
|
||
--作者: yangqf
|
||
--日期: 2021-02-22
|
||
--文件: GetNewItemSystem.lua
|
||
--模块: GetNewItemSystem
|
||
--描述: 新物品获取展示系统
|
||
------------------------------------------------
|
||
|
||
local GetNewItemSystem = {
|
||
--在界面上需要显示的物品信息
|
||
FormItemList = List:New(),
|
||
FormItemDelayTime = -1,
|
||
--在界面上显示物品信息的缓存,再本次显示不了的时候等待显示关闭后继续显示
|
||
FormItemCache = List:New(),
|
||
--装备展示队列
|
||
NewEquipQueue = List:New(),
|
||
ForceShowEquipTimer = 0,
|
||
--离线经验道具
|
||
AddOnHookTimeItemID = {1031, 1004},
|
||
AddOnHookTimeItemTime = {7200, 18000},
|
||
--离线经验最大时间
|
||
MaxOnHookTime = 0,
|
||
--boss宝箱展示的物品
|
||
BossBoxItemList = List:New(),
|
||
--装备展示倒计时
|
||
NewEquipTimer = 0,
|
||
--忽略的原因码
|
||
IngoreResons = {},
|
||
--暂停弹出提示
|
||
PauseGetNewItemTips = false,
|
||
|
||
--当前展示的红装
|
||
NeedShowRedEquip = nil,
|
||
--首次获得红装需要提示的ID
|
||
NeedTipsEquipIDlist = nil,
|
||
--已经显示过的装备ID
|
||
ShowTipsEquipIDlist = nil,
|
||
|
||
ItemTipsUIId = nil,
|
||
EquipTipsUIId = nil,
|
||
FirstEquipTipsUIId = nil,
|
||
}
|
||
|
||
function GetNewItemSystem:Initialize()
|
||
local _gCfg = DataConfig.DataGlobal[GlobalName.OnHookMaxNum]
|
||
if _gCfg ~= nil then
|
||
self.MaxOnHookTime = tonumber(_gCfg.Params)
|
||
self.MaxOnHookTime = self.MaxOnHookTime * 60
|
||
end
|
||
self.NeedTipsEquipIDlist = List:New()
|
||
_gCfg = DataConfig.DataGlobal[GlobalName.Special_Red_Equip_title]
|
||
if _gCfg ~= nil then
|
||
local _ids = Utils.SplitNumber(_gCfg.Params, '_')
|
||
for i = 1, #_ids do
|
||
self.NeedTipsEquipIDlist:Add(_ids[i])
|
||
end
|
||
end
|
||
self.PauseGetNewItemTips = false
|
||
self.ItemTipsUIId = GameCenter.FormStateSystem:EventIDToFormID(UnityUtils.GetObjct2Int(UIEventDefine.UIITEMGET_TIPS_OPEN))
|
||
self.EquipTipsUIId = GameCenter.FormStateSystem:EventIDToFormID(UnityUtils.GetObjct2Int(UIEventDefine.UIEQUIPGET_TIPS_OPEN))
|
||
self.FirstEquipTipsUIId = GameCenter.FormStateSystem:EventIDToFormID(UnityUtils.GetObjct2Int(UIEventDefine.UIFirstGetEquipForm_OPEN))
|
||
end
|
||
|
||
function GetNewItemSystem:UnInitialize()
|
||
self.FormItemList:Clear()
|
||
self.FormItemCache:Clear()
|
||
self.BossBoxItemList:Clear()
|
||
end
|
||
|
||
--增加忽略的原因码
|
||
function GetNewItemSystem:AddIngoreReson(reason)
|
||
self.IngoreResons[reason] = true
|
||
end
|
||
|
||
--删除忽略的原因码
|
||
function GetNewItemSystem:RemoveIngoreReson(reason)
|
||
self.IngoreResons[reason] = nil
|
||
end
|
||
|
||
--添加展示的物品
|
||
function GetNewItemSystem:AddShowItem(reason, itemInst, itemID, addCount)
|
||
if self.IngoreResons[reason] ~= nil then
|
||
return
|
||
end
|
||
local _reasonCfg = DataConfig.DataItemChangeReason[reason]
|
||
if _reasonCfg == nil then
|
||
return
|
||
end
|
||
|
||
local _itemCfg = DataConfig.DataItem[itemID]
|
||
local _equipCfg = DataConfig.DataEquip[itemID]
|
||
--判断是否展示飞的效果
|
||
if _reasonCfg.DropShow ~= 0 and itemInst ~= nil and addCount > 0 then
|
||
if (_itemCfg ~= nil and _itemCfg.FlyToBagType ~= 0) or (_equipCfg ~= nil and _equipCfg.FlyToBagType ~= 0) then
|
||
local _flyInfo = {}
|
||
_flyInfo.Reason = reason
|
||
_flyInfo.ItemCfg = _itemCfg
|
||
_flyInfo.EquipCfg = _equipCfg
|
||
_flyInfo.Item = itemInst
|
||
_flyInfo.ItemCount = addCount
|
||
if reason == ItemChangeReasonName.DropByKillMonsterGet then
|
||
--如果是杀怪掉落,做一个延迟
|
||
_flyInfo.DelayTime = 4
|
||
else
|
||
_flyInfo.DelayTime = 0
|
||
end
|
||
GameCenter.PushFixEvent(UIEventDefine.UIItemFlyToBagForm_OPEN, _flyInfo);
|
||
end
|
||
end
|
||
|
||
local _itemInfo = {}
|
||
_itemInfo.Reason = reason;
|
||
_itemInfo.ReasonCfg = _reasonCfg;
|
||
_itemInfo.Item = itemInst;
|
||
_itemInfo.ItemCfg = _itemCfg;
|
||
_itemInfo.EquipCfg = _equipCfg;
|
||
_itemInfo.ItemCount = addCount;
|
||
_itemInfo.ItemCfgID = itemID;
|
||
self:ShowItemInfo(_itemInfo)
|
||
end
|
||
|
||
function GetNewItemSystem:ShowItemInfo(itemInfo)
|
||
if itemInfo.ReasonCfg.ShowPos == ItemChangeShowPos.RightButtom then
|
||
--右下角
|
||
if itemInfo.Item ~= nil then
|
||
GameCenter.PushFixEvent(UIEventDefine.UIMSGTIPS_SHOWINFO, itemInfo.Item)
|
||
else
|
||
if itemInfo.EquipCfg ~= nil then
|
||
GameCenter.PushFixEvent(UIEventDefine.UIMSGTIPS_SHOWINFO, itemInfo.EquipCfg.Name)
|
||
end
|
||
if itemInfo.ItemCfg ~= nil then
|
||
if itemInfo.ItemCount < 0 then
|
||
local _showText = string.format("%s - %d", itemInfo.ItemCfg.Name, -itemInfo.ItemCount)
|
||
GameCenter.PushFixEvent(UIEventDefine.UIMSGTIPS_SHOWINFO, _showText)
|
||
else
|
||
local _countText = CommonUtils.CovertToBigUnit(itemInfo.ItemCount, 0);
|
||
local _showNormal = true
|
||
if itemInfo.ItemCfg.Id == ItemTypeCode.Exp and (
|
||
itemInfo.Reason == ItemChangeReasonName.ExpCopyGet or
|
||
itemInfo.Reason == ItemChangeReasonName.LeaderPreachAddExpGet or
|
||
itemInfo.Reason == ItemChangeReasonName.WorldBonfireExpGet or
|
||
itemInfo.Reason == ItemChangeReasonName.HookMapGet
|
||
) then
|
||
local _lp = GameCenter.GameSceneSystem:GetLocalPlayer()
|
||
if _lp ~= nil and _lp.PropMoudle.KillMonsterExpPercent > 0 then
|
||
_showNormal = false
|
||
local _showText = UIUtils.CSFormat("{0} {1}(+{2:F0}%)", itemInfo.ItemCfg.Name, _countText, _lp.PropMoudle.KillMonsterExpPercent / 100);
|
||
GameCenter.PushFixEvent(UIEventDefine.UIMSGTIPS_SHOWINFO, _showText)
|
||
end
|
||
end
|
||
if _showNormal then
|
||
local _showText = string.format("%s %s", itemInfo.ItemCfg.Name, _countText)
|
||
GameCenter.PushFixEvent(UIEventDefine.UIMSGTIPS_SHOWINFO, _showText)
|
||
end
|
||
end
|
||
end
|
||
end
|
||
elseif itemInfo.ReasonCfg.ShowPos == ItemChangeShowPos.Top then
|
||
--顶部
|
||
if itemInfo.Item ~= nil then
|
||
GameCenter.MsgPromptSystem:ShowPrompt(itemInfo.Item)
|
||
else
|
||
if itemInfo.EquipCfg ~= nil then
|
||
GameCenter.MsgPromptSystem:ShowPrompt(itemInfo.EquipCfg.Name)
|
||
end
|
||
if itemInfo.ItemCfg ~= nil then
|
||
if itemInfo.ItemCount > 0 then
|
||
local _showText = string.format("%s + %s", itemInfo.ItemCfg.Name, itemInfo.ItemCount)
|
||
GameCenter.MsgPromptSystem:ShowPrompt(_showText)
|
||
elseif itemInfo.ItemCount < 0 then
|
||
local _showText = string.format("%s - &d", itemInfo.ItemCfg.Name, -itemInfo.ItemCount)
|
||
GameCenter.MsgPromptSystem:ShowPrompt(_showText)
|
||
end
|
||
end
|
||
end
|
||
elseif itemInfo.ReasonCfg.ShowPos == ItemChangeShowPos.CenterPop then
|
||
--中间弹出
|
||
if (#self.FormItemList > 0 and self.FormItemList[1].Reason ~= itemInfo.Reason) or #self.FormItemList >= 16 then
|
||
--当前有正在显示的,并且不是同一个reason,放入缓存
|
||
if not self.FormItemCache:Contains(itemInfo) then
|
||
self.FormItemCache:Add(itemInfo)
|
||
end
|
||
else
|
||
local _dieJia = false
|
||
if itemInfo.Item == nil and itemInfo.ItemCfg ~= nil then
|
||
for i = 1, #self.FormItemList do
|
||
--判断是否可以叠加显示
|
||
local _tmp = self.FormItemList[i]
|
||
if _tmp.Item == nil and _tmp.ItemCfg ~= nil and _tmp.ItemCfg.Id == itemInfo.ItemCfg.Id then
|
||
_dieJia = true
|
||
_tmp.ItemCount = _tmp.ItemCount + itemInfo.ItemCount
|
||
break
|
||
end
|
||
end
|
||
end
|
||
if not _dieJia then
|
||
--需要展示获取界面的数据
|
||
self.FormItemList:Add(itemInfo);
|
||
end
|
||
|
||
if itemInfo.Reason == ItemChangeReasonName.FestvialWishGet then
|
||
GameCenter.PushFixEvent(UIEventDefine.UITHJRXYGetNewItemForm_OPEN)
|
||
else
|
||
GameCenter.PushFixEvent(UIEventDefine.UIGetNewItemForm_OPEN)
|
||
end
|
||
end
|
||
elseif itemInfo.ReasonCfg.ShowPos == ItemChangeShowPos.BossBox then
|
||
self.BossBoxItemList:Add(itemInfo)
|
||
GameCenter.PushFixEvent(UIEventDefine.UIBossBoxResultForm_OPEN);
|
||
end
|
||
end
|
||
|
||
function GetNewItemSystem:AddShowTips(item, reason, addCount)
|
||
if addCount <= 0 then
|
||
return
|
||
end
|
||
--判断是否是特殊物品,需要显示展示宝箱
|
||
self:CanShowSpecialBox(item, reason)
|
||
|
||
--判断是否需要打开红装提示
|
||
if reason == ItemChangeReasonName.ProDrop or reason == ItemChangeReasonName.GM then
|
||
local _cfgId = item.CfgID
|
||
self:LoadShowTipsEquipIDlist()
|
||
if self.ShowTipsEquipIDlist ~= nil then
|
||
if self.NeedTipsEquipIDlist:Contains(_cfgId) and item.IsNew and not self.ShowTipsEquipIDlist:Contains(_cfgId) then
|
||
self.NeedShowRedEquip = item
|
||
end
|
||
end
|
||
end
|
||
|
||
--使用或者装备展示
|
||
local _canShowTips, isItem = self:CanShowNewTips(item)
|
||
if _canShowTips then
|
||
if isItem then
|
||
local _cfgId = item.CfgID
|
||
--判断是否有重复添加
|
||
for i = 1, #self.NewEquipQueue do
|
||
if self.NewEquipQueue[i].CfgID == _cfgId then
|
||
return
|
||
end
|
||
end
|
||
end
|
||
self.NewEquipQueue:Add(item)
|
||
end
|
||
end
|
||
|
||
--判断装备是否可以进行新装备提示
|
||
function GetNewItemSystem:CanShowNewTips(item)
|
||
if item == nil then
|
||
return false
|
||
end
|
||
if item.Type == ItemType.HolyEquip then
|
||
return false
|
||
-- --判断物品是否还在背包
|
||
-- item = GameCenter.HolyEquipSystem:GetEquipByDBID(item.DBID)
|
||
-- if item == nil then
|
||
-- return false
|
||
-- end
|
||
-- --可以装备,并且比身上的更好
|
||
-- if item:CheckCanEquip() and item:CheckBetterThanDress() then
|
||
-- return true
|
||
-- end
|
||
elseif item.Type == ItemType.Equip then
|
||
--判断物品是否还在背包
|
||
item = GameCenter.ItemContianerSystem:GetItemByUIDFormBag(item.DBID)
|
||
if item == nil then
|
||
return false
|
||
end
|
||
--可以装备,并且比身上的更好
|
||
if item:CheckCanEquip() and item:CheckBetterThanDress() then
|
||
return true
|
||
end
|
||
elseif item.Type == ItemType.ImmortalEquip then
|
||
--判断物品是否还在背包
|
||
item = GameCenter.ItemContianerSystem:GetItemByUIDFormImmortalBag(item.DBID)
|
||
if item == nil then
|
||
return false
|
||
end
|
||
|
||
--可以装备,并且比身上的更好
|
||
if item:CheckCanEquip() and item:CheckBetterThanDress() then
|
||
return true
|
||
end
|
||
elseif item.Type == ItemType.UnrealEquip then
|
||
return false
|
||
else
|
||
item = GameCenter.ItemContianerSystem:GetItemByUIDFormBag(item.DBID)
|
||
if item == nil then
|
||
return false
|
||
end
|
||
local _cfgId = item.CfgID
|
||
local _count = item.Count
|
||
--判断离线经验道具
|
||
for i = 1, #self.AddOnHookTimeItemID do
|
||
if self.AddOnHookTimeItemID[i] == _cfgId and
|
||
GameCenter.OfflineOnHookSystem.RemainOnHookTime + self.AddOnHookTimeItemTime[i] >= self.MaxOnHookTime then
|
||
--离线经验到达上限,不展示离线经验道具
|
||
return false
|
||
end
|
||
end
|
||
--判断物品是否可以使用
|
||
local _itemCfg = DataConfig.DataItem[_cfgId]
|
||
if _itemCfg ~= nil and _itemCfg.IfUseInfo >= 1 and _count >= _itemCfg.IfUseInfo and not item:isTimeOut() and item:CheckLevel(GameCenter.GameSceneSystem:GetLocalPlayerLevel()) then
|
||
return true, true
|
||
end
|
||
end
|
||
return false
|
||
end
|
||
|
||
--判断是否是特殊物品,需要显示展示宝箱
|
||
function GetNewItemSystem:CanShowSpecialBox(item, reason)
|
||
if item == nil then
|
||
return
|
||
end
|
||
local _cfg = DataConfig.DataFBOpenShow[item.CfgID]
|
||
if _cfg == nil then
|
||
return
|
||
end
|
||
local _reaSeanList = Utils.SplitNumber(_cfg.ChangeReason, '_')
|
||
if _reaSeanList:Contains(reason) then
|
||
GameCenter.PushFixEvent(UILuaEventDefine.UIBaoXiangModelForm_OPEN, _cfg.Id)
|
||
end
|
||
end
|
||
|
||
--显示下一个物品
|
||
function GetNewItemSystem:ShowNextEquip()
|
||
while(#self.NewEquipQueue > 0) do
|
||
local _item = self.NewEquipQueue[1]
|
||
self.NewEquipQueue:RemoveAt(1)
|
||
local _canShowTips, isItem = self:CanShowNewTips(_item)
|
||
if _canShowTips then
|
||
if isItem then
|
||
GameCenter.PushFixEvent(UIEventDefine.UIITEMGET_TIPS_OPEN, _item);
|
||
else
|
||
GameCenter.PushFixEvent(UIEventDefine.UIEQUIPGET_TIPS_OPEN, _item);
|
||
end
|
||
self.ForceShowEquipTimer = 10
|
||
break
|
||
end
|
||
end
|
||
end
|
||
|
||
--清理界面显示的物品信息
|
||
function GetNewItemSystem:OnFormClose()
|
||
self.FormItemList:Clear()
|
||
self.FormItemDelayTime = 1
|
||
end
|
||
|
||
--清理boss宝箱展示
|
||
function GetNewItemSystem:ClearBossBoxResult()
|
||
self.BossBoxItemList:Clear()
|
||
end
|
||
|
||
--载入已经展示过的红装id
|
||
function GetNewItemSystem:LoadShowTipsEquipIDlist()
|
||
if self.ShowTipsEquipIDlist ~= nil then
|
||
return
|
||
end
|
||
local _lpId = GameCenter.GameSceneSystem:GetLocalPlayerID()
|
||
if _lpId <= 0 then
|
||
return
|
||
end
|
||
self.ShowTipsEquipIDlist = List:New()
|
||
local _setData = PlayerPrefs.GetString("FirstShowRedEquipIDlist" .. _lpId)
|
||
if _setData ~= nil and string.len(_setData) > 0 then
|
||
local _ids = Utils.SplitNumber(_setData, '_')
|
||
for i = 1, #_ids do
|
||
self.ShowTipsEquipIDlist:Add(_ids[i])
|
||
end
|
||
end
|
||
end
|
||
--保存已经展示过的红装id
|
||
function GetNewItemSystem:SaveShowTipsEquipIDlist()
|
||
if self.ShowTipsEquipIDlist == nil then
|
||
return
|
||
end
|
||
local _lpId = GameCenter.GameSceneSystem:GetLocalPlayerID()
|
||
if _lpId <= 0 then
|
||
return
|
||
end
|
||
local _saveText = ""
|
||
local _count = #self.ShowTipsEquipIDlist
|
||
for i = 1, _count do
|
||
_saveText = _saveText .. self.ShowTipsEquipIDlist[i]
|
||
if i < _count then
|
||
_saveText = _saveText .. '_'
|
||
end
|
||
end
|
||
PlayerPrefs.SetString("FirstShowRedEquipIDlist" .. _lpId, _saveText)
|
||
PlayerPrefs.Save()
|
||
end
|
||
|
||
--更新
|
||
function GetNewItemSystem:Update(dt)
|
||
--判断是否暂停了物品获得的弹出
|
||
if self.PauseGetNewItemTips then
|
||
return
|
||
end
|
||
|
||
--更新显示到界面上的物品
|
||
if self.FormItemDelayTime > 0 then
|
||
self.FormItemDelayTime = self.FormItemDelayTime - dt
|
||
if self.FormItemDelayTime <= 0 then
|
||
local _count = #self.FormItemCache
|
||
for i = 1, _count do
|
||
if i > 16 then
|
||
break
|
||
end
|
||
local _item = self.FormItemCache[1]
|
||
self.FormItemCache:RemoveAt(1)
|
||
self:ShowItemInfo(_item)
|
||
end
|
||
end
|
||
end
|
||
|
||
--更新展示的红装
|
||
if self.NeedShowRedEquip then
|
||
GameCenter.PushFixEvent(UIEventDefine.UIFirstGetEquipForm_OPEN, self.NeedShowRedEquip)
|
||
self.ShowTipsEquipIDlist:Add(self.NeedShowRedEquip.CfgID)
|
||
self:SaveShowTipsEquipIDlist()
|
||
self.NeedShowRedEquip = nil
|
||
end
|
||
|
||
if not GameCenter.FormStateSystem:FormIsOpen(self.ItemTipsUIId) and not GameCenter.FormStateSystem:FormIsOpen(self.EquipTipsUIId) and not GameCenter.FormStateSystem:FormIsOpen(self.FirstEquipTipsUIId) then
|
||
self.NewEquipTimer = self.NewEquipTimer - dt
|
||
if self.NewEquipTimer <= 0 then
|
||
self:ShowNextEquip()
|
||
end
|
||
else
|
||
self.NewEquipTimer = 0.5
|
||
end
|
||
|
||
if #self.NewEquipQueue > 0 and self.ForceShowEquipTimer > 0 then
|
||
self.ForceShowEquipTimer = self.ForceShowEquipTimer - dt
|
||
if self.ForceShowEquipTimer <= 0 then
|
||
self:ShowNextEquip()
|
||
end
|
||
end
|
||
end
|
||
|
||
return GetNewItemSystem |