HeroGrowUp.lua 32 KB

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