Efficiency_1.lua 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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. Bag.addItemToBag(actor, itemCfgId, itemCount, 0, 9999, "效率")
  63. sendluamsg(
  64. actor,
  65. LuaMessageIdToClient.RES_EFFECIENCY_REWARD_RESULT,
  66. {id = rewardId, itemId = itemCfgId, count = itemCount}
  67. )
  68. break
  69. end
  70. end
  71. if msgData.type then
  72. -- 保存红点信息
  73. Efficiency.SaveReDot(actor, msgData)
  74. end
  75. end
  76. -- 校验红点
  77. function Efficiency.CheckRedDot(actor, level)
  78. level = level or getbaseinfo(actor, "level")
  79. local msg = {}
  80. msg[redDotType.efficiency] = {}
  81. msg[redDotType.efficiency_level] = {}
  82. local redDots = getplaydef(actor, "T$redDots") or {}
  83. local efficiencyConfigs = ConfigDataManager.getList("cfg_efficiency")
  84. local effciencyRedDots = redDots[redDotType.efficiency] or {}
  85. for _, cfg in ipairs(efficiencyConfigs) do
  86. local cfgLevel = tonumber(cfg.level)
  87. if cfgLevel <= level then
  88. local group = ConfigDataManager.getTableValue("cfg_efficiency", "group", "id", tonumber(cfg.id))
  89. local hasShowEffciency = array.contains(effciencyRedDots, tonumber(group))
  90. if not hasShowEffciency then
  91. if not table.contains(msg[redDotType.efficiency], tonumber(group)) then
  92. table.insert(msg[redDotType.efficiency], tonumber(group))
  93. end
  94. end
  95. end
  96. end
  97. local levelConfigs = ConfigDataManager.getList("cfg_efficiency_level")
  98. local effciencyLevelRedDots = redDots[redDotType.efficiency_level] or {}
  99. if table.isNullOrEmpty(effciencyLevelRedDots) then
  100. local minLevel = 9999999
  101. local targetId = 1
  102. for _, cfg in ipairs(levelConfigs) do
  103. local cfgLevel = tonumber(cfg.level)
  104. if cfgLevel <= level and minLevel > cfgLevel then
  105. minLevel = cfgLevel
  106. targetId = tonumber(cfg.id)
  107. end
  108. end
  109. msg[redDotType.efficiency_level]["currId"] = 0
  110. msg[redDotType.efficiency_level]["targetId"] = tonumber(targetId)
  111. else
  112. local maxLevel = 0
  113. local currId = 0
  114. local nextId
  115. for _, id in ipairs(effciencyLevelRedDots) do
  116. local cfg = ConfigDataManager.getById("cfg_efficiency_level", id)
  117. if cfg then
  118. local cfgLevel = tonumber(cfg.level)
  119. if maxLevel < cfgLevel then
  120. maxLevel = cfgLevel
  121. currId = id
  122. nextId = cfg.nextid
  123. end
  124. end
  125. end
  126. msg[redDotType.efficiency_level]["currId"] = tonumber(currId)
  127. if nextId ~= nil and nextId ~= "" then
  128. msg[redDotType.efficiency_level]["targetId"] = tonumber(nextId)
  129. else
  130. msg[redDotType.efficiency_level]["targetId"] = 0
  131. end
  132. end
  133. -- lg("红点:", msg)
  134. sendluamsg(actor, LuaMessageIdToClient.RES_EFFECIENCY_RED_DOT, msg)
  135. end
  136. function Efficiency.SaveReDot(actor, msgData)
  137. local type = msgData.type
  138. local redDots = getplaydef(actor, "T$redDots") or {}
  139. local redDot = redDots[type] or {}
  140. if type == redDotType.efficiency then
  141. -- 效率红点
  142. local group = msgData.group
  143. if not table.contains(redDot, group) then
  144. table.insert(redDot, group)
  145. end
  146. redDots[type] = redDot
  147. elseif type == redDotType.efficiency_level then
  148. -- 等级红点
  149. local id = msgData.id
  150. local currCfgLevel = ConfigDataManager.getTableValue("cfg_efficiency_level", "level", "id", id)
  151. local configs = ConfigDataManager.getList("cfg_efficiency_level")
  152. for _, cfg in ipairs(configs) do
  153. local cfgLevel = tonumber(cfg.level)
  154. if cfgLevel <= tonumber(currCfgLevel) and not table.contains(redDot, tonumber(cfg.id)) then
  155. table.insert(redDot, tonumber(cfg.id))
  156. end
  157. end
  158. redDots[type] = redDot
  159. end
  160. setplaydef(actor, "T$redDots", redDots)
  161. -- 重新发送红点信息
  162. Efficiency.CheckRedDot(actor)
  163. end
  164. function testactive1(actor)
  165. setplaydef(actor, "T$_PLAYER_MONTH_PRIVILEGE_DATA_KEY", {})
  166. end
  167. function clearactive1(actor)
  168. setplaydef(actor, "T$effcicency_active", {})
  169. end