HeroGrowUp.lua 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140
  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 = actEndTime
  576. msgRet.startTime = actStartTime
  577. msgRet.leftTime = 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. Msg.send(msgRet, human.fd)
  594. end
  595. -- 领取任务奖励
  596. function getTaskItems(human, id)
  597. local actStartTime,actEndTime,groupID = getActStartTime()
  598. if not actStartTime then
  599. return Broadcast.sendErr(human, Lang.YUNYING_ERR_TIME)
  600. end
  601. local cf = AbsActExcel.heroGrowUpTask[id]
  602. if not cf then return end
  603. checkDB(human, actStartTime,groupID)
  604. local state = getTaskState(human, id, cf)
  605. if state == TASK_STATE_NONE then
  606. return Broadcast.sendErr(human, Lang.YUNYING_GET_ERR_CONDITION)
  607. end
  608. if state == TASK_STATE_HAD then
  609. return Broadcast.sendErr(human, Lang.YUNYING_GET_ERR_HADGET)
  610. end
  611. setGetTask(human, actStartTime, id, cf)
  612. for _, item in ipairs(cf.items) do
  613. local itemID = item[1]
  614. local itemCnt = item[2]
  615. BagLogic.addItem(human, itemID, itemCnt, "hero_growup_task")
  616. end
  617. BagLogic.sendItemGetList1(human, cf.items)
  618. sendTaskQuery(human, cf.mainType)
  619. YunYingLogic.updateIcon(YYInfo[DG_ABS_ACT_ID], human)
  620. end
  621. -- 查看王者礼包信息
  622. function sendKingQuery(human)
  623. if not SceneHandler.canCharge(human) then
  624. return
  625. end
  626. local actStartTime,actEndTime, groupID = getActStartTime()
  627. local lvConfigs = getLvConfigs(groupID)
  628. if not actStartTime then
  629. return Broadcast.sendErr(human, Lang.YUNYING_ERR_TIME)
  630. end
  631. if not lvConfigs then
  632. return
  633. end
  634. local lvdefine = lvConfigs[1].kingBuyItems
  635. checkDB(human, actStartTime,groupID)
  636. local isBuy = isBuyKing(human)
  637. if isBuy then
  638. lvdefine = lvConfigs[1].kingBuyItems2
  639. end
  640. local msgRet = Msg.gc.GC_HERO_GROWUP_KING_QUERY
  641. msgRet.items[0] = math.min(#lvdefine, #msgRet.items)
  642. for i = 1, msgRet.items[0] do
  643. local itemID = lvdefine[i][1]
  644. local itemCnt = lvdefine[i][2]
  645. Grid.makeItem(msgRet.items[i], itemID, itemCnt)
  646. end
  647. BuyLogic.fontBuyItem(human, msgRet.buyItem, lvConfigs[1].buyID)
  648. msgRet.isBuyKing = isBuy == 1 and 1 or 0
  649. --Msg.trace(msgRet)
  650. Msg.send(msgRet, human.fd)
  651. end
  652. -- 奖励界面查看
  653. function sendRewardQuery(human)
  654. local actStartTime,actEndTime, groupID = getActStartTime()
  655. local lvConfigs = getLvConfigs(groupID)
  656. if not actStartTime or not lvConfigs then
  657. return Broadcast.sendErr(human, Lang.YUNYING_ERR_TIME)
  658. end
  659. local lvdefine = lvConfigs[1]
  660. checkDB(human, actStartTime,groupID)
  661. local msgRet = Msg.gc.GC_HERO_GROWUP_REWARD_QUERY
  662. fontBaseNet(msgRet.data, human, actStartTime, lvdefine)
  663. msgRet.data.hasTaskRed = isRewardRed(human) and 1 or 0
  664. msgRet.rewardList[0] = #lvConfigs
  665. local nowLv = getLv(human)
  666. for lv = 1, msgRet.rewardList[0] do
  667. local net = msgRet.rewardList[lv]
  668. local cf = lvConfigs[lv]
  669. net.lv = lv
  670. net.items[0] = #cf.items
  671. net.state = 0
  672. net.stateEx = 0
  673. for i = 1, net.items[0] do
  674. local itemID = cf.items[i][1]
  675. local itemCnt = cf.items[i][2]
  676. Grid.makeItem(net.items[i], itemID, itemCnt)
  677. end
  678. if lv <= nowLv then
  679. net.state = getGetReward(human,lv)
  680. end
  681. net.itemsKing[0] = #cf.itemsKing
  682. for i = 1, net.itemsKing[0] do
  683. local itemID = cf.itemsKing[i][1]
  684. local itemCnt = cf.itemsKing[i][2]
  685. Grid.makeItem(net.itemsKing[i], itemID, itemCnt)
  686. end
  687. if lv <= nowLv then
  688. net.stateEx = getGetExReward(human,lv)
  689. end
  690. end
  691. local maxLv = #lvConfigs
  692. local exRewardNet = msgRet.exReward
  693. local nextLv = maxLv + lvdefine.lastNeedLv
  694. exRewardNet.needLv = lvdefine.lastNeedLv
  695. exRewardNet.items[0] = #lvdefine.lastItems
  696. exRewardNet.state = 0
  697. exRewardNet.stateEx = 0
  698. while true do
  699. if nextLv > nowLv then
  700. break
  701. end
  702. local nextState = getGetReward(human,nextLv)
  703. if not nextState or nextState == 1 then
  704. break
  705. end
  706. nextLv = nextLv + lvdefine.lastNeedLv
  707. end
  708. exRewardNet.lv = nextLv
  709. exRewardNet.state = getGetReward(human,nextLv)
  710. nextLv = maxLv + lvdefine.lastNeedLv
  711. while true do
  712. if nextLv > nowLv then
  713. break
  714. end
  715. local nextState = getGetExReward(human,nextLv)
  716. if not nextState or nextState == 1 then
  717. break
  718. end
  719. nextLv = nextLv + lvdefine.lastNeedLv
  720. end
  721. exRewardNet.exLv = nextLv
  722. exRewardNet.stateEx = getGetExReward(human,nextLv)
  723. local isBuy = isBuyKing(human)
  724. if isBuy ~= 1 then
  725. exRewardNet.stateEx = 0
  726. end
  727. for i = 1, exRewardNet.items[0] do
  728. local itemID = lvdefine.lastItems[i][1]
  729. local itemCnt = lvdefine.lastItems[i][2]
  730. Grid.makeItem(exRewardNet.items[i], itemID, itemCnt)
  731. end
  732. exRewardNet.itemsKing[0] = #lvdefine.lastItemsKing
  733. for i = 1, exRewardNet.itemsKing[0] do
  734. local itemID = lvdefine.lastItemsKing[i][1]
  735. local itemCnt = lvdefine.lastItemsKing[i][2]
  736. Grid.makeItem(exRewardNet.itemsKing[i], itemID, itemCnt)
  737. end
  738. --Msg.trace(msgRet)
  739. Msg.send(msgRet, human.fd)
  740. end
  741. -------------------------------------------- 回调 -------------------------------------------------------
  742. -- 升级回调
  743. function getLvReward(human, lv)
  744. local actStartTime,actEndTime, groupID = getActStartTime()
  745. if not groupID then
  746. return
  747. end
  748. local nowLv = getLv(human)
  749. if lv > nowLv then
  750. return
  751. end
  752. local normalGet = getGetReward(human,lv)
  753. local exGet = getGetExReward(human,lv)
  754. local lvConfigs = getLvConfigs(groupID)
  755. if not lvConfigs then
  756. return
  757. end
  758. local lvdefine = lvConfigs[1]
  759. local list = {}
  760. local maxLv = #lvConfigs
  761. local isBuy = isBuyKing(human)
  762. local cf = lvConfigs[lv]
  763. local items = cf and cf.items
  764. local itemsKing = cf and cf.itemsKing
  765. if (not cf) and (lv - maxLv) % lvdefine.lastNeedLv == 0 then
  766. items = lvdefine.lastItems
  767. itemsKing = lvdefine.lastItemsKing
  768. end
  769. if items and normalGet ~= 2 then
  770. for _, item in ipairs(items) do
  771. local itemID = item[1]
  772. local itemCnt = item[2]
  773. list[itemID] = (list[itemID] or 0) + itemCnt
  774. end
  775. end
  776. if itemsKing and isBuy == 1 and exGet ~= 2 then
  777. for _, item in ipairs(itemsKing) do
  778. local itemID = item[1]
  779. local itemCnt = item[2]
  780. list[itemID] = (list[itemID] or 0) + itemCnt
  781. end
  782. end
  783. if not next(list) then return end
  784. setGetReward(human,lv)
  785. if isBuy == 1 then
  786. setGetExReward(human,lv)
  787. end
  788. YunYingLogic.updateIcon(YYInfo[DG_ABS_ACT_ID], human)
  789. local msgRet = Msg.gc.GC_HERO_GROWUP_LVUP
  790. msgRet.lv = nowLv
  791. msgRet.items[0] = 0
  792. for itemID, itemCnt in pairs(list) do
  793. BagLogic.addItem(human, itemID, itemCnt, "hero_growup")
  794. if msgRet.items[0] < #msgRet.items then
  795. msgRet.items[0] = msgRet.items[0] + 1
  796. Grid.makeItem(msgRet.items[msgRet.items[0]], itemID, itemCnt)
  797. end
  798. end
  799. BagLogic.sendItemGetList2(human, list)
  800. msgRet.isBuyKing = isBuy == 1 and 1 or 0
  801. --Msg.trace(msgRet)
  802. Msg.send(msgRet, human.fd)
  803. end
  804. -- 购买王者礼包ii
  805. function buyKing(human)
  806. local actStartTime,actEndTime, groupID = getActStartTime()
  807. local lvConfigs = getLvConfigs(groupID)
  808. if not actStartTime then return end
  809. if not lvConfigs then
  810. return
  811. end
  812. local lvdefine = lvConfigs[1]
  813. checkDB(human, actStartTime,groupID)
  814. local isBuy = isBuyKing(human)
  815. if isBuy == 1 then return end
  816. setBuyKing(human, actStartTime)
  817. -- 计算可以给的东西
  818. -- local maxLv = #lvConfigs
  819. -- local nowLv = getLv(human)
  820. -- local list = {}
  821. -- for lv = 1, nowLv do
  822. -- local cf = lvConfigs[lv]
  823. -- local itemsKing = cf and cf.itemsKing
  824. -- if (not cf) and (lv - maxLv) % lvdefine.lastNeedLv then
  825. -- itemsKing = lvdefine.lastItemsKing
  826. -- end
  827. -- if itemsKing then
  828. -- for _, item in ipairs(itemsKing) do
  829. -- local itemID = item[1]
  830. -- local itemCnt = item[2]
  831. -- list[itemID] = (list[itemID] or 0) + itemCnt
  832. -- end
  833. -- end
  834. -- end
  835. local list = {}
  836. local config = lvdefine.kingBuyItems
  837. if isBuy then
  838. config = lvdefine.kingBuyItems2
  839. end
  840. -- 购买王者后直接赠送的东西
  841. for _, item in ipairs(config) do
  842. local itemID = item[1]
  843. local itemCnt = item[2]
  844. list[itemID] = (list[itemID] or 0) + itemCnt
  845. end
  846. -- 给东西
  847. for itemID, itemCnt in pairs(list) do
  848. BagLogic.addItem(human, itemID, itemCnt, "hero_growup")
  849. end
  850. BagLogic.sendItemGetList2(human, list)
  851. YunYingLogic.updateIcon(YYInfo[DG_ABS_ACT_ID], human)
  852. local msgRet = Msg.gc.GC_HERO_GROWUP_BUY_OK
  853. fontBaseNet(msgRet.data, human, actStartTime, lvdefine)
  854. Msg.send(msgRet, human.fd)
  855. sendRewardQuery(human)
  856. end
  857. -- 子回调
  858. local function doCallback(human, actStartTime, mainType, taskType, maxValue, key, value)
  859. local oldValue = getValueByKey(human, mainType, taskType, key)
  860. if oldValue >= maxValue then
  861. return
  862. end
  863. local newValue = oldValue
  864. -- 任务类型11 指定英雄 竞技场胜利指定次数
  865. if taskType == TASKTYPE11 then
  866. local isFind = nil
  867. for _, obj in pairs(value.objList) do
  868. if obj.side == CombatDefine.ATTACK_SIDE and
  869. obj.id == key then
  870. isFind = true
  871. break
  872. end
  873. end
  874. if not isFind then return end
  875. newValue = oldValue + 1
  876. elseif taskType == TASKTYPE12 then
  877. if key ~= value then
  878. return
  879. end
  880. newValue = oldValue + 1
  881. elseif taskType == TASKTYPE14 then
  882. if value > key then
  883. return
  884. end
  885. newValue = oldValue + 1
  886. else
  887. newValue = math.min(oldValue + value, maxValue)
  888. end
  889. updateValue(human, actStartTime, mainType, taskType, key, newValue)
  890. return true
  891. end
  892. -- 任务回调
  893. function onCallback(human, taskType, value)
  894. local actStartTime,actEndTime,groupID = getActStartTime()
  895. if not actStartTime then return end
  896. local mainTypes = getMainTypesByTaskType(taskType)
  897. if not mainTypes then return end
  898. checkDB(human, actStartTime,groupID)
  899. local isChange = nil
  900. for mainType, mainValue in pairs(mainTypes) do
  901. local mainValueType = type(mainValue)
  902. if mainValueType == "number" then
  903. if doCallback(human, actStartTime, mainType, taskType, mainValue, nil, value) then
  904. isChange = true
  905. end
  906. elseif mainValueType == "table" then
  907. for key, maxValue in pairs(mainValue) do
  908. if doCallback(human, actStartTime, mainType, taskType, maxValue, key, value) then
  909. isChange = true
  910. end
  911. end
  912. end
  913. end
  914. if isChange then
  915. YunYingLogic.updateIcon(YYInfo[DG_ABS_ACT_ID], human)
  916. Msg.send(Msg.gc.GC_HERO_GROWUP_TASK_REFRESH, human.fd)
  917. end
  918. return isChange
  919. end
  920. -- 任务回调 uuid
  921. local FakeHuman = {}
  922. function onCallbackByUuid(uuid, taskType, value)
  923. local db, online = RoleDBLogic.getDb(uuid)
  924. if not db then return end
  925. FakeHuman.db = db
  926. if onCallback(FakeHuman, taskType, value) and not online then
  927. RoleDBLogic.saveRole(db)
  928. end
  929. end
  930. function buyJifen(human,itemID,cnt)
  931. local actStartTime,actEndTime,groupID = getActStartTime()
  932. if not actStartTime then return end
  933. local now = os.time()
  934. if actEndTime - now > 3*86400 then
  935. return
  936. end
  937. checkDB(human, actStartTime,groupID)
  938. local config = ItemExcel.commonBuy[itemID]
  939. if not config then
  940. return
  941. end
  942. local price = config.price[2]*cnt
  943. if not ObjHuman.checkRMB(human,price) then
  944. return
  945. end
  946. ObjHuman.decZuanshi(human, - price, "hero_growup")
  947. addJifen(human, 1000*cnt)
  948. local msgRet = Msg.gc.GC_HERO_GROWUP_BUY_JIFEN
  949. msgRet.lv = human.db.heroGrowUp.lv or 0
  950. msgRet.jifen = human.db.heroGrowUp.jifen or 0
  951. msgRet.maxJifen = AbsActExcel.heroGrowUpLv[1].needJifen
  952. Msg.send(msgRet,human.fd)
  953. end
  954. -- 活动循环,开启与结束
  955. function actLoop()
  956. local workManStartTime,workManEndTime,groupID = getActStartTime()
  957. local workMan = CommonDB.getWorkMan()
  958. -- 活动未开,且commonDB活动开,则关闭活动
  959. if not workManStartTime and workMan.state then
  960. CommonDB.setWorkManState()
  961. return
  962. end
  963. -- 活动开,且commonDB活动未开,则开启活动
  964. -- 活动id不符
  965. if (workManStartTime and not workMan.state) or groupID ~= workMan.groupID then
  966. CommonDB.setWorkManState(true)
  967. CommonDB.setWorkManGroup(groupID)
  968. CommonDB.setWorkManTs(workManStartTime)
  969. --重置任务
  970. TASKTYPE_2_MAINTYPES = {}
  971. MAINTYPE_2_IDLIST = {}
  972. -- 设置新任务
  973. for id, cf in pairs(AbsActExcel.heroGrowUpTask) do
  974. if not TASKTYPE_2_MAINTYPES[cf.taskType] then
  975. TASKTYPE_2_MAINTYPES[cf.taskType] = {}
  976. end
  977. if not MAINTYPE_2_IDLIST[cf.mainType] then
  978. MAINTYPE_2_IDLIST[cf.mainType] = {}
  979. end
  980. local len = #MAINTYPE_2_IDLIST[cf.mainType]
  981. MAINTYPE_2_IDLIST[cf.mainType][len + 1] = id
  982. local list = TASKTYPE_2_MAINTYPES[cf.taskType]
  983. local value = cf.taskArgs[1]
  984. local key = cf.taskArgs[2]
  985. if type(cf.taskArgs[2]) == "table" then
  986. local lenth = #cf.taskArgs[2]
  987. local randomPos = math.random(1,lenth)
  988. key = cf.taskArgs[2][randomPos]
  989. end
  990. if key then
  991. list[cf.mainType] = list[cf.mainType] or {}
  992. list[cf.mainType][key] = math.max(list[cf.mainType][key] or 0, value)
  993. else
  994. list[cf.mainType] = math.max(list[cf.mainType] or 0, value)
  995. end
  996. end
  997. GROUPID_2_LVCONFIGS = {}
  998. for _, cf in ipairs(AbsActExcel.heroGrowUpLv) do
  999. if not GROUPID_2_LVCONFIGS[cf.groupID] then
  1000. GROUPID_2_LVCONFIGS[cf.groupID] = {}
  1001. end
  1002. GROUPID_2_LVCONFIGS[cf.groupID][cf.lv] = cf
  1003. end
  1004. return
  1005. end
  1006. end