HeroGrowUp.lua 31 KB

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