HeroGrowUp.lua 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122
  1. ---------------------------------------------------------------
  2. -- 英雄崛起(其实28天为一期的任务活动)
  3. -- 与创角时间相关
  4. -- tip 32
  5. -- db.heroGrowUp.groupID 活动组id
  6. -- db.heroGrowUp.time 活动开始的时间戳
  7. -- db.heroGrowUp.lv 等级
  8. -- db.heroGrowUp.lvGet 等级领取
  9. -- db.heroGrowUp.lvExGet 等级额外领取
  10. -- db.heroGrowUp.jifen 当前积分
  11. -- db.heroGrowUp.isBuy 是否购买
  12. -- db.heroGrowUp.task[mainType] = taskList
  13. -- taskList.time 刷新时间
  14. -- taskList.records 任务进度 [id] = value
  15. -- taskList.gets 领取记录 [id] = true
  16. ---------------------------------------------------------------
  17. local PresentExcel = require("excel.present")
  18. local OpenActExcel = require("excel.openAct")
  19. local Util = require("common.Util")
  20. local Lang = require("common.Lang")
  21. local Msg = require("core.Msg")
  22. local Broadcast = require("broadcast.Broadcast")
  23. local Grid = require("bag.Grid")
  24. local BagLogic = require("bag.BagLogic")
  25. local CombatDefine = require("combat.CombatDefine")
  26. local BuyLogic = require("topup.BuyLogic")
  27. local HeroDefine = require("hero.HeroDefine")
  28. local RoleDBLogic = require("role.RoleDBLogic")
  29. local YunYingLogic = require("yunying.YunYingLogic")
  30. local SceneHandler = require("scene.Handler")
  31. local CommonDB = require("common.CommonDB")
  32. local ItemExcel = require("excel.item")
  33. local ObjHuman = require("core.ObjHuman")
  34. local Config = require("Config")
  35. local AbsActExcel = require("excel.absAct")
  36. local AbsActLogic = require("absAct.AbsActLogic")
  37. DAY_TIME_SEC = 1 * 86400
  38. WEEK_TIME_SEC = 7 * 86400
  39. ACT_TIME_SEC1 = 28 * 86400
  40. ACT_TIME_SEC2 = 14 * 86400
  41. -- 任务分类
  42. MAINTYPE_DAY = 1 -- 每日
  43. MAINTYPE_WEEK = 2 -- 每周
  44. MAINTYPE_MONTH = 3 -- 每期
  45. MAINTYPE_CNT = 3
  46. -- 任务状态
  47. TASK_STATE_NONE = 0 -- 不可领
  48. TASK_STATE_CAN = 1 -- 可领
  49. TASK_STATE_HAD = 2 -- 已领
  50. -- 任务类型
  51. TASKTYPE1 = 1 -- o登录游戏
  52. TASKTYPE2 = 2 -- o天命召唤
  53. TASKTYPE3 = 3 -- o占卜合成
  54. TASKTYPE4 = 4 -- o消耗x金币
  55. TASKTYPE5 = 5 -- o消耗x钻石
  56. TASKTYPE6 = 6 -- o战报点赞X次
  57. TASKTYPE7 = 7 -- o皇冠联赛战场胜利X次
  58. TASKTYPE8 = 8 -- o合成X次任意符文
  59. TASKTYPE9 = 9 -- o冰龙巢穴
  60. TASKTYPE10 = 10 -- o随机商店购买道具
  61. TASKTYPE11 = 11 -- o上阵指定英雄XX,皇冠联赛战场获得X场胜利
  62. TASKTYPE12 = 12 -- o获取X个Y星英雄
  63. TASKTYPE13 = 13 -- o挑战战神殿
  64. TASKTYPE14 = 14 -- o王者争霸32强
  65. TASKTYPE15 = 15 -- o完成X次悬赏任务
  66. TASKTYPE16 = 16 -- o圣树试炼胜利X次
  67. TASKTYPE17 = 17 -- o接取X次红色悬赏任务
  68. TASKTYPE18 = 18 -- o消耗X英雄经验
  69. TASKTYPE19 = 19 -- o洗练X次任意装备
  70. TASKTYPE20 = 20 -- o遗迹探宝,击败x个守卫
  71. TASKTYPE21 = 21 -- o分解装备
  72. DG_ABS_ACT_ID = 8001
  73. HGU_AFTER_START = true
  74. function initAfterStart()
  75. HGU_AFTER_START = false
  76. end
  77. function initAfterHot()
  78. if HGU_AFTER_START then
  79. return
  80. end
  81. local workManStartTime,workManEndTime,groupID = getActStartTime()
  82. -- 活动未开
  83. if not workManStartTime then
  84. return
  85. end
  86. --重置任务
  87. TASKTYPE_2_MAINTYPES = {}
  88. MAINTYPE_2_IDLIST = {}
  89. -- 设置新任务
  90. for id, cf in pairs(AbsActExcel.heroGrowUpTask) do
  91. if not TASKTYPE_2_MAINTYPES[cf.taskType] then
  92. TASKTYPE_2_MAINTYPES[cf.taskType] = {}
  93. end
  94. if not MAINTYPE_2_IDLIST[cf.mainType] then
  95. MAINTYPE_2_IDLIST[cf.mainType] = {}
  96. end
  97. local len = #MAINTYPE_2_IDLIST[cf.mainType]
  98. MAINTYPE_2_IDLIST[cf.mainType][len + 1] = id
  99. local list = TASKTYPE_2_MAINTYPES[cf.taskType]
  100. local value = cf.taskArgs[1]
  101. local key = cf.taskArgs[2]
  102. if type(cf.taskArgs[2]) == "table" then
  103. local lenth = #cf.taskArgs[2]
  104. local randomPos = math.random(1,lenth)
  105. key = cf.taskArgs[2][randomPos]
  106. end
  107. if key then
  108. list[cf.mainType] = list[cf.mainType] or {}
  109. list[cf.mainType][key] = math.max(list[cf.mainType][key] or 0, value)
  110. else
  111. list[cf.mainType] = math.max(list[cf.mainType] or 0, value)
  112. end
  113. end
  114. GROUPID_2_LVCONFIGS = {}
  115. for _, cf in ipairs(AbsActExcel.heroGrowUpLv) do
  116. if not GROUPID_2_LVCONFIGS[cf.groupID] then
  117. GROUPID_2_LVCONFIGS[cf.groupID] = {}
  118. end
  119. GROUPID_2_LVCONFIGS[cf.groupID][cf.lv] = cf
  120. end
  121. end
  122. -- 本期活动开始时间
  123. function getActStartTime()
  124. --local id = AbsActLogic.getIDByActID(human, DG_ABS_ACT_ID)
  125. local absActConfig = AbsActExcel.absActivity[DG_ABS_ACT_ID]
  126. if absActConfig.actId and absActConfig.actId ~= 0 then
  127. return absActConfig.realStartTime,absActConfig.realEndTime,absActConfig.actId
  128. end
  129. end
  130. -- 活动剩余时间
  131. function getActLeftTime()
  132. local absActConfig = AbsActExcel.absActivity[DG_ABS_ACT_ID]
  133. if absActConfig.actId then
  134. return absActConfig.realEndTime - os.time()
  135. end
  136. return 0
  137. end
  138. -- 任务周期
  139. function getTaskTime(mainType)
  140. if mainType == MAINTYPE_DAY then
  141. return DAY_TIME_SEC
  142. elseif mainType == MAINTYPE_WEEK then
  143. return WEEK_TIME_SEC
  144. elseif mainType == MAINTYPE_MONTH then
  145. return ACT_TIME_SEC1
  146. end
  147. end
  148. -- 本期任务开始时间
  149. function getTaskStartTime(actStartTime, mainType)
  150. local time = getTaskTime(mainType)
  151. if not time then return end
  152. local sec = os.time() - actStartTime
  153. local cnt = math.floor(sec / time)
  154. return actStartTime + cnt * time
  155. end
  156. -- 获取任务剩余时间
  157. function getTaskLeftTime(actStartTime, mainType)
  158. local time = getTaskTime(mainType)
  159. if not time then return end
  160. local actLeftTime = getActLeftTime()
  161. return actLeftTime % time
  162. end
  163. -- 是否开放
  164. function isOpen(human)
  165. local openDay = CommonDB.getServerOpenDay()
  166. local absActConfig = AbsActExcel.absActivity[DG_ABS_ACT_ID]
  167. if openDay and openDay < absActConfig.openDay then
  168. return
  169. end
  170. if not getActStartTime() then
  171. return
  172. end
  173. return true
  174. end
  175. -- 是否红点
  176. function isRed(human)
  177. return isTaskRed(human) or isRewardRed(human)
  178. end
  179. -- 积分任务是否有红点
  180. function isTaskRed(human)
  181. for mainType = 1, MAINTYPE_CNT do
  182. if isTaskRedByType(human, mainType) then
  183. return true
  184. end
  185. end
  186. end
  187. -- 有奖励可领取
  188. function isRewardRed(human)
  189. local heroGrowUpDB = human.db.heroGrowUp
  190. if not heroGrowUpDB then
  191. return
  192. end
  193. local actStartTime,actEndTime,groupID = getActStartTime()
  194. local lvConfigs = getLvConfigs(groupID)
  195. if not actStartTime then return end
  196. if not lvConfigs then
  197. return
  198. end
  199. local maxLv = #lvConfigs
  200. for i = 1,heroGrowUpDB.lv do
  201. if i <= maxLv then
  202. if getGetReward(human,i) == 1 or not getGetExReward(human,i) == 1 then
  203. return true
  204. end
  205. else
  206. local lvDefine = lvConfigs[1]
  207. local flag = (i - maxLv) % lvDefine.lastNeedLv
  208. if flag == 0 then
  209. if getGetReward(human,i) == 1 or getGetExReward(human,i) == 1 then
  210. return true
  211. end
  212. end
  213. end
  214. end
  215. return
  216. end
  217. -- 根据分类判断是否有红点
  218. function isTaskRedByType(human, mainType)
  219. local list = getTaskIDList(mainType)
  220. local listLen = list and #list or 0
  221. for i = 1, listLen do
  222. local id = list[i]
  223. local cf = AbsActExcel.heroGrowUpTask[id]
  224. if getTaskState(human, id, cf) == TASK_STATE_CAN then
  225. return true
  226. end
  227. end
  228. end
  229. -- 根据类型获取任务id
  230. function getTaskIDList(mainType)
  231. return TASKTYPE_2_MAINTYPES and MAINTYPE_2_IDLIST[mainType]
  232. end
  233. -- 根据任务类型获取影响的分类
  234. -- [taskType] = {[mainType1] = maxValue, [mainType2][key] = maxValue2}
  235. function getMainTypesByTaskType(taskType)
  236. return TASKTYPE_2_MAINTYPES and TASKTYPE_2_MAINTYPES[taskType]
  237. end
  238. -- 最多x期
  239. local MAX_GROUPID = nil
  240. function getMaxGroupID()
  241. if not MAX_GROUPID then
  242. MAX_GROUPID = 0
  243. for _, cf in ipairs(AbsActExcel.heroGrowUpLv) do
  244. if cf.groupID > MAX_GROUPID then
  245. MAX_GROUPID = cf.groupID
  246. end
  247. end
  248. end
  249. return MAX_GROUPID
  250. end
  251. -- 根据第x期获取配置
  252. function getLvConfigs(groupID)
  253. return (groupID and GROUPID_2_LVCONFIGS) and GROUPID_2_LVCONFIGS[groupID]
  254. end
  255. -------------------------------------------- db -------------------------------------------------------
  256. -- 初始DB
  257. function initDB(human, actStartTime)
  258. local _,_,groupID = getActStartTime()
  259. local lvConfigs = getLvConfigs(groupID)
  260. if not lvConfigs then
  261. return
  262. end
  263. local heroGrowUpDB = {}
  264. heroGrowUpDB.time = actStartTime
  265. heroGrowUpDB.groupID = groupID
  266. heroGrowUpDB.lv = 0
  267. heroGrowUpDB.lvGet = {}
  268. heroGrowUpDB.lvExGet = {}
  269. heroGrowUpDB.jifen = 0
  270. heroGrowUpDB.isBuy = nil
  271. heroGrowUpDB.task = {}
  272. human.db.heroGrowUp = heroGrowUpDB
  273. end
  274. -- 初始任务DB
  275. function initTaskDB(human, actStartTime, mainType)
  276. local heroGrowUpDB = human.db.heroGrowUp
  277. local taskStartTime = getTaskStartTime(actStartTime, mainType)
  278. local taskList = {}
  279. taskList.time = taskStartTime
  280. taskList.records = {}
  281. taskList.gets = {}
  282. heroGrowUpDB.task[mainType] = taskList
  283. end
  284. -- 检查DB是否需要重置
  285. function checkDB(human, actStartTime,groupID)
  286. local heroGrowUpDB = human.db.heroGrowUp
  287. if not heroGrowUpDB then
  288. return
  289. end
  290. -- 新一期活动
  291. if heroGrowUpDB.groupID ~= groupID then
  292. heroGrowUpDB.groupID = groupID
  293. heroGrowUpDB.time = actStartTime
  294. heroGrowUpDB.lv = 0
  295. heroGrowUpDB.lvGet = {}
  296. heroGrowUpDB.lvExGet = {}
  297. heroGrowUpDB.jifen = 0
  298. heroGrowUpDB.isBuy = heroGrowUpDB.isBuy and 0 or nil
  299. heroGrowUpDB.task = {}
  300. return
  301. end
  302. -- 任务记录重置
  303. for mainType, taskList in pairs(heroGrowUpDB.task) do
  304. local taskStartTime = getTaskStartTime(actStartTime, mainType)
  305. if taskList.time ~= taskStartTime then
  306. heroGrowUpDB.task[mainType] = nil
  307. end
  308. end
  309. end
  310. -- 获取等级
  311. function getLv(human)
  312. local heroGrowUpDB = human.db.heroGrowUp
  313. if not heroGrowUpDB then
  314. return 0
  315. end
  316. return heroGrowUpDB.lv or 0
  317. end
  318. -- 获取当前积分
  319. function getJifen(human)
  320. local heroGrowUpDB = human.db.heroGrowUp
  321. if not heroGrowUpDB then
  322. return 0
  323. end
  324. return heroGrowUpDB.jifen or 0
  325. end
  326. -- 增加积分
  327. function addJifen(human, value)
  328. local actStartTime,actEndTime,groupID = getActStartTime()
  329. local lvConfigs = getLvConfigs(groupID)
  330. if not actStartTime then return end
  331. if not lvConfigs then
  332. return
  333. end
  334. local lvdefine = lvConfigs[1]
  335. checkDB(human, actStartTime,groupID)
  336. if not next(human.db.heroGrowUp) then
  337. initDB(human, actStartTime)
  338. end
  339. local heroGrowUpDB = human.db.heroGrowUp
  340. heroGrowUpDB.jifen = (heroGrowUpDB.jifen or 0) + value
  341. local addLv = math.floor(heroGrowUpDB.jifen / lvdefine.needJifen)
  342. local oldLv = heroGrowUpDB.lv or 0
  343. local newLv = oldLv + addLv
  344. heroGrowUpDB.jifen = heroGrowUpDB.jifen - addLv * lvdefine.needJifen
  345. heroGrowUpDB.lv = newLv
  346. if oldLv ~= newLv then
  347. YunYingLogic.updateIcon(YYInfo[DG_ABS_ACT_ID], human)
  348. end
  349. end
  350. -- 是否购买王者礼包
  351. function isBuyKing(human)
  352. local heroGrowUpDB = human.db.heroGrowUp
  353. if not heroGrowUpDB then
  354. return
  355. end
  356. return heroGrowUpDB.isBuy
  357. end
  358. -- 设置购买
  359. function setBuyKing(human, actStartTime)
  360. if not next(human.db.heroGrowUp) then
  361. initDB(human, actStartTime)
  362. end
  363. local heroGrowUpDB = human.db.heroGrowUp
  364. heroGrowUpDB.isBuy = 1
  365. end
  366. -- 设置领奖
  367. function setGetReward(human,lv)
  368. local actStartTime = getActStartTime()
  369. if not next(human.db.heroGrowUp) then
  370. initDB(human, actStartTime)
  371. end
  372. local heroGrowUpDB = human.db.heroGrowUp
  373. heroGrowUpDB.lvGet = heroGrowUpDB.lvGet or {}
  374. heroGrowUpDB.lvGet[lv] = 2
  375. end
  376. function getGetReward(human,lv)
  377. local heroGrowUpDB = human.db.heroGrowUp
  378. if not heroGrowUpDB then
  379. return 0
  380. end
  381. if lv > heroGrowUpDB.lv then
  382. return 0
  383. end
  384. if not heroGrowUpDB.lvGet or not heroGrowUpDB.lvGet[lv] then
  385. return 1
  386. else
  387. return heroGrowUpDB.lvGet[lv]
  388. end
  389. end
  390. function getGetExReward(human,lv)
  391. local heroGrowUpDB = human.db.heroGrowUp
  392. if not heroGrowUpDB then
  393. return 0
  394. end
  395. if lv > heroGrowUpDB.lv then
  396. return 0
  397. end
  398. if not heroGrowUpDB.lvExGet or not heroGrowUpDB.lvExGet[lv] then
  399. return 1
  400. else
  401. return heroGrowUpDB.lvExGet[lv]
  402. end
  403. end
  404. -- 设置领奖
  405. function setGetExReward(human,lv)
  406. local actStartTime = getActStartTime()
  407. if not next(human.db.heroGrowUp) then
  408. initDB(human, actStartTime)
  409. end
  410. local heroGrowUpDB = human.db.heroGrowUp
  411. heroGrowUpDB.lvExGet = heroGrowUpDB.lvExGet or {}
  412. heroGrowUpDB.lvExGet[lv] = 2
  413. end
  414. -- 是否领取
  415. function isGetTask(human, id, cf)
  416. local heroGrowUpDB = human.db.heroGrowUp
  417. if not heroGrowUpDB then
  418. return
  419. end
  420. local taskList = heroGrowUpDB.task[cf.mainType]
  421. if not taskList then return end
  422. if taskList.gets[id] then
  423. return true
  424. end
  425. end
  426. -- 设置已领取
  427. function setGetTask(human, actStartTime, id, cf)
  428. if not next(human.db.heroGrowUp)then
  429. initDB(human, actStartTime)
  430. end
  431. local heroGrowUpDB = human.db.heroGrowUp
  432. if not heroGrowUpDB.task[cf.mainType] then
  433. initTaskDB(human, actStartTime, cf.mainType)
  434. end
  435. heroGrowUpDB.task[cf.mainType].gets[id] = 1
  436. end
  437. local function getValueByKey(human, mainType, taskType, key)
  438. if taskType == TASKTYPE1 then
  439. return 1
  440. end
  441. local heroGrowUpDB = human.db.heroGrowUp
  442. local taskList = heroGrowUpDB and heroGrowUpDB.task[mainType]
  443. if not taskList then
  444. return 0
  445. end
  446. local record = taskList.records[taskType]
  447. if not key then
  448. return record or 0
  449. end
  450. return record and record[key] or 0
  451. end
  452. -- 当前进度
  453. function getValue(human, cf)
  454. local key = cf.taskArgs[2]
  455. if type(key) == "table" then
  456. local list = getMainTypesByTaskType(cf.taskType)
  457. for k,v in pairs(list[cf.mainType]) do
  458. key = k
  459. break
  460. end
  461. end
  462. return getValueByKey(human, cf.mainType, cf.taskType, key)
  463. end
  464. -- 更新进度
  465. function updateValue(human, actStartTime, mainType, taskType, key, value)
  466. if not next(human.db.heroGrowUp) then
  467. initDB(human, actStartTime)
  468. end
  469. local heroGrowUpDB = human.db.heroGrowUp
  470. if not heroGrowUpDB.task[mainType] then
  471. initTaskDB(human, actStartTime, mainType)
  472. end
  473. local taskList = heroGrowUpDB.task[mainType]
  474. if key then
  475. taskList.records[taskType] = taskList.records[taskType] or {}
  476. taskList.records[taskType][key] = value
  477. else
  478. taskList.records[taskType] = value
  479. end
  480. end
  481. -- 最大进度
  482. function getMaxValue(cf)
  483. return cf.taskArgs[1]
  484. end
  485. -- 获取任务状态
  486. function getTaskState(human, id, cf)
  487. if isGetTask(human, id, cf) then
  488. return TASK_STATE_HAD
  489. end
  490. local value = getValue(human, cf)
  491. local maxValue = getMaxValue(cf)
  492. if value >= maxValue then
  493. return TASK_STATE_CAN
  494. end
  495. return TASK_STATE_NONE
  496. end
  497. -- 获取任务名字
  498. function getTaskName(cf)
  499. if cf.taskType == TASKTYPE11 then
  500. local list = TASKTYPE_2_MAINTYPES[TASKTYPE11][cf.mainType]
  501. local heroID = cf.taskArgs[2]
  502. for k,v in pairs(list) do
  503. heroID = k
  504. break
  505. end
  506. local heroConfig = HeroDefine.getConfig(heroID)
  507. return Util.format(cf.name, heroConfig.name)
  508. end
  509. return cf.name
  510. end
  511. -- 获取任务描述
  512. function getTaskDesc(cf)
  513. if cf.taskType == TASKTYPE18 or
  514. cf.taskType == TASKTYPE4 or
  515. cf.taskType == TASKTYPE12 then
  516. return Util.format(cf.desc, cf.taskArgs[1], cf.taskArgs[2])
  517. elseif cf.taskType == TASKTYPE14 then
  518. return Util.format(cf.desc, cf.taskArgs[2])
  519. end
  520. return Util.format(cf.desc, cf.taskArgs[1])
  521. end
  522. -------------------------------------------- msg -------------------------------------------------------
  523. -- 封装基础信息
  524. function fontBaseNet(net, human, actStartTime, lvdefine)
  525. net.leftTime = getActLeftTime()
  526. net.lv = getLv(human)
  527. net.jifen = getJifen(human)
  528. net.maxJifen = lvdefine.needJifen
  529. local isBuy = isBuyKing(human)
  530. net.isBuyKing = isBuy == 1 and 1 or 0
  531. net.hasTaskRed = isRed(human) and 1 or 0
  532. end
  533. -- 封装任务信息
  534. function fontTaskNet(net, id, human)
  535. local cf = AbsActExcel.heroGrowUpTask[id]
  536. net.id = id
  537. net.taskName = getTaskName(cf)
  538. net.taskDesc = getTaskDesc(cf)
  539. net.maxValue = getMaxValue(cf)
  540. net.nowValue = math.min(getValue(human, cf), net.maxValue)
  541. Grid.makeItem(net.item, cf.items[1][1], cf.items[1][2])
  542. net.panelID = cf.panelID
  543. net.state = getTaskState(human, id, cf)
  544. end
  545. -- 积分任务界面
  546. function sendTaskQuery(human, mainType)
  547. local actStartTime,actEndTime, groupID = getActStartTime()
  548. local lvConfigs = getLvConfigs(groupID)
  549. if not actStartTime then
  550. return Broadcast.sendErr(human, Lang.YUNYING_ERR_TIME)
  551. end
  552. if not lvConfigs then
  553. return
  554. end
  555. local leftTime = getTaskLeftTime(actStartTime, mainType)
  556. if not leftTime then return end
  557. local lvdefine = lvConfigs[1]
  558. checkDB(human, actStartTime,groupID)
  559. local list = getTaskIDList(mainType)
  560. local msgRet = Msg.gc.GC_HERO_GROWUP_TASK_QUERY
  561. msgRet.endTime = actEndTime
  562. msgRet.startTime = actStartTime
  563. msgRet.leftTime = actEndTime - os.time()
  564. fontBaseNet(msgRet.data, human, actStartTime, lvdefine)
  565. msgRet.data.hasTaskRed = isTaskRed(human) and 1 or 0
  566. msgRet.mainType = mainType
  567. msgRet.taskLeftTime = leftTime
  568. msgRet.taskList[0] = list and #list or 0
  569. for i = 1, msgRet.taskList[0] do
  570. local id = list[i]
  571. fontTaskNet(msgRet.taskList[i], id, human)
  572. end
  573. msgRet.taskReds[0] = MAINTYPE_CNT
  574. for i = 1, msgRet.taskReds[0] do
  575. msgRet.taskReds[i] = isTaskRedByType(human, i) and 1 or 0
  576. end
  577. --Msg.trace(msgRet)
  578. Msg.send(msgRet, human.fd)
  579. end
  580. -- 领取任务奖励
  581. function getTaskItems(human, id)
  582. local actStartTime,actEndTime,groupID = getActStartTime()
  583. if not actStartTime then
  584. return Broadcast.sendErr(human, Lang.YUNYING_ERR_TIME)
  585. end
  586. local cf = AbsActExcel.heroGrowUpTask[id]
  587. if not cf then return end
  588. checkDB(human, actStartTime,groupID)
  589. local state = getTaskState(human, id, cf)
  590. if state == TASK_STATE_NONE then
  591. return Broadcast.sendErr(human, Lang.YUNYING_GET_ERR_CONDITION)
  592. end
  593. if state == TASK_STATE_HAD then
  594. return Broadcast.sendErr(human, Lang.YUNYING_GET_ERR_HADGET)
  595. end
  596. setGetTask(human, actStartTime, id, cf)
  597. for _, item in ipairs(cf.items) do
  598. local itemID = item[1]
  599. local itemCnt = item[2]
  600. BagLogic.addItem(human, itemID, itemCnt, "hero_growup_task")
  601. end
  602. BagLogic.sendItemGetList1(human, cf.items)
  603. sendTaskQuery(human, cf.mainType)
  604. YunYingLogic.updateIcon(YYInfo[DG_ABS_ACT_ID], human)
  605. end
  606. -- 查看王者礼包信息
  607. function sendKingQuery(human)
  608. if not SceneHandler.canCharge(human) then
  609. return
  610. end
  611. local actStartTime,actEndTime, groupID = getActStartTime()
  612. local lvConfigs = getLvConfigs(groupID)
  613. if not actStartTime then
  614. return Broadcast.sendErr(human, Lang.YUNYING_ERR_TIME)
  615. end
  616. if not lvConfigs then
  617. return
  618. end
  619. local lvdefine = lvConfigs[1].kingBuyItems
  620. checkDB(human, actStartTime,groupID)
  621. local isBuy = isBuyKing(human)
  622. if isBuy then
  623. lvdefine = lvConfigs[1].kingBuyItems2
  624. end
  625. local msgRet = Msg.gc.GC_HERO_GROWUP_KING_QUERY
  626. msgRet.items[0] = math.min(#lvdefine, #msgRet.items)
  627. for i = 1, msgRet.items[0] do
  628. local itemID = lvdefine[i][1]
  629. local itemCnt = lvdefine[i][2]
  630. Grid.makeItem(msgRet.items[i], itemID, itemCnt)
  631. end
  632. BuyLogic.fontBuyItem(human, msgRet.buyItem, lvConfigs[1].buyID)
  633. msgRet.isBuyKing = isBuy == 1 and 1 or 0
  634. --Msg.trace(msgRet)
  635. Msg.send(msgRet, human.fd)
  636. end
  637. -- 奖励界面查看
  638. function sendRewardQuery(human)
  639. local actStartTime,actEndTime, groupID = getActStartTime()
  640. local lvConfigs = getLvConfigs(groupID)
  641. if not actStartTime or not lvConfigs then
  642. return Broadcast.sendErr(human, Lang.YUNYING_ERR_TIME)
  643. end
  644. local lvdefine = lvConfigs[1]
  645. checkDB(human, actStartTime,groupID)
  646. local msgRet = Msg.gc.GC_HERO_GROWUP_REWARD_QUERY
  647. fontBaseNet(msgRet.data, human, actStartTime, lvdefine)
  648. msgRet.data.hasTaskRed = isRewardRed(human) and 1 or 0
  649. msgRet.rewardList[0] = #lvConfigs
  650. local nowLv = getLv(human)
  651. for lv = 1, msgRet.rewardList[0] do
  652. local net = msgRet.rewardList[lv]
  653. local cf = lvConfigs[lv]
  654. net.lv = lv
  655. net.items[0] = #cf.items
  656. net.state = 0
  657. net.stateEx = 0
  658. for i = 1, net.items[0] do
  659. local itemID = cf.items[i][1]
  660. local itemCnt = cf.items[i][2]
  661. Grid.makeItem(net.items[i], itemID, itemCnt)
  662. end
  663. if lv <= nowLv then
  664. net.state = getGetReward(human,lv)
  665. end
  666. net.itemsKing[0] = #cf.itemsKing
  667. for i = 1, net.itemsKing[0] do
  668. local itemID = cf.itemsKing[i][1]
  669. local itemCnt = cf.itemsKing[i][2]
  670. Grid.makeItem(net.itemsKing[i], itemID, itemCnt)
  671. end
  672. if lv <= nowLv then
  673. net.stateEx = getGetExReward(human,lv)
  674. end
  675. end
  676. local maxLv = #lvConfigs
  677. local exRewardNet = msgRet.exReward
  678. local nextLv = maxLv + lvdefine.lastNeedLv
  679. exRewardNet.needLv = lvdefine.lastNeedLv
  680. exRewardNet.items[0] = #lvdefine.lastItems
  681. exRewardNet.state = 0
  682. exRewardNet.stateEx = 0
  683. while true do
  684. if nextLv > nowLv then
  685. break
  686. end
  687. local nextState = getGetReward(human,nextLv)
  688. if not nextState or nextState == 1 then
  689. break
  690. end
  691. nextLv = nextLv + lvdefine.lastNeedLv
  692. end
  693. exRewardNet.lv = nextLv
  694. exRewardNet.state = getGetReward(human,nextLv)
  695. nextLv = maxLv + lvdefine.lastNeedLv
  696. while true do
  697. if nextLv > nowLv then
  698. break
  699. end
  700. local nextState = getGetExReward(human,nextLv)
  701. if not nextState or nextState == 1 then
  702. break
  703. end
  704. nextLv = nextLv + lvdefine.lastNeedLv
  705. end
  706. exRewardNet.exLv = nextLv
  707. exRewardNet.stateEx = getGetExReward(human,nextLv)
  708. local isBuy = isBuyKing(human)
  709. if isBuy ~= 1 then
  710. exRewardNet.stateEx = 0
  711. end
  712. for i = 1, exRewardNet.items[0] do
  713. local itemID = lvdefine.lastItems[i][1]
  714. local itemCnt = lvdefine.lastItems[i][2]
  715. Grid.makeItem(exRewardNet.items[i], itemID, itemCnt)
  716. end
  717. exRewardNet.itemsKing[0] = #lvdefine.lastItemsKing
  718. for i = 1, exRewardNet.itemsKing[0] do
  719. local itemID = lvdefine.lastItemsKing[i][1]
  720. local itemCnt = lvdefine.lastItemsKing[i][2]
  721. Grid.makeItem(exRewardNet.itemsKing[i], itemID, itemCnt)
  722. end
  723. --Msg.trace(msgRet)
  724. Msg.send(msgRet, human.fd)
  725. end
  726. -------------------------------------------- 回调 -------------------------------------------------------
  727. -- 升级回调
  728. function getLvReward(human, lv)
  729. local actStartTime,actEndTime, groupID = getActStartTime()
  730. if not groupID then
  731. return
  732. end
  733. local nowLv = getLv(human)
  734. if lv > nowLv then
  735. return
  736. end
  737. local normalGet = getGetReward(human,lv)
  738. local exGet = getGetExReward(human,lv)
  739. local lvConfigs = getLvConfigs(groupID)
  740. if not lvConfigs then
  741. return
  742. end
  743. local lvdefine = lvConfigs[1]
  744. local list = {}
  745. local maxLv = #lvConfigs
  746. local isBuy = isBuyKing(human)
  747. local cf = lvConfigs[lv]
  748. local items = cf and cf.items
  749. local itemsKing = cf and cf.itemsKing
  750. if (not cf) and (lv - maxLv) % lvdefine.lastNeedLv == 0 then
  751. items = lvdefine.lastItems
  752. itemsKing = lvdefine.lastItemsKing
  753. end
  754. if items and normalGet ~= 2 then
  755. for _, item in ipairs(items) do
  756. local itemID = item[1]
  757. local itemCnt = item[2]
  758. list[itemID] = (list[itemID] or 0) + itemCnt
  759. end
  760. end
  761. if itemsKing and isBuy == 1 and exGet ~= 2 then
  762. for _, item in ipairs(itemsKing) do
  763. local itemID = item[1]
  764. local itemCnt = item[2]
  765. list[itemID] = (list[itemID] or 0) + itemCnt
  766. end
  767. end
  768. if not next(list) then return end
  769. setGetReward(human,lv)
  770. if isBuy == 1 then
  771. setGetExReward(human,lv)
  772. end
  773. YunYingLogic.updateIcon(YYInfo[DG_ABS_ACT_ID], human)
  774. local msgRet = Msg.gc.GC_HERO_GROWUP_LVUP
  775. msgRet.lv = nowLv
  776. msgRet.items[0] = 0
  777. for itemID, itemCnt in pairs(list) do
  778. BagLogic.addItem(human, itemID, itemCnt, "hero_growup")
  779. if msgRet.items[0] < #msgRet.items then
  780. msgRet.items[0] = msgRet.items[0] + 1
  781. Grid.makeItem(msgRet.items[msgRet.items[0]], itemID, itemCnt)
  782. end
  783. end
  784. BagLogic.sendItemGetList2(human, list)
  785. msgRet.isBuyKing = isBuy == 1 and 1 or 0
  786. --Msg.trace(msgRet)
  787. Msg.send(msgRet, human.fd)
  788. end
  789. -- 购买王者礼包ii
  790. function buyKing(human)
  791. local actStartTime,actEndTime, groupID = getActStartTime()
  792. local lvConfigs = getLvConfigs(groupID)
  793. if not actStartTime then return end
  794. if not lvConfigs then
  795. return
  796. end
  797. local lvdefine = lvConfigs[1]
  798. checkDB(human, actStartTime,groupID)
  799. local isBuy = isBuyKing(human)
  800. if isBuy == 1 then return end
  801. setBuyKing(human, actStartTime)
  802. -- 计算可以给的东西
  803. -- local maxLv = #lvConfigs
  804. -- local nowLv = getLv(human)
  805. -- local list = {}
  806. -- for lv = 1, nowLv do
  807. -- local cf = lvConfigs[lv]
  808. -- local itemsKing = cf and cf.itemsKing
  809. -- if (not cf) and (lv - maxLv) % lvdefine.lastNeedLv then
  810. -- itemsKing = lvdefine.lastItemsKing
  811. -- end
  812. -- if itemsKing then
  813. -- for _, item in ipairs(itemsKing) do
  814. -- local itemID = item[1]
  815. -- local itemCnt = item[2]
  816. -- list[itemID] = (list[itemID] or 0) + itemCnt
  817. -- end
  818. -- end
  819. -- end
  820. local list = {}
  821. local config = lvdefine.kingBuyItems
  822. if isBuy then
  823. config = lvdefine.kingBuyItems2
  824. end
  825. -- 购买王者后直接赠送的东西
  826. for _, item in ipairs(config) do
  827. local itemID = item[1]
  828. local itemCnt = item[2]
  829. list[itemID] = (list[itemID] or 0) + itemCnt
  830. end
  831. -- 给东西
  832. for itemID, itemCnt in pairs(list) do
  833. BagLogic.addItem(human, itemID, itemCnt, "hero_growup")
  834. end
  835. BagLogic.sendItemGetList2(human, list)
  836. YunYingLogic.updateIcon(YYInfo[DG_ABS_ACT_ID], human)
  837. local msgRet = Msg.gc.GC_HERO_GROWUP_BUY_OK
  838. fontBaseNet(msgRet.data, human, actStartTime, lvdefine)
  839. Msg.send(msgRet, human.fd)
  840. sendRewardQuery(human)
  841. end
  842. -- 子回调
  843. local function doCallback(human, actStartTime, mainType, taskType, maxValue, key, value)
  844. local oldValue = getValueByKey(human, mainType, taskType, key)
  845. if oldValue >= maxValue then
  846. return
  847. end
  848. local newValue = oldValue
  849. -- 任务类型11 指定英雄 竞技场胜利指定次数
  850. if taskType == TASKTYPE11 then
  851. local isFind = nil
  852. for _, obj in pairs(value.objList) do
  853. if obj.side == CombatDefine.ATTACK_SIDE and
  854. obj.id == key then
  855. isFind = true
  856. break
  857. end
  858. end
  859. if not isFind then return end
  860. newValue = oldValue + 1
  861. elseif taskType == TASKTYPE12 then
  862. if key ~= value then
  863. return
  864. end
  865. newValue = oldValue + 1
  866. elseif taskType == TASKTYPE14 then
  867. if value > key then
  868. return
  869. end
  870. newValue = oldValue + 1
  871. else
  872. newValue = math.min(oldValue + value, maxValue)
  873. end
  874. updateValue(human, actStartTime, mainType, taskType, key, newValue)
  875. return true
  876. end
  877. -- 任务回调
  878. function onCallback(human, taskType, value)
  879. local actStartTime,actEndTime,groupID = getActStartTime()
  880. if not actStartTime then return end
  881. local mainTypes = getMainTypesByTaskType(taskType)
  882. if not mainTypes then return end
  883. checkDB(human, actStartTime,groupID)
  884. local isChange = nil
  885. for mainType, mainValue in pairs(mainTypes) do
  886. local mainValueType = type(mainValue)
  887. if mainValueType == "number" then
  888. if doCallback(human, actStartTime, mainType, taskType, mainValue, nil, value) then
  889. isChange = true
  890. end
  891. elseif mainValueType == "table" then
  892. for key, maxValue in pairs(mainValue) do
  893. if doCallback(human, actStartTime, mainType, taskType, maxValue, key, value) then
  894. isChange = true
  895. end
  896. end
  897. end
  898. end
  899. if isChange then
  900. YunYingLogic.updateIcon(YYInfo[DG_ABS_ACT_ID], human)
  901. Msg.send(Msg.gc.GC_HERO_GROWUP_TASK_REFRESH, human.fd)
  902. end
  903. return isChange
  904. end
  905. -- 任务回调 uuid
  906. local FakeHuman = {}
  907. function onCallbackByUuid(uuid, taskType, value)
  908. local db, online = RoleDBLogic.getDb(uuid)
  909. if not db then return end
  910. FakeHuman.db = db
  911. if onCallback(FakeHuman, taskType, value) and not online then
  912. RoleDBLogic.saveRole(db)
  913. end
  914. end
  915. function buyJifen(human,itemID,cnt)
  916. local actStartTime,actEndTime,groupID = getActStartTime()
  917. if not actStartTime then return end
  918. local now = os.time()
  919. if actEndTime - now > 3*86400 then
  920. return
  921. end
  922. checkDB(human, actStartTime,groupID)
  923. local config = ItemExcel.commonBuy[itemID]
  924. if not config then
  925. return
  926. end
  927. local price = config.price[2]*cnt
  928. if not ObjHuman.checkRMB(human,price) then
  929. return
  930. end
  931. ObjHuman.decZuanshi(human, - price, "hero_growup")
  932. addJifen(human, 1000*cnt)
  933. local msgRet = Msg.gc.GC_HERO_GROWUP_BUY_JIFEN
  934. msgRet.lv = human.db.heroGrowUp.lv or 0
  935. msgRet.jifen = human.db.heroGrowUp.jifen or 0
  936. msgRet.maxJifen = AbsActExcel.heroGrowUpLv[1].needJifen
  937. Msg.send(msgRet,human.fd)
  938. end
  939. -- 活动循环,开启与结束
  940. function actLoop()
  941. local workManStartTime,workManEndTime,groupID = getActStartTime()
  942. local workMan = CommonDB.getWorkMan()
  943. -- 活动未开,且commonDB活动开,则关闭活动
  944. if not workManStartTime and workMan.state then
  945. CommonDB.setWorkManState()
  946. return
  947. end
  948. -- 活动开,且commonDB活动未开,则开启活动
  949. -- 活动id不符
  950. if (workManStartTime and not workMan.state) or groupID ~= workMan.groupID then
  951. CommonDB.setWorkManState(true)
  952. CommonDB.setWorkManGroup(groupID)
  953. CommonDB.setWorkManTs(workManStartTime)
  954. --重置任务
  955. TASKTYPE_2_MAINTYPES = {}
  956. MAINTYPE_2_IDLIST = {}
  957. -- 设置新任务
  958. for id, cf in pairs(AbsActExcel.heroGrowUpTask) do
  959. if not TASKTYPE_2_MAINTYPES[cf.taskType] then
  960. TASKTYPE_2_MAINTYPES[cf.taskType] = {}
  961. end
  962. if not MAINTYPE_2_IDLIST[cf.mainType] then
  963. MAINTYPE_2_IDLIST[cf.mainType] = {}
  964. end
  965. local len = #MAINTYPE_2_IDLIST[cf.mainType]
  966. MAINTYPE_2_IDLIST[cf.mainType][len + 1] = id
  967. local list = TASKTYPE_2_MAINTYPES[cf.taskType]
  968. local value = cf.taskArgs[1]
  969. local key = cf.taskArgs[2]
  970. if type(cf.taskArgs[2]) == "table" then
  971. local lenth = #cf.taskArgs[2]
  972. local randomPos = math.random(1,lenth)
  973. key = cf.taskArgs[2][randomPos]
  974. end
  975. if key then
  976. list[cf.mainType] = list[cf.mainType] or {}
  977. list[cf.mainType][key] = math.max(list[cf.mainType][key] or 0, value)
  978. else
  979. list[cf.mainType] = math.max(list[cf.mainType] or 0, value)
  980. end
  981. end
  982. GROUPID_2_LVCONFIGS = {}
  983. for _, cf in ipairs(AbsActExcel.heroGrowUpLv) do
  984. if not GROUPID_2_LVCONFIGS[cf.groupID] then
  985. GROUPID_2_LVCONFIGS[cf.groupID] = {}
  986. end
  987. GROUPID_2_LVCONFIGS[cf.groupID][cf.lv] = cf
  988. end
  989. return
  990. end
  991. end