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. local SERVER_TIME_ZONE = 8 -- 服务器所在区服时区 北京东八区
  42. -- 任务分类
  43. MAINTYPE_DAY = 1 -- 每日
  44. MAINTYPE_WEEK = 2 -- 每周
  45. MAINTYPE_MONTH = 3 -- 每期
  46. MAINTYPE_CNT = 3
  47. -- 任务状态
  48. TASK_STATE_NONE = 0 -- 不可领
  49. TASK_STATE_CAN = 1 -- 可领
  50. TASK_STATE_HAD = 2 -- 已领
  51. -- 任务类型
  52. TASKTYPE1 = 1 -- o登录游戏
  53. TASKTYPE2 = 2 -- o天命召唤
  54. TASKTYPE3 = 3 -- o占卜合成
  55. TASKTYPE4 = 4 -- o消耗x金币
  56. TASKTYPE5 = 5 -- o消耗x钻石
  57. TASKTYPE6 = 6 -- o战报点赞X次
  58. TASKTYPE7 = 7 -- o皇冠联赛战场胜利X次
  59. TASKTYPE8 = 8 -- o合成X次任意符文
  60. TASKTYPE9 = 9 -- o冰龙巢穴
  61. TASKTYPE10 = 10 -- o随机商店购买道具
  62. TASKTYPE11 = 11 -- o上阵指定英雄XX,皇冠联赛战场获得X场胜利
  63. TASKTYPE12 = 12 -- o获取X个Y星英雄
  64. TASKTYPE13 = 13 -- o挑战战神殿
  65. TASKTYPE14 = 14 -- o王者争霸32强
  66. TASKTYPE15 = 15 -- o完成X次悬赏任务
  67. TASKTYPE16 = 16 -- o圣树试炼胜利X次
  68. TASKTYPE17 = 17 -- o接取X次红色悬赏任务
  69. TASKTYPE18 = 18 -- o消耗X英雄经验
  70. TASKTYPE19 = 19 -- o洗练X次任意装备
  71. TASKTYPE20 = 20 -- o遗迹探宝,击败x个守卫
  72. TASKTYPE21 = 21 -- o分解装备
  73. DG_ABS_ACT_ID = 8001
  74. HGU_AFTER_START = true
  75. function initAfterStart()
  76. HGU_AFTER_START = false
  77. end
  78. function initAfterHot()
  79. if HGU_AFTER_START then
  80. return
  81. end
  82. local workManStartTime,workManEndTime,groupID = getActStartTime()
  83. -- 活动未开
  84. if not workManStartTime then
  85. return
  86. end
  87. --重置任务
  88. TASKTYPE_2_MAINTYPES = {}
  89. MAINTYPE_2_IDLIST = {}
  90. -- 设置新任务
  91. for id, cf in pairs(AbsActExcel.heroGrowUpTask) do
  92. if not TASKTYPE_2_MAINTYPES[cf.taskType] then
  93. TASKTYPE_2_MAINTYPES[cf.taskType] = {}
  94. end
  95. if not MAINTYPE_2_IDLIST[cf.mainType] then
  96. MAINTYPE_2_IDLIST[cf.mainType] = {}
  97. end
  98. local len = #MAINTYPE_2_IDLIST[cf.mainType]
  99. MAINTYPE_2_IDLIST[cf.mainType][len + 1] = id
  100. local list = TASKTYPE_2_MAINTYPES[cf.taskType]
  101. local value = cf.taskArgs[1]
  102. local key = cf.taskArgs[2]
  103. if type(cf.taskArgs[2]) == "table" then
  104. local lenth = #cf.taskArgs[2]
  105. local randomPos = math.random(1,lenth)
  106. key = cf.taskArgs[2][randomPos]
  107. end
  108. if key then
  109. list[cf.mainType] = list[cf.mainType] or {}
  110. list[cf.mainType][key] = math.max(list[cf.mainType][key] or 0, value)
  111. else
  112. list[cf.mainType] = math.max(list[cf.mainType] or 0, value)
  113. end
  114. end
  115. GROUPID_2_LVCONFIGS = {}
  116. for _, cf in ipairs(AbsActExcel.heroGrowUpLv) do
  117. if not GROUPID_2_LVCONFIGS[cf.groupID] then
  118. GROUPID_2_LVCONFIGS[cf.groupID] = {}
  119. end
  120. GROUPID_2_LVCONFIGS[cf.groupID][cf.lv] = cf
  121. end
  122. end
  123. -- 本期活动开始时间 --@warning actID不存在
  124. function getActStartTime()
  125. --local id = AbsActLogic.getIDByActID(human, DG_ABS_ACT_ID)
  126. --[[if absActConfig.actId and absActConfig.actId ~= 0 then
  127. return absActConfig.startDate,absActConfig.endDate,absActConfig.actId
  128. end]]
  129. local absActConfig = AbsActExcel.absActivity[DG_ABS_ACT_ID]
  130. assert(#absActConfig.turns ~= 0,"invalid config error")
  131. return absActConfig.startDate,absActConfig.endDate,absActConfig.turns[1] -- @error 目前默认第一期
  132. end
  133. local function transBeiJingTime(d)
  134. return os.time(d) - SERVER_TIME_ZONE * 3600
  135. end
  136. -- 活动剩余时间
  137. function getActLeftTime(dateCfg)
  138. local finishTime = transBeiJingTime(dateCfg)
  139. local now = os.time()
  140. return finishTime > now and finishTime - now or 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(actFinishTime, mainType)
  162. local time = getTaskTime(mainType)
  163. if not time then return end
  164. local actLeftTime = getActLeftTime(actFinishTime)
  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(human) then
  175. return
  176. end
  177. return true
  178. end
  179. -- 是否红点
  180. function isRed(human)
  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 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 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. if not human.db.heroGrowUp then
  373. initDB(human, actStartTime)
  374. end
  375. local heroGrowUpDB = human.db.heroGrowUp
  376. heroGrowUpDB.lvGet = heroGrowUpDB.lvGet or {}
  377. heroGrowUpDB.lvGet[lv] = 2
  378. end
  379. function getGetReward(human,lv)
  380. local heroGrowUpDB = human.db.heroGrowUp
  381. if not heroGrowUpDB then
  382. return 0
  383. end
  384. if lv > heroGrowUpDB.lv then
  385. return 0
  386. end
  387. if not heroGrowUpDB.lvGet or not heroGrowUpDB.lvGet[lv] then
  388. return 1
  389. else
  390. return heroGrowUpDB.lvGet[lv]
  391. end
  392. end
  393. function getGetExReward(human,lv)
  394. local heroGrowUpDB = human.db.heroGrowUp
  395. if not heroGrowUpDB then
  396. return 0
  397. end
  398. if lv > heroGrowUpDB.lv then
  399. return 0
  400. end
  401. if not heroGrowUpDB.lvExGet or not heroGrowUpDB.lvExGet[lv] then
  402. return 1
  403. else
  404. return heroGrowUpDB.lvExGet[lv]
  405. end
  406. end
  407. -- 设置领奖
  408. function setGetExReward(human,lv)
  409. if not human.db.heroGrowUp then
  410. initDB(human, actStartTime)
  411. end
  412. local heroGrowUpDB = human.db.heroGrowUp
  413. heroGrowUpDB.lvExGet = heroGrowUpDB.lvExGet or {}
  414. heroGrowUpDB.lvExGet[lv] = 2
  415. end
  416. -- 是否领取
  417. function isGetTask(human, id, cf)
  418. local heroGrowUpDB = human.db.heroGrowUp
  419. if not heroGrowUpDB then
  420. return
  421. end
  422. local taskList = heroGrowUpDB.task[cf.mainType]
  423. if not taskList then return end
  424. if taskList.gets[id] then
  425. return true
  426. end
  427. end
  428. -- 设置已领取
  429. function setGetTask(human, actStartTime, id, cf)
  430. if not human.db.heroGrowUp then
  431. initDB(human, actStartTime)
  432. end
  433. local heroGrowUpDB = human.db.heroGrowUp
  434. if not heroGrowUpDB.task[cf.mainType] then
  435. initTaskDB(human, actStartTime, cf.mainType)
  436. end
  437. heroGrowUpDB.task[cf.mainType].gets[id] = 1
  438. end
  439. local function getValueByKey(human, mainType, taskType, key)
  440. if taskType == TASKTYPE1 then
  441. return 1
  442. end
  443. local heroGrowUpDB = human.db.heroGrowUp
  444. local taskList = heroGrowUpDB and heroGrowUpDB.task[mainType]
  445. if not taskList then
  446. return 0
  447. end
  448. local record = taskList.records[taskType]
  449. if not key then
  450. return record or 0
  451. end
  452. return record and record[key] or 0
  453. end
  454. -- 当前进度
  455. function getValue(human, cf)
  456. local key = cf.taskArgs[2]
  457. if type(key) == "table" then
  458. local list = getMainTypesByTaskType(cf.taskType)
  459. for k,v in pairs(list[cf.mainType]) do
  460. key = k
  461. break
  462. end
  463. end
  464. return getValueByKey(human, cf.mainType, cf.taskType, key)
  465. end
  466. -- 更新进度
  467. function updateValue(human, actStartTime, mainType, taskType, key, value)
  468. if not human.db.heroGrowUp then
  469. initDB(human, actStartTime)
  470. end
  471. local heroGrowUpDB = human.db.heroGrowUp
  472. if not heroGrowUpDB.task[mainType] then
  473. initTaskDB(human, actStartTime, mainType)
  474. end
  475. local taskList = heroGrowUpDB.task[mainType]
  476. if key then
  477. taskList.records[taskType] = taskList.records[taskType] or {}
  478. taskList.records[taskType][key] = value
  479. else
  480. taskList.records[taskType] = value
  481. end
  482. end
  483. -- 最大进度
  484. function getMaxValue(cf)
  485. return cf.taskArgs[1]
  486. end
  487. -- 获取任务状态
  488. function getTaskState(human, id, cf)
  489. if isGetTask(human, id, cf) then
  490. return TASK_STATE_HAD
  491. end
  492. local value = getValue(human, cf)
  493. local maxValue = getMaxValue(cf)
  494. if value >= maxValue then
  495. return TASK_STATE_CAN
  496. end
  497. return TASK_STATE_NONE
  498. end
  499. -- 获取任务名字
  500. function getTaskName(cf)
  501. if cf.taskType == TASKTYPE11 then
  502. local list = TASKTYPE_2_MAINTYPES[TASKTYPE11][cf.mainType]
  503. local heroID = cf.taskArgs[2]
  504. for k,v in pairs(list) do
  505. heroID = k
  506. break
  507. end
  508. local heroConfig = HeroDefine.getConfig(heroID)
  509. return Util.format(cf.name, heroConfig.name)
  510. end
  511. return cf.name
  512. end
  513. -- 获取任务描述
  514. function getTaskDesc(cf)
  515. if cf.taskType == TASKTYPE18 or
  516. cf.taskType == TASKTYPE4 or
  517. cf.taskType == TASKTYPE12 then
  518. return Util.format(cf.desc, cf.taskArgs[1], cf.taskArgs[2])
  519. elseif cf.taskType == TASKTYPE14 then
  520. return Util.format(cf.desc, cf.taskArgs[2])
  521. end
  522. return Util.format(cf.desc, cf.taskArgs[1])
  523. end
  524. -------------------------------------------- msg -------------------------------------------------------
  525. -- 封装基础信息
  526. function fontBaseNet(net, human, actStartTime, lvdefine)
  527. net.leftTime = getActLeftTime(actStartTime)
  528. net.lv = getLv(human)
  529. net.jifen = getJifen(human)
  530. net.maxJifen = lvdefine.needJifen
  531. local isBuy = isBuyKing(human)
  532. net.isBuyKing = isBuy == 1 and 1 or 0
  533. net.hasTaskRed = isRed(human) and 1 or 0
  534. end
  535. -- 封装任务信息
  536. function fontTaskNet(net, id, human)
  537. local cf = AbsActExcel.heroGrowUpTask[id]
  538. net.id = id
  539. net.taskName = getTaskName(cf)
  540. net.taskDesc = getTaskDesc(cf)
  541. net.maxValue = getMaxValue(cf)
  542. net.nowValue = math.min(getValue(human, cf), net.maxValue)
  543. Grid.makeItem(net.item, cf.items[1][1], cf.items[1][2])
  544. net.panelID = cf.panelID
  545. net.state = getTaskState(human, id, cf)
  546. end
  547. -- 积分任务界面
  548. function sendTaskQuery(human, mainType)
  549. local actStartTime,actEndTime, groupID = getActStartTime()
  550. local lvConfigs = getLvConfigs(groupID)
  551. if not actStartTime then
  552. return Broadcast.sendErr(human, Lang.YUNYING_ERR_TIME)
  553. end
  554. if not lvConfigs then
  555. return
  556. end
  557. local leftTime = getTaskLeftTime(actStartTime, mainType)
  558. if not leftTime then return end
  559. local lvdefine = lvConfigs[1]
  560. checkDB(human, actStartTime,groupID)
  561. local list = getTaskIDList(mainType)
  562. local msgRet = Msg.gc.GC_HERO_GROWUP_TASK_QUERY
  563. msgRet.endTime = actEndTime
  564. msgRet.startTime = actStartTime
  565. msgRet.leftTime = actEndTime - os.time()
  566. fontBaseNet(msgRet.data, human, actStartTime, lvdefine)
  567. msgRet.data.hasTaskRed = isTaskRed(human) and 1 or 0
  568. msgRet.mainType = mainType
  569. msgRet.taskLeftTime = leftTime
  570. msgRet.taskList[0] = list and #list or 0
  571. for i = 1, msgRet.taskList[0] do
  572. local id = list[i]
  573. fontTaskNet(msgRet.taskList[i], id, human)
  574. end
  575. msgRet.taskReds[0] = MAINTYPE_CNT
  576. for i = 1, msgRet.taskReds[0] do
  577. msgRet.taskReds[i] = isTaskRedByType(human, i) and 1 or 0
  578. end
  579. --Msg.trace(msgRet)
  580. Msg.send(msgRet, human.fd)
  581. end
  582. -- 领取任务奖励
  583. function getTaskItems(human, id)
  584. local actStartTime,actEndTime,groupID = getActStartTime()
  585. if not actStartTime then
  586. return Broadcast.sendErr(human, Lang.YUNYING_ERR_TIME)
  587. end
  588. local cf = AbsActExcel.heroGrowUpTask[id]
  589. if not cf then return end
  590. checkDB(human, actStartTime,groupID)
  591. local state = getTaskState(human, id, cf)
  592. if state == TASK_STATE_NONE then
  593. return Broadcast.sendErr(human, Lang.YUNYING_GET_ERR_CONDITION)
  594. end
  595. if state == TASK_STATE_HAD then
  596. return Broadcast.sendErr(human, Lang.YUNYING_GET_ERR_HADGET)
  597. end
  598. setGetTask(human, actStartTime, id, cf)
  599. for _, item in ipairs(cf.items) do
  600. local itemID = item[1]
  601. local itemCnt = item[2]
  602. BagLogic.addItem(human, itemID, itemCnt, "hero_growup_task")
  603. end
  604. BagLogic.sendItemGetList1(human, cf.items)
  605. sendTaskQuery(human, cf.mainType)
  606. YunYingLogic.updateIcon(YYInfo[DG_ABS_ACT_ID], human)
  607. end
  608. -- 查看王者礼包信息
  609. function sendKingQuery(human)
  610. if not SceneHandler.canCharge(human) then
  611. return
  612. end
  613. local actStartTime,actEndTime, groupID = getActStartTime()
  614. local lvConfigs = getLvConfigs(groupID)
  615. if not actStartTime then
  616. return Broadcast.sendErr(human, Lang.YUNYING_ERR_TIME)
  617. end
  618. if not lvConfigs then
  619. return
  620. end
  621. local lvdefine = lvConfigs[1].kingBuyItems
  622. checkDB(human, actStartTime,groupID)
  623. local isBuy = isBuyKing(human)
  624. if isBuy then
  625. lvdefine = lvConfigs[1].kingBuyItems2
  626. end
  627. local msgRet = Msg.gc.GC_HERO_GROWUP_KING_QUERY
  628. msgRet.items[0] = math.min(#lvdefine, #msgRet.items)
  629. for i = 1, msgRet.items[0] do
  630. local itemID = lvdefine[i][1]
  631. local itemCnt = lvdefine[i][2]
  632. Grid.makeItem(msgRet.items[i], itemID, itemCnt)
  633. end
  634. BuyLogic.fontBuyItem(human, msgRet.buyItem, lvConfigs[1].buyID)
  635. msgRet.isBuyKing = isBuy == 1 and 1 or 0
  636. --Msg.trace(msgRet)
  637. Msg.send(msgRet, human.fd)
  638. end
  639. -- 奖励界面查看
  640. function sendRewardQuery(human)
  641. local actStartTime,actEndTime, groupID = getActStartTime()
  642. local lvConfigs = getLvConfigs(groupID)
  643. if not actStartTime or not lvConfigs then
  644. return Broadcast.sendErr(human, Lang.YUNYING_ERR_TIME)
  645. end
  646. local lvdefine = lvConfigs[1]
  647. checkDB(human, actStartTime,groupID)
  648. local msgRet = Msg.gc.GC_HERO_GROWUP_REWARD_QUERY
  649. fontBaseNet(msgRet.data, human, actStartTime, lvdefine)
  650. msgRet.data.hasTaskRed = isRewardRed(human) and 1 or 0
  651. msgRet.rewardList[0] = #lvConfigs
  652. local nowLv = getLv(human)
  653. for lv = 1, msgRet.rewardList[0] do
  654. local net = msgRet.rewardList[lv]
  655. local cf = lvConfigs[lv]
  656. net.lv = lv
  657. net.items[0] = #cf.items
  658. net.state = 0
  659. net.stateEx = 0
  660. for i = 1, net.items[0] do
  661. local itemID = cf.items[i][1]
  662. local itemCnt = cf.items[i][2]
  663. Grid.makeItem(net.items[i], itemID, itemCnt)
  664. end
  665. if lv <= nowLv then
  666. net.state = getGetReward(human,lv)
  667. end
  668. net.itemsKing[0] = #cf.itemsKing
  669. for i = 1, net.itemsKing[0] do
  670. local itemID = cf.itemsKing[i][1]
  671. local itemCnt = cf.itemsKing[i][2]
  672. Grid.makeItem(net.itemsKing[i], itemID, itemCnt)
  673. end
  674. if lv <= nowLv then
  675. net.stateEx = getGetExReward(human,lv)
  676. end
  677. end
  678. local maxLv = #lvConfigs
  679. local exRewardNet = msgRet.exReward
  680. local nextLv = maxLv + lvdefine.lastNeedLv
  681. exRewardNet.needLv = lvdefine.lastNeedLv
  682. exRewardNet.items[0] = #lvdefine.lastItems
  683. exRewardNet.state = 0
  684. exRewardNet.stateEx = 0
  685. while true do
  686. if nextLv > nowLv then
  687. break
  688. end
  689. local nextState = getGetReward(human,nextLv)
  690. if not nextState or nextState == 1 then
  691. break
  692. end
  693. nextLv = nextLv + lvdefine.lastNeedLv
  694. end
  695. exRewardNet.lv = nextLv
  696. exRewardNet.state = getGetReward(human,nextLv)
  697. nextLv = maxLv + lvdefine.lastNeedLv
  698. while true do
  699. if nextLv > nowLv then
  700. break
  701. end
  702. local nextState = getGetExReward(human,nextLv)
  703. if not nextState or nextState == 1 then
  704. break
  705. end
  706. nextLv = nextLv + lvdefine.lastNeedLv
  707. end
  708. exRewardNet.exLv = nextLv
  709. exRewardNet.stateEx = getGetExReward(human,nextLv)
  710. local isBuy = isBuyKing(human)
  711. if isBuy ~= 1 then
  712. exRewardNet.stateEx = 0
  713. end
  714. for i = 1, exRewardNet.items[0] do
  715. local itemID = lvdefine.lastItems[i][1]
  716. local itemCnt = lvdefine.lastItems[i][2]
  717. Grid.makeItem(exRewardNet.items[i], itemID, itemCnt)
  718. end
  719. exRewardNet.itemsKing[0] = #lvdefine.lastItemsKing
  720. for i = 1, exRewardNet.itemsKing[0] do
  721. local itemID = lvdefine.lastItemsKing[i][1]
  722. local itemCnt = lvdefine.lastItemsKing[i][2]
  723. Grid.makeItem(exRewardNet.itemsKing[i], itemID, itemCnt)
  724. end
  725. --Msg.trace(msgRet)
  726. Msg.send(msgRet, human.fd)
  727. end
  728. -------------------------------------------- 回调 -------------------------------------------------------
  729. -- 升级回调
  730. function getLvReward(human, lv)
  731. local actStartTime,actEndTime, groupID = getActStartTime()
  732. if not groupID then
  733. return
  734. end
  735. local nowLv = getLv(human)
  736. if lv > nowLv then
  737. return
  738. end
  739. local normalGet = getGetReward(human,lv)
  740. local exGet = getGetExReward(human,lv)
  741. local lvConfigs = getLvConfigs(groupID)
  742. if not lvConfigs then
  743. return
  744. end
  745. local lvdefine = lvConfigs[1]
  746. local list = {}
  747. local maxLv = #lvConfigs
  748. local isBuy = isBuyKing(human)
  749. local cf = lvConfigs[lv]
  750. local items = cf and cf.items
  751. local itemsKing = cf and cf.itemsKing
  752. if (not cf) and (lv - maxLv) % lvdefine.lastNeedLv == 0 then
  753. items = lvdefine.lastItems
  754. itemsKing = lvdefine.lastItemsKing
  755. end
  756. if items and normalGet ~= 2 then
  757. for _, item in ipairs(items) do
  758. local itemID = item[1]
  759. local itemCnt = item[2]
  760. list[itemID] = (list[itemID] or 0) + itemCnt
  761. end
  762. end
  763. if itemsKing and isBuy == 1 and exGet ~= 2 then
  764. for _, item in ipairs(itemsKing) do
  765. local itemID = item[1]
  766. local itemCnt = item[2]
  767. list[itemID] = (list[itemID] or 0) + itemCnt
  768. end
  769. end
  770. if not next(list) then return end
  771. setGetReward(human,lv)
  772. if isBuy == 1 then
  773. setGetExReward(human,lv)
  774. end
  775. YunYingLogic.updateIcon(YYInfo[DG_ABS_ACT_ID], human)
  776. local msgRet = Msg.gc.GC_HERO_GROWUP_LVUP
  777. msgRet.lv = nowLv
  778. msgRet.items[0] = 0
  779. for itemID, itemCnt in pairs(list) do
  780. BagLogic.addItem(human, itemID, itemCnt, "hero_growup")
  781. if msgRet.items[0] < #msgRet.items then
  782. msgRet.items[0] = msgRet.items[0] + 1
  783. Grid.makeItem(msgRet.items[msgRet.items[0]], itemID, itemCnt)
  784. end
  785. end
  786. BagLogic.sendItemGetList2(human, list)
  787. msgRet.isBuyKing = isBuy == 1 and 1 or 0
  788. --Msg.trace(msgRet)
  789. Msg.send(msgRet, human.fd)
  790. end
  791. -- 购买王者礼包ii
  792. function buyKing(human)
  793. local actStartTime,actEndTime, groupID = getActStartTime()
  794. local lvConfigs = getLvConfigs(groupID)
  795. if not actStartTime then return end
  796. if not lvConfigs then
  797. return
  798. end
  799. local lvdefine = lvConfigs[1]
  800. checkDB(human, actStartTime,groupID)
  801. local isBuy = isBuyKing(human)
  802. if isBuy == 1 then return end
  803. setBuyKing(human, actStartTime)
  804. -- 计算可以给的东西
  805. -- local maxLv = #lvConfigs
  806. -- local nowLv = getLv(human)
  807. -- local list = {}
  808. -- for lv = 1, nowLv do
  809. -- local cf = lvConfigs[lv]
  810. -- local itemsKing = cf and cf.itemsKing
  811. -- if (not cf) and (lv - maxLv) % lvdefine.lastNeedLv then
  812. -- itemsKing = lvdefine.lastItemsKing
  813. -- end
  814. -- if itemsKing then
  815. -- for _, item in ipairs(itemsKing) do
  816. -- local itemID = item[1]
  817. -- local itemCnt = item[2]
  818. -- list[itemID] = (list[itemID] or 0) + itemCnt
  819. -- end
  820. -- end
  821. -- end
  822. local list = {}
  823. local config = lvdefine.kingBuyItems
  824. if isBuy then
  825. config = lvdefine.kingBuyItems2
  826. end
  827. -- 购买王者后直接赠送的东西
  828. for _, item in ipairs(config) do
  829. local itemID = item[1]
  830. local itemCnt = item[2]
  831. list[itemID] = (list[itemID] or 0) + itemCnt
  832. end
  833. -- 给东西
  834. for itemID, itemCnt in pairs(list) do
  835. BagLogic.addItem(human, itemID, itemCnt, "hero_growup")
  836. end
  837. BagLogic.sendItemGetList2(human, list)
  838. YunYingLogic.updateIcon(YYInfo[DG_ABS_ACT_ID], human)
  839. local msgRet = Msg.gc.GC_HERO_GROWUP_BUY_OK
  840. fontBaseNet(msgRet.data, human, actStartTime, lvdefine)
  841. Msg.send(msgRet, human.fd)
  842. sendRewardQuery(human)
  843. end
  844. -- 子回调
  845. local function doCallback(human, actStartTime, mainType, taskType, maxValue, key, value)
  846. local oldValue = getValueByKey(human, mainType, taskType, key)
  847. if oldValue >= maxValue then
  848. return
  849. end
  850. local newValue = oldValue
  851. -- 任务类型11 指定英雄 竞技场胜利指定次数
  852. if taskType == TASKTYPE11 then
  853. local isFind = nil
  854. for _, obj in pairs(value.objList) do
  855. if obj.side == CombatDefine.ATTACK_SIDE and
  856. obj.id == key then
  857. isFind = true
  858. break
  859. end
  860. end
  861. if not isFind then return end
  862. newValue = oldValue + 1
  863. elseif taskType == TASKTYPE12 then
  864. if key ~= value then
  865. return
  866. end
  867. newValue = oldValue + 1
  868. elseif taskType == TASKTYPE14 then
  869. if value > key then
  870. return
  871. end
  872. newValue = oldValue + 1
  873. else
  874. newValue = math.min(oldValue + value, maxValue)
  875. end
  876. updateValue(human, actStartTime, mainType, taskType, key, newValue)
  877. return true
  878. end
  879. -- 任务回调
  880. function onCallback(human, taskType, value)
  881. local actStartTime,actEndTime,groupID = getActStartTime()
  882. if not actStartTime then return end
  883. local mainTypes = getMainTypesByTaskType(taskType)
  884. if not mainTypes then return end
  885. checkDB(human, actStartTime,groupID)
  886. local isChange = nil
  887. for mainType, mainValue in pairs(mainTypes) do
  888. local mainValueType = type(mainValue)
  889. if mainValueType == "number" then
  890. if doCallback(human, actStartTime, mainType, taskType, mainValue, nil, value) then
  891. isChange = true
  892. end
  893. elseif mainValueType == "table" then
  894. for key, maxValue in pairs(mainValue) do
  895. if doCallback(human, actStartTime, mainType, taskType, maxValue, key, value) then
  896. isChange = true
  897. end
  898. end
  899. end
  900. end
  901. if isChange then
  902. YunYingLogic.updateIcon(YYInfo[DG_ABS_ACT_ID], human)
  903. Msg.send(Msg.gc.GC_HERO_GROWUP_TASK_REFRESH, human.fd)
  904. end
  905. return isChange
  906. end
  907. -- 任务回调 uuid
  908. local FakeHuman = {}
  909. function onCallbackByUuid(uuid, taskType, value)
  910. local db, online = RoleDBLogic.getDb(uuid)
  911. if not db then return end
  912. FakeHuman.db = db
  913. if onCallback(FakeHuman, taskType, value) and not online then
  914. RoleDBLogic.saveRole(db)
  915. end
  916. end
  917. function buyJifen(human,itemID,cnt)
  918. local actStartTime,actEndTime,groupID = getActStartTime()
  919. if not actStartTime then return end
  920. local now = os.time()
  921. if actEndTime - now > 3*86400 then
  922. return
  923. end
  924. checkDB(human, actStartTime,groupID)
  925. local config = ItemExcel.commonBuy[itemID]
  926. if not config then
  927. return
  928. end
  929. local price = config.price[2]*cnt
  930. if not ObjHuman.checkRMB(human,price) then
  931. return
  932. end
  933. ObjHuman.decZuanshi(human, - price, "hero_growup")
  934. addJifen(human, 1000*cnt)
  935. local msgRet = Msg.gc.GC_HERO_GROWUP_BUY_JIFEN
  936. msgRet.lv = human.db.heroGrowUp.lv or 0
  937. msgRet.jifen = human.db.heroGrowUp.jifen or 0
  938. msgRet.maxJifen = AbsActExcel.heroGrowUpLv[1].needJifen
  939. Msg.send(msgRet,human.fd)
  940. end
  941. -- 活动循环,开启与结束
  942. function actLoop()
  943. local workManStartTime,workManEndTime,groupID = getActStartTime()
  944. local workMan = CommonDB.getWorkMan()
  945. -- 活动未开,且commonDB活动开,则关闭活动
  946. if not workManStartTime and workMan.state then
  947. CommonDB.setWorkManState()
  948. return
  949. end
  950. -- 活动开,且commonDB活动未开,则开启活动
  951. -- 活动id不符
  952. if (workManStartTime and not workMan.state) or groupID ~= workMan.groupID then
  953. CommonDB.setWorkManState(true)
  954. CommonDB.setWorkManGroup(groupID)
  955. CommonDB.setWorkManTs(workManStartTime)
  956. --重置任务
  957. TASKTYPE_2_MAINTYPES = {}
  958. MAINTYPE_2_IDLIST = {}
  959. -- 设置新任务
  960. for id, cf in pairs(AbsActExcel.heroGrowUpTask) do
  961. if not TASKTYPE_2_MAINTYPES[cf.taskType] then
  962. TASKTYPE_2_MAINTYPES[cf.taskType] = {}
  963. end
  964. if not MAINTYPE_2_IDLIST[cf.mainType] then
  965. MAINTYPE_2_IDLIST[cf.mainType] = {}
  966. end
  967. local len = #MAINTYPE_2_IDLIST[cf.mainType]
  968. MAINTYPE_2_IDLIST[cf.mainType][len + 1] = id
  969. local list = TASKTYPE_2_MAINTYPES[cf.taskType]
  970. local value = cf.taskArgs[1]
  971. local key = cf.taskArgs[2]
  972. if type(cf.taskArgs[2]) == "table" then
  973. local lenth = #cf.taskArgs[2]
  974. local randomPos = math.random(1,lenth)
  975. key = cf.taskArgs[2][randomPos]
  976. end
  977. if key then
  978. list[cf.mainType] = list[cf.mainType] or {}
  979. list[cf.mainType][key] = math.max(list[cf.mainType][key] or 0, value)
  980. else
  981. list[cf.mainType] = math.max(list[cf.mainType] or 0, value)
  982. end
  983. end
  984. GROUPID_2_LVCONFIGS = {}
  985. for _, cf in ipairs(AbsActExcel.heroGrowUpLv) do
  986. if not GROUPID_2_LVCONFIGS[cf.groupID] then
  987. GROUPID_2_LVCONFIGS[cf.groupID] = {}
  988. end
  989. GROUPID_2_LVCONFIGS[cf.groupID][cf.lv] = cf
  990. end
  991. return
  992. end
  993. end