558 lines
18 KiB
Lua
558 lines
18 KiB
Lua
------------------------------------------------
|
|
--作者: yangqf
|
|
--日期: 2021-11-11
|
|
--文件: UnrealEquipSystem.lua
|
|
--模块: UnrealEquipSystem
|
|
--描述: 幻装系统
|
|
------------------------------------------------
|
|
|
|
local L_UnrealEquipSoul = require "Logic.UnrealEquip.UnrealEquipSoul"
|
|
local L_UnrealEquipPart = require "Logic.UnrealEquip.UnrealEquipPart"
|
|
local L_RedPointCustomCondition = CS.Thousandto.Code.Logic.RedPointCustomCondition
|
|
|
|
local UnrealEquipSystem = {
|
|
--装备栏的数据
|
|
EquipDic = Dictionary:New(),
|
|
--背包中的数据
|
|
BagList = List:New(),
|
|
--背包数量计数器
|
|
BagCounter = {},
|
|
--临时列表,用于返回给外部
|
|
TmpList = List:New(),
|
|
--圣魂列表
|
|
SoulList = List:New(),
|
|
--合成配置
|
|
SyncCfgTable = nil,
|
|
--可合成的装备idtable
|
|
CanSyncEquipIds = nil,
|
|
--可合成的道具 idtable
|
|
CanSyncItemIds = nil,
|
|
--合成需要的物品列表
|
|
SyncNeedItems = List:New(),
|
|
--检查背包红点
|
|
IsCheckBagRedPoint = false,
|
|
--检查合成红点
|
|
IsCheckSyncRedPoint = false,
|
|
--总战力
|
|
AllPower = 0,
|
|
}
|
|
|
|
function UnrealEquipSystem:Initialize()
|
|
self.SoulList:Clear()
|
|
local _gCfg = DataConfig.DataGlobal[GlobalName.Equip_Magic_att_item]
|
|
if _gCfg ~= nil then
|
|
local _paramArray = Utils.SplitStrByTableS(_gCfg.Params, {';', '_'})
|
|
for i = 1, #_paramArray do
|
|
local _itemId = _paramArray[i][1]
|
|
local _maxCount = _paramArray[i][2]
|
|
self.SoulList:Add(L_UnrealEquipSoul:New(_itemId, _maxCount))
|
|
end
|
|
end
|
|
self.SyncCfgTable = {}
|
|
self.CanSyncEquipIds = {}
|
|
self.CanSyncItemIds = {}
|
|
local _registerItems = {}
|
|
local _func = function(k, v)
|
|
local _needItem = Utils.SplitNumber(v.NeedItem, '_')
|
|
local _cfg = {}
|
|
if _needItem ~= nil and #_needItem >= 2 then
|
|
_registerItems[_needItem[1]] = true
|
|
_cfg.Item = _needItem
|
|
end
|
|
local _needEquip = Utils.SplitNumber(v.NeedEquip, '_')
|
|
if _needEquip ~= nil and #_needEquip >= 2 then
|
|
_cfg.Equip = _needEquip
|
|
self.CanSyncEquipIds[_needEquip[1]] = _cfg
|
|
elseif _cfg.Item ~= nil then
|
|
self.CanSyncItemIds[_needItem[1]] = _cfg
|
|
end
|
|
_cfg.TargetId = k
|
|
self.SyncCfgTable[k] = _cfg
|
|
end
|
|
DataConfig.DataEquipMagicSynthesis:Foreach(_func)
|
|
--注册物品改变消息
|
|
self.SyncNeedItems:Clear()
|
|
for k, v in pairs(_registerItems) do
|
|
self.SyncNeedItems:Add(k)
|
|
end
|
|
GameCenter.ItemContianerSystem:AddItemMsgCondition(LogicLuaEventDefine.EID_EVENT_UNREAL_ITEM_CHANGED, self.SyncNeedItems, FunctionStartIdCode.UnrealEquipSync)
|
|
GameCenter.RegFixEventHandle(LogicLuaEventDefine.EID_EVENT_UNREAL_ITEM_CHANGED, self.OnSyncItemChanged, self)
|
|
self.BagCounter = {}
|
|
end
|
|
|
|
function UnrealEquipSystem:UnInitialize()
|
|
GameCenter.UnRegFixEventHandle(LogicLuaEventDefine.EID_EVENT_UNREAL_ITEM_CHANGED, self.OnSyncItemChanged, self)
|
|
end
|
|
|
|
--获取身上穿戴的装备
|
|
function UnrealEquipSystem:GetDressEquip(part)
|
|
return self.EquipDic[part]
|
|
end
|
|
|
|
--根据DBID获取背包中的幻装
|
|
function UnrealEquipSystem:GetEquipByDBID(uid)
|
|
for i = 1, #self.BagList do
|
|
local _equip = self.BagList[i]
|
|
if _equip.DBID == uid then
|
|
return self.BagList[i]
|
|
end
|
|
end
|
|
return nil
|
|
end
|
|
|
|
--套装排序
|
|
local L_SuitSort = function(left, right)
|
|
return right.Grade < left.Grade
|
|
end
|
|
|
|
--计算套装属性
|
|
function UnrealEquipSystem:CalculateSuit()
|
|
local equipList = List:New()
|
|
for k, v in pairs(self.EquipDic) do
|
|
if v.Equip ~= nil then
|
|
equipList:Add(v.Equip)
|
|
end
|
|
end
|
|
--先从高到低排序
|
|
equipList:Sort(L_SuitSort)
|
|
local _suit2Grade = 0
|
|
local _suit2SuitID = 0
|
|
--2件
|
|
local _equipCount = #equipList
|
|
if _equipCount >= 2 then
|
|
_suit2SuitID = equipList[2].SuitID
|
|
_suit2Grade = equipList[2].Grade
|
|
end
|
|
--4件
|
|
local _suit4Grade = 0
|
|
local _suit4SuitID = 0
|
|
if _equipCount >= 4 then
|
|
_suit4SuitID = equipList[4].SuitID
|
|
_suit4Grade = equipList[4].Grade
|
|
end
|
|
--6件
|
|
local _suit6Grade = 0
|
|
local _suit6SuitID = 0
|
|
if _equipCount >= 6 then
|
|
_suit6SuitID = equipList[6].SuitID
|
|
_suit6Grade = equipList[6].Grade
|
|
end
|
|
--8件
|
|
local _suit8Grade = 0
|
|
local _suit8SuitID = 0
|
|
if _equipCount >= 8 then
|
|
_suit8SuitID = equipList[8].SuitID
|
|
_suit8Grade = equipList[8].Grade
|
|
end
|
|
--10件
|
|
local _suit10Grade = 0
|
|
local _suit10SuitID = 0
|
|
if _equipCount >= 10 then
|
|
_suit10SuitID = equipList[10].SuitID
|
|
_suit10Grade = equipList[10].Grade
|
|
end
|
|
if _suit2SuitID <= 0 then
|
|
_suit2SuitID = nil
|
|
end
|
|
if _suit4SuitID <= 0 then
|
|
_suit4SuitID = nil
|
|
end
|
|
if _suit6SuitID <= 0 then
|
|
_suit6SuitID = nil
|
|
end
|
|
if _suit8SuitID <= 0 then
|
|
_suit8SuitID = nil
|
|
end
|
|
if _suit10SuitID <= 0 then
|
|
_suit10SuitID = nil
|
|
end
|
|
for i = 1, #equipList do
|
|
local _equipGrade = equipList[i].Grade
|
|
local _equipSuitIds = equipList[i].ActiveSuits
|
|
_equipSuitIds:Clear()
|
|
if _equipGrade >= _suit2Grade then
|
|
_equipSuitIds[2] = _suit2SuitID
|
|
end
|
|
if _equipGrade >= _suit4Grade then
|
|
_equipSuitIds[4] = _suit4SuitID
|
|
end
|
|
if _equipGrade >= _suit6Grade then
|
|
_equipSuitIds[6] = _suit6SuitID
|
|
end
|
|
if _equipGrade >= _suit8Grade then
|
|
_equipSuitIds[8] = _suit8SuitID
|
|
end
|
|
if _equipGrade >= _suit10Grade then
|
|
_equipSuitIds[10] = _suit10SuitID
|
|
end
|
|
end
|
|
end
|
|
|
|
--排序装备
|
|
local L_SortEquip = function(left, right)
|
|
if left.Grade ~= right.Grade then
|
|
return right.Grade < left.Grade
|
|
end
|
|
if left.Quality ~= right.Quality then
|
|
return right.Quality < left.Quality
|
|
end
|
|
if left.Part ~= right.Part then
|
|
return left.Part < right.Part
|
|
end
|
|
return false
|
|
end
|
|
|
|
--上线初始化数据
|
|
function UnrealEquipSystem:ResOnlineInit(result)
|
|
self.BagList:Clear()
|
|
if result.unrealBagItemList ~= nil then
|
|
for i = 1, #result.unrealBagItemList do
|
|
local _msgItem = result.unrealBagItemList[i]
|
|
if _msgItem.num == nil then
|
|
_msgItem.num = 1
|
|
end
|
|
local _equip = LuaItemBase.CreateItemBaseByMsg(_msgItem)
|
|
self:AddBagEquip(_equip, 0)
|
|
end
|
|
end
|
|
self.BagList:Sort(L_SortEquip)
|
|
self.EquipDic:Clear()
|
|
if result.unrealEquipPartList ~= nil then
|
|
for i = 1, #result.unrealEquipPartList do
|
|
local _part = L_UnrealEquipPart:New(result.unrealEquipPartList[i])
|
|
self:UpdateEquipDic(_part)
|
|
end
|
|
end
|
|
for i = 1, #result.unrealSoulInfoList do
|
|
for j = 1, #self.SoulList do
|
|
if self.SoulList[j].ItemID == result.unrealSoulInfoList[i].itemId then
|
|
self.SoulList[j]:SetCurCount(result.unrealSoulInfoList[i].useNum)
|
|
end
|
|
end
|
|
end
|
|
self.IsCheckBagRedPoint = true
|
|
self.IsCheckSyncRedPoint = true
|
|
--计算套装属性
|
|
self:CalculateSuit()
|
|
GameCenter.PushFixEvent(LogicLuaEventDefine.EID_EVENT_UNREAL_EQUIP_ONLINE)
|
|
end
|
|
|
|
--镶嵌结果反馈
|
|
function UnrealEquipSystem:ResInlayUnrealReuslt(result)
|
|
if result.unrealPart ~= nil then
|
|
--更新装备栏
|
|
local _part = L_UnrealEquipPart:New(result.unrealPart)
|
|
self:UpdateEquipDic(_part)
|
|
--计算套装属性
|
|
self:CalculateSuit()
|
|
GameCenter.PushFixEvent(LogicLuaEventDefine.EID_EVENT_UNREAL_EQUIP_PART)
|
|
end
|
|
end
|
|
|
|
--幻魂使用结果
|
|
function UnrealEquipSystem:ResUseUnrealSoulResult(result)
|
|
for i = 1, #self.SoulList do
|
|
if self.SoulList[i].ItemID == result.unrealSoulData.itemId then
|
|
self.SoulList[i]:SetCurCount(result.unrealSoulData.useNum)
|
|
break
|
|
end
|
|
end
|
|
GameCenter.PushFixEvent(LogicLuaEventDefine.EID_EVENT_UNREAL_EQUIP_SOULUPDATE)
|
|
end
|
|
|
|
--删除圣装
|
|
function UnrealEquipSystem:ResDeleteUnreal(result)
|
|
if result.deleteUID ~= nil then
|
|
for i= 1, #result.deleteUID do
|
|
self:DeleteBagEquip(result.deleteUID[i], result.reason)
|
|
end
|
|
self.IsCheckBagRedPoint = true
|
|
self.IsCheckSyncRedPoint = true
|
|
GameCenter.PushFixEvent(LogicLuaEventDefine.EID_EVENT_UNREAL_EQUIP_UPDATE_BAG)
|
|
end
|
|
if result.reason == ItemChangeReasonName.UnrealEquipCompoundDec then
|
|
GameCenter.PushFixEvent(LogicLuaEventDefine.EID_EVENT_UNREAL_EQUIP_PLAY_SYNCVFX)
|
|
end
|
|
end
|
|
|
|
--添加幻装
|
|
function UnrealEquipSystem:ResAddUnreal(result)
|
|
if result.addUnrealitem ~= nil then
|
|
for i = 1, #result.addUnrealitem do
|
|
local _msgItem = result.addUnrealitem[i]
|
|
if _msgItem.num == nil then
|
|
_msgItem.num = 1
|
|
end
|
|
local _equip = LuaItemBase.CreateItemBaseByMsg(_msgItem)
|
|
_equip.IsNew = true
|
|
self:AddBagEquip(_equip, result.reason)
|
|
GameCenter.GetNewItemSystem:AddShowItem(result.reason, _equip, _equip.CfgID, 1)
|
|
end
|
|
self.BagList:Sort(L_SortEquip)
|
|
self.IsCheckBagRedPoint = true
|
|
self.IsCheckSyncRedPoint = true
|
|
GameCenter.PushFixEvent(LogicLuaEventDefine.EID_EVENT_UNREAL_EQUIP_UPDATE_BAG)
|
|
end
|
|
end
|
|
|
|
--同步战力
|
|
function UnrealEquipSystem:ResUnrealEquipFightPower(result)
|
|
self.AllPower = result.fightPower
|
|
GameCenter.PushFixEvent(LogicLuaEventDefine.EID_EVENT_UNREAL_EQUIP_FIGHTPOWER)
|
|
end
|
|
|
|
--检测背包红点
|
|
function UnrealEquipSystem:CheckBagRedPoint()
|
|
GameCenter.RedPointSystem:CleraFuncCondition(FunctionStartIdCode.UnrealEquip)
|
|
local _betterParts = List:New()
|
|
for i = 1, #self.BagList do
|
|
local _equip = self.BagList[i]
|
|
local _part = _equip.Part
|
|
if not _betterParts:Contains(_part) and _equip:CheckCanEquip() and _equip:CheckBetterThanDress() then
|
|
_betterParts:Add(_part)
|
|
end
|
|
end
|
|
for i = 1, #_betterParts do
|
|
GameCenter.RedPointSystem:AddFuncCondition(FunctionStartIdCode.UnrealEquip, _betterParts[i], L_RedPointCustomCondition(true))
|
|
end
|
|
end
|
|
|
|
function UnrealEquipSystem:OnSyncItemChanged(obj, sender)
|
|
self.IsCheckSyncRedPoint = true
|
|
end
|
|
|
|
function UnrealEquipSystem:GetCanMergeItemsById(equipNeed, itemNeed)
|
|
local _result = List:New()
|
|
if equipNeed ~= nil then
|
|
local _equipCount = 0
|
|
for k, v in pairs(self.EquipDic) do
|
|
if v.Equip ~= nil and v.Equip.CfgID == equipNeed[1] then
|
|
_equipCount = _equipCount + 1
|
|
_result:Add(v.Equip)
|
|
if _equipCount >= equipNeed[2] then
|
|
--数量够了
|
|
break
|
|
end
|
|
end
|
|
end
|
|
for i = 1, #self.BagList do
|
|
local _equip = self.BagList[i]
|
|
if _equip.CfgID == equipNeed[1] then
|
|
_equipCount = _equipCount + 1
|
|
_result:Add(_equip)
|
|
if _equipCount >= equipNeed[2] then
|
|
--数量够了
|
|
break
|
|
end
|
|
end
|
|
end
|
|
end
|
|
if itemNeed ~= nil then
|
|
local _itemList = GameCenter.ItemContianerSystem:GetItemListByCfgidNOGC(ContainerType.ITEM_LOCATION_BAG, itemNeed[1])
|
|
local _listCount = _itemList.Count
|
|
local _haveCount = 0
|
|
_result:Clear()
|
|
for i = 1, _listCount do
|
|
local _itemInst = _itemList[i - 1]
|
|
_haveCount = _haveCount + _itemInst.Count
|
|
_result:Add(_itemInst)
|
|
if _haveCount >= itemNeed[2] then
|
|
--数量足够了
|
|
break
|
|
end
|
|
end
|
|
end
|
|
return _result
|
|
end
|
|
|
|
--获取可合成的物品id
|
|
function UnrealEquipSystem:GetCanMergeItems()
|
|
for _, v in pairs(self.CanSyncItemIds) do
|
|
local _itemCount = GameCenter.ItemContianerSystem:GetItemCountFromCfgId(v.Item[1])
|
|
if _itemCount >= v.Item[2] then
|
|
return self:GetCanMergeItemsById(nil, v.Item), v.TargetId
|
|
end
|
|
end
|
|
local _euipCount = {}
|
|
for k, v in pairs(self.EquipDic) do
|
|
if v.Equip ~= nil then
|
|
local _oriCount = _euipCount[v.Equip.CfgID]
|
|
if _oriCount == nil then
|
|
_oriCount = 0
|
|
end
|
|
_euipCount[v.Equip.CfgID] = _oriCount + 1
|
|
end
|
|
end
|
|
for _, v in pairs(self.CanSyncEquipIds) do
|
|
local _partCount = _euipCount[v.Equip[1]]
|
|
if _partCount == nil then
|
|
_partCount = 0
|
|
end
|
|
local _bagCount = self.BagCounter[v.Equip[1]]
|
|
if _bagCount == nil then
|
|
_bagCount = 0
|
|
end
|
|
if (_bagCount + _partCount) >= v.Equip[2] then
|
|
--装备数量足够
|
|
if v.Item ~= nil then
|
|
--判断材料数量是否足够
|
|
local _itemCount = GameCenter.ItemContianerSystem:GetItemCountFromCfgId(v.Item[1])
|
|
if _itemCount >= v.Item[2] then
|
|
return self:GetCanMergeItemsById(v.Equip, nil), v.TargetId
|
|
end
|
|
else
|
|
--不需要材料
|
|
return self:GetCanMergeItemsById(v.Equip, nil), v.TargetId
|
|
end
|
|
end
|
|
end
|
|
return nil, nil
|
|
end
|
|
|
|
function UnrealEquipSystem:GetClipList()
|
|
local _resultList = List:New()
|
|
for _, v in pairs(self.CanSyncItemIds) do
|
|
local _itemId = v.Item[1]
|
|
local _itemList = GameCenter.ItemContianerSystem:GetItemListByCfgidNOGC(ContainerType.ITEM_LOCATION_BAG, _itemId)
|
|
local _count = _itemList.Count
|
|
for i = 1, _count do
|
|
_resultList:Add(_itemList[i - 1])
|
|
end
|
|
end
|
|
return _resultList
|
|
end
|
|
|
|
function UnrealEquipSystem:GetCanHeChengEquipList()
|
|
local _resultList = List:New()
|
|
--获取装备列表中的可合成物品
|
|
for _, v in pairs(self.EquipDic) do
|
|
if v.Equip ~= nil and self.CanSyncEquipIds[v.Equip.CfgID] then
|
|
_resultList:Add(v.Equip)
|
|
end
|
|
end
|
|
--获取幻装背包中的可合成物品
|
|
for i = 1, #self.BagList do
|
|
local _equip = self.BagList[i]
|
|
if self.CanSyncEquipIds[_equip.CfgID] then
|
|
_resultList:Add(_equip)
|
|
end
|
|
end
|
|
--获取玩家背包中的可合成物品
|
|
for _, v in pairs(self.CanSyncItemIds) do
|
|
local _itemId = v.Item[1]
|
|
local _itemList = GameCenter.ItemContianerSystem:GetItemListByCfgidNOGC(ContainerType.ITEM_LOCATION_BAG, _itemId)
|
|
local _count = _itemList.Count
|
|
for i = 1, _count do
|
|
_resultList:Add(_itemList[i - 1])
|
|
end
|
|
end
|
|
return _resultList
|
|
end
|
|
|
|
function UnrealEquipSystem:CheckSyncRedPoint()
|
|
local _countTable = {}
|
|
for i = 1, #self.SyncNeedItems do
|
|
local _itemId = self.SyncNeedItems[i]
|
|
_countTable[_itemId] = GameCenter.ItemContianerSystem:GetItemCountFromCfgId(_itemId)
|
|
end
|
|
local _euipCount = {}
|
|
for k, v in pairs(self.EquipDic) do
|
|
if v.Equip ~= nil then
|
|
local _oriCount = _euipCount[v.Equip.CfgID]
|
|
if _oriCount == nil then
|
|
_oriCount = 0
|
|
end
|
|
_euipCount[v.Equip.CfgID] = _oriCount + 1
|
|
end
|
|
end
|
|
local _canSync = false
|
|
for k, v in pairs(self.SyncCfgTable) do
|
|
local _equipEnough = true
|
|
local _itemEnough = true
|
|
if v.Equip ~= nil then
|
|
--需求装备
|
|
local _bagCount = self.BagCounter[v.Equip[1]]
|
|
local _partCount = _euipCount[v.Equip[1]]
|
|
if _bagCount == nil then
|
|
_bagCount = 0
|
|
end
|
|
if _partCount == nil then
|
|
_partCount = 0
|
|
end
|
|
if (_bagCount + _partCount) < v.Equip[2] then
|
|
_equipEnough = false
|
|
end
|
|
end
|
|
if v.Item ~= nil then
|
|
--需求物品
|
|
local _itemCount = _countTable[v.Item[1]]
|
|
if _itemCount == nil then
|
|
_itemCount = 0
|
|
end
|
|
if _itemCount < v.Item[2] then
|
|
_itemEnough = false
|
|
end
|
|
end
|
|
if _equipEnough and _itemEnough then
|
|
_canSync = true
|
|
break
|
|
end
|
|
end
|
|
GameCenter.MainFunctionSystem:SetAlertFlag(FunctionStartIdCode.UnrealEquipSync, _canSync)
|
|
end
|
|
|
|
--添加到背包栏
|
|
function UnrealEquipSystem:AddBagEquip(equip, reason)
|
|
equip.ContainerType = ContainerType.ITEM_LOCATION_BAG
|
|
self.BagList:Add(equip)
|
|
local _cfgId = equip.CfgID
|
|
local _oriCount = self.BagCounter[_cfgId]
|
|
if _oriCount == nil then
|
|
_oriCount = 0
|
|
end
|
|
self.BagCounter[_cfgId] = _oriCount + 1
|
|
GameCenter.GetNewItemSystem:AddShowTips(equip, reason, 1)
|
|
GameCenter.PushFixEvent(LogicLuaEventDefine.EID_EVENT_UNREAL_EQUIP_ADD, equip)
|
|
end
|
|
|
|
--删除背包栏中的装备
|
|
function UnrealEquipSystem:DeleteBagEquip(id, reason)
|
|
for i = 1, #self.BagList do
|
|
local _bagEquip = self.BagList[i]
|
|
if _bagEquip.DBID == id then
|
|
local _cfgId = _bagEquip.CfgID
|
|
self.BagList:RemoveAt(i)
|
|
local _oriCount = self.BagCounter[_cfgId]
|
|
if _oriCount == nil then
|
|
_oriCount = 0
|
|
end
|
|
if _oriCount <= 0 then
|
|
self.BagCounter[_cfgId] = nil
|
|
else
|
|
self.BagCounter[_cfgId] = _oriCount - 1
|
|
end
|
|
GameCenter.PushFixEvent(LogicLuaEventDefine.EID_EVENT_UNREAL_EQUIP_DELETE, id)
|
|
break
|
|
end
|
|
end
|
|
end
|
|
|
|
--更新装备栏
|
|
function UnrealEquipSystem:UpdateEquipDic(part)
|
|
local _partValue = part.Part
|
|
self.EquipDic[_partValue] = part
|
|
GameCenter.PushFixEvent(LogicLuaEventDefine.EID_EVENT_UNREAL_EQUIP_DELETE, id)
|
|
end
|
|
|
|
function UnrealEquipSystem:Update(dt)
|
|
if self.IsCheckBagRedPoint then
|
|
self:CheckBagRedPoint()
|
|
self.IsCheckBagRedPoint = false
|
|
end
|
|
if self.IsCheckSyncRedPoint then
|
|
self.IsCheckSyncRedPoint = false
|
|
self:CheckSyncRedPoint()
|
|
end
|
|
end
|
|
|
|
return UnrealEquipSystem |