AngelBenefit.lua 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  1. AngelBenefit = {}
  2. local this = {}
  3. AngelBenefit.Var = {
  4. ANGLE_TASK = "T$angletaskinfo",
  5. ANGLE_REWARD = "T$angletaskreward",
  6. ALL_SERVER_LIMIT_BUY = "R$allserverlimitbuy" --全服限量购买
  7. }
  8. ---任务状态
  9. AngelBenefit.TASK_STATUS = {
  10. ---已接取
  11. ACCEPT = 1,
  12. ---已完成
  13. FINISH = 2,
  14. ---已提交
  15. SUBMIT = 3
  16. }
  17. ---任务状态
  18. AngelBenefit.TASK_TYPE = {
  19. --试炼达人
  20. BRAVE = 1,
  21. --怪物猎人
  22. MONSTER = 2
  23. }
  24. --活动是否开启
  25. function AngelBenefit.isActivityOpen(actor)
  26. local config = ConfigDataManager.getTable("sub_mainActivity", "id", 2)
  27. if config == nil then
  28. return false
  29. end
  30. return ConditionManager.Check(actor, config[1].actualcondition)
  31. end
  32. --页签是否开启
  33. function AngelBenefit.tableOpen(actor)
  34. local config = ConfigDataManager.getTable("sub_mainActivity", "id", 2)
  35. if config == nil then
  36. return false
  37. end
  38. return ConditionManager.Check(actor, config[1].showcondition)
  39. end
  40. ---获取全服奖励信息和个人任务信息
  41. function AngelBenefit.getAllAngleBenefitInfo(actor)
  42. local result = {}
  43. --个人任务
  44. local taskInfo = getplaydef(actor, AngelBenefit.Var.ANGLE_TASK)
  45. if taskInfo == nil or taskInfo == "" then
  46. taskInfo = {}
  47. end
  48. local taskResult = {}
  49. for k, v in pairs(taskInfo) do
  50. local info = {}
  51. info.nowCount = v.nowCount
  52. info.status = v.status
  53. taskResult[v.taskId] = info
  54. end
  55. result.taskInfo = taskResult
  56. --个人奖励
  57. local rewardInfo = getplaydef(actor, AngelBenefit.Var.ANGLE_REWARD)
  58. if rewardInfo == nil or rewardInfo == "" then
  59. rewardInfo = {}
  60. end
  61. local info = {}
  62. for _, v in pairs(rewardInfo) do
  63. info[v] = 1
  64. end
  65. result.awards = info
  66. --全服限量购买
  67. local serverData = getsysvar(actor, AngelBenefit.Var.ALL_SERVER_LIMIT_BUY)
  68. if serverData == nil or serverData == "" then
  69. serverData = {}
  70. end
  71. local serverDataResult = {}
  72. for k, v in pairs(serverData) do
  73. serverDataResult[k] = table.count(v)
  74. end
  75. result.serverReward = serverDataResult
  76. --通知客户端
  77. sendluamsg(actor, LuaMessageIdToClient.RES_ANGLE_BENEFIT_INFO, table.valueConvertToString(result))
  78. end
  79. function AngelBenefit.login(actor)
  80. AngelBenefit.AcceptTask(actor)
  81. end
  82. ---接取任务
  83. function AngelBenefit.AcceptTask(actor)
  84. --活动是否开启
  85. if not AngelBenefit.isActivityOpen(actor) then
  86. return
  87. end
  88. local taskInfo = getplaydef(actor, AngelBenefit.Var.ANGLE_TASK)
  89. if taskInfo ~= nil then
  90. return
  91. end
  92. taskInfo = {}
  93. local config = ConfigDataManager.getTable("cfg_angleBenefitTask", "taskRank", 1)
  94. if not config then
  95. return
  96. end
  97. --接取任务
  98. for i = 1, #config, 1 do
  99. local cfg = config[i]
  100. local targetId = cfg.tasktargetid
  101. local type = cfg.type
  102. local targetCfg = ConfigDataManager.getTable("cfg_task_target", "id", targetId)
  103. local task = {}
  104. task.taskGoalId = targetCfg[1].taskgoalparam
  105. task.goalCount = targetCfg[1].goalcount
  106. task.nowCount = 0
  107. task.status = AngelBenefit.TASK_STATUS.ACCEPT
  108. task.taskRank = cfg.taskrank
  109. task.taskId = cfg.id
  110. taskInfo[type] = task
  111. end
  112. setplaydef(actor, AngelBenefit.Var.ANGLE_TASK, taskInfo)
  113. --通知客户端
  114. local result = {}
  115. for _, v in pairs(taskInfo) do
  116. local info = {}
  117. info.nowCount = v.nowCount
  118. info.status = v.status
  119. result[v.taskId] = info
  120. end
  121. sendluamsg(actor, LuaMessageIdToClient.RES_ANGLE_BENEFIT_TASK_CHANGE, table.valueConvertToString(result))
  122. end
  123. function AngelBenefit.UpdateTaskProgress(actor, type, param)
  124. local success, errorInfo = xpcall(this.UpdateTaskProgress, debug.traceback, actor, type, param)
  125. gameDebug.assertPrint(success, "大天使福利任务更新异常:", actor, type, param, errorInfo)
  126. end
  127. ---更新任务进度
  128. function this.UpdateTaskProgress(actor, type, param)
  129. if actor == nil then
  130. return
  131. end
  132. --活动是否开启
  133. if not AngelBenefit.isActivityOpen(actor) then
  134. return
  135. end
  136. local taskInfo = getplaydef(actor, AngelBenefit.Var.ANGLE_TASK)
  137. if not taskInfo then
  138. return
  139. end
  140. local task = taskInfo[tostring(type)]
  141. if not task then
  142. return
  143. end
  144. if task.status == AngelBenefit.TASK_STATUS.SUBMIT then
  145. return
  146. end
  147. --根据类型进行任务进度更新
  148. if tonumber(type) == AngelBenefit.TASK_TYPE.MONSTER then
  149. local monsterId = param
  150. if tonumber(task.taskGoalId) ~= tonumber(monsterId) then
  151. return
  152. else
  153. task.nowCount = tonumber(task.nowCount) + 1
  154. end
  155. end
  156. if tonumber(type) == AngelBenefit.TASK_TYPE.BRAVE then
  157. local floor = param
  158. --层数
  159. local oldF = task.nowCount
  160. if tonumber(oldF) < tonumber(floor) then
  161. task.nowCount = tonumber(floor)
  162. end
  163. end
  164. --更新任务状态
  165. if task.nowCount >= tonumber(task.goalCount) then
  166. task.status = AngelBenefit.TASK_STATUS.FINISH
  167. end
  168. taskInfo[tostring(type)] = task
  169. setplaydef(actor, AngelBenefit.Var.ANGLE_TASK, taskInfo)
  170. --通知客户端
  171. local result = {}
  172. for _, v in pairs(taskInfo) do
  173. local info = {}
  174. info.nowCount = v.nowCount
  175. info.status = v.status
  176. result[v.taskId] = info
  177. end
  178. sendluamsg(actor, LuaMessageIdToClient.RES_ANGLE_BENEFIT_TASK_CHANGE, table.valueConvertToString(result))
  179. end
  180. ---提交任务
  181. function AngelBenefit.submitTask(actor, msgData)
  182. local type = msgData.type
  183. local taskInfo = getplaydef(actor, AngelBenefit.Var.ANGLE_TASK)
  184. if not taskInfo then
  185. tipinfo(actor, "任务未接取")
  186. return
  187. end
  188. local task = taskInfo[tostring(type)]
  189. if not task then
  190. tipinfo(actor, "任务不存在")
  191. return
  192. end
  193. if task.status == AngelBenefit.TASK_STATUS.SUBMIT then
  194. tipinfo(actor, "任务不可重复提交")
  195. return
  196. end
  197. if task.status ~= AngelBenefit.TASK_STATUS.FINISH then
  198. tipinfo(actor, "任务未完成")
  199. return
  200. end
  201. --修改任务状态
  202. task.status = AngelBenefit.TASK_STATUS.SUBMIT
  203. taskInfo[tostring(type)] = task
  204. setplaydef(actor, AngelBenefit.Var.ANGLE_TASK, taskInfo)
  205. --发奖励
  206. local reward = AngelBenefit.GetTaskReward(type, task.taskRank)
  207. for itemCfgId, count in pairs(reward) do
  208. Bag.addItemToBag(actor, itemCfgId, count, 0, 9999, "大天使福利")
  209. end
  210. --接取下一个任务
  211. local taskCfg =
  212. ConfigDataManager.getTable("cfg_angleBenefitTask", "taskRank", tonumber(task.taskRank) + 1, "type", type)
  213. if taskCfg then
  214. local targetId = taskCfg[1].tasktargetid
  215. local targetCfg = ConfigDataManager.getTable("cfg_task_target", "id", targetId)
  216. local newTask = {}
  217. newTask.taskGoalId = targetCfg[1].taskgoalparam
  218. newTask.goalCount = targetCfg[1].goalcount
  219. if tonumber(type) == AngelBenefit.TASK_TYPE.BRAVE then
  220. newTask.nowCount = task.nowCount
  221. newTask.status =
  222. tonumber(newTask.nowCount) >= tonumber(newTask.goalCount) and AngelBenefit.TASK_STATUS.FINISH or
  223. AngelBenefit.TASK_STATUS.ACCEPT
  224. else
  225. newTask.status = AngelBenefit.TASK_STATUS.ACCEPT
  226. newTask.nowCount = 0
  227. end
  228. newTask.taskRank = taskCfg[1].taskrank
  229. newTask.taskId = taskCfg[1].id
  230. taskInfo[tostring(type)] = newTask
  231. setplaydef(actor, AngelBenefit.Var.ANGLE_TASK, taskInfo)
  232. end
  233. --通知客户端
  234. local resultInfo = getplaydef(actor, AngelBenefit.Var.ANGLE_TASK)
  235. local result = {}
  236. local taskResult = resultInfo[tostring(type)]
  237. local info = {}
  238. info.nowCount = taskResult.nowCount
  239. info.status = taskResult.status
  240. result[tostring(taskResult.taskId)] = info
  241. sendluamsg(actor, LuaMessageIdToClient.RES_SUBMIT_ANGLE_BENEFIT_TASK, table.valueConvertToString(result))
  242. end
  243. ---获取任务奖励
  244. function AngelBenefit.GetTaskReward(type, order)
  245. local config = ConfigDataManager.getTable("cfg_angleBenefitTask", "type", type, "taskRank", order)
  246. if not config then
  247. return {}
  248. end
  249. return string.putIntIntMap({}, config[1].rewarditem, "#", "|")
  250. end
  251. ---领取或购买积分奖励
  252. function AngelBenefit.receiveScoreReward(actor, msgData)
  253. --活动是否开启
  254. if not AngelBenefit.isActivityOpen(actor) then
  255. tipinfo(actor, "活动未开启!")
  256. return
  257. end
  258. local order = msgData.order
  259. local config = ConfigDataManager.getTable("cfg_angleBenefitReward", "id", order)
  260. if not config then
  261. tipinfo(actor, "奖励不存在!")
  262. return
  263. end
  264. local rewardInfo = getplaydef(actor, AngelBenefit.Var.ANGLE_REWARD) or {}
  265. if table.contains(rewardInfo, tostring(config[1].id)) then
  266. tipinfo(actor, "请勿重复领取!")
  267. return
  268. end
  269. local cost = string.putIntIntMap({}, config[1].rewardpoint, "#", "|")
  270. for k, v in pairs(cost) do
  271. if not Bag.checkItem(actor, k, v) then
  272. tipinfo(actor, "积分不足")
  273. return
  274. end
  275. end
  276. local hasCost = false
  277. --判断开服天数
  278. local serverOpenDays = getbaseinfo(actor, "serveropendays")
  279. if tonumber(serverOpenDays) > tonumber(config[1].limittime) then
  280. local payConsume = splitbyshuxianandjinghao2(config[1].payconsume)
  281. for k, v in pairs(payConsume) do
  282. if not Bag.checkItem(actor, k, v) then
  283. tipinfo(actor, "材料不足,购买失败")
  284. return
  285. end
  286. end
  287. --扣材料
  288. for k, v in pairs(payConsume) do
  289. removeitemfrombag(actor, k, v, 0, 9999, "大天使福利")
  290. end
  291. hasCost = true
  292. end
  293. --判断全服限购次数
  294. callonserial(actor, "all_server_reward_limit", config, hasCost)
  295. end
  296. function all_server_reward_limit(actor, config, hasCost)
  297. --判断全服限购次数
  298. local serverBuyInfo = getsysvar(actor, AngelBenefit.Var.ALL_SERVER_LIMIT_BUY)
  299. if serverBuyInfo == nil or serverBuyInfo == "" then
  300. serverBuyInfo = {}
  301. end
  302. local receiveList = serverBuyInfo[config[1].id] or {}
  303. if table.count(receiveList) >= tonumber(config[1].limitnum) and (not hasCost) then
  304. --花钱购买
  305. local payConsume = string.putIntIntMap({}, config[1].payconsume, "#", "|")
  306. for k, v in pairs(payConsume) do
  307. if not Bag.checkItem(actor, k, v) then
  308. tipinfo(actor, "材料不足,购买失败")
  309. return
  310. end
  311. end
  312. --扣材料
  313. for k, v in pairs(payConsume) do
  314. removeitemfrombag(actor, k, v, 0, 9999, "大天使福利")
  315. end
  316. else
  317. local playerBuyInfo = {}
  318. playerBuyInfo.receiveTime = getbaseinfo("now")
  319. playerBuyInfo.rid = getbaseinfo(actor, "rid")
  320. table.insert(receiveList, playerBuyInfo)
  321. serverBuyInfo[config[1].id] = receiveList
  322. setsysvar(AngelBenefit.Var.ALL_SERVER_LIMIT_BUY, serverBuyInfo)
  323. end
  324. --发奖励
  325. local career = getbaseinfo(actor, "getbasecareer")
  326. local reward = string.toIntIntMap4Career(career, config[1].reward, "#", "|")
  327. --local reward = string.putIntIntMap({},config[1].reward,"#","|")
  328. for itemCfgId, count in pairs(reward) do
  329. Bag.addItemToBag(actor, itemCfgId, count, 0, 9999, "大天使福利")
  330. end
  331. --奖励弹框
  332. sendluamsg(actor, LuaMessageIdToClient.COMMON_REWARD_PANEL, reward)
  333. --记录已经领取的奖励
  334. table.insert(rewardInfo, config[1].id)
  335. setplaydef(actor, AngelBenefit.Var.ANGLE_REWARD, rewardInfo)
  336. --通知客户端
  337. local result = {}
  338. for _, index in pairs(rewardInfo) do
  339. result[index] = 1
  340. end
  341. sendluamsg(actor, LuaMessageIdToClient.RES_RECEIVE_ANGLE_BENEFIT_REWARD, table.valueConvertToString(result))
  342. end
  343. --页签关闭时邮件发送未领取奖励
  344. function AngelBenefit.OnCloseMail()
  345. local allRoleInfos = getallrolesummaryinfos()
  346. if allRoleInfos == nil or next(allRoleInfos) == nil then
  347. return
  348. end
  349. for _, roleInfo in pairs(allRoleInfos) do
  350. local reward = {}
  351. local actor = roleInfo["actor"]
  352. if AngelBenefit.tableOpen(actor) then
  353. return
  354. end
  355. local taskInfo = getplaydef(actor, AngelBenefit.Var.ANGLE_TASK)
  356. if taskInfo == nil or taskInfo == "" then
  357. taskInfo = {}
  358. end
  359. for k, v in pairs(taskInfo) do
  360. if v.status == AngelBenefit.TASK_STATUS.FINISH then
  361. local config = ConfigDataManager.getTable("cfg_angleBenefitTask", "type", k, "taskRank", v.taskRank)
  362. string.putIntIntMap(reward, config[1].rewarditem)
  363. end
  364. end
  365. setplaydef(actor, AngelBenefit.Var.ANGLE_TASK, nil)
  366. --发邮件
  367. if table.count(reward) > 0 then
  368. sendconfigmailbyrid(actor, getbaseinfo(actor, "rid"), MailConfig.END_TIME_ANGLE_REWARD, reward, "")
  369. end
  370. end
  371. setsysvar(AngelBenefit.Var.ALL_SERVER_LIMIT_BUY, nil)
  372. end