HeroEquipVO.lua 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. local HeroEquipData = class( "HeroEquipData" )
  2. --[[
  3. README:
  4. 装备替换时时没有卸下消息
  5. 服务器消息具体的顺序为
  6. 1.删除背包道具
  7. 2.添加替换上的装备到人物装备数据中
  8. 3.添加装备栏卸下的道具到背包
  9. 这样会导致 人物装备数据中没有删除
  10. 所以前端手动删除
  11. 故在AddItem方法中删除了同位置的历史数据
  12. 并且刷新一遍背包 不刷新会导致背包战力对比没有刷新
  13. ]]
  14. function HeroEquipData:ctor()
  15. self.dataByMakeIndex = {}
  16. self.dataByPos = {}
  17. end
  18. function HeroEquipData:GetData()
  19. return self.dataByMakeIndex
  20. end
  21. function HeroEquipData:GetEquipPosData()
  22. return self.dataByPos
  23. end
  24. function HeroEquipData:GetDataByMakeIndex(MakeIndex)
  25. if self.dataByMakeIndex[MakeIndex] then
  26. return self.dataByMakeIndex[MakeIndex]
  27. end
  28. return nil
  29. end
  30. function HeroEquipData:GetDataByPos(pos)
  31. local item = nil
  32. if self.dataByPos[pos] then
  33. local MakeIndex = self.dataByPos[pos].MakeIndex
  34. item = self:GetDataByMakeIndex(MakeIndex)
  35. end
  36. return item
  37. end
  38. function HeroEquipData:ClearData()
  39. self.dataByMakeIndex = {}
  40. self.dataByPos = {}
  41. end
  42. function HeroEquipData:AddItem(item)
  43. local MakeIndex = item.MakeIndex
  44. local Where = item.Where
  45. self.dataByMakeIndex[MakeIndex] = item
  46. if not self.dataByPos[Where] then
  47. self.dataByPos[Where] = {}
  48. elseif self.dataByPos[Where] and next(self.dataByPos[Where]) then
  49. -- 清除原来该位置上的装备信息
  50. -- local lastMakeIndex = self.dataByPos[Where].MakeIndex
  51. -- self.dataByMakeIndex[lastMakeIndex] = nil
  52. end
  53. self.dataByPos[Where].MakeIndex = MakeIndex
  54. -- 刷一遍背包
  55. -- 这里刷一遍是因为没有装备卸下的步骤
  56. -- global.Facade:sendNotification(global.NoticeTable.Bag_Item_Pos_Change)
  57. end
  58. function HeroEquipData:SubItem(item)
  59. local equip = self:GetDataByMakeIndex(item.MakeIndex)
  60. if equip then
  61. local Where = equip.Where
  62. self.dataByPos[Where] = nil
  63. self.dataByMakeIndex[item.MakeIndex] = nil
  64. end
  65. end
  66. function HeroEquipData:ChangeItem(item)
  67. local MakeIndex = item.MakeIndex
  68. if self.dataByMakeIndex[MakeIndex] then
  69. self.dataByMakeIndex[MakeIndex] = item
  70. end
  71. end
  72. return HeroEquipData