WeekTaskLogic.lua 12 KB

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