AngelWeapon.lua 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. AngelWeapon ={}
  2. local this = {}
  3. AngelWeapon.var ={
  4. ANGEL_WEAPON_INFO = "T$angelweaponinfo",
  5. }
  6. AngelWeapon.TaskStatus = {
  7. CAN_RECEIVE = 1,--可领取
  8. UNFINISHED = 2,--未完成
  9. RECEIVED = 3 --已领取
  10. }
  11. AngelWeapon.TaskType = {
  12. MIN = 1,--小奖
  13. MAX = 2,--大奖
  14. }
  15. --活动是否开启
  16. function AngelWeapon.isActivityOpen(actor)
  17. local config = ConfigDataManager.getTable("sub_mainActivity","id",5)
  18. if config == nil then
  19. return false
  20. end
  21. return ConditionManager.Check(actor, config[1].actualcondition)
  22. end
  23. --页签是否开启
  24. function AngelWeapon.tableOpen(actor)
  25. local config = ConfigDataManager.getTable("sub_mainActivity","id",5)
  26. if config == nil then
  27. return false
  28. end
  29. return ConditionManager.Check(actor, config[1].showcondition)
  30. end
  31. function AngelWeapon.checkOpenTime(actor)
  32. local nowGroup = AngelWeapon.getGroup(actor)
  33. if nowGroup == 0 then
  34. --活动未开启,找最大的那个group
  35. local config = ConfigDataManager.getTable("cfg_activity_angelWeaponTime")
  36. local group = 0
  37. for i = 1, #config do
  38. if tonumber(config[i].taskgroup) > group then
  39. group = tonumber(config[i].taskgroup)
  40. end
  41. end
  42. local cfg = ConfigDataManager.getTable("cfg_activity_angelWeaponTime","taskGroup",group)
  43. if not cfg then
  44. return nil
  45. end
  46. local condition = cfg[1].condition
  47. local map = string.putIntIntMap({},condition,"#","&")
  48. local time = map[903]
  49. local serverOpenDays = getbaseinfo(actor, "serveropendays")
  50. if time + 1 == tonumber(serverOpenDays) then
  51. return group
  52. end
  53. return nil
  54. end
  55. local config = ConfigDataManager.getTable("cfg_activity_angelWeaponTime","taskGroup",nowGroup - 1)
  56. if config then
  57. local condition = config[1].condition
  58. local map = string.putIntIntMap({},condition,"#","&")
  59. local time = map[903]
  60. local serverOpenDays = getbaseinfo(actor, "serveropendays")
  61. if time + 1 == tonumber(serverOpenDays) then
  62. return nowGroup - 1
  63. end
  64. end
  65. return nil
  66. end
  67. function AngelWeapon.getGroup(actor)
  68. local config = ConfigDataManager.getTable("cfg_activity_angelWeaponTime")
  69. if not config then
  70. return 0
  71. end
  72. for _,cfg in pairs(config)do
  73. local condition = cfg.condition
  74. if ConditionManager.Check(actor, condition) then
  75. return tonumber(cfg.taskgroup)
  76. end
  77. end
  78. return 0
  79. end
  80. function AngelWeapon.login(actor)
  81. if not AngelWeapon.isActivityOpen(actor) then
  82. return
  83. end
  84. AngelWeapon.updateTaskInfo(actor)
  85. end
  86. --玩家穿戴|脱下装备时需要更新一次
  87. function AngelWeapon.updateTaskInfo(actor)
  88. if not AngelWeapon.isActivityOpen(actor) then
  89. return
  90. end
  91. local taskInfo = getplaydef(actor, AngelWeapon.var.ANGEL_WEAPON_INFO)
  92. if taskInfo == nil or taskInfo == "" then
  93. taskInfo = {}
  94. end
  95. local group = AngelWeapon.getGroup(actor)
  96. local career = getbaseinfo(actor,"getbasecareer")
  97. local equips = getputonequipinfo(actor)
  98. local map = {}
  99. for _,equip in pairs(equips) do
  100. local cfgId = tonumber(equip.cfgid)
  101. local num = map[cfgId] or 0
  102. map[cfgId] = num + 1
  103. end
  104. local config = ConfigDataManager.getTable("cfg_activity_angelWeapon","angelWeaponTaskGroup",group,"career",career)
  105. if not config then
  106. tipinfo(actor,"没有对应的活动数据!")
  107. return
  108. end
  109. local result = {}
  110. result.taskGroup = group
  111. result.taskList = {}
  112. local info = taskInfo[group]
  113. if info == nil or info == "" then
  114. info = {}
  115. info.taskList = {}
  116. end
  117. for _,cfg in pairs(config) do
  118. if tonumber(cfg.angelweapontype) ~= AngelWeapon.TaskType.MAX then
  119. local task = info.taskList[tostring(cfg.id)]
  120. if task == nil or task == "" then
  121. task = {}
  122. end
  123. local itemList = {}
  124. if table.count(task) == 0 or task.giftState ~= AngelWeapon.TaskStatus.RECEIVED then
  125. local str = string.toIntIntMap(cfg.angelweapontask,"#","|")
  126. local flag = true
  127. for k,v in pairs(str) do
  128. local num = map[k] or 0
  129. if num >= v then
  130. itemList[k] = v
  131. else
  132. itemList[k] = num
  133. flag = false
  134. end
  135. end
  136. task.id = tonumber(cfg.id)
  137. task.itemList = itemList
  138. task.giftState = flag and AngelWeapon.TaskStatus.CAN_RECEIVE or AngelWeapon.TaskStatus.UNFINISHED
  139. end
  140. result.taskList[tostring(cfg.id)] = task
  141. end
  142. end
  143. local config2 = ConfigDataManager.getTable("cfg_activity_angelWeapon","angelWeaponTaskGroup",group,"career",career,"angelWeaponType", AngelWeapon.TaskType.MAX)
  144. if config2 then
  145. local state = AngelWeapon.TaskStatus.CAN_RECEIVE
  146. if info.taskList then
  147. local task = info.taskList[tostring(config2[1].id)]
  148. if task and task.giftState == AngelWeapon.TaskStatus.RECEIVED then
  149. state = AngelWeapon.TaskStatus.RECEIVED
  150. else
  151. for _,v in pairs(result.taskList)do
  152. if v.giftState ~= AngelWeapon.TaskStatus.RECEIVED then
  153. state = AngelWeapon.TaskStatus.UNFINISHED
  154. break
  155. end
  156. end
  157. end
  158. else
  159. state = AngelWeapon.TaskStatus.UNFINISHED
  160. end
  161. local task = {}
  162. task.id = tonumber(config2[1].id)
  163. task.itemList = {}
  164. task.giftState = state
  165. result.taskList[tostring(config2[1].id)] = task
  166. end
  167. info.taskList = result.taskList
  168. taskInfo[group] = info
  169. setplaydef(actor, AngelWeapon.var.ANGEL_WEAPON_INFO,taskInfo)
  170. --通知客户端
  171. sendluamsg(actor,LuaMessageIdToClient.RES_ANGEL_WEAPON_TASK_CHANGE,result)
  172. end
  173. --请求领取任务奖励
  174. function AngelWeapon.receiveTaskReward(actor, msgData)
  175. if not AngelWeapon.isActivityOpen(actor) then
  176. tipinfo(actor,"活动未开启!")
  177. return
  178. end
  179. local taskId = msgData.taskId
  180. local group = AngelWeapon.getGroup(actor)
  181. local taskInfo = getplaydef(actor, AngelWeapon.var.ANGEL_WEAPON_INFO)
  182. if not taskInfo then
  183. tipinfo(actor,"任务不存在!")
  184. return
  185. end
  186. local info = taskInfo[group]
  187. if not info or not info.taskList then
  188. tipinfo(actor,"任务不存在!")
  189. return
  190. end
  191. local task = info.taskList[tostring(taskId)]
  192. if not task then
  193. tipinfo(actor,"任务不存在!")
  194. return
  195. end
  196. if task.giftState == AngelWeapon.TaskStatus.RECEIVED then
  197. tipinfo(actor,"请勿重复领取!")
  198. return
  199. end
  200. if task.giftState ~= AngelWeapon.TaskStatus.CAN_RECEIVE then
  201. tipinfo(actor,"任务未完成!")
  202. return
  203. end
  204. --发奖励
  205. local config = ConfigDataManager.getTable("cfg_activity_angelWeapon","id",task.id)
  206. local reward = string.toIntIntMap(config[1].angelweaponreward,"#","|")
  207. for k,v in pairs(reward) do
  208. additemtobag(actor, k, v,0,9999,'大天使武器')
  209. end
  210. --奖励弹框
  211. sendluamsg(actor, LuaMessageIdToClient.COMMON_REWARD_PANEL, reward)
  212. --修改状态
  213. task.giftState = AngelWeapon.TaskStatus.RECEIVED
  214. info.taskList[tostring(taskId)] = task
  215. taskInfo[group] = info
  216. setplaydef(actor, AngelWeapon.var.ANGEL_WEAPON_INFO,taskInfo)
  217. --通知客户端
  218. AngelWeapon.updateTaskInfo(actor)
  219. end
  220. --活动结束时邮件发放奖励
  221. function AngelWeapon.sendReward()
  222. local allRoleInfos = getallrolesummaryinfos()
  223. if allRoleInfos == nil or next(allRoleInfos) == nil then
  224. return
  225. end
  226. for _, roleInfo in pairs(allRoleInfos) do
  227. local reward = {}
  228. local actor = roleInfo["actor"]
  229. local group = AngelWeapon.checkOpenTime (actor)
  230. if not group then
  231. return
  232. end
  233. local taskInfo = getplaydef(actor, AngelWeapon.var.ANGEL_WEAPON_INFO)
  234. if not (taskInfo == nil or taskInfo == "") then
  235. local info = taskInfo[group] or {}
  236. if table.count(info) > 0 and info.taskList ~= nil then
  237. for _,task in pairs(info.taskList) do
  238. if task.giftState == AngelWeapon.TaskStatus.CAN_RECEIVE then
  239. local config = ConfigDataManager.getTable("cfg_activity_angelWeapon","id",task.id)
  240. string.putIntIntMap(reward,config[1].angelweaponreward,"#","|")
  241. end
  242. end
  243. end
  244. taskInfo[group] = nil
  245. if table.count(reward) > 0 then
  246. sendconfigmailbyrid(actor,getbaseinfo(actor,"rid"), MailConfig.END_TIME_ANGEL_WEAPON_REWARD, reward, "")
  247. end
  248. setplaydef(actor, AngelWeapon.var.ANGEL_WEAPON_INFO,taskInfo)
  249. end
  250. end
  251. end