LevelReward.lua 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. LevelReward ={}
  2. local this = {}
  3. LevelReward.var ={
  4. HAD_RECEIVE_REWARD = "T$hadreceivereward",
  5. SERVER_LIMIT_LEVEL_REWARD = "R$serverlimitlevelreward"
  6. }
  7. --活动是否开启
  8. function LevelReward.isActivityOpen(actor)
  9. local config = ConfigDataManager.getTable("sub_mainActivity","id",7)
  10. if config == nil then
  11. return false
  12. end
  13. return ConditionManager.Check(actor, config[1].actualcondition)
  14. end
  15. --是否页签关闭后的第一天
  16. function LevelReward.tableOpen(actor)
  17. local config = ConfigDataManager.getTable("sub_mainActivity","id",7)
  18. if config == nil then
  19. return nil
  20. end
  21. if config then
  22. local condition = config[1].showcondition
  23. local map = string.putIntIntMap({},condition,"#","&")
  24. local time = map[903]
  25. local serverOpenDays = getbaseinfo(actor, "serveropendays")
  26. if time + 1 == tonumber(serverOpenDays) then
  27. return true
  28. end
  29. end
  30. return nil
  31. end
  32. function LevelReward.login(actor)
  33. LevelReward.getLevelRewardInfo(actor)
  34. end
  35. ---请求当前已领取信息
  36. function LevelReward.getLevelRewardInfo(actor)
  37. if not LevelReward.isActivityOpen(actor) then
  38. return
  39. end
  40. local result = {}
  41. local rewardInfo = getplaydef(actor,LevelReward.var.HAD_RECEIVE_REWARD) or {}
  42. result.personInfo = rewardInfo
  43. local serverInfo = getsysvar(LevelReward.var.SERVER_LIMIT_LEVEL_REWARD)
  44. if not serverInfo then
  45. setsysvar(LevelReward.var.SERVER_LIMIT_LEVEL_REWARD,{})
  46. serverInfo = getsysvar(LevelReward.var.SERVER_LIMIT_LEVEL_REWARD)
  47. end
  48. result.serverInfo = serverInfo
  49. sendluamsg(actor,LuaMessageIdToClient.RES_PERSONAL_LEVEL_REWARD_INFO,table.valueConvertToString(result))
  50. end
  51. --请求领取等级奖励
  52. function LevelReward.receiveLevelReward(actor,msgData)
  53. local id = msgData.id
  54. local config = ConfigDataManager.getTable("cfg_activity_levelUp","id",id)
  55. if config == nil then
  56. return
  57. end
  58. local level = getbaseinfo(actor,"level")
  59. local cfgLv = config[1].level
  60. if tonumber(level) < tonumber(cfgLv) then
  61. tipinfo(actor,"等级不足!")
  62. return
  63. end
  64. local reward = {}
  65. local rewardInfo = getplaydef(actor,LevelReward.var.HAD_RECEIVE_REWARD) or {}
  66. local result = rewardInfo[tostring(id)] or {}
  67. if not result.basicItem then
  68. --增加限量判定
  69. local limitNum= config[1].places
  70. if not (limitNum == nil or limitNum == "" or limitNum == "0") then
  71. local nowInfo = getsysvar(LevelReward.var.SERVER_LIMIT_LEVEL_REWARD) or {}
  72. local nowNum = nowInfo[tostring(id)] or 0
  73. if nowNum >= tonumber(limitNum) then
  74. tipinfo(actor,"已达到领取上限!")
  75. return
  76. else
  77. nowNum = nowNum + 1
  78. nowInfo[tostring(id)] = nowNum
  79. setsysvar(LevelReward.var.SERVER_LIMIT_LEVEL_REWARD,nowInfo)
  80. end
  81. end
  82. string.putIntIntMap(reward,config[1].basicitem,"#","|")
  83. result.basicItem = true
  84. end
  85. if not result.specialItem then
  86. local condition = config[1].conditions
  87. if ConditionManager.Check(actor,condition) then
  88. string.putIntIntMap(reward,config[1].specialitem,"#","|")
  89. result.specialItem = true
  90. else
  91. result.specialItem = false
  92. end
  93. end
  94. --发奖励
  95. if table.count(reward) == 0 then
  96. return
  97. end
  98. for itemCfgId, count in pairs(reward) do
  99. additemtobag(actor, itemCfgId, count,0,9999,'等级奖励')
  100. end
  101. --奖励弹框
  102. sendluamsg(actor, LuaMessageIdToClient.COMMON_REWARD_PANEL, reward)
  103. rewardInfo[tostring(id)] = result
  104. setplaydef(actor,LevelReward.var.HAD_RECEIVE_REWARD,rewardInfo)
  105. --通知客户端
  106. sendluamsg(actor,LuaMessageIdToClient.RES_RECEIVE_LEVEL_REWARD,table.valueConvertToString(rewardInfo))
  107. LevelReward.getLevelRewardInfo(actor)
  108. end
  109. --活动结束时发放所有奖励
  110. function LevelReward.sendAllReward()
  111. local nowInfo = getsysvar(LevelReward.var.SERVER_LIMIT_LEVEL_REWARD)
  112. if nowInfo == nil or nowInfo == "" then
  113. return
  114. end
  115. local allRoleInfos = getallrolesummaryinfos()
  116. if allRoleInfos == nil or next(allRoleInfos) == nil then
  117. return
  118. end
  119. local tab = ConfigDataManager.getTable("cfg_activity_levelUp")
  120. for _, roleInfo in pairs(allRoleInfos) do
  121. local reward = {}
  122. local actor = roleInfo["actor"]
  123. if not LevelReward.tableOpen(actor) then
  124. return
  125. end
  126. local hadReward = getplaydef(actor, LevelReward.var.HAD_RECEIVE_REWARD) or {}
  127. if hadReward.lastReward then
  128. return
  129. end
  130. for i = 1,#tab,1 do
  131. local config = tab[i]
  132. local level = getbaseinfo(actor,"level")
  133. local id = config.id
  134. local cfgReward = hadReward[tostring(id)] or {}
  135. if table.count(cfgReward) > 0 then
  136. if cfgReward.specialItem == false and ConditionManager.Check(actor,config.conditions) then
  137. string.putIntIntMap(reward, config.specialitem)
  138. cfgReward.specialItem = true
  139. end
  140. hadReward[tostring(id)] = cfgReward
  141. else
  142. local cfgLv = config.level
  143. if tonumber(level) >= tonumber(cfgLv) then
  144. --判断限定数量
  145. local limitNum= config.places
  146. if not (limitNum == nil or limitNum == "" or limitNum == "0") then
  147. local nowNum = nowInfo[tostring(config.id)] or 0
  148. if nowNum < tonumber(limitNum) then
  149. nowNum = nowNum + 1
  150. nowInfo[tostring(config.id)] = nowNum
  151. setsysvar(LevelReward.var.SERVER_LIMIT_LEVEL_REWARD,nowInfo)
  152. string.putIntIntMap(reward, config.basicitem)
  153. cfgReward.basicItem = true
  154. if ConditionManager.Check(actor,config.conditions) then
  155. string.putIntIntMap(reward, config.specialitem)
  156. cfgReward.specialitem = true
  157. end
  158. end
  159. else
  160. string.putIntIntMap(reward, config.basicitem)
  161. cfgReward.basicItem = true
  162. if ConditionManager.Check(actor,config.conditions) then
  163. string.putIntIntMap(reward, config.specialitem)
  164. cfgReward.specialitem = true
  165. end
  166. end
  167. end
  168. end
  169. end
  170. --发邮件
  171. if table.count(reward) > 0 then
  172. sendconfigmailbyrid(actor,getbaseinfo(actor,"rid"), MailConfig.END_TIME_LEVEL_REWARD, reward, "")
  173. end
  174. hadReward.lastReward = true
  175. setplaydef(actor, LevelReward.var.HAD_RECEIVE_REWARD,hadReward)
  176. end
  177. setsysvar(LevelReward.var.SERVER_LIMIT_LEVEL_REWARD,nil)
  178. jprint("补发等级奖励邮件结束")
  179. end