WeekTaskLogic.lua 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  1. local Lang = require("common.Lang")
  2. local Util = require("common.Util")
  3. local Msg = require("core.Msg")
  4. local ObjHuman = require("core.ObjHuman")
  5. local WeekTaskExcel = require("excel.weekTask")
  6. local BagLogic = require("bag.BagLogic")
  7. local Grid = require("bag.Grid")
  8. local ChatPaoMaLogic = require("chat.ChatPaoMaLogic")
  9. local RoleSystemLogic = require("roleSystem.RoleSystemLogic")
  10. local RoleSystemDefine = require("roleSystem.RoleSystemDefine")
  11. local ItemDefine = require("bag.ItemDefine")
  12. local ChengjiuLogic = require("chengjiu.ChengjiuLogic")
  13. local ChengjiuDefine = require("chengjiu.ChengjiuDefine")
  14. local YunYingLogic = require("yunying.YunYingLogic")
  15. local WeekTaskExcel = require("excel.weekTask")
  16. -- weekTask = {
  17. -- task ={ id = isGet,finiscnt,state}
  18. --huoyueBox = {}
  19. --nowHuoyue
  20. -- }
  21. WEEK_TASK_ID_1 = 1 --寻星10次 o
  22. WEEK_TASK_ID_2 = 2 --高级召唤50次 o
  23. WEEK_TASK_ID_3 = 3 --天命召唤7次 o
  24. WEEK_TASK_ID_4 = 4 --公会BOSS挑战50次 x
  25. WEEK_TASK_ID_5 = 5 --宝箱开启35次 o
  26. WEEK_TASK_ID_6 = 6 --扫荡28次 o
  27. WEEK_TASK_ID_7 = 7 --任意商定购买50次 o
  28. WEEK_TASK_ID_8 = 8 --勇者试炼战胜30次 x
  29. WEEK_TASK_ID_9 = 9 --冰龙巢穴挑战7次 o
  30. WEEK_TASK_ID_10 = 10 --魔王珠玑跳转7次 o
  31. function WeekTaskQuery(human, isOnLogin)
  32. -- print("当前进入周任务查询")
  33. local sendErr = isOnLogin == false and true or false
  34. if RoleSystemLogic.isOpen(human, RoleSystemDefine.ROLE_SYS_ID_802, sendErr) ~= true then
  35. return
  36. end
  37. local weekTaskConfig = WeekTaskExcel.weekTask
  38. if not weekTaskConfig then return end
  39. -- 每周更新一次
  40. -- ObjHuman.updateWeek(human)
  41. local msgRet = Msg.gc.GC_WEEKTASK_QUERY
  42. --下次刷新时间?
  43. local now = os.time()
  44. local ts1 = Util.getDayStartTime(now)
  45. msgRet.nextRefreshTime = 24 * 60 * 60 - (now - ts1)
  46. local cnt = 0
  47. for key, value in ipairs(WeekTaskExcel.weekTask) do
  48. cnt = cnt + 1
  49. msgRet.list[cnt].taskID = key
  50. msgRet.list[cnt].desc = value.taskDesc
  51. msgRet.list[cnt].maxCnt = value.taskProgress
  52. local len = 0
  53. for i = 1, #value.reward do
  54. len = len + 1
  55. local itemId = value.reward[i][1]
  56. local itemCnt = value.reward[i][2]
  57. Grid.makeItem(msgRet.list[cnt].itemData[len], itemId, itemCnt)
  58. end
  59. msgRet.list[cnt].itemData[0] = len
  60. msgRet.list[cnt].finishCnt = 0
  61. msgRet.list[cnt].isGet = 0
  62. msgRet.list[cnt].jump = value.panelID
  63. if human.db.weekTask and human.db.weekTask.task and human.db.weekTask.task[key] then
  64. msgRet.list[cnt].finishCnt = human.db.weekTask.task[key].finishCnt or 0
  65. if human.db.weekTask.task[key].isGet then
  66. msgRet.list[cnt].isGet = 1
  67. end
  68. end
  69. end
  70. local huoYueBoxConfig = WeekTaskExcel.huoYueBox
  71. msgRet.huoYueBox[0] = #huoYueBoxConfig
  72. for i=1,#WeekTaskExcel.huoYueBox do
  73. msgRet.huoYueBox[i].boxID = i
  74. msgRet.huoYueBox[i].needHuoYue = huoYueBoxConfig[i].needHuoYue
  75. msgRet.huoYueBox[i].items[0] = #huoYueBoxConfig[i].reward
  76. for j=1,#huoYueBoxConfig[i].reward do
  77. local itemID = huoYueBoxConfig[i].reward[j][1]
  78. local itemCnt = huoYueBoxConfig[i].reward[j][2]
  79. Grid.makeItem(msgRet.huoYueBox[i].items[j],itemID,itemCnt)
  80. end
  81. local isGet = human.db.weekTask and human.db.weekTask.huoYueBox and human.db.weekTask.huoYueBox[i] or 0
  82. msgRet.huoYueBox[i].isGet = isGet
  83. end
  84. msgRet.nowHuoYue = human.db.weekTask and human.db.weekTask.nowHuoYue or 0
  85. msgRet.list[0] = cnt
  86. -- table.print_lua_table(msgRet)
  87. print("周任务查询成功!")
  88. Msg.send(msgRet, human.fd)
  89. end
  90. --统计奖励
  91. local function calcReward(human, awardCfg)
  92. for i = 1, #awardCfg do
  93. local itemId = awardCfg[i][1]
  94. local itemCnt = awardCfg[i][2]
  95. if itemId == ItemDefine.ITEM_WEEKTASK_ID then
  96. onWeekTaskHuoYue(human,itemCnt)
  97. else
  98. local newCnt = math.ceil(itemCnt)
  99. --BagLogic.updateMomentItem(2, itemId, itemCnt)
  100. BagLogic.updateMomentItem(2, itemId, newCnt)
  101. end
  102. end
  103. end
  104. -- 领取每周任务奖励
  105. function weekTaskGetReward(human, taskID)
  106. print("当前进入领取每周奖励")
  107. if RoleSystemLogic.isOpen(human, RoleSystemDefine.ROLE_SYS_ID_802) ~= true then
  108. return
  109. end
  110. print("当前进入领取每周奖励1111111111111111111111111111")
  111. -- ObjHuman.updateWeek(human)
  112. ------------------------------------新改为: 一键领取所有能领取的奖励---------------------------------------------
  113. if human.db.weekTask == nil or human.db.weekTask.task == nil then
  114. print("[weekTaskGetReward]..当前没有每周任务,返回了")
  115. table.print_lua_table(human.db.weekTask)
  116. return
  117. end
  118. print("当前进入领取每周奖励22222222222222222")
  119. local isClean = false
  120. local taskData = human.db.weekTask.task
  121. print("当前进入领取每周奖励3333333333333333333333333")
  122. for taskId, data in pairs(taskData) do
  123. if not data.isGet then
  124. local weekTaskConfig = WeekTaskExcel and WeekTaskExcel.weekTask and WeekTaskExcel.weekTask[taskId]
  125. if data.finishCnt and data.finishCnt >= weekTaskConfig.taskProgress then
  126. if not isClean then
  127. BagLogic.cleanMomentItemList()
  128. isClean = true
  129. end
  130. calcReward(human, weekTaskConfig.reward)
  131. -- onWeekTaskHuoYue(human,10)
  132. data.isGet = true
  133. end
  134. end
  135. end
  136. print("当前进入领取每周奖励44444444444444444444444")
  137. if isClean then
  138. BagLogic.addMomentItemList(human, "week_task")
  139. WeekTaskQuery(human)
  140. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_802)
  141. end
  142. print("每周奖励领取完毕")
  143. end
  144. -- 记录每个任务的完成次数
  145. function recordWeekTaskFinishCnt(human, taskID, addCnt, noSend)
  146. -- ObjHuman.updateWeek(human)
  147. human.db.weekTask = human.db.weekTask or {}
  148. human.db.weekTask.task = human.db.weekTask.task or {}
  149. human.db.weekTask.task[taskID] = human.db.weekTask.task[taskID] or {}
  150. if human.db.weekTask.task[taskID].state ~= nil then
  151. print("[WeekTaskLogic-recordWeekTaskFinishCnt].1111111111111111111111111111111111111在这里返回了")
  152. return
  153. end
  154. human.db.weekTask.task[taskID].finishCnt = (human.db.weekTask.task[taskID].finishCnt or 0) + addCnt
  155. print("[WeekTaskLogic-recordWeekTaskFinishCnt].2222222222222222222222222222222222222",addCnt)
  156. local weekTaskConfig = WeekTaskExcel.weekTask[taskID]
  157. if not weekTaskConfig then return end
  158. if human.db.weekTask.task[taskID].finishCnt >= weekTaskConfig.taskProgress then
  159. print("[WeekTaskLogic-recordWeekTaskFinishCnt].3333333333333333333333333333333333",addCnt)
  160. human.db.weekTask.task[taskID].finishCnt = weekTaskConfig.taskProgress
  161. human.db.weekTask.task[taskID].state = 1
  162. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_802)
  163. ChengjiuLogic.onCallback(human,ChengjiuDefine.CJ_TASK_TYPE_12,1)
  164. -- local msgRet = Msg.gc.GC_WEEKSHARE_SET
  165. -- msgRet.type = 4
  166. -- msgRet.desc = weekTaskConfig.taskDesc
  167. -- Msg.send(msgRet,human.fd)
  168. end
  169. print("[WeekTaskLogic-recordWeekTaskFinishCnt].44444444444444444444444444444444444",addCnt)
  170. if noSend ~= true then
  171. WeekTaskQuery(human)
  172. end
  173. print("[WeekTaskLogic-recordWeekTaskFinishCnt].22222222222222222222222222222222222222",human.db.weekTask.task[taskID].finishCnt)
  174. end
  175. -- 领取活跃宝箱
  176. local function huoYueBoxCanGet(human,boxID)
  177. local weekTaskDB = human.db.weekTask
  178. if not weekTaskDB then return end
  179. local isGet = weekTaskDB.huoYueBox and weekTaskDB.huoYueBox[boxID] or 0
  180. if isGet ~= 0 then return end
  181. local nowHuoYue = weekTaskDB.nowHuoYue or 0
  182. local huoYueBoxConfig = WeekTaskExcel.huoYueBox[boxID]
  183. if nowHuoYue <= 0 or nowHuoYue < huoYueBoxConfig.needHuoYue then return end
  184. return true
  185. end
  186. function CG_WEEKTASK_GET_HUOYUEBOX(human,boxID)
  187. ------------------------------一键领取所有能领取的宝箱奖励------------------------------------
  188. print("当前进入领取周活跃")
  189. local weekTaskDB = human.db.weekTask
  190. if not weekTaskDB then
  191. print("当前不包含dailDB,返回了")
  192. return
  193. end
  194. local nowHuoYue = weekTaskDB.nowHuoYue
  195. if not nowHuoYue then
  196. print("当前不包含nowHuoYue,返回了")
  197. return
  198. end
  199. local double = RoleSystemLogic.isDouble(human, RoleSystemDefine.ROLE_SYS_ID_802)
  200. local rewardCnt = double and 2 or 1
  201. local cjPrivilege = ChengjiuLogic.checkPrivilege(human,ChengjiuDefine.PRIVILEGE_TYPE_2)
  202. local len = 0
  203. local randRate = 1
  204. local awardList = {}
  205. local boxData = weekTaskDB.huoYueBox
  206. local boxConfig = WeekTaskExcel.huoYueBox
  207. print("是否走到循环之前?")
  208. for boxId, v in ipairs(boxConfig) do
  209. print("当前活跃度不够是否进入循环?")
  210. if nowHuoYue >= v.needHuoYue and (not boxData or not boxData[boxId]) then
  211. print("当前进入循环")
  212. weekTaskDB.huoYueBox = weekTaskDB.huoYueBox or {}
  213. boxData = weekTaskDB.huoYueBox
  214. boxData[boxId] = 1
  215. randRate = 1
  216. if cjPrivilege then
  217. local random = math.random(1,100)
  218. if random <= 1 then
  219. randRate = 2
  220. end
  221. end
  222. for _, itemInfo in ipairs(v.reward) do
  223. len = len + 1
  224. awardList[len] = {itemInfo[1], itemInfo[2] * randRate * rewardCnt}
  225. end
  226. --更新
  227. local msgRet = Msg.gc.GC_WEEKTASK_GET_HUOYUEBOX
  228. msgRet.boxID = boxId
  229. msgRet.double = double and 1 or 0
  230. print("当前周活跃奖励领取完毕")
  231. print("当前下发周活跃奖励")
  232. Msg.send(msgRet,human.fd)
  233. end
  234. end
  235. if len > 0 then
  236. BagLogic.addItemList(human, awardList, "week_task")
  237. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_802)
  238. end
  239. end
  240. function isDot(human)
  241. -- 主界面的任务包含2个标签 每日任务/成就
  242. if RoleSystemLogic.isOpen(human, RoleSystemDefine.ROLE_SYS_ID_802) ~= true then
  243. return false
  244. end
  245. if human.db.weekTask and human.db.weekTask.task then
  246. for k,v in pairs(human.db.weekTask.task) do
  247. if k and v and v.isGet ~= true then
  248. local weekTaskConfig = WeekTaskExcel.weekTask[k]
  249. if weekTaskConfig then
  250. local cnt = v.finishCnt or 0
  251. if cnt >= weekTaskConfig.taskProgress then
  252. return true
  253. end
  254. end
  255. end
  256. end
  257. end
  258. for i=1,#WeekTaskExcel.huoYueBox do
  259. if huoYueBoxCanGet(human,i) then
  260. return true
  261. end
  262. end
  263. return false
  264. end
  265. function onWeekTaskHuoYue(human,sum)
  266. if not human.db.weekTask then return end
  267. print("当前进入添加活跃度",sum)
  268. human.db.weekTask.nowHuoYue = (human.db.weekTask.nowHuoYue or 0) + sum
  269. YunYingLogic.onCallBack(human, "onDailyTask",sum)
  270. end
  271. function WeekTaskLogic_Refsh(human)
  272. if not human.db.weekTask then
  273. human.db.weekTask = {}
  274. human.db.weekTask.nTime = os.time()
  275. else
  276. if not human.db.weekTask.nTime then
  277. human.db.weekTask.nTime = os.time()
  278. end
  279. local nLastTime = human.db.weekTask.nTime
  280. local bIsWeek = Util.isSameWeek(nLastTime, os.time())
  281. if false == bIsWeek then
  282. human.db.weekTask = {}
  283. human.db.weekTask.nTime = os.time()
  284. end
  285. end
  286. end
  287. function onLogin(human)
  288. WeekTaskLogic_Refsh(human)
  289. end