AutoUseItemProxy.lua 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. local RemoteProxy = requireProxy("remote/RemoteProxy")
  2. local AutoUseItemProxy = class("AutoUseItemProxy", RemoteProxy)
  3. AutoUseItemProxy.NAME = global.ProxyTable.AutoUseItemProxy
  4. local ssplit = string.split
  5. function AutoUseItemProxy:ctor()
  6. AutoUseItemProxy.super.ctor(self)
  7. -- 脱下的装备
  8. self._equip_off_makeindex = {}
  9. -- 不显示的装备(key: 装备名/装备Index/装备唯一id)
  10. self._not_tip_equips = {
  11. [1] = {}, -- key: MakeIndex
  12. [2] = {}, -- key: Index
  13. [3] = {}, -- key: Name, value: 次数(可能有好几个)
  14. [99] = false, -- 总开关 是否打开提示 默认不提示
  15. }
  16. -- tips的装备数据 {key: 装备位 value: 装备唯一id}
  17. self._equip_tips = {
  18. [1] = {}, -- 人物
  19. [2] = {} -- 英雄
  20. }
  21. end
  22. function AutoUseItemProxy:onRegister()
  23. AutoUseItemProxy.super.onRegister(self)
  24. end
  25. -- 记录脱下的装备
  26. function AutoUseItemProxy:AddEquipOffMakeIndex(MakeIndex)
  27. if MakeIndex then
  28. self._equip_off_makeindex[MakeIndex] = true
  29. end
  30. end
  31. -- 判断是否是脱下的装备
  32. function AutoUseItemProxy:IsEquipOffByMakeIndex(MakeIndex)
  33. local offEquip = false
  34. if MakeIndex and self._equip_off_makeindex[MakeIndex] then
  35. offEquip = true
  36. self._equip_off_makeindex[MakeIndex] = nil
  37. end
  38. return offEquip
  39. end
  40. -- 判断是否是不弹出的装备
  41. function AutoUseItemProxy:IsEquipNotTip(data)
  42. if not data or not next(data) then
  43. return true
  44. end
  45. if self._not_tip_equips[99] then
  46. return true
  47. end
  48. local name = tostring(data.Name) or -1
  49. local Index = tostring(data.Index) or -1
  50. local MakeIndex = tostring(data.MakeIndex) or -1
  51. if self._not_tip_equips[1][MakeIndex] or self._not_tip_equips[2][Index] or self._not_tip_equips[3][name] then
  52. return true
  53. end
  54. return false
  55. end
  56. -- huoqu
  57. function AutoUseItemProxy:GetBagPosByMakeIndex(MakeIndex)
  58. for i, v in ipairs(self._equip_tips) do
  59. for kk, vv in pairs(v) do
  60. if vv == MakeIndex then
  61. return kk
  62. end
  63. end
  64. end
  65. return nil
  66. end
  67. function AutoUseItemProxy:GetMakeIndexByPos(type, pos)
  68. if (type ~= 1 and type ~= 2) or not pos then
  69. return nil
  70. end
  71. local list = self._equip_tips[type] or {}
  72. return list[pos]
  73. end
  74. function AutoUseItemProxy:SetMakeIndexByPos(type, pos, makeIndex)
  75. type = type or 1
  76. if (type ~= 1 and type ~= 2) or not pos then
  77. return nil
  78. end
  79. self._equip_tips[type][pos] = makeIndex
  80. end
  81. -- 移除tips的装备数据 pos: 装备位 playerType:人物类型(1: 人物; 2: 英雄)
  82. function AutoUseItemProxy:RemoveEquipTip(pos, playerType)
  83. playerType = playerType or 1
  84. if pos then
  85. self._equip_tips[playerType][pos] = nil
  86. end
  87. end
  88. -- 服务端通知不显示自动穿戴的消息
  89. function AutoUseItemProxy:handle_MSG_SC_NOT_AUTO_TIPS_EQUIPS(msg)
  90. --[[ recog = 1;body = Makeindex
  91. recog = 2;body = ItemIdx
  92. recog = 3;body = ItemName
  93. ]]
  94. local header = msg:GetHeader()
  95. if header.recog == 1 or header.recog == 2 or header.recog == 3 then
  96. local msgLen = msg:GetDataLength()
  97. if msgLen > 0 then
  98. local isAdd = header.param1 ~= 1 and true or false -- 1删除 非1添加
  99. local dataString = msg:GetData():ReadString(msgLen)
  100. local count = self._not_tip_equips[header.recog][tostring(dataString)] or 0
  101. count = isAdd and (count + 1) or (count - 1)
  102. self._not_tip_equips[header.recog][tostring(dataString)] = count > 0 and count or nil
  103. end
  104. elseif header.recog == 99 then
  105. local msgLen = msg:GetDataLength()
  106. if msgLen > 0 then
  107. local dataString = msg:GetData():ReadString(msgLen)
  108. local openValue = dataString and tonumber(dataString) or 0
  109. local isOpen = openValue ~= 1 and true or false -- 1关闭(因为是不弹出, 所以关闭就是开启) 非1开启
  110. self._not_tip_equips[99] = not isOpen
  111. end
  112. end
  113. end
  114. function AutoUseItemProxy:RegisterMsgHandler()
  115. AutoUseItemProxy.super.RegisterMsgHandler(self)
  116. LuaRegisterMsgHandler(global.MsgType.MSG_SC_NOT_AUTO_TIPS_EQUIPS, handler(self, self.handle_MSG_SC_NOT_AUTO_TIPS_EQUIPS))
  117. end
  118. return AutoUseItemProxy