BarTaskLogic.lua 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099
  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 BarTaskExcel = require("excel.barTask")
  6. -- local ItemExcel = require("excel.item")
  7. local HeroExcel = require("excel.hero")
  8. local Grid = require("bag.Grid")
  9. local BagLogic = require("bag.BagLogic")
  10. local Broadcast = require("broadcast.Broadcast")
  11. local ItemDefine = require("bag.ItemDefine")
  12. -- local HeroDefine = require("hero.HeroDefine")
  13. local RoleSystemLogic = require("roleSystem.RoleSystemLogic")
  14. local RoleSystemDefine = require("roleSystem.RoleSystemDefine")
  15. local ChengjiuLogic = require("chengjiu.ChengjiuLogic")
  16. local ChengjiuDefine = require("chengjiu.ChengjiuDefine")
  17. local DailyTaskLogic = require("dailyTask.DailyTaskLogic")
  18. local RoleExcel = require("excel.role")
  19. local Util = require("common.Util")
  20. -- local MoshouLogic = require("moshou.MoshouLogic")
  21. -- local TequanShopLogic = require("present.TequanShopLogic")
  22. local GuideLogic = require("guide.GuideLogic")
  23. local HeroLogLogic = require("absAct.HeroLogLogic")
  24. local HeroGrowUp = require("absAct.HeroGrowUp")
  25. local MengxinLogic = require("present.MengxinLogic")
  26. local YunYingLogic = require("yunying.YunYingLogic")
  27. local TalismanLogic = require("talisman.TalismanLogic")
  28. local TriggerLogic = require("trigger.TriggerLogic")
  29. local TriggerDefine = require("trigger.TriggerDefine")
  30. local Abs365CardLogic = require("absAct.Abs365CardLogic")
  31. DEFAULT_BASE_TASK_CNT = 6 -- 默认基本任务数
  32. DEFAULT_REFRESH_ZUANSHI_CNT = 30 -- 默认刷新所需钻石数量
  33. DEFAULT_MAX_TASK_CNT = 200 -- 最大的任务数
  34. DEFAULT_MAX_DOUBLE_CNT = 10 -- 双倍领取次数
  35. BARTASK_OP_1 = 1 -- 放弃任务
  36. BARTASK_OP_2 = 2 -- 刷新任务
  37. BARTASK_OP_3 = 3 -- 开始任务
  38. BARTASK_OP_4 = 4 -- 完成/加速任务
  39. BARTASK_DAY_FREE = 2 -- 玩家每日免费刷新次数
  40. BARTASK_QUICK_FINISH_TIME = 60 * 60 -- 玩家免费完成时间
  41. BARTASK_TASK_NEED_ISR = 2200 -- 接取任务所需要的情报
  42. local PURPLE_TASK_STAR = 4 -- 紫色任务的star
  43. GUIDE_DEFAUT_STAR = {[1] = 4}
  44. GUIDE_DEFAUT_ITEM = {[1]= {ItemDefine.ITEM_DRAWCARD_GAOCHOU_ID, 1}}
  45. -- 是否拥有特权 (首充后会获得一定特权)
  46. local function isHavePrivilege(human)
  47. if not human.db.topupAcount or human.db.topupAcount <= 0 then
  48. return false
  49. end
  50. return true
  51. end
  52. -- 领取任务所需消耗
  53. local function getTaskCost(human)
  54. local needIsr = BARTASK_TASK_NEED_ISR
  55. local cjPrivilege = ChengjiuLogic.checkPrivilege(human, ChengjiuDefine.PRIVILEGE_TYPE_5)
  56. if cjPrivilege then
  57. local rate =(100 - cjPrivilege) / 100
  58. needIsr = needIsr * rate
  59. end
  60. return needIsr
  61. end
  62. -- 自动领取紫色以上任务
  63. local function autoGetSpeTasks(human)
  64. if not human.db.bar.autoGetTask or human.db.bar.autoGetTask ~= 1 then
  65. return
  66. end
  67. local isGet = false
  68. local itemCnt = getTaskCost(human)
  69. for key, value in pairs(human.db.bar) do
  70. if type(key) == "number" and type(value) == "table" then
  71. if human.db.bar.qingbao < itemCnt then
  72. break
  73. end
  74. if value.star >= PURPLE_TASK_STAR and not value.isLock then
  75. getDo(human, key, nil, nil, true)
  76. isGet = true
  77. end
  78. end
  79. end
  80. return isGet
  81. end
  82. function setBarTaskData(msgData, taskID, human, dbData, now)
  83. if type(taskID) ~= "number" then
  84. return
  85. end
  86. if now == nil then
  87. now = os.time()
  88. end
  89. msgData.taskID = taskID
  90. local heroConfig = HeroExcel.hero[dbData.nameID]
  91. local name = heroConfig.name
  92. local tempConfig = BarTaskExcel.taskName[dbData.star]
  93. local action = nil
  94. if dbData.star <= 3 then
  95. action = tempConfig.actionName[dbData.actionID]
  96. msgData.name = Util.format(Lang.BAR_NAME_FORMAT, action, name)
  97. else
  98. action = tempConfig.taskName[dbData.actionID]
  99. msgData.name = Util.format(Lang.BAR_NAME_FORMAT, name, action)
  100. end
  101. msgData.star = dbData.star
  102. -- 存储的时间是:领取任务时间 - 1
  103. if dbData.ts then
  104. msgData.leftTime = BarTaskExcel.barTask[dbData.star].useTime -(now - dbData.ts)
  105. if msgData.leftTime < 0 then
  106. msgData.leftTime = 0
  107. end
  108. else
  109. msgData.leftTime = BarTaskExcel.barTask[dbData.star].useTime
  110. end
  111. msgData.needTime = BarTaskExcel.barTask[dbData.star].useTime
  112. -- local itemID = dbData.itemID
  113. -- local itemCnt = dbData.itemCnt
  114. -- Grid.makeItem(msgData.item, itemID, itemCnt)
  115. local need = getQuickNeed(msgData.leftTime)
  116. msgData.zuanshiNeed = need
  117. -- BarTaskExcel.barTask[dbData.star].zuanshiNeed
  118. msgData.heroIndex[0] = 0
  119. if dbData.hero then
  120. msgData.heroIndex[0] = #dbData.hero
  121. for i = 1, #dbData.hero do
  122. msgData.heroIndex[i] = dbData.hero[i]
  123. end
  124. end
  125. end
  126. function rewardQuery(human, star)
  127. local barTaskConfig = BarTaskExcel.barTask[star]
  128. local msgRet = Msg.gc.GC_BARTASK_REWARD_QUERY
  129. msgRet.star = star
  130. for k, v in ipairs(barTaskConfig.reward) do
  131. Grid.makeItem(msgRet.item[k], v[1], v[2][1])
  132. end
  133. msgRet.item[0] = #barTaskConfig.reward
  134. Msg.send(msgRet, human.fd)
  135. end
  136. -- 查询酒馆任务
  137. function query(human)
  138. if not RoleSystemLogic.isOpen(human, RoleSystemDefine.ROLE_SYS_ID_1104, true) then
  139. return
  140. end
  141. ObjHuman.updateDaily(human)
  142. initDB(human)
  143. guideBar(human)
  144. local isGet = autoGetSpeTasks(human)
  145. local needIsr = BARTASK_TASK_NEED_ISR
  146. local cjPrivilege = ChengjiuLogic.checkPrivilege(human, ChengjiuDefine.PRIVILEGE_TYPE_5)
  147. if cjPrivilege then
  148. local rate =(100 - cjPrivilege) / 100
  149. needIsr = needIsr * rate
  150. end
  151. local msgRet = Msg.gc.GC_BARTASK_QUERY
  152. local now = os.time()
  153. local ts1 = Util.getDayStartTime(now)
  154. local double = RoleSystemLogic.isDouble(human, RoleSystemDefine.ROLE_SYS_ID_1104)
  155. msgRet.bOpen = Abs365CardLogic.IsBuyCard(human)
  156. msgRet.refreshTime = 24 * 60 * 60 -(now - ts1)
  157. msgRet.refreshNeed = DEFAULT_REFRESH_ZUANSHI_CNT
  158. msgRet.qingbaoNeed = needIsr
  159. msgRet.nowQingBao = human.db.bar and human.db.bar.qingbao or 0
  160. msgRet.qingBaoMax = RoleExcel.exp[human.db.lv].qingBaoMax
  161. msgRet.tequan = human.db.bar and human.db.bar.vip or 0
  162. msgRet.tequanSuper = human.db.bar and human.db.bar.superVip or 0
  163. msgRet.freeCnt = BARTASK_DAY_FREE - human.db.bar.refresCnt
  164. msgRet.freeCnt = msgRet.freeCnt > 0 and msgRet.freeCnt or 0
  165. msgRet.doubleCnt = 0
  166. msgRet.hasCharge = isHavePrivilege(human) and 1 or 0
  167. msgRet.isAutoTask = human.db.bar.autoGetTask or 0
  168. msgRet.AutoTaskTips = isGet and 1 or 0
  169. --秘宝对悬赏情报上限加成
  170. local qingBaoAdd = TalismanLogic.getTalismanAdd(human, TalismanLogic.OTHER_EFFECT_TBL.XUANSHANG_QB_MAX) or 0
  171. msgRet.qingBaoMax = msgRet.qingBaoMax + qingBaoAdd
  172. Grid.makeItem(msgRet.refresItem, ItemDefine.ITEM_BASE_JUANZHOU_ID, 1)
  173. if double and human.db.bar.doubleCnt <= DEFAULT_MAX_DOUBLE_CNT then
  174. msgRet.doubleCnt = DEFAULT_MAX_DOUBLE_CNT - human.db.bar.doubleCnt
  175. end
  176. local cnt = 0
  177. for key, value in pairs(human.db.bar) do
  178. if type(key) == "number" then
  179. cnt = cnt + 1
  180. setBarTaskData(msgRet.list[cnt], key, human, value, now)
  181. if cnt >= 200 then
  182. break
  183. end
  184. end
  185. end
  186. msgRet.list[0] = cnt
  187. -- Msg.trace(msgRet)
  188. Msg.send(msgRet, human.fd)
  189. end
  190. -- 刷新酒吧任务
  191. function refresh(human)
  192. ObjHuman.updateDaily(human)
  193. initDB(human)
  194. local allTaskCnt = getAllTaskCnt(human)
  195. if allTaskCnt >= DEFAULT_MAX_TASK_CNT then
  196. return Broadcast.sendErr(human, Lang.BAR_TASK_ALL_MAX_ERR)
  197. end
  198. local isFree = false
  199. if human.db.bar.refresCnt < BARTASK_DAY_FREE then
  200. isFree = true
  201. end
  202. -- 判断消耗
  203. if not isFree then
  204. -- 检测 是否拥有道具
  205. if BagLogic.getItemCnt(human, ItemDefine.ITEM_BASE_JUANZHOU_ID) > 0 then
  206. BagLogic.delItem(human, ItemDefine.ITEM_BASE_JUANZHOU_ID, 1, "bar_refresh")
  207. else
  208. local needZuanshi = DEFAULT_REFRESH_ZUANSHI_CNT
  209. if not ObjHuman.checkRMB(human, needZuanshi) then
  210. return
  211. end
  212. -- 扣消耗
  213. ObjHuman.decZuanshi(human, - needZuanshi, "bar_refresh")
  214. end
  215. end
  216. human.db.bar.refresCnt = human.db.bar.refresCnt + 1
  217. -- 改db
  218. for taskID, taskData in pairs(human.db.bar) do
  219. if type(taskID) == "number" then
  220. if taskData.isLock == nil then
  221. human.db.bar[taskID] = nil
  222. end
  223. end
  224. end
  225. addRandomTask(human, DEFAULT_BASE_TASK_CNT)
  226. query(human)
  227. TriggerLogic.PublishEvent(TriggerDefine.BARTASK_REFRESH, human.db._id, 1)
  228. end
  229. -- 查看具体任务信息
  230. function getQuery(human, taskID)
  231. ObjHuman.updateDaily(human)
  232. initDB(human)
  233. local taskData = human.db.bar[taskID]
  234. if taskData == nil then
  235. return
  236. end
  237. local msgRet = Msg.gc.GC_BARTASK_GET_QUERY
  238. local barTaskConfig = BarTaskExcel.barTask[taskData.star]
  239. msgRet.star = barTaskConfig.starNeed[1] or 0
  240. msgRet.camp[0] = taskData.camp and #taskData.camp or 0
  241. for i = 1, #taskData.camp do
  242. msgRet.camp[i] = taskData.camp[i]
  243. end
  244. -- Msg.trace(msgRet)
  245. Msg.send(msgRet, human.fd)
  246. end
  247. -- 新手引导下默认高抽
  248. function guideBar(human)
  249. if not human.db.bar or not human.db.bar[1] then return end
  250. local flag = GuideLogic.getGuideSkip(human, GuideLogic.SKIPTYPE_JUMP_BARTASK)
  251. if flag then return end
  252. human.db.bar[1].star = GUIDE_DEFAUT_STAR[1]
  253. -- human.db.bar[1].itemID = GUIDE_DEFAUT_ITEM[1][1]
  254. -- human.db.bar[1].itemCnt = GUIDE_DEFAUT_ITEM[1][2]
  255. GuideLogic.setDoSpecialGuide(human, GuideLogic.SKIPTYPE_JUMP_BARTASK)
  256. end
  257. -- 领取任务
  258. function getDo(human, taskID, heroIndexList, heroIDList, noSend)
  259. if not RoleSystemLogic.isOpen(human, RoleSystemDefine.ROLE_SYS_ID_1104, true) then
  260. return
  261. end
  262. ObjHuman.updateDaily(human)
  263. initDB(human)
  264. guideBar(human)
  265. local taskData = human.db.bar[taskID]
  266. if taskData == nil then
  267. return
  268. end
  269. local isNeedCkeck = true
  270. if isHavePrivilege(human) then
  271. isNeedCkeck = false
  272. end
  273. local barTaskConfig = BarTaskExcel.barTask[taskData.star]
  274. -- 判断数量
  275. -- if heroIDList[0] ~= heroIndexList[0] then
  276. -- return
  277. -- end
  278. if isNeedCkeck and heroIDList[0] ~= heroIndexList[0] then
  279. return
  280. end
  281. local needIsr = BARTASK_TASK_NEED_ISR
  282. local cjPrivilege = ChengjiuLogic.checkPrivilege(human, ChengjiuDefine.PRIVILEGE_TYPE_5)
  283. if cjPrivilege then
  284. local rate =(100 - cjPrivilege) / 100
  285. needIsr = needIsr * rate
  286. end
  287. -- 判定情报值
  288. if human.db.bar.qingbao < needIsr then
  289. return Broadcast.sendErr(human, Lang.BAR_TASK_GET_ERR_ISR)
  290. end
  291. -- 判断英雄
  292. -- local indexTable = { }
  293. -- for i = 1, heroIDList[0] do
  294. -- local tempIndex = heroIndexList[i]
  295. -- local heroGird = human.db.heroBag[tempIndex]
  296. -- if type(heroGird) ~= "table" then
  297. -- -- 没有这个英雄
  298. -- return
  299. -- end
  300. -- if heroGird.id ~= heroIDList[i] then
  301. -- -- 没对应上
  302. -- return
  303. -- end
  304. -- if indexTable[tempIndex] then
  305. -- -- 发了重复id
  306. -- return
  307. -- end
  308. -- if isSelectForBarTask(human, tempIndex) then
  309. -- -- 已经在其它悬赏中选择了
  310. -- return
  311. -- end
  312. -- indexTable[tempIndex] = true
  313. -- local heroConfig = HeroExcel.hero[heroGird.id]
  314. -- if heroGird.star >= needStar then
  315. -- nowStarCnt = nowStarCnt + 1
  316. -- end
  317. -- camp2Cnt[heroConfig.camp] =(camp2Cnt[heroConfig.camp] or 0) + 1
  318. -- end
  319. -- -- 判断条件
  320. -- if nowStarCnt < needStarCnt then
  321. -- return Broadcast.sendErr(human, Util.format(Lang.BAR_TASK_GET_ERR_STAR, needStar, needStarCnt))
  322. -- end
  323. -- local campLen = taskData.camp and #taskData.camp or 0
  324. -- for i = 1, campLen do
  325. -- local needCamp = taskData.camp[i]
  326. -- local nowCampCnt = camp2Cnt[needCamp] or 0
  327. -- if nowCampCnt < 1 then
  328. -- return Broadcast.sendErr(human, Lang.BAR_TASK_GET_ERR_CAMP)
  329. -- end
  330. -- camp2Cnt[needCamp] = nowCampCnt - 1
  331. -- end
  332. -- -- 扣除情报点
  333. -- human.db.bar.qingbao = human.db.bar.qingbao - needIsr
  334. -- -- 改db
  335. -- human.db.bar[taskID].isLock = true
  336. -- -- 因为:领取任务后,马上就去query查询,间隔太短
  337. -- -- 导致:时间间隔为0,此时剩下的时间和需要花费的时间相等,导致客户端无法判断
  338. -- -- 所以:领取时间要减去1秒,用来区分
  339. -- -- 链接至:query(human)查看
  340. -- human.db.bar[taskID].ts = os.time() -1
  341. -- human.db.bar[taskID].hero = { }
  342. -- for i = 1, heroIDList[0] do
  343. -- human.db.bar[taskID].hero[i] = heroIndexList[i]
  344. -- end
  345. if isNeedCkeck then
  346. local needStar = barTaskConfig.starNeed[1]
  347. local needStarCnt = barTaskConfig.starNeed[2]
  348. local nowStarCnt = 0
  349. local camp2Cnt = { }
  350. local indexTable = { }
  351. for i = 1, heroIDList[0] do
  352. local tempIndex = heroIndexList[i]
  353. local heroGird = human.db.heroBag[tempIndex]
  354. if type(heroGird) ~= "table" then
  355. -- 没有这个英雄
  356. return
  357. end
  358. if heroGird.id ~= heroIDList[i] then
  359. -- 没对应上
  360. return
  361. end
  362. if indexTable[tempIndex] then
  363. -- 发了重复id
  364. return
  365. end
  366. if isSelectForBarTask(human, tempIndex) then
  367. -- 已经在其它悬赏中选择了
  368. return
  369. end
  370. indexTable[tempIndex] = true
  371. local heroConfig = HeroExcel.hero[heroGird.id]
  372. if heroGird.star >= needStar then
  373. nowStarCnt = nowStarCnt + 1
  374. end
  375. camp2Cnt[heroConfig.camp] =(camp2Cnt[heroConfig.camp] or 0) + 1
  376. end
  377. -- 判断条件
  378. if nowStarCnt < needStarCnt then
  379. return Broadcast.sendErr(human, Util.format(Lang.BAR_TASK_GET_ERR_STAR, needStar, needStarCnt))
  380. end
  381. local campLen = taskData.camp and #taskData.camp or 0
  382. for i = 1, campLen do
  383. local needCamp = taskData.camp[i]
  384. local nowCampCnt = camp2Cnt[needCamp] or 0
  385. if nowCampCnt < 1 then
  386. return Broadcast.sendErr(human, Lang.BAR_TASK_GET_ERR_CAMP)
  387. end
  388. camp2Cnt[needCamp] = nowCampCnt - 1
  389. end
  390. human.db.bar[taskID].hero = { }
  391. for i = 1, heroIDList[0] do
  392. human.db.bar[taskID].hero[i] = heroIndexList[i]
  393. end
  394. end
  395. -- 扣除情报点
  396. human.db.bar.qingbao = human.db.bar.qingbao - needIsr
  397. -- 改db
  398. human.db.bar[taskID].isLock = true
  399. -- 因为:领取任务后,马上就去query查询,间隔太短
  400. -- 导致:时间间隔为0,此时剩下的时间和需要花费的时间相等,导致客户端无法判断
  401. -- 所以:领取时间要减去1秒,用来区分
  402. -- 链接至:query(human)查看
  403. human.db.bar[taskID].ts = os.time() -1
  404. -- 通知客户端
  405. if not noSend then
  406. sendBarTaskUpdate(human, taskID, BARTASK_OP_3)
  407. end
  408. DailyTaskLogic.recordDailyTaskFinishCnt(human, DailyTaskLogic.DAILY_TASK_ID_9, 1)
  409. ChengjiuLogic.onCallback(human, ChengjiuDefine.CJ_TASK_TYPE_7, 1)
  410. MengxinLogic.onCallBack(human,MengxinLogic.MX_TASK_TYPE_4,1)
  411. if taskData.star == 6 then
  412. ChengjiuLogic.onCallback(human, ChengjiuDefine.CJ_TASK_TYPE_18, 1)
  413. HeroGrowUp.onCallback(human, HeroGrowUp.TASKTYPE17, 1)
  414. end
  415. if taskData.star >= 5 then
  416. HeroLogLogic.finishTaskCB(human,HeroLogLogic.HERO_LOG_TYPE_4,1)
  417. end
  418. YunYingLogic.onCallBack(human, "onBarTaskgetDo",1)
  419. TriggerLogic.PublishEvent(TriggerDefine.BARTASK_GET, human.db._id, 1, taskData.star)
  420. end
  421. function getQuickNeed(surTime)
  422. for k, config in ipairs(BarTaskExcel.accTime) do
  423. if surTime < config.maxTime then
  424. return config.zuanshiNeed
  425. end
  426. end
  427. return BarTaskExcel.accTime[#BarTaskExcel.accTime].zuanshiNeed
  428. end
  429. -- 加速完成任务
  430. function quickFinish(human, taskID)
  431. ObjHuman.updateDaily(human)
  432. initDB(human)
  433. local taskData = human.db.bar[taskID]
  434. if taskData == nil then
  435. return
  436. end
  437. -- 条件判断
  438. if taskData.isLock == nil or taskData.ts == nil then
  439. return
  440. end
  441. -- 消耗判断
  442. local barTaskConfig = BarTaskExcel.barTask[taskData.star]
  443. if not barTaskConfig then return end
  444. local surTime = barTaskConfig.useTime -(os.time() - taskData.ts)
  445. local needZuanshi = getQuickNeed(surTime)
  446. if needZuanshi > 0 then
  447. if not ObjHuman.checkRMB(human, needZuanshi) then
  448. return
  449. end
  450. -- 扣消耗
  451. ObjHuman.decZuanshi(human, - needZuanshi, "bar_quick_finish")
  452. end
  453. -- 改db
  454. human.db.bar[taskID].ts = 0
  455. finishTask(human, taskID)
  456. end
  457. function randomTak(human, taskID)
  458. local taskData = human.db.bar[taskID]
  459. if taskData.random then return end
  460. local barTaskConfig = BarTaskExcel.barTask[taskData.star]
  461. if not barTaskConfig then return end
  462. local totalWeight = 0
  463. for i = 1, #barTaskConfig.reward do
  464. totalWeight = totalWeight + barTaskConfig.reward[i][3]
  465. end
  466. local getList = {}
  467. local getRare = 0
  468. for i = 1 , 3 do
  469. local random = math.random(1, totalWeight - getRare)
  470. for k, v in pairs(barTaskConfig.reward) do
  471. if not getList[k] and random <= v[3] then
  472. getList[k] = i
  473. getRare = getRare + v[3]
  474. break
  475. elseif not getList[k] then
  476. -- 防止循环最后一个是 已经随机过的 导致 随机不出来
  477. random = random - v[3]
  478. end
  479. end
  480. end
  481. taskData.random = {}
  482. for k, v in pairs(getList) do
  483. local config = barTaskConfig.reward[k]
  484. taskData.random[v] = {}
  485. taskData.random[v].itemID = config[1]
  486. taskData.random[v].itemCnt = math.random(config[2][1], config[2][2] )
  487. end
  488. end
  489. -- 提交任务
  490. function finishTask(human, taskID)
  491. ObjHuman.updateDaily(human)
  492. initDB(human)
  493. local taskData = human.db.bar[taskID]
  494. if taskData == nil then
  495. return
  496. end
  497. -- 判断条件
  498. local star = taskData.star
  499. local needTime = BarTaskExcel.barTask[star].useTime
  500. local now = os.time()
  501. if now - taskData.ts < needTime then
  502. return
  503. end
  504. if not human.db.bar[taskID].random then
  505. randomTak(human, taskID)
  506. end
  507. -- 双倍参数
  508. --[[
  509. local itemID = taskData.itemID
  510. local itemCnt = taskData.itemCnt
  511. local double = RoleSystemLogic.isDouble(human, RoleSystemDefine.ROLE_SYS_ID_1104)
  512. local isDouble = false
  513. if star == 4 and double and human.db.bar.doubleCnt < DEFAULT_MAX_DOUBLE_CNT then
  514. itemCnt = itemCnt * 2
  515. human.db.bar.doubleCnt = human.db.bar.doubleCnt + 1
  516. isDouble = true
  517. end
  518. ]]
  519. -- 改db
  520. -- human.db.bar[taskID] = nil
  521. -- 给奖励
  522. -- BagLogic.addItem(human, itemID, itemCnt, "bar_reward")
  523. local double = RoleSystemLogic.isDouble(human, RoleSystemDefine.ROLE_SYS_ID_1104)
  524. local isDouble = false
  525. local beishu = 1
  526. if star == 4 and double and human.db.bar.doubleCnt < DEFAULT_MAX_DOUBLE_CNT then
  527. isDouble = true
  528. beishu = 2
  529. end
  530. -- 通知客户端
  531. local msgRet = Msg.gc.GC_BARTASK_FINISH_TASK
  532. msgRet.taskID = taskID
  533. msgRet.double = isDouble and 1 or 0
  534. for k, v in ipairs(human.db.bar[taskID].random) do
  535. Grid.makeItem(msgRet.item[k], v.itemID, v.itemCnt * beishu)
  536. end
  537. msgRet.item[0] = #human.db.bar[taskID].random
  538. Msg.send(msgRet, human.fd)
  539. -- MoshouLogic.onCallBack(human, MoshouLogic.MOSHOU_TASKTYPE_XUANSHANG, 1)
  540. HeroGrowUp.onCallback(human, HeroGrowUp.TASKTYPE15, 1)
  541. end
  542. function chooseReward(human, taskID, index)
  543. ObjHuman.updateDaily(human)
  544. initDB(human)
  545. local taskData = human.db.bar[taskID]
  546. if taskData == nil then
  547. return
  548. end
  549. if not human.db.bar[taskID].random or not human.db.bar[taskID].random[index] then
  550. return
  551. end
  552. local itemID = human.db.bar[taskID].random[index].itemID
  553. local itemCnt = human.db.bar[taskID].random[index].itemCnt
  554. local double = RoleSystemLogic.isDouble(human, RoleSystemDefine.ROLE_SYS_ID_1104)
  555. local isDouble = false
  556. if taskData.star == 4 and double and human.db.bar.doubleCnt < DEFAULT_MAX_DOUBLE_CNT then
  557. itemCnt = itemCnt * 2
  558. human.db.bar.doubleCnt = human.db.bar.doubleCnt + 1
  559. isDouble = true
  560. end
  561. -- 改db
  562. human.db.bar[taskID] = nil
  563. -- 给奖励
  564. BagLogic.addItem(human, itemID, itemCnt, "bar_reward")
  565. local msgRet = Msg.gc.GC_BARTASK_CHOOSE_REWARD
  566. msgRet.taskID = taskID
  567. msgRet.double = isDouble and 1 or 0
  568. Grid.makeItem(msgRet.item, itemID, itemCnt)
  569. Msg.send(msgRet, human.fd)
  570. end
  571. -- 一键领取
  572. function CG_BARTASK_FINISH_ALL(human)
  573. if not human.db.bar then return end
  574. if 0 == Abs365CardLogic.IsBuyCard(human) then
  575. print("[CG_BARTASK_FINISH_ALL] 当前没有购买直接返回")
  576. return
  577. end
  578. -- 双倍参数 -- 清空次数
  579. local double = RoleSystemLogic.isDouble(human, RoleSystemDefine.ROLE_SYS_ID_1104)
  580. local isDouble
  581. local msgRet = Msg.gc.GC_BARTASK_FINISH_ALL
  582. -- 随机出奖励
  583. local tPrizeTask = {}
  584. for taskID, taskData in pairs(human.db.bar) do
  585. if type(taskID) == "number" and taskData.ts then
  586. local star = taskData.star
  587. local needTime = BarTaskExcel.barTask[star].useTime
  588. local now = os.time()
  589. if now - taskData.ts >= needTime then
  590. if not taskData.random then
  591. randomTak(human, taskID)
  592. end
  593. table.insert(tPrizeTask, taskID)
  594. end
  595. end
  596. end
  597. if not tPrizeTask or nil == _G.next(tPrizeTask) then
  598. print("[CG_BARTASK_FINISH_ALL] 不存在可领取的任务奖励")
  599. return
  600. end
  601. local list = nil
  602. local cnt = 0
  603. for _, taskID in ipairs(tPrizeTask) do
  604. local taskData = human.db.bar[taskID]
  605. if taskData.ts then
  606. local star = taskData.star
  607. local needTime = BarTaskExcel.barTask[star].useTime
  608. local now = os.time()
  609. if now - taskData.ts >= needTime and taskData.random then
  610. local itemID, itemCnt
  611. local nLen = 0
  612. for k, v in pairs(taskData.random) do
  613. nLen = nLen + 1
  614. end
  615. local nChoseLen = math.random(1, nLen)
  616. local i = 0
  617. for k, v in pairs(taskData.random) do
  618. i = i + 1
  619. if i == nChoseLen then
  620. itemID = v.itemID
  621. itemCnt = v.itemCnt
  622. end
  623. end
  624. -- 计算双倍
  625. if star == 4 and double and human.db.bar.doubleCnt < DEFAULT_MAX_DOUBLE_CNT then
  626. itemCnt = itemCnt * 2
  627. human.db.bar.doubleCnt = human.db.bar.doubleCnt + 1
  628. isDouble = true
  629. end
  630. list = list or { }
  631. list[itemID] =(list[itemID] or 0) + itemCnt
  632. human.db.bar[taskID] = nil
  633. cnt = cnt + 1
  634. BagLogic.addItem(human, itemID, itemCnt, "bar_reward")
  635. end
  636. end
  637. end
  638. if not list then return end
  639. msgRet.double = isDouble and 1 or 0
  640. msgRet.items[0] = 0
  641. for itemID, itemCnt in pairs(list) do
  642. msgRet.items[0] = msgRet.items[0] + 1
  643. if not msgRet.items[msgRet.items[0]] then
  644. msgRet.items[msgRet.items[0]] = Util.copyTable(msgRet.items[msgRet.items[0] -1])
  645. end
  646. Grid.makeItem(msgRet.items[msgRet.items[0]], itemID, itemCnt)
  647. end
  648. -- Msg.trace(msgRet)
  649. Msg.send(msgRet, human.fd)
  650. query(human)
  651. end
  652. function heroIndexByDelForPos(human, index)
  653. if not human.db.bar then return end
  654. for taskID, v in pairs(human.db.bar) do
  655. if type(taskID) == "number" then
  656. local heroLen = v.hero and #v.hero or 0
  657. for i = 1, heroLen do
  658. if v.hero[i] == index then
  659. table.remove(v.hero, i)
  660. break
  661. end
  662. end
  663. end
  664. end
  665. end
  666. -- 是否已上阵
  667. function isSelectForBarTask(human, index)
  668. if not human.db.bar then return end
  669. for taskID, v in pairs(human.db.bar) do
  670. if type(taskID) == "number" then
  671. local heroLen = v.hero and #v.hero or 0
  672. for i = 1, heroLen do
  673. if v.hero[i] == index then
  674. return true
  675. end
  676. end
  677. end
  678. end
  679. end
  680. -- 激活酒馆悬赏 特权
  681. function activateBarVip(human, type)
  682. initDB(human)
  683. if type == 1 then
  684. human.db.bar.vip = 1
  685. elseif type == 2 then
  686. human.db.bar.superVip = 1
  687. end
  688. end
  689. ------------------------------功能函数-------------------------------------------
  690. function getEmptyIndex(human)
  691. for index = 1, 1000 do
  692. if human.db.bar[index] == nil then
  693. return index
  694. end
  695. end
  696. end
  697. -- 初始化酒馆任务数据
  698. function initDB(human)
  699. if human.db.bar ~= nil then
  700. return
  701. end
  702. human.db.bar = { }
  703. human.db.bar.refresCnt = 0
  704. human.db.bar.qingbao = 0
  705. human.db.bar.doubleCnt = 0 -- 双倍次数
  706. local newAddCnt = getBaseTaskCnt(human)
  707. addRandomTask(human, newAddCnt, {4}, true)
  708. end
  709. -- 跨天刷新酒馆任务
  710. function refreshDailyTask(human)
  711. if human.db.bar == nil then
  712. return
  713. end
  714. human.db.bar.refresCnt = 0
  715. human.db.bar.doubleCnt = 0 -- 双倍次数
  716. end
  717. -- 获取现在的任务总数
  718. function getAllTaskCnt(human)
  719. if human.db.bar == nil then
  720. return 0
  721. end
  722. local allTaskCnt = 0
  723. for key, value in pairs(human.db.bar) do
  724. if value ~= nil then
  725. allTaskCnt = allTaskCnt + 1
  726. end
  727. end
  728. return allTaskCnt
  729. end
  730. -- 获取玩家基础任务数
  731. function getBaseTaskCnt(human)
  732. return DEFAULT_BASE_TASK_CNT
  733. end
  734. -- 随机 悬赏任务 starList[第几个] = 星级 itemList[第几个] = {itemID, itemCnt}
  735. function addRandomTask(human, cnt, starList, isInit)
  736. if cnt < 1 then return end
  737. -- 检查是否 已经达到上限
  738. local allTaskCnt = getAllTaskCnt(human)
  739. if allTaskCnt >= 200 then
  740. return
  741. end
  742. local star = nil
  743. local camp = nil
  744. local nameID = nil
  745. local actionID = nil
  746. local vipChange = 0
  747. if (human.db.bar.refresCnt == BARTASK_DAY_FREE + 1 and human.db.bar.vip) or(human.db.bar.refresCnt == BARTASK_DAY_FREE + 3 and human.db.bar.superVip) then
  748. vipChange = math.random(1, cnt)
  749. end
  750. for i = 1, cnt do
  751. star = getRandomStar(human)
  752. if vipChange > 0 and i == vipChange then
  753. if human.db.bar.refresCnt == BARTASK_DAY_FREE + 1 then
  754. star = 4
  755. else
  756. star = 5
  757. end
  758. end
  759. if starList and starList[i] then
  760. star = starList[i]
  761. end
  762. itemID, itemCnt = getRandomItem(human, star)
  763. nameID, actionID = getRandomName(human, star)
  764. camp = getRandomCond(star)
  765. if isInit then
  766. camp[1] = 1
  767. camp[2] = 2
  768. end
  769. local emptyIndex = getEmptyIndex(human)
  770. if emptyIndex then
  771. human.db.bar[emptyIndex] = { }
  772. human.db.bar[emptyIndex].star = star
  773. human.db.bar[emptyIndex].nameID = nameID
  774. human.db.bar[emptyIndex].actionID = actionID
  775. human.db.bar[emptyIndex].camp = camp
  776. human.db.bar[emptyIndex].isLock = nil
  777. human.db.bar[emptyIndex].ts = nil
  778. human.db.bar[emptyIndex].hero = nil
  779. end
  780. end
  781. end
  782. -- 添加情报值
  783. function addBarQingBao(human, cnt)
  784. initDB(human)
  785. if human.db.bar == nil then
  786. return
  787. end
  788. local max = RoleExcel.exp[human.db.lv].qingBaoMax
  789. local qingBaoAdd = TalismanLogic.getTalismanAdd(human, TalismanLogic.OTHER_EFFECT_TBL.XUANSHANG_QB_MAX) or 0
  790. max = max + qingBaoAdd
  791. if human.db.bar.qingbao + cnt < max then
  792. human.db.bar.qingbao = human.db.bar.qingbao + cnt
  793. else
  794. human.db.bar.qingbao = max
  795. end
  796. end
  797. function getRandomStar(human)
  798. local barTaskConfig = BarTaskExcel.barTask
  799. local totalWeight = 0
  800. for i = 1, #barTaskConfig do
  801. totalWeight = totalWeight + barTaskConfig[i].chance
  802. end
  803. local randNum = math.random(1, totalWeight)
  804. local star = 0
  805. for j = 1, #barTaskConfig do
  806. local tempWeight = barTaskConfig[j].chance
  807. if randNum <= tempWeight then
  808. star = j
  809. break
  810. end
  811. randNum = randNum - tempWeight
  812. end
  813. return star
  814. end
  815. function getRandomItem(human, star)
  816. local barTaskConfig = BarTaskExcel.barTask[star]
  817. if not barTaskConfig then return end
  818. local totalWeight = 0
  819. for i = 1, #barTaskConfig.reward do
  820. totalWeight = totalWeight + barTaskConfig.reward[i][3]
  821. end
  822. local randNum = math.random(1, totalWeight)
  823. local itemID = 0
  824. local itemCnt = 0
  825. for j = 1, #barTaskConfig.reward do
  826. local tempWeight = barTaskConfig.reward[j][3]
  827. if randNum <= tempWeight then
  828. itemID = barTaskConfig.reward[j][1]
  829. local minCnt = barTaskConfig.reward[j][2][1]
  830. local maxCnt = barTaskConfig.reward[j][2][2]
  831. itemCnt = math.random(minCnt, maxCnt)
  832. break
  833. end
  834. randNum = randNum - tempWeight
  835. end
  836. return itemID, itemCnt
  837. end
  838. function getRandomName(human, star)
  839. local barTaskConfig = BarTaskExcel.taskName[star]
  840. if not barTaskConfig then return end
  841. local randNum = math.random(1, #barTaskConfig.heroName)
  842. local nameID = barTaskConfig.heroName[randNum]
  843. local actionID = nil
  844. if star <= 3 then
  845. actionID = math.random(1, #barTaskConfig.actionName)
  846. else
  847. actionID = math.random(1, #barTaskConfig.taskName)
  848. end
  849. return nameID, actionID
  850. end
  851. function getRandomCond(star)
  852. local barTaskConfig = BarTaskExcel.barTask[star]
  853. if not barTaskConfig then return end
  854. local heroCnt = barTaskConfig.heroCnt
  855. local camp = { }
  856. local c = 0
  857. local j = 0
  858. for i = 1, 5 do camp[i] = i end
  859. for i = 1, heroCnt do
  860. c = c + 1
  861. local r = math.random(c, #camp)
  862. camp[c], camp[r] = camp[r], camp[c]
  863. end
  864. for i = #camp, c + 1, -1 do
  865. camp[i] = nil
  866. end
  867. return camp
  868. end
  869. -- 下发酒馆任务更新
  870. function sendBarTaskUpdate(human, taskID, op)
  871. local msgRet = Msg.gc.GC_BARTASK_UPDATE
  872. msgRet.op = op
  873. setBarTaskData(msgRet.task, taskID, human, human.db.bar[taskID])
  874. msgRet.nowQingBao = human.db.bar and human.db.bar.qingbao or 0
  875. Msg.send(msgRet, human.fd)
  876. end
  877. -- 是否有红点
  878. function isDot(human)
  879. if human.db.bar == nil then
  880. return false
  881. end
  882. local now = os.time()
  883. for k, v in pairs(human.db.bar) do
  884. if type(k) == "number" then
  885. if v.ts == nil then
  886. return false
  887. end
  888. if v.isLock and v.ts then
  889. local needTime = BarTaskExcel.barTask[v.star].useTime
  890. if now - v.ts > needTime then
  891. return true
  892. end
  893. end
  894. end
  895. end
  896. return false
  897. end
  898. -- 更新勾选 "自动领取紫色以上任务"
  899. function UpdateOP(human, state)
  900. if not human.db.bar then
  901. return
  902. end
  903. if state ~= 0 and state ~= 1 then
  904. return Broadcast.sendErr(human, Lang.COMMON_ARGUMENT_ERROR)
  905. end
  906. human.db.bar.autoGetTask = state
  907. SendOPState(human)
  908. if state == 1 then
  909. query(human)
  910. end
  911. end
  912. function SendOPState(human)
  913. local msgRet = Msg.gc.GC_BARTASK_SET_OP
  914. msgRet.op = human.db.bar.autoGetTask or 0
  915. Msg.send(msgRet, human.fd)
  916. end