HeroGrowUp.lua 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120
  1. ---------------------------------------------------------------
  2. -- 英雄崛起(其实28天为一期的任务活动)
  3. -- 与创角时间相关
  4. -- tip 32
  5. -- db.heroGrowUp.groupID 活动组id
  6. -- db.heroGrowUp.time 活动开始的时间戳
  7. -- db.heroGrowUp.lv 等级
  8. -- db.heroGrowUp.lvGet 等级领取
  9. -- db.heroGrowUp.lvExGet 等级额外领取
  10. -- db.heroGrowUp.jifen 当前积分
  11. -- db.heroGrowUp.isBuy 是否购买
  12. -- db.heroGrowUp.task[mainType] = taskList
  13. -- taskList.time 刷新时间
  14. -- taskList.records 任务进度 [id] = value
  15. -- taskList.gets 领取记录 [id] = true
  16. ---------------------------------------------------------------
  17. local PresentExcel = require("excel.present")
  18. local OpenActExcel = require("excel.openAct")
  19. local Util = require("common.Util")
  20. local Lang = require("common.Lang")
  21. local Msg = require("core.Msg")
  22. local Broadcast = require("broadcast.Broadcast")
  23. local Grid = require("bag.Grid")
  24. local BagLogic = require("bag.BagLogic")
  25. local CombatDefine = require("combat.CombatDefine")
  26. local BuyLogic = require("topup.BuyLogic")
  27. local HeroDefine = require("hero.HeroDefine")
  28. local RoleDBLogic = require("role.RoleDBLogic")
  29. local YunYingLogic = require("yunying.YunYingLogic")
  30. local SceneHandler = require("scene.Handler")
  31. local CommonDB = require("common.CommonDB")
  32. local ItemExcel = require("excel.item")
  33. local ObjHuman = require("core.ObjHuman")
  34. local Config = require("Config")
  35. local AbsActExcel = require("excel.absAct")
  36. local AbsActLogic = require("absAct.AbsActLogic")
  37. DAY_TIME_SEC = 1 * 86400
  38. WEEK_TIME_SEC = 7 * 86400
  39. ACT_TIME_SEC1 = 28 * 86400
  40. ACT_TIME_SEC2 = 14 * 86400
  41. -- 任务分类
  42. MAINTYPE_DAY = 1 -- 每日
  43. MAINTYPE_WEEK = 2 -- 每周
  44. MAINTYPE_MONTH = 3 -- 每期
  45. MAINTYPE_CNT = 3
  46. -- 任务状态
  47. TASK_STATE_NONE = 0 -- 不可领
  48. TASK_STATE_CAN = 1 -- 可领
  49. TASK_STATE_HAD = 2 -- 已领
  50. -- 任务类型
  51. TASKTYPE1 = 1 -- o登录游戏
  52. TASKTYPE2 = 2 -- o天命召唤
  53. TASKTYPE3 = 3 -- o占卜合成
  54. TASKTYPE4 = 4 -- o消耗x金币
  55. TASKTYPE5 = 5 -- o消耗x钻石
  56. TASKTYPE6 = 6 -- o战报点赞X次
  57. TASKTYPE7 = 7 -- o皇冠联赛战场胜利X次
  58. TASKTYPE8 = 8 -- o合成X次任意符文
  59. TASKTYPE9 = 9 -- o冰龙巢穴
  60. TASKTYPE10 = 10 -- o随机商店购买道具
  61. TASKTYPE11 = 11 -- o上阵指定英雄XX,皇冠联赛战场获得X场胜利
  62. TASKTYPE12 = 12 -- o获取X个Y星英雄
  63. TASKTYPE13 = 13 -- o挑战战神殿
  64. TASKTYPE14 = 14 -- o王者争霸32强
  65. TASKTYPE15 = 15 -- o完成X次悬赏任务
  66. TASKTYPE16 = 16 -- o圣树试炼胜利X次
  67. TASKTYPE17 = 17 -- o接取X次红色悬赏任务
  68. TASKTYPE18 = 18 -- o消耗X英雄经验
  69. TASKTYPE19 = 19 -- o洗练X次任意装备
  70. TASKTYPE20 = 20 -- o遗迹探宝,击败x个守卫
  71. TASKTYPE21 = 21 -- o分解装备
  72. DG_ABS_ACT_ID = 8001
  73. HGU_AFTER_START = true
  74. function initAfterStart()
  75. HGU_AFTER_START = false
  76. end
  77. function initAfterHot()
  78. if HGU_AFTER_START then
  79. return
  80. end
  81. local workManStartTime,workManEndTime,groupID = getActStartTime()
  82. -- 活动未开
  83. if not workManStartTime then
  84. return
  85. end
  86. --重置任务
  87. TASKTYPE_2_MAINTYPES = {}
  88. MAINTYPE_2_IDLIST = {}
  89. -- 设置新任务
  90. for id, cf in pairs(AbsActExcel.heroGrowUpTask) do
  91. if not TASKTYPE_2_MAINTYPES[cf.taskType] then
  92. TASKTYPE_2_MAINTYPES[cf.taskType] = {}
  93. end
  94. if not MAINTYPE_2_IDLIST[cf.mainType] then
  95. MAINTYPE_2_IDLIST[cf.mainType] = {}
  96. end
  97. local len = #MAINTYPE_2_IDLIST[cf.mainType]
  98. MAINTYPE_2_IDLIST[cf.mainType][len + 1] = id
  99. local list = TASKTYPE_2_MAINTYPES[cf.taskType]
  100. local value = cf.taskArgs[1]
  101. local key = cf.taskArgs[2]
  102. if type(cf.taskArgs[2]) == "table" then
  103. local lenth = #cf.taskArgs[2]
  104. local randomPos = math.random(1,lenth)
  105. key = cf.taskArgs[2][randomPos]
  106. end
  107. if key then
  108. list[cf.mainType] = list[cf.mainType] or {}
  109. list[cf.mainType][key] = math.max(list[cf.mainType][key] or 0, value)
  110. else
  111. list[cf.mainType] = math.max(list[cf.mainType] or 0, value)
  112. end
  113. end
  114. GROUPID_2_LVCONFIGS = {}
  115. for _, cf in ipairs(AbsActExcel.heroGrowUpLv) do
  116. if not GROUPID_2_LVCONFIGS[cf.groupID] then
  117. GROUPID_2_LVCONFIGS[cf.groupID] = {}
  118. end
  119. GROUPID_2_LVCONFIGS[cf.groupID][cf.lv] = cf
  120. end
  121. end
  122. -- 本期活动开始时间
  123. function getActStartTime()
  124. --local id = AbsActLogic.getIDByActID(human, DG_ABS_ACT_ID)
  125. local absActConfig = AbsActExcel.absActivity[DG_ABS_ACT_ID]
  126. if absActConfig.actId and absActConfig.actId ~= 0 then
  127. return absActConfig.realStartTime,absActConfig.realEndTime,absActConfig.actId
  128. end
  129. end
  130. -- 活动剩余时间
  131. function getActLeftTime()
  132. local absActConfig = AbsActExcel.absActivity[DG_ABS_ACT_ID]
  133. if absActConfig.actId then
  134. return absActConfig.realEndTime - os.time()
  135. end
  136. return 0
  137. end
  138. -- 任务周期
  139. function getTaskTime(mainType)
  140. if mainType == MAINTYPE_DAY then
  141. return DAY_TIME_SEC
  142. elseif mainType == MAINTYPE_WEEK then
  143. return WEEK_TIME_SEC
  144. elseif mainType == MAINTYPE_MONTH then
  145. return ACT_TIME_SEC1
  146. end
  147. end
  148. -- 本期任务开始时间
  149. function getTaskStartTime(actStartTime, mainType)
  150. local time = getTaskTime(mainType)
  151. if not time then return end
  152. local sec = os.time() - actStartTime
  153. local cnt = math.floor(sec / time)
  154. return actStartTime + cnt * time
  155. end
  156. -- 获取任务剩余时间
  157. function getTaskLeftTime(actStartTime, mainType)
  158. local time = getTaskTime(mainType)
  159. if not time then return end
  160. local actLeftTime = getActLeftTime(actStartTime)
  161. return actLeftTime % time
  162. end
  163. -- 是否开放
  164. function isOpen(human)
  165. local openDay = CommonDB.getServerOpenDay()
  166. local absActConfig = AbsActExcel.absActivity[DG_ABS_ACT_ID]
  167. if openDay and openDay < absActConfig.openDay then
  168. return
  169. end
  170. if not getActStartTime(human) then
  171. return
  172. end
  173. return true
  174. end
  175. -- 是否红点
  176. function isRed(human)
  177. return isTaskRed(human) or isRewardRed(human)
  178. end
  179. -- 积分任务是否有红点
  180. function isTaskRed(human)
  181. for mainType = 1, MAINTYPE_CNT do
  182. if isTaskRedByType(human, mainType) then
  183. return true
  184. end
  185. end
  186. end
  187. -- 有奖励可领取
  188. function isRewardRed(human)
  189. local heroGrowUpDB = human.db.heroGrowUp
  190. if not heroGrowUpDB then
  191. return
  192. end
  193. local actStartTime,actEndTime,groupID = getActStartTime()
  194. local lvConfigs = getLvConfigs(groupID)
  195. if not actStartTime then return end
  196. if not lvConfigs then
  197. return
  198. end
  199. local maxLv = #lvConfigs
  200. for i = 1,heroGrowUpDB.lv do
  201. if i <= maxLv then
  202. if getGetReward(human,i) == 1 or not getGetExReward(human,i) == 1 then
  203. return true
  204. end
  205. else
  206. local lvDefine = lvConfigs[1]
  207. local flag = (i - maxLv) % lvDefine.lastNeedLv
  208. if flag == 0 then
  209. if getGetReward(human,i) == 1 or getGetExReward(human,i) == 1 then
  210. return true
  211. end
  212. end
  213. end
  214. end
  215. return
  216. end
  217. -- 根据分类判断是否有红点
  218. function isTaskRedByType(human, mainType)
  219. local list = getTaskIDList(mainType)
  220. local listLen = list and #list or 0
  221. for i = 1, listLen do
  222. local id = list[i]
  223. local cf = AbsActExcel.heroGrowUpTask[id]
  224. if getTaskState(human, id, cf) == TASK_STATE_CAN then
  225. return true
  226. end
  227. end
  228. end
  229. -- 根据类型获取任务id
  230. function getTaskIDList(mainType)
  231. return TASKTYPE_2_MAINTYPES and MAINTYPE_2_IDLIST[mainType]
  232. end
  233. -- 根据任务类型获取影响的分类
  234. -- [taskType] = {[mainType1] = maxValue, [mainType2][key] = maxValue2}
  235. function getMainTypesByTaskType(taskType)
  236. return TASKTYPE_2_MAINTYPES and TASKTYPE_2_MAINTYPES[taskType]
  237. end
  238. -- 最多x期
  239. local MAX_GROUPID = nil
  240. function getMaxGroupID()
  241. if not MAX_GROUPID then
  242. MAX_GROUPID = 0
  243. for _, cf in ipairs(AbsActExcel.heroGrowUpLv) do
  244. if cf.groupID > MAX_GROUPID then
  245. MAX_GROUPID = cf.groupID
  246. end
  247. end
  248. end
  249. return MAX_GROUPID
  250. end
  251. -- 根据第x期获取配置
  252. function getLvConfigs(groupID)
  253. return (groupID and GROUPID_2_LVCONFIGS) and GROUPID_2_LVCONFIGS[groupID]
  254. end
  255. -------------------------------------------- db -------------------------------------------------------
  256. -- 初始DB
  257. function initDB(human, actStartTime)
  258. local _,_,groupID = getActStartTime()
  259. local lvConfigs = getLvConfigs(groupID)
  260. if not lvConfigs then
  261. return
  262. end
  263. local heroGrowUpDB = {}
  264. heroGrowUpDB.time = actStartTime
  265. heroGrowUpDB.groupID = groupID
  266. heroGrowUpDB.lv = 0
  267. heroGrowUpDB.lvGet = {}
  268. heroGrowUpDB.lvExGet = {}
  269. heroGrowUpDB.jifen = 0
  270. heroGrowUpDB.isBuy = nil
  271. heroGrowUpDB.task = {}
  272. human.db.heroGrowUp = heroGrowUpDB
  273. end
  274. -- 初始任务DB
  275. function initTaskDB(human, actStartTime, mainType)
  276. local heroGrowUpDB = human.db.heroGrowUp
  277. local taskStartTime = getTaskStartTime(actStartTime, mainType)
  278. local taskList = {}
  279. taskList.time = taskStartTime
  280. taskList.records = {}
  281. taskList.gets = {}
  282. heroGrowUpDB.task[mainType] = taskList
  283. end
  284. -- 检查DB是否需要重置
  285. function checkDB(human, actStartTime,groupID)
  286. local heroGrowUpDB = human.db.heroGrowUp
  287. if not heroGrowUpDB then
  288. return
  289. end
  290. -- 新一期活动
  291. if heroGrowUpDB.groupID ~= groupID then
  292. heroGrowUpDB.groupID = groupID
  293. heroGrowUpDB.time = actStartTime
  294. heroGrowUpDB.lv = 0
  295. heroGrowUpDB.lvGet = {}
  296. heroGrowUpDB.lvExGet = {}
  297. heroGrowUpDB.jifen = 0
  298. heroGrowUpDB.isBuy = heroGrowUpDB.isBuy and 0 or nil
  299. heroGrowUpDB.task = {}
  300. return
  301. end
  302. -- 任务记录重置
  303. for mainType, taskList in pairs(heroGrowUpDB.task) do
  304. local taskStartTime = getTaskStartTime(actStartTime, mainType)
  305. if taskList.time ~= taskStartTime then
  306. heroGrowUpDB.task[mainType] = nil
  307. end
  308. end
  309. end
  310. -- 获取等级
  311. function getLv(human)
  312. local heroGrowUpDB = human.db.heroGrowUp
  313. if not heroGrowUpDB then
  314. return 0
  315. end
  316. return heroGrowUpDB.lv or 0
  317. end
  318. -- 获取当前积分
  319. function getJifen(human)
  320. local heroGrowUpDB = human.db.heroGrowUp
  321. if not heroGrowUpDB then
  322. return 0
  323. end
  324. return heroGrowUpDB.jifen or 0
  325. end
  326. -- 增加积分
  327. function addJifen(human, value)
  328. local actStartTime,actEndTime,groupID = getActStartTime()
  329. local lvConfigs = getLvConfigs(groupID)
  330. if not actStartTime then return end
  331. if not lvConfigs then
  332. return
  333. end
  334. local lvdefine = lvConfigs[1]
  335. checkDB(human, actStartTime,groupID)
  336. if not human.db.heroGrowUp then
  337. initDB(human, actStartTime)
  338. end
  339. local heroGrowUpDB = human.db.heroGrowUp
  340. heroGrowUpDB.jifen = (heroGrowUpDB.jifen or 0) + value
  341. local addLv = math.floor(heroGrowUpDB.jifen / lvdefine.needJifen)
  342. local oldLv = heroGrowUpDB.lv or 0
  343. local newLv = oldLv + addLv
  344. heroGrowUpDB.jifen = heroGrowUpDB.jifen - addLv * lvdefine.needJifen
  345. heroGrowUpDB.lv = newLv
  346. if oldLv ~= newLv then
  347. YunYingLogic.updateIcon(YYInfo[DG_ABS_ACT_ID], human)
  348. end
  349. end
  350. -- 是否购买王者礼包
  351. function isBuyKing(human)
  352. local heroGrowUpDB = human.db.heroGrowUp
  353. if not heroGrowUpDB then
  354. return
  355. end
  356. return heroGrowUpDB.isBuy
  357. end
  358. -- 设置购买
  359. function setBuyKing(human, actStartTime)
  360. if not human.db.heroGrowUp then
  361. initDB(human, actStartTime)
  362. end
  363. local heroGrowUpDB = human.db.heroGrowUp
  364. heroGrowUpDB.isBuy = 1
  365. end
  366. -- 设置领奖
  367. function setGetReward(human,lv)
  368. if not human.db.heroGrowUp then
  369. initDB(human, actStartTime)
  370. end
  371. local heroGrowUpDB = human.db.heroGrowUp
  372. heroGrowUpDB.lvGet = heroGrowUpDB.lvGet or {}
  373. heroGrowUpDB.lvGet[lv] = 2
  374. end
  375. function getGetReward(human,lv)
  376. local heroGrowUpDB = human.db.heroGrowUp
  377. if not heroGrowUpDB then
  378. return 0
  379. end
  380. if lv > heroGrowUpDB.lv then
  381. return 0
  382. end
  383. if not heroGrowUpDB.lvGet or not heroGrowUpDB.lvGet[lv] then
  384. return 1
  385. else
  386. return heroGrowUpDB.lvGet[lv]
  387. end
  388. end
  389. function getGetExReward(human,lv)
  390. local heroGrowUpDB = human.db.heroGrowUp
  391. if not heroGrowUpDB then
  392. return 0
  393. end
  394. if lv > heroGrowUpDB.lv then
  395. return 0
  396. end
  397. if not heroGrowUpDB.lvExGet or not heroGrowUpDB.lvExGet[lv] then
  398. return 1
  399. else
  400. return heroGrowUpDB.lvExGet[lv]
  401. end
  402. end
  403. -- 设置领奖
  404. function setGetExReward(human,lv)
  405. if not human.db.heroGrowUp then
  406. initDB(human, actStartTime)
  407. end
  408. local heroGrowUpDB = human.db.heroGrowUp
  409. heroGrowUpDB.lvExGet = heroGrowUpDB.lvExGet or {}
  410. heroGrowUpDB.lvExGet[lv] = 2
  411. end
  412. -- 是否领取
  413. function isGetTask(human, id, cf)
  414. local heroGrowUpDB = human.db.heroGrowUp
  415. if not heroGrowUpDB then
  416. return
  417. end
  418. local taskList = heroGrowUpDB.task[cf.mainType]
  419. if not taskList then return end
  420. if taskList.gets[id] then
  421. return true
  422. end
  423. end
  424. -- 设置已领取
  425. function setGetTask(human, actStartTime, id, cf)
  426. if not human.db.heroGrowUp then
  427. initDB(human, actStartTime)
  428. end
  429. local heroGrowUpDB = human.db.heroGrowUp
  430. if not heroGrowUpDB.task[cf.mainType] then
  431. initTaskDB(human, actStartTime, cf.mainType)
  432. end
  433. heroGrowUpDB.task[cf.mainType].gets[id] = 1
  434. end
  435. local function getValueByKey(human, mainType, taskType, key)
  436. if taskType == TASKTYPE1 then
  437. return 1
  438. end
  439. local heroGrowUpDB = human.db.heroGrowUp
  440. local taskList = heroGrowUpDB and heroGrowUpDB.task[mainType]
  441. if not taskList then
  442. return 0
  443. end
  444. local record = taskList.records[taskType]
  445. if not key then
  446. return record or 0
  447. end
  448. return record and record[key] or 0
  449. end
  450. -- 当前进度
  451. function getValue(human, cf)
  452. local key = cf.taskArgs[2]
  453. if type(key) == "table" then
  454. local list = getMainTypesByTaskType(cf.taskType)
  455. for k,v in pairs(list[cf.mainType]) do
  456. key = k
  457. break
  458. end
  459. end
  460. return getValueByKey(human, cf.mainType, cf.taskType, key)
  461. end
  462. -- 更新进度
  463. function updateValue(human, actStartTime, mainType, taskType, key, value)
  464. if not human.db.heroGrowUp then
  465. initDB(human, actStartTime)
  466. end
  467. local heroGrowUpDB = human.db.heroGrowUp
  468. if not heroGrowUpDB.task[mainType] then
  469. initTaskDB(human, actStartTime, mainType)
  470. end
  471. local taskList = heroGrowUpDB.task[mainType]
  472. if key then
  473. taskList.records[taskType] = taskList.records[taskType] or {}
  474. taskList.records[taskType][key] = value
  475. else
  476. taskList.records[taskType] = value
  477. end
  478. end
  479. -- 最大进度
  480. function getMaxValue(cf)
  481. return cf.taskArgs[1]
  482. end
  483. -- 获取任务状态
  484. function getTaskState(human, id, cf)
  485. if isGetTask(human, id, cf) then
  486. return TASK_STATE_HAD
  487. end
  488. local value = getValue(human, cf)
  489. local maxValue = getMaxValue(cf)
  490. if value >= maxValue then
  491. return TASK_STATE_CAN
  492. end
  493. return TASK_STATE_NONE
  494. end
  495. -- 获取任务名字
  496. function getTaskName(cf)
  497. if cf.taskType == TASKTYPE11 then
  498. local list = TASKTYPE_2_MAINTYPES[TASKTYPE11][cf.mainType]
  499. local heroID = cf.taskArgs[2]
  500. for k,v in pairs(list) do
  501. heroID = k
  502. break
  503. end
  504. local heroConfig = HeroDefine.getConfig(heroID)
  505. return Util.format(cf.name, heroConfig.name)
  506. end
  507. return cf.name
  508. end
  509. -- 获取任务描述
  510. function getTaskDesc(cf)
  511. if cf.taskType == TASKTYPE18 or
  512. cf.taskType == TASKTYPE4 or
  513. cf.taskType == TASKTYPE12 then
  514. return Util.format(cf.desc, cf.taskArgs[1], cf.taskArgs[2])
  515. elseif cf.taskType == TASKTYPE14 then
  516. return Util.format(cf.desc, cf.taskArgs[2])
  517. end
  518. return Util.format(cf.desc, cf.taskArgs[1])
  519. end
  520. -------------------------------------------- msg -------------------------------------------------------
  521. -- 封装基础信息
  522. function fontBaseNet(net, human, actStartTime, lvdefine)
  523. net.leftTime = getActLeftTime(actStartTime)
  524. net.lv = getLv(human)
  525. net.jifen = getJifen(human)
  526. net.maxJifen = lvdefine.needJifen
  527. local isBuy = isBuyKing(human)
  528. net.isBuyKing = isBuy == 1 and 1 or 0
  529. net.hasTaskRed = isRed(human) and 1 or 0
  530. end
  531. -- 封装任务信息
  532. function fontTaskNet(net, id, human)
  533. local cf = AbsActExcel.heroGrowUpTask[id]
  534. net.id = id
  535. net.taskName = getTaskName(cf)
  536. net.taskDesc = getTaskDesc(cf)
  537. net.maxValue = getMaxValue(cf)
  538. net.nowValue = math.min(getValue(human, cf), net.maxValue)
  539. Grid.makeItem(net.item, cf.items[1][1], cf.items[1][2])
  540. net.panelID = cf.panelID
  541. net.state = getTaskState(human, id, cf)
  542. end
  543. -- 积分任务界面
  544. function sendTaskQuery(human, mainType)
  545. local actStartTime,actEndTime, groupID = getActStartTime()
  546. local lvConfigs = getLvConfigs(groupID)
  547. if not actStartTime then
  548. return Broadcast.sendErr(human, Lang.YUNYING_ERR_TIME)
  549. end
  550. if not lvConfigs then
  551. return
  552. end
  553. local leftTime = getTaskLeftTime(actStartTime, mainType)
  554. if not leftTime then return end
  555. local lvdefine = lvConfigs[1]
  556. checkDB(human, actStartTime,groupID)
  557. local list = getTaskIDList(mainType)
  558. local msgRet = Msg.gc.GC_HERO_GROWUP_TASK_QUERY
  559. msgRet.endTime = actEndTime
  560. msgRet.startTime = actStartTime
  561. msgRet.leftTime = actEndTime - os.time()
  562. fontBaseNet(msgRet.data, human, actStartTime, lvdefine)
  563. msgRet.data.hasTaskRed = isTaskRed(human) and 1 or 0
  564. msgRet.mainType = mainType
  565. msgRet.taskLeftTime = leftTime
  566. msgRet.taskList[0] = list and #list or 0
  567. for i = 1, msgRet.taskList[0] do
  568. local id = list[i]
  569. fontTaskNet(msgRet.taskList[i], id, human)
  570. end
  571. msgRet.taskReds[0] = MAINTYPE_CNT
  572. for i = 1, msgRet.taskReds[0] do
  573. msgRet.taskReds[i] = isTaskRedByType(human, i) and 1 or 0
  574. end
  575. --Msg.trace(msgRet)
  576. Msg.send(msgRet, human.fd)
  577. end
  578. -- 领取任务奖励
  579. function getTaskItems(human, id)
  580. local actStartTime,actEndTime,groupID = getActStartTime()
  581. if not actStartTime then
  582. return Broadcast.sendErr(human, Lang.YUNYING_ERR_TIME)
  583. end
  584. local cf = AbsActExcel.heroGrowUpTask[id]
  585. if not cf then return end
  586. checkDB(human, actStartTime,groupID)
  587. local state = getTaskState(human, id, cf)
  588. if state == TASK_STATE_NONE then
  589. return Broadcast.sendErr(human, Lang.YUNYING_GET_ERR_CONDITION)
  590. end
  591. if state == TASK_STATE_HAD then
  592. return Broadcast.sendErr(human, Lang.YUNYING_GET_ERR_HADGET)
  593. end
  594. setGetTask(human, actStartTime, id, cf)
  595. for _, item in ipairs(cf.items) do
  596. local itemID = item[1]
  597. local itemCnt = item[2]
  598. BagLogic.addItem(human, itemID, itemCnt, "hero_growup_task")
  599. end
  600. BagLogic.sendItemGetList1(human, cf.items)
  601. sendTaskQuery(human, cf.mainType)
  602. YunYingLogic.updateIcon(YYInfo[DG_ABS_ACT_ID], human)
  603. end
  604. -- 查看王者礼包信息
  605. function sendKingQuery(human)
  606. if not SceneHandler.canCharge(human) then
  607. return
  608. end
  609. local actStartTime,actEndTime, groupID = getActStartTime()
  610. local lvConfigs = getLvConfigs(groupID)
  611. if not actStartTime then
  612. return Broadcast.sendErr(human, Lang.YUNYING_ERR_TIME)
  613. end
  614. if not lvConfigs then
  615. return
  616. end
  617. local lvdefine = lvConfigs[1].kingBuyItems
  618. checkDB(human, actStartTime,groupID)
  619. local isBuy = isBuyKing(human)
  620. if isBuy then
  621. lvdefine = lvConfigs[1].kingBuyItems2
  622. end
  623. local msgRet = Msg.gc.GC_HERO_GROWUP_KING_QUERY
  624. msgRet.items[0] = math.min(#lvdefine, #msgRet.items)
  625. for i = 1, msgRet.items[0] do
  626. local itemID = lvdefine[i][1]
  627. local itemCnt = lvdefine[i][2]
  628. Grid.makeItem(msgRet.items[i], itemID, itemCnt)
  629. end
  630. BuyLogic.fontBuyItem(human, msgRet.buyItem, lvConfigs[1].buyID)
  631. msgRet.isBuyKing = isBuy == 1 and 1 or 0
  632. --Msg.trace(msgRet)
  633. Msg.send(msgRet, human.fd)
  634. end
  635. -- 奖励界面查看
  636. function sendRewardQuery(human)
  637. local actStartTime,actEndTime, groupID = getActStartTime()
  638. local lvConfigs = getLvConfigs(groupID)
  639. if not actStartTime or not lvConfigs then
  640. return Broadcast.sendErr(human, Lang.YUNYING_ERR_TIME)
  641. end
  642. local lvdefine = lvConfigs[1]
  643. checkDB(human, actStartTime,groupID)
  644. local msgRet = Msg.gc.GC_HERO_GROWUP_REWARD_QUERY
  645. fontBaseNet(msgRet.data, human, actStartTime, lvdefine)
  646. msgRet.data.hasTaskRed = isRewardRed(human) and 1 or 0
  647. msgRet.rewardList[0] = #lvConfigs
  648. local nowLv = getLv(human)
  649. for lv = 1, msgRet.rewardList[0] do
  650. local net = msgRet.rewardList[lv]
  651. local cf = lvConfigs[lv]
  652. net.lv = lv
  653. net.items[0] = #cf.items
  654. net.state = 0
  655. net.stateEx = 0
  656. for i = 1, net.items[0] do
  657. local itemID = cf.items[i][1]
  658. local itemCnt = cf.items[i][2]
  659. Grid.makeItem(net.items[i], itemID, itemCnt)
  660. end
  661. if lv <= nowLv then
  662. net.state = getGetReward(human,lv)
  663. end
  664. net.itemsKing[0] = #cf.itemsKing
  665. for i = 1, net.itemsKing[0] do
  666. local itemID = cf.itemsKing[i][1]
  667. local itemCnt = cf.itemsKing[i][2]
  668. Grid.makeItem(net.itemsKing[i], itemID, itemCnt)
  669. end
  670. if lv <= nowLv then
  671. net.stateEx = getGetExReward(human,lv)
  672. end
  673. end
  674. local maxLv = #lvConfigs
  675. local exRewardNet = msgRet.exReward
  676. local nextLv = maxLv + lvdefine.lastNeedLv
  677. exRewardNet.needLv = lvdefine.lastNeedLv
  678. exRewardNet.items[0] = #lvdefine.lastItems
  679. exRewardNet.state = 0
  680. exRewardNet.stateEx = 0
  681. while true do
  682. if nextLv > nowLv then
  683. break
  684. end
  685. local nextState = getGetReward(human,nextLv)
  686. if not nextState or nextState == 1 then
  687. break
  688. end
  689. nextLv = nextLv + lvdefine.lastNeedLv
  690. end
  691. exRewardNet.lv = nextLv
  692. exRewardNet.state = getGetReward(human,nextLv)
  693. nextLv = maxLv + lvdefine.lastNeedLv
  694. while true do
  695. if nextLv > nowLv then
  696. break
  697. end
  698. local nextState = getGetExReward(human,nextLv)
  699. if not nextState or nextState == 1 then
  700. break
  701. end
  702. nextLv = nextLv + lvdefine.lastNeedLv
  703. end
  704. exRewardNet.exLv = nextLv
  705. exRewardNet.stateEx = getGetExReward(human,nextLv)
  706. local isBuy = isBuyKing(human)
  707. if isBuy ~= 1 then
  708. exRewardNet.stateEx = 0
  709. end
  710. for i = 1, exRewardNet.items[0] do
  711. local itemID = lvdefine.lastItems[i][1]
  712. local itemCnt = lvdefine.lastItems[i][2]
  713. Grid.makeItem(exRewardNet.items[i], itemID, itemCnt)
  714. end
  715. exRewardNet.itemsKing[0] = #lvdefine.lastItemsKing
  716. for i = 1, exRewardNet.itemsKing[0] do
  717. local itemID = lvdefine.lastItemsKing[i][1]
  718. local itemCnt = lvdefine.lastItemsKing[i][2]
  719. Grid.makeItem(exRewardNet.itemsKing[i], itemID, itemCnt)
  720. end
  721. --Msg.trace(msgRet)
  722. Msg.send(msgRet, human.fd)
  723. end
  724. -------------------------------------------- 回调 -------------------------------------------------------
  725. -- 升级回调
  726. function getLvReward(human, lv)
  727. local actStartTime,actEndTime, groupID = getActStartTime()
  728. if not groupID then
  729. return
  730. end
  731. local nowLv = getLv(human)
  732. if lv > nowLv then
  733. return
  734. end
  735. local normalGet = getGetReward(human,lv)
  736. local exGet = getGetExReward(human,lv)
  737. local lvConfigs = getLvConfigs(groupID)
  738. if not lvConfigs then
  739. return
  740. end
  741. local lvdefine = lvConfigs[1]
  742. local list = {}
  743. local maxLv = #lvConfigs
  744. local isBuy = isBuyKing(human)
  745. local cf = lvConfigs[lv]
  746. local items = cf and cf.items
  747. local itemsKing = cf and cf.itemsKing
  748. if (not cf) and (lv - maxLv) % lvdefine.lastNeedLv == 0 then
  749. items = lvdefine.lastItems
  750. itemsKing = lvdefine.lastItemsKing
  751. end
  752. if items and normalGet ~= 2 then
  753. for _, item in ipairs(items) do
  754. local itemID = item[1]
  755. local itemCnt = item[2]
  756. list[itemID] = (list[itemID] or 0) + itemCnt
  757. end
  758. end
  759. if itemsKing and isBuy == 1 and exGet ~= 2 then
  760. for _, item in ipairs(itemsKing) do
  761. local itemID = item[1]
  762. local itemCnt = item[2]
  763. list[itemID] = (list[itemID] or 0) + itemCnt
  764. end
  765. end
  766. if not next(list) then return end
  767. setGetReward(human,lv)
  768. if isBuy == 1 then
  769. setGetExReward(human,lv)
  770. end
  771. YunYingLogic.updateIcon(YYInfo[DG_ABS_ACT_ID], human)
  772. local msgRet = Msg.gc.GC_HERO_GROWUP_LVUP
  773. msgRet.lv = nowLv
  774. msgRet.items[0] = 0
  775. for itemID, itemCnt in pairs(list) do
  776. BagLogic.addItem(human, itemID, itemCnt, "hero_growup")
  777. if msgRet.items[0] < #msgRet.items then
  778. msgRet.items[0] = msgRet.items[0] + 1
  779. Grid.makeItem(msgRet.items[msgRet.items[0]], itemID, itemCnt)
  780. end
  781. end
  782. BagLogic.sendItemGetList2(human, list)
  783. msgRet.isBuyKing = isBuy == 1 and 1 or 0
  784. --Msg.trace(msgRet)
  785. Msg.send(msgRet, human.fd)
  786. end
  787. -- 购买王者礼包ii
  788. function buyKing(human)
  789. local actStartTime,actEndTime, groupID = getActStartTime()
  790. local lvConfigs = getLvConfigs(groupID)
  791. if not actStartTime then return end
  792. if not lvConfigs then
  793. return
  794. end
  795. local lvdefine = lvConfigs[1]
  796. checkDB(human, actStartTime,groupID)
  797. local isBuy = isBuyKing(human)
  798. if isBuy == 1 then return end
  799. setBuyKing(human, actStartTime)
  800. -- 计算可以给的东西
  801. -- local maxLv = #lvConfigs
  802. -- local nowLv = getLv(human)
  803. -- local list = {}
  804. -- for lv = 1, nowLv do
  805. -- local cf = lvConfigs[lv]
  806. -- local itemsKing = cf and cf.itemsKing
  807. -- if (not cf) and (lv - maxLv) % lvdefine.lastNeedLv then
  808. -- itemsKing = lvdefine.lastItemsKing
  809. -- end
  810. -- if itemsKing then
  811. -- for _, item in ipairs(itemsKing) do
  812. -- local itemID = item[1]
  813. -- local itemCnt = item[2]
  814. -- list[itemID] = (list[itemID] or 0) + itemCnt
  815. -- end
  816. -- end
  817. -- end
  818. local list = {}
  819. local config = lvdefine.kingBuyItems
  820. if isBuy then
  821. config = lvdefine.kingBuyItems2
  822. end
  823. -- 购买王者后直接赠送的东西
  824. for _, item in ipairs(config) do
  825. local itemID = item[1]
  826. local itemCnt = item[2]
  827. list[itemID] = (list[itemID] or 0) + itemCnt
  828. end
  829. -- 给东西
  830. for itemID, itemCnt in pairs(list) do
  831. BagLogic.addItem(human, itemID, itemCnt, "hero_growup")
  832. end
  833. BagLogic.sendItemGetList2(human, list)
  834. YunYingLogic.updateIcon(YYInfo[DG_ABS_ACT_ID], human)
  835. local msgRet = Msg.gc.GC_HERO_GROWUP_BUY_OK
  836. fontBaseNet(msgRet.data, human, actStartTime, lvdefine)
  837. Msg.send(msgRet, human.fd)
  838. sendRewardQuery(human)
  839. end
  840. -- 子回调
  841. local function doCallback(human, actStartTime, mainType, taskType, maxValue, key, value)
  842. local oldValue = getValueByKey(human, mainType, taskType, key)
  843. if oldValue >= maxValue then
  844. return
  845. end
  846. local newValue = oldValue
  847. -- 任务类型11 指定英雄 竞技场胜利指定次数
  848. if taskType == TASKTYPE11 then
  849. local isFind = nil
  850. for _, obj in pairs(value.objList) do
  851. if obj.side == CombatDefine.ATTACK_SIDE and
  852. obj.id == key then
  853. isFind = true
  854. break
  855. end
  856. end
  857. if not isFind then return end
  858. newValue = oldValue + 1
  859. elseif taskType == TASKTYPE12 then
  860. if key ~= value then
  861. return
  862. end
  863. newValue = oldValue + 1
  864. elseif taskType == TASKTYPE14 then
  865. if value > key then
  866. return
  867. end
  868. newValue = oldValue + 1
  869. else
  870. newValue = math.min(oldValue + value, maxValue)
  871. end
  872. updateValue(human, actStartTime, mainType, taskType, key, newValue)
  873. return true
  874. end
  875. -- 任务回调
  876. function onCallback(human, taskType, value)
  877. local actStartTime,actEndTime,groupID = getActStartTime()
  878. if not actStartTime then return end
  879. local mainTypes = getMainTypesByTaskType(taskType)
  880. if not mainTypes then return end
  881. checkDB(human, actStartTime,groupID)
  882. local isChange = nil
  883. for mainType, mainValue in pairs(mainTypes) do
  884. local mainValueType = type(mainValue)
  885. if mainValueType == "number" then
  886. if doCallback(human, actStartTime, mainType, taskType, mainValue, nil, value) then
  887. isChange = true
  888. end
  889. elseif mainValueType == "table" then
  890. for key, maxValue in pairs(mainValue) do
  891. if doCallback(human, actStartTime, mainType, taskType, maxValue, key, value) then
  892. isChange = true
  893. end
  894. end
  895. end
  896. end
  897. if isChange then
  898. YunYingLogic.updateIcon(YYInfo[DG_ABS_ACT_ID], human)
  899. Msg.send(Msg.gc.GC_HERO_GROWUP_TASK_REFRESH, human.fd)
  900. end
  901. return isChange
  902. end
  903. -- 任务回调 uuid
  904. local FakeHuman = {}
  905. function onCallbackByUuid(uuid, taskType, value)
  906. local db, online = RoleDBLogic.getDb(uuid)
  907. if not db then return end
  908. FakeHuman.db = db
  909. if onCallback(FakeHuman, taskType, value) and not online then
  910. RoleDBLogic.saveRole(db)
  911. end
  912. end
  913. function buyJifen(human,itemID,cnt)
  914. local actStartTime,actEndTime,groupID = getActStartTime()
  915. if not actStartTime then return end
  916. local now = os.time()
  917. if actEndTime - now > 3*86400 then
  918. return
  919. end
  920. checkDB(human, actStartTime,groupID)
  921. local config = ItemExcel.commonBuy[itemID]
  922. if not config then
  923. return
  924. end
  925. local price = config.price[2]*cnt
  926. if not ObjHuman.checkRMB(human,price) then
  927. return
  928. end
  929. ObjHuman.decZuanshi(human, - price, "hero_growup")
  930. addJifen(human, 1000*cnt)
  931. local msgRet = Msg.gc.GC_HERO_GROWUP_BUY_JIFEN
  932. msgRet.lv = human.db.heroGrowUp.lv or 0
  933. msgRet.jifen = human.db.heroGrowUp.jifen or 0
  934. msgRet.maxJifen = AbsActExcel.heroGrowUpLv[1].needJifen
  935. Msg.send(msgRet,human.fd)
  936. end
  937. -- 活动循环,开启与结束
  938. function actLoop()
  939. local workManStartTime,workManEndTime,groupID = getActStartTime()
  940. local workMan = CommonDB.getWorkMan()
  941. -- 活动未开,且commonDB活动开,则关闭活动
  942. if not workManStartTime and workMan.state then
  943. CommonDB.setWorkManState()
  944. return
  945. end
  946. -- 活动开,且commonDB活动未开,则开启活动
  947. -- 活动id不符
  948. if (workManStartTime and not workMan.state) or groupID ~= workMan.groupID then
  949. CommonDB.setWorkManState(true)
  950. CommonDB.setWorkManGroup(groupID)
  951. CommonDB.setWorkManTs(workManStartTime)
  952. --重置任务
  953. TASKTYPE_2_MAINTYPES = {}
  954. MAINTYPE_2_IDLIST = {}
  955. -- 设置新任务
  956. for id, cf in pairs(AbsActExcel.heroGrowUpTask) do
  957. if not TASKTYPE_2_MAINTYPES[cf.taskType] then
  958. TASKTYPE_2_MAINTYPES[cf.taskType] = {}
  959. end
  960. if not MAINTYPE_2_IDLIST[cf.mainType] then
  961. MAINTYPE_2_IDLIST[cf.mainType] = {}
  962. end
  963. local len = #MAINTYPE_2_IDLIST[cf.mainType]
  964. MAINTYPE_2_IDLIST[cf.mainType][len + 1] = id
  965. local list = TASKTYPE_2_MAINTYPES[cf.taskType]
  966. local value = cf.taskArgs[1]
  967. local key = cf.taskArgs[2]
  968. if type(cf.taskArgs[2]) == "table" then
  969. local lenth = #cf.taskArgs[2]
  970. local randomPos = math.random(1,lenth)
  971. key = cf.taskArgs[2][randomPos]
  972. end
  973. if key then
  974. list[cf.mainType] = list[cf.mainType] or {}
  975. list[cf.mainType][key] = math.max(list[cf.mainType][key] or 0, value)
  976. else
  977. list[cf.mainType] = math.max(list[cf.mainType] or 0, value)
  978. end
  979. end
  980. GROUPID_2_LVCONFIGS = {}
  981. for _, cf in ipairs(AbsActExcel.heroGrowUpLv) do
  982. if not GROUPID_2_LVCONFIGS[cf.groupID] then
  983. GROUPID_2_LVCONFIGS[cf.groupID] = {}
  984. end
  985. GROUPID_2_LVCONFIGS[cf.groupID][cf.lv] = cf
  986. end
  987. return
  988. end
  989. end