HeroGrowUp.lua 31 KB

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