| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135 |
- local RemoteProxy = requireProxy("remote/RemoteProxy")
- local BagProxy = class("BagProxy", RemoteProxy)
- BagProxy.NAME = global.ProxyTable.Bag
- local tinsert = table.insert
- local function MAKE_OPER_DATA(item, isHad, number)
- local operator = {}
- operator.item = item
- operator.isHad = isHad
- operator.change = number
- operator.MakeIndex = item.MakeIndex
- return operator
- end
- BagProxy.BAG_SELECT_TYPE = {
- TYPE_ALL = 0, -- 全部
- TYPE_EQUIP = 1, -- 装备
- TYPE_EXP = 2, -- 经验
- TYPE_REIN = 3, -- 转生
- TYPE_PET = 4, -- 宠物
- TYPE_OTHER = 5 -- 其他
- }
- function BagProxy:ctor()
- BagProxy.super.ctor(self)
- local BagVO = requireVO("remote/BagVO")
- self.VOdata = BagVO.new()
- self._maxBagNum = 0 -- 服务端发的最大背包格子数(不包括快捷栏)
- self._init_count = 0 -- 初始数量
- self._curSelPage = 1 -- 当前选中切页
- self._prompt_data = nil -- cfg_game_data的prompt
- self._selfDropItems = {} -- 自己丢弃的物品
- self._on_sell_repaire = nil -- 正在交易或者修理中物品
- self._collimator_MakeIndex = nil -- 记录背包选中的准星道具
- self._reconnect = false -- 是否重连
- self._customAttrs = {} -- 自定义属性 key: makeindex value: attrs
- self._receiveBagData = false -- 是否已经收到背包数据
- self._bigPerPageNum = nil -- 大背包单页大小
- self._bagFullInterval = tonumber(global.ConstantConfig.bag_full_interval) or 0.5 -- 默认给0.5
- self._bagFullTimerID = nil -- 背包满定时器
- end
- function BagProxy:SetServerBagNum(maxBag)
- self._maxBagNum = maxBag
- end
- function BagProxy:GetServerBagNum()
- return self._maxBagNum
- end
- function BagProxy:SetMaxBag(maxBag)
- self.VOdata:SetMaxBag(maxBag)
- self.VOdata:SetNewPosMark()
- end
- function BagProxy:GetMaxBag()
- return self.VOdata:GetMaxBag()
- end
- function BagProxy:SetCurPage(curPage)
- self._curSelPage = curPage
- end
- function BagProxy:GetCurPage(curPage)
- return self._curSelPage
- end
- function BagProxy:GetSelfDropItems()
- return self._selfDropItems
- end
- -- item提示:类似右上角满 获取cfg_game_data表的prompt字段的数据
- function BagProxy:GetPromptGameData()
- if not self._prompt_data then
- self._prompt_data = {}
- local prompt = SL:GetMetaValue("GAME_DATA","prompt")
- if prompt and string.len(prompt) then
- local promptArray = string.split(prompt, "|")
- for _, v in ipairs(promptArray) do
- if v and string.len(v) > 0 then
- local valueArray = string.split(v, "#")
- tinsert(self._prompt_data, {
- resPath = valueArray[1],
- posX = valueArray[2] and tonumber(valueArray[2]) or nil,
- posY = valueArray[3] and tonumber(valueArray[3]) or nil,
- resScale = valueArray[4] and tonumber(valueArray[4]) or nil
- })
- end
- end
- end
- end
- if global.isWinPlayMode then
- return self._prompt_data[1] or {}
- end
- return self._prompt_data[2] or {}
- end
- function BagProxy:Inited(bool)
- self.VOdata:Inited(bool)
- end
- function BagProxy:SetReconnect(bool)
- self._reconnect = bool
- end
- function BagProxy:GetBagData()
- return self.VOdata:GetBagData()
- end
- function BagProxy:GetTotalItemCount()
- return self.VOdata:GetItemCount()
- end
- function BagProxy:isToBeFull(tips)
- if tips and self.VOdata:isFull() then
- global.Facade:sendNotification(global.NoticeTable.SystemTips, GET_STRING(800050))
- end
- return self.VOdata:isFull()
- end
- function BagProxy:CheckNeedSpace(itemID, itemCount, tips)
- local ItemConfigProxy = global.Facade:retrieveProxy(global.ProxyTable.ItemConfigProxy)
- local itemData = ItemConfigProxy:GetItemDataByIndex(itemID)
- local isLap = ItemConfigProxy:CheckItemOverLap(itemData)
- local needPos = itemCount
- if isLap then
- needPos = math.ceil(itemCount / itemData.OverLap)
- end
- local bagItemNum = self:GetTotalItemCount()
- local maxBag = self:GetMaxBag()
- local TradeProxy = global.Facade:retrieveProxy(global.ProxyTable.TradeProxy)
- local onTradingNum = TradeProxy:GetSelfItemNum()
- local totalBagItemNum = bagItemNum + onTradingNum
- if bagItemNum + needPos > maxBag then
- if tips then
- global.Facade:sendNotification(global.NoticeTable.SystemTips, GET_STRING(1021))
- end
- return false
- end
- return true
- end
- -- 通过唯一id获取在背包中的切页
- function BagProxy:GetBagPageByMakeIndex(MakeIndex)
- local posPage = nil
- MakeIndex = MakeIndex and tonumber(MakeIndex) or nil
- if MakeIndex then
- local pos = self:GetBagPosByMakeIndex(MakeIndex)
- if pos and type(pos) == "number" then
- posPage = math.ceil(pos / (self:GetBigPerPageNum() or global.MMO.MAX_ITEM_NUMBER))
- end
- end
- return posPage
- end
- function BagProxy:GetBigPerPageNum()
- local bag_row_col = SL:GetMetaValue("GAME_DATA", "bag_row_col_max")
- if not SL:GetMetaValue("WINPLAYMODE") or not bag_row_col or self._bigPerPageNum then
- return self._bigPerPageNum
- end
- local param = string.split(bag_row_col, "|")
- local col = tonumber(param[1]) or 8
- local row = tonumber(param[2]) or 5
- self._bigPerPageNum = col * row
- return self._bigPerPageNum
- end
- -- 通过唯一id获取在背包中的位置
- function BagProxy:GetBagPosByMakeIndex(MakeIndex)
- return self.VOdata:GetBagPosByMakeIndex(MakeIndex)
- end
- -- 通过在背包中的位置获取唯一id
- function BagProxy:GetMakeIndexByBagPos(pos)
- return self.VOdata:GetMakeIndexByBagPos(pos)
- end
- -- 通过唯一id获取物品数据
- function BagProxy:GetItemDataByMakeIndex(MakeIndex)
- return self.VOdata:GetItemByMakeIndex(MakeIndex)
- end
- -- 获取背包数据 startPos: 开始的位置 endPos: 结束的位置
- function BagProxy:GetBagDataByBagPos(startPos, endPos)
- return self.VOdata:GetBagDataByBagPos(startPos, endPos)
- end
- -- 获取新位置
- function BagProxy:NewItemPos()
- return self.VOdata:NewItemPos()
- end
- -- 修正历史数据与当前数据位置信息
- function BagProxy:AmendHistoryPos(data, sort, startIndex, endIndex)
- self.VOdata:AmendHistoryPos(data, sort, startIndex, endIndex)
- end
- -- 清理背包数据及位置
- function BagProxy:CleanBagPosData()
- self.VOdata:CleanBagPosData()
- end
- -- 通过itemIndex获取物品数据
- function BagProxy:GetItemDataByItemIndex(itemIndex)
- local someItems = {}
- if not itemIndex then
- return someItems
- end
- local items = self:GetBagData()
- for _, v in pairs(items) do
- if v.Index == itemIndex then
- tinsert(someItems, v)
- end
- end
- return someItems
- end
- -- 通过物品名称获取物品数据
- function BagProxy:GetItemDataByItemName(itemName)
- if not itemName then
- return nil
- end
- local someItems = {}
- local items = self:GetBagData()
- for _, v in pairs(items) do
- if v.Name == itemName then
- tinsert(someItems, v)
- end
- end
- if not next(someItems) then
- return nil
- end
- return someItems
- end
- -- 通过itemIndex获取物品数量 famlilar是否包含绑定数量
- function BagProxy:GetItemCountByIndex(Index, famlilar)
- Index = Index or 0
- local count = 0
- local ItemConfigProxy = global.Facade:retrieveProxy(global.ProxyTable.ItemConfigProxy)
- local isBind, bindIndex = ItemConfigProxy:CheckItemBind(Index)
- local myCount = self.VOdata:GetItemCountByIndex(Index)
- local famlilarCount = 0
- if isBind and bindIndex ~= Index and famlilar then
- famlilarCount = self.VOdata:GetItemCountByIndex(bindIndex)
- end
- local totalCount = myCount + famlilarCount
- return totalCount
- end
- -- 设置正在交易或修理中
- function BagProxy:SetOnSellOrRepaire(MakeIndex)
- self._on_sell_repaire = MakeIndex
- global.Facade:sendNotification(global.NoticeTable.Bag_Item_Pos_Change)
- end
- -- 获取是否在交易或修理
- function BagProxy:GetOnSellOrRepaire()
- return self._on_sell_repaire
- end
- -- 清理交易或修理
- function BagProxy:CleanOnSellOrRepaire()
- self._on_sell_repaire = nil
- global.Facade:sendNotification(global.NoticeTable.Bag_Item_Pos_Change)
- end
- -- 添加物品
- function BagProxy:AddItemData(item, noNotice)
- if not item then
- return
- end
- local itemPos = self.VOdata:GetHistoryPos(item.MakeIndex) or self:NewItemPos()
- if itemPos then
- self.VOdata:SetItemPosData(item.MakeIndex, itemPos)
- end
- if not noNotice then
- self:ShowGetOrCostItems(item.OverLap or 1, item.Name)
- end
- self.VOdata:AddItem(item, itemPos)
- local ItemManagerProxy = global.Facade:retrieveProxy(global.ProxyTable.ItemManagerProxy)
- ItemManagerProxy:SetItemBelong(item.MakeIndex, global.MMO.ITEM_FROM_BELONG_BAG)
- end
- -- 显示获得或消耗物品
- function BagProxy:ShowGetOrCostItems(diff, name)
- if self.VOdata:IsInited() then
- return
- end
- local nData = {}
- nData.name = name
- nData.num = math.abs(diff)
- local notice = diff > 0 and global.NoticeTable.ShowGetBagItem or global.NoticeTable.ShowCostItem
- global.Facade:sendNotification(notice, nData)
- end
- -- 增加物品并通知
- function BagProxy:AddItemDataAndNotice(item)
- self:AddItemData(item)
- local operator = {}
- operator.opera = global.MMO.Operator_Add
- operator.operID = {}
- tinsert(operator.operID, MAKE_OPER_DATA(item, false))
- ssr.ssrBridge:OnPreBagOperData(operator)
- global.Facade:sendNotification(global.NoticeTable.Bag_Oper_Data, operator)
- ssr.ssrBridge:OnBagOperData(operator)
- SLBridge:onLUAEvent(LUA_EVENT_BAG_ITEM_CHANGE, operator)
- -- 延迟通知
- self:DelayNotifyBagOper()
- end
- -- 延迟通知,部分系统不需要实时监听背包改变,并且不需要知道背包操作类型,节省性能
- function BagProxy:DelayNotifyBagOper()
- if self._delayNotifyTimerID then
- UnSchedule(self._delayNotifyTimerID)
- self._delayNotifyTimerID = nil
- end
- self._delayNotifyTimerID = PerformWithDelayGlobal(function()
- global.Facade:sendNotification(global.NoticeTable.Bag_Oper_Data_Delay)
- end, 0.5)
- end
- -- 删除物品
- function BagProxy:DelItemData(data, showTip, noCleanPos, noNotify, isBaitan)
- if not data or not next(data) then
- return
- end
- local MakeIndex = data.MakeIndex
- local itemHasPos = true
- local noPosData = self.VOdata:GetBagNoPosDataByMakeIndex(MakeIndex)
- local item = self:GetItemDataByMakeIndex(MakeIndex)
- if noPosData then
- itemHasPos = false
- item = noPosData
- end
- if item then
- if not self.VOdata:IsInited() then
- global.Facade:sendNotification(global.NoticeTable.Layer_Auto_Use_UnAttach, {
- id = item.MakeIndex
- })
- end
- local operator = {}
- operator.opera = global.MMO.Operator_Sub
- operator.operID = {}
- operator.isBaitan = isBaitan
- local operitem = self:BagOperItemByMakeIndex(MakeIndex, itemHasPos)
- tinsert(operator.operID, operitem)
- self.VOdata:SubItem(MakeIndex)
- if not noCleanPos then
- self.VOdata:CleanItemPosData(MakeIndex)
- end
- local ItemManagerProxy = global.Facade:retrieveProxy(global.ProxyTable.ItemManagerProxy)
- ItemManagerProxy:SetItemBelong(item.MakeIndex, nil)
- if not noNotify then
- ssr.ssrBridge:OnPreBagOperData(operator)
- global.Facade:sendNotification(global.NoticeTable.Bag_Oper_Data, operator)
- ssr.ssrBridge:OnBagOperData(operator)
- SLBridge:onLUAEvent(LUA_EVENT_BAG_ITEM_CHANGE, operator)
- -- 延迟通知
- self:DelayNotifyBagOper()
- end
- if showTip then
- self:ShowGetOrCostItems(-(item.OverLap or 1), item.Name)
- end
- -- 缓存中的数据自动补充到背包
- local noPosData = self.VOdata:GetBagNoPosData()
- if noPosData and next(noPosData) and itemHasPos then
- for _, v in pairs(noPosData) do
- if v and next(v) then
- self:DelItemData(v, nil, nil, true)
- self:AddItemDataAndNotice(v)
- break
- end
- end
- end
- -- 清理删除红点
- local RedDotProxy = global.Facade:retrieveProxy(global.ProxyTable.RedDotProxy)
- RedDotProxy:DeleteBagRedDot(MakeIndex)
- end
- end
- function BagProxy:BagOperItemByMakeIndex(MakeIndex, isShowInBag)
- local item = self:GetItemDataByMakeIndex(MakeIndex)
- if not isShowInBag then
- item = self.VOdata:GetBagNoPosDataByMakeIndex(MakeIndex)
- end
- local operator = {}
- if item then
- local MakeIndex = item.MakeIndex
- operator.MakeIndex = MakeIndex
- operator.item = item
- end
- return operator
- end
- -- 更改物品数据
- function BagProxy:ChangeItemData(item)
- local makeIndex = item.MakeIndex
- local newnum = item.OverLap or 1
- local diff = 0
- local data = self:GetItemDataByMakeIndex(makeIndex)
- if data then
- local oldnum = data.OverLap or 1
- diff = newnum - oldnum
- self.VOdata:ChangeItem(item)
- if diff ~= 0 then
- self:ShowGetOrCostItems(diff, item.Name)
- end
- end
- return diff
- end
- -- 清理背包
- function BagProxy:ClearItemData(isReconnect)
- local array = self.VOdata:GetBagData()
- for key, var in pairs(array) do
- self:DelItemData(var, nil, true, isReconnect)
- end
- local arrayNoPos = self.VOdata:GetBagNoPosData()
- for _, item in pairs(arrayNoPos) do
- self:DelItemData(item, nil, nil, isReconnect)
- end
- self.VOdata:ClearItemData()
- end
- -- 换位
- function BagProxy:ExchangePos(MakeIndex1, pos1, MakeIndex2, pos2)
- self.VOdata:CleanItemPosData(MakeIndex1)
- self.VOdata:CleanItemPosData(MakeIndex2)
- self.VOdata:SetItemPosData(MakeIndex1, pos1)
- self.VOdata:SetItemPosData(MakeIndex2, pos2)
- global.Facade:sendNotification(global.NoticeTable.Bag_Item_Pos_Change, {MakeIndex1, MakeIndex2})
- end
- -- 修改位置数据
- function BagProxy:SetItemPosData(MakeIndex, pos)
- self.VOdata:CleanItemPosData(MakeIndex)
- self.VOdata:SetItemPosData(MakeIndex, pos)
- global.Facade:sendNotification(global.NoticeTable.Bag_Item_Pos_Change, {MakeIndex})
- end
- -- 获取背包道具的使用状态(0:使用 1:使用准星道具 2:取消准星 3:不可使用)
- function BagProxy:GetOnBagItemUseState(data)
- if self._collimator_MakeIndex then
- if self._collimator_MakeIndex == -1 then -- 脚本
- return 1
- end
- if data and self._collimator_MakeIndex == data.MakeIndex then
- return 2
- end
- return 1
- end
- return 0
- end
- -- 设置准星道具
- function BagProxy:SetBagCollimator(data)
- self._collimator_MakeIndex = data
- end
- -- 获取准星道具
- function BagProxy:GetBagCollimator()
- return self._collimator_MakeIndex
- end
- -- 清理准星道具
- function BagProxy:ClearBagCollimator()
- self._collimator_MakeIndex = nil
- end
- -- 获取自定义属性数据
- function BagProxy:GetCustomAttrData(MakeIndex)
- if not MakeIndex then
- return
- end
- return self._customAttrs[MakeIndex]
- end
- function BagProxy:IsReceiveBagData()
- return self._receiveBagData
- end
- function BagProxy:InitBagSizeWithData(bagSize)
- self:SetServerBagNum(bagSize)
- local QuickUseProxy = global.Facade:retrieveProxy(global.ProxyTable.QuickUseProxy)
- local quickUseSize = QuickUseProxy:GetQuickUseSize()
- local maxBag = self:GetServerBagNum() + global.MMO.QUICK_USE_SIZE - quickUseSize
- self:SetMaxBag(maxBag)
- end
- -- 是否背包满等待
- function BagProxy:IsBagFullWait()
- -- body
- if self._bagFullTimerID then
- return true
- end
- return false
- end
- -- 背包满等待计时
- function BagProxy:BagFullTimerBegan()
- if not self._bagFullTimerID then
- local function callback()
- self._bagFullTimerID = nil
- end
- self._bagFullTimerID = PerformWithDelayGlobal(callback, self._bagFullInterval)
- end
- end
- -- 背包满计时重置
- function BagProxy:BagFullTimerReset()
- -- body
- if self._bagFullTimerID then
- UnSchedule( self._bagFullTimerID )
- end
- self._bagFullTimerID = nil
- end
- -- 背包数据初始化
- function BagProxy:handle_MSG_SC_RETURN_BAGDATA(msg)
- local msgHdr = msg:GetHeader()
- local data = ParseRawMsgToJson(msg)
- -- print("------------------------------------")
- -- print(" into here to get and set bag data")
- -- print("------------------------------------")
- if not data then
- return
- end
- self._receiveBagData = true
- local isInit = msgHdr.param1 == 1
- if isInit then
- self:Inited(true)
- end
- local changedData = {}
- local dataCount = 0
- for _, v in ipairs(data) do
- local changeData = ChangeItemServersSendDatas(v)
- tinsert(changedData, changeData)
- dataCount = dataCount + 1
- end
- data = changedData
- -- 清理缓存
- if self.VOdata:IsInited() then
- self._init_count = 0
- self:Inited(false)
- self:ClearItemData()
- if msgHdr.recog > 0 then
- self:InitBagSizeWithData(msgHdr.recog)
- end
- end
- local startIndex = self._init_count + 1
- local endIndex = self._init_count + dataCount
- -- 301 最后一次的数据
- if msgHdr.msgId == global.MsgType.MSG_SC_RETURN_BAGDATA_REMAINING then
- endIndex = self:GetMaxBag()
- end
- self._init_count = self._init_count + dataCount
- -- 修正本地位置信息数据
- self:AmendHistoryPos(data, false, startIndex, endIndex)
- local history = {}
- for key, var in pairs(self.VOdata:GetBagData()) do
- history[var.MakeIndex] = var.MakeIndex
- end
- local operator = {}
- operator.initbool = false
- operator.opera = global.MMO.Operator_Init
- operator.operID = {}
- local QuickUseProxy = global.Facade:retrieveProxy(global.ProxyTable.QuickUseProxy)
- for _, item in pairs(data) do
- local quickUsePos = QuickUseProxy:CheckIsInQucikUseList(item)
- if quickUsePos then -- 快捷栏道具
- QuickUseProxy:SetQuickUsePosData(quickUsePos, item)
- else
- self:AddItemData(item, true)
- if not history[item.MakeIndex] then
- tinsert(operator.operID, MAKE_OPER_DATA(item, false))
- end
- end
- end
- if msgHdr.msgId == global.MsgType.MSG_SC_RETURN_BAGDATA_REMAINING then -- 301 最后一次的数据
- QuickUseProxy:RequireHistoryQuickyUseList() -- 修正本地信息
- end
- if not self._reconnect then
- ssr.ssrBridge:OnPreBagOperData(operator)
- global.Facade:sendNotification(global.NoticeTable.Bag_Oper_Data, operator)
- ssr.ssrBridge:OnBagOperData(operator)
- SLBridge:onLUAEvent(LUA_EVENT_BAG_ITEM_CHANGE, operator)
- global.Facade:sendNotification(global.NoticeTable.QuickUseDataInit)
- ssr.ssrBridge:OnQuickUseOperData({
- opera = 0
- })
- SLBridge:onLUAEvent(LUA_EVENT_QUICKUSE_DATA_OPER, {opera = 0})
- -- 延迟通知
- self:DelayNotifyBagOper()
- end
- end
- -- 增加道具
- function BagProxy:handle_MSG_SC_BAG_ADD_ITEM(msg)
- local header = msg:GetHeader()
- local recog = header.recog
- local data = ParseRawMsgToJson(msg)
- -- print("------------------------------------")
- -- print(" into here to add bag item")
- -- print("------------------------------------")
- if not recog or not data or next(data) == nil then
- return
- end
- if recog == -1 then
- data = ChangeItemServersSendDatas(data)
- if _DEBUG then
- local _ditem = self:GetItemDataByMakeIndex(data.MakeIndex)
- if _ditem then
- print("ERROR BAG ITEM EXIST, CAN'T ADD IT AGAIN", data.MakeIndex)
- end
- end
- local QuickUseProxy = global.Facade:retrieveProxy(global.ProxyTable.QuickUseProxy)
- local isCanAddToQuick = QuickUseProxy:CheckItemCanAddToQuickUse(data)
- local quickUsePos = QuickUseProxy:CheckQuickUseHasEmpty()
- -- 快捷栏道具
- if isCanAddToQuick and quickUsePos then
- self:ShowGetOrCostItems(data.OverLap or 1, data.Name)
- QuickUseProxy:SetQuickUsePosData(quickUsePos, data)
- else
- self:AddItemData(data)
- local operator = {}
- operator.opera = global.MMO.Operator_Add
- operator.operID = {}
- tinsert(operator.operID, MAKE_OPER_DATA(data, false))
- ssr.ssrBridge:OnPreBagOperData(operator)
- global.Facade:sendNotification(global.NoticeTable.Bag_Oper_Data, operator)
- ssr.ssrBridge:OnBagOperData(operator)
- SLBridge:onLUAEvent(LUA_EVENT_BAG_ITEM_CHANGE, operator)
- -- 延迟通知
- self:DelayNotifyBagOper()
- end
- else
- data = ChangeItemServersSendDatas(data)
- local proxy = global.Facade:retrieveProxy(global.ProxyTable.Equip)
- data.Where = recog
- proxy:AddEquipData(data)
- end
- end
- -- 删除道具
- function BagProxy:handle_MSG_SC_BAG_DEL_ITEM(msg)
- local header = msg:GetHeader()
- local makeIndex = header.recog
- local ItemManagerProxy = global.Facade:retrieveProxy(global.ProxyTable.ItemManagerProxy)
- local itemBelong = ItemManagerProxy:GetItemBelong(makeIndex)
- if not itemBelong then
- print("delete item error, can't find item belong")
- return
- end
- if itemBelong == global.MMO.ITEM_FROM_BELONG_BAG then
- local itemData = self:GetItemDataByMakeIndex(makeIndex)
- if not itemData then
- print("delete item error, can't find item")
- return
- end
- self:DelItemData(itemData, true)
- elseif itemBelong == global.MMO.ITEM_FROM_BELONG_EQUIP then
- local EquipProxy = global.Facade:retrieveProxy(global.ProxyTable.Equip)
- local itemData = EquipProxy:GetEquipDataByMakeIndex(makeIndex)
- if not itemData then
- print("delete item error, can't find item")
- return
- end
- EquipProxy:DelEquipData(itemData)
- elseif itemBelong == global.MMO.ITEM_FROM_BELONG_QUICKUSE then
- local QuickUseProxy = global.Facade:retrieveProxy(global.ProxyTable.QuickUseProxy)
- local itemData = QuickUseProxy:GetQucikUseDataByMakeIndex(makeIndex)
- if not itemData then
- print("delete item error, can't find item")
- return
- end
- self:ShowGetOrCostItems(-(itemData.OverLap or 1), itemData.Name)
- -- 自动补充
- local pos = QuickUseProxy:GetQucikUsePosByMakeIndex(itemData.MakeIndex)
- QuickUseProxy:SetQuickUsePosData(pos, itemData, true)
- local function delayAutoAddd()
- QuickUseProxy:AutoAddBagItemToQuick(itemData, pos)
- end
- PerformWithDelayGlobal(delayAutoAddd, 0.5)
- elseif itemBelong == global.MMO.ITEM_FROM_BELONG_STALL then
- local StallProxy = global.Facade:retrieveProxy(global.ProxyTable.StallProxy)
- StallProxy:PutOutItem(makeIndex, true)
- end
- self:BagFullTimerReset()
- -- 清理一下自定义属性
- if self._customAttrs[makeIndex] then
- self._customAttrs[makeIndex] = nil
- SLBridge:onLUAEvent(LUA_EVENT_ITEM_CUSTOM_ATTR, {
- MakeIndex = makeIndex,
- data = nil
- })
- end
- end
- -- 更新道具
- function BagProxy:handle_MSG_SC_BAG_UPDATE_ITEM(msg)
- local data = ParseRawMsgToJson(msg)
- -- print("------------------------------------")
- -- print(" into here to update bag item")
- -- print("------------------------------------")
- if not data or next(data) == nil then
- return
- end
- local itemMakeIndex = data.MakeIndex or data.makeindex
- local ItemManagerProxy = global.Facade:retrieveProxy(global.ProxyTable.ItemManagerProxy)
- local itemBelong = ItemManagerProxy:GetItemBelong(itemMakeIndex)
- if not itemBelong then
- return
- end
- data = ChangeItemServersSendDatas(data)
- if global.MMO.ITEM_FROM_BELONG_BAG == itemBelong then
- local operator = {}
- operator.opera = global.MMO.Operator_Change
- operator.operID = {}
- local diff = self:ChangeItemData(data)
- tinsert(operator.operID, MAKE_OPER_DATA(data, true, diff))
- ssr.ssrBridge:OnPreBagOperData(operator)
- global.Facade:sendNotification(global.NoticeTable.Bag_Oper_Data, operator)
- ssr.ssrBridge:OnBagOperData(operator)
- SLBridge:onLUAEvent(LUA_EVENT_BAG_ITEM_CHANGE, operator)
- -- 延迟通知
- self:DelayNotifyBagOper()
- elseif global.MMO.ITEM_FROM_BELONG_EQUIP == itemBelong then
- local proxy = global.Facade:retrieveProxy(global.ProxyTable.Equip)
- proxy:ChangeEquipData(data, true, true)
- elseif itemBelong == global.MMO.ITEM_FROM_BELONG_QUICKUSE then
- local QuickUseProxy = global.Facade:retrieveProxy(global.ProxyTable.QuickUseProxy)
- QuickUseProxy:UpDateQuickUseItemData(data)
- end
- -- for item update.
- local updateData = {
- from = itemBelong,
- item = data
- }
- global.Facade:sendNotification(global.NoticeTable.ItemUpdate, updateData)
- end
- function BagProxy:handle_MSG_SC_BAG_ITEM_USE_SUCCESS(msg)
- local header = msg:GetHeader()
- local ItemIndex = header.recog
- end
- -- 道具使用失败
- function BagProxy:handle_MSG_SC_BAG_ITEM_USE_FAILED(msg)
- print("道具使用失败消息")
- local header = msg:GetHeader()
- local makeIndex = header.recog
- local itemData = self:GetItemDataByMakeIndex(makeIndex)
- if itemData and itemData.StdMode == 49 then
- -- 49类型道具使用失败提醒 0关闭 非0开启
- if SL:GetMetaValue("GAME_DATA","Pearl_on_off") ~= 0 then
- global.Facade:sendNotification(global.NoticeTable.SystemTips, GET_STRING(50000321))
- end
- end
- end
- -- 道具拾取失败 -1背包满 -2负重满 -3物品禁止拾取 -99假道具拾取
- function BagProxy:handle_MSG_SC_DROP_ITEM_GET_FAILED(msg)
- local header = msg:GetHeader()
- local recog = header.recog
- if recog == -1 then
- self:BagFullTimerBegan()
- global.Facade:sendNotification(global.NoticeTable.SystemTips, GET_STRING(800050))
- elseif recog == -2 then
- global.Facade:sendNotification(global.NoticeTable.SystemTips, GET_STRING(800052))
- elseif recog == -3 then
- global.Facade:sendNotification(global.NoticeTable.SystemTips, GET_STRING(800056))
- elseif recog == -99 then
- local mapX = header.param1
- local mapY = header.param2
- local dItems = global.dropItemManager:FindDropItemAllInMapXY(mapX, mapY)
- if not dItems then
- return
- end
- for k, dItem in pairs(dItems) do
- if dItem:GetPickState() >= 1 or dItem:IsPickTimeout() then --移除
- global.gameMapController:rmvDropItem(dItem:GetID())
- end
- end
- end
- end
- -- 丢弃道具成功
- function BagProxy:handle_MSG_SC_DROP_ITEM_SUCCESS(msg)
- local header = msg:GetHeader()
- local MakeIndex = header.recog
- if MakeIndex then
- tinsert(self._selfDropItems, MakeIndex)
- if #self._selfDropItems > 100 then -- 记录自己丢弃的物品 挂机拾取的时候忽略
- table.remove(self._selfDropItems, 1)
- end
-
- local ItemManagerProxy = global.Facade:retrieveProxy(global.ProxyTable.ItemManagerProxy)
- local belong = ItemManagerProxy:GetItemBelong(MakeIndex)
- if global.MMO.ITEM_FROM_BELONG_BAG == belong then
- -- 背包中的重新刷出来
- local data = {
- dropping = {
- MakeIndex = MakeIndex,
- state = 1
- }
- }
- global.Facade:sendNotification(global.NoticeTable.Bag_State_Change, data)
- elseif global.MMO.ITEM_FROM_BELONG_QUICKUSE == belong then
- local QuickUseProxy = global.Facade:retrieveProxy(global.ProxyTable.QuickUseProxy)
- local itemPos = QuickUseProxy:GetQucikUsePosByMakeIndex(MakeIndex)
- local data = {
- pos = itemPos,
- state = 1
- }
- global.Facade:sendNotification(global.NoticeTable.QuickUseItemRefresh, data)
- ssr.ssrBridge:OnQuickUseOperData({
- opera = 4,
- param = data
- })
- end
- end
- local AutoProxy = global.Facade:retrieveProxy(global.ProxyTable.Auto)
- AutoProxy:ClearAutoMining()
- end
- -- 丢弃道具失败
- function BagProxy:handle_MSG_SC_DROP_ITEM_FAILED(msg)
- local header = msg:GetHeader()
- local MakeIndex = header.recog
- local ItemManagerProxy = global.Facade:retrieveProxy(global.ProxyTable.ItemManagerProxy)
- local belong = ItemManagerProxy:GetItemBelong(MakeIndex)
- if global.MMO.ITEM_FROM_BELONG_BAG == belong then
- -- 背包中的重新刷出来
- local data = {
- dropping = {
- MakeIndex = MakeIndex,
- state = 1
- }
- }
- global.Facade:sendNotification(global.NoticeTable.Bag_State_Change, data)
- elseif global.MMO.ITEM_FROM_BELONG_QUICKUSE == belong then
- local QuickUseProxy = global.Facade:retrieveProxy(global.ProxyTable.QuickUseProxy)
- local itemPos = QuickUseProxy:GetQucikUsePosByMakeIndex(MakeIndex)
- local data = {
- pos = itemPos,
- state = 1
- }
- global.Facade:sendNotification(global.NoticeTable.QuickUseItemRefresh, data)
- ssr.ssrBridge:OnQuickUseOperData({
- opera = 4,
- param = data
- })
- end
- end
- -- 移动到英雄背包失败
- function BagProxy:handle_MSG_SC_HUMBAG_TO_HEROBAG_FAIL(msg)
- local header = msg:GetHeader()
- local MakeIndex = header.recog
- dump(header, "handle_MSG_SC_HUMBAG_TO_HEROBAG_FAIL")
- local ItemManagerProxy = global.Facade:retrieveProxy(global.ProxyTable.ItemManagerProxy)
- local belong = ItemManagerProxy:GetItemBelong(MakeIndex)
- if global.MMO.ITEM_FROM_BELONG_BAG == belong then
- -- 背包中的重新刷出来
- local data = {
- dropping = {
- MakeIndex = MakeIndex,
- state = 1
- }
- }
- global.Facade:sendNotification(global.NoticeTable.Bag_State_Change, data)
- elseif global.MMO.ITEM_FROM_BELONG_QUICKUSE == belong then
- local QuickUseProxy = global.Facade:retrieveProxy(global.ProxyTable.QuickUseProxy)
- local itemPos = QuickUseProxy:GetQucikUsePosByMakeIndex(MakeIndex)
- local data = {
- pos = itemPos,
- state = 1
- }
- global.Facade:sendNotification(global.NoticeTable.QuickUseItemRefresh, data)
- ssr.ssrBridge:OnQuickUseOperData({
- opera = 4,
- param = data
- })
- end
- end
- -- 整理背包
- function BagProxy:handle_MSG_SC_RESET_BAG_POS(msg)
- local QuickUseProxy = global.Facade:retrieveProxy(global.ProxyTable.QuickUseProxy)
- local bagData = self:GetBagData()
- for _, v in pairs(bagData) do
- local isCanAddToQuick = QuickUseProxy:CheckItemCanAddToQuickUse(v)
- local quickUsePos = QuickUseProxy:CheckQuickUseHasEmpty()
- -- 快捷栏道具
- if isCanAddToQuick and quickUsePos then
- QuickUseProxy:AutoAddBagItemToQuick(v, quickUsePos)
- end
- end
- local newData = self:GetBagData()
- self:CleanBagPosData()
- self:AmendHistoryPos(newData, true)
- global.Facade:sendNotification(global.NoticeTable.Bag_Pos_Reset)
- SLBridge:onLUAEvent(LUA_EVENT_REF_ITEM_LIST)
- end
- -- 开启准星
- function BagProxy:handle_MSG_SM_COLLIMATOR_RESPONSE(msg)
- local jsonData = ParseRawMsgToJson(msg)
- if jsonData and jsonData.UseMakeIndex then
- if jsonData.UseMakeIndex > -1 then
- self:SetBagCollimator(jsonData.UseMakeIndex)
- global.Facade:sendNotification(global.NoticeTable.Bag_Item_Collimator, jsonData.UseMakeIndex)
- elseif jsonData.UseMakeIndex == -1 then
- self:SetBagCollimator(jsonData.UseMakeIndex)
- global.Facade:sendNotification(global.NoticeTable.Layer_Sight_Bead_Show)
- end
- end
- end
- function BagProxy:CheckNeedRefreshEquipShow(makeIndex)
- if not makeIndex then
- return
- end
- local ItemManagerProxy = global.Facade:retrieveProxy(global.ProxyTable.ItemManagerProxy)
- local itemBelong = ItemManagerProxy:GetItemBelong(makeIndex)
- if not itemBelong then
- return
- end
-
- if itemBelong == global.MMO.ITEM_FROM_BELONG_EQUIP then
- local EquipProxy = global.Facade:retrieveProxy(global.ProxyTable.Equip)
- local itemData = EquipProxy:GetEquipDataByMakeIndex(makeIndex)
- if not itemData then
- return
- end
- local makeIndex = itemData.MakeIndex
- local where = itemData.Where
-
- local sData = {}
- sData.MakeIndex = makeIndex
- sData.Where = where
- sData.opera = global.MMO.Operator_Change
- sData.bagDelayUpdate = nil
- sData.isChangeLook = true
- global.Facade:sendNotification(global.NoticeTable.PlayEquip_Oper_Data, sData)
- SLBridge:onLUAEvent(LUA_EVENT_PLAYER_EQUIP_CHANGE, sData)
- end
- end
- -- 物品自定义属性
- function BagProxy:handle_MSG_SC_ITEM_PARAMS(msg)
- local jsonData = ParseRawMsgToJson(msg)
- if not jsonData then
- return
- end
- for i,v in pairs(jsonData) do
- self._customAttrs[v.m] = v.p
- SLBridge:onLUAEvent(LUA_EVENT_ITEM_CUSTOM_ATTR, {
- MakeIndex = v.m,
- data = v.p
- })
- if SL:GetMetaValue("GAME_DATA", "CustomAttrUpdatePlayerEquip") == 1 then
- self:CheckNeedRefreshEquipShow(v.m)
- end
- end
- end
- -- 交易行物品自定义属性需要客户端自行设置
- function BagProxy:SetTradingBankItemParams(makeIndex, param)
- if not makeIndex then
- return
- end
- self._customAttrs[makeIndex] = param
- SLBridge:onLUAEvent(LUA_EVENT_ITEM_CUSTOM_ATTR, {
- MakeIndex = makeIndex,
- data = param
- })
- end
- -- 批量设置交易行角色 背包/仓库/身上物品自定义属性
- function BagProxy:SetTradingBankItemParamsBatch(jsonData)
- if not jsonData then
- return
- end
- releasePrint("!SetTradingBankItemParamsBatch______")
- for i, v in ipairs(jsonData) do
- self._customAttrs[v.m] = v.p
- SLBridge:onLUAEvent(LUA_EVENT_ITEM_CUSTOM_ATTR, {
- MakeIndex = v.m,
- data = v.p
- })
- end
- end
- -- 请求背包数据
- function BagProxy:RequestBagData()
- self:Inited(true)
- LuaSendMsg(global.MsgType.MSG_CS_REQUEST_BAGDATA)
- end
- -- 叠加道具
- function BagProxy:RequestItemTwoToOne(MakeIndex1, MakeIndex2)
- LuaSendMsg(global.MsgType.MSG_CS_ITEM_TWO_TO_ONE, MakeIndex1, MakeIndex2, 0, 0)
- end
- -- 拆分道具
- function BagProxy:RequestCountItem(makeIndex, num)
- LuaSendMsg(global.MsgType.MSG_CS_ITEM_NUMBER_CHANGE, makeIndex, num, 0, 0)
- end
- -- 请求准星瞄准消息(使用)
- function BagProxy:RequestCollimator(MakeIndex)
- if MakeIndex then
- LuaSendMsg(global.MsgType.MSG_CM_COLLIMATOR_REQUEST, MakeIndex)
- end
- end
- -- 请求取消准星瞄准
- function BagProxy:RequestCanceCollimator()
- LuaSendMsg(global.MsgType.MSG_CM_CANCELCOLLIMATOR_REQUEST, 0, 0, 0, 0)
- end
- function BagProxy:onRegister()
- BagProxy.super.onRegister(self)
- end
- function BagProxy:RegisterMsgHandler()
- BagProxy.super.RegisterMsgHandler(self)
- local msgType = global.MsgType
- LuaRegisterMsgHandler(msgType.MSG_SC_RETURN_BAGDATA, handler(self, self.handle_MSG_SC_RETURN_BAGDATA))
- LuaRegisterMsgHandler(msgType.MSG_SC_BAG_ADD_ITEM, handler(self, self.handle_MSG_SC_BAG_ADD_ITEM))
- LuaRegisterMsgHandler(msgType.MSG_SC_BAG_DEL_ITEM, handler(self, self.handle_MSG_SC_BAG_DEL_ITEM))
- LuaRegisterMsgHandler(msgType.MSG_SC_BAG_UPDATE_ITEM, handler(self, self.handle_MSG_SC_BAG_UPDATE_ITEM))
- LuaRegisterMsgHandler(msgType.MSG_SC_BAG_ITEM_USE_SUCCESS, handler(self, self.handle_MSG_SC_BAG_ITEM_USE_SUCCESS) )
- LuaRegisterMsgHandler(msgType.MSG_SC_BAG_ITEM_USE_FAILED, handler(self, self.handle_MSG_SC_BAG_ITEM_USE_FAILED))
- LuaRegisterMsgHandler(msgType.MSG_SC_DROP_ITEM_GET_FAILED, handler(self, self.handle_MSG_SC_DROP_ITEM_GET_FAILED))
- LuaRegisterMsgHandler(msgType.MSG_SC_DROP_ITEM_SUCCESS, handler(self, self.handle_MSG_SC_DROP_ITEM_SUCCESS))
- LuaRegisterMsgHandler(msgType.MSG_SC_DROP_ITEM_FAILED, handler(self, self.handle_MSG_SC_DROP_ITEM_FAILED))
- LuaRegisterMsgHandler(msgType.MSG_SC_HUMBAG_TO_HEROBAG_FAIL, handler(self, self.handle_MSG_SC_HUMBAG_TO_HEROBAG_FAIL))
- LuaRegisterMsgHandler(msgType.MSG_SC_RESET_BAG_POS, handler(self, self.handle_MSG_SC_RESET_BAG_POS))
- LuaRegisterMsgHandler(msgType.MSG_SM_COLLIMATOR_RESPONSE, handler(self, self.handle_MSG_SM_COLLIMATOR_RESPONSE))
- LuaRegisterMsgHandler(msgType.MSG_SC_RETURN_BAGDATA_REMAINING, handler(self, self.handle_MSG_SC_RETURN_BAGDATA))
- LuaRegisterMsgHandler(msgType.MSG_SC_ITEM_PARAMS, handler(self, self.handle_MSG_SC_ITEM_PARAMS))
- end
- return BagProxy
|