HeroGrowUp.lua 33 KB

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