BubbleProxy.lua 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. local RemoteProxy = requireProxy("remote/RemoteProxy")
  2. local BubbleProxy = class("BubbleProxy", RemoteProxy)
  3. BubbleProxy.NAME = global.ProxyTable.BubbleProxy
  4. --前端条件 气泡表
  5. local cjson = require("cjson")
  6. local getVarNames = nil
  7. getVarNames = function(conditions, vec)
  8. if not conditions then
  9. return
  10. end
  11. if conditions.dType == 2 then
  12. for i, condition in ipairs(conditions.conditions) do
  13. if condition.dType == 2 then
  14. getVarNames(condition, vec)
  15. else
  16. local name = ""
  17. if condition.var.Hero then
  18. name = "H_" .. name
  19. end
  20. name = name .. condition.var.key
  21. if condition.var.value then
  22. name = name .. "_" .. condition.var.value
  23. end
  24. table.insert(vec, name)
  25. end
  26. end
  27. else
  28. local name = ""
  29. if conditions.var.Hero then
  30. name = "H_" .. name
  31. end
  32. name = name .. conditions.var.key
  33. if conditions.var.value then
  34. name = name .. "_" .. conditions.var.value
  35. end
  36. table.insert(vec, name)
  37. end
  38. end
  39. function BubbleProxy:ctor()
  40. BubbleProxy.super.ctor(self)
  41. self:Init()
  42. end
  43. function BubbleProxy:onRegister()
  44. BubbleProxy.super.onRegister(self)
  45. end
  46. function BubbleProxy:Init()
  47. self._configs = {}
  48. self._valList = {} --触发表
  49. self._scheduleId = nil
  50. self._needCheckIDs = {}
  51. self._needCheckIDsVec = {}
  52. self._activeIDs = {}--激活列表
  53. self:LoadConfig()
  54. self:InitItems()
  55. end
  56. function BubbleProxy:LoadConfig()
  57. local configs = requireGameConfig("cfg_bubble")
  58. for k, v in pairs(configs) do
  59. self._configs[v.id] = v
  60. end
  61. end
  62. function BubbleProxy:InitItems()
  63. for id, config in pairs(self._configs) do
  64. self:addVarList(id)
  65. end
  66. end
  67. function BubbleProxy:StartSchedule()
  68. if self._scheduleId then
  69. UnSchedule(self._scheduleId)
  70. self._scheduleId = nil
  71. end
  72. self._scheduleId = Schedule(function()
  73. for i = 1, 5 do
  74. if #self._needCheckIDsVec > 0 then
  75. local id = table.remove(self._needCheckIDsVec, 1)
  76. local config = self._configs[id]
  77. if self:CheckStrConditions(config.VarCondition1,{ BindCurrency = config.BindCurrency })
  78. and self:CheckStrConditions(config.VarCondition2,{ BindCurrency = config.BindCurrency })
  79. and self:CheckStrConditions(config.currencyCondition, { BindCurrency = config.BindCurrency }) then --满足条件
  80. self:addActiveID(config.id)
  81. else
  82. self:rmvActiveID(config.id)
  83. end
  84. self._needCheckIDs[id] = false
  85. else
  86. break
  87. end
  88. end
  89. end, 1 / 60)
  90. end
  91. function BubbleProxy:addActiveID(id)
  92. if not self._activeIDs[id] then
  93. self._activeIDs[id] = true
  94. local config = self._configs[id]
  95. local RemindUpgradeProxy = global.Facade:retrieveProxy(global.ProxyTable.RemindUpgradeProxy)
  96. RemindUpgradeProxy:refData(id,true,{id = id,name = config.ShowText,link = config.Link})
  97. end
  98. end
  99. function BubbleProxy:rmvActiveID(id)
  100. if not self._activeIDs[id] then
  101. return
  102. end
  103. self._activeIDs[id] = false
  104. local RemindUpgradeProxy = global.Facade:retrieveProxy(global.ProxyTable.RemindUpgradeProxy)
  105. RemindUpgradeProxy:refData(id,false)
  106. end
  107. function BubbleProxy:addVarList(id)--增加触发变量
  108. local config = self._configs[id]
  109. local RedPointProxy = global.Facade:retrieveProxy(global.ProxyTable.RedPointProxy)
  110. local vConditions = RedPointProxy:getConditions(config.VarCondition1,{ BindCurrency = config.BindCurrency })
  111. local vConditions2 = RedPointProxy:getConditions(config.VarCondition2,{ BindCurrency = config.BindCurrency })
  112. local cConditions = RedPointProxy:getConditions(config.currencyCondition, { BindCurrency = config.BindCurrency })
  113. local namevec = {}
  114. getVarNames(vConditions, namevec)
  115. getVarNames(vConditions2, namevec)
  116. getVarNames(cConditions, namevec)
  117. for i, varname in ipairs(namevec) do
  118. self._valList[varname] = self._valList[varname] or {}
  119. self._valList[varname][id] = config
  120. end
  121. end
  122. -------------------------------------------------------------
  123. function BubbleProxy:CheckStrConditions(str, exData)
  124. if not str or str == "" then
  125. return true
  126. end
  127. local RedPointProxy = global.Facade:retrieveProxy(global.ProxyTable.RedPointProxy)
  128. return RedPointProxy:CheckStrConditions(str, exData)
  129. end
  130. function BubbleProxy:InstertCheckQue(Var)
  131. local List = self._valList[Var]
  132. if List then
  133. for id, val in pairs(List) do
  134. if not self._needCheckIDs[id] then
  135. self._needCheckIDs[id] = true
  136. table.insert(self._needCheckIDsVec, id)
  137. end
  138. end
  139. end
  140. end
  141. return BubbleProxy