WeekTaskLogic.lua 11 KB

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