AngelWeapon.lua 9.2 KB

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