HeroBagProxy.lua 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709
  1. local RemoteProxy = requireProxy("remote/RemoteProxy")
  2. local HeroBagProxy = class("HeroBagProxy", RemoteProxy)
  3. HeroBagProxy.NAME = global.ProxyTable.HeroBagProxy
  4. local tinsert = table.insert
  5. local function MAKE_OPER_DATA(item, isHad, number)
  6. local operator = {}
  7. operator.item = item
  8. operator.isHad = isHad
  9. operator.change = number
  10. operator.MakeIndex = item.MakeIndex
  11. return operator
  12. end
  13. HeroBagProxy.BAG_SELECT_TYPE = {
  14. TYPE_ALL = 0, -- 全部
  15. TYPE_EQUIP = 1, -- 装备
  16. TYPE_EXP = 2, -- 经验
  17. TYPE_REIN = 3, -- 转生
  18. TYPE_PET = 4, -- 宠物
  19. TYPE_OTHER = 5 -- 其他
  20. }
  21. local bag_Level = {[10] = 1, [20] = 2, [30] = 3, [35] = 4, [40] = 5}
  22. function HeroBagProxy:ctor()
  23. HeroBagProxy.super.ctor(self)
  24. local BagVO = requireVO("remote/HeroBagVO")
  25. self.VOdata = BagVO.new()
  26. self.m_maxNum = 40 -- 服务端发的英雄最大背包格子数
  27. self.m_level = 5
  28. self._prompt_data = nil -- cfg_game_data的prompt
  29. self._selfDropItems = {} -- 英雄丢弃的物品
  30. self._on_sell_repaire = nil -- 正在交易或者修理中物品
  31. self._collimator_MakeIndex = nil -- 记录背包选中的准星道具
  32. end
  33. function HeroBagProxy:setBagMaxNum(num)
  34. self.m_maxNum = num
  35. self.m_level = bag_Level[num] or 5
  36. end
  37. function HeroBagProxy:getBagMaxNum()
  38. return self.m_maxNum
  39. end
  40. function HeroBagProxy:getBagLevel()
  41. return self.m_level
  42. end
  43. function HeroBagProxy:GetSelfDropItems()
  44. return self._selfDropItems
  45. end
  46. -- item提示:类似右上角满 获取cfg_game_data表的prompt字段的数据
  47. function HeroBagProxy:GetPromptGameData()
  48. if not self._prompt_data then
  49. self._prompt_data = {}
  50. local prompt = SL:GetMetaValue("GAME_DATA","prompt")
  51. if prompt and string.len(prompt) then
  52. local promptArray = string.split(prompt, "|")
  53. for _, v in ipairs(promptArray) do
  54. if v and string.len(v) > 0 then
  55. local valueArray = string.split(v, "#")
  56. tinsert(self._prompt_data, {
  57. resPath = valueArray[1],
  58. posX = valueArray[2] and tonumber(valueArray[2]) or nil,
  59. posY = valueArray[3] and tonumber(valueArray[3]) or nil,
  60. resScale = valueArray[4] and tonumber(valueArray[4]) or nil
  61. })
  62. end
  63. end
  64. end
  65. end
  66. if global.isWinPlayMode then
  67. return self._prompt_data[1] or {}
  68. end
  69. return self._prompt_data[2] or {}
  70. end
  71. function HeroBagProxy:Inited(bool)
  72. self.VOdata:Inited(bool)
  73. end
  74. function HeroBagProxy:GetBagData()
  75. return self.VOdata:GetBagData()
  76. end
  77. function HeroBagProxy:GetTotalItemCount()
  78. return self.VOdata:GetItemCount()
  79. end
  80. function HeroBagProxy:isToBeFull(tips)
  81. if tips and self.VOdata:isFull() then
  82. global.Facade:sendNotification(global.NoticeTable.SystemTips, GET_STRING(800050))
  83. end
  84. return self.VOdata:isFull()
  85. end
  86. function HeroBagProxy:CheckNeedSpace(itemID, itemCount, tips)
  87. local ItemConfigProxy = global.Facade:retrieveProxy(global.ProxyTable.ItemConfigProxy)
  88. local itemData = ItemConfigProxy:GetItemDataByIndex(itemID)
  89. local isLap = ItemConfigProxy:CheckItemOverLap(itemData)
  90. local needPos = itemCount
  91. if isLap then
  92. needPos = math.ceil(itemCount / itemData.OverLap)
  93. end
  94. local bagItemNum = self:GetTotalItemCount()
  95. if bagItemNum + needPos > self.m_maxNum then
  96. if tips then
  97. global.Facade:sendNotification(global.NoticeTable.SystemTips, GET_STRING(1021))
  98. end
  99. return false
  100. end
  101. return true
  102. end
  103. -- 通过唯一id获取在背包中的位置
  104. function HeroBagProxy:GetBagPosByMakeIndex(MakeIndex)
  105. return self.VOdata:GetBagPosByMakeIndex(MakeIndex)
  106. end
  107. -- 通过在背包中的位置获取唯一id
  108. function HeroBagProxy:GetMakeIndexByBagPos(pos)
  109. return self.VOdata:GetMakeIndexByBagPos(pos)
  110. end
  111. -- 通过唯一id获取物品数据
  112. function HeroBagProxy:GetItemDataByMakeIndex(MakeIndex)
  113. return self.VOdata:GetItemByMakeIndex(MakeIndex)
  114. end
  115. -- 获取新位置
  116. function HeroBagProxy:NewItemPos()
  117. return self.VOdata:NewItemPos()
  118. end
  119. -- 修正历史数据与当前数据位置信息
  120. function HeroBagProxy:AmendHistoryPos(data, sort)
  121. self.VOdata:AmendHistoryPos(data, sort)
  122. end
  123. -- 清理背包数据及位置
  124. function HeroBagProxy:CleanBagPosData()
  125. self.VOdata:CleanBagPosData()
  126. end
  127. -- 通过itemIndex获取物品数据
  128. function HeroBagProxy:GetItemDataByItemIndex(itemIndex)
  129. local someItems = {}
  130. if not itemIndex then
  131. return someItems
  132. end
  133. local items = self:GetBagData()
  134. for _, v in pairs(items) do
  135. if v.Index == itemIndex then
  136. tinsert(someItems, v)
  137. end
  138. end
  139. return someItems
  140. end
  141. -- 通过物品名称获取物品数据
  142. function HeroBagProxy:GetItemDataByItemName(itemName)
  143. if not itemName then
  144. return nil
  145. end
  146. local someItems = {}
  147. local items = self:GetBagData()
  148. for _, v in pairs(items) do
  149. if v.Name == itemName then
  150. tinsert(someItems, v)
  151. end
  152. end
  153. if not next(someItems) then
  154. return nil
  155. end
  156. return someItems
  157. end
  158. -- 通过itemIndex获取物品数量 famlilar是否包含绑定数量
  159. function HeroBagProxy:GetItemCountByIndex(Index, famlilar)
  160. Index = Index or 0
  161. local count = 0
  162. local ItemConfigProxy = global.Facade:retrieveProxy(global.ProxyTable.ItemConfigProxy)
  163. local isBind, bindIndex = ItemConfigProxy:CheckItemBind(Index)
  164. local myCount = self.VOdata:GetItemCountByIndex(Index)
  165. local famlilarCount = 0
  166. if isBind and bindIndex ~= Index and famlilar then
  167. famlilarCount = self.VOdata:GetItemCountByIndex(bindIndex)
  168. end
  169. local totalCount = myCount + famlilarCount
  170. return totalCount
  171. end
  172. -- 设置正在交易或修理中
  173. function HeroBagProxy:SetOnSellOrRepaire(MakeIndex)
  174. self._on_sell_repaire = MakeIndex
  175. global.Facade:sendNotification(global.NoticeTable.HeroBag_Item_Pos_Change)
  176. end
  177. -- 获取是否在交易或修理
  178. function HeroBagProxy:GetOnSellOrRepaire()
  179. return self._on_sell_repaire
  180. end
  181. -- 清理交易或修理
  182. function HeroBagProxy:CleanOnSellOrRepaire()
  183. self._on_sell_repaire = nil
  184. global.Facade:sendNotification(global.NoticeTable.HeroBag_Item_Pos_Change)
  185. end
  186. -- 添加物品
  187. function HeroBagProxy:AddItemData(item, noNotice)
  188. if not item then
  189. return
  190. end
  191. local itemPos = self.VOdata:GetHistoryPos(item.MakeIndex) or self:NewItemPos()
  192. if itemPos then
  193. self.VOdata:SetItemPosData(item.MakeIndex, itemPos)
  194. end
  195. if not noNotice then
  196. self:ShowGetOrCostItems(item.OverLap or 1, item.Name)
  197. end
  198. self.VOdata:AddItem(item, itemPos)
  199. local ItemManagerProxy = global.Facade:retrieveProxy(global.ProxyTable.ItemManagerProxy)
  200. ItemManagerProxy:SetItemBelong(item.MakeIndex, global.MMO.ITEM_FROM_BELONG_HEROBAG)
  201. end
  202. -- 显示获得或消耗物品
  203. function HeroBagProxy:ShowGetOrCostItems(diff, name)
  204. if self.VOdata:IsInited() then
  205. return
  206. end
  207. local nData = {}
  208. nData.name = name
  209. nData.num = math.abs(diff)
  210. local notice = diff > 0 and global.NoticeTable.ShowGetBagItem_Hero or global.NoticeTable.ShowCostItem_Hero
  211. global.Facade:sendNotification(notice, nData)
  212. end
  213. -- 增加物品并通知
  214. function HeroBagProxy:AddItemDataAndNotice(item)
  215. self:AddItemData(item)
  216. local operator = {}
  217. operator.opera = global.MMO.Operator_Add
  218. operator.operID = {}
  219. tinsert(operator.operID, MAKE_OPER_DATA(item, false))
  220. global.Facade:sendNotification(global.NoticeTable.HeroBag_Oper_Data, operator)
  221. SLBridge:onLUAEvent(LUA_EVENT_HERO_BAG_ITEM_CAHNGE, operator)
  222. end
  223. -- 删除物品
  224. function HeroBagProxy:DelItemData(data, showTip, noCleanPos, noNotify)
  225. if not data or not next(data) then
  226. return
  227. end
  228. local MakeIndex = data.MakeIndex
  229. local itemHasPos = true
  230. local noPosData = self.VOdata:GetBagNoPosDataByMakeIndex(MakeIndex)
  231. local item = self:GetItemDataByMakeIndex(MakeIndex)
  232. if noPosData then
  233. itemHasPos = false
  234. item = noPosData
  235. end
  236. if item then
  237. if not self.VOdata:IsInited() then
  238. global.Facade:sendNotification(global.NoticeTable.Layer_Auto_Use_UnAttach, { id = item.MakeIndex })
  239. end
  240. local operator = {}
  241. operator.opera = global.MMO.Operator_Sub
  242. operator.operID = {}
  243. local operitem = self:BagOperItemByMakeIndex(MakeIndex, itemHasPos)
  244. tinsert(operator.operID, operitem)
  245. self.VOdata:SubItem(MakeIndex)
  246. if not noCleanPos then
  247. self.VOdata:CleanItemPosData(MakeIndex)
  248. end
  249. local ItemManagerProxy = global.Facade:retrieveProxy(global.ProxyTable.ItemManagerProxy)
  250. ItemManagerProxy:SetItemBelong(item.MakeIndex, nil)
  251. if not noNotify then
  252. global.Facade:sendNotification(global.NoticeTable.HeroBag_Oper_Data, operator)
  253. SLBridge:onLUAEvent(LUA_EVENT_HERO_BAG_ITEM_CAHNGE, operator)
  254. end
  255. if showTip then
  256. self:ShowGetOrCostItems(-(item.OverLap or 1), item.Name)
  257. end
  258. -- 缓存中的数据自动补充到背包
  259. local noPosData = self.VOdata:GetBagNoPosData()
  260. if noPosData and next(noPosData) and itemHasPos then
  261. for _, v in pairs(noPosData) do
  262. if v and next(v) then
  263. self:DelItemData(v, nil, nil, true)
  264. self:AddItemDataAndNotice(v, true)
  265. break
  266. end
  267. end
  268. end
  269. end
  270. end
  271. function HeroBagProxy:BagOperItemByMakeIndex(MakeIndex, isShowInBag)
  272. local item = self:GetItemDataByMakeIndex(MakeIndex)
  273. if not isShowInBag then
  274. item = self.VOdata:GetBagNoPosDataByMakeIndex(MakeIndex)
  275. end
  276. local operator = {}
  277. if item then
  278. local MakeIndex = item.MakeIndex
  279. operator.MakeIndex = MakeIndex
  280. operator.item = item
  281. end
  282. return operator
  283. end
  284. -- 更改物品数据
  285. function HeroBagProxy:ChangeItemData(item)
  286. local makeIndex = item.MakeIndex
  287. local newnum = item.OverLap or 1
  288. local diff = 0
  289. local data = self:GetItemDataByMakeIndex(makeIndex)
  290. if data then
  291. local oldnum = data.OverLap or 1
  292. diff = newnum - oldnum
  293. self.VOdata:ChangeItem(item)
  294. if diff ~= 0 then
  295. self:ShowGetOrCostItems(diff, item.Name)
  296. end
  297. end
  298. return diff
  299. end
  300. -- 清理背包
  301. function HeroBagProxy:ClearItemData()
  302. local array = self.VOdata:GetBagData()
  303. for key, var in pairs(array) do
  304. self:DelItemData(var, nil, true)
  305. end
  306. local arrayNoPos = self.VOdata:GetBagNoPosData()
  307. for _, item in pairs(arrayNoPos) do
  308. self:DelItemData(item)
  309. end
  310. self.VOdata:ClearItemData()
  311. end
  312. -- 换位
  313. function HeroBagProxy:ExchangePos(MakeIndex1, pos1, MakeIndex2, pos2)
  314. self.VOdata:CleanItemPosData(MakeIndex1)
  315. self.VOdata:CleanItemPosData(MakeIndex2)
  316. self.VOdata:SetItemPosData(MakeIndex1, pos1)
  317. self.VOdata:SetItemPosData(MakeIndex2, pos2)
  318. global.Facade:sendNotification(global.NoticeTable.HeroBag_Item_Pos_Change, { MakeIndex1, MakeIndex2 })
  319. end
  320. -- 修改位置数据
  321. function HeroBagProxy:SetItemPosData(MakeIndex, pos)
  322. self.VOdata:CleanItemPosData(MakeIndex)
  323. self.VOdata:SetItemPosData(MakeIndex, pos)
  324. global.Facade:sendNotification(global.NoticeTable.HeroBag_Item_Pos_Change, { MakeIndex })
  325. end
  326. -- 获取背包道具的使用状态(0:使用 1:使用准星道具 2:取消准星 3:不可使用)
  327. function HeroBagProxy:GetOnBagItemUseState(data)
  328. if self._collimator_MakeIndex then
  329. if self._collimator_MakeIndex == -1 then -- 脚本
  330. return 1
  331. end
  332. if data and self._collimator_MakeIndex == data.MakeIndex then
  333. return 2
  334. end
  335. return 1
  336. end
  337. return 0
  338. end
  339. -- 设置准星道具
  340. function HeroBagProxy:SetBagCollimator(data)
  341. self._collimator_MakeIndex = data
  342. end
  343. -- 获取准星道具
  344. function HeroBagProxy:GetBagCollimator()
  345. return self._collimator_MakeIndex
  346. end
  347. -- 清理准星道具
  348. function HeroBagProxy:ClearBagCollimator()
  349. self._collimator_MakeIndex = nil
  350. end
  351. -- 背包数据初始化
  352. function HeroBagProxy:handle_MSG_SC_RETURN_BAGDATA_HERO(msg)
  353. local header = msg:GetHeader()
  354. local data = ParseRawMsgToJson(msg)
  355. -- print("------------------------------------")
  356. -- print(" into here to get and set bag data")
  357. -- print("------------------------------------")
  358. if not data then
  359. return
  360. end
  361. local changedData = {}
  362. for _, v in ipairs(data) do
  363. local changeData = ChangeItemServersSendDatas(v)
  364. tinsert(changedData, changeData)
  365. end
  366. data = changedData
  367. -- 排序整理
  368. if header.recog == 1 then
  369. self:CleanBagPosData()
  370. self:AmendHistoryPos(data, true)
  371. global.Facade:sendNotification(global.NoticeTable.HeroBag_Pos_Reset)
  372. SLBridge:onLUAEvent(LUA_EVENT_REF_HERO_ITEM_LIST)
  373. else
  374. --清理缓存
  375. self:ClearItemData()
  376. --修正本地位置信息数据
  377. self:AmendHistoryPos(data)
  378. local history = {}
  379. for key, var in pairs(self.VOdata:GetBagData()) do
  380. history[var.MakeIndex] = var.MakeIndex
  381. end
  382. local operator = {}
  383. operator.initbool = false
  384. operator.opera = global.MMO.Operator_Init
  385. operator.operID = {}
  386. for _, item in pairs(data) do
  387. self:AddItemData(item)
  388. if not history[item.MakeIndex] then
  389. tinsert(operator.operID, MAKE_OPER_DATA(item, false))
  390. end
  391. end
  392. if not self.reconnet then
  393. global.Facade:sendNotification(global.NoticeTable.HeroBag_Oper_Data, operator)
  394. SLBridge:onLUAEvent(LUA_EVENT_HERO_BAG_ITEM_CAHNGE, operator)
  395. elseif self.reconnet then
  396. self.reconnet = false
  397. end
  398. -- 是否初始化
  399. if self.VOdata:IsInited() then
  400. self:Inited(false)
  401. end
  402. end
  403. end
  404. -- 增加道具
  405. function HeroBagProxy:handle_MSG_SC_BAG_ADD_ITEM_HERO(msg)
  406. local header = msg:GetHeader()
  407. local recog = header.recog
  408. local data = ParseRawMsgToJson(msg)
  409. -- print("------------------------------------")
  410. -- print(" into here to add bag item")
  411. -- print("------------------------------------")
  412. if not recog or not data or next(data) == nil then
  413. return
  414. end
  415. if recog == -1 then
  416. data = ChangeItemServersSendDatas(data)
  417. self:AddItemData(data)
  418. local operator = {}
  419. operator.opera = global.MMO.Operator_Add
  420. operator.operID = {}
  421. tinsert(operator.operID, MAKE_OPER_DATA(data, false))
  422. global.Facade:sendNotification(global.NoticeTable.HeroBag_Oper_Data, operator)
  423. SLBridge:onLUAEvent(LUA_EVENT_HERO_BAG_ITEM_CAHNGE, operator)
  424. else
  425. data = ChangeItemServersSendDatas(data)
  426. local HeroEquipProxy = global.Facade:retrieveProxy(global.ProxyTable.HeroEquipProxy)
  427. data.Where = recog
  428. HeroEquipProxy:AddEquipData(data)
  429. end
  430. end
  431. -- 删除道具
  432. function HeroBagProxy:handle_MSG_SC_BAG_DEL_ITEM_HERO(msg)
  433. local data = ParseRawMsgToJson(msg)
  434. -- print("------------------------------------")
  435. -- print(" into here to delete bag item")
  436. -- print("------------------------------------")
  437. if not data or next(data) == nil then
  438. return
  439. end
  440. local itemMakeIndex = data.MakeIndex or data.makeindex
  441. local ItemManagerProxy = global.Facade:retrieveProxy(global.ProxyTable.ItemManagerProxy)
  442. local itemBelong = ItemManagerProxy:GetItemBelong(itemMakeIndex)
  443. if not itemBelong then
  444. return
  445. end
  446. data = ChangeItemServersSendDatas(data)
  447. if itemBelong == global.MMO.ITEM_FROM_BELONG_HEROBAG then
  448. self:DelItemData(data, true)
  449. elseif itemBelong == global.MMO.ITEM_FROM_BELONG_HEROEQUIP then
  450. local HeroEquipProxy = global.Facade:retrieveProxy(global.ProxyTable.HeroEquipProxy)
  451. HeroEquipProxy:DelEquipData(data)
  452. end
  453. end
  454. -- 更新道具
  455. function HeroBagProxy:handle_MSG_SC_BAG_UPDATE_ITEM_HERO(msg)
  456. local data = ParseRawMsgToJson(msg)
  457. -- print("------------------------------------")
  458. -- print(" into here to update herobag item")
  459. -- print("------------------------------------")
  460. if not data or next(data) == nil then
  461. return
  462. end
  463. local itemMakeIndex = data.MakeIndex or data.makeindex
  464. local ItemManagerProxy = global.Facade:retrieveProxy(global.ProxyTable.ItemManagerProxy)
  465. local itemBelong = ItemManagerProxy:GetItemBelong(itemMakeIndex)
  466. if not itemBelong then
  467. return
  468. end
  469. data = ChangeItemServersSendDatas(data)
  470. if global.MMO.ITEM_FROM_BELONG_HEROBAG == itemBelong then
  471. local operator = {}
  472. operator.opera = global.MMO.Operator_Change
  473. operator.operID = {}
  474. local diff = self:ChangeItemData(data)
  475. tinsert(operator.operID, MAKE_OPER_DATA(data, true, diff))
  476. global.Facade:sendNotification(global.NoticeTable.HeroBag_Oper_Data, operator)
  477. SLBridge:onLUAEvent(LUA_EVENT_HERO_BAG_ITEM_CAHNGE, operator)
  478. elseif global.MMO.ITEM_FROM_BELONG_HEROEQUIP == itemBelong then
  479. local proxy = global.Facade:retrieveProxy(global.ProxyTable.HeroEquipProxy)
  480. proxy:ChangeEquipData(data, true, true)
  481. end
  482. -- for item update.
  483. local updateData = {
  484. from = itemBelong,
  485. item = data,
  486. }
  487. global.Facade:sendNotification(global.NoticeTable.ItemUpdate, updateData)
  488. end
  489. -- 道具使用失败
  490. function HeroBagProxy:handle_MSG_SC_BAG_ITEM_USE_FAILED_HERO(msg)
  491. print("道具使用失败消息")
  492. local header = msg:GetHeader()
  493. local makeIndex = header.recog
  494. local itemData = self:GetItemDataByMakeIndex(makeIndex)
  495. if itemData and itemData.StdMode == 49 then
  496. global.Facade:sendNotification(global.NoticeTable.SystemTips, GET_STRING(50000321))
  497. end
  498. end
  499. -- 道具拾取失败 -1背包满 -2负重满 -3物品禁止拾取
  500. function HeroBagProxy:handle_MSG_SC_DROP_ITEM_GET_FAILED(msg)
  501. local header = msg:GetHeader()
  502. local recog = header.recog
  503. if recog == -1 then
  504. global.Facade:sendNotification(global.NoticeTable.SystemTips, GET_STRING(800050))
  505. elseif recog == -2 then
  506. global.Facade:sendNotification(global.NoticeTable.SystemTips, GET_STRING(800052))
  507. elseif recog == -3 then
  508. global.Facade:sendNotification(global.NoticeTable.SystemTips, GET_STRING(800056))
  509. end
  510. end
  511. -- 丢弃道具成功
  512. function HeroBagProxy:handle_MSG_SC_DROP_ITEM_SUCCESS(msg)
  513. local header = msg:GetHeader()
  514. local MakeIndex = header.recog
  515. if MakeIndex then
  516. tinsert(self._selfDropItems, MakeIndex)
  517. if #self._selfDropItems > 100 then -- 记录自己丢弃的物品 挂机拾取的时候忽略
  518. table.remove(self._selfDropItems, 1)
  519. end
  520. local ItemManagerProxy = global.Facade:retrieveProxy(global.ProxyTable.ItemManagerProxy)
  521. local belong = ItemManagerProxy:GetItemBelong(MakeIndex)
  522. if global.MMO.ITEM_FROM_BELONG_HEROBAG == belong then
  523. -- 背包中的重新刷出来
  524. local data = {
  525. dropping = {
  526. MakeIndex = MakeIndex,
  527. state = 1
  528. }
  529. }
  530. global.Facade:sendNotification(global.NoticeTable.HeroBag_State_Change, data)
  531. end
  532. end
  533. end
  534. -- 丢弃道具失败
  535. function HeroBagProxy:handle_MSG_SC_DROP_ITEM_FAILED(msg)
  536. local header = msg:GetHeader()
  537. local MakeIndex = header.recog
  538. if MakeIndex then
  539. local ItemManagerProxy = global.Facade:retrieveProxy(global.ProxyTable.ItemManagerProxy)
  540. local belong = ItemManagerProxy:GetItemBelong(MakeIndex)
  541. if global.MMO.ITEM_FROM_BELONG_HEROBAG == belong then
  542. -- 背包中的重新刷出来
  543. local data = {
  544. dropping = {
  545. MakeIndex = MakeIndex,
  546. state = 1
  547. }
  548. }
  549. global.Facade:sendNotification(global.NoticeTable.HeroBag_State_Change, data)
  550. end
  551. end
  552. end
  553. -- 英雄背包到人物背包失败
  554. function HeroBagProxy:handle_MSG_SC_HEROBAG_TO_HUMBAG_FAIL(msg)
  555. local header = msg:GetHeader()
  556. local MakeIndex = header.recog
  557. dump(header, "handle_MSG_SC_HEROBAG_TO_HUMBAG_FAIL")
  558. if MakeIndex then
  559. local ItemManagerProxy = global.Facade:retrieveProxy(global.ProxyTable.ItemManagerProxy)
  560. local belong = ItemManagerProxy:GetItemBelong(MakeIndex)
  561. if global.MMO.ITEM_FROM_BELONG_HEROBAG == belong then
  562. -- 背包中的重新刷出来
  563. local data = {
  564. dropping = {
  565. MakeIndex = MakeIndex,
  566. state = 1
  567. }
  568. }
  569. global.Facade:sendNotification(global.NoticeTable.HeroBag_State_Change, data)
  570. end
  571. end
  572. end
  573. -- 叠加道具
  574. function HeroBagProxy:RequestItemTwoToOne(MakeIndex1, MakeIndex2)
  575. LuaSendMsg(global.MsgType.MSG_CS_ITEM_TWO_TO_ONE, MakeIndex1, MakeIndex2, 0, 0)
  576. end
  577. -- 拆分道具
  578. function HeroBagProxy:RequestCountItem(makeIndex, num)
  579. LuaSendMsg(global.MsgType.MSG_CS_ITEM_NUMBER_CHANGE, makeIndex, num, 0, 0)
  580. end
  581. --请求人物背包到英雄背包
  582. function HeroBagProxy:RequestHumBagToHeroBag(makeindex, ItemName)
  583. dump({ makeindex, ItemName }, "RequestHumBagToHeroBag___")
  584. LuaSendMsg(global.MsgType.MSG_CS_HUMBAG_TO_HEROBAG, makeindex, 0, 0, 0, ItemName, string.len(ItemName))
  585. end
  586. --请求英雄背包到人物背包
  587. function HeroBagProxy:RequestHeroBagToHumBag(makeindex, ItemName)
  588. dump({ makeindex, ItemName }, "RequestHeroBagToHumBag")
  589. LuaSendMsg(global.MsgType.MSG_CS_HEROBAG_TO_HUMBAG, makeindex, 0, 0, 0, ItemName, string.len(ItemName))
  590. end
  591. function HeroBagProxy:onRegister()
  592. HeroBagProxy.super.onRegister(self)
  593. end
  594. function HeroBagProxy:RegisterMsgHandler()
  595. HeroBagProxy.super.RegisterMsgHandler(self)
  596. local msgType = global.MsgType
  597. LuaRegisterMsgHandler(msgType.MSG_SC_RETURN_BAGDATA_HERO, handler(self, self.handle_MSG_SC_RETURN_BAGDATA_HERO))
  598. LuaRegisterMsgHandler(msgType.MSG_SC_BAG_ADD_ITEM_HERO, handler(self, self.handle_MSG_SC_BAG_ADD_ITEM_HERO))
  599. LuaRegisterMsgHandler(msgType.MSG_SC_BAG_DEL_ITEM_HERO, handler(self, self.handle_MSG_SC_BAG_DEL_ITEM_HERO))
  600. LuaRegisterMsgHandler(msgType.MSG_SC_BAG_UPDATE_ITEM_HERO, handler(self, self.handle_MSG_SC_BAG_UPDATE_ITEM_HERO))
  601. LuaRegisterMsgHandler(msgType.MSG_SC_BAG_ITEM_USE_FAILED_HERO, handler(self, self.handle_MSG_SC_BAG_ITEM_USE_FAILED_HERO))
  602. LuaRegisterMsgHandler(msgType.MSG_SC_DROP_ITEM_SUCCESS_HERO, handler(self, self.handle_MSG_SC_DROP_ITEM_SUCCESS))
  603. LuaRegisterMsgHandler(msgType.MSG_SC_DROP_ITEM_FAILED_HERO, handler(self, self.handle_MSG_SC_DROP_ITEM_FAILED))
  604. LuaRegisterMsgHandler(msgType.MSG_SC_HEROBAG_TO_HUMBAG_FAIL, handler(self, self.handle_MSG_SC_HEROBAG_TO_HUMBAG_FAIL))
  605. end
  606. return HeroBagProxy