Efficiency.lua 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. Efficiency = {}
  2. local redDotType = {
  3. efficiency = 1,
  4. efficiency_level = 2,
  5. }
  6. -- 校验激活状态
  7. function Efficiency.CheckActive(actor, ids)
  8. local msg = {}
  9. for _, id in ipairs(ids) do
  10. local condition = ConfigDataManager.getTableValue("cfg_efficiency", "conditions", "id", id)
  11. if condition == '' then
  12. goto continue
  13. end
  14. -- 激活过的信息
  15. -- local group = ConfigDataManager.getTableValue("cfg_efficiency", "group", "id", id)
  16. -- local actives = getplaydef(actor, "T$effcicency_active")
  17. -- if group ~= '1' then
  18. -- if actives then
  19. -- if actives[id] then
  20. -- table.insert(msg, id)
  21. -- goto continue
  22. -- end
  23. -- else
  24. -- actives = {}
  25. -- end
  26. -- end
  27. -- lg(condition)
  28. local result = ConditionManager.Check(actor, condition)
  29. if result then
  30. table.insert(msg, id)
  31. -- if group ~= '1' then
  32. -- -- actives[id] = true
  33. -- setplaydef(actor, "T$effcicency_active", actives)
  34. -- end
  35. end
  36. ::continue::
  37. end
  38. -- lg(msg)
  39. sendluamsg(actor, LuaMessageIdToClient.RES_EFFECIENCY_TAB_ACTIVE, msg)
  40. end
  41. -- 领取奖励
  42. function Efficiency.GetReward(actor, msgData)
  43. local rewardId = msgData.id
  44. local career_item_Count_Str = ConfigDataManager.getTableValue("cfg_efficiency_level", "item", "id", rewardId)
  45. if career_item_Count_Str == '' then
  46. return
  47. end
  48. local redDots = getplaydef(actor, "T$redDots") or {}
  49. local effciencyRedDots = redDots[redDotType.efficiency_level] or {}
  50. local has = table.contains(effciencyRedDots, rewardId)
  51. if has then
  52. return
  53. end
  54. local career_item_Counts = string.splitByAll(career_item_Count_Str, "|")
  55. for _, career_item_Count in ipairs(career_item_Counts) do
  56. local value = string.splitByAll(career_item_Count, "#")
  57. local career = tonumber(value[1])
  58. local myCreer = getbaseinfo(actor, "getbasecareer")
  59. if myCreer == career then
  60. local itemCfgId = tonumber(value[2])
  61. local itemCount = tonumber(value[3])
  62. additemtobag(actor, itemCfgId, itemCount,0,9999,'效率')
  63. sendluamsg(actor, LuaMessageIdToClient.RES_EFFECIENCY_REWARD_RESULT,
  64. { id = rewardId, itemId = itemCfgId, count = itemCount })
  65. break
  66. end
  67. end
  68. if msgData.type then
  69. -- 保存红点信息
  70. Efficiency.SaveReDot(actor, msgData)
  71. end
  72. end
  73. -- 校验红点
  74. function Efficiency.CheckRedDot(actor, level)
  75. level = level or getbaseinfo(actor, "level")
  76. local msg = {}
  77. msg[redDotType.efficiency] = {}
  78. msg[redDotType.efficiency_level] = {}
  79. local redDots = getplaydef(actor, "T$redDots") or {}
  80. local efficiencyConfigs = ConfigDataManager.getList("cfg_efficiency")
  81. local effciencyRedDots = redDots[redDotType.efficiency] or {}
  82. for _, cfg in ipairs(efficiencyConfigs) do
  83. local cfgLevel = tonumber(cfg.level)
  84. if cfgLevel <= level then
  85. local group = ConfigDataManager.getTableValue("cfg_efficiency", "group", "id", tonumber(cfg.id))
  86. local hasShowEffciency = array.contains(effciencyRedDots, tonumber(group))
  87. if not hasShowEffciency then
  88. if not table.contains(msg[redDotType.efficiency], tonumber(group)) then
  89. table.insert(msg[redDotType.efficiency], tonumber(group))
  90. end
  91. end
  92. end
  93. end
  94. local levelConfigs = ConfigDataManager.getList("cfg_efficiency_level")
  95. local effciencyLevelRedDots = redDots[redDotType.efficiency_level] or {}
  96. if table.isNullOrEmpty(effciencyLevelRedDots) then
  97. local minLevel = 9999999
  98. local targetId = 1
  99. for _, cfg in ipairs(levelConfigs) do
  100. local cfgLevel = tonumber(cfg.level)
  101. if cfgLevel <= level and minLevel > cfgLevel then
  102. minLevel = cfgLevel
  103. targetId = tonumber(cfg.id)
  104. end
  105. end
  106. msg[redDotType.efficiency_level]["currId"] = 0
  107. msg[redDotType.efficiency_level]["targetId"] = tonumber(targetId)
  108. else
  109. local maxLevel = 0
  110. local currId = 0
  111. local nextId
  112. for _, id in ipairs(effciencyLevelRedDots) do
  113. local cfg = ConfigDataManager.getById("cfg_efficiency_level", id)
  114. if cfg then
  115. local cfgLevel = tonumber(cfg.level)
  116. if maxLevel < cfgLevel then
  117. maxLevel = cfgLevel
  118. currId = id
  119. nextId = cfg.nextid
  120. end
  121. end
  122. end
  123. msg[redDotType.efficiency_level]["currId"] = tonumber(currId)
  124. if nextId ~= nil and nextId ~= '' then
  125. msg[redDotType.efficiency_level]["targetId"] = tonumber(nextId)
  126. else
  127. msg[redDotType.efficiency_level]["targetId"] = 0
  128. end
  129. end
  130. -- lg("红点:", msg)
  131. sendluamsg(actor, LuaMessageIdToClient.RES_EFFECIENCY_RED_DOT, msg)
  132. end
  133. function Efficiency.SaveReDot(actor, msgData)
  134. local type = msgData.type
  135. local redDots = getplaydef(actor, "T$redDots") or {}
  136. local redDot = redDots[type] or {}
  137. if type == redDotType.efficiency then
  138. -- 效率红点
  139. local group = msgData.group
  140. if not table.contains(redDot, group) then
  141. table.insert(redDot, group)
  142. end
  143. redDots[type] = redDot
  144. elseif type == redDotType.efficiency_level then
  145. -- 等级红点
  146. local id = msgData.id
  147. local currCfgLevel = ConfigDataManager.getTableValue("cfg_efficiency_level", "level", "id", id)
  148. local configs = ConfigDataManager.getList("cfg_efficiency_level")
  149. for _, cfg in ipairs(configs) do
  150. local cfgLevel = tonumber(cfg.level)
  151. if cfgLevel <= tonumber(currCfgLevel) and not table.contains(redDot, tonumber(cfg.id)) then
  152. table.insert(redDot, tonumber(cfg.id))
  153. end
  154. end
  155. redDots[type] = redDot
  156. end
  157. setplaydef(actor, "T$redDots", redDots)
  158. -- 重新发送红点信息
  159. Efficiency.CheckRedDot(actor)
  160. end
  161. function testactive1(actor)
  162. setplaydef(actor, "T$_PLAYER_MONTH_PRIVILEGE_DATA_KEY", {})
  163. end
  164. function clearactive1(actor)
  165. setplaydef(actor, "T$effcicency_active", {})
  166. end